Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / chromecast / renderer / media / chromecast_media_renderer_factory.cc
blob62fe7716a3d9770f28d3e2fa8ad841e6ea3dcd6a
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 {
18 namespace media {
20 ChromecastMediaRendererFactory::ChromecastMediaRendererFactory(
21 const scoped_refptr<::media::MediaLog>& media_log,
22 int render_frame_id)
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);
49 ::media::AudioHardwareConfig audio_config(input_audio_params,
50 output_audio_params);
52 default_render_factory_.reset(new ::media::DefaultRendererFactory(
53 media_log_, /*gpu_factories*/ nullptr, audio_config));
56 DCHECK(default_render_factory_);
57 // TODO(erickung): crbug.com/443956. Need to provide right LoadType.
58 LoadType cma_load_type = kLoadTypeMediaSource;
59 scoped_ptr<MediaPipeline> cma_media_pipeline(
60 new MediaPipelineProxy(
61 render_frame_id_,
62 content::RenderThread::Get()->GetIOMessageLoopProxy(),
63 cma_load_type));
64 scoped_ptr<CmaRenderer> cma_renderer(
65 new CmaRenderer(cma_media_pipeline.Pass(), video_renderer_sink));
66 scoped_ptr<::media::Renderer> default_media_render(
67 default_render_factory_->CreateRenderer(media_task_runner,
68 audio_renderer_sink,
69 video_renderer_sink));
70 scoped_ptr<SwitchingMediaRenderer> media_renderer(new SwitchingMediaRenderer(
71 default_media_render.Pass(), cma_renderer.Pass()));
72 return media_renderer.Pass();
75 } // namespace media
76 } // namespace chromecast