Make Chromoting browser tests pass again
[chromium-blink-merge.git] / media / renderers / default_renderer_factory.cc
blob8f701b3ac5037234dab8571cff05965a6a639eae
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"
7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h"
9 #if !defined(MEDIA_DISABLE_FFMPEG)
10 #include "media/filters/ffmpeg_audio_decoder.h"
11 #include "media/filters/ffmpeg_video_decoder.h"
12 #endif
13 #include "media/filters/gpu_video_accelerator_factories.h"
14 #include "media/filters/gpu_video_decoder.h"
15 #include "media/filters/opus_audio_decoder.h"
16 #include "media/renderers/audio_renderer_impl.h"
17 #include "media/renderers/renderer_impl.h"
18 #include "media/renderers/video_renderer_impl.h"
19 #if !defined(MEDIA_DISABLE_LIBVPX)
20 #include "media/filters/vpx_video_decoder.h"
21 #endif
23 namespace media {
25 #if !defined(MEDIA_DISABLE_FFMPEG)
26 // TODO(xhwang): We are abusing CreateMediaSourceErrorEvent() in a lot of places
27 // that are not MediaSource related. Fix this in a separate CL.
28 static void LogError(const scoped_refptr<MediaLog>& media_log,
29 const std::string& error) {
30 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error));
32 #endif
34 DefaultRendererFactory::DefaultRendererFactory(
35 const scoped_refptr<MediaLog>& media_log,
36 const scoped_refptr<GpuVideoAcceleratorFactories>& gpu_factories,
37 const AudioHardwareConfig& audio_hardware_config)
38 : media_log_(media_log),
39 gpu_factories_(gpu_factories),
40 audio_hardware_config_(audio_hardware_config) {
43 DefaultRendererFactory::~DefaultRendererFactory() {
46 // TODO(xhwang): Use RendererConfig to customize what decoders we use.
47 scoped_ptr<Renderer> DefaultRendererFactory::CreateRenderer(
48 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
49 AudioRendererSink* audio_renderer_sink) {
50 DCHECK(audio_renderer_sink);
52 // Create our audio decoders and renderer.
53 ScopedVector<AudioDecoder> audio_decoders;
55 #if !defined(MEDIA_DISABLE_FFMPEG)
56 audio_decoders.push_back(new FFmpegAudioDecoder(
57 media_task_runner, base::Bind(&LogError, media_log_)));
58 #endif
60 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));
80 #endif
82 #if !defined(MEDIA_DISABLE_FFMPEG)
83 video_decoders.push_back(new FFmpegVideoDecoder(media_task_runner));
84 #endif
86 scoped_ptr<VideoRenderer> video_renderer(new VideoRendererImpl(
87 media_task_runner, video_decoders.Pass(), true, media_log_));
89 // Create renderer.
90 return scoped_ptr<Renderer>(new RendererImpl(
91 media_task_runner, audio_renderer.Pass(), video_renderer.Pass()));
94 } // namespace media