Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: content/renderer/media/restartable_audio_output_device_factory.cc

Issue 1666363005: Switching audio clients to using RestartableAudioRendererSink interface as a sink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing RestartableAudioOutputDevice interface Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/restartable_audio_output_device_factory.h"
6
7 #include "content/renderer/media/audio_device_factory.h"
8 #include "content/renderer/media/audio_renderer_mixer_manager.h"
9 #include "content/renderer/render_thread_impl.h"
10 #include "media/audio/audio_output_device.h"
11 #include "media/audio/restartable_audio_output_device_impl.h"
12 #include "media/base/audio_renderer_mixer_input.h"
13 #include "url/origin.h"
14
15 namespace content {
16
17 RestartableAudioOutputDeviceFactory*
18 RestartableAudioOutputDeviceFactory::factory_ = nullptr;
19
20 namespace {
21
22 // This is where we decide which audio will go to mixers and wich one to
23 // AudioOutpuDevice directly.
24 bool IsMixable(RestartableAudioOutputDeviceFactory::SourceType source_type) {
25 if (source_type == RestartableAudioOutputDeviceFactory::kSourceHighLatency)
26 return true; // Must ALWAYS go through mixer.
27
28 // TODO(olka): make a decision for the rest of the sources basing on OS
29 // type and configuration parameters.
30 return false;
31 }
32
33 scoped_refptr<media::RestartableAudioRendererSink> NewMixableSink(
34 int render_frame_id,
35 const std::string& device_id,
36 const url::Origin& security_origin) {
37 RenderThreadImpl* render_thread = RenderThreadImpl::current();
38 return render_thread->GetAudioRendererMixerManager()->CreateInput(
39 render_frame_id, device_id, security_origin);
40 }
41
42 scoped_refptr<media::RestartableAudioRendererSink> NewUnmixableSink(
43 int render_frame_id,
44 int session_id,
45 const std::string& device_id,
46 const url::Origin& security_origin) {
47 return new media::RestartableAudioOutputDeviceImpl(
48 base::Bind(&AudioDeviceFactory::NewOutputDevice, render_frame_id,
49 session_id, device_id, security_origin),
50 base::Bind(&RestartableAudioOutputDeviceFactory::GetOutputHWParams,
51 render_frame_id, session_id, device_id, security_origin));
52 }
53
54 } // namespace
55
56 // static
57 scoped_refptr<media::RestartableAudioRendererSink>
58 RestartableAudioOutputDeviceFactory::NewOutputDevice(
59 SourceType source_type,
60 int render_frame_id,
61 int session_id,
62 const std::string& device_id,
63 const url::Origin& security_origin) {
64 if (factory_) {
65 media::RestartableAudioRendererSink* const device =
66 factory_->CreateOutputDevice(source_type, render_frame_id, session_id,
67 device_id, security_origin);
68 if (device)
69 return device;
70 }
71
72 if (IsMixable(source_type))
73 return NewMixableSink(render_frame_id, device_id, security_origin);
74
75 return NewUnmixableSink(render_frame_id, session_id, device_id,
76 security_origin);
77 }
78
79 RestartableAudioOutputDeviceFactory::RestartableAudioOutputDeviceFactory() {
80 DCHECK(!factory_) << "Can't register two factories at once.";
81 factory_ = this;
82 }
83
84 RestartableAudioOutputDeviceFactory::~RestartableAudioOutputDeviceFactory() {
85 factory_ = NULL;
86 }
87
88 // static
89 media::AudioParameters RestartableAudioOutputDeviceFactory::GetOutputHWParams(
DaleCurtis 2016/02/08 19:10:25 This adds overhead that I don't think we want. Whe
o1ka 2016/02/09 14:15:38 This is a great idea. I'll take care of it.
90 int render_frame_id,
91 int session_id,
92 const std::string& device_id,
93 const url::Origin& security_origin) {
94 media::AudioParameters params; // Invalid parameters to return by default.
95
96 // AudioOutputDevice is the only interface we have to communicate with output
97 // device via IPC. So, that's how we get the parameters when there is no
98 // AudioOutputDevice:
99 scoped_refptr<media::AudioOutputDevice> aod =
100 AudioDeviceFactory::NewOutputDevice(render_frame_id, session_id,
101 device_id, security_origin);
102
103 if (aod->GetDeviceStatus() == media::OUTPUT_DEVICE_STATUS_OK)
104 params = aod->GetOutputParameters();
105
106 aod->Stop(); // Must be stopped.
107 return params;
108 }
109
110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698