| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/base/android/media_codec_audio_decoder.h" | 5 #include "media/base/android/media_codec_audio_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "media/base/android/media_codec_bridge.h" | 9 #include "media/base/android/media_codec_bridge.h" |
| 10 #include "media/base/audio_timestamp_helper.h" | 10 #include "media/base/audio_timestamp_helper.h" |
| 11 #include "media/base/demuxer_stream.h" | 11 #include "media/base/demuxer_stream.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // Use 16bit PCM for audio output. Keep this value in sync with the output | 15 // Use 16bit PCM for audio output. Keep this value in sync with the output |
| 16 // format we passed to AudioTrack in MediaCodecBridge. | 16 // format we passed to AudioTrack in MediaCodecBridge. |
| 17 const int kBytesPerAudioOutputSample = 2; | 17 const int kBytesPerAudioOutputSample = 2; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 MediaCodecAudioDecoder::MediaCodecAudioDecoder( | 22 MediaCodecAudioDecoder::MediaCodecAudioDecoder( |
| 23 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 23 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 24 const base::Closure& request_data_cb, | 24 const base::Closure& request_data_cb, |
| 25 const base::Closure& starvation_cb, | 25 const base::Closure& starvation_cb, |
| 26 const base::Closure& decoder_drained_cb, | 26 const base::Closure& decoder_drained_cb, |
| 27 const base::Closure& stop_done_cb, | 27 const base::Closure& stop_done_cb, |
| 28 const base::Closure& waiting_for_decryption_key_cb, |
| 28 const base::Closure& error_cb, | 29 const base::Closure& error_cb, |
| 29 const SetTimeCallback& update_current_time_cb) | 30 const SetTimeCallback& update_current_time_cb) |
| 30 : MediaCodecDecoder(media_task_runner, | 31 : MediaCodecDecoder(media_task_runner, |
| 31 request_data_cb, | 32 request_data_cb, |
| 32 starvation_cb, | 33 starvation_cb, |
| 33 decoder_drained_cb, | 34 decoder_drained_cb, |
| 34 stop_done_cb, | 35 stop_done_cb, |
| 36 waiting_for_decryption_key_cb, |
| 35 error_cb, | 37 error_cb, |
| 36 "AudioDecoder"), | 38 "AudioDecoder"), |
| 37 volume_(-1.0), | 39 volume_(-1.0), |
| 38 bytes_per_frame_(0), | 40 bytes_per_frame_(0), |
| 39 output_sampling_rate_(0), | 41 output_sampling_rate_(0), |
| 40 frame_count_(0), | 42 frame_count_(0), |
| 41 update_current_time_cb_(update_current_time_cb) { | 43 update_current_time_cb_(update_current_time_cb) { |
| 42 } | 44 } |
| 43 | 45 |
| 44 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { | 46 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 } | 60 } |
| 59 | 61 |
| 60 void MediaCodecAudioDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { | 62 void MediaCodecAudioDecoder::SetDemuxerConfigs(const DemuxerConfigs& configs) { |
| 61 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; | 63 DVLOG(1) << class_name() << "::" << __FUNCTION__ << " " << configs; |
| 62 | 64 |
| 63 configs_ = configs; | 65 configs_ = configs; |
| 64 if (!media_codec_bridge_) | 66 if (!media_codec_bridge_) |
| 65 output_sampling_rate_ = configs.audio_sampling_rate; | 67 output_sampling_rate_ = configs.audio_sampling_rate; |
| 66 } | 68 } |
| 67 | 69 |
| 70 bool MediaCodecAudioDecoder::IsContentEncrypted() const { |
| 71 // Make sure SetDemuxerConfigs() as been called. |
| 72 DCHECK(configs_.audio_codec != kUnknownAudioCodec); |
| 73 return configs_.is_audio_encrypted; |
| 74 } |
| 75 |
| 68 void MediaCodecAudioDecoder::ReleaseDecoderResources() { | 76 void MediaCodecAudioDecoder::ReleaseDecoderResources() { |
| 69 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 77 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 70 DVLOG(1) << class_name() << "::" << __FUNCTION__; | 78 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 71 | 79 |
| 72 DoEmergencyStop(); | 80 DoEmergencyStop(); |
| 73 | 81 |
| 74 ReleaseMediaCodec(); | 82 ReleaseMediaCodec(); |
| 75 } | 83 } |
| 76 | 84 |
| 77 void MediaCodecAudioDecoder::Flush() { | 85 void MediaCodecAudioDecoder::Flush() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 } | 110 } |
| 103 | 111 |
| 104 bool MediaCodecAudioDecoder::IsCodecReconfigureNeeded( | 112 bool MediaCodecAudioDecoder::IsCodecReconfigureNeeded( |
| 105 const DemuxerConfigs& next) const { | 113 const DemuxerConfigs& next) const { |
| 106 if (always_reconfigure_for_tests_) | 114 if (always_reconfigure_for_tests_) |
| 107 return true; | 115 return true; |
| 108 | 116 |
| 109 return configs_.audio_codec != next.audio_codec || | 117 return configs_.audio_codec != next.audio_codec || |
| 110 configs_.audio_channels != next.audio_channels || | 118 configs_.audio_channels != next.audio_channels || |
| 111 configs_.audio_sampling_rate != next.audio_sampling_rate || | 119 configs_.audio_sampling_rate != next.audio_sampling_rate || |
| 112 next.is_audio_encrypted != next.is_audio_encrypted || | 120 configs_.is_audio_encrypted != next.is_audio_encrypted || |
| 113 configs_.audio_extra_data.size() != next.audio_extra_data.size() || | 121 configs_.audio_extra_data.size() != next.audio_extra_data.size() || |
| 114 !std::equal(configs_.audio_extra_data.begin(), | 122 !std::equal(configs_.audio_extra_data.begin(), |
| 115 configs_.audio_extra_data.end(), | 123 configs_.audio_extra_data.end(), |
| 116 next.audio_extra_data.begin()); | 124 next.audio_extra_data.begin()); |
| 117 } | 125 } |
| 118 | 126 |
| 119 MediaCodecDecoder::ConfigStatus MediaCodecAudioDecoder::ConfigureInternal() { | 127 MediaCodecDecoder::ConfigStatus MediaCodecAudioDecoder::ConfigureInternal( |
| 128 jobject media_crypto) { |
| 120 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 129 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 121 | 130 |
| 122 DVLOG(1) << class_name() << "::" << __FUNCTION__; | 131 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
| 123 | 132 |
| 124 if (configs_.audio_codec == kUnknownAudioCodec) { | 133 if (configs_.audio_codec == kUnknownAudioCodec) { |
| 125 DVLOG(0) << class_name() << "::" << __FUNCTION__ | 134 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 126 << " configuration parameters are required"; | 135 << " configuration parameters are required"; |
| 127 return kConfigFailure; | 136 return kConfigFailure; |
| 128 } | 137 } |
| 129 | 138 |
| 130 media_codec_bridge_.reset(AudioCodecBridge::Create(configs_.audio_codec)); | 139 media_codec_bridge_.reset(AudioCodecBridge::Create(configs_.audio_codec)); |
| 131 if (!media_codec_bridge_) | 140 if (!media_codec_bridge_) |
| 132 return kConfigFailure; | 141 return kConfigFailure; |
| 133 | 142 |
| 134 if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) | 143 if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) |
| 135 ->Start( | 144 ->Start( |
| 136 configs_.audio_codec, | 145 configs_.audio_codec, |
| 137 configs_.audio_sampling_rate, | 146 configs_.audio_sampling_rate, |
| 138 configs_.audio_channels, | 147 configs_.audio_channels, |
| 139 &configs_.audio_extra_data[0], | 148 &configs_.audio_extra_data[0], |
| 140 configs_.audio_extra_data.size(), | 149 configs_.audio_extra_data.size(), |
| 141 configs_.audio_codec_delay_ns, | 150 configs_.audio_codec_delay_ns, |
| 142 configs_.audio_seek_preroll_ns, | 151 configs_.audio_seek_preroll_ns, |
| 143 true, | 152 true, |
| 144 GetMediaCrypto().obj())) { | 153 media_crypto)) { |
| 145 DVLOG(0) << class_name() << "::" << __FUNCTION__ | 154 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
| 146 << " failed: cannot start audio codec"; | 155 << " failed: cannot start audio codec"; |
| 147 | 156 |
| 148 media_codec_bridge_.reset(); | 157 media_codec_bridge_.reset(); |
| 149 return kConfigFailure; | 158 return kConfigFailure; |
| 150 } | 159 } |
| 151 | 160 |
| 152 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; | 161 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; |
| 153 | 162 |
| 154 SetVolumeInternal(); | 163 SetVolumeInternal(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (audio_timestamp_helper_) | 268 if (audio_timestamp_helper_) |
| 260 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 269 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
| 261 | 270 |
| 262 audio_timestamp_helper_.reset( | 271 audio_timestamp_helper_.reset( |
| 263 new AudioTimestampHelper(configs_.audio_sampling_rate)); | 272 new AudioTimestampHelper(configs_.audio_sampling_rate)); |
| 264 | 273 |
| 265 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 274 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
| 266 } | 275 } |
| 267 | 276 |
| 268 } // namespace media | 277 } // namespace media |
| OLD | NEW |