Perform a graceful disconnection if the termination was locally initiated

This commit is contained in:
Cameron Gutman
2021-05-14 22:06:07 -05:00
parent 1b3c14a792
commit 387ff48a65
4 changed files with 70 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ OPUS_MULTISTREAM_CONFIGURATION HighQualityOpusConfig;
int OriginalVideoBitrate;
int AudioPacketDuration;
bool AudioEncryptionEnabled;
bool UserRequestedTermination;
// Connection stages
static const char* stageNames[STAGE_MAX] = {
@@ -55,6 +56,12 @@ void LiInterruptConnection(void) {
// Stop the connection by undoing the step at the current stage and those before it
void LiStopConnection(void) {
// If this was a fully complete connection and we haven't started any termination
// logic prior to this point, this termination is user requested.
if (stage == STAGE_MAX - 1 && !alreadyTerminated) {
UserRequestedTermination = true;
}
// Disable termination callbacks now
alreadyTerminated = true;
@@ -190,6 +197,10 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
memcpy(&StreamConfig, streamConfig, sizeof(StreamConfig));
OriginalVideoBitrate = streamConfig->bitrate;
RemoteAddrString = strdup(serverInfo->address);
alreadyTerminated = false;
ConnectionInterrupted = false;
UserRequestedTermination = false;
// Validate the audio configuration
if (MAGIC_BYTE_FROM_AUDIO_CONFIG(StreamConfig.audioConfiguration) != 0xCA ||
@@ -245,9 +256,6 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
goto Cleanup;
}
alreadyTerminated = false;
ConnectionInterrupted = false;
Limelog("Initializing platform...");
ListenerCallbacks.stageStarting(STAGE_PLATFORM_INIT);
err = initializePlatform();