Index: media/base/audio_buffer.cc |
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc |
index b502bf84753105ca936321b41dd80ccada90fed8..181dab4b2dce029549dd047a09eba465a8bd25cf 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); |
@@ -51,6 +52,18 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format, |
if (!create_buffer) |
return; |
+ if (sample_format == kSampleFormatRaw) { |
AndyWu
2016/11/04 18:04:24
I refactored the code a little to avoid code dupli
|
+ if (data_size_) { |
+ data_.reset(static_cast<uint8_t*>( |
+ base::AlignedAlloc(data_size_, kChannelAlignment))); |
DaleCurtis
2016/11/01 23:05:13
AlignedAlloc shouldn't be necessary in this case.
AndyWu
2016/11/04 18:04:24
|data_| is defined as:
std::unique_ptr<uint8_t, ba
|
+ channel_data_.reserve(1); |
DaleCurtis
2016/11/01 23:05:13
Just channel_data_ = std::vector(1, data_.get()) ?
AndyWu
2016/11/04 18:04:24
Yes, it should work. It's better in terms of line
|
+ channel_data_.push_back(data_.get()); |
+ if (data) |
DaleCurtis
2016/11/01 23:05:13
This should never be null now right?
AndyWu
2016/11/04 18:04:24
In current use cases, yes. But I would prefer to k
|
+ memcpy(data_.get(), data[0], data_size_); |
+ } |
+ return; |
+ } |
+ |
int data_size_per_channel = frame_count * bytes_per_channel; |
if (IsPlanar(sample_format)) { |
// Planar data, so need to allocate buffer for each channel. |
@@ -98,18 +111,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) { |
DaleCurtis
2016/11/01 23:05:13
Instead of adding this, if you specify the appropr
AndyWu
2016/11/04 18:04:24
I see your point, but it would also introduce anot
DaleCurtis
2016/11/04 19:48:29
Hmm, I guess you're saying that we don't always en
DaleCurtis
2016/11/04 21:17:33
Actually, why can't you just define these sample f
AndyWu
2016/11/08 00:04:21
The |data_size_| calculation is based on
https://c
|
// 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 +127,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 +144,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 +180,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 +307,7 @@ void AudioBuffer::TrimRange(int start, int end) { |
frame_size * frames_to_copy); |
break; |
} |
+ case kSampleFormatRaw: |
case kUnknownSampleFormat: |
NOTREACHED() << "Invalid sample format!"; |
} |