mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Optimize the audio receive path
This commit is contained in:
parent
4d4a6c236e
commit
fa93a6cef5
@ -17,6 +17,8 @@ static PLT_THREAD decoderThread;
|
|||||||
|
|
||||||
#define RTP_PORT 48000
|
#define RTP_PORT 48000
|
||||||
|
|
||||||
|
#define MAX_PACKET_SIZE 100
|
||||||
|
|
||||||
/* Initialize the audio stream */
|
/* Initialize the audio stream */
|
||||||
void initializeAudioStream(IP_ADDRESS host, PAUDIO_RENDERER_CALLBACKS arCallbacks, PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
void initializeAudioStream(IP_ADDRESS host, PAUDIO_RENDERER_CALLBACKS arCallbacks, PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
||||||
memcpy(&callbacks, arCallbacks, sizeof(callbacks));
|
memcpy(&callbacks, arCallbacks, sizeof(callbacks));
|
||||||
@ -68,16 +70,21 @@ static void UdpPingThreadProc(void *context) {
|
|||||||
|
|
||||||
static void ReceiveThreadProc(void* context) {
|
static void ReceiveThreadProc(void* context) {
|
||||||
int err;
|
int err;
|
||||||
|
PRTP_PACKET rtp;
|
||||||
|
|
||||||
while (!PltIsThreadInterrupted(&receiveThread)) {
|
while (!PltIsThreadInterrupted(&receiveThread)) {
|
||||||
char* buffer = (char*) malloc(1500 + sizeof(int));
|
char* buffer = NULL;
|
||||||
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
Limelog("Receive thread terminating\n");
|
buffer = (char*) malloc(MAX_PACKET_SIZE + sizeof(int));
|
||||||
listenerCallbacks->connectionTerminated(-1);
|
if (buffer == NULL) {
|
||||||
return;
|
Limelog("Receive thread terminating\n");
|
||||||
|
listenerCallbacks->connectionTerminated(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = recv(rtpSocket, &buffer[sizeof(int)], 1500, 0);
|
err = recv(rtpSocket, &buffer[sizeof(int)], MAX_PACKET_SIZE, 0);
|
||||||
if (err <= 0) {
|
if (err <= 0) {
|
||||||
Limelog("Receive thread terminating #2\n");
|
Limelog("Receive thread terminating #2\n");
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@ -85,12 +92,27 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (err < sizeof(RTP_PACKET)) {
|
||||||
|
// Runt packet
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtp = (PRTP_PACKET) &buffer[sizeof(int)];
|
||||||
|
if (rtp->packetType != 97) {
|
||||||
|
// Not audio
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(buffer, &err, sizeof(err));
|
memcpy(buffer, &err, sizeof(err));
|
||||||
|
|
||||||
err = LbqOfferQueueItem(&packetQueue, buffer);
|
err = LbqOfferQueueItem(&packetQueue, buffer);
|
||||||
if (err != LBQ_SUCCESS) {
|
if (err != LBQ_SUCCESS) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// The queue owns the buffer now
|
||||||
|
buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (err == LBQ_BOUND_EXCEEDED) {
|
if (err == LBQ_BOUND_EXCEEDED) {
|
||||||
Limelog("Audio packet queue overflow\n");
|
Limelog("Audio packet queue overflow\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user