Parse the RTSP port out of the RTSP session URL

This commit is contained in:
Cameron Gutman 2021-07-02 01:17:34 -05:00
parent 0cd3fcf1be
commit 5ec8ee7cbf
2 changed files with 37 additions and 2 deletions

View File

@ -171,6 +171,32 @@ static void ClInternalConnectionTerminated(int errorCode)
PltCloseThread(&terminationCallbackThread);
}
static bool parseRtspPortNumberFromUrl(const char* rtspSessionUrl, uint16_t* port)
{
// If the session URL is not present, we will just use the well known port
if (rtspSessionUrl == NULL) {
return false;
}
// Pick the last colon in the string to match the port number
char* portNumberStart = strrchr(rtspSessionUrl, ':');
if (portNumberStart == NULL) {
return false;
}
// Skip the colon
portNumberStart++;
// Validate the port number
long int rawPort = strtol(portNumberStart, NULL, 10);
if (rawPort <= 0 || rawPort > 65535) {
return false;
}
*port = (uint16_t)rawPort;
return true;
}
// Starts the connection to the streaming machine
int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks, void* renderContext, int drFlags,
@ -212,11 +238,17 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
OriginalVideoBitrate = streamConfig->bitrate;
RemoteAddrString = strdup(serverInfo->address);
// Configure default ports
// Initialize port numbers to defaults. The values in RTSP SETUP (if valid)
// will override these to allow dynamic port selection.
VideoPortNumber = 47998;
ControlPortNumber = 47999;
AudioPortNumber = 48000;
RtspPortNumber = 48010; // TODO: Parse this out of RTSP session URL
// Parse RTSP port number from RTSP session URL
if (!parseRtspPortNumberFromUrl(serverInfo->rtspSessionUrl, &RtspPortNumber)) {
// Use the well known port if parsing fails
RtspPortNumber = 48010;
}
alreadyTerminated = false;
ConnectionInterrupted = false;

View File

@ -445,6 +445,9 @@ typedef struct _SERVER_INFORMATION {
// Text inside 'GfeVersion' tag in /serverinfo (if present)
const char* serverInfoGfeVersion;
// Text inside 'sessionUrl0' tag in /resume and /launch (if present)
const char* rtspSessionUrl;
} SERVER_INFORMATION, *PSERVER_INFORMATION;
// Use this function to zero the server information when allocated on the stack or heap