Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/audio_decoder_job.h" | 5 #include "media/base/android/audio_decoder_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 g_audio_decoder_thread = LAZY_INSTANCE_INITIALIZER; | 33 g_audio_decoder_thread = LAZY_INSTANCE_INITIALIZER; |
| 34 | 34 |
| 35 AudioDecoderJob::AudioDecoderJob( | 35 AudioDecoderJob::AudioDecoderJob( |
| 36 const base::Closure& request_data_cb, | 36 const base::Closure& request_data_cb, |
| 37 const base::Closure& on_demuxer_config_changed_cb) | 37 const base::Closure& on_demuxer_config_changed_cb) |
| 38 : MediaDecoderJob(g_audio_decoder_thread.Pointer()->message_loop_proxy(), | 38 : MediaDecoderJob(g_audio_decoder_thread.Pointer()->message_loop_proxy(), |
| 39 request_data_cb, | 39 request_data_cb, |
| 40 on_demuxer_config_changed_cb), | 40 on_demuxer_config_changed_cb), |
| 41 audio_codec_(kUnknownAudioCodec), | 41 audio_codec_(kUnknownAudioCodec), |
| 42 num_channels_(0), | 42 num_channels_(0), |
| 43 sampling_rate_(0), | 43 config_sampling_rate_(0), |
| 44 volume_(-1.0), | 44 volume_(-1.0), |
| 45 bytes_per_frame_(0) { | 45 bytes_per_frame_(0), |
| 46 output_sampling_rate_(0) { | |
| 46 } | 47 } |
| 47 | 48 |
| 48 AudioDecoderJob::~AudioDecoderJob() {} | 49 AudioDecoderJob::~AudioDecoderJob() {} |
| 49 | 50 |
| 50 bool AudioDecoderJob::HasStream() const { | 51 bool AudioDecoderJob::HasStream() const { |
| 51 return audio_codec_ != kUnknownAudioCodec; | 52 return audio_codec_ != kUnknownAudioCodec; |
| 52 } | 53 } |
| 53 | 54 |
| 54 void AudioDecoderJob::SetDemuxerConfigs(const DemuxerConfigs& configs) { | 55 void AudioDecoderJob::SetDemuxerConfigs(const DemuxerConfigs& configs) { |
| 55 // TODO(qinmin): split DemuxerConfig for audio and video separately so we | 56 // TODO(qinmin): split DemuxerConfig for audio and video separately so we |
| 56 // can simply store the stucture here. | 57 // can simply store the stucture here. |
| 57 audio_codec_ = configs.audio_codec; | 58 audio_codec_ = configs.audio_codec; |
| 58 num_channels_ = configs.audio_channels; | 59 num_channels_ = configs.audio_channels; |
| 59 sampling_rate_ = configs.audio_sampling_rate; | 60 config_sampling_rate_ = configs.audio_sampling_rate; |
| 60 set_is_content_encrypted(configs.is_audio_encrypted); | 61 set_is_content_encrypted(configs.is_audio_encrypted); |
| 61 audio_extra_data_ = configs.audio_extra_data; | 62 audio_extra_data_ = configs.audio_extra_data; |
| 62 bytes_per_frame_ = kBytesPerAudioOutputSample * num_channels_; | 63 bytes_per_frame_ = kBytesPerAudioOutputSample * num_channels_; |
| 64 if (!media_codec_bridge_) | |
| 65 output_sampling_rate_ = config_sampling_rate_; | |
| 63 } | 66 } |
| 64 | 67 |
| 65 void AudioDecoderJob::SetVolume(double volume) { | 68 void AudioDecoderJob::SetVolume(double volume) { |
| 66 volume_ = volume; | 69 volume_ = volume; |
| 67 SetVolumeInternal(); | 70 SetVolumeInternal(); |
| 68 } | 71 } |
| 69 | 72 |
| 70 void AudioDecoderJob::SetBaseTimestamp(base::TimeDelta base_timestamp) { | 73 void AudioDecoderJob::SetBaseTimestamp(base::TimeDelta base_timestamp) { |
| 71 DCHECK(!is_decoding()); | 74 DCHECK(!is_decoding()); |
| 72 base_timestamp_ = base_timestamp; | 75 base_timestamp_ = base_timestamp; |
| 73 if (audio_timestamp_helper_) | 76 if (audio_timestamp_helper_) |
| 74 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | 77 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
| 75 } | 78 } |
| 76 | 79 |
| 80 void AudioDecoderJob::ResetTimestampHelper() { | |
| 81 if (audio_timestamp_helper_) | |
| 82 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | |
| 83 audio_timestamp_helper_.reset( | |
| 84 new AudioTimestampHelper(output_sampling_rate_)); | |
| 85 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | |
|
qinmin
2015/01/21 21:43:56
what is the max timestamp here? the new audio_time
kjoswiak
2015/01/21 22:53:11
What do you mean?
We preserve storage of time by
kjoswiak
2015/01/21 23:00:47
Clarification: We don't TRANSFER base timestamp, w
qinmin
2015/01/22 00:07:45
Suppose we got the following situation:
audioTrack
| |
| 86 } | |
| 87 | |
| 77 void AudioDecoderJob::ReleaseOutputBuffer( | 88 void AudioDecoderJob::ReleaseOutputBuffer( |
| 78 int output_buffer_index, | 89 int output_buffer_index, |
| 79 size_t size, | 90 size_t size, |
| 80 bool render_output, | 91 bool render_output, |
| 81 base::TimeDelta current_presentation_timestamp, | 92 base::TimeDelta current_presentation_timestamp, |
| 82 const ReleaseOutputCompletionCallback& callback) { | 93 const ReleaseOutputCompletionCallback& callback) { |
| 83 render_output = render_output && (size != 0u); | 94 render_output = render_output && (size != 0u); |
| 84 if (render_output) { | 95 if (render_output) { |
| 85 int64 head_position = (static_cast<AudioCodecBridge*>( | 96 int64 head_position = (static_cast<AudioCodecBridge*>( |
| 86 media_codec_bridge_.get()))->PlayOutputBuffer( | 97 media_codec_bridge_.get()))->PlayOutputBuffer( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 102 } | 113 } |
| 103 | 114 |
| 104 bool AudioDecoderJob::ComputeTimeToRender() const { | 115 bool AudioDecoderJob::ComputeTimeToRender() const { |
| 105 return false; | 116 return false; |
| 106 } | 117 } |
| 107 | 118 |
| 108 bool AudioDecoderJob::AreDemuxerConfigsChanged( | 119 bool AudioDecoderJob::AreDemuxerConfigsChanged( |
| 109 const DemuxerConfigs& configs) const { | 120 const DemuxerConfigs& configs) const { |
| 110 return audio_codec_ != configs.audio_codec || | 121 return audio_codec_ != configs.audio_codec || |
| 111 num_channels_ != configs.audio_channels || | 122 num_channels_ != configs.audio_channels || |
| 112 sampling_rate_ != configs.audio_sampling_rate || | 123 config_sampling_rate_ != configs.audio_sampling_rate || |
| 113 is_content_encrypted() != configs.is_audio_encrypted || | 124 is_content_encrypted() != configs.is_audio_encrypted || |
| 114 audio_extra_data_.size() != configs.audio_extra_data.size() || | 125 audio_extra_data_.size() != configs.audio_extra_data.size() || |
| 115 !std::equal(audio_extra_data_.begin(), | 126 !std::equal(audio_extra_data_.begin(), |
| 116 audio_extra_data_.end(), | 127 audio_extra_data_.end(), |
| 117 configs.audio_extra_data.begin()); | 128 configs.audio_extra_data.begin()); |
| 118 } | 129 } |
| 119 | 130 |
| 120 bool AudioDecoderJob::CreateMediaCodecBridgeInternal() { | 131 bool AudioDecoderJob::CreateMediaCodecBridgeInternal() { |
| 121 media_codec_bridge_.reset(AudioCodecBridge::Create(audio_codec_)); | 132 media_codec_bridge_.reset(AudioCodecBridge::Create(audio_codec_)); |
| 122 if (!media_codec_bridge_) | 133 if (!media_codec_bridge_) |
| 123 return false; | 134 return false; |
| 124 | 135 |
| 125 if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get()))->Start( | 136 if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get()))->Start( |
| 126 audio_codec_, sampling_rate_, num_channels_, &audio_extra_data_[0], | 137 audio_codec_, config_sampling_rate_, num_channels_, &audio_extra_data_[0], |
| 127 audio_extra_data_.size(), true, GetMediaCrypto().obj())) { | 138 audio_extra_data_.size(), true, GetMediaCrypto().obj())) { |
| 128 media_codec_bridge_.reset(); | 139 media_codec_bridge_.reset(); |
| 129 return false; | 140 return false; |
| 130 } | 141 } |
| 131 | 142 |
| 132 SetVolumeInternal(); | 143 SetVolumeInternal(); |
| 133 | 144 |
| 134 // Need to pass the base timestamp to the new decoder. | 145 // Need to pass the base timestamp to the new decoder. |
| 135 if (audio_timestamp_helper_) | 146 ResetTimestampHelper(); |
| 136 base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); | 147 |
| 137 audio_timestamp_helper_.reset(new AudioTimestampHelper(sampling_rate_)); | |
| 138 audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); | |
| 139 return true; | 148 return true; |
| 140 } | 149 } |
| 141 | 150 |
| 142 void AudioDecoderJob::SetVolumeInternal() { | 151 void AudioDecoderJob::SetVolumeInternal() { |
| 143 if (media_codec_bridge_) { | 152 if (media_codec_bridge_) { |
| 144 static_cast<AudioCodecBridge*>(media_codec_bridge_.get())->SetVolume( | 153 static_cast<AudioCodecBridge*>(media_codec_bridge_.get())->SetVolume( |
| 145 volume_); | 154 volume_); |
| 146 } | 155 } |
| 147 } | 156 } |
| 148 | 157 |
| 158 void AudioDecoderJob::GotOutputFormatChanged() { | |
| 159 if (!media_codec_bridge_) | |
| 160 return; | |
| 161 | |
| 162 int old_sampling_rate = output_sampling_rate_; | |
| 163 output_sampling_rate_ = media_codec_bridge_->GetOutputSamplingRate(); | |
| 164 if (output_sampling_rate_ != old_sampling_rate) | |
| 165 ResetTimestampHelper(); | |
| 166 } | |
| 167 | |
| 149 } // namespace media | 168 } // namespace media |
| OLD | NEW |