1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/strings/string_piece.h"
12 #include "base/threading/thread_checker.h"
13 #include "content/common/content_export.h"
14 #include "third_party/WebKit/public/platform/WebMediaRecorderHandler.h"
15 #include "third_party/WebKit/public/platform/WebMediaStream.h"
18 class WebMediaRecorderHandlerClient
;
29 class VideoTrackRecorder
;
31 // MediaRecorderHandler orchestrates the creation, lifetime mgmt and mapping
33 // - MediaStreamTrack(s) providing data,
34 // - {Audio,Video}TrackRecorders encoding that data,
35 // - a WebmMuxer class multiplexing encoded data into a WebM container, and
36 // - a single recorder client receiving this contained data.
37 // All methods are called on the same thread as construction and destruction,
38 // i.e. the Main Render thread.
39 // TODO(mcasas): Implement audio recording.
40 class CONTENT_EXPORT MediaRecorderHandler final
41 : public NON_EXPORTED_BASE(blink::WebMediaRecorderHandler
) {
43 MediaRecorderHandler();
44 ~MediaRecorderHandler() override
;
46 // See above, these methods should override blink::WebMediaRecorderHandler.
47 bool canSupportMimeType(const blink::WebString
& mimeType
) override
;
48 bool initialize(blink::WebMediaRecorderHandlerClient
* client
,
49 const blink::WebMediaStream
& media_stream
,
50 const blink::WebString
& mimeType
) override
;
51 bool start() override
;
52 bool start(int timeslice
) override
;
54 void pause() override
;
55 void resume() override
;
58 friend class MediaRecorderHandlerTest
;
60 void WriteData(const base::StringPiece
& data
);
62 void OnVideoFrameForTesting(const scoped_refptr
<media::VideoFrame
>& frame
,
63 const base::TimeTicks
& timestamp
);
65 // Bound to the main render thread.
66 base::ThreadChecker main_render_thread_checker_
;
69 blink::WebMediaStream media_stream_
; // The MediaStream being recorded.
71 // |client_| is a weak pointer, and is valid for the lifetime of this object.
72 blink::WebMediaRecorderHandlerClient
* client_
;
74 ScopedVector
<VideoTrackRecorder
> video_recorders_
;
76 // Worker class doing the actual Webm Muxing work.
77 scoped_ptr
<media::WebmMuxer
> webm_muxer_
;
79 base::WeakPtrFactory
<MediaRecorderHandler
> weak_factory_
;
81 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler
);
84 } // namespace content
85 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_