| 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/filters/decoder_stream.h" | 5 #include "media/filters/decoder_stream.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 template <DemuxerStream::Type StreamType> | 329 template <DemuxerStream::Type StreamType> |
| 330 void DecoderStream<StreamType>::Decode( | 330 void DecoderStream<StreamType>::Decode( |
| 331 const scoped_refptr<DecoderBuffer>& buffer) { | 331 const scoped_refptr<DecoderBuffer>& buffer) { |
| 332 FUNCTION_DVLOG(2); | 332 FUNCTION_DVLOG(2); |
| 333 | 333 |
| 334 // We don't know if the decoder will error out on first decode yet. Save the | 334 // We don't know if the decoder will error out on first decode yet. Save the |
| 335 // buffer to feed it to the fallback decoder later if needed. | 335 // buffer to feed it to the fallback decoder later if needed. |
| 336 if (!decoded_frames_since_fallback_) | 336 if (!decoded_frames_since_fallback_) |
| 337 pending_buffers_.push_back(buffer); | 337 pending_buffers_.push_back(buffer); |
| 338 | 338 |
| 339 DecodeInternal(buffer); | 339 // It's possible for a buffer to arrive from the demuxer right after the |
| 340 // fallback decoder successfully completed its initialization. At this point |
| 341 // |pending_buffers_| has already been copied to |fallback_buffers_| and we |
| 342 // need to append it ourselves. |
| 343 if (!fallback_buffers_.empty()) { |
| 344 fallback_buffers_.push_back(buffer); |
| 345 |
| 346 scoped_refptr<DecoderBuffer> temp = fallback_buffers_.front(); |
| 347 fallback_buffers_.pop_front(); |
| 348 DecodeInternal(temp); |
| 349 } else { |
| 350 DecodeInternal(buffer); |
| 351 } |
| 340 } | 352 } |
| 341 | 353 |
| 342 template <DemuxerStream::Type StreamType> | 354 template <DemuxerStream::Type StreamType> |
| 343 void DecoderStream<StreamType>::DecodeInternal( | 355 void DecoderStream<StreamType>::DecodeInternal( |
| 344 const scoped_refptr<DecoderBuffer>& buffer) { | 356 const scoped_refptr<DecoderBuffer>& buffer) { |
| 345 FUNCTION_DVLOG(2); | 357 FUNCTION_DVLOG(2); |
| 346 DCHECK(state_ == STATE_NORMAL || state_ == STATE_FLUSHING_DECODER) << state_; | 358 DCHECK(state_ == STATE_NORMAL || state_ == STATE_FLUSHING_DECODER) << state_; |
| 347 DCHECK_LT(pending_decode_requests_, GetMaxDecodeRequests()); | 359 DCHECK_LT(pending_decode_requests_, GetMaxDecodeRequests()); |
| 348 DCHECK(reset_cb_.is_null()); | 360 DCHECK(reset_cb_.is_null()); |
| 349 DCHECK(buffer.get()); | 361 DCHECK(buffer.get()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 543 |
| 532 template <DemuxerStream::Type StreamType> | 544 template <DemuxerStream::Type StreamType> |
| 533 void DecoderStream<StreamType>::OnBufferReady( | 545 void DecoderStream<StreamType>::OnBufferReady( |
| 534 DemuxerStream::Status status, | 546 DemuxerStream::Status status, |
| 535 const scoped_refptr<DecoderBuffer>& buffer) { | 547 const scoped_refptr<DecoderBuffer>& buffer) { |
| 536 FUNCTION_DVLOG(2) << ": " << status << ", " | 548 FUNCTION_DVLOG(2) << ": " << status << ", " |
| 537 << (buffer.get() ? buffer->AsHumanReadableString() | 549 << (buffer.get() ? buffer->AsHumanReadableString() |
| 538 : "NULL"); | 550 : "NULL"); |
| 539 | 551 |
| 540 DCHECK(task_runner_->BelongsToCurrentThread()); | 552 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 553 DCHECK(pending_demuxer_read_); |
| 541 if (decoded_frames_since_fallback_) { | 554 if (decoded_frames_since_fallback_) { |
| 542 DCHECK(state_ == STATE_PENDING_DEMUXER_READ || state_ == STATE_ERROR) | 555 DCHECK(state_ == STATE_PENDING_DEMUXER_READ || state_ == STATE_ERROR) |
| 543 << state_; | 556 << state_; |
| 544 } else { | 557 } else { |
| 545 DCHECK(state_ == STATE_PENDING_DEMUXER_READ || state_ == STATE_ERROR || | 558 DCHECK(state_ == STATE_PENDING_DEMUXER_READ || state_ == STATE_ERROR || |
| 546 STATE_REINITIALIZING_DECODER) | 559 state_ == STATE_REINITIALIZING_DECODER || state_ == STATE_NORMAL) |
| 547 << state_; | 560 << state_; |
| 548 } | 561 } |
| 549 DCHECK_EQ(buffer.get() != NULL, status == DemuxerStream::kOk) << status; | 562 DCHECK_EQ(buffer.get() != NULL, status == DemuxerStream::kOk) << status; |
| 550 | 563 |
| 551 // Unset the flag. STATE_PENDING_DEMUXER_READ might have been overwritten. | 564 // Unset the flag. STATE_PENDING_DEMUXER_READ might have been overwritten. |
| 552 // See crbug.com/597605. | 565 // See crbug.com/597605. |
| 553 pending_demuxer_read_ = false; | 566 pending_demuxer_read_ = false; |
| 554 | 567 |
| 555 // If parallel decode requests are supported, multiple read requests might | 568 // If parallel decode requests are supported, multiple read requests might |
| 556 // have been sent to the demuxer. The buffers might arrive while the decoder | 569 // have been sent to the demuxer. The buffers might arrive while the decoder |
| (...skipping 17 matching lines...) Expand all Loading... |
| 574 break; | 587 break; |
| 575 case DemuxerStream::kAborted: | 588 case DemuxerStream::kAborted: |
| 576 // |this| will read from the demuxer stream again in OnDecoderSelected() | 589 // |this| will read from the demuxer stream again in OnDecoderSelected() |
| 577 // and receive a kAborted then. | 590 // and receive a kAborted then. |
| 578 pending_buffers_.clear(); | 591 pending_buffers_.clear(); |
| 579 break; | 592 break; |
| 580 } | 593 } |
| 581 return; | 594 return; |
| 582 } | 595 } |
| 583 | 596 |
| 584 // Decoding has been stopped (e.g due to an error). | 597 // Decoding has been stopped. |
| 585 if (state_ != STATE_PENDING_DEMUXER_READ) { | 598 if (state_ == STATE_ERROR) { |
| 586 DCHECK(state_ == STATE_ERROR); | |
| 587 DCHECK(read_cb_.is_null()); | 599 DCHECK(read_cb_.is_null()); |
| 588 | 600 |
| 589 if (!reset_cb_.is_null()) { | 601 if (!reset_cb_.is_null()) { |
| 590 // If we are using DecryptingDemuxerStream, we already called DDS::Reset() | 602 // If we are using DecryptingDemuxerStream, we already called DDS::Reset() |
| 591 // which will continue the resetting process in its callback. | 603 // which will continue the resetting process in its callback. |
| 592 if (!decrypting_demuxer_stream_) | 604 if (!decrypting_demuxer_stream_) |
| 593 Reset(base::ResetAndReturn(&reset_cb_)); | 605 Reset(base::ResetAndReturn(&reset_cb_)); |
| 594 } | 606 } |
| 595 return; | 607 return; |
| 596 } | 608 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 } | 781 } |
| 770 | 782 |
| 771 // The resetting process will be continued in OnDecoderReinitialized(). | 783 // The resetting process will be continued in OnDecoderReinitialized(). |
| 772 ReinitializeDecoder(); | 784 ReinitializeDecoder(); |
| 773 } | 785 } |
| 774 | 786 |
| 775 template class DecoderStream<DemuxerStream::VIDEO>; | 787 template class DecoderStream<DemuxerStream::VIDEO>; |
| 776 template class DecoderStream<DemuxerStream::AUDIO>; | 788 template class DecoderStream<DemuxerStream::AUDIO>; |
| 777 | 789 |
| 778 } // namespace media | 790 } // namespace media |
| OLD | NEW |