Skip to content

Commit

Permalink
Fixing the RTP timestamps that rendered A/V sync impossible, playback…
Browse files Browse the repository at this point in the history
… is smooth on VLC and FFmpeg-based apps
  • Loading branch information
wberube committed Oct 25, 2024
1 parent d2c68c6 commit affcbfe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/rtsp/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ static inline int __rtp_send_eachconnection(struct list_t *e, void *v)
if (!con->trans[track_id].server_port_rtp) return SUCCESS;

rtp->packet.header.seq = htons(con->trans[track_id].rtp_seq);
if (rtp->packet.header.m)
con->trans[track_id].rtp_timestamp = (millis() * 90) & UINT32_MAX;
rtp->packet.header.ts = htonl(con->trans[track_id].rtp_timestamp);
rtp->packet.header.ssrc = htonl(con->ssrc);
con->trans[track_id].rtp_seq += 1;
Expand Down
2 changes: 2 additions & 0 deletions src/rtsp/rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern "C" {
#endif

#include "../hal/tools.h"

/******************************************************************************
* DEFINITIONS
******************************************************************************/
Expand Down
11 changes: 4 additions & 7 deletions src/rtsp/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ 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 profile-level-id=000000;"
" packetization-mode=1;%s",
"a=fmtp:96 packetization-mode=1;%s",
baseRtp,
h->isH265 ? "H265" : "H264",
audioRtp);
Expand Down Expand Up @@ -292,7 +291,7 @@ static void __method_play(struct connection_item_t *p, rtsp_handle h)

ASSERT(__bind_rtcp(p) == SUCCESS, return);
ASSERT(__bind_rtp(p) == SUCCESS, return);
p->trans[p->track_id].rtp_timestamp = rand_r(&h->ctx);
p->trans[p->track_id].rtp_timestamp = (millis() * 90) & UINT32_MAX;
p->trans[p->track_id].rtp_seq = rand_r(&h->ctx);
p->trans[p->track_id].rtcp_octet = 0;
p->trans[p->track_id].rtcp_packet_cnt = 0;
Expand Down Expand Up @@ -453,23 +452,21 @@ static int __connection_reset(void *v)
CLOSE(p->trans[i].server_rtp_fd);
p->trans[i].server_rtp_fd = 0;
}

p->trans[i].rtp_timestamp = 0;
}


p->given_session_id = 0;
p->cseq = 0;

ctx = p->trans[0].rtp_timestamp;

/* randomize session id to avoid conflict */
p->session_id = __get_random_llu(&ctx);

return SUCCESS;
}

static inline int
__connection_list_add(bufpool_handle con_pool, struct list_head_t *head,int fd, struct sockaddr_in addr)
__connection_list_add(bufpool_handle con_pool, struct list_head_t *head, int fd, struct sockaddr_in addr)
{
DASSERT(head, return FAILURE);
DASSERT(fd > 0, return FAILURE);
Expand Down

0 comments on commit affcbfe

Please sign in to comment.