• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/renderer/media/audio_device_factory.h"
6 
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"
12 
13 namespace content {
14 
15 // static
16 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL;
17 
18 // static
NewOutputDevice(int render_view_id,int render_frame_id)19 scoped_refptr<media::AudioOutputDevice> AudioDeviceFactory::NewOutputDevice(
20     int render_view_id, int render_frame_id) {
21   if (factory_) {
22     media::AudioOutputDevice* const device =
23         factory_->CreateOutputDevice(render_view_id);
24     if (device)
25       return device;
26   }
27 
28   AudioMessageFilter* const filter = AudioMessageFilter::Get();
29   return new media::AudioOutputDevice(
30       filter->CreateAudioOutputIPC(render_view_id, render_frame_id),
31       filter->io_message_loop());
32 }
33 
34 // static
NewInputDevice(int render_view_id)35 scoped_refptr<media::AudioInputDevice> AudioDeviceFactory::NewInputDevice(
36     int render_view_id) {
37   if (factory_) {
38     media::AudioInputDevice* const device =
39         factory_->CreateInputDevice(render_view_id);
40     if (device)
41       return device;
42   }
43 
44   AudioInputMessageFilter* const filter = AudioInputMessageFilter::Get();
45   return new media::AudioInputDevice(
46       filter->CreateAudioInputIPC(render_view_id), filter->io_message_loop());
47 }
48 
AudioDeviceFactory()49 AudioDeviceFactory::AudioDeviceFactory() {
50   DCHECK(!factory_) << "Can't register two factories at once.";
51   factory_ = this;
52 }
53 
~AudioDeviceFactory()54 AudioDeviceFactory::~AudioDeviceFactory() {
55   factory_ = NULL;
56 }
57 
58 }  // namespace content
59