OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ | 6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "media/base/audio_renderer_sink.h" | 14 #include "media/base/output_device_info.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 class AudioInputDevice; | 17 class AudioRendererSink; |
18 class AudioOutputDevice; | 18 class SwitchableAudioRendererSink; |
| 19 class AudioCapturerSource; |
19 } | 20 } |
20 | 21 |
21 namespace url { | 22 namespace url { |
22 class Origin; | 23 class Origin; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 | 27 |
27 // A factory for creating AudioOutputDevices and AudioInputDevices. There is a | 28 // A factory for creating AudioRendererSinks and AudioCapturerSources. There is |
28 // global factory function that can be installed for the purposes of testing to | 29 // a global factory function that can be installed for the purposes of testing |
29 // provide specialized implementations. | 30 // to provide specialized implementations. |
30 class CONTENT_EXPORT AudioDeviceFactory { | 31 class CONTENT_EXPORT AudioDeviceFactory { |
31 public: | 32 public: |
32 // Types of audio sources. | 33 // Types of audio sources. |
33 enum SourceType { | 34 enum SourceType { |
34 kSourceNone = 0, | 35 kSourceNone = 0, |
35 kSourceMediaElement, | 36 kSourceMediaElement, |
36 kSourceWebRtc, | 37 kSourceWebRtc, |
37 kSourceNonRtcAudioTrack, | 38 kSourceNonRtcAudioTrack, |
38 kSourceWebAudio, | 39 kSourceWebAudio, |
39 kSourceLast = kSourceWebAudio // Only used for validation of format. | 40 kSourceLast = kSourceWebAudio // Only used for validation of format. |
40 }; | 41 }; |
41 | 42 |
42 // Creates an AudioOutputDevice. | 43 // Creates a sink for AudioRendererMixer. |
43 // |render_frame_id| refers to the RenderFrame containing the entity | 44 // |render_frame_id| refers to the RenderFrame containing the entity |
44 // producing the audio. If |session_id| is nonzero, it is used by the browser | 45 // producing the audio. If |session_id| is nonzero, it is used by the browser |
45 // to select the correct input device ID and its associated output device, if | 46 // to select the correct input device ID and its associated output device, if |
46 // it exists. If |session_id| is zero, |device_id| and |security_origin| | 47 // it exists. If |session_id| is zero, |device_id| and |security_origin| |
47 // identify the output device to use. | 48 // identify the output device to use. |
48 // If |session_id| is zero and |device_id| and |security_origin| are empty, | 49 // If |session_id| is zero and |device_id| and |security_origin| are empty, |
49 // the default output device will be selected. | 50 // the default output device will be selected. |
50 static scoped_refptr<media::AudioOutputDevice> NewOutputDevice( | 51 static scoped_refptr<media::AudioRendererSink> NewAudioRendererMixerSink( |
51 int render_frame_id, | 52 int render_frame_id, |
52 int session_id, | 53 int session_id, |
53 const std::string& device_id, | 54 const std::string& device_id, |
54 const url::Origin& security_origin); | 55 const url::Origin& security_origin); |
55 | 56 |
56 // Creates an AudioRendererSink bound to an AudioOutputDevice. | 57 // Creates an AudioRendererSink bound to an AudioOutputDevice. |
57 // Basing on |source_type| and build configuration, audio played out through | 58 // Basing on |source_type| and build configuration, audio played out through |
58 // the sink goes to AOD directly or can be mixed with other audio before that. | 59 // the sink goes to AOD directly or can be mixed with other audio before that. |
59 // TODO(olka): merge it with NewRestartableOutputDevice() as soon as | 60 // TODO(olka): merge it with NewRestartableOutputDevice() as soon as |
60 // AudioOutputDevice is fixed to be restartable. | 61 // AudioOutputDevice is fixed to be restartable. |
61 static scoped_refptr<media::AudioRendererSink> NewAudioRendererSink( | 62 static scoped_refptr<media::AudioRendererSink> NewAudioRendererSink( |
62 SourceType source_type, | 63 SourceType source_type, |
63 int render_frame_id, | 64 int render_frame_id, |
64 int session_id, | 65 int session_id, |
65 const std::string& device_id, | 66 const std::string& device_id, |
66 const url::Origin& security_origin); | 67 const url::Origin& security_origin); |
67 | 68 |
68 // Creates a RestartableAudioRendererSink bound to an AudioOutputDevice | 69 // Creates a SwitchableAudioRendererSink bound to an AudioOutputDevice |
69 // Basing on |source_type| and build configuration, audio played out through | 70 // Basing on |source_type| and build configuration, audio played out through |
70 // the sink goes to AOD directly or can be mixed with other audio before that. | 71 // the sink goes to AOD directly or can be mixed with other audio before that. |
71 static scoped_refptr<media::RestartableAudioRendererSink> | 72 static scoped_refptr<media::SwitchableAudioRendererSink> |
72 NewRestartableAudioRendererSink(SourceType source_type, | 73 NewSwitchableAudioRendererSink(SourceType source_type, |
73 int render_frame_id, | 74 int render_frame_id, |
74 int session_id, | 75 int session_id, |
75 const std::string& device_id, | 76 const std::string& device_id, |
76 const url::Origin& security_origin); | 77 const url::Origin& security_origin); |
77 | 78 |
78 // A helper to get HW device status in the absence of AudioOutputDevice. | 79 // A helper to get device info in the absence of AudioOutputDevice. |
79 static media::OutputDeviceStatus GetOutputDeviceStatus( | 80 static media::OutputDeviceInfo GetOutputDeviceInfo( |
80 int render_frame_id, | 81 int render_frame_id, |
81 int session_id, | 82 int session_id, |
82 const std::string& device_id, | 83 const std::string& device_id, |
83 const url::Origin& security_origin); | 84 const url::Origin& security_origin); |
84 | 85 |
85 // Creates an AudioInputDevice using the currently registered factory. | 86 // Creates an AudioCapturerSource using the currently registered factory. |
86 // |render_frame_id| refers to the RenderFrame containing the entity | 87 // |render_frame_id| refers to the RenderFrame containing the entity |
87 // consuming the audio. | 88 // consuming the audio. |
88 static scoped_refptr<media::AudioInputDevice> NewInputDevice( | 89 static scoped_refptr<media::AudioCapturerSource> NewAudioCapturerSource( |
89 int render_frame_id); | 90 int render_frame_id); |
90 | 91 |
91 protected: | 92 protected: |
92 AudioDeviceFactory(); | 93 AudioDeviceFactory(); |
93 virtual ~AudioDeviceFactory(); | 94 virtual ~AudioDeviceFactory(); |
94 | 95 |
95 // You can derive from this class and specify an implementation for these | 96 // You can derive from this class and specify an implementation for these |
96 // functions to provide alternate audio device implementations. | 97 // functions to provide alternate audio device implementations. |
97 // If the return value of either of these function is NULL, we fall back | 98 // If the return value of either of these function is NULL, we fall back |
98 // on the default implementation. | 99 // on the default implementation. |
99 virtual media::AudioOutputDevice* CreateOutputDevice( | 100 virtual scoped_refptr<media::AudioRendererSink> CreateAudioRendererMixerSink( |
100 int render_frame_id, | 101 int render_frame_id, |
101 int sesssion_id, | 102 int sesssion_id, |
102 const std::string& device_id, | 103 const std::string& device_id, |
103 const url::Origin& security_origin) = 0; | 104 const url::Origin& security_origin) = 0; |
104 | 105 |
105 virtual media::AudioRendererSink* CreateAudioRendererSink( | 106 virtual scoped_refptr<media::AudioRendererSink> CreateAudioRendererSink( |
106 SourceType source_type, | 107 SourceType source_type, |
107 int render_frame_id, | 108 int render_frame_id, |
108 int sesssion_id, | 109 int sesssion_id, |
109 const std::string& device_id, | 110 const std::string& device_id, |
110 const url::Origin& security_origin) = 0; | 111 const url::Origin& security_origin) = 0; |
111 | 112 |
112 virtual media::RestartableAudioRendererSink* | 113 virtual scoped_refptr<media::SwitchableAudioRendererSink> |
113 CreateRestartableAudioRendererSink(SourceType source_type, | 114 CreateSwitchableAudioRendererSink(SourceType source_type, |
114 int render_frame_id, | 115 int render_frame_id, |
115 int sesssion_id, | 116 int sesssion_id, |
116 const std::string& device_id, | 117 const std::string& device_id, |
117 const url::Origin& security_origin) = 0; | 118 const url::Origin& security_origin) = 0; |
118 | 119 |
119 virtual media::AudioInputDevice* CreateInputDevice(int render_frame_id) = 0; | 120 virtual scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource( |
| 121 int render_frame_id) = 0; |
120 | 122 |
121 private: | 123 private: |
122 // The current globally registered factory. This is NULL when we should | 124 // The current globally registered factory. This is NULL when we should |
123 // create the default AudioRendererSinks. | 125 // create the default AudioRendererSinks. |
124 static AudioDeviceFactory* factory_; | 126 static AudioDeviceFactory* factory_; |
125 | 127 |
126 DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory); | 128 DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory); |
127 }; | 129 }; |
128 | 130 |
129 } // namespace content | 131 } // namespace content |
130 | 132 |
131 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ | 133 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
OLD | NEW |