Index: media/filters/video_decoder_selector.cc |
diff --git a/media/filters/video_decoder_selector.cc b/media/filters/video_decoder_selector.cc |
index b1f186f2cf280abaab4a8181ae1d5a49ecee00ef..f1aebb26426a476fd85f7316fd50ab1a55811654 100644 |
--- a/media/filters/video_decoder_selector.cc |
+++ b/media/filters/video_decoder_selector.cc |
@@ -19,10 +19,10 @@ namespace media { |
VideoDecoderSelector::VideoDecoderSelector( |
const scoped_refptr<base::MessageLoopProxy>& message_loop, |
- const VideoDecoderList& decoders, |
+ ScopedVector<VideoDecoder> decoders, |
const SetDecryptorReadyCB& set_decryptor_ready_cb) |
: message_loop_(message_loop), |
- decoders_(decoders), |
+ decoders_(decoders.Pass()), |
set_decryptor_ready_cb_(set_decryptor_ready_cb), |
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
} |
@@ -43,7 +43,8 @@ void VideoDecoderSelector::SelectVideoDecoder( |
const VideoDecoderConfig& config = stream->video_decoder_config(); |
if (!config.IsValidConfig()) { |
DLOG(ERROR) << "Invalid video stream config."; |
- base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); |
+ base::ResetAndReturn(&select_decoder_cb_).Run( |
+ scoped_ptr<VideoDecoder>(), NULL); |
return; |
} |
@@ -51,24 +52,19 @@ void VideoDecoderSelector::SelectVideoDecoder( |
statistics_cb_ = statistics_cb; |
if (!config.is_encrypted()) { |
- if (decoders_.empty()) { |
- DLOG(ERROR) << "No video decoder can be used to decode the input stream."; |
- base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); |
- return; |
- } |
- |
- InitializeNextDecoder(); |
+ InitializeDecoder(decoders_.begin()); |
return; |
} |
// This could happen if Encrypted Media Extension (EME) is not enabled. |
if (set_decryptor_ready_cb_.is_null()) { |
- base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); |
+ base::ResetAndReturn(&select_decoder_cb_).Run( |
+ scoped_ptr<VideoDecoder>(), NULL); |
return; |
} |
- video_decoder_ = new DecryptingVideoDecoder(message_loop_, |
- set_decryptor_ready_cb_); |
+ video_decoder_.reset(new DecryptingVideoDecoder( |
+ message_loop_, set_decryptor_ready_cb_)); |
video_decoder_->Initialize( |
input_stream_, |
@@ -83,16 +79,7 @@ void VideoDecoderSelector::DecryptingVideoDecoderInitDone( |
DCHECK(message_loop_->BelongsToCurrentThread()); |
if (status == PIPELINE_OK) { |
- decoders_.clear(); |
- base::ResetAndReturn(&select_decoder_cb_).Run(video_decoder_, NULL); |
- return; |
- } |
- |
- video_decoder_ = NULL; |
- |
- if (decoders_.empty()) { |
- DLOG(ERROR) << "No video decoder can be used to decode the input stream."; |
- base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); |
+ base::ResetAndReturn(&select_decoder_cb_).Run(video_decoder_.Pass(), NULL); |
return; |
} |
@@ -112,42 +99,48 @@ void VideoDecoderSelector::DecryptingDemuxerStreamInitDone( |
if (status != PIPELINE_OK) { |
decrypted_stream_ = NULL; |
- base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); |
+ base::ResetAndReturn(&select_decoder_cb_).Run( |
+ scoped_ptr<VideoDecoder>(), NULL); |
return; |
} |
DCHECK(!decrypted_stream_->video_decoder_config().is_encrypted()); |
input_stream_ = decrypted_stream_; |
- InitializeNextDecoder(); |
+ InitializeDecoder(decoders_.begin()); |
} |
-void VideoDecoderSelector::InitializeNextDecoder() { |
+void VideoDecoderSelector::InitializeDecoder( |
+ ScopedVector<VideoDecoder>::iterator iter) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
- DCHECK(!decoders_.empty()); |
- |
- video_decoder_ = decoders_.front(); |
- decoders_.pop_front(); |
- DCHECK(video_decoder_); |
- video_decoder_->Initialize(input_stream_, |
- BindToCurrentLoop(base::Bind( |
- &VideoDecoderSelector::DecoderInitDone, |
- weak_ptr_factory_.GetWeakPtr())), |
- statistics_cb_); |
+ |
+ if (iter == decoders_.end()) { |
+ base::ResetAndReturn(&select_decoder_cb_).Run( |
+ scoped_ptr<VideoDecoder>(), NULL); |
+ return; |
+ } |
+ |
+ (*iter)->Initialize( |
+ input_stream_, |
xhwang
2013/03/22 01:00:32
nit: move this after "Initialize(" and align accor
scherkus (not reviewing)
2013/03/22 01:06:56
looks super funky due to the BTCL(base::Bind()) co
|
+ BindToCurrentLoop(base::Bind( |
+ &VideoDecoderSelector::DecoderInitDone, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ iter)), |
+ statistics_cb_); |
} |
-void VideoDecoderSelector::DecoderInitDone(PipelineStatus status) { |
+void VideoDecoderSelector::DecoderInitDone( |
+ ScopedVector<VideoDecoder>::iterator iter, PipelineStatus status) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
if (status != PIPELINE_OK) { |
- if (!decoders_.empty()) |
- InitializeNextDecoder(); |
- else |
- base::ResetAndReturn(&select_decoder_cb_).Run(NULL, NULL); |
+ InitializeDecoder(++iter); |
return; |
} |
- decoders_.clear(); |
- base::ResetAndReturn(&select_decoder_cb_).Run(video_decoder_, |
+ scoped_ptr<VideoDecoder> video_decoder(*iter); |
+ decoders_.weak_erase(iter); |
+ |
+ base::ResetAndReturn(&select_decoder_cb_).Run(video_decoder.Pass(), |
decrypted_stream_); |
} |