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

Unified Diff: media/filters/decoder_selector.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 side-by-side diff with in-line comments
Download patch
Index: media/filters/decoder_selector.cc
diff --git a/media/filters/decoder_selector.cc b/media/filters/decoder_selector.cc
index c4271060efc28567097de1866657f761c830bdb8..ddbc4c3ab9162210eab31001260850692cb70584 100644
--- a/media/filters/decoder_selector.cc
+++ b/media/filters/decoder_selector.cc
@@ -43,10 +43,10 @@ static bool HasValidStreamConfig(DemuxerStream* stream) {
template <DemuxerStream::Type StreamType>
DecoderSelector<StreamType>::DecoderSelector(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
- ScopedVector<Decoder> decoders,
+ const CreateDecodersCB& create_decoders_cb,
const scoped_refptr<MediaLog>& media_log)
: task_runner_(task_runner),
- decoders_(std::move(decoders)),
+ create_decoders_cb_(create_decoders_cb),
media_log_(media_log),
input_stream_(nullptr),
weak_ptr_factory_(this) {}
@@ -68,6 +68,7 @@ void DecoderSelector<StreamType>::SelectDecoder(
StreamTraits* traits,
DemuxerStream* stream,
CdmContext* cdm_context,
+ const std::string& blacklisted_decoder,
sandersd (OOO until July 31) 2017/04/24 20:55:14 I worry that blacklisting a single decoder may be
xhwang 2017/04/25 00:43:30 We "could" host the same decoder via GVD and MVD,
const SelectDecoderCB& select_decoder_cb,
const typename Decoder::OutputCB& output_cb,
const base::Closure& waiting_for_decryption_key_cb) {
@@ -77,9 +78,6 @@ void DecoderSelector<StreamType>::SelectDecoder(
DCHECK(stream);
DCHECK(select_decoder_cb_.is_null());
- cdm_context_ = cdm_context;
- waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb;
-
// Make sure |select_decoder_cb| runs on a different execution stack.
select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb);
@@ -91,11 +89,20 @@ void DecoderSelector<StreamType>::SelectDecoder(
traits_ = traits;
input_stream_ = stream;
+ cdm_context_ = cdm_context;
+ blacklisted_decoder_ = blacklisted_decoder;
output_cb_ = output_cb;
+ waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb;
+
+ decoders_ = create_decoders_cb_.Run();
+ config_ = StreamTraits::GetDecoderConfig(input_stream_);
// When there is a CDM attached, always try the decrypting decoder or
// demuxer-stream first.
- if (cdm_context_) {
+ if (config_.is_encrypted()) {
+ DCHECK(cdm_context_);
+// TODO(xhwang): This if-defined doesn't make a lot of sense. It should be
+// replaced by some better checks.
#if !defined(DISABLE_FFMPEG_VIDEO_DECODERS)
InitializeDecryptingDecoder();
#else
@@ -104,11 +111,6 @@ void DecoderSelector<StreamType>::SelectDecoder(
return;
}
- config_ = StreamTraits::GetDecoderConfig(input_stream_);
-
- // If the input stream is encrypted, CdmContext must be non-null.
- DCHECK(!config_.is_encrypted());
-
InitializeDecoder();
}
@@ -116,9 +118,15 @@ void DecoderSelector<StreamType>::SelectDecoder(
template <DemuxerStream::Type StreamType>
void DecoderSelector<StreamType>::InitializeDecryptingDecoder() {
DVLOG(2) << __func__;
+
decoder_.reset(new typename StreamTraits::DecryptingDecoderType(
task_runner_, media_log_, waiting_for_decryption_key_cb_));
+ if (decoder_->GetDisplayName() == blacklisted_decoder_) {
sandersd (OOO until July 31) 2017/04/24 20:55:14 This implies some new semantics for the DisplayNam
xhwang 2017/04/25 00:43:30 Good point. Will do!
+ DecryptingDecoderInitDone(false);
+ return;
+ }
+
traits_->InitializeDecoder(
decoder_.get(), StreamTraits::GetDecoderConfig(input_stream_),
input_stream_->liveness() == DemuxerStream::LIVENESS_LIVE, cdm_context_,
@@ -177,11 +185,7 @@ void DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone(
DCHECK(!config_.is_encrypted());
} else {
decrypted_stream_.reset();
- config_ = StreamTraits::GetDecoderConfig(input_stream_);
-
- // Prefer decrypting decoder by using an encrypted config.
- if (!config_.is_encrypted())
- config_.SetIsEncrypted(true);
+ DCHECK(config_.is_encrypted());
}
InitializeDecoder();
@@ -193,14 +197,24 @@ void DecoderSelector<StreamType>::InitializeDecoder() {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!decoder_);
- if (decoders_.empty()) {
+ // Select the next non-blacklisted decoder.
+ while (!decoders_.empty()) {
+ std::unique_ptr<Decoder> decoder(decoders_.front());
+ decoders_.weak_erase(decoders_.begin());
+ // When |decrypted_stream_| is selected, the |config_| has changed so ignore
DaleCurtis 2017/04/24 19:39:39 Can you explain this comment a bit more? The code
DaleCurtis 2017/04/24 19:41:04 Ah just saw your entry in the CL description now.
xhwang 2017/04/25 00:43:29 From my understanding, DecoderStream doesn't know
+ // the blacklist.
+ if (decrypted_stream_ ||
+ decoder->GetDisplayName() != blacklisted_decoder_) {
+ decoder_ = std::move(decoder);
+ break;
+ }
+ }
+
+ if (!decoder_) {
ReturnNullDecoder();
return;
}
- decoder_.reset(decoders_.front());
- decoders_.weak_erase(decoders_.begin());
-
traits_->InitializeDecoder(
decoder_.get(), config_,
input_stream_->liveness() == DemuxerStream::LIVENESS_LIVE, cdm_context_,

Powered by Google App Engine
This is Rietveld 408576698