Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/rtc_video_decoder.h" | 5 #include "content/renderer/media/rtc_video_decoder.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 gfx::Size prev_frame_size = frame_size_; | 229 gfx::Size prev_frame_size = frame_size_; |
| 230 frame_size_ = new_frame_size; | 230 frame_size_ = new_frame_size; |
| 231 if (!kVDACanHandleMidstreamResize && !prev_frame_size.IsEmpty() && | 231 if (!kVDACanHandleMidstreamResize && !prev_frame_size.IsEmpty() && |
| 232 prev_frame_size != frame_size_) { | 232 prev_frame_size != frame_size_) { |
| 233 need_to_reset_for_midstream_resize = true; | 233 need_to_reset_for_midstream_resize = true; |
| 234 } | 234 } |
| 235 } else if (IsFirstBufferAfterReset(next_bitstream_buffer_id_, | 235 } else if (IsFirstBufferAfterReset(next_bitstream_buffer_id_, |
| 236 reset_bitstream_buffer_id_)) { | 236 reset_bitstream_buffer_id_)) { |
| 237 // TODO(wuchengli): VDA should handle it. Remove this when | 237 // TODO(wuchengli): VDA should handle it. Remove this when |
| 238 // http://crosbug.com/p/21913 is fixed. | 238 // http://crosbug.com/p/21913 is fixed. |
| 239 DVLOG(1) << "The first frame should be a key frame. Drop this."; | 239 DVLOG(1) << "The first frame should be a key frame. Drop this."; |
|
mcasas
2016/06/30 18:07:25
This DVLOG() goes with l.243 now.
emircan
2016/06/30 20:39:17
Done.
| |
| 240 if (vda_error_counter_) | |
| 241 ++vda_error_counter_; | |
|
mcasas
2016/06/30 18:07:25
I'd write this instead:
// If we're are in an err
emircan
2016/06/30 20:39:17
Done.
| |
| 242 | |
| 240 return WEBRTC_VIDEO_CODEC_ERROR; | 243 return WEBRTC_VIDEO_CODEC_ERROR; |
| 241 } | 244 } |
| 242 | 245 |
| 243 // Create buffer metadata. | 246 // Create buffer metadata. |
| 244 BufferData buffer_data(next_bitstream_buffer_id_, | 247 BufferData buffer_data(next_bitstream_buffer_id_, |
| 245 inputImage._timeStamp, | 248 inputImage._timeStamp, |
| 246 inputImage._length, | 249 inputImage._length, |
| 247 gfx::Rect(frame_size_)); | 250 gfx::Rect(frame_size_)); |
| 248 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 251 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
| 249 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & ID_LAST; | 252 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & ID_LAST; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 262 // Better to drop any pending buffers and start afresh to catch up faster. | 265 // Better to drop any pending buffers and start afresh to catch up faster. |
| 263 DVLOG(1) << "Exceeded maximum pending buffer count, dropping"; | 266 DVLOG(1) << "Exceeded maximum pending buffer count, dropping"; |
| 264 ClearPendingBuffers(); | 267 ClearPendingBuffers(); |
| 265 return WEBRTC_VIDEO_CODEC_ERROR; | 268 return WEBRTC_VIDEO_CODEC_ERROR; |
| 266 } | 269 } |
| 267 | 270 |
| 268 if (need_to_reset_for_midstream_resize) { | 271 if (need_to_reset_for_midstream_resize) { |
| 269 base::AutoUnlock auto_unlock(lock_); | 272 base::AutoUnlock auto_unlock(lock_); |
| 270 Release(); | 273 Release(); |
| 271 } | 274 } |
| 272 | |
| 273 TryResetVDAErrorCounter_Locked(); | |
| 274 return WEBRTC_VIDEO_CODEC_OK; | 275 return WEBRTC_VIDEO_CODEC_OK; |
| 275 } | 276 } |
| 276 | 277 |
| 277 SaveToDecodeBuffers_Locked(inputImage, std::move(shm_buffer), buffer_data); | 278 SaveToDecodeBuffers_Locked(inputImage, std::move(shm_buffer), buffer_data); |
| 278 factories_->GetTaskRunner()->PostTask( | 279 factories_->GetTaskRunner()->PostTask( |
| 279 FROM_HERE, | 280 FROM_HERE, |
| 280 base::Bind(&RTCVideoDecoder::RequestBufferDecode, | 281 base::Bind(&RTCVideoDecoder::RequestBufferDecode, |
| 281 weak_factory_.GetWeakPtr())); | 282 weak_factory_.GetWeakPtr())); |
| 282 TryResetVDAErrorCounter_Locked(); | |
| 283 return WEBRTC_VIDEO_CODEC_OK; | 283 return WEBRTC_VIDEO_CODEC_OK; |
| 284 } | 284 } |
| 285 | 285 |
| 286 int32_t RTCVideoDecoder::RegisterDecodeCompleteCallback( | 286 int32_t RTCVideoDecoder::RegisterDecodeCompleteCallback( |
| 287 webrtc::DecodedImageCallback* callback) { | 287 webrtc::DecodedImageCallback* callback) { |
| 288 DVLOG(2) << "RegisterDecodeCompleteCallback"; | 288 DVLOG(2) << "RegisterDecodeCompleteCallback"; |
| 289 DCHECK(callback); | 289 DCHECK(callback); |
| 290 base::AutoLock auto_lock(lock_); | 290 base::AutoLock auto_lock(lock_); |
| 291 decode_complete_callback_ = callback; | 291 decode_complete_callback_ = callback; |
| 292 return WEBRTC_VIDEO_CODEC_OK; | 292 return WEBRTC_VIDEO_CODEC_OK; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 437 |
| 438 // Invoke decode callback. WebRTC expects no callback after Release. | 438 // Invoke decode callback. WebRTC expects no callback after Release. |
| 439 { | 439 { |
| 440 base::AutoLock auto_lock(lock_); | 440 base::AutoLock auto_lock(lock_); |
| 441 DCHECK(decode_complete_callback_); | 441 DCHECK(decode_complete_callback_); |
| 442 if (IsBufferAfterReset(picture.bitstream_buffer_id(), | 442 if (IsBufferAfterReset(picture.bitstream_buffer_id(), |
| 443 reset_bitstream_buffer_id_)) { | 443 reset_bitstream_buffer_id_)) { |
| 444 decode_complete_callback_->Decoded(decoded_image); | 444 decode_complete_callback_->Decoded(decoded_image); |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 TryResetVDAErrorCounter(); | |
| 447 } | 448 } |
| 448 | 449 |
| 449 scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame( | 450 scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame( |
| 450 const media::Picture& picture, | 451 const media::Picture& picture, |
| 451 const media::PictureBuffer& pb, | 452 const media::PictureBuffer& pb, |
| 452 uint32_t timestamp, | 453 uint32_t timestamp, |
| 453 const gfx::Rect& visible_rect, | 454 const gfx::Rect& visible_rect, |
| 454 media::VideoPixelFormat pixel_format) { | 455 media::VideoPixelFormat pixel_format) { |
| 455 DCHECK(decoder_texture_target_); | 456 DCHECK(decoder_texture_target_); |
| 456 // Convert timestamp from 90KHz to ms. | 457 // Convert timestamp from 90KHz to ms. |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 883 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 883 } | 884 } |
| 884 | 885 |
| 885 void RTCVideoDecoder::ClearPendingBuffers() { | 886 void RTCVideoDecoder::ClearPendingBuffers() { |
| 886 // Delete WebRTC input buffers. | 887 // Delete WebRTC input buffers. |
| 887 for (const auto& pending_buffer : pending_buffers_) | 888 for (const auto& pending_buffer : pending_buffers_) |
| 888 delete[] pending_buffer.first._buffer; | 889 delete[] pending_buffer.first._buffer; |
| 889 pending_buffers_.clear(); | 890 pending_buffers_.clear(); |
| 890 } | 891 } |
| 891 | 892 |
| 892 void RTCVideoDecoder::TryResetVDAErrorCounter_Locked() { | 893 void RTCVideoDecoder::TryResetVDAErrorCounter() { |
| 893 lock_.AssertAcquired(); | 894 base::AutoLock auto_lock(lock_); |
| 894 | 895 |
| 895 if (vda_error_counter_ == 0) | 896 if (vda_error_counter_ == 0) |
| 896 return; | 897 return; |
| 897 vda_error_counter_ = 0; | 898 vda_error_counter_ = 0; |
| 898 } | 899 } |
| 899 | 900 |
| 900 } // namespace content | 901 } // namespace content |
| OLD | NEW |