Skip to content

Commit c743ea2

Browse files
Fix indexing problem with mac devices (#4676)
* Fix indexing problem with mac devices This resulted in the wrong device being selected. Also, fix a shutdown crash where recording was not being stopped, hence the recording thread was still running on shutdown and crashed because it lost access to resources. Fix an issue with p2p calls where they're coming up muted even though the button indicates they are unmuted. * Always refresh device list on notification of device changes Even when the selected device doesn't change, we need to re-deploy it as it might have had characteristics (sampling rate, etc.) changed. Also, we need to redeploy when the Default device has changed
1 parent 7ec9736 commit c743ea2

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

indra/llwebrtc/llwebrtc.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@ void LLWebRTCImpl::init()
350350

351351
void LLWebRTCImpl::terminate()
352352
{
353+
mWorkerThread->BlockingCall(
354+
[this]()
355+
{
356+
if (mDeviceModule)
357+
{
358+
mDeviceModule->ForceStopRecording();
359+
mDeviceModule->StopPlayout();
360+
}
361+
});
362+
353363
for (auto &connection : mPeerConnections)
354364
{
355365
connection->terminate();
@@ -368,8 +378,6 @@ void LLWebRTCImpl::terminate()
368378
{
369379
if (mDeviceModule)
370380
{
371-
mDeviceModule->StopRecording();
372-
mDeviceModule->StopPlayout();
373381
mDeviceModule->Terminate();
374382
}
375383
mDeviceModule = nullptr;
@@ -442,11 +450,7 @@ void LLWebRTCImpl::unsetDevicesObserver(LLWebRTCDevicesObserver *observer)
442450
void LLWebRTCImpl::workerDeployDevices()
443451
{
444452
int16_t recordingDevice = RECORD_DEVICE_DEFAULT;
445-
#if WEBRTC_WIN
446453
int16_t recording_device_start = 0;
447-
#else
448-
int16_t recording_device_start = 1;
449-
#endif
450454

451455
if (mRecordingDevice != "Default")
452456
{
@@ -455,6 +459,12 @@ void LLWebRTCImpl::workerDeployDevices()
455459
if (mRecordingDeviceList[i].mID == mRecordingDevice)
456460
{
457461
recordingDevice = i;
462+
#if !WEBRTC_WIN
463+
// linux and mac devices range from 1 to the end of the list, with the index 0 being the
464+
// 'default' device. Windows has a special 'default' device and other devices are indexed
465+
// from 0
466+
recordingDevice++;
467+
#endif
458468
break;
459469
}
460470
}
@@ -479,18 +489,20 @@ void LLWebRTCImpl::workerDeployDevices()
479489
mDeviceModule->InitRecording();
480490

481491
int16_t playoutDevice = PLAYOUT_DEVICE_DEFAULT;
482-
#if WEBRTC_WIN
483492
int16_t playout_device_start = 0;
484-
#else
485-
int16_t playout_device_start = 1;
486-
#endif
487493
if (mPlayoutDevice != "Default")
488494
{
489495
for (int16_t i = playout_device_start; i < mPlayoutDeviceList.size(); i++)
490496
{
491497
if (mPlayoutDeviceList[i].mID == mPlayoutDevice)
492498
{
493499
playoutDevice = i;
500+
#if !WEBRTC_WIN
501+
// linux and mac devices range from 1 to the end of the list, with the index 0 being the
502+
// 'default' device. Windows has a special 'default' device and other devices are indexed
503+
// from 0
504+
playoutDevice++;
505+
#endif
494506
break;
495507
}
496508
}
@@ -546,20 +558,14 @@ void LLWebRTCImpl::workerDeployDevices()
546558
void LLWebRTCImpl::setCaptureDevice(const std::string &id)
547559
{
548560

549-
if (mRecordingDevice != id)
550-
{
551-
mRecordingDevice = id;
552-
deployDevices();
553-
}
561+
mRecordingDevice = id;
562+
deployDevices();
554563
}
555564

556565
void LLWebRTCImpl::setRenderDevice(const std::string &id)
557566
{
558-
if (mPlayoutDevice != id)
559-
{
560-
mPlayoutDevice = id;
561-
deployDevices();
562-
}
567+
mPlayoutDevice = id;
568+
deployDevices();
563569
}
564570

565571
// updateDevices needs to happen on the worker thread.
@@ -609,7 +615,7 @@ void LLWebRTCImpl::updateDevices()
609615

610616
void LLWebRTCImpl::OnDevicesUpdated()
611617
{
612-
deployDevices();
618+
updateDevices();
613619
}
614620

615621

indra/llwebrtc/llwebrtc_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ class LLWebRTCAudioDeviceModule : public webrtc::AudioDeviceModule
239239
return 0;
240240
}
241241
int32_t StopRecording() override {
242-
if (tuning_) return 0; // if we're tuning, disregard the StopRecording we get from disabling the streams
243-
return inner_->StopRecording();
242+
// ignore stop recording as webrtc.lib will send one when streams shut down,
243+
// even if there are other streams in place. Start/Stop recording are entirely
244+
// controlled by the app
245+
return 0;
244246
}
245247
int32_t ForceStartRecording() { return inner_->StartRecording(); }
246248
int32_t ForceStopRecording() { return inner_->StopRecording(); }

0 commit comments

Comments
 (0)