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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "media/base/audio_decoder.h" | 14 #include "media/base/audio_decoder.h" |
15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/cdm_context.h" |
16 #include "media/base/demuxer_stream.h" | 17 #include "media/base/demuxer_stream.h" |
17 #include "media/base/media_log.h" | 18 #include "media/base/media_log.h" |
18 #include "media/base/pipeline.h" | 19 #include "media/base/pipeline.h" |
19 #include "media/base/video_decoder.h" | 20 #include "media/base/video_decoder.h" |
20 #include "media/filters/decoder_stream_traits.h" | 21 #include "media/filters/decoder_stream_traits.h" |
21 #include "media/filters/decrypting_demuxer_stream.h" | 22 #include "media/filters/decrypting_demuxer_stream.h" |
22 | 23 |
23 #if !defined(OS_ANDROID) | 24 #if !defined(OS_ANDROID) |
24 #include "media/filters/decrypting_audio_decoder.h" | 25 #include "media/filters/decrypting_audio_decoder.h" |
25 #include "media/filters/decrypting_video_decoder.h" | 26 #include "media/filters/decrypting_video_decoder.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (!select_decoder_cb_.is_null()) | 75 if (!select_decoder_cb_.is_null()) |
75 ReturnNullDecoder(); | 76 ReturnNullDecoder(); |
76 | 77 |
77 decoder_.reset(); | 78 decoder_.reset(); |
78 decrypted_stream_.reset(); | 79 decrypted_stream_.reset(); |
79 } | 80 } |
80 | 81 |
81 template <DemuxerStream::Type StreamType> | 82 template <DemuxerStream::Type StreamType> |
82 void DecoderSelector<StreamType>::SelectDecoder( | 83 void DecoderSelector<StreamType>::SelectDecoder( |
83 DemuxerStream* stream, | 84 DemuxerStream* stream, |
84 const SetCdmReadyCB& set_cdm_ready_cb, | 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()); |
90 DCHECK(stream); | 91 DCHECK(stream); |
91 DCHECK(select_decoder_cb_.is_null()); | 92 DCHECK(select_decoder_cb_.is_null()); |
92 | 93 |
93 set_cdm_ready_cb_ = set_cdm_ready_cb; | 94 cdm_context_ = cdm_context; |
94 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; | 95 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb; |
95 | 96 |
96 // Make sure |select_decoder_cb| runs on a different execution stack. | 97 // Make sure |select_decoder_cb| runs on a different execution stack. |
97 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); | 98 select_decoder_cb_ = BindToCurrentLoop(select_decoder_cb); |
98 | 99 |
99 if (!HasValidStreamConfig(stream)) { | 100 if (!HasValidStreamConfig(stream)) { |
100 DLOG(ERROR) << "Invalid stream config."; | 101 DLOG(ERROR) << "Invalid stream config."; |
101 ReturnNullDecoder(); | 102 ReturnNullDecoder(); |
102 return; | 103 return; |
103 } | 104 } |
104 | 105 |
105 input_stream_ = stream; | 106 input_stream_ = stream; |
106 output_cb_ = output_cb; | 107 output_cb_ = output_cb; |
107 | 108 |
108 if (!IsStreamEncrypted(input_stream_)) { | 109 if (!IsStreamEncrypted(input_stream_)) { |
109 InitializeDecoder(); | 110 InitializeDecoder(); |
110 return; | 111 return; |
111 } | 112 } |
112 | 113 |
113 // This could be null during fallback after decoder reinitialization failure. | 114 // This could be null during fallback after decoder reinitialization failure. |
114 // See DecoderStream<StreamType>::OnDecoderReinitialized(). | 115 // See DecoderStream<StreamType>::OnDecoderReinitialized(). |
115 if (set_cdm_ready_cb_.is_null()) { | 116 if (!cdm_context_) { |
116 ReturnNullDecoder(); | 117 ReturnNullDecoder(); |
117 return; | 118 return; |
118 } | 119 } |
119 | 120 |
120 #if !defined(OS_ANDROID) | 121 #if !defined(OS_ANDROID) |
121 InitializeDecryptingDecoder(); | 122 InitializeDecryptingDecoder(); |
122 #else | 123 #else |
123 InitializeDecryptingDemuxerStream(); | 124 InitializeDecryptingDemuxerStream(); |
124 #endif | 125 #endif |
125 } | 126 } |
126 | 127 |
127 #if !defined(OS_ANDROID) | 128 #if !defined(OS_ANDROID) |
128 template <DemuxerStream::Type StreamType> | 129 template <DemuxerStream::Type StreamType> |
129 void DecoderSelector<StreamType>::InitializeDecryptingDecoder() { | 130 void DecoderSelector<StreamType>::InitializeDecryptingDecoder() { |
| 131 DVLOG(2) << __FUNCTION__; |
130 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( | 132 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( |
131 task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 133 task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
132 | 134 |
133 DecoderStreamTraits<StreamType>::InitializeDecoder( | 135 DecoderStreamTraits<StreamType>::InitializeDecoder( |
134 decoder_.get(), input_stream_, set_cdm_ready_cb_, | 136 decoder_.get(), input_stream_, cdm_context_, |
135 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, | 137 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, |
136 weak_ptr_factory_.GetWeakPtr()), | 138 weak_ptr_factory_.GetWeakPtr()), |
137 output_cb_); | 139 output_cb_); |
138 } | 140 } |
139 | 141 |
140 template <DemuxerStream::Type StreamType> | 142 template <DemuxerStream::Type StreamType> |
141 void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) { | 143 void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) { |
142 DVLOG(2) << __FUNCTION__; | 144 DVLOG(2) << __FUNCTION__; |
143 DCHECK(task_runner_->BelongsToCurrentThread()); | 145 DCHECK(task_runner_->BelongsToCurrentThread()); |
144 | 146 |
145 if (success) { | 147 if (success) { |
146 base::ResetAndReturn(&select_decoder_cb_) | 148 base::ResetAndReturn(&select_decoder_cb_) |
147 .Run(std::move(decoder_), scoped_ptr<DecryptingDemuxerStream>()); | 149 .Run(std::move(decoder_), scoped_ptr<DecryptingDemuxerStream>()); |
148 return; | 150 return; |
149 } | 151 } |
150 | 152 |
151 decoder_.reset(); | 153 decoder_.reset(); |
152 | 154 |
153 // When we get here decrypt-and-decode is not supported. Try to use | 155 // When we get here decrypt-and-decode is not supported. Try to use |
154 // DecryptingDemuxerStream to do decrypt-only. | 156 // DecryptingDemuxerStream to do decrypt-only. |
155 InitializeDecryptingDemuxerStream(); | 157 InitializeDecryptingDemuxerStream(); |
156 } | 158 } |
157 #endif // !defined(OS_ANDROID) | 159 #endif // !defined(OS_ANDROID) |
158 | 160 |
159 template <DemuxerStream::Type StreamType> | 161 template <DemuxerStream::Type StreamType> |
| 162 void DecoderSelector<StreamType>::SetCdmReadyCallback( |
| 163 const CdmReadyCB& cdm_ready_cb) { |
| 164 DCHECK(cdm_context_); |
| 165 cdm_ready_cb.Run(cdm_context_, base::Bind(IgnoreCdmAttached)); |
| 166 } |
| 167 |
| 168 template <DemuxerStream::Type StreamType> |
160 void DecoderSelector<StreamType>::InitializeDecryptingDemuxerStream() { | 169 void DecoderSelector<StreamType>::InitializeDecryptingDemuxerStream() { |
161 decrypted_stream_.reset(new DecryptingDemuxerStream( | 170 decrypted_stream_.reset(new DecryptingDemuxerStream( |
162 task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 171 task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
163 | 172 |
| 173 // TODO(xhwang): Fix DecryptingDemuxerStream::Initialize() to take |
| 174 // |cdm_context_| directly. |
164 decrypted_stream_->Initialize( | 175 decrypted_stream_->Initialize( |
165 input_stream_, set_cdm_ready_cb_, | 176 input_stream_, |
| 177 base::Bind(&DecoderSelector<StreamType>::SetCdmReadyCallback, |
| 178 weak_ptr_factory_.GetWeakPtr()), |
166 base::Bind(&DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone, | 179 base::Bind(&DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone, |
167 weak_ptr_factory_.GetWeakPtr())); | 180 weak_ptr_factory_.GetWeakPtr())); |
168 } | 181 } |
169 | 182 |
170 template <DemuxerStream::Type StreamType> | 183 template <DemuxerStream::Type StreamType> |
171 void DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone( | 184 void DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone( |
172 PipelineStatus status) { | 185 PipelineStatus status) { |
173 DVLOG(2) << __FUNCTION__; | 186 DVLOG(2) << __FUNCTION__; |
174 DCHECK(task_runner_->BelongsToCurrentThread()); | 187 DCHECK(task_runner_->BelongsToCurrentThread()); |
175 | 188 |
(...skipping 21 matching lines...) Expand all Loading... |
197 | 210 |
198 if (decoders_.empty()) { | 211 if (decoders_.empty()) { |
199 ReturnNullDecoder(); | 212 ReturnNullDecoder(); |
200 return; | 213 return; |
201 } | 214 } |
202 | 215 |
203 decoder_.reset(decoders_.front()); | 216 decoder_.reset(decoders_.front()); |
204 decoders_.weak_erase(decoders_.begin()); | 217 decoders_.weak_erase(decoders_.begin()); |
205 | 218 |
206 DecoderStreamTraits<StreamType>::InitializeDecoder( | 219 DecoderStreamTraits<StreamType>::InitializeDecoder( |
207 decoder_.get(), input_stream_, set_cdm_ready_cb_, | 220 decoder_.get(), input_stream_, cdm_context_, |
208 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, | 221 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, |
209 weak_ptr_factory_.GetWeakPtr()), | 222 weak_ptr_factory_.GetWeakPtr()), |
210 output_cb_); | 223 output_cb_); |
211 } | 224 } |
212 | 225 |
213 template <DemuxerStream::Type StreamType> | 226 template <DemuxerStream::Type StreamType> |
214 void DecoderSelector<StreamType>::DecoderInitDone(bool success) { | 227 void DecoderSelector<StreamType>::DecoderInitDone(bool success) { |
215 DVLOG(2) << __FUNCTION__; | 228 DVLOG(2) << __FUNCTION__; |
216 DCHECK(task_runner_->BelongsToCurrentThread()); | 229 DCHECK(task_runner_->BelongsToCurrentThread()); |
217 | 230 |
(...skipping 18 matching lines...) Expand all Loading... |
236 | 249 |
237 // These forward declarations tell the compiler that we will use | 250 // These forward declarations tell the compiler that we will use |
238 // DecoderSelector with these arguments, allowing us to keep these definitions | 251 // DecoderSelector with these arguments, allowing us to keep these definitions |
239 // in our .cc without causing linker errors. This also means if anyone tries to | 252 // in our .cc without causing linker errors. This also means if anyone tries to |
240 // instantiate a DecoderSelector with anything but these two specializations | 253 // instantiate a DecoderSelector with anything but these two specializations |
241 // they'll most likely get linker errors. | 254 // they'll most likely get linker errors. |
242 template class DecoderSelector<DemuxerStream::AUDIO>; | 255 template class DecoderSelector<DemuxerStream::AUDIO>; |
243 template class DecoderSelector<DemuxerStream::VIDEO>; | 256 template class DecoderSelector<DemuxerStream::VIDEO>; |
244 | 257 |
245 } // namespace media | 258 } // namespace media |
OLD | NEW |