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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. | 187 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. |
188 DCHECK(read_cb_.is_null()); // No Read() before initialization finished. | 188 DCHECK(read_cb_.is_null()); // No Read() before initialization finished. |
189 | 189 |
190 if (!success) { | 190 if (!success) { |
191 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 191 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
192 state_ = kDecodeFinished; | 192 state_ = kDecodeFinished; |
193 return; | 193 return; |
194 } | 194 } |
195 | 195 |
196 // Success! | 196 // Success! |
197 const AudioDecoderConfig& config = demuxer_stream_->audio_decoder_config(); | 197 UpdateDecoderConfig(); |
198 bits_per_channel_ = config.bits_per_channel(); | |
199 channel_layout_ = config.channel_layout(); | |
200 samples_per_second_ = config.samples_per_second(); | |
201 const int kBitsPerByte = 8; | |
202 bytes_per_sample_ = ChannelLayoutToChannelCount(channel_layout_) * | |
203 bits_per_channel_ / kBitsPerByte; | |
204 | 198 |
205 decryptor_->RegisterNewKeyCB( | 199 decryptor_->RegisterNewKeyCB( |
206 Decryptor::kAudio, BIND_TO_LOOP(&DecryptingAudioDecoder::OnKeyAdded)); | 200 Decryptor::kAudio, BIND_TO_LOOP(&DecryptingAudioDecoder::OnKeyAdded)); |
207 | 201 |
208 state_ = kIdle; | 202 state_ = kIdle; |
209 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 203 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
210 } | 204 } |
211 | 205 |
212 void DecryptingAudioDecoder::FinishConfigChange(bool success) { | 206 void DecryptingAudioDecoder::FinishConfigChange(bool success) { |
213 DVLOG(2) << "FinishConfigChange()"; | 207 DVLOG(2) << "FinishConfigChange()"; |
214 DCHECK(message_loop_->BelongsToCurrentThread()); | 208 DCHECK(message_loop_->BelongsToCurrentThread()); |
215 DCHECK_EQ(state_, kPendingConfigChange) << state_; | 209 DCHECK_EQ(state_, kPendingConfigChange) << state_; |
216 DCHECK(!read_cb_.is_null()); | 210 DCHECK(!read_cb_.is_null()); |
217 | 211 |
218 if (!success) { | 212 if (!success) { |
219 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | 213 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
220 state_ = kDecodeFinished; | 214 state_ = kDecodeFinished; |
221 if (!reset_cb_.is_null()) | 215 if (!reset_cb_.is_null()) |
222 base::ResetAndReturn(&reset_cb_).Run(); | 216 base::ResetAndReturn(&reset_cb_).Run(); |
223 return; | 217 return; |
224 } | 218 } |
225 | 219 |
226 // Config change succeeded. | 220 // Config change succeeded. |
| 221 UpdateDecoderConfig(); |
| 222 |
227 if (!reset_cb_.is_null()) { | 223 if (!reset_cb_.is_null()) { |
228 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 224 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
229 DoReset(); | 225 DoReset(); |
230 return; | 226 return; |
231 } | 227 } |
232 | 228 |
233 state_ = kPendingDemuxerRead; | 229 state_ = kPendingDemuxerRead; |
234 ReadFromDemuxerStream(); | 230 ReadFromDemuxerStream(); |
235 } | 231 } |
236 | 232 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 436 |
441 void DecryptingAudioDecoder::DoReset() { | 437 void DecryptingAudioDecoder::DoReset() { |
442 DCHECK(init_cb_.is_null()); | 438 DCHECK(init_cb_.is_null()); |
443 DCHECK(read_cb_.is_null()); | 439 DCHECK(read_cb_.is_null()); |
444 output_timestamp_base_ = kNoTimestamp(); | 440 output_timestamp_base_ = kNoTimestamp(); |
445 total_samples_decoded_ = 0; | 441 total_samples_decoded_ = 0; |
446 state_ = kIdle; | 442 state_ = kIdle; |
447 base::ResetAndReturn(&reset_cb_).Run(); | 443 base::ResetAndReturn(&reset_cb_).Run(); |
448 } | 444 } |
449 | 445 |
| 446 void DecryptingAudioDecoder::UpdateDecoderConfig() { |
| 447 const AudioDecoderConfig& config = demuxer_stream_->audio_decoder_config(); |
| 448 bits_per_channel_ = config.bits_per_channel(); |
| 449 channel_layout_ = config.channel_layout(); |
| 450 samples_per_second_ = config.samples_per_second(); |
| 451 const int kBitsPerByte = 8; |
| 452 bytes_per_sample_ = ChannelLayoutToChannelCount(channel_layout_) * |
| 453 bits_per_channel_ / kBitsPerByte; |
| 454 output_timestamp_base_ = kNoTimestamp(); |
| 455 total_samples_decoded_ = 0; |
| 456 } |
| 457 |
450 void DecryptingAudioDecoder::EnqueueFrames( | 458 void DecryptingAudioDecoder::EnqueueFrames( |
451 const Decryptor::AudioBuffers& frames) { | 459 const Decryptor::AudioBuffers& frames) { |
452 queued_audio_frames_ = frames; | 460 queued_audio_frames_ = frames; |
453 | 461 |
454 for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin(); | 462 for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin(); |
455 iter != queued_audio_frames_.end(); | 463 iter != queued_audio_frames_.end(); |
456 ++iter) { | 464 ++iter) { |
457 scoped_refptr<Buffer>& frame = *iter; | 465 scoped_refptr<Buffer>& frame = *iter; |
458 | 466 |
459 DCHECK(!frame->IsEndOfStream()) << "EOS frame returned."; | 467 DCHECK(!frame->IsEndOfStream()) << "EOS frame returned."; |
(...skipping 24 matching lines...) Expand all Loading... |
484 | 492 |
485 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( | 493 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( |
486 int number_of_samples) const { | 494 int number_of_samples) const { |
487 DCHECK(samples_per_second_); | 495 DCHECK(samples_per_second_); |
488 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | 496 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * |
489 number_of_samples / | 497 number_of_samples / |
490 samples_per_second_); | 498 samples_per_second_); |
491 } | 499 } |
492 | 500 |
493 } // namespace media | 501 } // namespace media |
OLD | NEW |