Chromium Code Reviews| Index: media/base/android/audio_decoder_job.cc |
| diff --git a/media/base/android/audio_decoder_job.cc b/media/base/android/audio_decoder_job.cc |
| index e3769200abd473e9981a29ca680ed795ae1baf6b..1d046006a7be9c6fb0dc24f579e976031b691e4a 100644 |
| --- a/media/base/android/audio_decoder_job.cc |
| +++ b/media/base/android/audio_decoder_job.cc |
| @@ -40,9 +40,10 @@ AudioDecoderJob::AudioDecoderJob( |
| on_demuxer_config_changed_cb), |
| audio_codec_(kUnknownAudioCodec), |
| num_channels_(0), |
| - sampling_rate_(0), |
| + config_sampling_rate_(0), |
| volume_(-1.0), |
| - bytes_per_frame_(0) { |
| + bytes_per_frame_(0), |
| + output_sampling_rate_(0) { |
| } |
| AudioDecoderJob::~AudioDecoderJob() {} |
| @@ -56,10 +57,12 @@ void AudioDecoderJob::SetDemuxerConfigs(const DemuxerConfigs& configs) { |
| // can simply store the stucture here. |
| audio_codec_ = configs.audio_codec; |
| num_channels_ = configs.audio_channels; |
| - sampling_rate_ = configs.audio_sampling_rate; |
| + config_sampling_rate_ = configs.audio_sampling_rate; |
| set_is_content_encrypted(configs.is_audio_encrypted); |
| audio_extra_data_ = configs.audio_extra_data; |
| bytes_per_frame_ = kBytesPerAudioOutputSample * num_channels_; |
| + if (!media_codec_bridge_) |
| + output_sampling_rate_ = config_sampling_rate_; |
| } |
| void AudioDecoderJob::SetVolume(double volume) { |
| @@ -74,6 +77,14 @@ void AudioDecoderJob::SetBaseTimestamp(base::TimeDelta base_timestamp) { |
| audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
| } |
| +void AudioDecoderJob::ResetTimestampHelper() { |
| + if (audio_timestamp_helper_) |
| + base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
| + audio_timestamp_helper_.reset( |
| + new AudioTimestampHelper(output_sampling_rate_)); |
| + audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
| +} |
| + |
| void AudioDecoderJob::ReleaseOutputBuffer( |
| int output_buffer_index, |
| size_t size, |
| @@ -109,7 +120,7 @@ bool AudioDecoderJob::AreDemuxerConfigsChanged( |
| const DemuxerConfigs& configs) const { |
| return audio_codec_ != configs.audio_codec || |
| num_channels_ != configs.audio_channels || |
| - sampling_rate_ != configs.audio_sampling_rate || |
| + config_sampling_rate_ != configs.audio_sampling_rate || |
| is_content_encrypted() != configs.is_audio_encrypted || |
| audio_extra_data_.size() != configs.audio_extra_data.size() || |
| !std::equal(audio_extra_data_.begin(), |
| @@ -123,7 +134,7 @@ bool AudioDecoderJob::CreateMediaCodecBridgeInternal() { |
| return false; |
| if (!(static_cast<AudioCodecBridge*>(media_codec_bridge_.get()))->Start( |
| - audio_codec_, sampling_rate_, num_channels_, &audio_extra_data_[0], |
| + audio_codec_, config_sampling_rate_, num_channels_, &audio_extra_data_[0], |
| audio_extra_data_.size(), true, GetMediaCrypto().obj())) { |
| media_codec_bridge_.reset(); |
| return false; |
| @@ -132,10 +143,8 @@ bool AudioDecoderJob::CreateMediaCodecBridgeInternal() { |
| SetVolumeInternal(); |
| // Need to pass the base timestamp to the new decoder. |
| - if (audio_timestamp_helper_) |
| - base_timestamp_ = audio_timestamp_helper_->GetTimestamp(); |
| - audio_timestamp_helper_.reset(new AudioTimestampHelper(sampling_rate_)); |
| - audio_timestamp_helper_->SetBaseTimestamp(base_timestamp_); |
| + ResetTimestampHelper(); |
| + |
| return true; |
| } |
| @@ -146,4 +155,20 @@ void AudioDecoderJob::SetVolumeInternal() { |
| } |
| } |
| +bool AudioDecoderJob::UpdateOutputFormat( |
| + const base::Closure& config_changed_cb) { |
| + if (!media_codec_bridge_) |
| + return true; |
| + |
| + int old_sampling_rate = output_sampling_rate_; |
| + media_codec_bridge_->GetOutputSamplingRate(&output_sampling_rate_); |
| + if (output_sampling_rate_ == old_sampling_rate) |
| + return true; |
| + if (!media_codec_bridge_->ReconfigureAudioTrack()) |
| + return false; |
| + ResetTimestampHelper(); |
|
kjoswiak
2015/01/16 23:14:56
This function call is still not threadsafe with Re
kjoswiak
2015/01/17 01:13:20
Ehh I think it's fine since there can only be one
|
| + config_changed_cb.Run(); |
| + return true; |
| +} |
| + |
| } // namespace media |