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

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: Comments. 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 25e8dbe1a1b77a42fef7211dae2710a78c08b486..039fefc983727a1d062c1e2e4552625a39e5d7c6 100644
--- a/media/base/audio_buffer.cc
+++ b/media/base/audio_buffer.cc
@@ -263,4 +263,47 @@ void AudioBuffer::TrimEnd(int frames_to_trim) {
duration_ = CalculateDuration(adjusted_frame_count_, sample_rate_);
}
+void AudioBuffer::TrimRange(int start, int end) {
+ CHECK_GE(start, 0);
+ CHECK_LE(end, adjusted_frame_count_);
+
+ 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_ - end;
wolenetz 2014/05/05 19:01:23 nit: remove extra whitespace
wolenetz 2014/05/05 19:03:03 Never mind. My mistake for not seeing the '_' :)
+ if (frames_to_copy > 0) {
+ switch (sample_format_) {
+ case kSampleFormatPlanarS16:
+ case kSampleFormatPlanarF32:
+ // Planar data must be shifted per channel.
+ for (int ch = 0; ch < channel_count_; ++ch) {
+ memmove(channel_data_[ch] + (trim_start_ + start) * bytes_per_channel,
+ channel_data_[ch] + (trim_start_ + 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;
+ memmove(channel_data_[0] + (trim_start_ + start) * frame_size,
+ channel_data_[0] + (trim_start_ + end) * frame_size,
+ frame_size * frames_to_copy);
+ break;
+ }
+ case kUnknownSampleFormat:
+ NOTREACHED() << "Invalid sample format!";
+ }
+ } else {
+ CHECK_EQ(frames_to_copy, 0);
+ }
+
+ // 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