Skip to content

Commit

Permalink
When devices go from one channel to two, resume stereo playout
Browse files Browse the repository at this point in the history
Previously, if a device (bluetooth) went from two channels playout
to one, it'd stay there even after bluetooth stopped hands-free mode.

This resulted in losing stereo after talking.
  • Loading branch information
roxanneskelly committed Aug 18, 2024
1 parent 59124ca commit 1af700e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 25 deletions.
69 changes: 68 additions & 1 deletion build/patches/airpod_fixes.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc
index 0a371737b3..e3a902270d 100644
index 0a371737b3..eb6061a5d9 100644
--- a/modules/audio_device/mac/audio_device_mac.cc
+++ b/modules/audio_device/mac/audio_device_mac.cc
@@ -1043,13 +1043,6 @@ int32_t AudioDeviceMac::InitPlayout() {
RTC_LOG(LS_VERBOSE) << "mFormatFlags = " << _outStreamFormat.mFormatFlags;
logCAMsg(rtc::LS_VERBOSE, "mFormatID",
(const char*)&_outStreamFormat.mFormatID);
-
- // Our preferred format to work with.
- if (_outStreamFormat.mChannelsPerFrame < 2) {
- // Disable stereo playout when we only have one channel on the device.
- _playChannels = 1;
- RTC_LOG(LS_VERBOSE) << "Stereo playout unavailable on this device";
- }
WEBRTC_CA_RETURN_ON_ERR(SetDesiredPlayoutFormat());

// Listen for format changes.
@@ -1790,12 +1783,19 @@ int32_t AudioDeviceMac::InitDevice(const uint16_t userDeviceIndex,
OSStatus AudioDeviceMac::SetDesiredPlayoutFormat() {
// Our preferred format to work with.
_outDesiredFormat.mSampleRate = N_PLAY_SAMPLES_PER_SEC;
- _outDesiredFormat.mChannelsPerFrame = _playChannels;
+ _outDesiredFormat.mChannelsPerFrame = _outStreamFormat.mChannelsPerFrame;
+ if (_playChannels > 1 && _outDesiredFormat.mChannelsPerFrame < 2) {
+ RTC_LOG(LS_VERBOSE) << "Stereo playout unavailable on this device";
+ }
+ if (_outDesiredFormat.mChannelsPerFrame > _playChannels)
+ {
+ _outDesiredFormat.mChannelsPerFrame = _playChannels;
+ }

if (_ptrAudioBuffer) {
// Update audio buffer with the selected parameters.
_ptrAudioBuffer->SetPlayoutSampleRate(N_PLAY_SAMPLES_PER_SEC);
- _ptrAudioBuffer->SetPlayoutChannels((uint8_t)_playChannels);
+ _ptrAudioBuffer->SetPlayoutChannels((uint8_t)_outDesiredFormat.mChannelsPerFrame);
}

_renderDelayOffsetSamples =
@@ -2096,12 +2096,6 @@ int32_t AudioDeviceMac::HandleStreamFormatChange(
return -1;
}
Expand All @@ -28,3 +64,34 @@ index 0a371737b3..e3a902270d 100644
const int io_block_size_samples = streamFormat.mChannelsPerFrame *
streamFormat.mSampleRate / 100 *
N_BLOCKS_IO;
@@ -2144,12 +2144,6 @@ int32_t AudioDeviceMac::HandleStreamFormatChange(
&_captureConverter));
} else {
memcpy(&_outStreamFormat, &streamFormat, sizeof(streamFormat));
-
- // Our preferred format to work with
- if (_outStreamFormat.mChannelsPerFrame < 2) {
- _playChannels = 1;
- RTC_LOG(LS_VERBOSE) << "Stereo playout unavailable on this device";
- }
WEBRTC_CA_RETURN_ON_ERR(SetDesiredPlayoutFormat());
}
return 0;
@@ -2262,7 +2256,7 @@ OSStatus AudioDeviceMac::implDeviceIOProc(const AudioBufferList* inputData,
if (_twoDevices || (!_recording && !_playing)) {
// In the case of a shared device, the single driving ioProc
// is stopped here
- WEBRTC_CA_LOG_ERR(AudioDeviceStop(_outputDeviceID, _deviceIOProcID));
+ WEBRTC_CA_LOG_WARN(AudioDeviceStop(_outputDeviceID, _deviceIOProcID));
WEBRTC_CA_LOG_WARN(
AudioDeviceDestroyIOProcID(_outputDeviceID, _deviceIOProcID));
if (err == noErr) {
@@ -2353,7 +2347,7 @@ OSStatus AudioDeviceMac::implInDeviceIOProc(const AudioBufferList* inputData,
MutexLock lock(&mutex_);
if (_doStopRec) {
// This will be signalled only when a shared device is not in use.
- WEBRTC_CA_LOG_ERR(AudioDeviceStop(_inputDeviceID, _inDeviceIOProcID));
+ WEBRTC_CA_LOG_WARN(AudioDeviceStop(_inputDeviceID, _inDeviceIOProcID));
WEBRTC_CA_LOG_WARN(
AudioDeviceDestroyIOProcID(_inputDeviceID, _inDeviceIOProcID));
if (err == noErr) {
22 changes: 0 additions & 22 deletions build/patches/dont_fatal_error_on_audio_device_stop.patch

This file was deleted.

2 changes: 0 additions & 2 deletions build/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def get_depot_tools(source_dir, fetch=False):
'bug_8759_workaround.patch',
'disable_mute_of_audio_processing.patch',
'crash_on_fatal_error.patch',
'dont_fatal_error_on_audio_device_stop.patch',
'airpod_fixes.patch',
],
'macos_arm64': [
Expand All @@ -232,7 +231,6 @@ def get_depot_tools(source_dir, fetch=False):
'bug_8759_workaround.patch',
'disable_mute_of_audio_processing.patch',
'crash_on_fatal_error.patch',
'dont_fatal_error_on_audio_device_stop.patch',
'airpod_fixes.patch',
],
'ios': [
Expand Down

0 comments on commit 1af700e

Please sign in to comment.