Index: media/base/audio_splicer.cc |
diff --git a/media/base/audio_splicer.cc b/media/base/audio_splicer.cc |
index 9fae4175f032408eb94e3a5be3ed810972a790c4..b83765e76066bda8e93840f703371959344a6524 100644 |
--- a/media/base/audio_splicer.cc |
+++ b/media/base/audio_splicer.cc |
@@ -35,6 +35,20 @@ |
const AudioTimestampHelper& timestamp_helper) { |
buffer->TrimStart(frames_to_trim); |
buffer->set_timestamp(timestamp_helper.GetTimestamp()); |
+ buffer->set_duration( |
+ timestamp_helper.GetFrameDuration(buffer->frame_count())); |
+} |
+ |
+// AudioBuffer::TrimEnd() is not as accurate as the timestamp helper, so |
+// manually adjust the duration after trimming. |
+static void AccurateTrimEnd(int frames_to_trim, |
+ const scoped_refptr<AudioBuffer> buffer, |
+ const AudioTimestampHelper& timestamp_helper) { |
+ DCHECK_LT(std::abs(timestamp_helper.GetFramesToTarget(buffer->timestamp())), |
+ kMinGapSize); |
+ buffer->TrimEnd(frames_to_trim); |
+ buffer->set_duration( |
+ timestamp_helper.GetFrameDuration(buffer->frame_count())); |
} |
// Returns an AudioBus whose frame buffer is backed by the provided AudioBuffer. |
@@ -163,12 +177,13 @@ |
// Create a buffer with enough silence samples to fill the gap and |
// add it to the output buffer. |
- scoped_refptr<AudioBuffer> gap = |
- AudioBuffer::CreateEmptyBuffer(input->channel_layout(), |
- input->channel_count(), |
- input->sample_rate(), |
- frames_to_fill, |
- expected_timestamp); |
+ scoped_refptr<AudioBuffer> gap = AudioBuffer::CreateEmptyBuffer( |
+ input->channel_layout(), |
+ input->channel_count(), |
+ input->sample_rate(), |
+ frames_to_fill, |
+ expected_timestamp, |
+ output_timestamp_helper_.GetFrameDuration(frames_to_fill)); |
AddOutputBuffer(gap); |
// Add the input buffer now that the gap has been filled. |
@@ -428,7 +443,9 @@ |
// If only part of the buffer was consumed, trim it appropriately and stick |
// it into the output queue. |
if (frames_before_splice) { |
- preroll->TrimEnd(preroll->frame_count() - frames_before_splice); |
+ AccurateTrimEnd(preroll->frame_count() - frames_before_splice, |
+ preroll, |
+ output_ts_helper); |
CHECK(output_sanitizer_->AddInput(preroll)); |
frames_before_splice = 0; |
} |
@@ -449,6 +466,8 @@ |
const AudioTimestampHelper& output_ts_helper = |
output_sanitizer_->timestamp_helper(); |
crossfade_buffer->set_timestamp(output_ts_helper.GetTimestamp()); |
+ crossfade_buffer->set_duration( |
+ output_ts_helper.GetFrameDuration(pre_splice_bus->frames())); |
// AudioBuffer::ReadFrames() only allows output into an AudioBus, so wrap |
// our AudioBuffer in one so we can avoid extra data copies. |