Index: content/renderer/media/media_recorder_handler.h |
diff --git a/content/renderer/media/media_recorder_handler.h b/content/renderer/media/media_recorder_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8b9ed28048a17ada0f39f7ef17585c1dabd6aff9 |
--- /dev/null |
+++ b/content/renderer/media/media_recorder_handler.h |
@@ -0,0 +1,89 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ |
+#define CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ |
+ |
+#include "base/memory/scoped_vector.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/strings/string_piece.h" |
+#include "base/threading/thread_checker.h" |
+#include "content/common/content_export.h" |
+#include "third_party/WebKit/public/platform/WebMediaStream.h" |
+#include "third_party/WebKit/public/platform/WebString.h" |
+ |
+namespace media { |
+class VideoFrame; |
+class WebmMuxer; |
+} // namespace media |
+ |
+namespace content { |
+ |
+class VideoTrackRecorder; |
+ |
+// TODO(mcasas): This class should derive from WebMediaRecorderHandler as |
+// defined in [1] whenever Blink http://crrev.com/1255873002 is landed, and use |
+// a WebMediaRecorderHandlerClient instead of MediaRecorderHandlerClient. |
+// [1] http://w3c.github.io/mediacapture-record/MediaRecorder.html#MediaRecorderAPI |
+class MediaRecorderHandlerClient { |
+ public: |
+ virtual ~MediaRecorderHandlerClient() = default; |
+ |
+ virtual void writeData(const char* data, size_t length, bool lastInslice) = 0; |
miu
2015/09/02 21:28:13
Should the name of the 3rd arg be lastInSlice (cap
mcasas
2015/09/04 02:16:30
Done.
|
+}; |
+ |
+// MediaRecorderHandler orchestrates the creation, lifetime mgmt and mapping |
+// between: |
+// - MediaStreamTrack(s) providing data, |
+// - {Audio,Video}TrackRecorders encoding that data, |
+// - a WebmMuxer class multiplexing encoded data into a WebM container, and |
+// - a single recorder |client_| receiving this contained data. |
+// All methods are called on the same thread as construction and destruction, |
+// i.e. the Main Render thread. |
+// TODO(mcasas): Implement audio recording. |
+class CONTENT_EXPORT MediaRecorderHandler final { |
+ public: |
+ MediaRecorderHandler(); |
+ ~MediaRecorderHandler(); |
+ |
+ // See above, these methods should override blink::WebMediaRecorderHandler. |
+ bool canSupportMimeType(const blink::WebString& mimeType); |
+ bool initialize(MediaRecorderHandlerClient* client, |
+ const blink::WebMediaStream& media_stream, |
+ const blink::WebString& mimeType); |
+ bool start(); |
+ bool start(int timeslice); |
+ void stop(); |
+ void pause(); |
+ void resume(); |
+ |
+ private: |
+ friend class MediaRecorderHandlerTest; |
+ |
+ void WriteData(const base::StringPiece& data); |
+ |
+ void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, |
+ const base::TimeTicks& timestamp); |
+ |
+ // Bound to the main render thread. |
+ base::ThreadChecker main_render_thread_checker_; |
+ |
+ bool recording_; |
miu
2015/09/02 21:28:13
You don't need this boolean. You could replace it
mcasas
2015/09/04 02:16:30
Still needs to be |recording_| == false between p
miu
2015/09/04 21:48:52
Acknowledged.
|
+ blink::WebMediaStream media_stream_; // The MediaStream being recorded. |
+ |
+ // |client_| is a weak pointer, and is valid for the lifetime of this object. |
+ MediaRecorderHandlerClient* client_; |
+ |
+ ScopedVector<VideoTrackRecorder> video_recorders_; |
+ |
+ // Worker class doing the actual Webm Muxing work. |
+ scoped_ptr<media::WebmMuxer> webm_muxer_; |
+ |
+ base::WeakPtrFactory<MediaRecorderHandler> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler); |
+}; |
+ |
+} // namespace content |
+#endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ |