Index: media/base/audio_buffer.cc |
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc |
index 8b029930dec53cd304b834365d4c3562f0a8240c..cf997a94fb6b1d24befbe192ecff6d56c7be3296 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 (!IsBitstream(sample_format)) |
chcunningham
2016/12/16 22:03:14
I feel like the interleaved code path is the only
AndyWu
2017/05/02 23:41:03
I do make (E)AC3 as interleaved formats:
https://c
|
+ data_size_ = data_size_per_channel * channel_count_; |
data_.reset( |
static_cast<uint8_t*>(base::AlignedAlloc(data_size_, kChannelAlignment))); |
channel_data_.reserve(1); |
@@ -102,14 +104,27 @@ scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom( |
// 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, 0, timestamp)); |
+} |
+ |
+// static |
+scoped_refptr<AudioBuffer> AudioBuffer::CopyBitstreamFrom( |
+ SampleFormat sample_format, |
+ ChannelLayout channel_layout, |
+ int channel_count, |
+ int sample_rate, |
+ int frame_count, |
+ const uint8_t* const* data, |
+ const size_t data_size, |
+ const base::TimeDelta timestamp) { |
+ // 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]); |
chcunningham
2016/12/16 22:03:14
Are we confident that data[0] would never return 0
AndyWu
2017/05/02 23:41:03
data[0] is a pointer; null pointer is unexpected.
|
+ return make_scoped_refptr( |
+ new AudioBuffer(sample_format, channel_layout, channel_count, sample_rate, |
+ frame_count, true, data, data_size, timestamp)); |
} |
// static |
@@ -122,7 +137,21 @@ scoped_refptr<AudioBuffer> AudioBuffer::CreateBuffer( |
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, 0, kNoTimestamp)); |
+} |
+ |
+// static |
+scoped_refptr<AudioBuffer> AudioBuffer::CreateBitstreamBuffer( |
+ SampleFormat sample_format, |
+ ChannelLayout channel_layout, |
+ int channel_count, |
+ int sample_rate, |
+ 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, data_size, kNoTimestamp)); |
} |
// static |
@@ -134,21 +163,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 +199,14 @@ 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_); |
+ |
+ const bool is_bitstream_format = IsBitstream(sample_format_); |
+ |
+ if (is_bitstream_format) { |
+ // TODO(tsunghung): Implement it along with AudioBus changes. |
+ NOTREACHED() << "Invalid sample format!"; |
+ } |
+ |
DCHECK_LE(dest_frame_offset + frames_to_copy, dest->frames()); |
if (!data_) { |
@@ -240,6 +272,7 @@ void AudioBuffer::ReadFrames(int frames_to_copy, |
void AudioBuffer::TrimStart(int frames_to_trim) { |
CHECK_GE(frames_to_trim, 0); |
CHECK_LE(frames_to_trim, adjusted_frame_count_); |
+ DCHECK(!IsBitstream(sample_format_)); |
TrimRange(0, frames_to_trim); |
} |
@@ -247,6 +280,7 @@ void AudioBuffer::TrimStart(int frames_to_trim) { |
void AudioBuffer::TrimEnd(int frames_to_trim) { |
CHECK_GE(frames_to_trim, 0); |
CHECK_LE(frames_to_trim, adjusted_frame_count_); |
+ DCHECK(!IsBitstream(sample_format_)); |
// Adjust the number of frames and duration for this buffer. |
adjusted_frame_count_ -= frames_to_trim; |
@@ -256,6 +290,7 @@ void AudioBuffer::TrimEnd(int frames_to_trim) { |
void AudioBuffer::TrimRange(int start, int end) { |
CHECK_GE(start, 0); |
CHECK_LE(end, adjusted_frame_count_); |
+ DCHECK(!IsBitstream(sample_format_)); |
const int frames_to_trim = end - start; |
CHECK_GE(frames_to_trim, 0); |