Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/audio_device/audio_device_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class AudioDeviceGeneric {
#endif // WEBRTC_IOS

virtual int32_t SetAudioDeviceSink(AudioDeviceSink* sink) = 0;
virtual int32_t GetPlayoutDevice() const { return -1; }
virtual int32_t GetRecordingDevice() const { return -1; }

virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) = 0;

Expand Down
14 changes: 14 additions & 0 deletions modules/audio_device/audio_device_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,20 @@ int32_t AudioDeviceModuleImpl::SetAudioDeviceSink(AudioDeviceSink* sink) const {
return ok;
}

int32_t AudioDeviceModuleImpl::GetPlayoutDevice() const {
RTC_LOG(LS_INFO) << __FUNCTION__;
int32_t r = audio_device_->GetPlayoutDevice();
RTC_LOG(LS_INFO) << "output: " << r;
return r;
}

int32_t AudioDeviceModuleImpl::GetRecordingDevice() const {
RTC_LOG(LS_INFO) << __FUNCTION__;
int32_t r = audio_device_->GetRecordingDevice();
RTC_LOG(LS_INFO) << "output: " << r;
return r;
}

AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
RTC_LOG(LS_INFO) << __FUNCTION__;
return platform_type_;
Expand Down
2 changes: 2 additions & 0 deletions modules/audio_device/audio_device_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
#endif // WEBRTC_IOS

int32_t SetAudioDeviceSink(AudioDeviceSink* sink) const override;
int32_t GetPlayoutDevice() const override;
int32_t GetRecordingDevice() const override;

#if defined(WEBRTC_ANDROID)
// Only use this acccessor for test purposes on Android.
Expand Down
2 changes: 2 additions & 0 deletions modules/audio_device/include/audio_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class AudioDeviceModule : public rtc::RefCountInterface {
#endif // WEBRTC_IOS

virtual int32_t SetAudioDeviceSink(AudioDeviceSink* sink) const = 0;
virtual int32_t GetPlayoutDevice() const { return -1; }
virtual int32_t GetRecordingDevice() const { return -1; }

protected:
~AudioDeviceModule() override {}
Expand Down
16 changes: 16 additions & 0 deletions modules/audio_device/mac/audio_device_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,14 @@ int16_t AudioDeviceMac::PlayoutDevices() {
MaxNumberDevices);
}

int32_t AudioDeviceMac::GetPlayoutDevice() const {
if (_outputDeviceIsSpecified) {
return _outputDeviceIndex;
}

return 0;
}

int32_t AudioDeviceMac::SetPlayoutDevice(uint16_t index) {
MutexLock lock(&mutex_);

Expand Down Expand Up @@ -869,6 +877,14 @@ int16_t AudioDeviceMac::RecordingDevices() {
MaxNumberDevices);
}

int32_t AudioDeviceMac::GetRecordingDevice() const {
if (_inputDeviceIsSpecified) {
return _inputDeviceIndex;
}

return 0;
}

int32_t AudioDeviceMac::SetRecordingDevice(uint16_t index) {
if (_recIsInitialized) {
return -1;
Expand Down
2 changes: 2 additions & 0 deletions modules/audio_device/mac/audio_device_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class AudioDeviceMac : public AudioDeviceGeneric {
audio_device_module_sink_ = sink;
return 0;
}
virtual int32_t GetPlayoutDevice() const;
virtual int32_t GetRecordingDevice() const;

private:
int32_t InitSpeakerLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Expand Down
9 changes: 7 additions & 2 deletions sdk/objc/api/peerconnection/RTCAudioDeviceModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ RTC_OBJC_EXPORT
@property(nonatomic, readonly) BOOL playing;
@property(nonatomic, readonly) BOOL recording;

@property(nonatomic, assign) RTC_OBJC_TYPE(RTCAudioDevice) *outputDevice;
@property(nonatomic, assign) RTC_OBJC_TYPE(RTCAudioDevice) *inputDevice;

// Executes low-level API's in sequence to switch the device
- (BOOL)setOutputDevice: (nullable RTCAudioDevice *)device;
- (BOOL)setInputDevice: (nullable RTCAudioDevice *)device;
// Use outputDevice / inputDevice property unless you need to know if setting the device is
// successful.
- (BOOL)trySetOutputDevice:(nullable RTCAudioDevice *)device;
- (BOOL)trySetInputDevice:(nullable RTCAudioDevice *)device;

- (BOOL)setDevicesUpdatedHandler: (nullable RTCOnAudioDevicesDidUpdate) handler;

Expand Down
44 changes: 42 additions & 2 deletions sdk/objc/api/peerconnection/RTCAudioDeviceModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,27 @@ - (instancetype)initWithNativeModule:(rtc::scoped_refptr<webrtc::AudioDeviceModu
});
}

- (BOOL)setOutputDevice: (nullable RTCAudioDevice *)device {
- (RTCAudioDevice *)outputDevice {

return _workerThread->Invoke<RTC_OBJC_TYPE(RTCAudioDevice) *>(RTC_FROM_HERE, [self] {

NSArray<RTC_OBJC_TYPE(RTCAudioDevice) *> *devices = [self _outputDevices];
int16_t devicesCount = (int16_t)([devices count]);
int16_t index = _native->GetPlayoutDevice();

if (devicesCount == 0 || index <= -1 || index > (devicesCount - 1)) {
return (RTC_OBJC_TYPE(RTCAudioDevice) *)nil;
}

return (RTC_OBJC_TYPE(RTCAudioDevice) *)[devices objectAtIndex:index];
});
}

- (void)setOutputDevice: (RTCAudioDevice *)device {
[self trySetOutputDevice: device];
}

- (BOOL)trySetOutputDevice: (RTCAudioDevice *)device {

return _workerThread->Invoke<BOOL>(RTC_FROM_HERE, [self, device] {

Expand Down Expand Up @@ -111,7 +131,27 @@ - (BOOL)setOutputDevice: (nullable RTCAudioDevice *)device {
});
}

- (BOOL)setInputDevice: (nullable RTCAudioDevice *)device {
- (RTCAudioDevice *)inputDevice {

return _workerThread->Invoke<RTC_OBJC_TYPE(RTCAudioDevice) *>(RTC_FROM_HERE, [self] {

NSArray<RTC_OBJC_TYPE(RTCAudioDevice) *> *devices = [self _inputDevices];
int16_t devicesCount = (int16_t)([devices count]);
int16_t index = _native->GetRecordingDevice();

if (devicesCount == 0 || index <= -1 || index > (devicesCount - 1)) {
return (RTC_OBJC_TYPE(RTCAudioDevice) *)nil;
}

return (RTC_OBJC_TYPE(RTCAudioDevice) *)[devices objectAtIndex:index];
});
}

- (void)setInputDevice: (RTCAudioDevice *)device {
[self trySetInputDevice: device];
}

- (BOOL)trySetInputDevice: (RTCAudioDevice *)device {

return _workerThread->Invoke<BOOL>(RTC_FROM_HERE, [self, device] {

Expand Down