Index: media/filters/opus_audio_decoder.cc |
diff --git a/media/filters/opus_audio_decoder.cc b/media/filters/opus_audio_decoder.cc |
index 115799ab71193fe829265268c3898a5cbbc6cf95..a79fb8847b7cd07eb14f8f9a3de2e037b9cf9252 100644 |
--- a/media/filters/opus_audio_decoder.cc |
+++ b/media/filters/opus_audio_decoder.cc |
@@ -250,7 +250,6 @@ OpusAudioDecoder::OpusAudioDecoder( |
channel_layout_(CHANNEL_LAYOUT_NONE), |
samples_per_second_(0), |
last_input_timestamp_(kNoTimestamp()), |
- output_bytes_to_drop_(0), |
skip_samples_(0) { |
} |
@@ -457,10 +456,17 @@ bool OpusAudioDecoder::ConfigureDecoder() { |
config, |
&opus_header); |
- skip_samples_ = opus_header.skip_samples; |
- |
- if (skip_samples_ > 0) |
- output_bytes_to_drop_ = skip_samples_ * config.bytes_per_frame(); |
+ if (!config.codec_delay()) { |
+ skip_samples_ = opus_header.skip_samples; |
fgalligan1
2013/08/26 21:10:06
Is this the same value as below? I.e. skipped_byte
vignesh
2013/08/26 21:44:23
No it is not. If you look below (Line 542 in the r
fgalligan1
2013/08/26 22:11:53
Sorry I was just asking if opus_header.skip_sample
vignesh
2013/08/26 23:55:48
No it does not. Neither does the skip_samples_ var
|
+ } else { |
+ // WebM container stores codec delay in nanoseconds. Convert it to samples. |
+ skip_samples_ = config.codec_delay() * config.samples_per_second() / |
+ 1000000000; |
+ if (skip_samples_ != opus_header.skip_samples) { |
+ DVLOG(1) << "Codec Delay in container does not match the value in Opus " |
+ << "header. Using the value in container."; |
+ } |
+ } |
uint8 channel_mapping[kMaxVorbisChannels]; |
memcpy(&channel_mapping, |
@@ -508,7 +514,7 @@ void OpusAudioDecoder::CloseDecoder() { |
void OpusAudioDecoder::ResetTimestampState() { |
output_timestamp_helper_->SetBaseTimestamp(kNoTimestamp()); |
last_input_timestamp_ = kNoTimestamp(); |
- output_bytes_to_drop_ = 0; |
+ skip_samples_ = 0; |
} |
bool OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& input, |
@@ -539,16 +545,6 @@ bool OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& input, |
output_timestamp_helper_->SetBaseTimestamp(input->timestamp()); |
} |
- if (decoded_audio_size > 0 && output_bytes_to_drop_ > 0) { |
- int dropped_size = std::min(decoded_audio_size, output_bytes_to_drop_); |
- DCHECK_EQ(dropped_size % kBytesPerChannel, 0); |
- decoded_audio_data += dropped_size; |
- decoded_audio_size -= dropped_size; |
- output_bytes_to_drop_ -= dropped_size; |
- samples_decoded = decoded_audio_size / |
- demuxer_stream_->audio_decoder_config().bytes_per_frame(); |
- } |
- |
if (decoded_audio_size > 0) { |
// Copy the audio samples into an output buffer. |
uint8* data[] = { decoded_audio_data }; |
@@ -560,6 +556,17 @@ bool OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& input, |
output_timestamp_helper_->GetTimestamp(), |
output_timestamp_helper_->GetFrameDuration(samples_decoded)); |
output_timestamp_helper_->AddFrames(samples_decoded); |
+ if (skip_samples_ > 0) { |
+ int dropped_size = std::min(samples_decoded, skip_samples_); |
+ output_buffer->get()->TrimStart(dropped_size); |
fgalligan1
2013/08/26 21:10:06
I'm assuming this works on samples? Does it take i
vignesh
2013/08/26 21:44:23
Yes, it works on samples. I am unsure if it takes
vignesh
2013/08/26 23:55:48
As mentioned in the other comment in this file, th
|
+ skip_samples_ -= dropped_size; |
+ samples_decoded -= dropped_size; |
+ } |
+ if (input->discard_padding() > 0) { |
+ int discard_padding = input->discard_padding() * samples_per_second_ / |
+ 1000000000; |
+ output_buffer->get()->TrimEnd(std::min(samples_decoded, discard_padding)); |
+ } |
} |
// Decoding finished successfully, update statistics. |