| Index: media/base/audio_buffer.cc
|
| diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc
|
| index b502bf84753105ca936321b41dd80ccada90fed8..a3e25091c81f2baf1b0bd3d1b4b7da6b69344a14 100644
|
| --- a/media/base/audio_buffer.cc
|
| +++ b/media/base/audio_buffer.cc
|
| @@ -26,6 +26,7 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format,
|
| int frame_count,
|
| bool create_buffer,
|
| const uint8_t* const* data,
|
| + size_t data_size,
|
| const base::TimeDelta timestamp)
|
| : sample_format_(sample_format),
|
| channel_layout_(channel_layout),
|
| @@ -37,7 +38,7 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format,
|
| duration_(end_of_stream_
|
| ? base::TimeDelta()
|
| : CalculateDuration(adjusted_frame_count_, sample_rate_)),
|
| - data_size_(0) {
|
| + data_size_(data_size) {
|
| CHECK_GE(channel_count_, 0);
|
| CHECK_LE(channel_count_, limits::kMaxChannels);
|
| CHECK_GE(frame_count, 0);
|
| @@ -79,7 +80,8 @@ AudioBuffer::AudioBuffer(SampleFormat 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_ = data_size_per_channel * channel_count_;
|
| + if (sample_format != kSampleFormatRaw)
|
| + data_size_ = data_size_per_channel * channel_count_;
|
| data_.reset(
|
| static_cast<uint8_t*>(base::AlignedAlloc(data_size_, kChannelAlignment)));
|
| channel_data_.reserve(1);
|
| @@ -98,18 +100,14 @@ scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom(
|
| int sample_rate,
|
| int frame_count,
|
| const uint8_t* const* data,
|
| - const base::TimeDelta timestamp) {
|
| + const base::TimeDelta timestamp,
|
| + const size_t data_size) {
|
| // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
|
| CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer.
|
| CHECK(data[0]);
|
| - return make_scoped_refptr(new AudioBuffer(sample_format,
|
| - channel_layout,
|
| - channel_count,
|
| - sample_rate,
|
| - frame_count,
|
| - true,
|
| - data,
|
| - timestamp));
|
| + return make_scoped_refptr(
|
| + new AudioBuffer(sample_format, channel_layout, channel_count, sample_rate,
|
| + frame_count, true, data, data_size, timestamp));
|
| }
|
|
|
| // static
|
| @@ -118,11 +116,12 @@ scoped_refptr<AudioBuffer> AudioBuffer::CreateBuffer(
|
| ChannelLayout channel_layout,
|
| int channel_count,
|
| int sample_rate,
|
| - int frame_count) {
|
| + int frame_count,
|
| + size_t data_size) {
|
| CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer.
|
| return make_scoped_refptr(
|
| new AudioBuffer(sample_format, channel_layout, channel_count, sample_rate,
|
| - frame_count, true, NULL, kNoTimestamp));
|
| + frame_count, true, NULL, data_size, kNoTimestamp));
|
| }
|
|
|
| // static
|
| @@ -134,21 +133,16 @@ scoped_refptr<AudioBuffer> AudioBuffer::CreateEmptyBuffer(
|
| const base::TimeDelta timestamp) {
|
| CHECK_GT(frame_count, 0); // Otherwise looks like an EOF buffer.
|
| // Since data == NULL, format doesn't matter.
|
| - return make_scoped_refptr(new AudioBuffer(kSampleFormatF32,
|
| - channel_layout,
|
| - channel_count,
|
| - sample_rate,
|
| - frame_count,
|
| - false,
|
| - NULL,
|
| - timestamp));
|
| + return make_scoped_refptr(
|
| + new AudioBuffer(kSampleFormatF32, channel_layout, channel_count,
|
| + sample_rate, frame_count, false, NULL, 0, timestamp));
|
| }
|
|
|
| // static
|
| scoped_refptr<AudioBuffer> AudioBuffer::CreateEOSBuffer() {
|
| return make_scoped_refptr(new AudioBuffer(kUnknownSampleFormat,
|
| CHANNEL_LAYOUT_NONE, 0, 0, 0, false,
|
| - NULL, kNoTimestamp));
|
| + NULL, 0, kNoTimestamp));
|
| }
|
|
|
| // Convert int16_t values in the range [INT16_MIN, INT16_MAX] to [-1.0, 1.0].
|
| @@ -175,6 +169,21 @@ void AudioBuffer::ReadFrames(int frames_to_copy,
|
| DCHECK(!end_of_stream());
|
| DCHECK_EQ(dest->channels(), channel_count_);
|
| DCHECK_LE(source_frame_offset + frames_to_copy, adjusted_frame_count_);
|
| +
|
| + bool is_raw_format = (sample_format_ == kSampleFormatRaw);
|
| + dest->set_is_raw_format(is_raw_format);
|
| +
|
| + if (is_raw_format) {
|
| + DCHECK(!source_frame_offset);
|
| + uint8_t* dest_data =
|
| + reinterpret_cast<uint8_t*>(dest->channel(0)) + dest->data_size();
|
| +
|
| + memcpy(dest_data, channel_data_[0], data_size());
|
| + dest->set_data_size(dest_frame_offset + data_size());
|
| + dest->set_frames(dest->frames() + frame_count());
|
| + return;
|
| + }
|
| +
|
| DCHECK_LE(dest_frame_offset + frames_to_copy, dest->frames());
|
|
|
| if (!data_) {
|
| @@ -287,6 +296,7 @@ void AudioBuffer::TrimRange(int start, int end) {
|
| frame_size * frames_to_copy);
|
| break;
|
| }
|
| + case kSampleFormatRaw:
|
| case kUnknownSampleFormat:
|
| NOTREACHED() << "Invalid sample format!";
|
| }
|
|
|