Chromium Code Reviews| 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; |
|
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
|
| + 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.
|
| + 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, |
|
wolenetz
2014/04/29 19:18:08
Use memmove, not memcpy due to potentially overlap
DaleCurtis
2014/04/30 22:04:04
Done.
|
| + 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, |
|
wolenetz
2014/04/29 19:18:08
ditto: memmove?
DaleCurtis
2014/04/30 22:04:04
Done.
|
| + 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 |