Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: media/filters/android/media_codec_audio_decoder.cc

Issue 2572573007: Use passthrough decoder for (E)AC3 formats (Closed)
Patch Set: Use BitReader to unpack header fileds Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a2b2d40703551a5bb1f6e6562bcefb4f9a37f183 100644
--- a/media/filters/android/media_codec_audio_decoder.cc
+++ b/media/filters/android/media_codec_audio_decoder.cc
@@ -4,6 +4,8 @@
#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"
@@ -14,6 +16,7 @@
#include "media/base/audio_timestamp_helper.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/timestamp_constants.h"
+#include "media/formats/ac3/ac3_util.h"
namespace media {
@@ -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) {
chcunningham 2016/12/16 22:03:14 You make the is_passthrough_ decision in two place
AndyWu 2017/05/02 23:41:03 Done, thanks for your comment. On 2016/12/16 22:0
+ 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());

Powered by Google App Engine
This is Rietveld 408576698