| 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 |
| 228 encoded_frame->codec = codec_; | 228 encoded_frame->frame_id = ++last_encoded_frame_id_; |
| 229 encoded_frame->key_frame = key_frame; | 229 encoded_frame->base_frame_id = encoded_frame->frame_id; |
| 230 encoded_frame->last_referenced_frame_id = last_encoded_frame_id_; | 230 if (!key_frame) |
| 231 last_encoded_frame_id_++; | 231 --encoded_frame->base_frame_id; |
| 232 encoded_frame->frame_id = last_encoded_frame_id_; | 232 encoded_frame->reference_time = |
| 233 encoded_frame->rtp_timestamp = GetVideoRtpTimestamp( | 233 encoded_frame_data_storage_.front().capture_time; |
| 234 encoded_frame_data_storage_.front().capture_time); | 234 encoded_frame->rtp_timestamp = |
| 235 if (key_frame) { | 235 GetVideoRtpTimestamp(encoded_frame->reference_time); |
| 236 // Self referenced. | |
| 237 encoded_frame->last_referenced_frame_id = encoded_frame->frame_id; | |
| 238 } | |
| 239 | |
| 240 if (!stream_header_.empty()) { | 236 if (!stream_header_.empty()) { |
| 241 encoded_frame->data = stream_header_; | 237 encoded_frame->data = stream_header_; |
| 242 stream_header_.clear(); | 238 stream_header_.clear(); |
| 243 } | 239 } |
| 244 encoded_frame->data.append( | 240 encoded_frame->data.append( |
| 245 static_cast<const char*>(output_buffer->memory()), payload_size); | 241 static_cast<const char*>(output_buffer->memory()), payload_size); |
| 246 | 242 |
| 247 cast_environment_->PostTask( | 243 cast_environment_->PostTask( |
| 248 CastEnvironment::MAIN, | 244 CastEnvironment::MAIN, |
| 249 FROM_HERE, | 245 FROM_HERE, |
| 250 base::Bind(&LogFrameEncodedEvent, | 246 base::Bind(&LogFrameEncodedEvent, |
| 251 cast_environment_, | 247 cast_environment_, |
| 252 cast_environment_->Clock()->NowTicks(), | 248 cast_environment_->Clock()->NowTicks(), |
| 253 encoded_frame->rtp_timestamp, | 249 encoded_frame->rtp_timestamp, |
| 254 encoded_frame->frame_id)); | 250 encoded_frame->frame_id)); |
| 255 | 251 |
| 256 cast_environment_->PostTask( | 252 cast_environment_->PostTask( |
| 257 CastEnvironment::MAIN, | 253 CastEnvironment::MAIN, |
| 258 FROM_HERE, | 254 FROM_HERE, |
| 259 base::Bind(encoded_frame_data_storage_.front().frame_encoded_callback, | 255 base::Bind(encoded_frame_data_storage_.front().frame_encoded_callback, |
| 260 base::Passed(&encoded_frame), | 256 base::Passed(&encoded_frame))); |
| 261 encoded_frame_data_storage_.front().capture_time)); | |
| 262 | 257 |
| 263 encoded_frame_data_storage_.pop_front(); | 258 encoded_frame_data_storage_.pop_front(); |
| 264 } else { | 259 } else { |
| 265 VLOG(1) << "BitstreamBufferReady(): no encoded frame data available"; | 260 VLOG(1) << "BitstreamBufferReady(): no encoded frame data available"; |
| 266 } | 261 } |
| 267 | 262 |
| 268 // We need to re-add the output buffer to the encoder after we are done | 263 // We need to re-add the output buffer to the encoder after we are done |
| 269 // with it. | 264 // with it. |
| 270 video_encode_accelerator_->UseOutputBitstreamBuffer(media::BitstreamBuffer( | 265 video_encode_accelerator_->UseOutputBitstreamBuffer(media::BitstreamBuffer( |
| 271 bitstream_buffer_id, | 266 bitstream_buffer_id, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 // Do nothing not supported. | 437 // Do nothing not supported. |
| 443 } | 438 } |
| 444 | 439 |
| 445 int ExternalVideoEncoder::NumberOfSkippedFrames() const { | 440 int ExternalVideoEncoder::NumberOfSkippedFrames() const { |
| 446 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 441 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 447 return skip_count_; | 442 return skip_count_; |
| 448 } | 443 } |
| 449 | 444 |
| 450 } // namespace cast | 445 } // namespace cast |
| 451 } // namespace media | 446 } // namespace media |
| OLD | NEW |