Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / mojo / services / default_mojo_media_client.cc
blob57bf900792c150188bb271c4c2a3f8b8b86a6b30
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/mojo/services/mojo_media_client.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "media/audio/audio_manager_base.h"
9 #include "media/audio/audio_output_stream_sink.h"
10 #include "media/audio/fake_audio_log_factory.h"
11 #include "media/base/media.h"
12 #include "media/base/null_video_sink.h"
13 #include "media/cdm/default_cdm_factory.h"
14 #include "media/renderers/default_renderer_factory.h"
15 #include "media/renderers/gpu_video_accelerator_factories.h"
17 namespace media {
18 namespace internal {
20 class DefaultMojoMediaClient : public PlatformMojoMediaClient {
21 public:
22 DefaultMojoMediaClient() {
23 InitializeMediaLibrary();
25 // TODO(dalecurtis): We should find a single owner per process for the audio
26 // manager or make it a lazy instance. It's not safe to call Get()/Create()
27 // across multiple threads...
29 // TODO(dalecurtis): Eventually we'll want something other than a fake audio
30 // log factory here too. We should probably at least DVLOG() such info.
31 AudioManager* audio_manager = AudioManager::Get();
32 if (!audio_manager)
33 audio_manager = media::AudioManager::Create(&fake_audio_log_factory_);
35 audio_hardware_config_.reset(new AudioHardwareConfig(
36 audio_manager->GetInputStreamParameters(
37 AudioManagerBase::kDefaultDeviceId),
38 audio_manager->GetDefaultOutputStreamParameters()));
41 scoped_ptr<RendererFactory> CreateRendererFactory(
42 const scoped_refptr<MediaLog>& media_log) override {
43 return make_scoped_ptr(new DefaultRendererFactory(media_log, nullptr,
44 *audio_hardware_config_));
47 ScopedVector<AudioDecoder> CreateAudioDecoders(
48 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
49 const scoped_refptr<MediaLog>& media_log) override {
50 NOTREACHED();
51 return ScopedVector<AudioDecoder>();
54 ScopedVector<VideoDecoder> CreateVideoDecoders(
55 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
56 const scoped_refptr<MediaLog>& media_log) override {
57 NOTREACHED();
58 return ScopedVector<VideoDecoder>();
61 scoped_refptr<AudioRendererSink> CreateAudioRendererSink() override {
62 return new AudioOutputStreamSink();
65 scoped_ptr<VideoRendererSink> CreateVideoRendererSink(
66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) override {
67 return make_scoped_ptr(
68 new NullVideoSink(false, base::TimeDelta::FromSecondsD(1.0 / 60),
69 NullVideoSink::NewFrameCB(), task_runner));
72 const AudioHardwareConfig& GetAudioHardwareConfig() override {
73 return *audio_hardware_config_;
76 scoped_ptr<CdmFactory> CreateCdmFactory() override {
77 return make_scoped_ptr(new DefaultCdmFactory());
80 private:
81 FakeAudioLogFactory fake_audio_log_factory_;
82 scoped_ptr<AudioHardwareConfig> audio_hardware_config_;
84 DISALLOW_COPY_AND_ASSIGN(DefaultMojoMediaClient);
87 scoped_ptr<PlatformMojoMediaClient> CreatePlatformMojoMediaClient() {
88 return make_scoped_ptr(new DefaultMojoMediaClient());
91 } // namespace internal
92 } // namespace media