| 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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
| 14 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
| 15 #include "media/base/bind_to_loop.h" | 15 #include "media/base/bind_to_loop.h" |
| 16 #include "media/base/buffers.h" | 16 #include "media/base/buffers.h" |
| 17 #include "media/base/data_buffer.h" | 17 #include "media/base/data_buffer.h" |
| 18 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
| 19 #include "media/base/decryptor.h" | 19 #include "media/base/decryptor.h" |
| 20 #include "media/base/demuxer_stream.h" | 20 #include "media/base/demuxer_stream.h" |
| 21 #include "media/base/pipeline.h" | 21 #include "media/base/pipeline.h" |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 #define BIND_TO_LOOP(function) \ | 25 #define BIND_TO_LOOP(function) \ |
| 26 media::BindToLoop(message_loop_, base::Bind(function, this)) | 26 media::BindToLoop(message_loop_, base::Bind(function, this)) |
| 27 | 27 |
| 28 const int DecryptingAudioDecoder::kSupportedBitsPerChannel = 16; |
| 29 |
| 28 static inline bool IsOutOfSync(const base::TimeDelta& timestamp_1, | 30 static inline bool IsOutOfSync(const base::TimeDelta& timestamp_1, |
| 29 const base::TimeDelta& timestamp_2) { | 31 const base::TimeDelta& timestamp_2) { |
| 30 // Out of sync of 100ms would be pretty noticeable and we should keep any | 32 // Out of sync of 100ms would be pretty noticeable and we should keep any |
| 31 // drift below that. | 33 // drift below that. |
| 32 const int64 kOutOfSyncThresholdInMicroseconds = 100000; | 34 const int64 kOutOfSyncThresholdInMicroseconds = 100000; |
| 33 return std::abs(timestamp_1.InMicroseconds() - timestamp_2.InMicroseconds()) > | 35 return std::abs(timestamp_1.InMicroseconds() - timestamp_2.InMicroseconds()) > |
| 34 kOutOfSyncThresholdInMicroseconds; | 36 kOutOfSyncThresholdInMicroseconds; |
| 35 } | 37 } |
| 36 | 38 |
| 37 DecryptingAudioDecoder::DecryptingAudioDecoder( | 39 DecryptingAudioDecoder::DecryptingAudioDecoder( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { | 165 void DecryptingAudioDecoder::SetDecryptor(Decryptor* decryptor) { |
| 164 DVLOG(2) << "SetDecryptor()"; | 166 DVLOG(2) << "SetDecryptor()"; |
| 165 DCHECK(message_loop_->BelongsToCurrentThread()); | 167 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 166 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 168 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
| 167 DCHECK(!init_cb_.is_null()); | 169 DCHECK(!init_cb_.is_null()); |
| 168 DCHECK(!set_decryptor_ready_cb_.is_null()); | 170 DCHECK(!set_decryptor_ready_cb_.is_null()); |
| 169 | 171 |
| 170 set_decryptor_ready_cb_.Reset(); | 172 set_decryptor_ready_cb_.Reset(); |
| 171 decryptor_ = decryptor; | 173 decryptor_ = decryptor; |
| 172 | 174 |
| 175 const AudioDecoderConfig& input_config = |
| 176 demuxer_stream_->audio_decoder_config(); |
| 173 scoped_ptr<AudioDecoderConfig> scoped_config(new AudioDecoderConfig()); | 177 scoped_ptr<AudioDecoderConfig> scoped_config(new AudioDecoderConfig()); |
| 174 scoped_config->CopyFrom(demuxer_stream_->audio_decoder_config()); | 178 scoped_config->Initialize(input_config.codec(), |
| 179 kSampleFormatS16, |
| 180 input_config.channel_layout(), |
| 181 input_config.samples_per_second(), |
| 182 input_config.extra_data(), |
| 183 input_config.extra_data_size(), |
| 184 input_config.is_encrypted(), |
| 185 false); |
| 175 | 186 |
| 176 state_ = kPendingDecoderInit; | 187 state_ = kPendingDecoderInit; |
| 177 decryptor_->InitializeAudioDecoder( | 188 decryptor_->InitializeAudioDecoder( |
| 178 scoped_config.Pass(), | 189 scoped_config.Pass(), |
| 179 BIND_TO_LOOP(&DecryptingAudioDecoder::FinishInitialization)); | 190 BIND_TO_LOOP(&DecryptingAudioDecoder::FinishInitialization)); |
| 180 } | 191 } |
| 181 | 192 |
| 182 void DecryptingAudioDecoder::FinishInitialization(bool success) { | 193 void DecryptingAudioDecoder::FinishInitialization(bool success) { |
| 183 DVLOG(2) << "FinishInitialization()"; | 194 DVLOG(2) << "FinishInitialization()"; |
| 184 DCHECK(message_loop_->BelongsToCurrentThread()); | 195 DCHECK(message_loop_->BelongsToCurrentThread()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 285 } |
| 275 | 286 |
| 276 DVLOG(3) << "DoDecryptAndDecodeBuffer()"; | 287 DVLOG(3) << "DoDecryptAndDecodeBuffer()"; |
| 277 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 288 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; |
| 278 DCHECK(!read_cb_.is_null()); | 289 DCHECK(!read_cb_.is_null()); |
| 279 DCHECK_EQ(buffer != NULL, status == DemuxerStream::kOk) << status; | 290 DCHECK_EQ(buffer != NULL, status == DemuxerStream::kOk) << status; |
| 280 | 291 |
| 281 if (status == DemuxerStream::kConfigChanged) { | 292 if (status == DemuxerStream::kConfigChanged) { |
| 282 DVLOG(2) << "DoDecryptAndDecodeBuffer() - kConfigChanged"; | 293 DVLOG(2) << "DoDecryptAndDecodeBuffer() - kConfigChanged"; |
| 283 | 294 |
| 284 scoped_ptr<AudioDecoderConfig> scoped_config(new AudioDecoderConfig()); | 295 const AudioDecoderConfig& input_config = |
| 285 scoped_config->CopyFrom(demuxer_stream_->audio_decoder_config()); | 296 demuxer_stream_->audio_decoder_config(); |
| 297 scoped_ptr<AudioDecoderConfig> scoped_config(new AudioDecoderConfig()); |
| 298 scoped_config->Initialize(input_config.codec(), |
| 299 kSampleFormatS16, |
| 300 input_config.channel_layout(), |
| 301 input_config.samples_per_second(), |
| 302 input_config.extra_data(), |
| 303 input_config.extra_data_size(), |
| 304 input_config.is_encrypted(), |
| 305 false); |
| 286 | 306 |
| 287 state_ = kPendingConfigChange; | 307 state_ = kPendingConfigChange; |
| 288 decryptor_->DeinitializeDecoder(Decryptor::kAudio); | 308 decryptor_->DeinitializeDecoder(Decryptor::kAudio); |
| 289 decryptor_->InitializeAudioDecoder( | 309 decryptor_->InitializeAudioDecoder( |
| 290 scoped_config.Pass(), BindToCurrentLoop(base::Bind( | 310 scoped_config.Pass(), BindToCurrentLoop(base::Bind( |
| 291 &DecryptingAudioDecoder::FinishConfigChange, this))); | 311 &DecryptingAudioDecoder::FinishConfigChange, this))); |
| 292 return; | 312 return; |
| 293 } | 313 } |
| 294 | 314 |
| 295 if (!reset_cb_.is_null()) { | 315 if (!reset_cb_.is_null()) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 DCHECK(init_cb_.is_null()); | 458 DCHECK(init_cb_.is_null()); |
| 439 DCHECK(read_cb_.is_null()); | 459 DCHECK(read_cb_.is_null()); |
| 440 output_timestamp_base_ = kNoTimestamp(); | 460 output_timestamp_base_ = kNoTimestamp(); |
| 441 total_samples_decoded_ = 0; | 461 total_samples_decoded_ = 0; |
| 442 state_ = kIdle; | 462 state_ = kIdle; |
| 443 base::ResetAndReturn(&reset_cb_).Run(); | 463 base::ResetAndReturn(&reset_cb_).Run(); |
| 444 } | 464 } |
| 445 | 465 |
| 446 void DecryptingAudioDecoder::UpdateDecoderConfig() { | 466 void DecryptingAudioDecoder::UpdateDecoderConfig() { |
| 447 const AudioDecoderConfig& config = demuxer_stream_->audio_decoder_config(); | 467 const AudioDecoderConfig& config = demuxer_stream_->audio_decoder_config(); |
| 448 bits_per_channel_ = config.bits_per_channel(); | 468 bits_per_channel_ = kSupportedBitsPerChannel; |
| 449 channel_layout_ = config.channel_layout(); | 469 channel_layout_ = config.channel_layout(); |
| 450 samples_per_second_ = config.samples_per_second(); | 470 samples_per_second_ = config.samples_per_second(); |
| 451 const int kBitsPerByte = 8; | 471 const int kBitsPerByte = 8; |
| 452 bytes_per_sample_ = ChannelLayoutToChannelCount(channel_layout_) * | 472 bytes_per_sample_ = ChannelLayoutToChannelCount(channel_layout_) * |
| 453 bits_per_channel_ / kBitsPerByte; | 473 bits_per_channel_ / kBitsPerByte; |
| 454 output_timestamp_base_ = kNoTimestamp(); | 474 output_timestamp_base_ = kNoTimestamp(); |
| 455 total_samples_decoded_ = 0; | 475 total_samples_decoded_ = 0; |
| 456 } | 476 } |
| 457 | 477 |
| 458 void DecryptingAudioDecoder::EnqueueFrames( | 478 void DecryptingAudioDecoder::EnqueueFrames( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 512 |
| 493 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( | 513 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( |
| 494 int number_of_samples) const { | 514 int number_of_samples) const { |
| 495 DCHECK(samples_per_second_); | 515 DCHECK(samples_per_second_); |
| 496 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | 516 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * |
| 497 number_of_samples / | 517 number_of_samples / |
| 498 samples_per_second_); | 518 samples_per_second_); |
| 499 } | 519 } |
| 500 | 520 |
| 501 } // namespace media | 521 } // namespace media |
| OLD | NEW |