Skip to content

Commit 5f1c987

Browse files
committed
fix(fcc): distinguish fcc signaling/media packets by detecting RTCP header instead of server port
1 parent bf8ff23 commit 5f1c987

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/stream.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,34 @@
1111
#include "worker.h"
1212
#include <errno.h>
1313
#include <netinet/in.h>
14+
#include <stdbool.h>
1415
#include <stdlib.h>
1516
#include <string.h>
1617
#include <sys/epoll.h>
1718
#include <sys/socket.h>
1819
#include <unistd.h>
1920

21+
static bool is_rtcp_packet(const uint8_t *data, size_t len) {
22+
if (!data || len < 8) {
23+
return false;
24+
}
25+
26+
uint8_t version = (data[0] >> 6) & 0x03;
27+
if (version != 2) {
28+
return false;
29+
}
30+
31+
uint8_t payload_type = data[1];
32+
if (payload_type < 200 || payload_type > 211) {
33+
return false;
34+
}
35+
36+
uint16_t length_words = ((uint16_t)data[2] << 8) | data[3];
37+
size_t packet_len = (size_t)(length_words + 1) * 4;
38+
39+
return packet_len > 0 && packet_len <= len;
40+
}
41+
2042
/*
2143
* Wrapper for join_mcast_group that also resets the multicast data timeout
2244
* timer. This ensures that every time we join/rejoin a multicast group, the
@@ -122,7 +144,7 @@ int stream_handle_fd_event(stream_context_t *ctx, int fd, uint32_t events,
122144
/* Handle different types of FCC packets */
123145
uint8_t *recv_data = (uint8_t *)recv_buf->data;
124146
int result = 0;
125-
if (peer_addr.sin_port == ctx->fcc.fcc_server->sin_port) {
147+
if (is_rtcp_packet(recv_data, (size_t)actualr)) {
126148
/* RTCP control message from FCC server */
127149
int res = fcc_handle_server_response(ctx, recv_data, actualr);
128150
if (res == 1) {
@@ -136,7 +158,7 @@ int stream_handle_fd_event(stream_context_t *ctx, int fd, uint32_t events,
136158
return 0; /* Redirect handled successfully */
137159
}
138160
result = res;
139-
} else if (peer_addr.sin_port == ctx->fcc.media_port) {
161+
} else {
140162
/* RTP media packet from FCC unicast stream */
141163
result = fcc_handle_unicast_media(ctx, recv_buf);
142164
}

0 commit comments

Comments
 (0)