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::MediaLog
>& media_log
,
23 : render_frame_id_(render_frame_id
),
24 media_log_(media_log
) {
27 ChromecastMediaRendererFactory::~ChromecastMediaRendererFactory() {
30 scoped_ptr
<::media::Renderer
> ChromecastMediaRendererFactory::CreateRenderer(
31 const scoped_refptr
<base::SingleThreadTaskRunner
>& media_task_runner
,
32 ::media::AudioRendererSink
* audio_renderer_sink
,
33 ::media::VideoRendererSink
* video_renderer_sink
) {
34 if (!default_render_factory_
) {
35 // Chromecast doesn't have input audio devices, so leave this uninitialized
36 ::media::AudioParameters input_audio_params
;
37 // TODO(servolk): Audio parameters are hardcoded for now, but in the future
38 // either we need to obtain AudioHardwareConfig from RenderThreadImpl,
39 // or media renderer needs to figure out optimal audio parameters itself.
40 const int kDefaultSamplingRate
= 48000;
41 const int kDefaultBitsPerSample
= 16;
42 // About 20ms of stereo (2 channels) 16bit (2 byte) audio
43 int buffer_size
= kDefaultSamplingRate
* 20 * 2 * 2 / 1000;
44 ::media::AudioParameters
output_audio_params(
45 ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
46 ::media::CHANNEL_LAYOUT_STEREO
,
47 kDefaultSamplingRate
, kDefaultBitsPerSample
,
48 buffer_size
, ::media::AudioParameters::NO_EFFECTS
);
50 audio_config_
.reset(new ::media::AudioHardwareConfig(input_audio_params
,
51 output_audio_params
));
53 default_render_factory_
.reset(new ::media::DefaultRendererFactory(
54 media_log_
, /*gpu_factories*/ nullptr, *audio_config_
));
57 DCHECK(default_render_factory_
);
58 // TODO(erickung): crbug.com/443956. Need to provide right LoadType.
59 LoadType cma_load_type
= kLoadTypeMediaSource
;
60 scoped_ptr
<MediaPipeline
> cma_media_pipeline(
61 new MediaPipelineProxy(
63 content::RenderThread::Get()->GetIOMessageLoopProxy(),
65 scoped_ptr
<CmaRenderer
> cma_renderer(
66 new CmaRenderer(cma_media_pipeline
.Pass(), video_renderer_sink
));
67 scoped_ptr
<::media::Renderer
> default_media_render(
68 default_render_factory_
->CreateRenderer(media_task_runner
,
70 video_renderer_sink
));
71 scoped_ptr
<SwitchingMediaRenderer
> media_renderer(new SwitchingMediaRenderer(
72 default_media_render
.Pass(), cma_renderer
.Pass()));
73 return media_renderer
.Pass();
77 } // namespace chromecast