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

Unified Diff: media/base/audio_buffer.cc

Issue 251893002: Support start trimming post-decoding. Use it with FFmpegDemuxer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typo. 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
Index: media/base/audio_buffer.cc
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc
index 4b972b90a1abda47c363b0cd46c7c8362ca60ee2..61d73a322a41d71ddf9453851ec2b148f0ebe662 100644
--- a/media/base/audio_buffer.cc
+++ b/media/base/audio_buffer.cc
@@ -275,4 +275,40 @@ void AudioBuffer::TrimEnd(int frames_to_trim) {
adjusted_frame_count_ -= frames_to_trim;
}
+void AudioBuffer::TrimRange(int start, int end) {
+ const int frames_to_trim = end - start;
+ CHECK_GE(frames_to_trim, 0);
+ CHECK_LE(frames_to_trim, adjusted_frame_count_);
+
+ const int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_);
+ const int frames_to_copy = adjusted_frame_count_ - frames_to_trim;
+ switch (sample_format_) {
+ case kSampleFormatPlanarS16:
+ case kSampleFormatPlanarF32:
+ // Planar data must be shifted per channel.
+ for (int ch = 0; ch < channel_count_; ++ch) {
+ memcpy(channel_data_[ch] + start * bytes_per_channel,
+ channel_data_[ch] + end * bytes_per_channel,
+ bytes_per_channel * frames_to_copy);
+ }
+ break;
+ case kSampleFormatU8:
+ case kSampleFormatS16:
+ case kSampleFormatS32:
+ case kSampleFormatF32: {
+ // Interleaved data can be shifted all at once.
+ const int frame_size = channel_count_ * bytes_per_channel;
+ memcpy(channel_data_[0] + start * frame_size,
+ channel_data_[0] + end * frame_size,
+ frame_size * frames_to_copy);
+ break;
+ }
+ case kUnknownSampleFormat:
+ NOTREACHED() << "Invalid sample format!";
+ }
+
+ // Trim the leftover data off the end of the buffer and update duration.
+ TrimEnd(frames_to_trim);
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698