| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 | 101 |
| 102 void GpuVideoDecoder::Stop(const base::Closure& closure) { | 102 void GpuVideoDecoder::Stop(const base::Closure& closure) { |
| 103 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 103 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 104 if (vda_.get()) | 104 if (vda_.get()) |
| 105 DestroyVDA(); | 105 DestroyVDA(); |
| 106 if (!pending_read_cb_.is_null()) | 106 if (!pending_read_cb_.is_null()) |
| 107 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEmptyFrame()); | 107 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEmptyFrame()); |
| 108 if (!pending_reset_cb_.is_null()) | 108 if (!pending_reset_cb_.is_null()) |
| 109 base::ResetAndReturn(&pending_reset_cb_).Run(); | 109 base::ResetAndReturn(&pending_reset_cb_).Run(); |
| 110 demuxer_stream_ = NULL; |
| 110 BindToCurrentLoop(closure).Run(); | 111 BindToCurrentLoop(closure).Run(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void GpuVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream, | 114 void GpuVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream, |
| 114 const PipelineStatusCB& orig_status_cb, | 115 const PipelineStatusCB& orig_status_cb, |
| 115 const StatisticsCB& statistics_cb) { | 116 const StatisticsCB& statistics_cb) { |
| 116 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 117 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 117 PipelineStatusCB status_cb = CreateUMAReportingPipelineCB( | 118 PipelineStatusCB status_cb = CreateUMAReportingPipelineCB( |
| 118 "Media.GpuVideoDecoderInitializeStatus", | 119 "Media.GpuVideoDecoderInitializeStatus", |
| 119 BindToCurrentLoop(orig_status_cb)); | 120 BindToCurrentLoop(orig_status_cb)); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 297 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
| 297 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; | 298 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; |
| 298 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( | 299 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( |
| 299 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; | 300 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; |
| 300 DCHECK(inserted); | 301 DCHECK(inserted); |
| 301 RecordBufferData(bitstream_buffer, *buffer); | 302 RecordBufferData(bitstream_buffer, *buffer); |
| 302 | 303 |
| 303 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 304 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 304 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); | 305 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); |
| 305 | 306 |
| 306 if (CanMoreDecodeWorkBeDone()) | 307 if (CanMoreDecodeWorkBeDone()) { |
| 307 EnsureDemuxOrDecode(); | 308 // Force post here to prevent reentrancy into DemuxerStream. |
| 309 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 310 &GpuVideoDecoder::EnsureDemuxOrDecode, this)); |
| 311 } |
| 308 } | 312 } |
| 309 | 313 |
| 310 void GpuVideoDecoder::RecordBufferData( | 314 void GpuVideoDecoder::RecordBufferData( |
| 311 const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer) { | 315 const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer) { |
| 312 input_buffer_data_.push_front(BufferData( | 316 input_buffer_data_.push_front(BufferData( |
| 313 bitstream_buffer.id(), buffer.GetTimestamp(), | 317 bitstream_buffer.id(), buffer.GetTimestamp(), |
| 314 demuxer_stream_->video_decoder_config().visible_rect(), | 318 demuxer_stream_->video_decoder_config().visible_rect(), |
| 315 demuxer_stream_->video_decoder_config().natural_size())); | 319 demuxer_stream_->video_decoder_config().natural_size())); |
| 316 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but | 320 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but |
| 317 // that's too small for some pathological B-frame test videos. The cost of | 321 // that's too small for some pathological B-frame test videos. The cost of |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 it != bitstream_buffers_in_decoder_.end(); ++it) { | 548 it != bitstream_buffers_in_decoder_.end(); ++it) { |
| 545 it->second.shm_buffer->shm->Close(); | 549 it->second.shm_buffer->shm->Close(); |
| 546 } | 550 } |
| 547 bitstream_buffers_in_decoder_.clear(); | 551 bitstream_buffers_in_decoder_.clear(); |
| 548 | 552 |
| 549 DestroyTextures(); | 553 DestroyTextures(); |
| 550 } | 554 } |
| 551 | 555 |
| 552 void GpuVideoDecoder::EnsureDemuxOrDecode() { | 556 void GpuVideoDecoder::EnsureDemuxOrDecode() { |
| 553 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 557 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 554 if (demuxer_read_in_progress_) | 558 |
| 559 // The second condition can happen during the tear-down process. |
| 560 // GpuVideoDecoder::Stop() returns the |pending_read_cb_| immediately without |
| 561 // waiting for the demuxer read to be returned. Therefore, this function could |
| 562 // be called even after the decoder has been stopped. |
| 563 if (demuxer_read_in_progress_ || !demuxer_stream_) |
| 555 return; | 564 return; |
| 565 |
| 556 demuxer_read_in_progress_ = true; | 566 demuxer_read_in_progress_ = true; |
| 557 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 567 demuxer_stream_->Read(base::Bind( |
| 558 &DemuxerStream::Read, demuxer_stream_.get(), | 568 &GpuVideoDecoder::RequestBufferDecode, this)); |
| 559 base::Bind(&GpuVideoDecoder::RequestBufferDecode, this))); | |
| 560 } | 569 } |
| 561 | 570 |
| 562 void GpuVideoDecoder::NotifyFlushDone() { | 571 void GpuVideoDecoder::NotifyFlushDone() { |
| 563 if (!gvd_loop_proxy_->BelongsToCurrentThread()) { | 572 if (!gvd_loop_proxy_->BelongsToCurrentThread()) { |
| 564 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 573 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 565 &GpuVideoDecoder::NotifyFlushDone, this)); | 574 &GpuVideoDecoder::NotifyFlushDone, this)); |
| 566 return; | 575 return; |
| 567 } | 576 } |
| 568 DCHECK_EQ(state_, kDrainingDecoder); | 577 DCHECK_EQ(state_, kDrainingDecoder); |
| 569 state_ = kDecoderDrained; | 578 state_ = kDecoderDrained; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 613 |
| 605 error_occured_ = true; | 614 error_occured_ = true; |
| 606 | 615 |
| 607 if (!pending_read_cb_.is_null()) { | 616 if (!pending_read_cb_.is_null()) { |
| 608 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); | 617 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); |
| 609 return; | 618 return; |
| 610 } | 619 } |
| 611 } | 620 } |
| 612 | 621 |
| 613 } // namespace media | 622 } // namespace media |
| OLD | NEW |