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 | 15 |
15 namespace media { | 16 namespace media { |
16 class AudioInputDevice; | 17 class AudioInputDevice; |
17 class AudioOutputDevice; | 18 class AudioOutputDevice; |
18 } | 19 } |
19 | 20 |
20 namespace url { | 21 namespace url { |
21 class Origin; | 22 class Origin; |
22 } | 23 } |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 // A factory for creating AudioOutputDevices and AudioInputDevices. There is a | 27 // A factory for creating AudioOutputDevices and AudioInputDevices. There is a |
27 // global factory function that can be installed for the purposes of testing to | 28 // global factory function that can be installed for the purposes of testing to |
28 // provide specialized implementations. | 29 // provide specialized implementations. |
29 class CONTENT_EXPORT AudioDeviceFactory { | 30 class CONTENT_EXPORT AudioDeviceFactory { |
30 public: | 31 public: |
32 // Types of audio sources. | |
33 enum SourceType { | |
34 kSourceNone = 0, | |
35 kSourceMediaElement, | |
36 kSourceWebRTC, | |
Henrik Grunell
2016/02/15 12:21:17
Nit: RTC -> Rtc
o1ka
2016/02/17 17:40:44
Done.
| |
37 kSourceNonRtcAudioTrack, | |
38 kSourceWebAudio, | |
39 kSourceLast = kSourceWebAudio // Only used for validation of format. | |
40 }; | |
41 | |
31 // Creates an AudioOutputDevice. | 42 // Creates an AudioOutputDevice. |
32 // |render_frame_id| refers to the RenderFrame containing the entity | 43 // |render_frame_id| refers to the RenderFrame containing the entity |
33 // producing the audio. If |session_id| is nonzero, it is used by the browser | 44 // producing the audio. If |session_id| is nonzero, it is used by the browser |
34 // to select the correct input device ID and its associated output device, if | 45 // to select the correct input device ID and its associated output device, if |
35 // it exists. If |session_id| is zero, |device_id| and |security_origin| | 46 // it exists. If |session_id| is zero, |device_id| and |security_origin| |
36 // identify the output device to use. | 47 // identify the output device to use. |
37 // If |session_id| is zero and |device_id| and |security_origin| are empty, | 48 // If |session_id| is zero and |device_id| and |security_origin| are empty, |
38 // the default output device will be selected. | 49 // the default output device will be selected. |
39 static scoped_refptr<media::AudioOutputDevice> NewOutputDevice( | 50 static scoped_refptr<media::AudioOutputDevice> NewOutputDevice( |
40 int render_frame_id, | 51 int render_frame_id, |
41 int session_id, | 52 int session_id, |
42 const std::string& device_id, | 53 const std::string& device_id, |
43 const url::Origin& security_origin); | 54 const url::Origin& security_origin); |
44 | 55 |
56 // Creates an AudioRendererSink bound to an AudioOutputDevice. | |
57 // 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 // TODO(olka): merge it with NewRestartableOutputDevice() as soon as | |
60 // AudioOutputDevice is fixed to be restartable. | |
61 static scoped_refptr<media::AudioRendererSink> NewAudioRendererSink( | |
62 SourceType source_type, | |
63 int render_frame_id, | |
64 int session_id, | |
65 const std::string& device_id, | |
66 const url::Origin& security_origin); | |
67 | |
68 // Creates a RestartableAudioRendererSink bound to an AudioOutputDevice | |
69 // 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 static scoped_refptr<media::RestartableAudioRendererSink> | |
72 NewRestartableAudioRendererSink(SourceType source_type, | |
73 int render_frame_id, | |
74 int session_id, | |
75 const std::string& device_id, | |
76 const url::Origin& security_origin); | |
77 | |
78 // A helper to get HW device status in the absence of AudioOutputDevice. | |
79 static media::OutputDeviceStatus GetOutputDeviceStatus( | |
80 int render_frame_id, | |
81 int session_id, | |
82 const std::string& device_id, | |
83 const url::Origin& security_origin); | |
84 | |
45 // Creates an AudioInputDevice using the currently registered factory. | 85 // Creates an AudioInputDevice using the currently registered factory. |
46 // |render_frame_id| refers to the RenderFrame containing the entity | 86 // |render_frame_id| refers to the RenderFrame containing the entity |
47 // consuming the audio. | 87 // consuming the audio. |
48 static scoped_refptr<media::AudioInputDevice> NewInputDevice( | 88 static scoped_refptr<media::AudioInputDevice> NewInputDevice( |
49 int render_frame_id); | 89 int render_frame_id); |
50 | 90 |
51 protected: | 91 protected: |
52 AudioDeviceFactory(); | 92 AudioDeviceFactory(); |
53 virtual ~AudioDeviceFactory(); | 93 virtual ~AudioDeviceFactory(); |
54 | 94 |
55 // You can derive from this class and specify an implementation for these | 95 // You can derive from this class and specify an implementation for these |
56 // functions to provide alternate audio device implementations. | 96 // functions to provide alternate audio device implementations. |
57 // If the return value of either of these function is NULL, we fall back | 97 // If the return value of either of these function is NULL, we fall back |
58 // on the default implementation. | 98 // on the default implementation. |
59 virtual media::AudioOutputDevice* CreateOutputDevice( | 99 virtual media::AudioOutputDevice* CreateOutputDevice( |
60 int render_frame_id, | 100 int render_frame_id, |
61 int sesssion_id, | 101 int sesssion_id, |
62 const std::string& device_id, | 102 const std::string& device_id, |
63 const url::Origin& security_origin) = 0; | 103 const url::Origin& security_origin) = 0; |
104 | |
105 virtual media::AudioRendererSink* CreateAudioRendererSink( | |
106 SourceType source_type, | |
107 int render_frame_id, | |
108 int sesssion_id, | |
109 const std::string& device_id, | |
110 const url::Origin& security_origin) = 0; | |
111 | |
112 virtual media::RestartableAudioRendererSink* | |
113 CreateRestartableAudioRendererSink(SourceType source_type, | |
114 int render_frame_id, | |
115 int sesssion_id, | |
116 const std::string& device_id, | |
117 const url::Origin& security_origin) = 0; | |
118 | |
64 virtual media::AudioInputDevice* CreateInputDevice(int render_frame_id) = 0; | 119 virtual media::AudioInputDevice* CreateInputDevice(int render_frame_id) = 0; |
65 | 120 |
66 private: | 121 private: |
67 // The current globally registered factory. This is NULL when we should | 122 // The current globally registered factory. This is NULL when we should |
68 // create the default AudioRendererSinks. | 123 // create the default AudioRendererSinks. |
69 static AudioDeviceFactory* factory_; | 124 static AudioDeviceFactory* factory_; |
70 | 125 |
71 DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory); | 126 DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory); |
72 }; | 127 }; |
73 | 128 |
74 } // namespace content | 129 } // namespace content |
75 | 130 |
76 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ | 131 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
OLD | NEW |