Minor cleanups to RTSP URL parsing

This commit is contained in:
Cameron Gutman
2023-10-06 21:30:45 -05:00
parent 24750d4b74
commit 1351f382aa

View File

@@ -701,8 +701,10 @@ static bool parseUrlAddrFromRtspUrlString(const char* rtspUrlString, char* desti
*urlPathSeparator = 0; *urlPathSeparator = 0;
} }
PltSafeStrcpy(destination, destinationLength, rtspUrlScratchBuffer + prefixLen); if (!PltSafeStrcpy(destination, destinationLength, rtspUrlScratchBuffer + prefixLen)) {
destination[destinationLength - 1] = '\0'; free(rtspUrlScratchBuffer);
return false;
}
free(rtspUrlScratchBuffer); free(rtspUrlScratchBuffer);
return true; return true;
@@ -774,24 +776,22 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
if (OriginalVideoBitrate >= HIGH_AUDIO_BITRATE_THRESHOLD && if (OriginalVideoBitrate >= HIGH_AUDIO_BITRATE_THRESHOLD &&
(AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) == 0 && (AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) == 0 &&
(StreamConfig.streamingRemotely != STREAM_CFG_REMOTE || CHANNEL_COUNT_FROM_AUDIO_CONFIGURATION(StreamConfig.audioConfiguration) <= 2)) { (StreamConfig.streamingRemotely != STREAM_CFG_REMOTE || CHANNEL_COUNT_FROM_AUDIO_CONFIGURATION(StreamConfig.audioConfiguration) <= 2)) {
// If we have an RTSP URL string and it was successfully parsed, use that string // If we have an RTSP URL string and it was successfully parsed and copied, use that string
if (serverInfo->rtspSessionUrl != NULL && parseUrlAddrFromRtspUrlString(serverInfo->rtspSessionUrl, urlAddr, sizeof(urlAddr))) { if (serverInfo->rtspSessionUrl == NULL ||
PltSafeStrcpy(rtspTargetUrl, sizeof(rtspTargetUrl), serverInfo->rtspSessionUrl); !parseUrlAddrFromRtspUrlString(serverInfo->rtspSessionUrl, urlAddr, sizeof(urlAddr)) ||
rtspTargetUrl[sizeof(rtspTargetUrl) - 1] = '\0'; !PltSafeStrcpy(rtspTargetUrl, sizeof(rtspTargetUrl), serverInfo->rtspSessionUrl)) {
}
else {
// If an RTSP URL string was not provided or failed to parse, we will construct one now as best we can. // If an RTSP URL string was not provided or failed to parse, we will construct one now as best we can.
// //
// NB: If the remote address is not a LAN address, the host will likely not enable high quality // NB: If the remote address is not a LAN address, the host will likely not enable high quality
// audio since it only does that for local streaming normally. We can avoid this limitation, // audio since it only does that for local streaming normally. We can avoid this limitation,
// but only if the caller gave us the RTSP session URL that it received from the host during launch. // but only if the caller gave us the RTSP session URL that it received from the host during launch.
addrToUrlSafeString(&RemoteAddr, urlAddr, sizeof(urlAddr)); addrToUrlSafeString(&RemoteAddr, urlAddr, sizeof(urlAddr));
snprintf(rtspTargetUrl, sizeof(rtspTargetUrl), "rtsp%s://%s:%u", useEnet ? "ru" : "", urlAddr, RtspPortNumber); snprintf(rtspTargetUrl, sizeof(rtspTargetUrl), "rtsp%s://%s:%u", useEnet ? "ru" : "", urlAddr, RtspPortNumber);
} }
} }
else { else {
PltSafeStrcpy(urlAddr, sizeof(urlAddr), "0.0.0.0"); PltSafeStrcpy(urlAddr, sizeof(urlAddr), "0.0.0.0");
snprintf(rtspTargetUrl, sizeof(rtspTargetUrl), "rtsp%s://%s:%u", useEnet ? "ru" : "", urlAddr, RtspPortNumber); snprintf(rtspTargetUrl, sizeof(rtspTargetUrl), "rtsp%s://%s:%u", useEnet ? "ru" : "", urlAddr, RtspPortNumber);
} }
switch (AppVersionQuad[0]) { switch (AppVersionQuad[0]) {