Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / renderer / media / audio_device_factory.cc
blobf3c4f0f102071da0917010e4eff3a8cea4c32b20
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"
12 #include "url/origin.h"
14 namespace content {
16 // static
17 AudioDeviceFactory* AudioDeviceFactory::factory_ = NULL;
19 // static
20 scoped_refptr<media::AudioOutputDevice> AudioDeviceFactory::NewOutputDevice(
21 int render_frame_id,
22 int session_id,
23 const std::string& device_id,
24 const url::Origin& security_origin) {
25 if (factory_) {
26 media::AudioOutputDevice* const device = factory_->CreateOutputDevice(
27 render_frame_id, session_id, device_id, security_origin);
28 if (device)
29 return device;
32 AudioMessageFilter* const filter = AudioMessageFilter::Get();
33 scoped_refptr<media::AudioOutputDevice> device = new media::AudioOutputDevice(
34 filter->CreateAudioOutputIPC(render_frame_id), filter->io_task_runner(),
35 session_id, device_id, security_origin);
36 device->RequestDeviceAuthorization();
37 return device;
40 // static
41 scoped_refptr<media::AudioInputDevice> AudioDeviceFactory::NewInputDevice(
42 int render_frame_id) {
43 if (factory_) {
44 media::AudioInputDevice* const device =
45 factory_->CreateInputDevice(render_frame_id);
46 if (device)
47 return device;
50 AudioInputMessageFilter* const filter = AudioInputMessageFilter::Get();
51 return new media::AudioInputDevice(
52 filter->CreateAudioInputIPC(render_frame_id), filter->io_task_runner());
55 AudioDeviceFactory::AudioDeviceFactory() {
56 DCHECK(!factory_) << "Can't register two factories at once.";
57 factory_ = this;
60 AudioDeviceFactory::~AudioDeviceFactory() {
61 factory_ = NULL;
64 } // namespace content