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.isEmpty()) { | |
71 // TODO(mcasas): Add audio_tracks and update the code in this function | |
72 // correspondingly, see http://crbug.com/528519. As of now, only video | |
73 // tracks are supported. | |
74 LOG(WARNING) << "Recording audio tracks is not implemented"; | |
miu
2015/09/09 00:07:10
s/Recording audio/Recording no video/
mcasas
2015/09/09 00:22:15
Done.
| |
75 return false; | |
76 } | |
77 // TODO(mcasas): The muxer API supports only one video track. Extend it to | |
78 // several video tracks, see http://crbug.com/528523. | |
79 LOG_IF(WARNING, video_tracks.size() > 1u) << "Recording multiple video" | |
80 << " tracks is not implemented. Only recording first video track."; | |
81 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | |
82 if (video_track.isNull()) | |
83 return false; | |
84 | |
85 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | |
86 base::Bind(&media::WebmMuxer::OnEncodedVideo, | |
87 base::Unretained(webm_muxer_.get())); | |
88 | |
89 video_recorders_.push_back(new VideoTrackRecorder(video_track, | |
90 on_encoded_video_cb)); | |
91 | |
92 recording_ = true; | |
93 return true; | |
94 } | |
95 | |
96 void MediaRecorderHandler::stop() { | |
97 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
98 DCHECK(recording_); | |
99 | |
100 recording_ = false; | |
101 video_recorders_.clear(); | |
102 webm_muxer_.reset(NULL); | |
103 } | |
104 | |
105 void MediaRecorderHandler::pause() { | |
106 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
107 DCHECK(recording_); | |
108 recording_ = false; | |
109 NOTIMPLEMENTED(); | |
110 } | |
111 | |
112 void MediaRecorderHandler::resume() { | |
113 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
114 DCHECK(!recording_); | |
115 recording_ = true; | |
116 NOTIMPLEMENTED(); | |
117 } | |
118 | |
119 void MediaRecorderHandler::WriteData(const base::StringPiece& data) { | |
120 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | |
121 client_->writeData(data.data(), data.size(), false /* lastInSlice */); | |
122 } | |
123 | |
124 void MediaRecorderHandler::OnVideoFrameForTesting( | |
125 const scoped_refptr<media::VideoFrame>& frame, | |
126 const base::TimeTicks& timestamp) { | |
127 for (auto* recorder : video_recorders_) | |
128 recorder->OnVideoFrameForTesting(frame, timestamp); | |
129 } | |
130 | |
131 } // namespace content | |
OLD | NEW |