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

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

Issue 2625333003: media: Always provide CdmContext when selecting decoder in DecoderStream (Closed)
Patch Set: rebase only Created 3 years, 11 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
« no previous file with comments | « media/filters/decoder_stream.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ScopedVector<Decoder> decoders,
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 decoder_selector_(new DecoderSelector<StreamType>(task_runner, 56 decoder_selector_(new DecoderSelector<StreamType>(task_runner,
56 std::move(decoders), 57 std::move(decoders),
57 media_log)), 58 media_log)),
58 decoded_frames_since_fallback_(0), 59 decoded_frames_since_fallback_(0),
59 decoding_eos_(false), 60 decoding_eos_(false),
60 pending_decode_requests_(0), 61 pending_decode_requests_(0),
61 duration_tracker_(8), 62 duration_tracker_(8),
62 received_config_change_during_reinit_(false), 63 received_config_change_during_reinit_(false),
63 pending_demuxer_read_(false), 64 pending_demuxer_read_(false),
64 weak_factory_(this), 65 weak_factory_(this),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const InitCB& init_cb, 101 const InitCB& init_cb,
101 CdmContext* cdm_context, 102 CdmContext* cdm_context,
102 const StatisticsCB& statistics_cb, 103 const StatisticsCB& statistics_cb,
103 const base::Closure& waiting_for_decryption_key_cb) { 104 const base::Closure& waiting_for_decryption_key_cb) {
104 FUNCTION_DVLOG(1); 105 FUNCTION_DVLOG(1);
105 DCHECK(task_runner_->BelongsToCurrentThread()); 106 DCHECK(task_runner_->BelongsToCurrentThread());
106 DCHECK_EQ(state_, STATE_UNINITIALIZED); 107 DCHECK_EQ(state_, STATE_UNINITIALIZED);
107 DCHECK(init_cb_.is_null()); 108 DCHECK(init_cb_.is_null());
108 DCHECK(!init_cb.is_null()); 109 DCHECK(!init_cb.is_null());
109 110
111 stream_ = stream;
112 init_cb_ = init_cb;
113 cdm_context_ = cdm_context;
110 statistics_cb_ = statistics_cb; 114 statistics_cb_ = statistics_cb;
111 init_cb_ = init_cb;
112 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; 115 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb;
113 stream_ = stream;
114 116
115 traits_.OnStreamReset(stream_); 117 traits_.OnStreamReset(stream_);
116 118
117 state_ = STATE_INITIALIZING; 119 state_ = STATE_INITIALIZING;
118 SelectDecoder(cdm_context); 120 SelectDecoder();
119 } 121 }
120 122
121 template <DemuxerStream::Type StreamType> 123 template <DemuxerStream::Type StreamType>
122 void DecoderStream<StreamType>::Read(const ReadCB& read_cb) { 124 void DecoderStream<StreamType>::Read(const ReadCB& read_cb) {
123 FUNCTION_DVLOG(3); 125 FUNCTION_DVLOG(3);
124 DCHECK(task_runner_->BelongsToCurrentThread()); 126 DCHECK(task_runner_->BelongsToCurrentThread());
125 DCHECK(state_ != STATE_UNINITIALIZED && state_ != STATE_INITIALIZING) 127 DCHECK(state_ != STATE_UNINITIALIZED && state_ != STATE_INITIALIZING)
126 << state_; 128 << state_;
127 // No two reads in the flight at any time. 129 // No two reads in the flight at any time.
128 DCHECK(read_cb_.is_null()); 130 DCHECK(read_cb_.is_null());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 243 }
242 244
243 template <DemuxerStream::Type StreamType> 245 template <DemuxerStream::Type StreamType>
244 base::TimeDelta DecoderStream<StreamType>::AverageDuration() const { 246 base::TimeDelta DecoderStream<StreamType>::AverageDuration() const {
245 DCHECK(task_runner_->BelongsToCurrentThread()); 247 DCHECK(task_runner_->BelongsToCurrentThread());
246 return duration_tracker_.count() ? duration_tracker_.Average() 248 return duration_tracker_.count() ? duration_tracker_.Average()
247 : base::TimeDelta(); 249 : base::TimeDelta();
248 } 250 }
249 251
250 template <DemuxerStream::Type StreamType> 252 template <DemuxerStream::Type StreamType>
251 void DecoderStream<StreamType>::SelectDecoder(CdmContext* cdm_context) { 253 void DecoderStream<StreamType>::SelectDecoder() {
252 decoder_selector_->SelectDecoder( 254 decoder_selector_->SelectDecoder(
253 &traits_, stream_, cdm_context, 255 &traits_, stream_, cdm_context_,
254 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected, 256 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected,
255 weak_factory_.GetWeakPtr()), 257 weak_factory_.GetWeakPtr()),
256 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady, 258 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady,
257 fallback_weak_factory_.GetWeakPtr()), 259 fallback_weak_factory_.GetWeakPtr()),
258 waiting_for_decryption_key_cb_); 260 waiting_for_decryption_key_cb_);
259 } 261 }
260 262
261 template <DemuxerStream::Type StreamType> 263 template <DemuxerStream::Type StreamType>
262 void DecoderStream<StreamType>::OnDecoderSelected( 264 void DecoderStream<StreamType>::OnDecoderSelected(
263 std::unique_ptr<Decoder> selected_decoder, 265 std::unique_ptr<Decoder> selected_decoder,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 if (!decoded_frames_since_fallback_) { 428 if (!decoded_frames_since_fallback_) {
427 pending_decode_requests_ = 0; 429 pending_decode_requests_ = 0;
428 430
429 // Prevent all pending decode requests and outputs form those requests 431 // Prevent all pending decode requests and outputs form those requests
430 // from being called back. 432 // from being called back.
431 fallback_weak_factory_.InvalidateWeakPtrs(); 433 fallback_weak_factory_.InvalidateWeakPtrs();
432 434
433 FUNCTION_DVLOG(1) 435 FUNCTION_DVLOG(1)
434 << ": Falling back to new decoder after initial decode error."; 436 << ": Falling back to new decoder after initial decode error.";
435 state_ = STATE_REINITIALIZING_DECODER; 437 state_ = STATE_REINITIALIZING_DECODER;
436 decoder_selector_->SelectDecoder( 438 SelectDecoder();
437 &traits_, stream_, nullptr,
438 base::Bind(&DecoderStream<StreamType>::OnDecoderSelected,
439 weak_factory_.GetWeakPtr()),
440 base::Bind(&DecoderStream<StreamType>::OnDecodeOutputReady,
441 fallback_weak_factory_.GetWeakPtr()),
442 waiting_for_decryption_key_cb_);
443 return; 439 return;
444 } 440 }
445 FUNCTION_DVLOG(1) << ": Decode error!"; 441 FUNCTION_DVLOG(1) << ": Decode error!";
446 state_ = STATE_ERROR; 442 state_ = STATE_ERROR;
447 MEDIA_LOG(ERROR, media_log_) << GetStreamTypeString() << " decode error"; 443 MEDIA_LOG(ERROR, media_log_) << GetStreamTypeString() << " decode error";
448 ready_outputs_.clear(); 444 ready_outputs_.clear();
449 if (!read_cb_.is_null()) 445 if (!read_cb_.is_null())
450 SatisfyRead(DECODE_ERROR, NULL); 446 SatisfyRead(DECODE_ERROR, NULL);
451 return; 447 return;
452 448
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 // ReinitializeDecoder() can be called in two cases: 700 // ReinitializeDecoder() can be called in two cases:
705 // 1, Flushing decoder finished (see OnDecodeOutputReady()). 701 // 1, Flushing decoder finished (see OnDecodeOutputReady()).
706 // 2, Reset() was called during flushing decoder (see OnDecoderReset()). 702 // 2, Reset() was called during flushing decoder (see OnDecoderReset()).
707 // Also, Reset() can be called during pending ReinitializeDecoder(). 703 // Also, Reset() can be called during pending ReinitializeDecoder().
708 // This function needs to handle them all! 704 // This function needs to handle them all!
709 705
710 if (!success) { 706 if (!success) {
711 // Reinitialization failed. Try to fall back to one of the remaining 707 // Reinitialization failed. Try to fall back to one of the remaining
712 // decoders. This will consume at least one decoder so doing it more than 708 // decoders. This will consume at least one decoder so doing it more than
713 // once is safe. 709 // once is safe.
714 // For simplicity, don't attempt to fall back to a decrypting decoder. 710 SelectDecoder();
715 // Calling this with a null CdmContext ensures that one won't be selected.
716 SelectDecoder(nullptr);
717 } else { 711 } else {
718 CompleteDecoderReinitialization(true); 712 CompleteDecoderReinitialization(true);
719 } 713 }
720 } 714 }
721 715
722 template <DemuxerStream::Type StreamType> 716 template <DemuxerStream::Type StreamType>
723 void DecoderStream<StreamType>::CompleteDecoderReinitialization(bool success) { 717 void DecoderStream<StreamType>::CompleteDecoderReinitialization(bool success) {
724 FUNCTION_DVLOG(2); 718 FUNCTION_DVLOG(2);
725 DCHECK(task_runner_->BelongsToCurrentThread()); 719 DCHECK(task_runner_->BelongsToCurrentThread());
726 DCHECK_EQ(state_, STATE_REINITIALIZING_DECODER); 720 DCHECK_EQ(state_, STATE_REINITIALIZING_DECODER);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 } 773 }
780 774
781 // The resetting process will be continued in OnDecoderReinitialized(). 775 // The resetting process will be continued in OnDecoderReinitialized().
782 ReinitializeDecoder(); 776 ReinitializeDecoder();
783 } 777 }
784 778
785 template class DecoderStream<DemuxerStream::VIDEO>; 779 template class DecoderStream<DemuxerStream::VIDEO>;
786 template class DecoderStream<DemuxerStream::AUDIO>; 780 template class DecoderStream<DemuxerStream::AUDIO>;
787 781
788 } // namespace media 782 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decoder_stream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698