1 // Copyright 2015 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 "chromecast/renderer/media/chromecast_media_renderer_factory.h"
7 #include "base/command_line.h"
8 #include "chromecast/media/base/switching_media_renderer.h"
9 #include "chromecast/media/cma/filters/cma_renderer.h"
10 #include "chromecast/renderer/media/media_pipeline_proxy.h"
11 #include "content/public/renderer/render_thread.h"
12 #include "media/base/audio_hardware_config.h"
13 #include "media/base/media_log.h"
14 #include "media/renderers/default_renderer_factory.h"
15 #include "media/renderers/gpu_video_accelerator_factories.h"
17 namespace chromecast
{
20 ChromecastMediaRendererFactory::ChromecastMediaRendererFactory(
21 const scoped_refptr
<::media::GpuVideoAcceleratorFactories
>& gpu_factories
,
22 const scoped_refptr
<::media::MediaLog
>& media_log
,
24 : render_frame_id_(render_frame_id
),
25 gpu_factories_(gpu_factories
),
26 media_log_(media_log
) {
29 ChromecastMediaRendererFactory::~ChromecastMediaRendererFactory() {
32 scoped_ptr
<::media::Renderer
> ChromecastMediaRendererFactory::CreateRenderer(
33 const scoped_refptr
<base::SingleThreadTaskRunner
>& media_task_runner
,
34 const scoped_refptr
<base::TaskRunner
>& worker_task_runner
,
35 ::media::AudioRendererSink
* audio_renderer_sink
,
36 ::media::VideoRendererSink
* video_renderer_sink
) {
37 if (!default_render_factory_
) {
38 // Chromecast doesn't have input audio devices, so leave this uninitialized
39 ::media::AudioParameters input_audio_params
;
40 // TODO(servolk): Audio parameters are hardcoded for now, but in the future
41 // either we need to obtain AudioHardwareConfig from RenderThreadImpl,
42 // or media renderer needs to figure out optimal audio parameters itself.
43 const int kDefaultSamplingRate
= 48000;
44 const int kDefaultBitsPerSample
= 16;
45 // About 20ms of stereo (2 channels) 16bit (2 byte) audio
46 int buffer_size
= kDefaultSamplingRate
* 20 * 2 * 2 / 1000;
47 ::media::AudioParameters
output_audio_params(
48 ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
49 ::media::CHANNEL_LAYOUT_STEREO
, kDefaultSamplingRate
,
50 kDefaultBitsPerSample
, buffer_size
);
52 audio_config_
.reset(new ::media::AudioHardwareConfig(input_audio_params
,
53 output_audio_params
));
55 default_render_factory_
.reset(new ::media::DefaultRendererFactory(
56 media_log_
, /*gpu_factories*/ nullptr, *audio_config_
));
59 DCHECK(default_render_factory_
);
60 // TODO(erickung): crbug.com/443956. Need to provide right LoadType.
61 LoadType cma_load_type
= kLoadTypeMediaSource
;
62 scoped_ptr
<MediaPipeline
> cma_media_pipeline(
63 new MediaPipelineProxy(
65 content::RenderThread::Get()->GetIOMessageLoopProxy(),
67 scoped_ptr
<CmaRenderer
> cma_renderer(new CmaRenderer(
68 cma_media_pipeline
.Pass(), video_renderer_sink
, gpu_factories_
));
69 scoped_ptr
<::media::Renderer
> default_media_render(
70 default_render_factory_
->CreateRenderer(
71 media_task_runner
, media_task_runner
, audio_renderer_sink
,
72 video_renderer_sink
));
73 scoped_ptr
<SwitchingMediaRenderer
> media_renderer(new SwitchingMediaRenderer(
74 default_media_render
.Pass(), cma_renderer
.Pass()));
75 return media_renderer
.Pass();
79 } // namespace chromecast