| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 template <DemuxerStream::Type StreamType> | 83 template <DemuxerStream::Type StreamType> |
| 84 std::string DecoderStream<StreamType>::GetStreamTypeString() { | 84 std::string DecoderStream<StreamType>::GetStreamTypeString() { |
| 85 return DecoderStreamTraits<StreamType>::ToString(); | 85 return DecoderStreamTraits<StreamType>::ToString(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 template <DemuxerStream::Type StreamType> | 88 template <DemuxerStream::Type StreamType> |
| 89 void DecoderStream<StreamType>::Initialize( | 89 void DecoderStream<StreamType>::Initialize( |
| 90 DemuxerStream* stream, | 90 DemuxerStream* stream, |
| 91 const InitCB& init_cb, | 91 const InitCB& init_cb, |
| 92 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 92 const SetCdmReadyCB& set_cdm_ready_cb, |
| 93 const StatisticsCB& statistics_cb, | 93 const StatisticsCB& statistics_cb, |
| 94 const base::Closure& waiting_for_decryption_key_cb) { | 94 const base::Closure& waiting_for_decryption_key_cb) { |
| 95 FUNCTION_DVLOG(2); | 95 FUNCTION_DVLOG(2); |
| 96 DCHECK(task_runner_->BelongsToCurrentThread()); | 96 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 97 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 97 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 98 DCHECK(init_cb_.is_null()); | 98 DCHECK(init_cb_.is_null()); |
| 99 DCHECK(!init_cb.is_null()); | 99 DCHECK(!init_cb.is_null()); |
| 100 | 100 |
| 101 statistics_cb_ = statistics_cb; | 101 statistics_cb_ = statistics_cb; |
| 102 init_cb_ = init_cb; | 102 init_cb_ = init_cb; |
| 103 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; | 103 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; |
| 104 stream_ = stream; | 104 stream_ = stream; |
| 105 | 105 |
| 106 state_ = STATE_INITIALIZING; | 106 state_ = STATE_INITIALIZING; |
| 107 SelectDecoder(set_decryptor_ready_cb); | 107 SelectDecoder(set_cdm_ready_cb); |
| 108 } | 108 } |
| 109 | 109 |
| 110 template <DemuxerStream::Type StreamType> | 110 template <DemuxerStream::Type StreamType> |
| 111 void DecoderStream<StreamType>::Read(const ReadCB& read_cb) { | 111 void DecoderStream<StreamType>::Read(const ReadCB& read_cb) { |
| 112 FUNCTION_DVLOG(2); | 112 FUNCTION_DVLOG(2); |
| 113 DCHECK(task_runner_->BelongsToCurrentThread()); | 113 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 114 DCHECK(state_ != STATE_UNINITIALIZED && state_ != STATE_INITIALIZING) | 114 DCHECK(state_ != STATE_UNINITIALIZED && state_ != STATE_INITIALIZING) |
| 115 << state_; | 115 << state_; |
| 116 // No two reads in the flight at any time. | 116 // No two reads in the flight at any time. |
| 117 DCHECK(read_cb_.is_null()); | 117 DCHECK(read_cb_.is_null()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // Limit total number of outputs stored in |ready_outputs_| and being decoded. | 208 // Limit total number of outputs stored in |ready_outputs_| and being decoded. |
| 209 // It only makes sense to saturate decoder completely when output queue is | 209 // It only makes sense to saturate decoder completely when output queue is |
| 210 // empty. | 210 // empty. |
| 211 int num_decodes = | 211 int num_decodes = |
| 212 static_cast<int>(ready_outputs_.size()) + pending_decode_requests_; | 212 static_cast<int>(ready_outputs_.size()) + pending_decode_requests_; |
| 213 return !decoding_eos_ && num_decodes < GetMaxDecodeRequests(); | 213 return !decoding_eos_ && num_decodes < GetMaxDecodeRequests(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 template <DemuxerStream::Type StreamType> | 216 template <DemuxerStream::Type StreamType> |
| 217 void DecoderStream<StreamType>::SelectDecoder( | 217 void DecoderStream<StreamType>::SelectDecoder( |
| 218 const SetDecryptorReadyCB& set_decryptor_ready_cb) { | 218 const SetCdmReadyCB& set_cdm_ready_cb) { |
| 219 decoder_selector_->SelectDecoder( | 219 decoder_selector_->SelectDecoder( |
| 220 stream_, set_decryptor_ready_cb, | 220 stream_, set_cdm_ready_cb, |
| 221 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, | 221 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, |
| 222 weak_factory_.GetWeakPtr()), | 222 weak_factory_.GetWeakPtr()), |
| 223 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady, | 223 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady, |
| 224 weak_factory_.GetWeakPtr()), | 224 weak_factory_.GetWeakPtr()), |
| 225 waiting_for_decryption_key_cb_); | 225 waiting_for_decryption_key_cb_); |
| 226 } | 226 } |
| 227 | 227 |
| 228 template <DemuxerStream::Type StreamType> | 228 template <DemuxerStream::Type StreamType> |
| 229 void DecoderStream<StreamType>::OnDecoderSelected( | 229 void DecoderStream<StreamType>::OnDecoderSelected( |
| 230 scoped_ptr<Decoder> selected_decoder, | 230 scoped_ptr<Decoder> selected_decoder, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // 2, Reset() was called during flushing decoder (see OnDecoderReset()). | 535 // 2, Reset() was called during flushing decoder (see OnDecoderReset()). |
| 536 // Also, Reset() can be called during pending ReinitializeDecoder(). | 536 // Also, Reset() can be called during pending ReinitializeDecoder(). |
| 537 // This function needs to handle them all! | 537 // This function needs to handle them all! |
| 538 | 538 |
| 539 if (!success) { | 539 if (!success) { |
| 540 // Reinitialization failed. Try to fall back to one of the remaining | 540 // Reinitialization failed. Try to fall back to one of the remaining |
| 541 // decoders. This will consume at least one decoder so doing it more than | 541 // decoders. This will consume at least one decoder so doing it more than |
| 542 // once is safe. | 542 // once is safe. |
| 543 // For simplicity, don't attempt to fall back to a decryptor. Calling this | 543 // For simplicity, don't attempt to fall back to a decryptor. Calling this |
| 544 // with a null callback ensures that one won't be selected. | 544 // with a null callback ensures that one won't be selected. |
| 545 SelectDecoder(SetDecryptorReadyCB()); | 545 SelectDecoder(SetCdmReadyCB()); |
| 546 } else { | 546 } else { |
| 547 CompleteDecoderReinitialization(true); | 547 CompleteDecoderReinitialization(true); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 | 550 |
| 551 template <DemuxerStream::Type StreamType> | 551 template <DemuxerStream::Type StreamType> |
| 552 void DecoderStream<StreamType>::CompleteDecoderReinitialization(bool success) { | 552 void DecoderStream<StreamType>::CompleteDecoderReinitialization(bool success) { |
| 553 FUNCTION_DVLOG(2); | 553 FUNCTION_DVLOG(2); |
| 554 DCHECK(task_runner_->BelongsToCurrentThread()); | 554 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 555 DCHECK_EQ(state_, STATE_REINITIALIZING_DECODER); | 555 DCHECK_EQ(state_, STATE_REINITIALIZING_DECODER); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 605 } |
| 606 | 606 |
| 607 // The resetting process will be continued in OnDecoderReinitialized(). | 607 // The resetting process will be continued in OnDecoderReinitialized(). |
| 608 ReinitializeDecoder(); | 608 ReinitializeDecoder(); |
| 609 } | 609 } |
| 610 | 610 |
| 611 template class DecoderStream<DemuxerStream::VIDEO>; | 611 template class DecoderStream<DemuxerStream::VIDEO>; |
| 612 template class DecoderStream<DemuxerStream::AUDIO>; | 612 template class DecoderStream<DemuxerStream::AUDIO>; |
| 613 | 613 |
| 614 } // namespace media | 614 } // namespace media |
| OLD | NEW |