OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "content/renderer/media/media_recorder_handler.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/logging.h" | |
10 #include "content/renderer/media/video_track_recorder.h" | |
11 #include "media/base/bind_to_current_loop.h" | |
12 #include "media/capture/webm_muxer.h" | |
13 #include "third_party/WebKit/public/platform/WebString.h" | |
14 | |
15 namespace content { | |
16 | |
17 MediaRecorderHandler::MediaRecorderHandler() | |
18 : recording_(false), client_(nullptr), weak_factory_(this) { | |
19 DVLOG(3) << __FUNCTION__; | |
20 } | |
21 | |
22 MediaRecorderHandler::~MediaRecorderHandler() { | |
23 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
24 // Send a |last_in_slice| to our |client_|. | |
25 if (client_) | |
26 client_->writeData(nullptr, 0u, true); | |
27 } | |
28 | |
29 bool MediaRecorderHandler::canSupportMimeType( | |
30 const blink::WebString& mimeType) { | |
31 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
32 // TODO(mcasas): For the time being only "video/vp8" is supported. | |
33 return mimeType.utf8().compare("video/vp8") == 0; | |
34 } | |
35 | |
36 bool MediaRecorderHandler::initialize( | |
37 blink::WebMediaRecorderHandlerClient* client, | |
38 const blink::WebMediaStream& media_stream, | |
39 const blink::WebString& mimeType) { | |
40 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
41 if (!canSupportMimeType(mimeType)) { | |
42 DLOG(ERROR) << "Can't support type " << mimeType.utf8(); | |
43 return false; | |
44 } | |
45 media_stream_ = media_stream; | |
46 DCHECK(client); | |
47 client_ = client; | |
48 | |
49 return true; | |
50 } | |
51 | |
52 bool MediaRecorderHandler::start() { | |
53 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
54 DCHECK(!recording_); | |
55 return start(0); | |
56 } | |
57 | |
58 bool MediaRecorderHandler::start(int timeslice) { | |
59 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
60 DCHECK(!recording_); | |
61 DCHECK(!media_stream_.isNull()); | |
62 | |
63 webm_muxer_.reset(new media::WebmMuxer(media::BindToCurrentLoop(base::Bind( | |
64 &MediaRecorderHandler::WriteData, weak_factory_.GetWeakPtr())))); | |
65 DCHECK(webm_muxer_); | |
66 | |
67 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | |
68 media_stream_.videoTracks(video_tracks); | |
69 | |
70 if (video_tracks.size() != 1u) { | |
71 // TODO(mcasas): Add audio_tracks and update this DCHECK() correspondingly, | |
miu
2015/09/08 20:24:40
Comment refers to a DCHECK that is now gone.
mcasas
2015/09/08 23:36:14
Done.
| |
72 // see http://crbug.com/528519. As of now only video tracks are supported. | |
73 LOG_IF(WARNING, video_tracks.isEmpty()) | |
74 << "Recording audio tracks is not implemented"; | |
75 // TODO(mcasas): The muxer API supports only one video track. Extend it to | |
76 // several video tracks, see http://crbug.com/528523. | |
77 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" | |
78 << " tracks is not implemented. Only recording first video track."; | |
79 return false; | |
miu
2015/09/08 20:24:40
You should only return false if video_tracks.IsEmp
mcasas
2015/09/08 23:36:14
Done.
| |
80 } | |
81 | |
82 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | |
83 if (video_track.isNull()) | |
84 return false; | |
85 | |
86 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | |
87 base::Bind(&media::WebmMuxer::OnEncodedVideo, | |
88 base::Unretained(webm_muxer_.get())); | |
89 | |
90 video_recorders_.push_back(new VideoTrackRecorder(video_track, | |
91 on_encoded_video_cb)); | |
92 | |
93 recording_ = true; | |
94 return true; | |
95 } | |
96 | |
97 void MediaRecorderHandler::stop() { | |
98 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
99 DCHECK(recording_); | |
100 | |
101 recording_ = false; | |
102 video_recorders_.clear(); | |
103 webm_muxer_.reset(NULL); | |
104 } | |
105 | |
106 void MediaRecorderHandler::pause() { | |
107 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
108 DCHECK(recording_); | |
109 recording_ = false; | |
110 NOTIMPLEMENTED(); | |
111 } | |
112 | |
113 void MediaRecorderHandler::resume() { | |
114 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
115 DCHECK(!recording_); | |
116 recording_ = true; | |
117 NOTIMPLEMENTED(); | |
118 } | |
119 | |
120 void MediaRecorderHandler::WriteData(const base::StringPiece& data) { | |
121 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
122 client_->writeData(data.data(), data.size(), false /* lastInSlice */); | |
123 } | |
124 | |
125 void MediaRecorderHandler::OnVideoFrameForTesting( | |
126 const scoped_refptr<media::VideoFrame>& frame, | |
127 const base::TimeTicks& timestamp) { | |
128 for (auto* recorder : video_recorders_) | |
129 recorder->OnVideoFrameForTesting(frame, timestamp); | |
130 } | |
131 | |
132 } // namespace content | |
OLD | NEW |