mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 09:25:49 +00:00
Centralize logic to use UDP for RTSP and append Host option if we use TCP
This commit is contained in:
parent
cde117df06
commit
a0b500a834
@ -12,6 +12,8 @@ static char sessionIdString[16];
|
|||||||
static int hasSessionId;
|
static int hasSessionId;
|
||||||
static char responseBuffer[RTSP_MAX_RESP_SIZE];
|
static char responseBuffer[RTSP_MAX_RESP_SIZE];
|
||||||
static int rtspClientVersion;
|
static int rtspClientVersion;
|
||||||
|
static char urlAddr[URLSAFESTRING_LEN];
|
||||||
|
static int useEnet;
|
||||||
|
|
||||||
static SOCKET sock = INVALID_SOCKET;
|
static SOCKET sock = INVALID_SOCKET;
|
||||||
static ENetHost* client;
|
static ENetHost* client;
|
||||||
@ -75,7 +77,8 @@ static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
|
|||||||
sprintf(sequenceNumberStr, "%d", currentSeqNumber++);
|
sprintf(sequenceNumberStr, "%d", currentSeqNumber++);
|
||||||
sprintf(clientVersionStr, "%d", rtspClientVersion);
|
sprintf(clientVersionStr, "%d", rtspClientVersion);
|
||||||
if (!addOption(msg, "CSeq", sequenceNumberStr) ||
|
if (!addOption(msg, "CSeq", sequenceNumberStr) ||
|
||||||
!addOption(msg, "X-GS-ClientVersion", clientVersionStr)) {
|
!addOption(msg, "X-GS-ClientVersion", clientVersionStr) ||
|
||||||
|
(!useEnet && !addOption(msg, "Host", urlAddr))) {
|
||||||
freeMessage(msg);
|
freeMessage(msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -273,7 +276,7 @@ Exit:
|
|||||||
|
|
||||||
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int expectingPayload, int* error) {
|
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int expectingPayload, int* error) {
|
||||||
// Gen 5+ does RTSP over ENet not TCP
|
// Gen 5+ does RTSP over ENet not TCP
|
||||||
if (AppVersionQuad[0] >= 5) {
|
if (useEnet) {
|
||||||
return transactRtspMessageEnet(request, response, expectingPayload, error);
|
return transactRtspMessageEnet(request, response, expectingPayload, error);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -426,12 +429,12 @@ static int sendVideoAnnounce(PRTSP_MESSAGE response, int* error) {
|
|||||||
|
|
||||||
// Perform RTSP Handshake with the streaming server machine as part of the connection process
|
// Perform RTSP Handshake with the streaming server machine as part of the connection process
|
||||||
int performRtspHandshake(void) {
|
int performRtspHandshake(void) {
|
||||||
char urlAddr[URLSAFESTRING_LEN];
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// Initialize global state
|
// Initialize global state
|
||||||
|
useEnet = AppVersionQuad[0] >= 5;
|
||||||
addrToUrlSafeString(&RemoteAddr, urlAddr);
|
addrToUrlSafeString(&RemoteAddr, urlAddr);
|
||||||
sprintf(rtspTargetUrl, "rtsp://%s", urlAddr);
|
sprintf(rtspTargetUrl, "rtsp%s://%s:48010", useEnet ? "ru" : "", urlAddr);
|
||||||
currentSeqNumber = 1;
|
currentSeqNumber = 1;
|
||||||
hasSessionId = 0;
|
hasSessionId = 0;
|
||||||
|
|
||||||
@ -456,7 +459,7 @@ int performRtspHandshake(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gen 5 servers use ENet to do the RTSP handshake
|
// Gen 5 servers use ENet to do the RTSP handshake
|
||||||
if (AppVersionQuad[0] >= 5) {
|
if (useEnet) {
|
||||||
ENetAddress address;
|
ENetAddress address;
|
||||||
ENetEvent event;
|
ENetEvent event;
|
||||||
|
|
||||||
@ -464,7 +467,7 @@ int performRtspHandshake(void) {
|
|||||||
enet_address_set_port(&address, 48010);
|
enet_address_set_port(&address, 48010);
|
||||||
|
|
||||||
// Create a client that can use 1 outgoing connection and 1 channel
|
// Create a client that can use 1 outgoing connection and 1 channel
|
||||||
client = enet_host_create(address.address.ss_family, NULL, 1, 1, 0, 0);
|
client = enet_host_create(RemoteAddr.ss_family, NULL, 1, 1, 0, 0);
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -695,7 +698,7 @@ int performRtspHandshake(void) {
|
|||||||
|
|
||||||
Exit:
|
Exit:
|
||||||
// Cleanup the ENet stuff
|
// Cleanup the ENet stuff
|
||||||
if (AppVersionQuad[0] >= 5) {
|
if (useEnet) {
|
||||||
if (peer != NULL) {
|
if (peer != NULL) {
|
||||||
enet_peer_disconnect_now(peer, 0);
|
enet_peer_disconnect_now(peer, 0);
|
||||||
peer = NULL;
|
peer = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user