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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/renderer/media/video_track_recorder.h" | 10 #include "content/renderer/media/video_track_recorder.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool MediaRecorderHandler::start(int timeslice) { | 73 bool MediaRecorderHandler::start(int timeslice) { |
| 74 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 74 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 75 DCHECK(!recording_); | 75 DCHECK(!recording_); |
| 76 DCHECK(!media_stream_.isNull()); | 76 DCHECK(!media_stream_.isNull()); |
| 77 DCHECK(!webm_muxer_); | 77 DCHECK(!webm_muxer_); |
| 78 DCHECK(timeslice_.is_zero()); | 78 DCHECK(timeslice_.is_zero()); |
| 79 | 79 |
| 80 timeslice_ = TimeDelta::FromMilliseconds(timeslice); | 80 timeslice_ = TimeDelta::FromMilliseconds(timeslice); |
| 81 slice_origin_timestamp_ = TimeTicks::Now(); | 81 slice_origin_timestamp_ = TimeTicks::Now(); |
|
xhwang
2015/11/02 18:11:51
Move these two lines to below l.83 as well.
Julien Isorce Samsung
2015/11/03 16:02:27
ok, I see it will still work since ::start and ::W
| |
| 82 | 82 |
| 83 #if !defined(MEDIA_DISABLE_LIBWEBM) | |
|
xhwang
2015/11/02 18:11:51
+mcasas: shouldn't we exclude media_recorder_hande
Julien Isorce Samsung
2015/11/03 16:02:27
I'll let mcasas decide but I think not disabling m
| |
| 83 webm_muxer_.reset( | 84 webm_muxer_.reset( |
|
xhwang
2015/11/02 18:11:51
Do you need to fix the header file as well?
Julien Isorce Samsung
2015/11/03 16:02:27
Yes I will add the guard. Thx
| |
| 84 new media::WebmMuxer(use_vp9_ ? media::kCodecVP9 : media::kCodecVP8, | 85 new media::WebmMuxer(use_vp9_ ? media::kCodecVP9 : media::kCodecVP8, |
| 85 base::Bind(&MediaRecorderHandler::WriteData, | 86 base::Bind(&MediaRecorderHandler::WriteData, |
| 86 weak_factory_.GetWeakPtr()))); | 87 weak_factory_.GetWeakPtr()))); |
| 88 #else | |
| 89 return false; | |
| 90 #endif | |
| 87 | 91 |
| 88 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 92 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 89 media_stream_.videoTracks(video_tracks); | 93 media_stream_.videoTracks(video_tracks); |
| 90 | 94 |
| 91 if (video_tracks.isEmpty()) { | 95 if (video_tracks.isEmpty()) { |
| 92 // TODO(mcasas): Add audio_tracks and update the code in this function | 96 // TODO(mcasas): Add audio_tracks and update the code in this function |
| 93 // correspondingly, see http://crbug.com/528519. As of now, only video | 97 // correspondingly, see http://crbug.com/528519. As of now, only video |
| 94 // tracks are supported. | 98 // tracks are supported. |
| 95 LOG(WARNING) << "Recording no video tracks is not implemented"; | 99 LOG(WARNING) << "Recording no video tracks is not implemented"; |
| 96 return false; | 100 return false; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 } | 146 } |
| 143 | 147 |
| 144 void MediaRecorderHandler::OnEncodedVideo( | 148 void MediaRecorderHandler::OnEncodedVideo( |
| 145 const scoped_refptr<media::VideoFrame>& video_frame, | 149 const scoped_refptr<media::VideoFrame>& video_frame, |
| 146 scoped_ptr<std::string> encoded_data, | 150 scoped_ptr<std::string> encoded_data, |
| 147 TimeTicks timestamp, | 151 TimeTicks timestamp, |
| 148 bool is_key_frame) { | 152 bool is_key_frame) { |
| 149 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 153 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 150 if (!webm_muxer_) | 154 if (!webm_muxer_) |
| 151 return; | 155 return; |
| 156 #if !defined(MEDIA_DISABLE_LIBWEBM) | |
| 152 webm_muxer_->OnEncodedVideo(video_frame, encoded_data.Pass(), timestamp, | 157 webm_muxer_->OnEncodedVideo(video_frame, encoded_data.Pass(), timestamp, |
| 153 is_key_frame); | 158 is_key_frame); |
| 159 #endif | |
| 154 } | 160 } |
| 155 | 161 |
| 156 void MediaRecorderHandler::WriteData(base::StringPiece data) { | 162 void MediaRecorderHandler::WriteData(base::StringPiece data) { |
| 157 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 163 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 158 | 164 |
| 159 // Non-buffered mode does not need to check timestamps. | 165 // Non-buffered mode does not need to check timestamps. |
| 160 if (timeslice_.is_zero()) { | 166 if (timeslice_.is_zero()) { |
| 161 client_->writeData(data.data(), data.length(), true /* lastInSlice */); | 167 client_->writeData(data.data(), data.length(), true /* lastInSlice */); |
| 162 return; | 168 return; |
| 163 } | 169 } |
| 164 | 170 |
| 165 const TimeTicks now = TimeTicks::Now(); | 171 const TimeTicks now = TimeTicks::Now(); |
| 166 const bool last_in_slice = now > slice_origin_timestamp_ + timeslice_; | 172 const bool last_in_slice = now > slice_origin_timestamp_ + timeslice_; |
| 167 DVLOG_IF(1, last_in_slice) << "Slice finished @ " << now; | 173 DVLOG_IF(1, last_in_slice) << "Slice finished @ " << now; |
| 168 if (last_in_slice) | 174 if (last_in_slice) |
| 169 slice_origin_timestamp_ = now; | 175 slice_origin_timestamp_ = now; |
| 170 client_->writeData(data.data(), data.length(), last_in_slice); | 176 client_->writeData(data.data(), data.length(), last_in_slice); |
| 171 } | 177 } |
| 172 | 178 |
| 173 void MediaRecorderHandler::OnVideoFrameForTesting( | 179 void MediaRecorderHandler::OnVideoFrameForTesting( |
| 174 const scoped_refptr<media::VideoFrame>& frame, | 180 const scoped_refptr<media::VideoFrame>& frame, |
| 175 const TimeTicks& timestamp) { | 181 const TimeTicks& timestamp) { |
| 176 for (auto* recorder : video_recorders_) | 182 for (auto* recorder : video_recorders_) |
| 177 recorder->OnVideoFrameForTesting(frame, timestamp); | 183 recorder->OnVideoFrameForTesting(frame, timestamp); |
| 178 } | 184 } |
| 179 | 185 |
| 180 } // namespace content | 186 } // namespace content |
| OLD | NEW |