Skip to content

Commit

Permalink
Cleaning up, preparing to truly synchronize audio and video feeds on …
Browse files Browse the repository at this point in the history
…RTSP
  • Loading branch information
wberube committed Oct 25, 2024
1 parent 6c746e1 commit d2c68c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
3 changes: 1 addition & 2 deletions src/rtsp/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static inline int __rtp_setup_transfer(struct list_t *e, void *v)
struct connection_item_t *con;
struct __transfer_set_t *trans_set = v;
struct transfer_item_t *trans;
unsigned int timestamp_offset;
unsigned int timestamp_offset;
int ret = FAILURE;

list_upcast(con,e);
Expand Down Expand Up @@ -390,7 +390,6 @@ int rtp_send_h26x(rtsp_handle h, unsigned char *buf, size_t len, char isH265)
if (trans.list_head.list) {
while (__split_nal(buf, &nalptr, &single_len, len) == SUCCESS) {
ASSERT(__transfer_nal_h26x(&(trans.list_head), nalptr, single_len, h->isH265) == SUCCESS, goto error);
ASSERT(list_map_inline(&(trans.list_head), (__rtcp_poll), &track_id) == SUCCESS, goto error);
}
ASSERT(list_map_inline(&(trans.list_head), (__rtcp_poll), &track_id) == SUCCESS, goto error);
}
Expand Down
51 changes: 19 additions & 32 deletions src/rtsp/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,12 @@ static void __method_describe(struct connection_item_t *p, rtsp_handle h)

if (h->audioPt != 255) {
switch (h->audioPt) {
case 0:
strncpy(audioRtpfmt, "PCMU", 16 - 1);
break;
case 8:
strncpy(audioRtpfmt, "PCMA", 16 - 1);
break;
case 14:
strncpy(audioRtpfmt, "MPA", 16 - 1);
break;
case 18:
strncpy(audioRtpfmt, "G729", 16 - 1);
break;
case 96:
strncpy(audioRtpfmt, "MPEG4-GENERIC", 16 - 1);
break;
default:
strncpy(audioRtpfmt, "UNKNOWN", 16 - 1);
break;
case 0: strncpy(audioRtpfmt, "PCMU", 16 - 1); break;
case 8: strncpy(audioRtpfmt, "PCMA", 16 - 1); break;
case 14: strncpy(audioRtpfmt, "MPA", 16 - 1); break;
case 18: strncpy(audioRtpfmt, "G729", 16 - 1); break;
case 96: strncpy(audioRtpfmt, "MPEG4-GENERIC", 16 - 1); break;
default: strncpy(audioRtpfmt, "UNKNOWN", 16 - 1); break;
}
sprintf(audioRtp,
"\r\n"
Expand Down Expand Up @@ -230,7 +218,8 @@ static void __method_describe(struct connection_item_t *p, rtsp_handle h)
"%sm=video 0 RTP/AVP 96\r\n"
"a=control:track=0\r\n"
"a=rtpmap:96 %s/90000\r\n"
"a=fmtp:96 packetization-mode=1%s",
"a=fmtp:96 profile-level-id=000000;"
" packetization-mode=1;%s",
baseRtp,
h->isH265 ? "H265" : "H264",
audioRtp);
Expand Down Expand Up @@ -294,8 +283,8 @@ static void __method_play(struct connection_item_t *p, rtsp_handle h)
fprintf(p->fp_tcp_write,
"RTSP/1.0 200 OK\r\n"
"CSeq: %d\r\n"
"Session: %llx\r\n"
"\r\n" , p->cseq, p->session_id);
"Range: npt=now-\r\n"
"\r\n" , p->cseq);

for (int i = 0; i < sizeof(p->trans) / sizeof(*p->trans); i++) {
if (!p->trans[i].server_port_rtp) continue;
Expand Down Expand Up @@ -323,8 +312,7 @@ static int __method_teardown(struct connection_item_t *p, rtsp_handle h)
fprintf(p->fp_tcp_write,
"RTSP/1.0 200 OK\r\n"
"CSeq: %d\r\n"
"Session: %llx\r\n"
"\r\n", p->cseq, p->session_id);
"\r\n", p->cseq);

p->con_state = __CON_S_INIT;

Expand Down Expand Up @@ -517,7 +505,7 @@ static inline int __find_fd_max(struct list_head_t *head)
while (p) {
list_upcast(c,p);
if (c->con_state != __CON_S_DISCONNECTED) {
m = max(c->client_fd,m);
m = max(c->client_fd, m);
}
p = p->next;
}
Expand All @@ -543,7 +531,7 @@ static inline int __bind_tcp(unsigned short port)
int tmp = 1;

/* setup serve rsocket */
ASSERT((server_fd = socket(AF_INET,SOCK_STREAM,0)) > 0, ({
ASSERT((server_fd = socket(AF_INET, SOCK_STREAM, 0)) > 0, ({
ERR("socket:%s\n", strerror(errno));
goto error;}));

Expand All @@ -553,16 +541,16 @@ static inline int __bind_tcp(unsigned short port)
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_family = AF_INET;

ASSERT(bind(server_fd,(struct sockaddr *)&addr,sizeof(addr)) == 0, ({
ERR("bind:%s\n",strerror(errno));
ASSERT(bind(server_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0, ({
ERR("bind:%s\n", strerror(errno));
goto error;}));

ASSERT(listen(server_fd,5) >= 0, ({
ERR("listen:%s\n",strerror(errno));
ASSERT(listen(server_fd, 5) >= 0, ({
ERR("listen:%s\n", strerror(errno));
goto error;}));

/* set the socket to non-blocking */
fcntl(server_fd,F_SETFL,fcntl(server_fd,F_GETFL) | O_NONBLOCK);
fcntl(server_fd, F_SETFL, fcntl(server_fd, F_GETFL) | O_NONBLOCK);

return server_fd;
error:
Expand Down Expand Up @@ -726,7 +714,6 @@ static void *rtspThrFxn(void *v)
thread_sync_init(h);

while (!gbl_get_quit(h->sharedp->gbl)) {

FD_ZERO(&(socks.rfds));
FD_SET(server_fd, &(socks.rfds));
socks.timeout.tv_sec = 1;
Expand Down Expand Up @@ -847,5 +834,5 @@ int rtsp_tick(rtsp_handle h)
ERR("gettimeofday failed\n");
return FAILURE;}));

return __get_timestamp_offset(&h->stat,&tv);
return __get_timestamp_offset(&h->stat, &tv);
}

0 comments on commit d2c68c6

Please sign in to comment.