Skip to content

Commit 1af700e

Browse files
committed
When devices go from one channel to two, resume stereo playout
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.
1 parent 59124ca commit 1af700e

File tree

3 files changed

+68
-25
lines changed

3 files changed

+68
-25
lines changed

build/patches/airpod_fixes.patch

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc
2-
index 0a371737b3..e3a902270d 100644
2+
index 0a371737b3..eb6061a5d9 100644
33
--- a/modules/audio_device/mac/audio_device_mac.cc
44
+++ b/modules/audio_device/mac/audio_device_mac.cc
5+
@@ -1043,13 +1043,6 @@ int32_t AudioDeviceMac::InitPlayout() {
6+
RTC_LOG(LS_VERBOSE) << "mFormatFlags = " << _outStreamFormat.mFormatFlags;
7+
logCAMsg(rtc::LS_VERBOSE, "mFormatID",
8+
(const char*)&_outStreamFormat.mFormatID);
9+
-
10+
- // Our preferred format to work with.
11+
- if (_outStreamFormat.mChannelsPerFrame < 2) {
12+
- // Disable stereo playout when we only have one channel on the device.
13+
- _playChannels = 1;
14+
- RTC_LOG(LS_VERBOSE) << "Stereo playout unavailable on this device";
15+
- }
16+
WEBRTC_CA_RETURN_ON_ERR(SetDesiredPlayoutFormat());
17+
18+
// Listen for format changes.
19+
@@ -1790,12 +1783,19 @@ int32_t AudioDeviceMac::InitDevice(const uint16_t userDeviceIndex,
20+
OSStatus AudioDeviceMac::SetDesiredPlayoutFormat() {
21+
// Our preferred format to work with.
22+
_outDesiredFormat.mSampleRate = N_PLAY_SAMPLES_PER_SEC;
23+
- _outDesiredFormat.mChannelsPerFrame = _playChannels;
24+
+ _outDesiredFormat.mChannelsPerFrame = _outStreamFormat.mChannelsPerFrame;
25+
+ if (_playChannels > 1 && _outDesiredFormat.mChannelsPerFrame < 2) {
26+
+ RTC_LOG(LS_VERBOSE) << "Stereo playout unavailable on this device";
27+
+ }
28+
+ if (_outDesiredFormat.mChannelsPerFrame > _playChannels)
29+
+ {
30+
+ _outDesiredFormat.mChannelsPerFrame = _playChannels;
31+
+ }
32+
33+
if (_ptrAudioBuffer) {
34+
// Update audio buffer with the selected parameters.
35+
_ptrAudioBuffer->SetPlayoutSampleRate(N_PLAY_SAMPLES_PER_SEC);
36+
- _ptrAudioBuffer->SetPlayoutChannels((uint8_t)_playChannels);
37+
+ _ptrAudioBuffer->SetPlayoutChannels((uint8_t)_outDesiredFormat.mChannelsPerFrame);
38+
}
39+
40+
_renderDelayOffsetSamples =
541
@@ -2096,12 +2096,6 @@ int32_t AudioDeviceMac::HandleStreamFormatChange(
642
return -1;
743
}
@@ -28,3 +64,34 @@ index 0a371737b3..e3a902270d 100644
2864
const int io_block_size_samples = streamFormat.mChannelsPerFrame *
2965
streamFormat.mSampleRate / 100 *
3066
N_BLOCKS_IO;
67+
@@ -2144,12 +2144,6 @@ int32_t AudioDeviceMac::HandleStreamFormatChange(
68+
&_captureConverter));
69+
} else {
70+
memcpy(&_outStreamFormat, &streamFormat, sizeof(streamFormat));
71+
-
72+
- // Our preferred format to work with
73+
- if (_outStreamFormat.mChannelsPerFrame < 2) {
74+
- _playChannels = 1;
75+
- RTC_LOG(LS_VERBOSE) << "Stereo playout unavailable on this device";
76+
- }
77+
WEBRTC_CA_RETURN_ON_ERR(SetDesiredPlayoutFormat());
78+
}
79+
return 0;
80+
@@ -2262,7 +2256,7 @@ OSStatus AudioDeviceMac::implDeviceIOProc(const AudioBufferList* inputData,
81+
if (_twoDevices || (!_recording && !_playing)) {
82+
// In the case of a shared device, the single driving ioProc
83+
// is stopped here
84+
- WEBRTC_CA_LOG_ERR(AudioDeviceStop(_outputDeviceID, _deviceIOProcID));
85+
+ WEBRTC_CA_LOG_WARN(AudioDeviceStop(_outputDeviceID, _deviceIOProcID));
86+
WEBRTC_CA_LOG_WARN(
87+
AudioDeviceDestroyIOProcID(_outputDeviceID, _deviceIOProcID));
88+
if (err == noErr) {
89+
@@ -2353,7 +2347,7 @@ OSStatus AudioDeviceMac::implInDeviceIOProc(const AudioBufferList* inputData,
90+
MutexLock lock(&mutex_);
91+
if (_doStopRec) {
92+
// This will be signalled only when a shared device is not in use.
93+
- WEBRTC_CA_LOG_ERR(AudioDeviceStop(_inputDeviceID, _inDeviceIOProcID));
94+
+ WEBRTC_CA_LOG_WARN(AudioDeviceStop(_inputDeviceID, _inDeviceIOProcID));
95+
WEBRTC_CA_LOG_WARN(
96+
AudioDeviceDestroyIOProcID(_inputDeviceID, _inDeviceIOProcID));
97+
if (err == noErr) {

build/patches/dont_fatal_error_on_audio_device_stop.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

build/run.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def get_depot_tools(source_dir, fetch=False):
221221
'bug_8759_workaround.patch',
222222
'disable_mute_of_audio_processing.patch',
223223
'crash_on_fatal_error.patch',
224-
'dont_fatal_error_on_audio_device_stop.patch',
225224
'airpod_fixes.patch',
226225
],
227226
'macos_arm64': [
@@ -232,7 +231,6 @@ def get_depot_tools(source_dir, fetch=False):
232231
'bug_8759_workaround.patch',
233232
'disable_mute_of_audio_processing.patch',
234233
'crash_on_fatal_error.patch',
235-
'dont_fatal_error_on_audio_device_stop.patch',
236234
'airpod_fixes.patch',
237235
],
238236
'ios': [

0 commit comments

Comments
 (0)