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() { |
130 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( | 131 decoder_.reset(new typename StreamTraits::DecryptingDecoderType( |
131 task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 132 task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
132 | 133 |
133 DecoderStreamTraits<StreamType>::InitializeDecoder( | 134 DecoderStreamTraits<StreamType>::InitializeDecoder( |
134 decoder_.get(), input_stream_, set_cdm_ready_cb_, | 135 decoder_.get(), input_stream_, cdm_context_, |
135 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, | 136 base::Bind(&DecoderSelector<StreamType>::DecryptingDecoderInitDone, |
136 weak_ptr_factory_.GetWeakPtr()), | 137 weak_ptr_factory_.GetWeakPtr()), |
137 output_cb_); | 138 output_cb_); |
138 } | 139 } |
139 | 140 |
140 template <DemuxerStream::Type StreamType> | 141 template <DemuxerStream::Type StreamType> |
141 void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) { | 142 void DecoderSelector<StreamType>::DecryptingDecoderInitDone(bool success) { |
142 DVLOG(2) << __FUNCTION__; | 143 DVLOG(2) << __FUNCTION__; |
143 DCHECK(task_runner_->BelongsToCurrentThread()); | 144 DCHECK(task_runner_->BelongsToCurrentThread()); |
144 | 145 |
(...skipping 10 matching lines...) Expand all Loading... |
155 InitializeDecryptingDemuxerStream(); | 156 InitializeDecryptingDemuxerStream(); |
156 } | 157 } |
157 #endif // !defined(OS_ANDROID) | 158 #endif // !defined(OS_ANDROID) |
158 | 159 |
159 template <DemuxerStream::Type StreamType> | 160 template <DemuxerStream::Type StreamType> |
160 void DecoderSelector<StreamType>::InitializeDecryptingDemuxerStream() { | 161 void DecoderSelector<StreamType>::InitializeDecryptingDemuxerStream() { |
161 decrypted_stream_.reset(new DecryptingDemuxerStream( | 162 decrypted_stream_.reset(new DecryptingDemuxerStream( |
162 task_runner_, media_log_, waiting_for_decryption_key_cb_)); | 163 task_runner_, media_log_, waiting_for_decryption_key_cb_)); |
163 | 164 |
164 decrypted_stream_->Initialize( | 165 decrypted_stream_->Initialize( |
165 input_stream_, set_cdm_ready_cb_, | 166 input_stream_, cdm_context_, |
166 base::Bind(&DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone, | 167 base::Bind(&DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone, |
167 weak_ptr_factory_.GetWeakPtr())); | 168 weak_ptr_factory_.GetWeakPtr())); |
168 } | 169 } |
169 | 170 |
170 template <DemuxerStream::Type StreamType> | 171 template <DemuxerStream::Type StreamType> |
171 void DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone( | 172 void DecoderSelector<StreamType>::DecryptingDemuxerStreamInitDone( |
172 PipelineStatus status) { | 173 PipelineStatus status) { |
173 DVLOG(2) << __FUNCTION__; | 174 DVLOG(2) << __FUNCTION__; |
174 DCHECK(task_runner_->BelongsToCurrentThread()); | 175 DCHECK(task_runner_->BelongsToCurrentThread()); |
175 | 176 |
(...skipping 21 matching lines...) Expand all Loading... |
197 | 198 |
198 if (decoders_.empty()) { | 199 if (decoders_.empty()) { |
199 ReturnNullDecoder(); | 200 ReturnNullDecoder(); |
200 return; | 201 return; |
201 } | 202 } |
202 | 203 |
203 decoder_.reset(decoders_.front()); | 204 decoder_.reset(decoders_.front()); |
204 decoders_.weak_erase(decoders_.begin()); | 205 decoders_.weak_erase(decoders_.begin()); |
205 | 206 |
206 DecoderStreamTraits<StreamType>::InitializeDecoder( | 207 DecoderStreamTraits<StreamType>::InitializeDecoder( |
207 decoder_.get(), input_stream_, set_cdm_ready_cb_, | 208 decoder_.get(), input_stream_, cdm_context_, |
208 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, | 209 base::Bind(&DecoderSelector<StreamType>::DecoderInitDone, |
209 weak_ptr_factory_.GetWeakPtr()), | 210 weak_ptr_factory_.GetWeakPtr()), |
210 output_cb_); | 211 output_cb_); |
211 } | 212 } |
212 | 213 |
213 template <DemuxerStream::Type StreamType> | 214 template <DemuxerStream::Type StreamType> |
214 void DecoderSelector<StreamType>::DecoderInitDone(bool success) { | 215 void DecoderSelector<StreamType>::DecoderInitDone(bool success) { |
215 DVLOG(2) << __FUNCTION__; | 216 DVLOG(2) << __FUNCTION__; |
216 DCHECK(task_runner_->BelongsToCurrentThread()); | 217 DCHECK(task_runner_->BelongsToCurrentThread()); |
217 | 218 |
(...skipping 18 matching lines...) Expand all Loading... |
236 | 237 |
237 // These forward declarations tell the compiler that we will use | 238 // These forward declarations tell the compiler that we will use |
238 // DecoderSelector with these arguments, allowing us to keep these definitions | 239 // 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 | 240 // in our .cc without causing linker errors. This also means if anyone tries to |
240 // instantiate a DecoderSelector with anything but these two specializations | 241 // instantiate a DecoderSelector with anything but these two specializations |
241 // they'll most likely get linker errors. | 242 // they'll most likely get linker errors. |
242 template class DecoderSelector<DemuxerStream::AUDIO>; | 243 template class DecoderSelector<DemuxerStream::AUDIO>; |
243 template class DecoderSelector<DemuxerStream::VIDEO>; | 244 template class DecoderSelector<DemuxerStream::VIDEO>; |
244 | 245 |
245 } // namespace media | 246 } // namespace media |
OLD | NEW |