Fix for browser_plugin_host_browsertest when embedder is not yet available.
[chromium-blink-merge.git] / media / base / android / audio_decoder_job.cc
blobd089796ccc65cc1de197aa75b2b1f25a58b7ca7e
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"
7 #include "base/bind.h"
8 #include "base/lazy_instance.h"
9 #include "base/threading/thread.h"
10 #include "media/base/android/media_codec_bridge.h"
12 namespace media {
14 class AudioDecoderThread : public base::Thread {
15 public:
16 AudioDecoderThread() : base::Thread("MediaSource_AudioDecoderThread") {
17 Start();
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,
29 int sample_rate,
30 int channel_count,
31 const uint8* extra_data,
32 size_t extra_data_size,
33 jobject media_crypto,
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.";
42 return NULL;
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,
62 size_t size,
63 bool render_output,
64 const ReleaseOutputCompletionCallback& callback) {
65 size_t size_to_render = render_output ? size : 0u;
66 if (size_to_render)
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 {
74 return false;
77 } // namespace media