| 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 "decoder_selector.h" | 5 #include "decoder_selector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 template <DemuxerStream::Type StreamType> | 62 template <DemuxerStream::Type StreamType> |
| 63 DecoderSelector<StreamType>::~DecoderSelector() { | 63 DecoderSelector<StreamType>::~DecoderSelector() { |
| 64 DVLOG(2) << __FUNCTION__; | 64 DVLOG(2) << __FUNCTION__; |
| 65 DCHECK(select_decoder_cb_.is_null()); | 65 DCHECK(select_decoder_cb_.is_null()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 template <DemuxerStream::Type StreamType> | 68 template <DemuxerStream::Type StreamType> |
| 69 void DecoderSelector<StreamType>::SelectDecoder( | 69 void DecoderSelector<StreamType>::SelectDecoder( |
| 70 DemuxerStream* stream, | 70 DemuxerStream* stream, |
| 71 bool low_delay, | 71 bool low_delay, |
| 72 const SelectDecoderCB& select_decoder_cb) { | 72 const SelectDecoderCB& select_decoder_cb, |
| 73 const typename Decoder::OutputCB& output_cb) { |
| 73 DVLOG(2) << __FUNCTION__; | 74 DVLOG(2) << __FUNCTION__; |
| 74 DCHECK(task_runner_->BelongsToCurrentThread()); | 75 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 75 DCHECK(stream); | 76 DCHECK(stream); |
| 76 | 77 |
| 77 // Make sure |select_decoder_cb| runs on a different execution stack. | 78 // Make sure |select_decoder_cb| runs on a different execution stack. |
| 78 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); | 79 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); |
| 79 | 80 |
| 80 if (!HasValidStreamConfig(stream)) { | 81 if (!HasValidStreamConfig(stream)) { |
| 81 DLOG(ERROR) << "Invalid stream config."; | 82 DLOG(ERROR) << "Invalid stream config."; |
| 82 ReturnNullDecoder(); | 83 ReturnNullDecoder(); |
| 83 return; | 84 return; |
| 84 } | 85 } |
| 85 | 86 |
| 86 input_stream_ = stream; | 87 input_stream_ = stream; |
| 87 low_delay_ = low_delay; | 88 low_delay_ = low_delay; |
| 89 output_cb_ = output_cb; |
| 88 | 90 |
| 89 if (!IsStreamEncrypted(input_stream_)) { | 91 if (!IsStreamEncrypted(input_stream_)) { |
| 90 InitializeDecoder(); | 92 InitializeDecoder(); |
| 91 return; | 93 return; |
| 92 } | 94 } |
| 93 | 95 |
| 94 // This could happen if Encrypted Media Extension (EME) is not enabled. | 96 // This could happen if Encrypted Media Extension (EME) is not enabled. |
| 95 if (set_decryptor_ready_cb_.is_null()) { | 97 if (set_decryptor_ready_cb_.is_null()) { |
| 96 ReturnNullDecoder(); | 98 ReturnNullDecoder(); |
| 97 return; | 99 return; |
| 98 } | 100 } |
| 99 | 101 |
| 100 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( | 102 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( |
| 101 task_runner_, set_decryptor_ready_cb_)); | 103 task_runner_, set_decryptor_ready_cb_)); |
| 102 | 104 |
| 103 DecoderStreamTraits<StreamType>::Initialize( | 105 DecoderStreamTraits<StreamType>::Initialize( |
| 104 decoder_.get(), | 106 decoder_.get(), |
| 105 StreamTraits::GetDecoderConfig(*input_stream_), | 107 StreamTraits::GetDecoderConfig(*input_stream_), |
| 106 low_delay_, | 108 low_delay_, |
| 107 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, | 109 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, |
| 108 weak_ptr_factory_.GetWeakPtr())); | 110 weak_ptr_factory_.GetWeakPtr()), |
| 111 output_cb_); |
| 109 } | 112 } |
| 110 | 113 |
| 111 template <DemuxerStream::Type StreamType> | 114 template <DemuxerStream::Type StreamType> |
| 112 void DecoderSelector<StreamType>::Abort() { | 115 void DecoderSelector<StreamType>::Abort() { |
| 113 DVLOG(2) << __FUNCTION__; | 116 DVLOG(2) << __FUNCTION__; |
| 114 DCHECK(task_runner_->BelongsToCurrentThread()); | 117 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 115 | 118 |
| 116 // This could happen when SelectDecoder() was not called or when | 119 // This could happen when SelectDecoder() was not called or when |
| 117 // |select_decoder_cb_| was already posted but not fired (e.g. in the | 120 // |select_decoder_cb_| was already posted but not fired (e.g. in the |
| 118 // message loop queue). | 121 // message loop queue). |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 196 } |
| 194 | 197 |
| 195 decoder_.reset(decoders_.front()); | 198 decoder_.reset(decoders_.front()); |
| 196 decoders_.weak_erase(decoders_.begin()); | 199 decoders_.weak_erase(decoders_.begin()); |
| 197 | 200 |
| 198 DecoderStreamTraits<StreamType>::Initialize( | 201 DecoderStreamTraits<StreamType>::Initialize( |
| 199 decoder_.get(), | 202 decoder_.get(), |
| 200 StreamTraits::GetDecoderConfig(*input_stream_), | 203 StreamTraits::GetDecoderConfig(*input_stream_), |
| 201 low_delay_, | 204 low_delay_, |
| 202 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, | 205 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, |
| 203 weak_ptr_factory_.GetWeakPtr())); | 206 weak_ptr_factory_.GetWeakPtr()), |
| 207 output_cb_); |
| 204 } | 208 } |
| 205 | 209 |
| 206 template <DemuxerStream::Type StreamType> | 210 template <DemuxerStream::Type StreamType> |
| 207 void DecoderSelector<StreamType>::DecoderInitDone(PipelineStatus status) { | 211 void DecoderSelector<StreamType>::DecoderInitDone(PipelineStatus status) { |
| 208 DVLOG(2) << __FUNCTION__; | 212 DVLOG(2) << __FUNCTION__; |
| 209 DCHECK(task_runner_->BelongsToCurrentThread()); | 213 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 210 | 214 |
| 211 if (status != PIPELINE_OK) { | 215 if (status != PIPELINE_OK) { |
| 212 decoder_.reset(); | 216 decoder_.reset(); |
| 213 InitializeDecoder(); | 217 InitializeDecoder(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 229 | 233 |
| 230 // These forward declarations tell the compiler that we will use | 234 // These forward declarations tell the compiler that we will use |
| 231 // DecoderSelector with these arguments, allowing us to keep these definitions | 235 // DecoderSelector with these arguments, allowing us to keep these definitions |
| 232 // in our .cc without causing linker errors. This also means if anyone tries to | 236 // in our .cc without causing linker errors. This also means if anyone tries to |
| 233 // instantiate a DecoderSelector with anything but these two specializations | 237 // instantiate a DecoderSelector with anything but these two specializations |
| 234 // they'll most likely get linker errors. | 238 // they'll most likely get linker errors. |
| 235 template class DecoderSelector<DemuxerStream::AUDIO>; | 239 template class DecoderSelector<DemuxerStream::AUDIO>; |
| 236 template class DecoderSelector<DemuxerStream::VIDEO>; | 240 template class DecoderSelector<DemuxerStream::VIDEO>; |
| 237 | 241 |
| 238 } // namespace media | 242 } // namespace media |
| OLD | NEW |