Chromium Code Reviews| 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 #include "content/renderer/media/media_recorder_handler.h" | 5 #include "content/renderer/media/media_recorder_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 << "Recording multiple video tracks is not implemented. " | 192 << "Recording multiple video tracks is not implemented. " |
| 193 << "Only recording first video track."; | 193 << "Only recording first video track."; |
| 194 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; | 194 const blink::WebMediaStreamTrack& video_track = video_tracks[0]; |
| 195 if (video_track.isNull()) | 195 if (video_track.isNull()) |
| 196 return false; | 196 return false; |
| 197 | 197 |
| 198 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = | 198 const VideoTrackRecorder::OnEncodedVideoCB on_encoded_video_cb = |
| 199 media::BindToCurrentLoop(base::Bind( | 199 media::BindToCurrentLoop(base::Bind( |
| 200 &MediaRecorderHandler::OnEncodedVideo, weak_factory_.GetWeakPtr())); | 200 &MediaRecorderHandler::OnEncodedVideo, weak_factory_.GetWeakPtr())); |
| 201 | 201 |
| 202 video_recorders_.push_back(new VideoTrackRecorder( | 202 video_recorders_.emplace_back(new VideoTrackRecorder( |
| 203 codec_id_, video_track, on_encoded_video_cb, video_bits_per_second_)); | 203 codec_id_, video_track, on_encoded_video_cb, video_bits_per_second_)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 if (use_audio_tracks) { | 206 if (use_audio_tracks) { |
| 207 // TODO(ajose): The muxer API supports only one audio track. Extend it to | 207 // TODO(ajose): The muxer API supports only one audio track. Extend it to |
| 208 // several tracks. | 208 // several tracks. |
| 209 LOG_IF(WARNING, audio_tracks.size() > 1u) | 209 LOG_IF(WARNING, audio_tracks.size() > 1u) |
| 210 << "Recording multiple audio" | 210 << "Recording multiple audio" |
| 211 << " tracks is not implemented. Only recording first audio track."; | 211 << " tracks is not implemented. Only recording first audio track."; |
| 212 const blink::WebMediaStreamTrack& audio_track = audio_tracks[0]; | 212 const blink::WebMediaStreamTrack& audio_track = audio_tracks[0]; |
| 213 if (audio_track.isNull()) | 213 if (audio_track.isNull()) |
| 214 return false; | 214 return false; |
| 215 | 215 |
| 216 const AudioTrackRecorder::OnEncodedAudioCB on_encoded_audio_cb = | 216 const AudioTrackRecorder::OnEncodedAudioCB on_encoded_audio_cb = |
| 217 media::BindToCurrentLoop(base::Bind( | 217 media::BindToCurrentLoop(base::Bind( |
| 218 &MediaRecorderHandler::OnEncodedAudio, weak_factory_.GetWeakPtr())); | 218 &MediaRecorderHandler::OnEncodedAudio, weak_factory_.GetWeakPtr())); |
| 219 | 219 |
| 220 audio_recorders_.push_back(new AudioTrackRecorder( | 220 audio_recorders_.emplace_back(new AudioTrackRecorder( |
| 221 audio_track, on_encoded_audio_cb, audio_bits_per_second_)); | 221 audio_track, on_encoded_audio_cb, audio_bits_per_second_)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 recording_ = true; | 224 recording_ = true; |
| 225 return true; | 225 return true; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void MediaRecorderHandler::stop() { | 228 void MediaRecorderHandler::stop() { |
| 229 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 229 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 230 // Don't check |recording_| since we can go directly from pause() to stop(). | 230 // Don't check |recording_| since we can go directly from pause() to stop(). |
| 231 | 231 |
| 232 recording_ = false; | 232 recording_ = false; |
| 233 timeslice_ = TimeDelta::FromMilliseconds(0); | 233 timeslice_ = TimeDelta::FromMilliseconds(0); |
| 234 video_recorders_.clear(); | 234 video_recorders_.clear(); |
| 235 audio_recorders_.clear(); | 235 audio_recorders_.clear(); |
| 236 webm_muxer_.reset(); | 236 webm_muxer_.reset(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void MediaRecorderHandler::pause() { | 239 void MediaRecorderHandler::pause() { |
| 240 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 240 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 241 DCHECK(recording_); | 241 DCHECK(recording_); |
| 242 recording_ = false; | 242 recording_ = false; |
| 243 for (auto* video_recorder : video_recorders_) | 243 for (auto& video_recorder : video_recorders_) |
|
mcasas
2016/09/08 16:21:08
const auto&, here and elsewhere.
| |
| 244 video_recorder->Pause(); | 244 video_recorder->Pause(); |
| 245 for (auto* audio_recorder : audio_recorders_) | 245 for (auto& audio_recorder : audio_recorders_) |
| 246 audio_recorder->Pause(); | 246 audio_recorder->Pause(); |
| 247 webm_muxer_->Pause(); | 247 webm_muxer_->Pause(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void MediaRecorderHandler::resume() { | 250 void MediaRecorderHandler::resume() { |
| 251 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 251 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 252 DCHECK(!recording_); | 252 DCHECK(!recording_); |
| 253 recording_ = true; | 253 recording_ = true; |
| 254 for (auto* video_recorder : video_recorders_) | 254 for (auto& video_recorder : video_recorders_) |
| 255 video_recorder->Resume(); | 255 video_recorder->Resume(); |
| 256 for (auto* audio_recorder : audio_recorders_) | 256 for (auto& audio_recorder : audio_recorders_) |
| 257 audio_recorder->Resume(); | 257 audio_recorder->Resume(); |
| 258 webm_muxer_->Resume(); | 258 webm_muxer_->Resume(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void MediaRecorderHandler::OnEncodedVideo( | 261 void MediaRecorderHandler::OnEncodedVideo( |
| 262 const scoped_refptr<media::VideoFrame>& video_frame, | 262 const scoped_refptr<media::VideoFrame>& video_frame, |
| 263 std::unique_ptr<std::string> encoded_data, | 263 std::unique_ptr<std::string> encoded_data, |
| 264 TimeTicks timestamp, | 264 TimeTicks timestamp, |
| 265 bool is_key_frame) { | 265 bool is_key_frame) { |
| 266 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 266 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 291 const bool last_in_slice = now > slice_origin_timestamp_ + timeslice_; | 291 const bool last_in_slice = now > slice_origin_timestamp_ + timeslice_; |
| 292 DVLOG_IF(1, last_in_slice) << "Slice finished @ " << now; | 292 DVLOG_IF(1, last_in_slice) << "Slice finished @ " << now; |
| 293 if (last_in_slice) | 293 if (last_in_slice) |
| 294 slice_origin_timestamp_ = now; | 294 slice_origin_timestamp_ = now; |
| 295 client_->writeData(data.data(), data.length(), last_in_slice); | 295 client_->writeData(data.data(), data.length(), last_in_slice); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void MediaRecorderHandler::OnVideoFrameForTesting( | 298 void MediaRecorderHandler::OnVideoFrameForTesting( |
| 299 const scoped_refptr<media::VideoFrame>& frame, | 299 const scoped_refptr<media::VideoFrame>& frame, |
| 300 const TimeTicks& timestamp) { | 300 const TimeTicks& timestamp) { |
| 301 for (auto* recorder : video_recorders_) | 301 for (auto& recorder : video_recorders_) |
| 302 recorder->OnVideoFrameForTesting(frame, timestamp); | 302 recorder->OnVideoFrameForTesting(frame, timestamp); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void MediaRecorderHandler::OnAudioBusForTesting( | 305 void MediaRecorderHandler::OnAudioBusForTesting( |
| 306 const media::AudioBus& audio_bus, | 306 const media::AudioBus& audio_bus, |
| 307 const base::TimeTicks& timestamp) { | 307 const base::TimeTicks& timestamp) { |
| 308 for (auto* recorder : audio_recorders_) | 308 for (auto& recorder : audio_recorders_) |
| 309 recorder->OnData(audio_bus, timestamp); | 309 recorder->OnData(audio_bus, timestamp); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void MediaRecorderHandler::SetAudioFormatForTesting( | 312 void MediaRecorderHandler::SetAudioFormatForTesting( |
| 313 const media::AudioParameters& params) { | 313 const media::AudioParameters& params) { |
| 314 for (auto* recorder : audio_recorders_) | 314 for (auto& recorder : audio_recorders_) |
| 315 recorder->OnSetFormat(params); | 315 recorder->OnSetFormat(params); |
| 316 } | 316 } |
| 317 | 317 |
| 318 } // namespace content | 318 } // namespace content |
| OLD | NEW |