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

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

Issue 1351473006: WebmMuxer-MediaRecorderHandler: thread hopping and data ownership (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: miu@ proposal Created 5 years, 3 months 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"
12 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
13 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
14 #include "third_party/WebKit/public/platform/WebMediaRecorderHandler.h" 13 #include "third_party/WebKit/public/platform/WebMediaRecorderHandler.h"
15 #include "third_party/WebKit/public/platform/WebMediaStream.h" 14 #include "third_party/WebKit/public/platform/WebMediaStream.h"
16 15
17 namespace blink { 16 namespace blink {
18 class WebMediaRecorderHandlerClient; 17 class WebMediaRecorderHandlerClient;
19 class WebString; 18 class WebString;
20 } // namespace blink 19 } // namespace blink
21 20
22 namespace media { 21 namespace media {
23 class VideoFrame; 22 class VideoFrame;
24 class WebmMuxer; 23 class WebmMuxer;
25 } // namespace media 24 } // namespace media
26 25
27 namespace content { 26 namespace content {
28 27
29 class VideoTrackRecorder; 28 class VideoTrackRecorder;
30 29
31 // MediaRecorderHandler orchestrates the creation, lifetime mgmt and mapping 30 // MediaRecorderHandler orchestrates the creation, lifetime management and
32 // between: 31 // mapping between:
33 // - MediaStreamTrack(s) providing data, 32 // - MediaStreamTrack(s) providing data,
34 // - {Audio,Video}TrackRecorders encoding that data, 33 // - {Audio,Video}TrackRecorders encoding that data,
35 // - a WebmMuxer class multiplexing encoded data into a WebM container, and 34 // - a WebmMuxer class multiplexing encoded data into a WebM container, and
36 // - a single recorder client receiving this contained data. 35 // - a single recorder client receiving this contained data.
37 // All methods are called on the same thread as construction and destruction, 36 // All methods are called on the same thread as construction and destruction,
38 // i.e. the Main Render thread. 37 // i.e. the Main Render thread. (Note that a BindToCurrentLoop is used to
39 // TODO(mcasas): Implement audio recording. 38 // guarantee this, since VideoTrackRecorder sends back frames on IO thread.)
39 // TODO(mcasas): http://crbug.com/528519 Implement audio recording.
40 class CONTENT_EXPORT MediaRecorderHandler final 40 class CONTENT_EXPORT MediaRecorderHandler final
41 : public NON_EXPORTED_BASE(blink::WebMediaRecorderHandler) { 41 : public NON_EXPORTED_BASE(blink::WebMediaRecorderHandler) {
42 public: 42 public:
43 MediaRecorderHandler(); 43 MediaRecorderHandler();
44 ~MediaRecorderHandler() override; 44 ~MediaRecorderHandler() override;
45 45
46 // See above, these methods should override blink::WebMediaRecorderHandler. 46 // blink::WebMediaRecorderHandler.
47 bool canSupportMimeType(const blink::WebString& mimeType) override; 47 bool canSupportMimeType(const blink::WebString& mimeType) override;
48 bool initialize(blink::WebMediaRecorderHandlerClient* client, 48 bool initialize(blink::WebMediaRecorderHandlerClient* client,
49 const blink::WebMediaStream& media_stream, 49 const blink::WebMediaStream& media_stream,
50 const blink::WebString& mimeType) override; 50 const blink::WebString& mimeType) override;
51 bool start() override; 51 bool start() override;
52 bool start(int timeslice) override; 52 bool start(int timeslice) override;
53 void stop() override; 53 void stop() override;
54 void pause() override; 54 void pause() override;
55 void resume() override; 55 void resume() override;
56 56
57 private: 57 private:
58 friend class MediaRecorderHandlerTest; 58 friend class MediaRecorderHandlerTest;
59 59
60 void WriteData(const base::StringPiece& data); 60 void OnEncodedVideo(const scoped_refptr<media::VideoFrame>& video_frame,
61 scoped_ptr<std::string> encoded_data,
62 base::TimeTicks timestamp,
63 bool is_key_frame);
64 void WriteData(scoped_ptr<std::string> data);
miu 2015/09/22 04:11:08 FWICT, there was no need to change the WriteData()
mcasas 2015/09/22 16:58:40 Acknowledged.
61 65
62 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, 66 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame,
63 const base::TimeTicks& timestamp); 67 const base::TimeTicks& timestamp);
64 68
65 // Bound to the main render thread. 69 // Bound to the main render thread.
66 base::ThreadChecker main_render_thread_checker_; 70 base::ThreadChecker main_render_thread_checker_;
67 71
68 bool recording_; 72 bool recording_;
69 blink::WebMediaStream media_stream_; // The MediaStream being recorded. 73 blink::WebMediaStream media_stream_; // The MediaStream being recorded.
70 74
71 // |client_| is a weak pointer, and is valid for the lifetime of this object. 75 // |client_| is a weak pointer, and is valid for the lifetime of this object.
72 blink::WebMediaRecorderHandlerClient* client_; 76 blink::WebMediaRecorderHandlerClient* client_;
73 77
74 ScopedVector<VideoTrackRecorder> video_recorders_; 78 ScopedVector<VideoTrackRecorder> video_recorders_;
75 79
76 // Worker class doing the actual Webm Muxing work. 80 // Worker class doing the actual Webm Muxing work.
77 scoped_ptr<media::WebmMuxer> webm_muxer_; 81 scoped_ptr<media::WebmMuxer> webm_muxer_;
78 82
79 base::WeakPtrFactory<MediaRecorderHandler> weak_factory_; 83 base::WeakPtrFactory<MediaRecorderHandler> weak_factory_;
80 84
81 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler); 85 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandler);
82 }; 86 };
83 87
84 } // namespace content 88 } // namespace content
85 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_ 89 #endif // CONTENT_RENDERER_MEDIA_MEDIA_RECORDER_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/media_recorder_handler.cc » ('j') | content/renderer/media/media_recorder_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698