1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/android/audio_decoder_job.h"
8 #include "base/lazy_instance.h"
9 #include "base/threading/thread.h"
10 #include "media/base/android/media_codec_bridge.h"
14 class AudioDecoderThread
: public base::Thread
{
16 AudioDecoderThread() : base::Thread("MediaSource_AudioDecoderThread") {
21 // TODO(qinmin): Check if it is tolerable to use worker pool to handle all the
22 // decoding tasks so that we don't need a global thread here.
23 // http://crbug.com/245750
24 base::LazyInstance
<AudioDecoderThread
>::Leaky
25 g_audio_decoder_thread
= LAZY_INSTANCE_INITIALIZER
;
27 AudioDecoderJob
* AudioDecoderJob::Create(
28 const AudioCodec audio_codec
,
31 const uint8
* extra_data
,
32 size_t extra_data_size
,
34 const base::Closure
& request_data_cb
) {
35 scoped_ptr
<AudioCodecBridge
> codec(AudioCodecBridge::Create(audio_codec
));
36 if (codec
&& codec
->Start(audio_codec
, sample_rate
, channel_count
, extra_data
,
37 extra_data_size
, true, media_crypto
)) {
38 return new AudioDecoderJob(codec
.Pass(), request_data_cb
);
41 LOG(ERROR
) << "Failed to create AudioDecoderJob.";
45 AudioDecoderJob::AudioDecoderJob(
46 scoped_ptr
<AudioCodecBridge
> audio_codec_bridge
,
47 const base::Closure
& request_data_cb
)
48 : MediaDecoderJob(g_audio_decoder_thread
.Pointer()->message_loop_proxy(),
49 audio_codec_bridge
.get(), request_data_cb
),
50 audio_codec_bridge_(audio_codec_bridge
.Pass()) {
53 AudioDecoderJob::~AudioDecoderJob() {
56 void AudioDecoderJob::SetVolume(double volume
) {
57 audio_codec_bridge_
->SetVolume(volume
);
60 void AudioDecoderJob::ReleaseOutputBuffer(
61 int output_buffer_index
,
64 const ReleaseOutputCompletionCallback
& callback
) {
65 size_t size_to_render
= render_output
? size
: 0u;
67 audio_codec_bridge_
->PlayOutputBuffer(output_buffer_index
, size_to_render
);
68 audio_codec_bridge_
->ReleaseOutputBuffer(output_buffer_index
, false);
70 callback
.Run(size_to_render
);
73 bool AudioDecoderJob::ComputeTimeToRender() const {