OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_WEBRTC_AUDIO_DEVICE_NOT_IMPL_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_AUDIO_MODULE_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_NOT_IMPL_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_AUDIO_MODULE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include "base/memory/ref_counted.h" |
9 | 9 #include "base/synchronization/lock.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/timer/timer.h" |
11 #include "base/macros.h" | |
12 #include "base/time/time.h" | |
13 #include "content/common/content_export.h" | |
14 #include "third_party/webrtc/modules/audio_device/include/audio_device.h" | 11 #include "third_party/webrtc/modules/audio_device/include/audio_device.h" |
15 | 12 |
16 namespace content { | 13 namespace base { |
| 14 class SingleThreadTaskRunner; |
| 15 } // namespace base |
17 | 16 |
18 // WebRtcAudioDeviceNotImpl contains default implementations of all methods | 17 namespace remoting { |
19 // in the webrtc::AudioDeviceModule which are currently not supported in Chrome. | 18 namespace protocol { |
20 // The real implementation is in WebRtcAudioDeviceImpl and it derives from | 19 |
21 // this class. The main purpose of breaking out non-implemented methods into | 20 class AudioStub; |
22 // a separate unit is to make WebRtcAudioDeviceImpl more readable and easier | 21 |
23 // to maintain. | 22 // Audio module passed to WebRTC. It doesn't access actual audio devices, but it |
24 class CONTENT_EXPORT WebRtcAudioDeviceNotImpl | 23 // provides all functionality we need to ensure that audio streaming works |
25 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule) { | 24 // properly in WebRTC. Particularly it's responsible for calling AudioTransport |
| 25 // on regular intervals when playback is active. This ensures that all incoming |
| 26 // audio data is processed and passed to webrtc::AudioTrackSinkInterface |
| 27 // connected to the audio track. |
| 28 class WebrtcAudioModule : public webrtc::AudioDeviceModule { |
26 public: | 29 public: |
27 WebRtcAudioDeviceNotImpl(); | 30 WebrtcAudioModule(); |
| 31 ~WebrtcAudioModule() override; |
28 | 32 |
29 // webrtc::Module implementation. | 33 void SetAudioTaskRunner( |
30 // TODO(henrika): it is possible to add functionality in these methods. | 34 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner); |
31 // Only adding very basic support for now without triggering any callback | 35 |
32 // in the webrtc::AudioDeviceObserver interface. | 36 // webrtc::AudioDeviceModule implementation. |
33 int64_t TimeUntilNextProcess() override; | 37 int64_t TimeUntilNextProcess() override; |
34 void Process() override; | 38 void Process() override; |
35 | 39 int32_t ActiveAudioLayer(AudioLayer* audio_layer) const override; |
36 // Methods in webrtc::AudioDeviceModule which are not yet implemented. | 40 ErrorCode LastError() const override; |
37 // The idea is that we can move methods from this class to the real | |
38 // implementation in WebRtcAudioDeviceImpl when needed. | |
39 | |
40 int32_t RegisterEventObserver( | 41 int32_t RegisterEventObserver( |
41 webrtc::AudioDeviceObserver* event_callback) override; | 42 webrtc::AudioDeviceObserver* event_callback) override; |
42 int32_t ActiveAudioLayer(AudioLayer* audio_layer) const override; | 43 int32_t RegisterAudioCallback( |
43 webrtc::AudioDeviceModule::ErrorCode LastError() const override; | 44 webrtc::AudioTransport* audio_callback) override; |
| 45 int32_t Init() override; |
| 46 int32_t Terminate() override; |
| 47 bool Initialized() const override; |
44 int16_t PlayoutDevices() override; | 48 int16_t PlayoutDevices() override; |
45 int16_t RecordingDevices() override; | 49 int16_t RecordingDevices() override; |
46 int32_t PlayoutDeviceName(uint16_t index, | 50 int32_t PlayoutDeviceName(uint16_t index, |
47 char name[webrtc::kAdmMaxDeviceNameSize], | 51 char name[webrtc::kAdmMaxDeviceNameSize], |
48 char guid[webrtc::kAdmMaxGuidSize]) override; | 52 char guid[webrtc::kAdmMaxGuidSize]) override; |
49 int32_t RecordingDeviceName(uint16_t index, | 53 int32_t RecordingDeviceName(uint16_t index, |
50 char name[webrtc::kAdmMaxDeviceNameSize], | 54 char name[webrtc::kAdmMaxDeviceNameSize], |
51 char guid[webrtc::kAdmMaxGuidSize]) override; | 55 char guid[webrtc::kAdmMaxGuidSize]) override; |
52 int32_t SetPlayoutDevice(uint16_t index) override; | 56 int32_t SetPlayoutDevice(uint16_t index) override; |
53 int32_t SetPlayoutDevice(WindowsDeviceType device) override; | 57 int32_t SetPlayoutDevice(WindowsDeviceType device) override; |
54 int32_t SetRecordingDevice(uint16_t index) override; | 58 int32_t SetRecordingDevice(uint16_t index) override; |
55 int32_t SetRecordingDevice(WindowsDeviceType device) override; | 59 int32_t SetRecordingDevice(WindowsDeviceType device) override; |
| 60 int32_t PlayoutIsAvailable(bool* available) override; |
56 int32_t InitPlayout() override; | 61 int32_t InitPlayout() override; |
| 62 bool PlayoutIsInitialized() const override; |
| 63 int32_t RecordingIsAvailable(bool* available) override; |
57 int32_t InitRecording() override; | 64 int32_t InitRecording() override; |
| 65 bool RecordingIsInitialized() const override; |
| 66 int32_t StartPlayout() override; |
| 67 int32_t StopPlayout() override; |
| 68 bool Playing() const override; |
| 69 int32_t StartRecording() override; |
| 70 int32_t StopRecording() override; |
| 71 bool Recording() const override; |
| 72 int32_t SetAGC(bool enable) override; |
| 73 bool AGC() const override; |
58 int32_t SetWaveOutVolume(uint16_t volume_left, | 74 int32_t SetWaveOutVolume(uint16_t volume_left, |
59 uint16_t volume_right) override; | 75 uint16_t volume_right) override; |
60 int32_t WaveOutVolume(uint16_t* volume_left, | 76 int32_t WaveOutVolume(uint16_t* volume_left, |
61 uint16_t* volume_right) const override; | 77 uint16_t* volume_right) const override; |
62 int32_t InitSpeaker() override; | 78 int32_t InitSpeaker() override; |
63 bool SpeakerIsInitialized() const override; | 79 bool SpeakerIsInitialized() const override; |
64 int32_t InitMicrophone() override; | 80 int32_t InitMicrophone() override; |
65 bool MicrophoneIsInitialized() const override; | 81 bool MicrophoneIsInitialized() const override; |
66 int32_t SpeakerVolumeIsAvailable(bool* available) override; | 82 int32_t SpeakerVolumeIsAvailable(bool* available) override; |
67 int32_t SetSpeakerVolume(uint32_t volume) override; | 83 int32_t SetSpeakerVolume(uint32_t volume) override; |
68 int32_t SpeakerVolume(uint32_t* volume) const override; | 84 int32_t SpeakerVolume(uint32_t* volume) const override; |
69 int32_t MaxSpeakerVolume(uint32_t* max_volume) const override; | 85 int32_t MaxSpeakerVolume(uint32_t* max_volume) const override; |
70 int32_t MinSpeakerVolume(uint32_t* min_volume) const override; | 86 int32_t MinSpeakerVolume(uint32_t* min_volume) const override; |
71 int32_t SpeakerVolumeStepSize(uint16_t* step_size) const override; | 87 int32_t SpeakerVolumeStepSize(uint16_t* step_size) const override; |
72 int32_t MicrophoneVolumeIsAvailable(bool* available) override; | 88 int32_t MicrophoneVolumeIsAvailable(bool* available) override; |
| 89 int32_t SetMicrophoneVolume(uint32_t volume) override; |
| 90 int32_t MicrophoneVolume(uint32_t* volume) const override; |
| 91 int32_t MaxMicrophoneVolume(uint32_t* max_volume) const override; |
| 92 int32_t MinMicrophoneVolume(uint32_t* min_volume) const override; |
73 int32_t MicrophoneVolumeStepSize(uint16_t* step_size) const override; | 93 int32_t MicrophoneVolumeStepSize(uint16_t* step_size) const override; |
74 int32_t SpeakerMuteIsAvailable(bool* available) override; | 94 int32_t SpeakerMuteIsAvailable(bool* available) override; |
75 int32_t SetSpeakerMute(bool enable) override; | 95 int32_t SetSpeakerMute(bool enable) override; |
76 int32_t SpeakerMute(bool* enabled) const override; | 96 int32_t SpeakerMute(bool* enabled) const override; |
77 int32_t MicrophoneMuteIsAvailable(bool* available) override; | 97 int32_t MicrophoneMuteIsAvailable(bool* available) override; |
78 int32_t SetMicrophoneMute(bool enable) override; | 98 int32_t SetMicrophoneMute(bool enable) override; |
79 int32_t MicrophoneMute(bool* enabled) const override; | 99 int32_t MicrophoneMute(bool* enabled) const override; |
80 int32_t MicrophoneBoostIsAvailable(bool* available) override; | 100 int32_t MicrophoneBoostIsAvailable(bool* available) override; |
81 int32_t SetMicrophoneBoost(bool enable) override; | 101 int32_t SetMicrophoneBoost(bool enable) override; |
82 int32_t MicrophoneBoost(bool* enabled) const override; | 102 int32_t MicrophoneBoost(bool* enabled) const override; |
| 103 int32_t StereoPlayoutIsAvailable(bool* available) const override; |
83 int32_t SetStereoPlayout(bool enable) override; | 104 int32_t SetStereoPlayout(bool enable) override; |
84 int32_t StereoPlayout(bool* enabled) const override; | 105 int32_t StereoPlayout(bool* enabled) const override; |
| 106 int32_t StereoRecordingIsAvailable(bool* available) const override; |
85 int32_t SetStereoRecording(bool enable) override; | 107 int32_t SetStereoRecording(bool enable) override; |
86 int32_t StereoRecording(bool* enabled) const override; | 108 int32_t StereoRecording(bool* enabled) const override; |
87 int32_t SetRecordingChannel(const ChannelType channel) override; | 109 int32_t SetRecordingChannel(const ChannelType channel) override; |
88 int32_t RecordingChannel(ChannelType* channel) const override; | 110 int32_t RecordingChannel(ChannelType* channel) const override; |
89 int32_t SetPlayoutBuffer(const BufferType type, uint16_t size_ms) override; | 111 int32_t SetPlayoutBuffer(const BufferType type, uint16_t size_ms) override; |
90 int32_t PlayoutBuffer(BufferType* type, uint16_t* size_ms) const override; | 112 int32_t PlayoutBuffer(BufferType* type, uint16_t* size_ms) const override; |
| 113 int32_t PlayoutDelay(uint16_t* delay_ms) const override; |
| 114 int32_t RecordingDelay(uint16_t* delay_ms) const override; |
91 int32_t CPULoad(uint16_t* load) const override; | 115 int32_t CPULoad(uint16_t* load) const override; |
92 int32_t StartRawOutputFileRecording( | 116 int32_t StartRawOutputFileRecording( |
93 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) override; | 117 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) override; |
94 int32_t StopRawOutputFileRecording() override; | 118 int32_t StopRawOutputFileRecording() override; |
95 int32_t StartRawInputFileRecording( | 119 int32_t StartRawInputFileRecording( |
96 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) override; | 120 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) override; |
97 int32_t StopRawInputFileRecording() override; | 121 int32_t StopRawInputFileRecording() override; |
98 int32_t SetRecordingSampleRate(const uint32_t samples_per_sec) override; | 122 int32_t SetRecordingSampleRate(const uint32_t samples_per_sec) override; |
| 123 int32_t RecordingSampleRate(uint32_t* samples_per_sec) const override; |
99 int32_t SetPlayoutSampleRate(const uint32_t samples_per_sec) override; | 124 int32_t SetPlayoutSampleRate(const uint32_t samples_per_sec) override; |
| 125 int32_t PlayoutSampleRate(uint32_t* samples_per_sec) const override; |
100 int32_t ResetAudioDevice() override; | 126 int32_t ResetAudioDevice() override; |
101 int32_t SetLoudspeakerStatus(bool enable) override; | 127 int32_t SetLoudspeakerStatus(bool enable) override; |
102 int32_t GetLoudspeakerStatus(bool* enabled) const override; | 128 int32_t GetLoudspeakerStatus(bool* enabled) const override; |
103 int32_t SetAGC(bool enable) override; | |
104 bool AGC() const override; | |
105 bool BuiltInAECIsAvailable() const override; | 129 bool BuiltInAECIsAvailable() const override; |
106 bool BuiltInAGCIsAvailable() const override; | 130 bool BuiltInAGCIsAvailable() const override; |
107 bool BuiltInNSIsAvailable() const override; | 131 bool BuiltInNSIsAvailable() const override; |
108 int32_t EnableBuiltInAEC(bool enable) override; | 132 int32_t EnableBuiltInAEC(bool enable) override; |
109 int32_t EnableBuiltInAGC(bool enable) override; | 133 int32_t EnableBuiltInAGC(bool enable) override; |
110 int32_t EnableBuiltInNS(bool enable) override; | 134 int32_t EnableBuiltInNS(bool enable) override; |
111 #if defined(OS_IOS) | 135 |
| 136 // Only supported on iOS. |
| 137 #if defined(WEBRTC_IOS) |
112 int GetPlayoutAudioParameters(AudioParameters* params) const override; | 138 int GetPlayoutAudioParameters(AudioParameters* params) const override; |
113 int GetRecordAudioParameters(AudioParameters* params) const override; | 139 int GetRecordAudioParameters(AudioParameters* params) const override; |
114 #endif // OS_IOS | 140 #endif // WEBRTC_IOS |
115 | |
116 protected: | |
117 ~WebRtcAudioDeviceNotImpl() override{}; | |
118 | 141 |
119 private: | 142 private: |
120 base::TimeTicks last_process_time_; | 143 void StartPlayoutOnAudioThread(); |
121 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceNotImpl); | 144 void StopPlayoutOnAudioThread(); |
| 145 |
| 146 void PollFromSource(); |
| 147 |
| 148 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 149 |
| 150 // |lock_| must be locked when accessing |initialized_|, |playing_| and |
| 151 // |audio_transport_|. |
| 152 mutable base::Lock lock_; |
| 153 |
| 154 bool initialized_ = false; |
| 155 bool playing_ = false; |
| 156 webrtc::AudioTransport* audio_transport_ = nullptr; |
| 157 |
| 158 // Timer running on the |audio_task_runner_| that polls audio from |
| 159 // |audio_transport_|. |
| 160 base::RepeatingTimer poll_timer_; |
122 }; | 161 }; |
123 | 162 |
124 } // namespace content | 163 } // namespace protocol |
| 164 } // namespace remoting |
125 | 165 |
126 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_NOT_IMPL_H_ | 166 #endif // REMOTING_PROTOCOL_WEBRTC_AUDIO_MODULE_H_ |
OLD | NEW |