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() { |
120 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 126 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
121 | 127 |
122 DVLOG(1) << class_name() << "::" << __FUNCTION__; | 128 DVLOG(1) << class_name() << "::" << __FUNCTION__; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 if (audio_timestamp_helper_) | 265 if (audio_timestamp_helper_) |
260 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 266 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
261 | 267 |
262 audio_timestamp_helper_.reset( | 268 audio_timestamp_helper_.reset( |
263 new AudioTimestampHelper(configs_.audio_sampling_rate)); | 269 new AudioTimestampHelper(configs_.audio_sampling_rate)); |
264 | 270 |
265 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 271 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
266 } | 272 } |
267 | 273 |
268 } // namespace media | 274 } // namespace media |
OLD | NEW |