Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / media / audio_device_factory.cc
blob6d0dd1db021f43cac1cdc886195d3f0fda88d360
1 // Copyright (c) 2012 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 "content/renderer/media/audio_device_factory.h"
7 #include "base/logging.h"
8 #include "content/renderer/media/audio_input_message_filter.h"
9 #include "content/renderer/media/audio_message_filter.h"
10 #include "media/audio/audio_input_device.h"
11 #include "media/audio/audio_output_device.h"
13 namespace content {
15 // static
16 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL;
18 // static
19 scoped_refptr<media::AudioOutputDevice> AudioDeviceFactory::NewOutputDevice(
20 int render_frame_id) {
21 if (factory_) {
22 media::AudioOutputDevice* const device =
23 factory_->CreateOutputDevice(render_frame_id);
24 if (device)
25 return device;
28 AudioMessageFilter* const filter = AudioMessageFilter::Get();
29 return new media::AudioOutputDevice(
30 filter->CreateAudioOutputIPC(render_frame_id), filter->io_message_loop());
33 // static
34 scoped_refptr<media::AudioInputDevice> AudioDeviceFactory::NewInputDevice(
35 int render_frame_id) {
36 if (factory_) {
37 media::AudioInputDevice* const device =
38 factory_->CreateInputDevice(render_frame_id);
39 if (device)
40 return device;
43 AudioInputMessageFilter* const filter = AudioInputMessageFilter::Get();
44 return new media::AudioInputDevice(
45 filter->CreateAudioInputIPC(render_frame_id), filter->io_message_loop());
48 AudioDeviceFactory::AudioDeviceFactory() {
49 DCHECK(!factory_) << "Can't register two factories at once.";
50 factory_ = this;
53 AudioDeviceFactory::~AudioDeviceFactory() {
54 factory_ = NULL;
57 } // namespace content