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

Unified Diff: media/base/audio_buffer.cc

Issue 1468153003: Define AudioBuffer and VideoFrame for mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch statement Created 5 years, 1 month 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
« no previous file with comments | « media/base/audio_buffer.h ('k') | media/base/sample_format.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_buffer.cc
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc
index 564cff156bbb7f5defa7067439731a1efa44c500..a49764073548ecb24692b2e568cbf2cafa040340 100644
--- a/media/base/audio_buffer.cc
+++ b/media/base/audio_buffer.cc
@@ -37,7 +37,8 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format,
timestamp_(timestamp),
duration_(end_of_stream_
? base::TimeDelta()
- : CalculateDuration(adjusted_frame_count_, sample_rate_)) {
+ : CalculateDuration(adjusted_frame_count_, sample_rate_)),
+ data_size_(0) {
CHECK_GE(channel_count_, 0);
CHECK_LE(channel_count_, limits::kMaxChannels);
CHECK_GE(frame_count, 0);
@@ -46,49 +47,46 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format,
int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format);
DCHECK_LE(bytes_per_channel, kChannelAlignment);
- int data_size = frame_count * bytes_per_channel;
// Empty buffer?
if (!create_buffer)
return;
- if (sample_format == kSampleFormatPlanarF32 ||
- sample_format == kSampleFormatPlanarS16 ||
- sample_format == kSampleFormatPlanarS32) {
+ int data_size_per_channel = frame_count * bytes_per_channel;
+ if (IsPlanar(sample_format)) {
// Planar data, so need to allocate buffer for each channel.
// Determine per channel data size, taking into account alignment.
int block_size_per_channel =
- (data_size + kChannelAlignment - 1) & ~(kChannelAlignment - 1);
- DCHECK_GE(block_size_per_channel, data_size);
+ (data_size_per_channel + kChannelAlignment - 1) &
+ ~(kChannelAlignment - 1);
+ DCHECK_GE(block_size_per_channel, data_size_per_channel);
// Allocate a contiguous buffer for all the channel data.
- data_.reset(static_cast<uint8*>(base::AlignedAlloc(
- channel_count_ * block_size_per_channel, kChannelAlignment)));
+ data_size_ = channel_count_ * block_size_per_channel;
+ data_.reset(
+ static_cast<uint8*>(base::AlignedAlloc(data_size_, kChannelAlignment)));
channel_data_.reserve(channel_count_);
// Copy each channel's data into the appropriate spot.
for (int i = 0; i < channel_count_; ++i) {
channel_data_.push_back(data_.get() + i * block_size_per_channel);
if (data)
- memcpy(channel_data_[i], data[i], data_size);
+ memcpy(channel_data_[i], data[i], data_size_per_channel);
}
return;
}
// Remaining formats are interleaved data.
- DCHECK(sample_format_ == kSampleFormatU8 ||
- sample_format_ == kSampleFormatS16 ||
- sample_format_ == kSampleFormatS32 ||
- sample_format_ == kSampleFormatF32) << sample_format_;
+ DCHECK(IsInterleaved(sample_format)) << sample_format_;
// Allocate our own buffer and copy the supplied data into it. Buffer must
// contain the data for all channels.
- data_size *= channel_count_;
+ data_size_ = data_size_per_channel * channel_count_;
data_.reset(
- static_cast<uint8*>(base::AlignedAlloc(data_size, kChannelAlignment)));
+ static_cast<uint8*>(base::AlignedAlloc(data_size_, kChannelAlignment)));
channel_data_.reserve(1);
channel_data_.push_back(data_.get());
if (data)
- memcpy(data_.get(), data[0], data_size);
+ memcpy(data_.get(), data[0], data_size_);
}
AudioBuffer::~AudioBuffer() {}
« no previous file with comments | « media/base/audio_buffer.h ('k') | media/base/sample_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698