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