@@ -218,7 +218,7 @@ LLWebRTCVoiceClient::LLWebRTCVoiceClient() :
218
218
mAvatarNameCacheConnection(),
219
219
mIsInTuningMode(false ),
220
220
mIsProcessingChannels(false ),
221
- mIsCoroutineActive (false ),
221
+ mIsTimerActive (false ),
222
222
mWebRTCPump(" WebRTCClientPump" ),
223
223
mWebRTCDeviceInterface(nullptr )
224
224
{
@@ -295,6 +295,16 @@ void LLWebRTCVoiceClient::cleanUp()
295
295
mNeighboringRegions .clear ();
296
296
sessionState::for_each (boost::bind (predShutdownSession, _1));
297
297
LL_DEBUGS (" Voice" ) << " Exiting" << LL_ENDL;
298
+ stopTimer ();
299
+ }
300
+
301
+ void LLWebRTCVoiceClient::stopTimer ()
302
+ {
303
+ if (mIsTimerActive )
304
+ {
305
+ mIsTimerActive = false ;
306
+ LL::Timers::instance ().cancel (mVoiceTimerHandle );
307
+ }
298
308
}
299
309
300
310
void LLWebRTCVoiceClient::LogMessage (llwebrtc::LLWebRTCLogCallback::LogLevel level, const std::string& message)
@@ -443,8 +453,7 @@ void LLWebRTCVoiceClient::removeObserver(LLFriendObserver *observer)
443
453
444
454
// ---------------------------------------------------
445
455
// Primary voice loop.
446
- // This voice loop is called every 100ms plus the time it
447
- // takes to process the various functions called in the loop
456
+ // This voice loop is called every 100ms
448
457
// The loop does the following:
449
458
// * gates whether we do channel processing depending on
450
459
// whether we're running a WebRTC voice channel or
@@ -456,118 +465,109 @@ void LLWebRTCVoiceClient::removeObserver(LLFriendObserver *observer)
456
465
// connection to various voice channels.
457
466
// * Sends updates to the voice server when this agent's
458
467
// voice levels, or positions have changed.
459
- void LLWebRTCVoiceClient::voiceConnectionCoro ()
468
+ void LLWebRTCVoiceClient::connectionTimer ()
460
469
{
461
- LL_DEBUGS (" Voice" ) << " starting" << LL_ENDL;
462
- mIsCoroutineActive = true ;
463
- LLCoros::set_consuming (true );
470
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
464
471
try
465
472
{
466
- LLMuteList::getInstance ()->addObserver (this );
467
- while (!sShuttingDown )
468
- {
469
- LL_PROFILE_ZONE_NAMED_CATEGORY_VOICE (" voiceConnectionCoroLoop" )
470
- // TODO: Doing some measurement and calculation here,
471
- // we could reduce the timeout to take into account the
472
- // time spent on the previous loop to have the loop
473
- // cycle at exactly 100ms, instead of 100ms + loop
474
- // execution time.
475
- // Could help with voice updates making for smoother
476
- // voice when we're busy.
477
- llcoro::suspendUntilTimeout (UPDATE_THROTTLE_SECONDS);
478
- if (sShuttingDown ) return ; // 'this' migh already be invalid
479
- bool voiceEnabled = mVoiceEnabled ;
480
-
481
- if (!isAgentAvatarValid ())
473
+ // TODO: Doing some measurement and calculation here,
474
+ // we could reduce the timeout to take into account the
475
+ // time spent on the previous loop to have the loop
476
+ // cycle at exactly 100ms, instead of 100ms + loop
477
+ // execution time.
478
+ // Could help with voice updates making for smoother
479
+ // voice when we're busy.
480
+ bool voiceEnabled = mVoiceEnabled ;
481
+
482
+ if (!isAgentAvatarValid ())
483
+ {
484
+ if (sShuttingDown )
482
485
{
483
- continue ;
486
+ cleanUp () ;
484
487
}
488
+ return ;
489
+ }
485
490
486
- LLViewerRegion *regionp = gAgent .getRegion ();
487
- if (!regionp)
491
+ LLViewerRegion* regionp = gAgent .getRegion ();
492
+ if (!regionp)
493
+ {
494
+ if (sShuttingDown )
488
495
{
489
- continue ;
496
+ cleanUp () ;
490
497
}
498
+ return ;
499
+ }
491
500
492
- if (!mProcessChannels )
501
+ if (!mProcessChannels )
502
+ {
503
+ // we've switched away from webrtc voice, so shut all channels down.
504
+ // leave channel can be called again and again without adverse effects.
505
+ // it merely tells channels to shut down if they're not already doing so.
506
+ leaveChannel (false );
507
+ }
508
+ else if (inSpatialChannel ())
509
+ {
510
+ bool useEstateVoice = true ;
511
+ // add session for region or parcel voice.
512
+ if (!regionp || regionp->getRegionID ().isNull ())
493
513
{
494
- // we've switched away from webrtc voice, so shut all channels down.
495
- // leave channel can be called again and again without adverse effects.
496
- // it merely tells channels to shut down if they're not already doing so.
497
- leaveChannel (false );
514
+ // no region, no voice.
515
+ return ;
498
516
}
499
- else if (inSpatialChannel ())
500
- {
501
- bool useEstateVoice = true ;
502
- // add session for region or parcel voice.
503
- if (!regionp || regionp->getRegionID ().isNull ())
504
- {
505
- // no region, no voice.
506
- continue ;
507
- }
508
517
509
- voiceEnabled = voiceEnabled && regionp->isVoiceEnabled ();
518
+ voiceEnabled = voiceEnabled && regionp->isVoiceEnabled ();
510
519
511
- if (voiceEnabled)
520
+ if (voiceEnabled)
521
+ {
522
+ LLParcel* parcel = LLViewerParcelMgr::getInstance ()->getAgentParcel ();
523
+ // check to see if parcel changed.
524
+ if (parcel && parcel->getLocalID () != INVALID_PARCEL_ID)
512
525
{
513
- LLParcel *parcel = LLViewerParcelMgr::getInstance ()->getAgentParcel ();
514
- // check to see if parcel changed.
515
- if (parcel && parcel->getLocalID () != INVALID_PARCEL_ID)
526
+ // parcel voice
527
+ if (!parcel->getParcelFlagAllowVoice ())
516
528
{
517
- // parcel voice
518
- if (!parcel->getParcelFlagAllowVoice ())
519
- {
520
- voiceEnabled = false ;
521
- }
522
- else if (!parcel->getParcelFlagUseEstateVoiceChannel ())
523
- {
524
- // use the parcel-specific voice channel.
525
- S32 parcel_local_id = parcel->getLocalID ();
526
- std::string channelID = regionp->getRegionID ().asString () + " -" + std::to_string (parcel->getLocalID ());
527
-
528
- useEstateVoice = false ;
529
- if (!inOrJoiningChannel (channelID))
530
- {
531
- startParcelSession (channelID, parcel_local_id);
532
- }
533
- }
529
+ voiceEnabled = false ;
534
530
}
535
- if (voiceEnabled && useEstateVoice && ! inEstateChannel ())
531
+ else if (!parcel-> getParcelFlagUseEstateVoiceChannel ())
536
532
{
537
- // estate voice
538
- startEstateSession ();
533
+ // use the parcel-specific voice channel.
534
+ S32 parcel_local_id = parcel->getLocalID ();
535
+ std::string channelID = regionp->getRegionID ().asString () + " -" + std::to_string (parcel->getLocalID ());
536
+
537
+ useEstateVoice = false ;
538
+ if (!inOrJoiningChannel (channelID))
539
+ {
540
+ startParcelSession (channelID, parcel_local_id);
541
+ }
539
542
}
540
543
}
541
- if (!voiceEnabled)
542
- {
543
- // voice is disabled, so leave and disable PTT
544
- leaveChannel (true );
545
- }
546
- else
544
+ if (voiceEnabled && useEstateVoice && !inEstateChannel ())
547
545
{
548
- // we're in spatial voice, and voice is enabled, so determine positions in order
549
- // to send position updates.
550
- updatePosition ();
546
+ // estate voice
547
+ startEstateSession ();
551
548
}
552
549
}
553
- LL::WorkQueue::postMaybe (mMainQueue ,
554
- [=] {
555
- if (sShuttingDown )
556
- {
557
- return ;
558
- }
559
- sessionState::processSessionStates ();
560
- if (mProcessChannels && voiceEnabled && !mHidden )
561
- {
562
- sendPositionUpdate (false );
563
- updateOwnVolume ();
564
- }
565
- });
550
+ if (!voiceEnabled)
551
+ {
552
+ // voice is disabled, so leave and disable PTT
553
+ leaveChannel (true );
554
+ }
555
+ else
556
+ {
557
+ // we're in spatial voice, and voice is enabled, so determine positions in order
558
+ // to send position updates.
559
+ updatePosition ();
560
+ }
561
+ }
562
+ if (!sShuttingDown )
563
+ {
564
+ sessionState::processSessionStates ();
565
+ if (mProcessChannels && voiceEnabled && !mHidden )
566
+ {
567
+ sendPositionUpdate (false );
568
+ updateOwnVolume ();
569
+ }
566
570
}
567
- }
568
- catch (const LLCoros::Stop&)
569
- {
570
- LL_DEBUGS (" LLWebRTCVoiceClient" ) << " Received a shutdown exception" << LL_ENDL;
571
571
}
572
572
catch (const LLContinueError&)
573
573
{
@@ -582,7 +582,10 @@ void LLWebRTCVoiceClient::voiceConnectionCoro()
582
582
throw ;
583
583
}
584
584
585
- cleanUp ();
585
+ if (sShuttingDown )
586
+ {
587
+ cleanUp ();
588
+ }
586
589
}
587
590
588
591
// For spatial, determine which neighboring regions to connect to
@@ -1340,7 +1343,7 @@ bool LLWebRTCVoiceClient::isVoiceWorking() const
1340
1343
// webrtc is working if the coroutine is active in the case of
1341
1344
// webrtc. WebRTC doesn't need to connect to a secondary process
1342
1345
// or a login server to become active.
1343
- return mIsCoroutineActive ;
1346
+ return mIsTimerActive ;
1344
1347
}
1345
1348
1346
1349
// Returns true if calling back the session URI after the session has closed is possible.
@@ -1552,7 +1555,7 @@ void LLWebRTCVoiceClient::setVoiceEnabled(bool enabled)
1552
1555
LL_DEBUGS (" Voice" )
1553
1556
<< " ( " << (enabled ? " enabled" : " disabled" ) << " )"
1554
1557
<< " was " << (mVoiceEnabled ? " enabled" : " disabled" )
1555
- << " coro " << (mIsCoroutineActive ? " active" : " inactive" )
1558
+ << " coro " << (mIsTimerActive ? " active" : " inactive" )
1556
1559
<< LL_ENDL;
1557
1560
1558
1561
if (enabled != mVoiceEnabled )
@@ -1569,10 +1572,13 @@ void LLWebRTCVoiceClient::setVoiceEnabled(bool enabled)
1569
1572
status = LLVoiceClientStatusObserver::STATUS_VOICE_ENABLED;
1570
1573
mSpatialCoordsDirty = true ;
1571
1574
updatePosition ();
1572
- if (!mIsCoroutineActive )
1575
+ if (!mIsTimerActive )
1573
1576
{
1574
- LLCoros::instance ().launch (" LLWebRTCVoiceClient::voiceConnectionCoro" ,
1575
- boost::bind (&LLWebRTCVoiceClient::voiceConnectionCoro, LLWebRTCVoiceClient::getInstance ()));
1577
+ LL_DEBUGS (" Voice" ) << " Starting" << LL_ENDL;
1578
+ mIsTimerActive = true ;
1579
+ LLMuteList::getInstance ()->addObserver (this );
1580
+ const F32 SECS_BETWEEN_REQUESTS = 0 .5f ;
1581
+ mVoiceTimerHandle = LL::Timers::instance ().scheduleEvery ([this ]() { connectionTimer (); return false ; }, UPDATE_THROTTLE_SECONDS);
1576
1582
}
1577
1583
else
1578
1584
{
0 commit comments