Index: media/base/audio_buffer.cc |
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc |
index d921a8a39d7d5752174bb3f08edc4f770ce71a6a..93a06aaaaa047f750cb379029491faa1a6cad9eb 100644 |
--- a/media/base/audio_buffer.cc |
+++ b/media/base/audio_buffer.cc |
@@ -49,6 +49,7 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format, |
int frame_count, |
bool create_buffer, |
const uint8_t* const* data, |
+ const size_t data_size, |
const base::TimeDelta timestamp, |
scoped_refptr<AudioBufferMemoryPool> pool) |
: sample_format_(sample_format), |
@@ -61,7 +62,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), |
pool_(std::move(pool)) { |
CHECK_GE(channel_count_, 0); |
CHECK_LE(channel_count_, limits::kMaxChannels); |
@@ -108,7 +109,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)) |
+ data_size_ = data_size_per_channel * channel_count_; |
chcunningham
2017/05/05 01:14:12
else DCHECK(data_size_ > 0)?
AndyWu
2017/05/06 01:46:48
Done.
|
if (pool_) { |
data_ = pool_->CreateBuffer(data_size_); |
@@ -143,7 +145,26 @@ scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom( |
CHECK(data[0]); |
return make_scoped_refptr( |
new AudioBuffer(sample_format, channel_layout, channel_count, sample_rate, |
- frame_count, true, data, timestamp, std::move(pool))); |
+ frame_count, true, data, 0, timestamp, std::move(pool))); |
+} |
+ |
+// 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, |
+ scoped_refptr<AudioBufferMemoryPool> pool) { |
+ // 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, data_size, timestamp, std::move(pool))); |
} |
// static |
@@ -157,7 +178,22 @@ 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, nullptr, kNoTimestamp, std::move(pool))); |
+ true, nullptr, 0, kNoTimestamp, std::move(pool))); |
+} |
+ |
+// 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, |
+ scoped_refptr<AudioBufferMemoryPool> pool) { |
+ 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, nullptr, data_size, kNoTimestamp, std::move(pool))); |
} |
// static |
@@ -171,14 +207,14 @@ scoped_refptr<AudioBuffer> AudioBuffer::CreateEmptyBuffer( |
// Since data == nullptr, format doesn't matter. |
return make_scoped_refptr(new AudioBuffer( |
kSampleFormatF32, channel_layout, channel_count, sample_rate, frame_count, |
- false, nullptr, timestamp, nullptr)); |
+ false, nullptr, 0, timestamp, nullptr)); |
} |
// static |
scoped_refptr<AudioBuffer> AudioBuffer::CreateEOSBuffer() { |
return make_scoped_refptr(new AudioBuffer(kUnknownSampleFormat, |
CHANNEL_LAYOUT_NONE, 0, 0, 0, false, |
- nullptr, kNoTimestamp, nullptr)); |
+ nullptr, 0, kNoTimestamp, nullptr)); |
} |
// Convert int16_t values in the range [INT16_MIN, INT16_MAX] to [-1.0, 1.0]. |
@@ -205,6 +241,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_compressed_format = IsBitstream(sample_format_); |
+ dest->set_is_compressed_format(is_compressed_format); |
chcunningham
2017/05/05 01:14:11
is_compressed_format is slightly different name fr
AndyWu
2017/05/06 01:46:48
Sorry, this change should not be included in this
|
+ |
+ if (is_compressed_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_) { |
@@ -269,6 +320,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_)); |
chcunningham
2017/05/05 01:14:11
These methods are called in frame_processor as par
AndyWu
2017/05/06 01:46:48
Done. However, we really should prevent trimming c
chcunningham
2017/05/08 20:01:02
They current MediaSource API doesn't really afford
|
TrimRange(0, frames_to_trim); |
} |
@@ -276,6 +328,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; |
@@ -285,6 +338,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); |