OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/decrypting_audio_decoder.h" | 5 #include "media/filters/decrypting_audio_decoder.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 DCHECK(message_loop_->BelongsToCurrentThread()); | 167 DCHECK(message_loop_->BelongsToCurrentThread()); |
168 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 168 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
169 DCHECK(!init_cb_.is_null()); | 169 DCHECK(!init_cb_.is_null()); |
170 DCHECK(!set_decryptor_ready_cb_.is_null()); | 170 DCHECK(!set_decryptor_ready_cb_.is_null()); |
171 | 171 |
172 set_decryptor_ready_cb_.Reset(); | 172 set_decryptor_ready_cb_.Reset(); |
173 decryptor_ = decryptor; | 173 decryptor_ = decryptor; |
174 | 174 |
175 const AudioDecoderConfig& input_config = | 175 const AudioDecoderConfig& input_config = |
176 demuxer_stream_->audio_decoder_config(); | 176 demuxer_stream_->audio_decoder_config(); |
177 scoped_ptr<AudioDecoderConfig> scoped_config(new AudioDecoderConfig()); | 177 AudioDecoderConfig config; |
178 scoped_config->Initialize(input_config.codec(), | 178 config.Initialize(input_config.codec(), |
179 kSampleFormatS16, | 179 kSampleFormatS16, |
180 input_config.channel_layout(), | 180 input_config.channel_layout(), |
181 input_config.samples_per_second(), | 181 input_config.samples_per_second(), |
182 input_config.extra_data(), | 182 input_config.extra_data(), |
183 input_config.extra_data_size(), | 183 input_config.extra_data_size(), |
184 input_config.is_encrypted(), | 184 input_config.is_encrypted(), |
185 false); | 185 false); |
186 | 186 |
187 state_ = kPendingDecoderInit; | 187 state_ = kPendingDecoderInit; |
188 decryptor_->InitializeAudioDecoder( | 188 decryptor_->InitializeAudioDecoder( |
189 scoped_config.Pass(), | 189 config, |
190 BindToCurrentLoop(base::Bind( | 190 BindToCurrentLoop(base::Bind( |
191 &DecryptingAudioDecoder::FinishInitialization, this))); | 191 &DecryptingAudioDecoder::FinishInitialization, this))); |
192 } | 192 } |
193 | 193 |
194 void DecryptingAudioDecoder::FinishInitialization(bool success) { | 194 void DecryptingAudioDecoder::FinishInitialization(bool success) { |
195 DVLOG(2) << "FinishInitialization()"; | 195 DVLOG(2) << "FinishInitialization()"; |
196 DCHECK(message_loop_->BelongsToCurrentThread()); | 196 DCHECK(message_loop_->BelongsToCurrentThread()); |
197 DCHECK_EQ(state_, kPendingDecoderInit) << state_; | 197 DCHECK_EQ(state_, kPendingDecoderInit) << state_; |
198 DCHECK(!init_cb_.is_null()); | 198 DCHECK(!init_cb_.is_null()); |
199 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. | 199 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DCHECK(message_loop_->BelongsToCurrentThread()); | 258 DCHECK(message_loop_->BelongsToCurrentThread()); |
259 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 259 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; |
260 DCHECK(!read_cb_.is_null()); | 260 DCHECK(!read_cb_.is_null()); |
261 DCHECK_EQ(buffer != NULL, status == DemuxerStream::kOk) << status; | 261 DCHECK_EQ(buffer != NULL, status == DemuxerStream::kOk) << status; |
262 | 262 |
263 if (status == DemuxerStream::kConfigChanged) { | 263 if (status == DemuxerStream::kConfigChanged) { |
264 DVLOG(2) << "DecryptAndDecodeBuffer() - kConfigChanged"; | 264 DVLOG(2) << "DecryptAndDecodeBuffer() - kConfigChanged"; |
265 | 265 |
266 const AudioDecoderConfig& input_config = | 266 const AudioDecoderConfig& input_config = |
267 demuxer_stream_->audio_decoder_config(); | 267 demuxer_stream_->audio_decoder_config(); |
268 scoped_ptr<AudioDecoderConfig> scoped_config(new AudioDecoderConfig()); | 268 AudioDecoderConfig config; |
269 scoped_config->Initialize(input_config.codec(), | 269 config.Initialize(input_config.codec(), |
270 kSampleFormatS16, | 270 kSampleFormatS16, |
271 input_config.channel_layout(), | 271 input_config.channel_layout(), |
272 input_config.samples_per_second(), | 272 input_config.samples_per_second(), |
273 input_config.extra_data(), | 273 input_config.extra_data(), |
274 input_config.extra_data_size(), | 274 input_config.extra_data_size(), |
275 input_config.is_encrypted(), | 275 input_config.is_encrypted(), |
276 false); | 276 false); |
277 | 277 |
278 state_ = kPendingConfigChange; | 278 state_ = kPendingConfigChange; |
279 decryptor_->DeinitializeDecoder(Decryptor::kAudio); | 279 decryptor_->DeinitializeDecoder(Decryptor::kAudio); |
280 decryptor_->InitializeAudioDecoder( | 280 decryptor_->InitializeAudioDecoder( |
281 scoped_config.Pass(), BindToCurrentLoop(base::Bind( | 281 config, BindToCurrentLoop(base::Bind( |
282 &DecryptingAudioDecoder::FinishConfigChange, this))); | 282 &DecryptingAudioDecoder::FinishConfigChange, this))); |
283 return; | 283 return; |
284 } | 284 } |
285 | 285 |
286 if (!reset_cb_.is_null()) { | 286 if (!reset_cb_.is_null()) { |
287 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 287 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
288 DoReset(); | 288 DoReset(); |
289 return; | 289 return; |
290 } | 290 } |
291 | 291 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 487 |
488 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( | 488 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( |
489 int number_of_samples) const { | 489 int number_of_samples) const { |
490 DCHECK(samples_per_second_); | 490 DCHECK(samples_per_second_); |
491 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | 491 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * |
492 number_of_samples / | 492 number_of_samples / |
493 samples_per_second_); | 493 samples_per_second_); |
494 } | 494 } |
495 | 495 |
496 } // namespace media | 496 } // namespace media |
OLD | NEW |