1 // Copyright 2014 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/mojo/services/renderer_config.h"
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "media/audio/audio_manager_base.h"
10 #include "media/audio/audio_output_stream_sink.h"
11 #include "media/audio/fake_audio_log_factory.h"
12 #include "media/base/media.h"
13 #include "media/filters/opus_audio_decoder.h"
15 #if !defined(MEDIA_DISABLE_FFMPEG)
16 #include "media/filters/ffmpeg_audio_decoder.h"
17 #include "media/filters/ffmpeg_video_decoder.h"
20 #if !defined(MEDIA_DISABLE_LIBVPX)
21 #include "media/filters/vpx_video_decoder.h"
27 class DefaultRendererConfig
: public PlatformRendererConfig
{
29 DefaultRendererConfig() {
30 // TODO(dalecurtis): This will not work if the process is sandboxed...
31 if (!media::IsMediaLibraryInitialized()) {
32 base::FilePath module_dir
;
33 CHECK(PathService::Get(base::DIR_EXE
, &module_dir
));
34 CHECK(media::InitializeMediaLibrary(module_dir
));
37 // TODO(dalecurtis): We should find a single owner per process for the audio
38 // manager or make it a lazy instance. It's not safe to call Get()/Create()
39 // across multiple threads...
41 // TODO(dalecurtis): Eventually we'll want something other than a fake audio
42 // log factory here too. We should probably at least DVLOG() such info.
43 AudioManager
* audio_manager
= AudioManager::Get();
45 audio_manager
= media::AudioManager::Create(&fake_audio_log_factory_
);
47 audio_hardware_config_
.reset(new AudioHardwareConfig(
48 audio_manager
->GetInputStreamParameters(
49 AudioManagerBase::kDefaultDeviceId
),
50 audio_manager
->GetDefaultOutputStreamParameters()));
53 ScopedVector
<AudioDecoder
> GetAudioDecoders(
54 const scoped_refptr
<base::SingleThreadTaskRunner
>& media_task_runner
,
55 const LogCB
& media_log_cb
) override
{
56 ScopedVector
<AudioDecoder
> audio_decoders
;
58 #if !defined(MEDIA_DISABLE_FFMPEG)
59 audio_decoders
.push_back(
60 new FFmpegAudioDecoder(media_task_runner
, media_log_cb
));
61 audio_decoders
.push_back(new OpusAudioDecoder(media_task_runner
));
64 return audio_decoders
.Pass();
67 ScopedVector
<VideoDecoder
> GetVideoDecoders(
68 const scoped_refptr
<base::SingleThreadTaskRunner
>& media_task_runner
,
69 const LogCB
& media_log_cb
) override
{
70 ScopedVector
<VideoDecoder
> video_decoders
;
72 // TODO(dalecurtis): If we ever need GPU video decoders, we'll need to
73 // figure out how to retrieve the GpuVideoAcceleratorFactories...
75 #if !defined(MEDIA_DISABLE_LIBVPX)
76 video_decoders
.push_back(new VpxVideoDecoder(media_task_runner
));
79 #if !defined(MEDIA_DISABLE_FFMPEG)
80 video_decoders
.push_back(new FFmpegVideoDecoder(media_task_runner
));
83 return video_decoders
.Pass();
86 scoped_refptr
<AudioRendererSink
> GetAudioRendererSink() override
{
87 return new AudioOutputStreamSink();
90 const AudioHardwareConfig
& GetAudioHardwareConfig() override
{
91 return *audio_hardware_config_
;
95 FakeAudioLogFactory fake_audio_log_factory_
;
96 scoped_ptr
<AudioHardwareConfig
> audio_hardware_config_
;
98 DISALLOW_COPY_AND_ASSIGN(DefaultRendererConfig
);
101 scoped_ptr
<PlatformRendererConfig
> CreatePlatformRendererConfig() {
102 return make_scoped_ptr(new DefaultRendererConfig());
105 } // namespace internal