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& key_required_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 key_required_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 return configs_.is_audio_encrypted; |
| 72 } |
| 73 |
68 void MediaCodecAudioDecoder::ReleaseDecoderResources() { | 74 void MediaCodecAudioDecoder::ReleaseDecoderResources() { |
69 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 75 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
70 DVLOG(1) << class_name() << "::" << __FUNCTION__; | 76 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
71 | 77 |
72 DoEmergencyStop(); | 78 DoEmergencyStop(); |
73 | 79 |
74 ReleaseMediaCodec(); | 80 ReleaseMediaCodec(); |
75 } | 81 } |
76 | 82 |
77 void MediaCodecAudioDecoder::Flush() { | 83 void MediaCodecAudioDecoder::Flush() { |
(...skipping 24 matching lines...) Expand all Loading... |
102 } | 108 } |
103 | 109 |
104 bool MediaCodecAudioDecoder::IsCodecReconfigureNeeded( | 110 bool MediaCodecAudioDecoder::IsCodecReconfigureNeeded( |
105 const DemuxerConfigs& next) const { | 111 const DemuxerConfigs& next) const { |
106 if (always_reconfigure_for_tests_) | 112 if (always_reconfigure_for_tests_) |
107 return true; | 113 return true; |
108 | 114 |
109 return configs_.audio_codec != next.audio_codec || | 115 return configs_.audio_codec != next.audio_codec || |
110 configs_.audio_channels != next.audio_channels || | 116 configs_.audio_channels != next.audio_channels || |
111 configs_.audio_sampling_rate != next.audio_sampling_rate || | 117 configs_.audio_sampling_rate != next.audio_sampling_rate || |
112 next.is_audio_encrypted != next.is_audio_encrypted || | 118 configs_.is_audio_encrypted != next.is_audio_encrypted || |
113 configs_.audio_extra_data.size() != next.audio_extra_data.size() || | 119 configs_.audio_extra_data.size() != next.audio_extra_data.size() || |
114 !std::equal(configs_.audio_extra_data.begin(), | 120 !std::equal(configs_.audio_extra_data.begin(), |
115 configs_.audio_extra_data.end(), | 121 configs_.audio_extra_data.end(), |
116 next.audio_extra_data.begin()); | 122 next.audio_extra_data.begin()); |
117 } | 123 } |
118 | 124 |
119 MediaCodecDecoder::ConfigStatus MediaCodecAudioDecoder::ConfigureInternal() { | 125 MediaCodecDecoder::ConfigStatus MediaCodecAudioDecoder::ConfigureInternal( |
| 126 jobject media_crypto) { |
120 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 127 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
121 | 128 |
122 DVLOG(1) << class_name() << "::" << __FUNCTION__; | 129 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
123 | 130 |
124 if (configs_.audio_codec == kUnknownAudioCodec) { | 131 if (configs_.audio_codec == kUnknownAudioCodec) { |
125 DVLOG(0) << class_name() << "::" << __FUNCTION__ | 132 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
126 << " configuration parameters are required"; | 133 << " configuration parameters are required"; |
127 return kConfigFailure; | 134 return kConfigFailure; |
128 } | 135 } |
129 | 136 |
130 media_codec_bridge_.reset(AudioCodecBridge::Create(configs_.audio_codec)); | 137 media_codec_bridge_.reset(AudioCodecBridge::Create(configs_.audio_codec)); |
131 if (!media_codec_bridge_) | 138 if (!media_codec_bridge_) |
132 return kConfigFailure; | 139 return kConfigFailure; |
133 | 140 |
134 if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) | 141 if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get())) |
135 ->Start( | 142 ->Start( |
136 configs_.audio_codec, | 143 configs_.audio_codec, |
137 configs_.audio_sampling_rate, | 144 configs_.audio_sampling_rate, |
138 configs_.audio_channels, | 145 configs_.audio_channels, |
139 &configs_.audio_extra_data[0], | 146 &configs_.audio_extra_data[0], |
140 configs_.audio_extra_data.size(), | 147 configs_.audio_extra_data.size(), |
141 configs_.audio_codec_delay_ns, | 148 configs_.audio_codec_delay_ns, |
142 configs_.audio_seek_preroll_ns, | 149 configs_.audio_seek_preroll_ns, |
143 true, | 150 true, |
144 GetMediaCrypto().obj())) { | 151 media_crypto)) { |
145 DVLOG(0) << class_name() << "::" << __FUNCTION__ | 152 DVLOG(0) << class_name() << "::" << __FUNCTION__ |
146 << " failed: cannot start audio codec"; | 153 << " failed: cannot start audio codec"; |
147 | 154 |
148 media_codec_bridge_.reset(); | 155 media_codec_bridge_.reset(); |
149 return kConfigFailure; | 156 return kConfigFailure; |
150 } | 157 } |
151 | 158 |
152 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; | 159 DVLOG(0) << class_name() << "::" << __FUNCTION__ << " succeeded"; |
153 | 160 |
154 SetVolumeInternal(); | 161 SetVolumeInternal(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 if (audio_timestamp_helper_) | 266 if (audio_timestamp_helper_) |
260 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 267 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
261 | 268 |
262 audio_timestamp_helper_.reset( | 269 audio_timestamp_helper_.reset( |
263 new AudioTimestampHelper(configs_.audio_sampling_rate)); | 270 new AudioTimestampHelper(configs_.audio_sampling_rate)); |
264 | 271 |
265 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 272 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
266 } | 273 } |
267 | 274 |
268 } // namespace media | 275 } // namespace media |
OLD | NEW |