Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 trim_start_ += frames_to_trim; | 249 trim_start_ += frames_to_trim; |
| 250 | 250 |
| 251 // Adjust timestamp_ and duration_ to reflect the smaller number of frames. | 251 // Adjust timestamp_ and duration_ to reflect the smaller number of frames. |
| 252 const base::TimeDelta old_duration = duration_; | 252 const base::TimeDelta old_duration = duration_; |
| 253 duration_ = CalculateDuration(adjusted_frame_count_, sample_rate_); | 253 duration_ = CalculateDuration(adjusted_frame_count_, sample_rate_); |
| 254 timestamp_ += old_duration - duration_; | 254 timestamp_ += old_duration - duration_; |
| 255 } | 255 } |
| 256 | 256 |
| 257 void AudioBuffer::TrimEnd(int frames_to_trim) { | 257 void AudioBuffer::TrimEnd(int frames_to_trim) { |
| 258 CHECK_GE(frames_to_trim, 0); | 258 CHECK_GE(frames_to_trim, 0); |
| 259 CHECK_LE(frames_to_trim, adjusted_frame_count_); | 259 CHECK_LE(frames_to_trim, adjusted_frame_count_);; |
|
acolwell GONE FROM CHROMIUM
2014/05/01 01:08:34
nit: remove extra ;
DaleCurtis
2014/05/01 19:21:27
Done.
| |
| 260 | 260 |
| 261 // Adjust the number of frames and duration for this buffer. | 261 // Adjust the number of frames and duration for this buffer. |
| 262 adjusted_frame_count_ -= frames_to_trim; | 262 adjusted_frame_count_ -= frames_to_trim; |
| 263 duration_ = CalculateDuration(adjusted_frame_count_, sample_rate_); | 263 duration_ = CalculateDuration(adjusted_frame_count_, sample_rate_); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void AudioBuffer::TrimRange(int start, int end) { | |
| 267 CHECK_GE(start, 0); | |
| 268 CHECK_LE(end, adjusted_frame_count_); | |
| 269 | |
| 270 const int frames_to_trim = end - start; | |
| 271 CHECK_GE(frames_to_trim, 0); | |
| 272 CHECK_LE(frames_to_trim, adjusted_frame_count_); | |
| 273 | |
| 274 const int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_); | |
| 275 const int frames_to_copy = adjusted_frame_count_ - end; | |
| 276 if (frames_to_copy > 0) { | |
| 277 switch (sample_format_) { | |
| 278 case kSampleFormatPlanarS16: | |
| 279 case kSampleFormatPlanarF32: | |
| 280 // Planar data must be shifted per channel. | |
| 281 for (int ch = 0; ch < channel_count_; ++ch) { | |
| 282 memmove(channel_data_[ch] + (trim_start_ + start) * bytes_per_channel, | |
| 283 channel_data_[ch] + (trim_start_ + end) * bytes_per_channel, | |
| 284 bytes_per_channel * frames_to_copy); | |
| 285 } | |
| 286 break; | |
| 287 case kSampleFormatU8: | |
| 288 case kSampleFormatS16: | |
| 289 case kSampleFormatS32: | |
| 290 case kSampleFormatF32: { | |
| 291 // Interleaved data can be shifted all at once. | |
| 292 const int frame_size = channel_count_ * bytes_per_channel; | |
| 293 memmove(channel_data_[0] + (trim_start_ + start) * frame_size, | |
| 294 channel_data_[0] + (trim_start_ + end) * frame_size, | |
| 295 frame_size * frames_to_copy); | |
| 296 break; | |
| 297 } | |
| 298 case kUnknownSampleFormat: | |
| 299 NOTREACHED() << "Invalid sample format!"; | |
| 300 } | |
| 301 } else { | |
| 302 CHECK_EQ(frames_to_copy, 0); | |
| 303 } | |
| 304 | |
| 305 // Trim the leftover data off the end of the buffer and update duration. | |
| 306 TrimEnd(frames_to_trim); | |
| 307 } | |
| 308 | |
| 266 } // namespace media | 309 } // namespace media |
| OLD | NEW |