| Index: media/filters/android/media_codec_audio_decoder.cc
|
| diff --git a/media/filters/android/media_codec_audio_decoder.cc b/media/filters/android/media_codec_audio_decoder.cc
|
| index a38e57a3770d17ad947a4fed7eada3b0b9349f9b..1e33f6bd2f9224d26bc105bae411e7b351ca8c43 100644
|
| --- a/media/filters/android/media_codec_audio_decoder.cc
|
| +++ b/media/filters/android/media_codec_audio_decoder.cc
|
| @@ -4,11 +4,14 @@
|
|
|
| #include "media/filters/android/media_codec_audio_decoder.h"
|
|
|
| +#include <cmath>
|
| +
|
| #include "base/android/build_info.h"
|
| #include "base/bind.h"
|
| #include "base/callback_helpers.h"
|
| #include "base/logging.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| +#include "media/base/ac3_util.h"
|
| #include "media/base/android/sdk_media_codec_bridge.h"
|
| #include "media/base/audio_buffer.h"
|
| #include "media/base/audio_timestamp_helper.h"
|
| @@ -21,6 +24,8 @@ MediaCodecAudioDecoder::MediaCodecAudioDecoder(
|
| scoped_refptr<base::SingleThreadTaskRunner> task_runner)
|
| : task_runner_(task_runner),
|
| state_(STATE_UNINITIALIZED),
|
| + is_passthrough_(false),
|
| + sample_format_(kSampleFormatS16),
|
| channel_count_(0),
|
| channel_layout_(CHANNEL_LAYOUT_NONE),
|
| sample_rate_(0),
|
| @@ -60,6 +65,19 @@ void MediaCodecAudioDecoder::Initialize(const AudioDecoderConfig& config,
|
| DCHECK_EQ(state_, STATE_UNINITIALIZED);
|
|
|
| InitCB bound_init_cb = BindToCurrentLoop(init_cb);
|
| + sample_format_ = kSampleFormatS16;
|
| + is_passthrough_ = false;
|
| +
|
| + if (config.codec() == kCodecAC3) {
|
| + sample_format_ = kSampleFormatAc3;
|
| + is_passthrough_ = true;
|
| + } else if (config.codec() == kCodecEAC3) {
|
| + sample_format_ = kSampleFormatEac3;
|
| + is_passthrough_ = true;
|
| + }
|
| +
|
| + // TODO(tsunghung): Add |is_passthrough_| in the following statement
|
| + // to enable passthrough decoder.
|
|
|
| // We can support only the codecs that AudioCodecBridge can decode.
|
| const bool is_codec_supported = config.codec() == kCodecVorbis ||
|
| @@ -353,14 +371,42 @@ bool MediaCodecAudioDecoder::OnDecodedFrame(
|
| // of channels which can be different from |config_| value.
|
| DCHECK_GT(channel_count_, 0);
|
|
|
| - // Android MediaCodec can only output 16bit PCM audio.
|
| - const int bytes_per_frame = sizeof(uint16_t) * channel_count_;
|
| - const size_t frame_count = out.size / bytes_per_frame;
|
| + size_t frame_count = 0;
|
| + scoped_refptr<AudioBuffer> audio_buffer;
|
| +
|
| + if (is_passthrough_) {
|
| + const uint8_t* data = nullptr;
|
| + size_t data_size;
|
| + MediaCodecStatus status = media_codec->GetOutputBufferAddress(
|
| + out.index, out.offset, &data, &data_size);
|
| +
|
| + if (status != MEDIA_CODEC_OK || !data) {
|
| + media_codec->ReleaseOutputBuffer(out.index, false);
|
| + return false;
|
| + }
|
| +
|
| + if (config_.codec() == kCodecAC3) {
|
| + frame_count = Ac3Util::ParseTotalAc3SampleCount(data, data_size);
|
| + } else if (config_.codec() == kCodecEAC3) {
|
| + frame_count = Ac3Util::ParseTotalEac3SampleCount(data, data_size);
|
| + } else {
|
| + NOTREACHED() << "Unsupported passthrough format.";
|
| + }
|
|
|
| - // Create AudioOutput buffer based on current parameters.
|
| - scoped_refptr<AudioBuffer> audio_buffer =
|
| - AudioBuffer::CreateBuffer(kSampleFormatS16, channel_layout_,
|
| - channel_count_, sample_rate_, frame_count);
|
| + // Create AudioOutput buffer based on current parameters.
|
| + audio_buffer = AudioBuffer::CreateBitstreamBuffer(
|
| + sample_format_, channel_layout_, channel_count_, sample_rate_,
|
| + frame_count, out.size);
|
| + } else {
|
| + // Android MediaCodec can only output 16bit PCM audio.
|
| + const int bytes_per_frame = sizeof(uint16_t) * channel_count_;
|
| + frame_count = out.size / bytes_per_frame;
|
| +
|
| + // Create AudioOutput buffer based on current parameters.
|
| + audio_buffer =
|
| + AudioBuffer::CreateBuffer(sample_format_, channel_layout_,
|
| + channel_count_, sample_rate_, frame_count);
|
| + }
|
|
|
| // Copy data into AudioBuffer.
|
| CHECK_LE(out.size, audio_buffer->data_size());
|
|
|