OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/cast/video_sender/external_video_encoder.h" | 5 #include "media/cast/video_sender/external_video_encoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 215 } |
216 if (key_frame) | 216 if (key_frame) |
217 key_frame_encountered_ = true; | 217 key_frame_encountered_ = true; |
218 if (!key_frame_encountered_) { | 218 if (!key_frame_encountered_) { |
219 // Do not send video until we have encountered the first key frame. | 219 // Do not send video until we have encountered the first key frame. |
220 // Save the bitstream buffer in |stream_header_| to be sent later along | 220 // Save the bitstream buffer in |stream_header_| to be sent later along |
221 // with the first key frame. | 221 // with the first key frame. |
222 stream_header_.append(static_cast<const char*>(output_buffer->memory()), | 222 stream_header_.append(static_cast<const char*>(output_buffer->memory()), |
223 payload_size); | 223 payload_size); |
224 } else if (!encoded_frame_data_storage_.empty()) { | 224 } else if (!encoded_frame_data_storage_.empty()) { |
225 scoped_ptr<transport::EncodedVideoFrame> encoded_frame( | 225 scoped_ptr<transport::EncodedFrame> encoded_frame( |
226 new transport::EncodedVideoFrame()); | 226 new transport::EncodedFrame()); |
227 | 227 encoded_frame->relationship = key_frame ? transport::EncodedFrame::KEY : |
228 encoded_frame->codec = codec_; | 228 transport::EncodedFrame::DEPENDENT; |
229 encoded_frame->key_frame = key_frame; | 229 encoded_frame->frame_id = ++last_encoded_frame_id_; |
230 encoded_frame->last_referenced_frame_id = last_encoded_frame_id_; | 230 encoded_frame->referenced_frame_id = encoded_frame->frame_id; |
231 last_encoded_frame_id_++; | 231 if (!key_frame) |
hubbe
2014/05/16 17:13:20
I think
if (key_frame)
encoded_frame->reference
miu
2014/05/16 21:28:46
Done.
| |
232 encoded_frame->frame_id = last_encoded_frame_id_; | 232 --encoded_frame->referenced_frame_id; |
233 encoded_frame->rtp_timestamp = GetVideoRtpTimestamp( | 233 encoded_frame->reference_time = |
234 encoded_frame_data_storage_.front().capture_time); | 234 encoded_frame_data_storage_.front().capture_time; |
235 if (key_frame) { | 235 encoded_frame->rtp_timestamp = |
236 // Self referenced. | 236 GetVideoRtpTimestamp(encoded_frame->reference_time); |
237 encoded_frame->last_referenced_frame_id = encoded_frame->frame_id; | |
238 } | |
239 | |
240 if (!stream_header_.empty()) { | 237 if (!stream_header_.empty()) { |
241 encoded_frame->data = stream_header_; | 238 encoded_frame->data = stream_header_; |
242 stream_header_.clear(); | 239 stream_header_.clear(); |
243 } | 240 } |
244 encoded_frame->data.append( | 241 encoded_frame->data.append( |
245 static_cast<const char*>(output_buffer->memory()), payload_size); | 242 static_cast<const char*>(output_buffer->memory()), payload_size); |
246 | 243 |
247 cast_environment_->PostTask( | 244 cast_environment_->PostTask( |
248 CastEnvironment::MAIN, | 245 CastEnvironment::MAIN, |
249 FROM_HERE, | 246 FROM_HERE, |
250 base::Bind(&LogFrameEncodedEvent, | 247 base::Bind(&LogFrameEncodedEvent, |
251 cast_environment_, | 248 cast_environment_, |
252 cast_environment_->Clock()->NowTicks(), | 249 cast_environment_->Clock()->NowTicks(), |
253 encoded_frame->rtp_timestamp, | 250 encoded_frame->rtp_timestamp, |
254 encoded_frame->frame_id)); | 251 encoded_frame->frame_id)); |
255 | 252 |
256 cast_environment_->PostTask( | 253 cast_environment_->PostTask( |
257 CastEnvironment::MAIN, | 254 CastEnvironment::MAIN, |
258 FROM_HERE, | 255 FROM_HERE, |
259 base::Bind(encoded_frame_data_storage_.front().frame_encoded_callback, | 256 base::Bind(encoded_frame_data_storage_.front().frame_encoded_callback, |
260 base::Passed(&encoded_frame), | 257 base::Passed(&encoded_frame))); |
261 encoded_frame_data_storage_.front().capture_time)); | |
262 | 258 |
263 encoded_frame_data_storage_.pop_front(); | 259 encoded_frame_data_storage_.pop_front(); |
264 } else { | 260 } else { |
265 VLOG(1) << "BitstreamBufferReady(): no encoded frame data available"; | 261 VLOG(1) << "BitstreamBufferReady(): no encoded frame data available"; |
266 } | 262 } |
267 | 263 |
268 // We need to re-add the output buffer to the encoder after we are done | 264 // We need to re-add the output buffer to the encoder after we are done |
269 // with it. | 265 // with it. |
270 video_encode_accelerator_->UseOutputBitstreamBuffer(media::BitstreamBuffer( | 266 video_encode_accelerator_->UseOutputBitstreamBuffer(media::BitstreamBuffer( |
271 bitstream_buffer_id, | 267 bitstream_buffer_id, |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 // Do nothing not supported. | 438 // Do nothing not supported. |
443 } | 439 } |
444 | 440 |
445 int ExternalVideoEncoder::NumberOfSkippedFrames() const { | 441 int ExternalVideoEncoder::NumberOfSkippedFrames() const { |
446 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 442 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
447 return skip_count_; | 443 return skip_count_; |
448 } | 444 } |
449 | 445 |
450 } // namespace cast | 446 } // namespace cast |
451 } // namespace media | 447 } // namespace media |
OLD | NEW |