| 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_selector.h" | 5 #include "media/filters/decoder_selector.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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 if (!select_decoder_cb_.is_null()) | 74 if (!select_decoder_cb_.is_null()) |
| 75 ReturnNullDecoder(); | 75 ReturnNullDecoder(); |
| 76 | 76 |
| 77 decoder_.reset(); | 77 decoder_.reset(); |
| 78 decrypted_stream_.reset(); | 78 decrypted_stream_.reset(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 template <DemuxerStream::Type StreamType> | 81 template <DemuxerStream::Type StreamType> |
| 82 void DecoderSelector<StreamType>::SelectDecoder( | 82 void DecoderSelector<StreamType>::SelectDecoder( |
| 83 StreamTraits* traits, |
| 83 DemuxerStream* stream, | 84 DemuxerStream* stream, |
| 84 CdmContext* cdm_context, | 85 CdmContext* cdm_context, |
| 85 const SelectDecoderCB& select_decoder_cb, | 86 const SelectDecoderCB& select_decoder_cb, |
| 86 const typename Decoder::OutputCB& output_cb, | 87 const typename Decoder::OutputCB& output_cb, |
| 87 const base::Closure& waiting_for_decryption_key_cb) { | 88 const base::Closure& waiting_for_decryption_key_cb) { |
| 88 DVLOG(2) << __FUNCTION__; | 89 DVLOG(2) << __FUNCTION__; |
| 89 DCHECK(task_runner_->BelongsToCurrentThread()); | 90 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 91 DCHECK(traits); |
| 90 DCHECK(stream); | 92 DCHECK(stream); |
| 91 DCHECK(select_decoder_cb_.is_null()); | 93 DCHECK(select_decoder_cb_.is_null()); |
| 92 | 94 |
| 93 cdm_context_ = cdm_context; | 95 cdm_context_ = cdm_context; |
| 94 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; | 96 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; |
| 95 | 97 |
| 96 // Make sure |select_decoder_cb| runs on a different execution stack. | 98 // Make sure |select_decoder_cb| runs on a different execution stack. |
| 97 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); | 99 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); |
| 98 | 100 |
| 99 if (!HasValidStreamConfig(stream)) { | 101 if (!HasValidStreamConfig(stream)) { |
| 100 DLOG(ERROR) << "Invalid stream config."; | 102 DLOG(ERROR) << "Invalid stream config."; |
| 101 ReturnNullDecoder(); | 103 ReturnNullDecoder(); |
| 102 return; | 104 return; |
| 103 } | 105 } |
| 104 | 106 |
| 107 traits_ = traits; |
| 105 input_stream_ = stream; | 108 input_stream_ = stream; |
| 106 output_cb_ = output_cb; | 109 output_cb_ = output_cb; |
| 107 | 110 |
| 108 if (!IsStreamEncrypted(input_stream_)) { | 111 if (!IsStreamEncrypted(input_stream_)) { |
| 109 InitializeDecoder(); | 112 InitializeDecoder(); |
| 110 return; | 113 return; |
| 111 } | 114 } |
| 112 | 115 |
| 113 // This could be null during fallback after decoder reinitialization failure. | 116 // This could be null during fallback after decoder reinitialization failure. |
| 114 // See DecoderStream<StreamType>::OnDecoderReinitialized(). | 117 // See DecoderStream<StreamType>::OnDecoderReinitialized(). |
| 115 if (!cdm_context_) { | 118 if (!cdm_context_) { |
| 116 ReturnNullDecoder(); | 119 ReturnNullDecoder(); |
| 117 return; | 120 return; |
| 118 } | 121 } |
| 119 | 122 |
| 120 #if !defined(OS_ANDROID) | 123 #if !defined(OS_ANDROID) |
| 121 InitializeDecryptingDecoder(); | 124 InitializeDecryptingDecoder(); |
| 122 #else | 125 #else |
| 123 InitializeDecryptingDemuxerStream(); | 126 InitializeDecryptingDemuxerStream(); |
| 124 #endif | 127 #endif |
| 125 } | 128 } |
| 126 | 129 |
| 127 #if !defined(OS_ANDROID) | 130 #if !defined(OS_ANDROID) |
| 128 template <DemuxerStream::Type StreamType> | 131 template <DemuxerStream::Type StreamType> |
| 129 void DecoderSelector<StreamType>::InitializeDecryptingDecoder() { | 132 void DecoderSelector<StreamType>::InitializeDecryptingDecoder() { |
| 130 DVLOG(2) << __FUNCTION__; | 133 DVLOG(2) << __FUNCTION__; |
| 131 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( | 134 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( |
| 132 task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 135 task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
| 133 | 136 |
| 134 DecoderStreamTraits<StreamType>::InitializeDecoder( | 137 traits_->InitializeDecoder( |
| 135 decoder_.get(), input_stream_, cdm_context_, | 138 decoder_.get(), input_stream_, cdm_context_, |
| 136 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, | 139 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, |
| 137 weak_ptr_factory_.GetWeakPtr()), | 140 weak_ptr_factory_.GetWeakPtr()), |
| 138 output_cb_); | 141 output_cb_); |
| 139 } | 142 } |
| 140 | 143 |
| 141 template <DemuxerStream::Type StreamType> | 144 template <DemuxerStream::Type StreamType> |
| 142 void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) { | 145 void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) { |
| 143 DVLOG(2) << __FUNCTION__; | 146 DVLOG(2) << __FUNCTION__; |
| 144 DCHECK(task_runner_->BelongsToCurrentThread()); | 147 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 DCHECK(!decoder_); | 200 DCHECK(!decoder_); |
| 198 | 201 |
| 199 if (decoders_.empty()) { | 202 if (decoders_.empty()) { |
| 200 ReturnNullDecoder(); | 203 ReturnNullDecoder(); |
| 201 return; | 204 return; |
| 202 } | 205 } |
| 203 | 206 |
| 204 decoder_.reset(decoders_.front()); | 207 decoder_.reset(decoders_.front()); |
| 205 decoders_.weak_erase(decoders_.begin()); | 208 decoders_.weak_erase(decoders_.begin()); |
| 206 | 209 |
| 207 DecoderStreamTraits<StreamType>::InitializeDecoder( | 210 traits_->InitializeDecoder( |
| 208 decoder_.get(), input_stream_, cdm_context_, | 211 decoder_.get(), input_stream_, cdm_context_, |
| 209 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, | 212 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, |
| 210 weak_ptr_factory_.GetWeakPtr()), | 213 weak_ptr_factory_.GetWeakPtr()), |
| 211 output_cb_); | 214 output_cb_); |
| 212 } | 215 } |
| 213 | 216 |
| 214 template <DemuxerStream::Type StreamType> | 217 template <DemuxerStream::Type StreamType> |
| 215 void DecoderSelector<StreamType>::DecoderInitDone(bool success) { | 218 void DecoderSelector<StreamType>::DecoderInitDone(bool success) { |
| 216 DVLOG(2) << __FUNCTION__; | 219 DVLOG(2) << __FUNCTION__; |
| 217 DCHECK(task_runner_->BelongsToCurrentThread()); | 220 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 237 | 240 |
| 238 // These forward declarations tell the compiler that we will use | 241 // These forward declarations tell the compiler that we will use |
| 239 // DecoderSelector with these arguments, allowing us to keep these definitions | 242 // DecoderSelector with these arguments, allowing us to keep these definitions |
| 240 // in our .cc without causing linker errors. This also means if anyone tries to | 243 // in our .cc without causing linker errors. This also means if anyone tries to |
| 241 // instantiate a DecoderSelector with anything but these two specializations | 244 // instantiate a DecoderSelector with anything but these two specializations |
| 242 // they'll most likely get linker errors. | 245 // they'll most likely get linker errors. |
| 243 template class DecoderSelector<DemuxerStream::AUDIO>; | 246 template class DecoderSelector<DemuxerStream::AUDIO>; |
| 244 template class DecoderSelector<DemuxerStream::VIDEO>; | 247 template class DecoderSelector<DemuxerStream::VIDEO>; |
| 245 | 248 |
| 246 } // namespace media | 249 } // namespace media |
| OLD | NEW |