Skip to content

Commit 6ba820c

Browse files
committed
Squashed recent progress
Fix adm selection Fixes Revert adm selection in audio_device_impl Rename IsManualRenderingMode Simplify pcm buffer delegate Fixes Fixes Ducking config Strip manual rendering logic Runtime-ducking config Fix compile Fix start recording Connect output Buffer logic Enable output when input is enabled
1 parent 49ca1ee commit 6ba820c

18 files changed

+904
-492
lines changed

modules/audio_device/audio_device_data_observer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class ADMWrapper : public AudioDeviceModule, public AudioTransport {
307307
}
308308
#endif // WEBRTC_IOS
309309

310-
int32_t SetObserver(AudioDeviceObserver* observer) const override {
310+
int32_t SetObserver(AudioDeviceObserver* observer) override {
311311
return impl_->SetObserver(observer);
312312
}
313313

modules/audio_device/audio_device_impl.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@
3434
#if defined(WEBRTC_ENABLE_LINUX_PULSE)
3535
#include "modules/audio_device/linux/audio_device_pulse_linux.h"
3636
#endif
37+
#elif defined(WEBRTC_IOS)
38+
#include "sdk/objc/native/src/audio/audio_device_ios.h"
39+
#elif defined(WEBRTC_MAC)
40+
#include "modules/audio_device/mac/audio_device_mac.h"
3741
#endif
38-
39-
#if defined(WEBRTC_IOS) || defined(WEBRTC_MAC)
40-
#include "modules/audio_device/audio_engine_device.h"
41-
#endif
42-
4342
#if defined(WEBRTC_DUMMY_FILE_DEVICES)
4443
#include "modules/audio_device/dummy/file_audio_device.h"
4544
#include "modules/audio_device/dummy/file_audio_device_factory.h"
@@ -247,15 +246,16 @@ int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
247246
// iOS ADM implementation.
248247
#if defined(WEBRTC_IOS)
249248
if (audio_layer == kPlatformDefaultAudio) {
250-
audio_device_.reset(new AudioEngineDevice(/*bypass_voice_processing=*/bypass_voice_processing_));
249+
audio_device_.reset(
250+
new ios_adm::AudioDeviceIOS(/*bypass_voice_processing=*/bypass_voice_processing_));
251251
RTC_LOG(LS_INFO) << "iPhone Audio APIs will be utilized.";
252252
}
253253
// END #if defined(WEBRTC_IOS)
254254

255255
// Mac OS X ADM implementation.
256256
#elif defined(WEBRTC_MAC)
257257
if (audio_layer == kPlatformDefaultAudio) {
258-
audio_device_.reset(new AudioEngineDevice(/*bypass_voice_processing=*/false));
258+
audio_device_.reset(new AudioDeviceMac());
259259
RTC_LOG(LS_INFO) << "Mac OS X Audio APIs will be utilized.";
260260
}
261261
#endif // WEBRTC_MAC
@@ -902,7 +902,7 @@ int AudioDeviceModuleImpl::GetRecordAudioParameters(
902902
}
903903
#endif // WEBRTC_IOS
904904

905-
int32_t AudioDeviceModuleImpl::SetObserver(AudioDeviceObserver* observer) const {
905+
int32_t AudioDeviceModuleImpl::SetObserver(AudioDeviceObserver* observer) {
906906
RTC_LOG(LS_INFO) << __FUNCTION__ << "(" << observer << ")";
907907
int32_t ok = audio_device_->SetObserver(observer);
908908
RTC_LOG(LS_INFO) << "output: " << ok;

modules/audio_device/audio_device_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
156156
int GetRecordAudioParameters(AudioParameters* params) const override;
157157
#endif // WEBRTC_IOS
158158

159-
int32_t SetObserver(AudioDeviceObserver* observer) const override;
159+
int32_t SetObserver(AudioDeviceObserver* observer) override;
160160
int32_t GetPlayoutDevice() const override;
161161
int32_t GetRecordingDevice() const override;
162162

modules/audio_device/audio_engine_device.h

Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_AUDIOENGINE_H_
1818
#define SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_AUDIOENGINE_H_
1919

20+
#import <AVFAudio/AVFAudio.h>
21+
2022
#include <atomic>
2123
#include <memory>
2224

@@ -31,26 +33,18 @@
3133
#include "sdk/objc/native/src/audio/audio_session_observer.h"
3234

3335
RTC_FWD_DECL_OBJC_CLASS(RTC_OBJC_TYPE(RTCNativeAudioSessionDelegateAdapter));
34-
RTC_FWD_DECL_OBJC_CLASS(AVAudioEngine);
35-
RTC_FWD_DECL_OBJC_CLASS(AVAudioSourceNode);
36-
RTC_FWD_DECL_OBJC_CLASS(AVAudioSinkNode);
37-
RTC_FWD_DECL_OBJC_CLASS(AVAudioFormat);
38-
RTC_FWD_DECL_OBJC_CLASS(AVAudioMixerNode);
39-
RTC_FWD_DECL_OBJC_CLASS(AVAudioUnitEQ);
4036

4137
namespace webrtc {
4238

4339
class FineAudioBuffer;
4440

45-
class AudioEngineDevice : public AudioDeviceGeneric,
41+
class AudioEngineDevice : public AudioDeviceModule,
4642
public AudioSessionObserver {
4743
public:
4844
explicit AudioEngineDevice(bool bypass_voice_processing);
4945
~AudioEngineDevice() override;
5046

51-
void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
52-
53-
InitStatus Init() override;
47+
int32_t Init() override;
5448
int32_t Terminate() override;
5549
bool Initialized() const override;
5650

@@ -68,16 +62,18 @@ class AudioEngineDevice : public AudioDeviceGeneric,
6862
int32_t StopRecording() override;
6963
bool Recording() const override;
7064

71-
int32_t PlayoutDelay(uint16_t& delayMS) const override;
65+
int32_t PlayoutDelay(uint16_t* delayMS) const override;
7266
int32_t GetPlayoutUnderrunCount() const override { return -1; }
7367

74-
// int GetPlayoutAudioParameters(AudioParameters* params) const override;
75-
// int GetRecordAudioParameters(AudioParameters* params) const override;
68+
#if defined(WEBRTC_IOS)
69+
int GetPlayoutAudioParameters(AudioParameters* params) const override;
70+
int GetRecordAudioParameters(AudioParameters* params) const override;
71+
#endif
7672

7773
int32_t ActiveAudioLayer(
78-
AudioDeviceModule::AudioLayer& audioLayer) const override;
79-
int32_t PlayoutIsAvailable(bool& available) override;
80-
int32_t RecordingIsAvailable(bool& available) override;
74+
AudioDeviceModule::AudioLayer* audioLayer) const override;
75+
int32_t PlayoutIsAvailable(bool* available) override;
76+
int32_t RecordingIsAvailable(bool* available) override;
8177
int16_t PlayoutDevices() override;
8278
int16_t RecordingDevices() override;
8379
int32_t PlayoutDeviceName(uint16_t index, char name[kAdmMaxDeviceNameSize],
@@ -94,28 +90,40 @@ class AudioEngineDevice : public AudioDeviceGeneric,
9490
bool SpeakerIsInitialized() const override;
9591
int32_t InitMicrophone() override;
9692
bool MicrophoneIsInitialized() const override;
97-
int32_t SpeakerVolumeIsAvailable(bool& available) override;
93+
int32_t SpeakerVolumeIsAvailable(bool* available) override;
9894
int32_t SetSpeakerVolume(uint32_t volume) override;
99-
int32_t SpeakerVolume(uint32_t& volume) const override;
100-
int32_t MaxSpeakerVolume(uint32_t& maxVolume) const override;
101-
int32_t MinSpeakerVolume(uint32_t& minVolume) const override;
102-
int32_t MicrophoneVolumeIsAvailable(bool& available) override;
95+
int32_t SpeakerVolume(uint32_t* volume) const override;
96+
int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
97+
int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
98+
int32_t MicrophoneVolumeIsAvailable(bool* available) override;
10399
int32_t SetMicrophoneVolume(uint32_t volume) override;
104-
int32_t MicrophoneVolume(uint32_t& volume) const override;
105-
int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const override;
106-
int32_t MinMicrophoneVolume(uint32_t& minVolume) const override;
107-
int32_t MicrophoneMuteIsAvailable(bool& available) override;
100+
int32_t MicrophoneVolume(uint32_t* volume) const override;
101+
int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
102+
int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
103+
int32_t MicrophoneMuteIsAvailable(bool* available) override;
108104
int32_t SetMicrophoneMute(bool enable) override;
109-
int32_t MicrophoneMute(bool& enabled) const override;
110-
int32_t SpeakerMuteIsAvailable(bool& available) override;
105+
int32_t MicrophoneMute(bool* enabled) const override;
106+
int32_t SpeakerMuteIsAvailable(bool* available) override;
111107
int32_t SetSpeakerMute(bool enable) override;
112-
int32_t SpeakerMute(bool& enabled) const override;
113-
int32_t StereoPlayoutIsAvailable(bool& available) override;
108+
int32_t SpeakerMute(bool* enabled) const override;
109+
int32_t StereoPlayoutIsAvailable(bool* available) const override;
114110
int32_t SetStereoPlayout(bool enable) override;
115-
int32_t StereoPlayout(bool& enabled) const override;
116-
int32_t StereoRecordingIsAvailable(bool& available) override;
111+
int32_t StereoPlayout(bool* enabled) const override;
112+
int32_t StereoRecordingIsAvailable(bool* available) const override;
117113
int32_t SetStereoRecording(bool enable) override;
118-
int32_t StereoRecording(bool& enabled) const override;
114+
int32_t StereoRecording(bool* enabled) const override;
115+
116+
int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
117+
118+
// Only supported on Android.
119+
bool BuiltInAECIsAvailable() const override;
120+
bool BuiltInAGCIsAvailable() const override;
121+
bool BuiltInNSIsAvailable() const override;
122+
123+
// Enables the built-in audio effects. Only supported on Android.
124+
int32_t EnableBuiltInAEC(bool enable) override;
125+
int32_t EnableBuiltInAGC(bool enable) override;
126+
int32_t EnableBuiltInNS(bool enable) override;
119127

120128
// AudioSessionObserver methods. May be called from any thread.
121129
void OnInterruptionBegin() override;
@@ -128,6 +136,17 @@ class AudioEngineDevice : public AudioDeviceGeneric,
128136

129137
int32_t SetObserver(AudioDeviceObserver* observer) override;
130138

139+
int32_t SetManualRenderingMode(bool enable);
140+
int32_t ManualRenderingMode(bool* enabled);
141+
142+
int32_t SetAdvancedDucking(bool enable);
143+
int32_t AdvancedDucking(bool* enabled);
144+
145+
int32_t SetDuckingLevel(long level);
146+
int32_t DuckingLevel(long* level);
147+
148+
int32_t InitAndStartRecording();
149+
131150
private:
132151
struct EngineState {
133152
bool input_enabled = false;
@@ -138,6 +157,11 @@ class AudioEngineDevice : public AudioDeviceGeneric,
138157
bool input_muted = false;
139158
bool is_interrupted = false;
140159

160+
bool is_manual_mode = false;
161+
bool voice_processing = true;
162+
bool advanced_ducking = true;
163+
long ducking_level = 0; // 0 = Default
164+
141165
bool operator==(const EngineState& rhs) const;
142166
bool operator!=(const EngineState& rhs) const;
143167

@@ -150,40 +174,36 @@ class AudioEngineDevice : public AudioDeviceGeneric,
150174

151175
EngineState engine_state_ RTC_GUARDED_BY(thread_);
152176

177+
AVAudioInputNode* InputNode();
178+
AVAudioOutputNode* OutputNode();
179+
153180
bool IsMicrophonePermissionGranted();
154181
void SetEngineState(std::function<EngineState(EngineState)> state_transform);
155182
void UpdateEngineState(EngineState old_state, EngineState new_state);
156183

157-
// Configures the audio session for WebRTC.
158-
bool ConfigureAudioSession();
159-
160-
// Like above, but requires caller to already hold session lock.
161-
bool ConfigureAudioSessionLocked();
162-
163-
// Unconfigures the audio session.
164-
void UnconfigureAudioSession();
165-
166184
// AudioEngine observer methods. May be called from any thread.
167185
void OnEngineConfigurationChange();
168186

169187
void DebugAudioEngine();
170188

189+
void StartRenderLoop();
190+
AVAudioEngineManualRenderingBlock render_block_;
191+
171192
// Determines whether voice processing should be enabled or disabled.
172193
const bool bypass_voice_processing_;
173194

174-
// Native I/O audio thread checker.
175-
SequenceChecker io_thread_checker_;
176-
177195
// Thread that this object is created on.
178196
rtc::Thread* thread_;
197+
std::unique_ptr<rtc::Thread> render_thread_;
198+
AVAudioPCMBuffer* render_buffer_;
179199

180-
AudioDeviceBuffer* audio_device_buffer_;
200+
const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
201+
std::unique_ptr<AudioDeviceBuffer> audio_device_buffer_;
202+
std::unique_ptr<FineAudioBuffer> fine_audio_buffer_;
181203

182204
AudioParameters playout_parameters_;
183205
AudioParameters record_parameters_;
184206

185-
std::unique_ptr<FineAudioBuffer> fine_audio_buffer_;
186-
187207
// Set to true after successful call to Init(), false otherwise.
188208
bool initialized_ RTC_GUARDED_BY(thread_);
189209

@@ -193,9 +213,6 @@ class AudioEngineDevice : public AudioDeviceGeneric,
193213
RTC_OBJC_TYPE(RTCNativeAudioSessionDelegateAdapter) * audio_session_observer_
194214
RTC_GUARDED_BY(thread_);
195215

196-
// Set to true if we've activated the audio session.
197-
bool has_configured_session_ RTC_GUARDED_BY(thread_);
198-
199216
// Avoids running pending task after `this` is Terminated.
200217
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_ =
201218
PendingTaskSafetyFlag::Create();
@@ -206,8 +223,7 @@ class AudioEngineDevice : public AudioDeviceGeneric,
206223

207224
// AVAudioEngine objects
208225
AVAudioEngine* audio_engine_;
209-
AVAudioFormat* rtc_internal_format_; // Int16
210-
AVAudioFormat* engine_internal_format_; // Float32
226+
AVAudioFormat* manual_render_rtc_format_; // Int16
211227

212228
// Output related
213229
AVAudioSourceNode* source_node_;

0 commit comments

Comments
 (0)