Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Unified Diff: media/base/audio_splicer.cc

Issue 265943002: Revert of Remove AudioBuffer::set_duration(), instead base on frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/audio_discard_helper_unittest.cc ('k') | media/base/audio_splicer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « media/base/audio_discard_helper_unittest.cc ('k') | media/base/audio_splicer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698