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/renderers/default_renderer_factory.h"
8 #include "build/build_config.h"
9 #include "base/single_thread_task_runner.h"
10 #include "media/base/media_log.h"
11 #include "media/filters/gpu_video_decoder.h"
12 #include "media/renderers/audio_renderer_impl.h"
13 #include "media/renderers/gpu_video_accelerator_factories.h"
14 #include "media/renderers/renderer_impl.h"
15 #include "media/renderers/video_renderer_impl.h"
17 #if !defined(MEDIA_DISABLE_FFMPEG)
18 #include "media/filters/ffmpeg_audio_decoder.h"
19 #include "media/filters/ffmpeg_video_decoder.h"
22 #if !defined(OS_ANDROID)
23 #include "media/filters/opus_audio_decoder.h"
26 #if !defined(MEDIA_DISABLE_LIBVPX)
27 #include "media/filters/vpx_video_decoder.h"
32 DefaultRendererFactory::DefaultRendererFactory(
33 const scoped_refptr
<MediaLog
>& media_log
,
34 const scoped_refptr
<GpuVideoAcceleratorFactories
>& gpu_factories
,
35 const AudioHardwareConfig
& audio_hardware_config
)
36 : media_log_(media_log
),
37 gpu_factories_(gpu_factories
),
38 audio_hardware_config_(audio_hardware_config
) {
41 DefaultRendererFactory::~DefaultRendererFactory() {
44 scoped_ptr
<Renderer
> DefaultRendererFactory::CreateRenderer(
45 const scoped_refptr
<base::SingleThreadTaskRunner
>& media_task_runner
,
46 AudioRendererSink
* audio_renderer_sink
,
47 VideoRendererSink
* video_renderer_sink
) {
48 DCHECK(audio_renderer_sink
);
50 // Create our audio decoders and renderer.
51 ScopedVector
<AudioDecoder
> audio_decoders
;
53 #if !defined(MEDIA_DISABLE_FFMPEG)
54 audio_decoders
.push_back(new FFmpegAudioDecoder(
55 media_task_runner
, base::Bind(&MediaLog::AddLogEvent
, media_log_
)));
58 #if !defined(OS_ANDROID)
59 audio_decoders
.push_back(new OpusAudioDecoder(media_task_runner
));
62 scoped_ptr
<AudioRenderer
> audio_renderer(new AudioRendererImpl(
63 media_task_runner
, audio_renderer_sink
, audio_decoders
.Pass(),
64 audio_hardware_config_
, media_log_
));
66 // Create our video decoders and renderer.
67 ScopedVector
<VideoDecoder
> video_decoders
;
69 // |gpu_factories_| requires that its entry points be called on its
70 // |GetTaskRunner()|. Since |pipeline_| will own decoders created from the
71 // factories, require that their message loops are identical.
72 DCHECK(!gpu_factories_
.get() ||
73 (gpu_factories_
->GetTaskRunner() == media_task_runner
.get()));
75 if (gpu_factories_
.get())
76 video_decoders
.push_back(new GpuVideoDecoder(gpu_factories_
));
78 #if !defined(MEDIA_DISABLE_LIBVPX)
79 video_decoders
.push_back(new VpxVideoDecoder(media_task_runner
));
82 #if !defined(MEDIA_DISABLE_FFMPEG)
83 video_decoders
.push_back(new FFmpegVideoDecoder(media_task_runner
));
86 scoped_ptr
<VideoRenderer
> video_renderer(new VideoRendererImpl(
87 media_task_runner
, video_renderer_sink
, video_decoders
.Pass(), true,
88 gpu_factories_
, media_log_
));
91 return scoped_ptr
<Renderer
>(new RendererImpl(
92 media_task_runner
, audio_renderer
.Pass(), video_renderer
.Pass()));