Skip to content

Commit 8bd3991

Browse files
authored
AudioUnit: Don't rely on category switch for mic indicator to turn off (#52)
* progress * tweak * clean * simplify audio unit restart call to SetupAudioBuffersForActiveAudioSession() might not be needed since sample rate won't change during restart. This might help reduce the unwanted noise when restarting audio unit. * clean
1 parent 3fcec9f commit 8bd3991

File tree

9 files changed

+76
-110
lines changed

9 files changed

+76
-110
lines changed

sdk/objc/components/audio/RTCAudioSession+Private.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ NS_ASSUME_NONNULL_BEGIN
3535
*/
3636
@property(nonatomic, assign) BOOL isInterrupted;
3737

38-
@property(nonatomic, strong) NSString *activeCategory;
39-
4038
/** Adds the delegate to the list of delegates, and places it at the front of
4139
* the list. This delegate will be notified before other delegates of
4240
* audio events.

sdk/objc/components/audio/RTCAudioSession.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ RTC_OBJC_EXPORT
102102
- (void)audioSession:(RTC_OBJC_TYPE(RTCAudioSession) *)audioSession
103103
audioUnitStartFailedWithError:(NSError *)error;
104104

105-
/** Called when audio session changed from output-only to input & output */
106-
- (void)audioSessionDidChangeRecordingEnabled:(RTC_OBJC_TYPE(RTCAudioSession) *)audioSession;
107-
108105
@end
109106

110107
/** This is a protocol used to inform RTCAudioSession when the audio session

sdk/objc/components/audio/RTCAudioSession.mm

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ - (instancetype)initWithAudioSession:(id)audioSession {
114114
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
115115
context:(__bridge void *)RTC_OBJC_TYPE(RTCAudioSession).class];
116116

117-
_activeCategory = _session.category;
118-
119117
RTCLog(@"RTC_OBJC_TYPE(RTCAudioSession) (%p): init.", self);
120118
}
121119
return self;
@@ -543,13 +541,6 @@ - (void)handleRouteChangeNotification:(NSNotification *)notification {
543541
break;
544542
case AVAudioSessionRouteChangeReasonCategoryChange:
545543
RTCLog(@"Audio route changed: CategoryChange to :%@", self.session.category);
546-
{
547-
if (![_session.category isEqualToString:_activeCategory]) {
548-
_activeCategory = _session.category;
549-
RTCLog(@"Audio route changed: Restarting Audio Unit");
550-
[self notifyDidChangeAudioSessionRecordingEnabled];
551-
}
552-
}
553544
break;
554545
case AVAudioSessionRouteChangeReasonOverride:
555546
RTCLog(@"Audio route changed: Override");
@@ -1005,13 +996,4 @@ - (void)notifyFailedToSetActive:(BOOL)active error:(NSError *)error {
1005996
}
1006997
}
1007998

1008-
- (void)notifyDidChangeAudioSessionRecordingEnabled {
1009-
for (auto delegate : self.delegates) {
1010-
SEL sel = @selector(audioSessionDidChangeRecordingEnabled:);
1011-
if ([delegate respondsToSelector:sel]) {
1012-
[delegate audioSessionDidChangeRecordingEnabled:self];
1013-
}
1014-
}
1015-
}
1016-
1017999
@end

sdk/objc/components/audio/RTCNativeAudioSessionDelegateAdapter.mm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,4 @@ - (void)audioSession:(RTC_OBJC_TYPE(RTCAudioSession) *)audioSession
8686
_observer->OnChangedOutputVolume();
8787
}
8888

89-
- (void)audioSessionDidChangeRecordingEnabled:(RTC_OBJC_TYPE(RTCAudioSession) *)session {
90-
// re-trigger audio unit init, by using interrupt ended callback
91-
_observer->OnChangedRecordingEnabled();
92-
}
93-
9489
@end

sdk/objc/native/src/audio/audio_device_ios.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
147147
void OnValidRouteChange() override;
148148
void OnCanPlayOrRecordChange(bool can_play_or_record) override;
149149
void OnChangedOutputVolume() override;
150-
void OnChangedRecordingEnabled() override;
151150

152151
// VoiceProcessingAudioUnitObserver methods.
153152
OSStatus OnDeliverRecordedData(AudioUnitRenderActionFlags* flags,
@@ -175,7 +174,8 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
175174
void HandleSampleRateChange();
176175
void HandlePlayoutGlitchDetected();
177176
void HandleOutputVolumeChange();
178-
void HandleAudioSessionRecordingEnabledChange();
177+
178+
bool RestartAudioUnit(bool enable_input);
179179

180180
// Uses current `playout_parameters_` and `record_parameters_` to inform the
181181
// audio device buffer (ADB) about our internal audio parameters.
@@ -205,7 +205,7 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
205205

206206
// Activates our audio session, creates and initializes the voice-processing
207207
// audio unit and verifies that we got the preferred native audio parameters.
208-
bool InitPlayOrRecord();
208+
bool InitPlayOrRecord(bool enable_input);
209209

210210
// Closes and deletes the voice-processing I/O unit.
211211
void ShutdownPlayOrRecord();
@@ -269,19 +269,21 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
269269
// will be changed dynamically to account for this behavior.
270270
rtc::BufferT<int16_t> record_audio_buffer_;
271271

272+
// Set to 1 when recording is initialized and 0 otherwise.
273+
volatile int recording_is_initialized_;
274+
272275
// Set to 1 when recording is active and 0 otherwise.
273276
volatile int recording_;
274277

278+
// Set to 1 when playout is initialized and 0 otherwise.
279+
volatile int playout_is_initialized_;
280+
275281
// Set to 1 when playout is active and 0 otherwise.
276282
volatile int playing_;
277283

278284
// Set to true after successful call to Init(), false otherwise.
279285
bool initialized_ RTC_GUARDED_BY(thread_checker_);
280286

281-
// Set to true after successful call to InitRecording() or InitPlayout(),
282-
// false otherwise.
283-
bool audio_is_initialized_;
284-
285287
// Set to true if audio session is interrupted, false otherwise.
286288
bool is_interrupted_;
287289

0 commit comments

Comments
 (0)