Skip to content

Commit 1460fb4

Browse files
committed
Catch exception at start
1 parent fbb0ed7 commit 1460fb4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

modules/audio_device/audio_engine_device.mm

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,26 +1849,35 @@
18491849
}
18501850

18511851
LOGI() << "Starting AVAudioEngine...";
1852-
NSError* error = nil;
18531852
BOOL start_result = false;
18541853
int start_retry_count = 0;
18551854

18561855
// Workaround for error -66637, when recovering from interruptions with categoryMode:
18571856
// .mixWithOthers.
18581857
while (!start_result && start_retry_count < kStartEngineMaxRetries) {
18591858
if (start_retry_count > 0) {
1860-
LOGW() << "Retrying engine start (attempt " << start_retry_count + 1 << "/"
1859+
LOGW() << "Retrying engine start (attempt " << (start_retry_count + 1) << "/"
18611860
<< kStartEngineMaxRetries << ")";
18621861
usleep(kStartEngineRetryDelayMs * 1000);
18631862
}
18641863

1865-
// Workaround for cases where engine fails to start.
1866-
[engine_device_ prepare];
1867-
sleep(1);
1864+
NSString* error_string = nil;
1865+
1866+
@try {
1867+
NSError* error = nil;
1868+
start_result = [engine_device_ startAndReturnError:&error];
1869+
if (!start_result && error != nil) {
1870+
error_string = error.localizedDescription;
1871+
}
1872+
} @catch (NSException* exception) {
1873+
start_result = false;
1874+
error_string = exception.reason ?: @"Unknown exception";
1875+
}
18681876

1869-
start_result = [engine_device_ startAndReturnError:&error];
18701877
if (!start_result) {
1871-
LOGE() << "Failed to start engine: " << error.localizedDescription.UTF8String;
1878+
if (error_string != nil) {
1879+
LOGE() << "Failed to start engine: " << error_string.UTF8String;
1880+
}
18721881
start_retry_count++;
18731882
}
18741883
}

0 commit comments

Comments
 (0)