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

Side by Side Diff: media/base/audio_buffer.cc

Issue 881603002: Adding an ALAC enum to AudioDecoderConfig (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation error Created 5 years, 10 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
« no previous file with comments | « no previous file | media/base/audio_buffer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format); 45 int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format);
46 DCHECK_LE(bytes_per_channel, kChannelAlignment); 46 DCHECK_LE(bytes_per_channel, kChannelAlignment);
47 int data_size = frame_count * bytes_per_channel; 47 int data_size = frame_count * bytes_per_channel;
48 48
49 // Empty buffer? 49 // Empty buffer?
50 if (!create_buffer) 50 if (!create_buffer)
51 return; 51 return;
52 52
53 if (sample_format == kSampleFormatPlanarF32 || 53 if (sample_format == kSampleFormatPlanarF32 ||
54 sample_format == kSampleFormatPlanarS16) { 54 sample_format == kSampleFormatPlanarS16 ||
55 sample_format == kSampleFormatPlanarS32) {
55 // Planar data, so need to allocate buffer for each channel. 56 // Planar data, so need to allocate buffer for each channel.
56 // Determine per channel data size, taking into account alignment. 57 // Determine per channel data size, taking into account alignment.
57 int block_size_per_channel = 58 int block_size_per_channel =
58 (data_size + kChannelAlignment - 1) & ~(kChannelAlignment - 1); 59 (data_size + kChannelAlignment - 1) & ~(kChannelAlignment - 1);
59 DCHECK_GE(block_size_per_channel, data_size); 60 DCHECK_GE(block_size_per_channel, data_size);
60 61
61 // Allocate a contiguous buffer for all the channel data. 62 // Allocate a contiguous buffer for all the channel data.
62 data_.reset(static_cast<uint8*>(base::AlignedAlloc( 63 data_.reset(static_cast<uint8*>(base::AlignedAlloc(
63 channel_count_ * block_size_per_channel, kChannelAlignment))); 64 channel_count_ * block_size_per_channel, kChannelAlignment)));
64 channel_data_.reserve(channel_count_); 65 channel_data_.reserve(channel_count_);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 static inline int32 ConvertS16ToS32(int16 value) { 248 static inline int32 ConvertS16ToS32(int16 value) {
248 return static_cast<int32>(value) << 16; 249 return static_cast<int32>(value) << 16;
249 } 250 }
250 251
251 static inline int32 ConvertF32ToS32(float value) { 252 static inline int32 ConvertF32ToS32(float value) {
252 return static_cast<int32>(value < 0 253 return static_cast<int32>(value < 0
253 ? (-value) * std::numeric_limits<int32>::min() 254 ? (-value) * std::numeric_limits<int32>::min()
254 : value * std::numeric_limits<int32>::max()); 255 : value * std::numeric_limits<int32>::max());
255 } 256 }
256 257
258 // No need for conversion. Return value as is. Keeping function to align with
259 // code structure.
260 static inline int32 ConvertS32ToS32(int32 value) {
261 return value;
262 }
263
257 template <class Target, typename Converter> 264 template <class Target, typename Converter>
258 void InterleaveToS32(const std::vector<uint8*>& channel_data, 265 void InterleaveToS32(const std::vector<uint8*>& channel_data,
259 size_t frames_to_copy, 266 size_t frames_to_copy,
260 int trim_start, 267 int trim_start,
261 int32* dest_data, 268 int32* dest_data,
262 Converter convert_func) { 269 Converter convert_func) {
263 for (size_t ch = 0; ch < channel_data.size(); ++ch) { 270 for (size_t ch = 0; ch < channel_data.size(); ++ch) {
264 const Target* source_data = 271 const Target* source_data =
265 reinterpret_cast<const Target*>(channel_data[ch]) + trim_start; 272 reinterpret_cast<const Target*>(channel_data[ch]) + trim_start;
266 for (size_t i = 0, offset = ch; i < frames_to_copy; 273 for (size_t i = 0, offset = ch; i < frames_to_copy;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 break; 322 break;
316 case kSampleFormatPlanarF32: 323 case kSampleFormatPlanarF32:
317 // Format is planar float. Convert each value into int32 and insert into 324 // Format is planar float. Convert each value into int32 and insert into
318 // output channel data. 325 // output channel data.
319 InterleaveToS32<float>(channel_data_, 326 InterleaveToS32<float>(channel_data_,
320 frames_to_copy, 327 frames_to_copy,
321 trim_start_, 328 trim_start_,
322 dest_data, 329 dest_data,
323 ConvertF32ToS32); 330 ConvertF32ToS32);
324 break; 331 break;
332 case kSampleFormatPlanarS32:
333 // Format is planar signed 32 bit. Convert each value into int32 and
334 // insert into output channel data.
335 InterleaveToS32<int32>(channel_data_,
336 frames_to_copy,
337 trim_start_,
338 dest_data,
339 ConvertS32ToS32);
325 case kUnknownSampleFormat: 340 case kUnknownSampleFormat:
326 NOTREACHED(); 341 NOTREACHED();
327 break; 342 break;
328 } 343 }
329 } 344 }
330 345
331 void AudioBuffer::TrimStart(int frames_to_trim) { 346 void AudioBuffer::TrimStart(int frames_to_trim) {
332 CHECK_GE(frames_to_trim, 0); 347 CHECK_GE(frames_to_trim, 0);
333 CHECK_LE(frames_to_trim, adjusted_frame_count_); 348 CHECK_LE(frames_to_trim, adjusted_frame_count_);
334 349
(...skipping 23 matching lines...) Expand all
358 const int frames_to_trim = end - start; 373 const int frames_to_trim = end - start;
359 CHECK_GE(frames_to_trim, 0); 374 CHECK_GE(frames_to_trim, 0);
360 CHECK_LE(frames_to_trim, adjusted_frame_count_); 375 CHECK_LE(frames_to_trim, adjusted_frame_count_);
361 376
362 const int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_); 377 const int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_);
363 const int frames_to_copy = adjusted_frame_count_ - end; 378 const int frames_to_copy = adjusted_frame_count_ - end;
364 if (frames_to_copy > 0) { 379 if (frames_to_copy > 0) {
365 switch (sample_format_) { 380 switch (sample_format_) {
366 case kSampleFormatPlanarS16: 381 case kSampleFormatPlanarS16:
367 case kSampleFormatPlanarF32: 382 case kSampleFormatPlanarF32:
383 case kSampleFormatPlanarS32:
368 // Planar data must be shifted per channel. 384 // Planar data must be shifted per channel.
369 for (int ch = 0; ch < channel_count_; ++ch) { 385 for (int ch = 0; ch < channel_count_; ++ch) {
370 memmove(channel_data_[ch] + (trim_start_ + start) * bytes_per_channel, 386 memmove(channel_data_[ch] + (trim_start_ + start) * bytes_per_channel,
371 channel_data_[ch] + (trim_start_ + end) * bytes_per_channel, 387 channel_data_[ch] + (trim_start_ + end) * bytes_per_channel,
372 bytes_per_channel * frames_to_copy); 388 bytes_per_channel * frames_to_copy);
373 } 389 }
374 break; 390 break;
375 case kSampleFormatU8: 391 case kSampleFormatU8:
376 case kSampleFormatS16: 392 case kSampleFormatS16:
377 case kSampleFormatS32: 393 case kSampleFormatS32:
(...skipping 10 matching lines...) Expand all
388 } 404 }
389 } else { 405 } else {
390 CHECK_EQ(frames_to_copy, 0); 406 CHECK_EQ(frames_to_copy, 0);
391 } 407 }
392 408
393 // Trim the leftover data off the end of the buffer and update duration. 409 // Trim the leftover data off the end of the buffer and update duration.
394 TrimEnd(frames_to_trim); 410 TrimEnd(frames_to_trim);
395 } 411 }
396 412
397 } // namespace media 413 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698