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

Side by Side 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: Rebase. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/audio_buffer.h" 5 #include "media/base/audio_buffer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/audio_bus.h" 8 #include "media/base/audio_bus.h"
9 #include "media/base/buffers.h" 9 #include "media/base/buffers.h"
10 #include "media/base/limits.h" 10 #include "media/base/limits.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 double offset = static_cast<double>(duration_.InMicroseconds()) * 268 double offset = static_cast<double>(duration_.InMicroseconds()) *
269 frames_to_trim / adjusted_frame_count_; 269 frames_to_trim / adjusted_frame_count_;
270 base::TimeDelta offset_as_time = 270 base::TimeDelta offset_as_time =
271 base::TimeDelta::FromMicroseconds(static_cast<int64>(offset)); 271 base::TimeDelta::FromMicroseconds(static_cast<int64>(offset));
272 duration_ -= offset_as_time; 272 duration_ -= offset_as_time;
273 273
274 // Finally adjust the number of frames in this buffer. 274 // Finally adjust the number of frames in this buffer.
275 adjusted_frame_count_ -= frames_to_trim; 275 adjusted_frame_count_ -= frames_to_trim;
276 } 276 }
277 277
278 void AudioBuffer::TrimRange(int start, int end) {
279 const int frames_to_trim = end - start;
280 CHECK_GE(frames_to_trim, 0);
281 CHECK_LE(frames_to_trim, adjusted_frame_count_);
282
283 const int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_);
284 const int frames_to_copy = adjusted_frame_count_ - frames_to_trim;
wolenetz 2014/04/29 01:18:30 This is wrong for all cases where start > 0: examp
DaleCurtis 2014/04/29 03:16:20 Yeah this is all wrong, I'm surprised it works at
285 switch (sample_format_) {
wolenetz 2014/04/29 01:18:30 If frames_to_copy is 0, skip the shifting and just
DaleCurtis 2014/04/30 22:04:04 Done.
286 case kSampleFormatPlanarS16:
287 case kSampleFormatPlanarF32:
288 // Planar data must be shifted per channel.
289 for (int ch = 0; ch < channel_count_; ++ch) {
290 memcpy(channel_data_[ch] + start * bytes_per_channel,
wolenetz 2014/04/29 19:18:08 Use memmove, not memcpy due to potentially overlap
DaleCurtis 2014/04/30 22:04:04 Done.
291 channel_data_[ch] + end * bytes_per_channel,
292 bytes_per_channel * frames_to_copy);
293 }
294 break;
295 case kSampleFormatU8:
296 case kSampleFormatS16:
297 case kSampleFormatS32:
298 case kSampleFormatF32: {
299 // Interleaved data can be shifted all at once.
300 const int frame_size = channel_count_ * bytes_per_channel;
301 memcpy(channel_data_[0] + start * frame_size,
wolenetz 2014/04/29 19:18:08 ditto: memmove?
DaleCurtis 2014/04/30 22:04:04 Done.
302 channel_data_[0] + end * frame_size,
303 frame_size * frames_to_copy);
304 break;
305 }
306 case kUnknownSampleFormat:
307 NOTREACHED() << "Invalid sample format!";
308 }
309
310 // Trim the leftover data off the end of the buffer and update duration.
311 TrimEnd(frames_to_trim);
312 }
313
278 } // namespace media 314 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698