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 27 matching lines...) Expand all Loading... | |
38 } | 38 } |
39 | 39 |
40 template <> | 40 template <> |
41 const char* GetTraceString<DemuxerStream::AUDIO>() { | 41 const char* GetTraceString<DemuxerStream::AUDIO>() { |
42 return "DecoderStream<AUDIO>::Decode"; | 42 return "DecoderStream<AUDIO>::Decode"; |
43 } | 43 } |
44 | 44 |
45 template <DemuxerStream::Type StreamType> | 45 template <DemuxerStream::Type StreamType> |
46 DecoderStream<StreamType>::DecoderStream( | 46 DecoderStream<StreamType>::DecoderStream( |
47 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 47 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
48 ScopedVector<Decoder> decoders, | 48 CreateDecodersCB create_decoders_cb, |
49 MediaLog* media_log) | 49 MediaLog* media_log) |
50 : traits_(media_log), | 50 : traits_(media_log), |
51 task_runner_(task_runner), | 51 task_runner_(task_runner), |
52 media_log_(media_log), | 52 media_log_(media_log), |
53 state_(STATE_UNINITIALIZED), | 53 state_(STATE_UNINITIALIZED), |
54 stream_(NULL), | 54 stream_(NULL), |
55 cdm_context_(nullptr), | 55 cdm_context_(nullptr), |
56 decoder_selector_(new DecoderSelector<StreamType>(task_runner, | 56 decoder_selector_( |
57 std::move(decoders), | 57 new DecoderSelector<StreamType>(task_runner, |
58 media_log)), | 58 std::move(create_decoders_cb), |
59 media_log)), | |
59 decoder_produced_a_frame_(false), | 60 decoder_produced_a_frame_(false), |
61 is_on_fallback_decoder_(false), | |
60 decoding_eos_(false), | 62 decoding_eos_(false), |
61 pending_decode_requests_(0), | 63 pending_decode_requests_(0), |
62 duration_tracker_(8), | 64 duration_tracker_(8), |
63 received_config_change_during_reinit_(false), | 65 received_config_change_during_reinit_(false), |
64 pending_demuxer_read_(false), | 66 pending_demuxer_read_(false), |
65 weak_factory_(this), | 67 weak_factory_(this), |
66 fallback_weak_factory_(this) { | 68 fallback_weak_factory_(this) { |
67 FUNCTION_DVLOG(1); | 69 FUNCTION_DVLOG(1); |
68 } | 70 } |
69 | 71 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 : base::TimeDelta(); | 251 : base::TimeDelta(); |
250 } | 252 } |
251 | 253 |
252 template <DemuxerStream::Type StreamType> | 254 template <DemuxerStream::Type StreamType> |
253 void DecoderStream<StreamType>::SelectDecoder() { | 255 void DecoderStream<StreamType>::SelectDecoder() { |
254 // If we are already using DecryptingDemuxerStream (DDS), e.g. during | 256 // If we are already using DecryptingDemuxerStream (DDS), e.g. during |
255 // fallback, the |stream_| will always be clear. In this case, no need pass in | 257 // fallback, the |stream_| will always be clear. In this case, no need pass in |
256 // the |cdm_context_|. This will also help prevent creating a new DDS on top | 258 // the |cdm_context_|. This will also help prevent creating a new DDS on top |
257 // of the current DDS. | 259 // of the current DDS. |
258 CdmContext* cdm_context = decrypting_demuxer_stream_ ? nullptr : cdm_context_; | 260 CdmContext* cdm_context = decrypting_demuxer_stream_ ? nullptr : cdm_context_; |
261 std::string blacklisted_decoder = decoder_ ? decoder_->GetDisplayName() : ""; | |
259 | 262 |
260 decoder_selector_->SelectDecoder( | 263 decoder_selector_->SelectDecoder( |
261 &traits_, stream_, cdm_context, | 264 &traits_, stream_, cdm_context, blacklisted_decoder, |
262 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, | 265 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, |
263 weak_factory_.GetWeakPtr()), | 266 weak_factory_.GetWeakPtr()), |
264 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady, | 267 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady, |
265 fallback_weak_factory_.GetWeakPtr()), | 268 fallback_weak_factory_.GetWeakPtr()), |
266 waiting_for_decryption_key_cb_); | 269 waiting_for_decryption_key_cb_); |
267 } | 270 } |
268 | 271 |
269 template <DemuxerStream::Type StreamType> | 272 template <DemuxerStream::Type StreamType> |
270 void DecoderStream<StreamType>::OnDecoderSelected( | 273 void DecoderStream<StreamType>::OnDecoderSelected( |
271 std::unique_ptr<Decoder> selected_decoder, | 274 std::unique_ptr<Decoder> selected_decoder, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 return; | 427 return; |
425 } | 428 } |
426 | 429 |
427 // Drop decoding result if Reset() was called during decoding. | 430 // Drop decoding result if Reset() was called during decoding. |
428 // The resetting process will be handled when the decoder is reset. | 431 // The resetting process will be handled when the decoder is reset. |
429 if (!reset_cb_.is_null()) | 432 if (!reset_cb_.is_null()) |
430 return; | 433 return; |
431 | 434 |
432 switch (status) { | 435 switch (status) { |
433 case DecodeStatus::DECODE_ERROR: | 436 case DecodeStatus::DECODE_ERROR: |
434 if (!decoder_produced_a_frame_) { | 437 // Only fall back to a new decoder after failing to decode the first |
438 // buffer, and we have not falled back before. | |
439 if (!decoder_produced_a_frame_ && !is_on_fallback_decoder_) { | |
440 is_on_fallback_decoder_ = true; | |
435 pending_decode_requests_ = 0; | 441 pending_decode_requests_ = 0; |
436 | 442 |
437 // Prevent all pending decode requests and outputs from those requests | 443 // Prevent all pending decode requests and outputs from those requests |
438 // from being called back. | 444 // from being called back. |
439 fallback_weak_factory_.InvalidateWeakPtrs(); | 445 fallback_weak_factory_.InvalidateWeakPtrs(); |
440 | 446 |
441 FUNCTION_DVLOG(1) | 447 FUNCTION_DVLOG(1) |
442 << ": Falling back to new decoder after initial decode error."; | 448 << ": Falling back to new decoder after initial decode error."; |
443 state_ = STATE_REINITIALIZING_DECODER; | 449 state_ = STATE_REINITIALIZING_DECODER; |
444 SelectDecoder(); | 450 SelectDecoder(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 DCHECK(read_cb_.is_null()); | 500 DCHECK(read_cb_.is_null()); |
495 return; | 501 return; |
496 } | 502 } |
497 | 503 |
498 // Drop decoding result if Reset() was called during decoding. | 504 // Drop decoding result if Reset() was called during decoding. |
499 // The resetting process will be handled when the decoder is reset. | 505 // The resetting process will be handled when the decoder is reset. |
500 if (!reset_cb_.is_null()) | 506 if (!reset_cb_.is_null()) |
501 return; | 507 return; |
502 | 508 |
503 decoder_produced_a_frame_ = true; | 509 decoder_produced_a_frame_ = true; |
510 is_on_fallback_decoder_ = false; | |
DaleCurtis
2017/05/04 02:37:24
Name is a bit off since we clear it here. Not sure
| |
504 traits_.OnDecodeDone(output); | 511 traits_.OnDecodeDone(output); |
505 | 512 |
506 // |decoder_| sucessfully decoded a frame. No need to keep buffers for a | 513 // |decoder_| sucessfully decoded a frame. No need to keep buffers for a |
507 // fallback decoder. | 514 // fallback decoder. |
508 // Note: |fallback_buffers_| might still have buffers, and we will keep | 515 // Note: |fallback_buffers_| might still have buffers, and we will keep |
509 // reading from there before requesting new buffers from |stream_|. | 516 // reading from there before requesting new buffers from |stream_|. |
510 pending_buffers_.clear(); | 517 pending_buffers_.clear(); |
511 | 518 |
512 if (!read_cb_.is_null()) { | 519 if (!read_cb_.is_null()) { |
513 // If |ready_outputs_| was non-empty, the read would have already been | 520 // If |ready_outputs_| was non-empty, the read would have already been |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 } | 778 } |
772 | 779 |
773 // The resetting process will be continued in OnDecoderReinitialized(). | 780 // The resetting process will be continued in OnDecoderReinitialized(). |
774 ReinitializeDecoder(); | 781 ReinitializeDecoder(); |
775 } | 782 } |
776 | 783 |
777 template class DecoderStream<DemuxerStream::VIDEO>; | 784 template class DecoderStream<DemuxerStream::VIDEO>; |
778 template class DecoderStream<DemuxerStream::AUDIO>; | 785 template class DecoderStream<DemuxerStream::AUDIO>; |
779 | 786 |
780 } // namespace media | 787 } // namespace media |
OLD | NEW |