Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / media_recorder_handler.h
bloba97843bba757f81ed06da8c691718b4bf3962300
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"
17 namespace blink {
18 class WebMediaRecorderHandlerClient;
19 class WebString;
20 } // namespace blink
22 namespace media {
23 class VideoFrame;
24 class WebmMuxer;
25 } // namespace media
27 namespace content {
29 class VideoTrackRecorder;
31 // MediaRecorderHandler orchestrates the creation, lifetime mgmt and mapping
32 // between:
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) {
42 public:
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;
53 void stop() override;
54 void pause() override;
55 void resume() override;
57 private:
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_;
68 bool recording_;
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_