Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/renderer/media/media_recorder_handler.h

Issue 1407083006: Update MediaRecorderHandler to use AudioTrackRecorder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add layout tests Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
69 76
70 // Bound to the main render thread. 77 // Bound to the main render thread.
71 base::ThreadChecker main_render_thread_checker_; 78 base::ThreadChecker main_render_thread_checker_;
72 79
73 // Force using VP9 for video encoding, otherwise VP8 will be used by default. 80 // Force using VP9 for video encoding, otherwise VP8 will be used by default.
74 bool use_vp9_; 81 bool use_vp9_;
75 82
76 // |client_| has no notion of time, thus may configure us via start(timeslice) 83 // |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 84 // to notify it after a certain |timeslice_| has passed. We use a moving
78 // |slice_origin_timestamp_| to track those time chunks. 85 // |slice_origin_timestamp_| to track those time chunks.
79 base::TimeDelta timeslice_; 86 base::TimeDelta timeslice_;
80 base::TimeTicks slice_origin_timestamp_; 87 base::TimeTicks slice_origin_timestamp_;
81 88
82 bool recording_; 89 bool recording_;
83 blink::WebMediaStream media_stream_; // The MediaStream being recorded. 90 blink::WebMediaStream media_stream_; // The MediaStream being recorded.
84 91
85 // |client_| is a weak pointer, and is valid for the lifetime of this object. 92 // |client_| is a weak pointer, and is valid for the lifetime of this object.
86 blink::WebMediaRecorderHandlerClient* client_; 93 blink::WebMediaRecorderHandlerClient* client_;
87 94
88 ScopedVector<VideoTrackRecorder> video_recorders_; 95 ScopedVector<VideoTrackRecorder> video_recorders_;
96 ScopedVector<AudioTrackRecorder> audio_recorders_;
89 97
90 // Worker class doing the actual Webm Muxing work. 98 // Worker class doing the actual Webm Muxing work.
91 scoped_ptr<media::WebmMuxer> webm_muxer_; 99 scoped_ptr<media::WebmMuxer> webm_muxer_;
92 100
93 base::WeakPtrFactory<MediaRecorderHandler> weak_factory_; 101 base::WeakPtrFactory<MediaRecorderHandler> weak_factory_;
94 102
95 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler); 103 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler);
96 }; 104 };
97 105
98 } // namespace content 106 } // namespace content
99 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ 107 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698