Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: media/filters/decoder_stream.cc

Issue 2837613004: media: Support better decoder switching (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 const CreateDecodersCB& create_decoders_cb,
49 const scoped_refptr<MediaLog>& media_log) 49 const scoped_refptr<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_(new DecoderSelector<StreamType>(task_runner,
57 std::move(decoders), 57 create_decoders_cb,
58 media_log)), 58 media_log)),
59 decoded_frames_since_fallback_(0), 59 decoded_frames_since_fallback_(0),
60 decoding_eos_(false), 60 decoding_eos_(false),
61 pending_decode_requests_(0), 61 pending_decode_requests_(0),
62 duration_tracker_(8), 62 duration_tracker_(8),
63 received_config_change_during_reinit_(false), 63 received_config_change_during_reinit_(false),
64 pending_demuxer_read_(false), 64 pending_demuxer_read_(false),
65 weak_factory_(this), 65 weak_factory_(this),
66 fallback_weak_factory_(this) { 66 fallback_weak_factory_(this) {
67 FUNCTION_DVLOG(1); 67 FUNCTION_DVLOG(1);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 : base::TimeDelta(); 249 : base::TimeDelta();
250 } 250 }
251 251
252 template <DemuxerStream::Type StreamType> 252 template <DemuxerStream::Type StreamType>
253 void DecoderStream<StreamType>::SelectDecoder() { 253 void DecoderStream<StreamType>::SelectDecoder() {
254 // If we are already using DecryptingDemuxerStream (DDS), e.g. during 254 // 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 255 // 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 256 // the |cdm_context_|. This will also help prevent creating a new DDS on top
257 // of the current DDS. 257 // of the current DDS.
258 CdmContext* cdm_context = decrypting_demuxer_stream_ ? nullptr : cdm_context_; 258 CdmContext* cdm_context = decrypting_demuxer_stream_ ? nullptr : cdm_context_;
259 std::string blacklisted_decoder = decoder_ ? decoder_->GetDisplayName() : "";
259 260
260 decoder_selector_->SelectDecoder( 261 decoder_selector_->SelectDecoder(
261 &traits_, stream_, cdm_context, 262 &traits_, stream_, cdm_context, blacklisted_decoder,
262 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, 263 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected,
263 weak_factory_.GetWeakPtr()), 264 weak_factory_.GetWeakPtr()),
264 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady, 265 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady,
265 fallback_weak_factory_.GetWeakPtr()), 266 fallback_weak_factory_.GetWeakPtr()),
266 waiting_for_decryption_key_cb_); 267 waiting_for_decryption_key_cb_);
267 } 268 }
268 269
269 template <DemuxerStream::Type StreamType> 270 template <DemuxerStream::Type StreamType>
270 void DecoderStream<StreamType>::OnDecoderSelected( 271 void DecoderStream<StreamType>::OnDecoderSelected(
271 std::unique_ptr<Decoder> selected_decoder, 272 std::unique_ptr<Decoder> selected_decoder,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return; 425 return;
425 } 426 }
426 427
427 // Drop decoding result if Reset() was called during decoding. 428 // Drop decoding result if Reset() was called during decoding.
428 // The resetting process will be handled when the decoder is reset. 429 // The resetting process will be handled when the decoder is reset.
429 if (!reset_cb_.is_null()) 430 if (!reset_cb_.is_null())
430 return; 431 return;
431 432
432 switch (status) { 433 switch (status) {
433 case DecodeStatus::DECODE_ERROR: 434 case DecodeStatus::DECODE_ERROR:
434 if (!decoded_frames_since_fallback_) { 435 // Only fall back to a new decoder after failing to decode the first
436 // buffer, and we have not falled back before.
437 if (!decoded_frames_since_fallback_ && !previous_decoder_) {
435 pending_decode_requests_ = 0; 438 pending_decode_requests_ = 0;
436 439
437 // Prevent all pending decode requests and outputs form those requests 440 // Prevent all pending decode requests and outputs form those requests
438 // from being called back. 441 // from being called back.
439 fallback_weak_factory_.InvalidateWeakPtrs(); 442 fallback_weak_factory_.InvalidateWeakPtrs();
440 443
441 FUNCTION_DVLOG(1) 444 FUNCTION_DVLOG(1)
442 << ": Falling back to new decoder after initial decode error."; 445 << ": Falling back to new decoder after initial decode error.";
443 state_ = STATE_REINITIALIZING_DECODER; 446 state_ = STATE_REINITIALIZING_DECODER;
444 SelectDecoder(); 447 SelectDecoder();
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 } 785 }
783 786
784 // The resetting process will be continued in OnDecoderReinitialized(). 787 // The resetting process will be continued in OnDecoderReinitialized().
785 ReinitializeDecoder(); 788 ReinitializeDecoder();
786 } 789 }
787 790
788 template class DecoderStream<DemuxerStream::VIDEO>; 791 template class DecoderStream<DemuxerStream::VIDEO>;
789 template class DecoderStream<DemuxerStream::AUDIO>; 792 template class DecoderStream<DemuxerStream::AUDIO>;
790 793
791 } // namespace media 794 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698