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