Index: media/filters/opus_audio_decoder.cc |
diff --git a/media/filters/opus_audio_decoder.cc b/media/filters/opus_audio_decoder.cc |
index d234b19726af7cceaaae57801518ac9b486ec2d7..324b8b3438a6c5c9c5f96b32dbb890bbe26ca75a 100644 |
--- a/media/filters/opus_audio_decoder.cc |
+++ b/media/filters/opus_audio_decoder.cc |
@@ -31,12 +31,12 @@ static uint16 ReadLE16(const uint8* data, size_t data_size, int read_offset) { |
} |
// Returns true if the decode result was end of stream. |
-static inline bool IsEndOfStream(int decoded_size, |
- const scoped_refptr<DecoderBuffer>& input) { |
+static inline bool is_end_of_stream(int decoded_size, |
+ const scoped_refptr<DecoderBuffer>& input) { |
// Two conditions to meet to declare end of stream for this decoder: |
// 1. Opus didn't output anything. |
// 2. An end of stream buffer is received. |
- return decoded_size == 0 && input->IsEndOfStream(); |
+ return decoded_size == 0 && input->is_end_of_stream(); |
} |
// The Opus specification is part of IETF RFC 6716: |
@@ -58,8 +58,7 @@ static const int kMaxOpusOutputPacketSizeSamples = 960 * 6 * kMaxVorbisChannels; |
static const int kMaxOpusOutputPacketSizeBytes = |
kMaxOpusOutputPacketSizeSamples * kBytesPerChannel; |
-static void RemapOpusChannelLayout(const uint8* opus_mapping, |
- int num_channels, |
+static void RemapOpusChannelLayout(const uint8* opus_mapping, int num_channels, |
uint8* channel_layout) { |
DCHECK_LE(num_channels, kMaxVorbisChannels); |
@@ -90,33 +89,33 @@ static void RemapOpusChannelLayout(const uint8* opus_mapping, |
// These are the FFmpeg channel layouts expressed using the position of each |
// channel in the output stream from libopus. |
const uint8 kFFmpegChannelLayouts[num_layouts][num_layout_values] = { |
- { 0 }, |
+ {0}, |
// Stereo: No reorder. |
- { 0, 1 }, |
+ {0, 1}, |
// 3 Channels, from Vorbis order to: |
// L, R, Center |
- { 0, 2, 1 }, |
+ {0, 2, 1}, |
// 4 Channels: No reorder. |
- { 0, 1, 2, 3 }, |
+ {0, 1, 2, 3}, |
// 5 Channels, from Vorbis order to: |
// Front L, Front R, Center, Back L, Back R |
- { 0, 2, 1, 3, 4 }, |
+ {0, 2, 1, 3, 4}, |
// 6 Channels (5.1), from Vorbis order to: |
// Front L, Front R, Center, LFE, Back L, Back R |
- { 0, 2, 1, 5, 3, 4 }, |
+ {0, 2, 1, 5, 3, 4}, |
// 7 Channels (6.1), from Vorbis order to: |
// Front L, Front R, Front Center, LFE, Side L, Side R, Back Center |
- { 0, 2, 1, 6, 3, 4, 5 }, |
+ {0, 2, 1, 6, 3, 4, 5}, |
// 8 Channels (7.1), from Vorbis order to: |
// Front L, Front R, Center, LFE, Back L, Back R, Side L, Side R |
- { 0, 2, 1, 7, 5, 6, 3, 4 }, |
+ {0, 2, 1, 7, 5, 6, 3, 4}, |
}; |
// Reorder the channels to produce the same ordering as FFmpeg, which is |
@@ -155,7 +154,8 @@ static void RemapOpusChannelLayout(const uint8* opus_mapping, |
// stereo output: Opus streams with more than 2 channels require a stream map. |
static const int kMaxChannelsWithDefaultLayout = 2; |
static const uint8 kDefaultOpusChannelLayout[kMaxChannelsWithDefaultLayout] = { |
- 0, 1 }; |
+ 0, 1 |
+}; |
// Size of the Opus header excluding optional mapping information. |
static const int kOpusHeaderSize = 19; |
@@ -186,8 +186,7 @@ struct OpusHeader { |
channel_mapping(0), |
num_streams(0), |
num_coupled(0) { |
- memcpy(stream_map, |
- kDefaultOpusChannelLayout, |
+ memcpy(stream_map, kDefaultOpusChannelLayout, |
kMaxChannelsWithDefaultLayout); |
} |
int channels; |
@@ -251,13 +250,11 @@ OpusAudioDecoder::OpusAudioDecoder( |
samples_per_second_(0), |
last_input_timestamp_(kNoTimestamp()), |
output_bytes_to_drop_(0), |
- skip_samples_(0) { |
-} |
+ skip_samples_(0) {} |
-void OpusAudioDecoder::Initialize( |
- DemuxerStream* stream, |
- const PipelineStatusCB& status_cb, |
- const StatisticsCB& statistics_cb) { |
+void OpusAudioDecoder::Initialize(DemuxerStream* stream, |
+ const PipelineStatusCB& status_cb, |
+ const StatisticsCB& statistics_cb) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); |
@@ -324,9 +321,8 @@ void OpusAudioDecoder::ReadFromDemuxerStream() { |
demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_)); |
} |
-void OpusAudioDecoder::BufferReady( |
- DemuxerStream::Status status, |
- const scoped_refptr<DecoderBuffer>& input) { |
+void OpusAudioDecoder::BufferReady(DemuxerStream::Status status, |
+ const scoped_refptr<DecoderBuffer>& input) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
DCHECK(!read_cb_.is_null()); |
DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status; |
@@ -356,14 +352,14 @@ void OpusAudioDecoder::BufferReady( |
// Libopus does not buffer output. Decoding is complete when an end of stream |
// input buffer is received. |
- if (input->IsEndOfStream()) { |
+ if (input->is_end_of_stream()) { |
base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::create_eos_buffer()); |
return; |
} |
// Make sure we are notified if http://crbug.com/49709 returns. Issue also |
// occurs with some damaged files. |
- if (input->GetTimestamp() == kNoTimestamp() && |
+ if (input->get_timestamp() == kNoTimestamp() && |
output_timestamp_helper_->base_timestamp() == kNoTimestamp()) { |
DVLOG(1) << "Received a buffer without timestamps!"; |
base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
@@ -371,17 +367,17 @@ void OpusAudioDecoder::BufferReady( |
} |
if (last_input_timestamp_ != kNoTimestamp() && |
- input->GetTimestamp() != kNoTimestamp() && |
- input->GetTimestamp() < last_input_timestamp_) { |
- base::TimeDelta diff = input->GetTimestamp() - last_input_timestamp_; |
+ input->get_timestamp() != kNoTimestamp() && |
+ input->get_timestamp() < last_input_timestamp_) { |
+ base::TimeDelta diff = input->get_timestamp() - last_input_timestamp_; |
DVLOG(1) << "Input timestamps are not monotonically increasing! " |
- << " ts " << input->GetTimestamp().InMicroseconds() << " us" |
- << " diff " << diff.InMicroseconds() << " us"; |
+ << " ts " << input->get_timestamp().InMicroseconds() << " us" |
+ << " diff " << diff.InMicroseconds() << " us"; |
base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
return; |
} |
- last_input_timestamp_ = input->GetTimestamp(); |
+ last_input_timestamp_ = input->get_timestamp(); |
scoped_refptr<DataBuffer> output_buffer; |
@@ -430,17 +426,16 @@ bool OpusAudioDecoder::ConfigureDecoder() { |
return false; |
} |
- if (opus_decoder_ && |
- (bits_per_channel_ != config.bits_per_channel() || |
- channel_layout_ != config.channel_layout() || |
- samples_per_second_ != config.samples_per_second())) { |
+ if (opus_decoder_ && (bits_per_channel_ != config.bits_per_channel() || |
+ channel_layout_ != config.channel_layout() || |
+ samples_per_second_ != config.samples_per_second())) { |
DVLOG(1) << "Unsupported config change :"; |
- DVLOG(1) << "\tbits_per_channel : " << bits_per_channel_ |
- << " -> " << config.bits_per_channel(); |
- DVLOG(1) << "\tchannel_layout : " << channel_layout_ |
- << " -> " << config.channel_layout(); |
- DVLOG(1) << "\tsample_rate : " << samples_per_second_ |
- << " -> " << config.samples_per_second(); |
+ DVLOG(1) << "\tbits_per_channel : " << bits_per_channel_ << " -> " |
+ << config.bits_per_channel(); |
+ DVLOG(1) << "\tchannel_layout : " << channel_layout_ << " -> " |
+ << config.channel_layout(); |
+ DVLOG(1) << "\tsample_rate : " << samples_per_second_ << " -> " |
+ << config.samples_per_second(); |
return false; |
} |
@@ -453,8 +448,7 @@ bool OpusAudioDecoder::ConfigureDecoder() { |
// Parse the Opus header. |
OpusHeader opus_header; |
- ParseOpusHeader(config.extra_data(), config.extra_data_size(), |
- config, |
+ ParseOpusHeader(config.extra_data(), config.extra_data_size(), config, |
&opus_header); |
skip_samples_ = opus_header.skip_samples; |
@@ -463,24 +457,19 @@ bool OpusAudioDecoder::ConfigureDecoder() { |
output_bytes_to_drop_ = skip_samples_ * config.bytes_per_frame(); |
uint8 channel_mapping[kMaxVorbisChannels]; |
- memcpy(&channel_mapping, |
- kDefaultOpusChannelLayout, |
+ memcpy(&channel_mapping, kDefaultOpusChannelLayout, |
kMaxChannelsWithDefaultLayout); |
if (channel_count > kMaxChannelsWithDefaultLayout) { |
- RemapOpusChannelLayout(opus_header.stream_map, |
- channel_count, |
+ RemapOpusChannelLayout(opus_header.stream_map, channel_count, |
channel_mapping); |
} |
// Init Opus. |
int status = OPUS_INVALID_STATE; |
- opus_decoder_ = opus_multistream_decoder_create(config.samples_per_second(), |
- channel_count, |
- opus_header.num_streams, |
- opus_header.num_coupled, |
- channel_mapping, |
- &status); |
+ opus_decoder_ = opus_multistream_decoder_create( |
+ config.samples_per_second(), channel_count, opus_header.num_streams, |
+ opus_header.num_coupled, channel_mapping, &status); |
if (!opus_decoder_ || status != OPUS_OK) { |
LOG(ERROR) << "opus_multistream_decoder_create failed status=" |
<< opus_strerror(status); |
@@ -513,30 +502,29 @@ void OpusAudioDecoder::ResetTimestampState() { |
bool OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& input, |
scoped_refptr<DataBuffer>* output_buffer) { |
- const int samples_decoded = |
- opus_multistream_decode(opus_decoder_, |
- input->GetData(), input->GetDataSize(), |
- &output_buffer_[0], |
- kMaxOpusOutputPacketSizeSamples, |
- 0); |
+ const int samples_decoded = opus_multistream_decode( |
+ opus_decoder_, input->get_data(), input->get_data_size(), |
+ &output_buffer_[0], kMaxOpusOutputPacketSizeSamples, 0); |
if (samples_decoded < 0) { |
LOG(ERROR) << "opus_multistream_decode failed for" |
- << " timestamp: " << input->GetTimestamp().InMicroseconds() |
- << " us, duration: " << input->GetDuration().InMicroseconds() |
- << " us, packet size: " << input->GetDataSize() << " bytes with" |
+ << " timestamp: " << input->get_timestamp().InMicroseconds() |
+ << " us, duration: " << input->get_duration().InMicroseconds() |
+ << " us, packet size: " << input->get_data_size() |
+ << " bytes with" |
<< " status: " << opus_strerror(samples_decoded); |
return false; |
} |
uint8* decoded_audio_data = reinterpret_cast<uint8*>(&output_buffer_[0]); |
- int decoded_audio_size = samples_decoded * |
+ int decoded_audio_size = |
+ samples_decoded * |
demuxer_stream_->audio_decoder_config().bytes_per_frame(); |
DCHECK_LE(decoded_audio_size, kMaxOpusOutputPacketSizeBytes); |
if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() && |
- !input->IsEndOfStream()) { |
- DCHECK(input->GetTimestamp() != kNoTimestamp()); |
- output_timestamp_helper_->SetBaseTimestamp(input->GetTimestamp()); |
+ !input->is_end_of_stream()) { |
+ DCHECK(input->get_timestamp() != kNoTimestamp()); |
+ output_timestamp_helper_->SetBaseTimestamp(input->get_timestamp()); |
} |
if (decoded_audio_size > 0 && output_bytes_to_drop_ > 0) { |
@@ -549,8 +537,8 @@ bool OpusAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& input, |
if (decoded_audio_size > 0) { |
// Copy the audio samples into an output buffer. |
- *output_buffer = DataBuffer::copy_from( |
- decoded_audio_data, decoded_audio_size); |
+ *output_buffer = |
+ DataBuffer::copy_from(decoded_audio_data, decoded_audio_size); |
(*output_buffer)->set_timestamp(output_timestamp_helper_->GetTimestamp()); |
(*output_buffer)->set_duration( |
output_timestamp_helper_->GetDuration(decoded_audio_size)); |