summaryrefslogtreecommitdiffstats
path: root/media/mojo/services/renderer_config_default.cc
blob: 7cee1a7ac6c35531d6c88d583970f96b2c872888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/mojo/services/renderer_config.h"

#include "base/files/file_path.h"
#include "base/path_service.h"
#include "media/audio/audio_manager_base.h"
#include "media/audio/audio_output_stream_sink.h"
#include "media/audio/fake_audio_log_factory.h"
#include "media/base/media.h"
#include "media/filters/opus_audio_decoder.h"

#if !defined(MEDIA_DISABLE_FFMPEG)
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_video_decoder.h"
#endif

#if !defined(MEDIA_DISABLE_LIBVPX)
#include "media/filters/vpx_video_decoder.h"
#endif

namespace media {
namespace internal {

class DummyVideoRendererSink : public VideoRendererSink {
 public:
  DummyVideoRendererSink() {}
  ~DummyVideoRendererSink() override {}

  void Start(RenderCallback* callback) override {}
  void Stop() override {}
  void PaintFrameUsingOldRenderingPath(
      const scoped_refptr<VideoFrame>& frame) override {}

 private:
  DISALLOW_COPY_AND_ASSIGN(DummyVideoRendererSink);
};

class DefaultRendererConfig : public PlatformRendererConfig {
 public:
  DefaultRendererConfig() {
    // TODO(dalecurtis): This will not work if the process is sandboxed...
    if (!media::IsMediaLibraryInitialized()) {
      base::FilePath module_dir;
      CHECK(PathService::Get(base::DIR_EXE, &module_dir));
      CHECK(media::InitializeMediaLibrary(module_dir));
    }

    // TODO(dalecurtis): We should find a single owner per process for the audio
    // manager or make it a lazy instance.  It's not safe to call Get()/Create()
    // across multiple threads...
    //
    // TODO(dalecurtis): Eventually we'll want something other than a fake audio
    // log factory here too.  We should probably at least DVLOG() such info.
    AudioManager* audio_manager = AudioManager::Get();
    if (!audio_manager)
      audio_manager = media::AudioManager::Create(&fake_audio_log_factory_);

    audio_hardware_config_.reset(new AudioHardwareConfig(
        audio_manager->GetInputStreamParameters(
            AudioManagerBase::kDefaultDeviceId),
        audio_manager->GetDefaultOutputStreamParameters()));
  }

  ScopedVector<AudioDecoder> GetAudioDecoders(
      const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
      const LogCB& media_log_cb) override {
    ScopedVector<AudioDecoder> audio_decoders;

#if !defined(MEDIA_DISABLE_FFMPEG)
    audio_decoders.push_back(
        new FFmpegAudioDecoder(media_task_runner, media_log_cb));
    audio_decoders.push_back(new OpusAudioDecoder(media_task_runner));
#endif

    return audio_decoders.Pass();
  }

  ScopedVector<VideoDecoder> GetVideoDecoders(
      const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
      const LogCB& media_log_cb) override {
    ScopedVector<VideoDecoder> video_decoders;

    // TODO(dalecurtis): If we ever need GPU video decoders, we'll need to
    // figure out how to retrieve the GpuVideoAcceleratorFactories...

#if !defined(MEDIA_DISABLE_LIBVPX)
    video_decoders.push_back(new VpxVideoDecoder(media_task_runner));
#endif

#if !defined(MEDIA_DISABLE_FFMPEG)
    video_decoders.push_back(new FFmpegVideoDecoder(media_task_runner));
#endif

    return video_decoders.Pass();
  }

  scoped_refptr<AudioRendererSink> GetAudioRendererSink() override {
    return new AudioOutputStreamSink();
  }

  scoped_ptr<VideoRendererSink> GetVideoRendererSink() override {
    return make_scoped_ptr(new DummyVideoRendererSink());
  }

  const AudioHardwareConfig& GetAudioHardwareConfig() override {
    return *audio_hardware_config_;
  }

 private:
  FakeAudioLogFactory fake_audio_log_factory_;
  scoped_ptr<AudioHardwareConfig> audio_hardware_config_;

  DISALLOW_COPY_AND_ASSIGN(DefaultRendererConfig);
};

scoped_ptr<PlatformRendererConfig> CreatePlatformRendererConfig() {
  return make_scoped_ptr(new DefaultRendererConfig());
}

}  // namespace internal
}  // namespace media