| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 394 } |
| 395 | 395 |
| 396 // VideoFrameStream ensures no kConfigChanged is passed to VideoDecoders. | 396 // VideoFrameStream ensures no kConfigChanged is passed to VideoDecoders. |
| 397 DCHECK_EQ(status, DemuxerStream::kOk) << status; | 397 DCHECK_EQ(status, DemuxerStream::kOk) << status; |
| 398 | 398 |
| 399 if (!vda_) { | 399 if (!vda_) { |
| 400 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEmptyFrame()); | 400 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEmptyFrame()); |
| 401 return; | 401 return; |
| 402 } | 402 } |
| 403 | 403 |
| 404 if (buffer->IsEndOfStream()) { | 404 if (buffer->is_end_of_stream()) { |
| 405 if (state_ == kNormal) { | 405 if (state_ == kNormal) { |
| 406 state_ = kDrainingDecoder; | 406 state_ = kDrainingDecoder; |
| 407 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 407 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 408 &VideoDecodeAccelerator::Flush, weak_vda_)); | 408 &VideoDecodeAccelerator::Flush, weak_vda_)); |
| 409 } | 409 } |
| 410 return; | 410 return; |
| 411 } | 411 } |
| 412 | 412 |
| 413 if (!pending_reset_cb_.is_null()) | 413 if (!pending_reset_cb_.is_null()) |
| 414 return; | 414 return; |
| 415 | 415 |
| 416 size_t size = buffer->GetDataSize(); | 416 size_t size = buffer->get_data_size(); |
| 417 SHMBuffer* shm_buffer = GetSHM(size); | 417 SHMBuffer* shm_buffer = GetSHM(size); |
| 418 if (!shm_buffer) | 418 if (!shm_buffer) |
| 419 return; | 419 return; |
| 420 | 420 |
| 421 memcpy(shm_buffer->shm->memory(), buffer->GetData(), size); | 421 memcpy(shm_buffer->shm->memory(), buffer->get_data(), size); |
| 422 BitstreamBuffer bitstream_buffer( | 422 BitstreamBuffer bitstream_buffer( |
| 423 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size); | 423 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size); |
| 424 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 424 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
| 425 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; | 425 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; |
| 426 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( | 426 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( |
| 427 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; | 427 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; |
| 428 DCHECK(inserted); | 428 DCHECK(inserted); |
| 429 RecordBufferData(bitstream_buffer, *buffer.get()); | 429 RecordBufferData(bitstream_buffer, *buffer.get()); |
| 430 | 430 |
| 431 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 431 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 432 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); | 432 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); |
| 433 | 433 |
| 434 if (CanMoreDecodeWorkBeDone()) { | 434 if (CanMoreDecodeWorkBeDone()) { |
| 435 // Force post here to prevent reentrancy into DemuxerStream. | 435 // Force post here to prevent reentrancy into DemuxerStream. |
| 436 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 436 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 437 &GpuVideoDecoder::EnsureDemuxOrDecode, weak_this_)); | 437 &GpuVideoDecoder::EnsureDemuxOrDecode, weak_this_)); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 void GpuVideoDecoder::RecordBufferData( | 441 void GpuVideoDecoder::RecordBufferData( |
| 442 const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer) { | 442 const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer) { |
| 443 input_buffer_data_.push_front(BufferData( | 443 input_buffer_data_.push_front(BufferData( |
| 444 bitstream_buffer.id(), buffer.GetTimestamp(), | 444 bitstream_buffer.id(), buffer.get_timestamp(), |
| 445 demuxer_stream_->video_decoder_config().visible_rect(), | 445 demuxer_stream_->video_decoder_config().visible_rect(), |
| 446 demuxer_stream_->video_decoder_config().natural_size())); | 446 demuxer_stream_->video_decoder_config().natural_size())); |
| 447 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but | 447 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but |
| 448 // that's too small for some pathological B-frame test videos. The cost of | 448 // that's too small for some pathological B-frame test videos. The cost of |
| 449 // using too-high a value is low (192 bits per extra slot). | 449 // using too-high a value is low (192 bits per extra slot). |
| 450 static const size_t kMaxInputBufferDataSize = 128; | 450 static const size_t kMaxInputBufferDataSize = 128; |
| 451 // Pop from the back of the list, because that's the oldest and least likely | 451 // Pop from the back of the list, because that's the oldest and least likely |
| 452 // to be useful in the future data. | 452 // to be useful in the future data. |
| 453 if (input_buffer_data_.size() > kMaxInputBufferDataSize) | 453 if (input_buffer_data_.size() > kMaxInputBufferDataSize) |
| 454 input_buffer_data_.pop_back(); | 454 input_buffer_data_.pop_back(); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 std::map<int32, BufferPair>::iterator it = | 667 std::map<int32, BufferPair>::iterator it = |
| 668 bitstream_buffers_in_decoder_.find(id); | 668 bitstream_buffers_in_decoder_.find(id); |
| 669 if (it == bitstream_buffers_in_decoder_.end()) { | 669 if (it == bitstream_buffers_in_decoder_.end()) { |
| 670 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 670 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 671 NOTREACHED() << "Missing bitstream buffer: " << id; | 671 NOTREACHED() << "Missing bitstream buffer: " << id; |
| 672 return; | 672 return; |
| 673 } | 673 } |
| 674 | 674 |
| 675 PutSHM(it->second.shm_buffer); | 675 PutSHM(it->second.shm_buffer); |
| 676 const scoped_refptr<DecoderBuffer>& buffer = it->second.buffer; | 676 const scoped_refptr<DecoderBuffer>& buffer = it->second.buffer; |
| 677 if (buffer->GetDataSize()) { | 677 if (buffer->get_data_size()) { |
| 678 PipelineStatistics statistics; | 678 PipelineStatistics statistics; |
| 679 statistics.video_bytes_decoded = buffer->GetDataSize(); | 679 statistics.video_bytes_decoded = buffer->get_data_size(); |
| 680 statistics_cb_.Run(statistics); | 680 statistics_cb_.Run(statistics); |
| 681 } | 681 } |
| 682 bitstream_buffers_in_decoder_.erase(it); | 682 bitstream_buffers_in_decoder_.erase(it); |
| 683 | 683 |
| 684 if (pending_reset_cb_.is_null() && state_ != kDrainingDecoder && | 684 if (pending_reset_cb_.is_null() && state_ != kDrainingDecoder && |
| 685 CanMoreDecodeWorkBeDone()) { | 685 CanMoreDecodeWorkBeDone()) { |
| 686 EnsureDemuxOrDecode(); | 686 EnsureDemuxOrDecode(); |
| 687 } | 687 } |
| 688 } | 688 } |
| 689 | 689 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 752 |
| 753 state_ = kError; | 753 state_ = kError; |
| 754 | 754 |
| 755 if (!pending_read_cb_.is_null()) { | 755 if (!pending_read_cb_.is_null()) { |
| 756 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); | 756 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); |
| 757 return; | 757 return; |
| 758 } | 758 } |
| 759 } | 759 } |
| 760 | 760 |
| 761 } // namespace media | 761 } // namespace media |
| OLD | NEW |