OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "third_party/WebKit/public/platform/WebMediaRecorderHandler.h" | 14 #include "third_party/WebKit/public/platform/WebMediaRecorderHandler.h" |
15 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 15 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 class WebMediaRecorderHandlerClient; | 18 class WebMediaRecorderHandlerClient; |
19 class WebString; | 19 class WebString; |
20 } // namespace blink | 20 } // namespace blink |
21 | 21 |
22 namespace media { | 22 namespace media { |
| 23 class AudioBus; |
| 24 class AudioParameters; |
23 class VideoFrame; | 25 class VideoFrame; |
24 class WebmMuxer; | 26 class WebmMuxer; |
25 } // namespace media | 27 } // namespace media |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 class VideoTrackRecorder; | 31 class VideoTrackRecorder; |
| 32 class AudioTrackRecorder; |
30 | 33 |
31 // MediaRecorderHandler orchestrates the creation, lifetime management and | 34 // MediaRecorderHandler orchestrates the creation, lifetime management and |
32 // mapping between: | 35 // mapping between: |
33 // - MediaStreamTrack(s) providing data, | 36 // - MediaStreamTrack(s) providing data, |
34 // - {Audio,Video}TrackRecorders encoding that data, | 37 // - {Audio,Video}TrackRecorders encoding that data, |
35 // - a WebmMuxer class multiplexing encoded data into a WebM container, and | 38 // - a WebmMuxer class multiplexing encoded data into a WebM container, and |
36 // - a single recorder client receiving this contained data. | 39 // - a single recorder client receiving this contained data. |
37 // All methods are called on the same thread as construction and destruction, | 40 // All methods are called on the same thread as construction and destruction, |
38 // i.e. the Main Render thread. (Note that a BindToCurrentLoop is used to | 41 // i.e. the Main Render thread. (Note that a BindToCurrentLoop is used to |
39 // guarantee this, since VideoTrackRecorder sends back frames on IO thread.) | 42 // guarantee this, since VideoTrackRecorder sends back frames on IO thread.) |
40 // TODO(mcasas): http://crbug.com/528519 Implement audio recording. | |
41 class CONTENT_EXPORT MediaRecorderHandler final | 43 class CONTENT_EXPORT MediaRecorderHandler final |
42 : public NON_EXPORTED_BASE(blink::WebMediaRecorderHandler) { | 44 : public NON_EXPORTED_BASE(blink::WebMediaRecorderHandler) { |
43 public: | 45 public: |
44 MediaRecorderHandler(); | 46 MediaRecorderHandler(); |
45 ~MediaRecorderHandler() override; | 47 ~MediaRecorderHandler() override; |
46 | 48 |
47 // blink::WebMediaRecorderHandler. | 49 // blink::WebMediaRecorderHandler. |
48 bool canSupportMimeType(const blink::WebString& mimeType) override; | 50 bool canSupportMimeType(const blink::WebString& mimeType) override; |
49 bool initialize(blink::WebMediaRecorderHandlerClient* client, | 51 bool initialize(blink::WebMediaRecorderHandlerClient* client, |
50 const blink::WebMediaStream& media_stream, | 52 const blink::WebMediaStream& media_stream, |
51 const blink::WebString& mimeType) override; | 53 const blink::WebString& mimeType) override; |
52 bool start() override; | 54 bool start() override; |
53 bool start(int timeslice) override; | 55 bool start(int timeslice) override; |
54 void stop() override; | 56 void stop() override; |
55 void pause() override; | 57 void pause() override; |
56 void resume() override; | 58 void resume() override; |
57 | 59 |
58 private: | 60 private: |
59 friend class MediaRecorderHandlerTest; | 61 friend class MediaRecorderHandlerTest; |
60 | 62 |
61 void OnEncodedVideo(const scoped_refptr<media::VideoFrame>& video_frame, | 63 void OnEncodedVideo(const scoped_refptr<media::VideoFrame>& video_frame, |
62 scoped_ptr<std::string> encoded_data, | 64 scoped_ptr<std::string> encoded_data, |
63 base::TimeTicks timestamp, | 65 base::TimeTicks timestamp, |
64 bool is_key_frame); | 66 bool is_key_frame); |
| 67 void OnEncodedAudio(const media::AudioParameters& params, |
| 68 scoped_ptr<std::string> encoded_data, |
| 69 base::TimeTicks timestamp); |
65 void WriteData(base::StringPiece data); | 70 void WriteData(base::StringPiece data); |
66 | 71 |
67 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, | 72 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, |
68 const base::TimeTicks& timestamp); | 73 const base::TimeTicks& timestamp); |
| 74 void OnAudioBusForTesting(const media::AudioBus& audio_bus, |
| 75 const base::TimeTicks& timestamp); |
| 76 void SetAudioFormatForTesting(const media::AudioParameters& params); |
69 | 77 |
70 // Bound to the main render thread. | 78 // Bound to the main render thread. |
71 base::ThreadChecker main_render_thread_checker_; | 79 base::ThreadChecker main_render_thread_checker_; |
72 | 80 |
73 // Force using VP9 for video encoding, otherwise VP8 will be used by default. | 81 // Force using VP9 for video encoding, otherwise VP8 will be used by default. |
74 bool use_vp9_; | 82 bool use_vp9_; |
75 | 83 |
76 // |client_| has no notion of time, thus may configure us via start(timeslice) | 84 // |client_| has no notion of time, thus may configure us via start(timeslice) |
77 // to notify it after a certain |timeslice_| has passed. We use a moving | 85 // to notify it after a certain |timeslice_| has passed. We use a moving |
78 // |slice_origin_timestamp_| to track those time chunks. | 86 // |slice_origin_timestamp_| to track those time chunks. |
79 base::TimeDelta timeslice_; | 87 base::TimeDelta timeslice_; |
80 base::TimeTicks slice_origin_timestamp_; | 88 base::TimeTicks slice_origin_timestamp_; |
81 | 89 |
82 bool recording_; | 90 bool recording_; |
83 blink::WebMediaStream media_stream_; // The MediaStream being recorded. | 91 blink::WebMediaStream media_stream_; // The MediaStream being recorded. |
84 | 92 |
85 // |client_| is a weak pointer, and is valid for the lifetime of this object. | 93 // |client_| is a weak pointer, and is valid for the lifetime of this object. |
86 blink::WebMediaRecorderHandlerClient* client_; | 94 blink::WebMediaRecorderHandlerClient* client_; |
87 | 95 |
88 ScopedVector<VideoTrackRecorder> video_recorders_; | 96 ScopedVector<VideoTrackRecorder> video_recorders_; |
| 97 ScopedVector<AudioTrackRecorder> audio_recorders_; |
89 | 98 |
90 #if !defined(MEDIA_DISABLE_LIBWEBM) | 99 #if !defined(MEDIA_DISABLE_LIBWEBM) |
91 // Worker class doing the actual Webm Muxing work. | 100 // Worker class doing the actual Webm Muxing work. |
92 scoped_ptr<media::WebmMuxer> webm_muxer_; | 101 scoped_ptr<media::WebmMuxer> webm_muxer_; |
93 #endif | 102 #endif |
94 | 103 |
95 base::WeakPtrFactory<MediaRecorderHandler> weak_factory_; | 104 base::WeakPtrFactory<MediaRecorderHandler> weak_factory_; |
96 | 105 |
97 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler); | 106 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler); |
98 }; | 107 }; |
99 | 108 |
100 } // namespace content | 109 } // namespace content |
101 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ | 110 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ |
OLD | NEW |