diff options
author | Marvin Scholz <epirat07@gmail.com> | 2025-04-25 18:18:21 +0200 |
---|---|---|
committer | Marvin Scholz <epirat07@gmail.com> | 2025-07-07 16:14:02 +0200 |
commit | 74aa710879689bf9ba569fbd13fb5074a666e92b (patch) | |
tree | d57b857444b4dac9d2a434d53a603bffb2c95799 /libavformat/rtpdec.c | |
parent | e0abe0a02a6963955f1463d32c441fa22c1673a7 (diff) | |
download | ffmpeg-74aa710879689bf9ba569fbd13fb5074a666e92b.tar.gz |
lavf: add and use AVRTCPSenderReport struct
This will be used in a future commit to expose the SR as side-data.
Diffstat (limited to 'libavformat/rtpdec.c')
-rw-r--r-- | libavformat/rtpdec.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 5aecf7fbc7..f27ef106b4 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -192,14 +192,20 @@ static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, return AVERROR_INVALIDDATA; } + s->last_sr.ssrc = AV_RB32(buf + 4); + s->last_sr.ntp_timestamp = AV_RB64(buf + 8); + s->last_sr.rtp_timestamp = AV_RB32(buf + 16); + s->last_sr.sender_nb_packets = AV_RB32(buf + 20); + s->last_sr.sender_nb_bytes = AV_RB32(buf + 24); + + s->pending_sr = 1; s->last_rtcp_reception_time = av_gettime_relative(); - s->last_rtcp_ntp_time = AV_RB64(buf + 8); - s->last_rtcp_timestamp = AV_RB32(buf + 16); + if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) { - s->first_rtcp_ntp_time = s->last_rtcp_ntp_time; + s->first_rtcp_ntp_time = s->last_sr.ntp_timestamp; if (!s->base_timestamp) - s->base_timestamp = s->last_rtcp_timestamp; - s->rtcp_ts_offset = (int32_t)(s->last_rtcp_timestamp - s->base_timestamp); + s->base_timestamp = s->last_sr.rtp_timestamp; + s->rtcp_ts_offset = (int32_t)(s->last_sr.rtp_timestamp - s->base_timestamp); } break; @@ -367,11 +373,11 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, avio_wb32(pb, extended_max); /* max sequence received */ avio_wb32(pb, stats->jitter >> 4); /* jitter */ - if (s->last_rtcp_ntp_time == AV_NOPTS_VALUE) { + if (s->last_sr.ntp_timestamp == AV_NOPTS_VALUE) { avio_wb32(pb, 0); /* last SR timestamp */ avio_wb32(pb, 0); /* delay since last SR */ } else { - uint32_t middle_32_bits = s->last_rtcp_ntp_time >> 16; // this is valid, right? do we need to handle 64 bit values special? + uint32_t middle_32_bits = s->last_sr.ntp_timestamp >> 16; // this is valid, right? do we need to handle 64 bit values special? uint32_t delay_since_last = av_rescale(av_gettime_relative() - s->last_rtcp_reception_time, 65536, AV_TIME_BASE); @@ -538,7 +544,7 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, if (!s) return NULL; s->payload_type = payload_type; - s->last_rtcp_ntp_time = AV_NOPTS_VALUE; + s->last_sr.ntp_timestamp = AV_NOPTS_VALUE; s->first_rtcp_ntp_time = AV_NOPTS_VALUE; s->ic = s1; s->st = st; @@ -596,9 +602,9 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { if (!prft) return AVERROR(ENOMEM); - rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US; + rtcp_time = ff_parse_ntp_time(s->last_sr.ntp_timestamp) - NTP_OFFSET_US; /* Cast to int32_t to handle timestamp wraparound correctly */ - delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp); + delta_timestamp = (int32_t)(timestamp - s->last_sr.rtp_timestamp); delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q); prft->wallclock = rtcp_time + delta_time; @@ -617,21 +623,21 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam if (timestamp == RTP_NOTS_VALUE) return; - if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) { + if (s->last_sr.ntp_timestamp != AV_NOPTS_VALUE) { if (rtp_set_prft(s, pkt, timestamp) < 0) { av_log(s->ic, AV_LOG_WARNING, "rtpdec: failed to set prft"); } } - if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) { + if (s->last_sr.ntp_timestamp != AV_NOPTS_VALUE && s->ic->nb_streams > 1) { int64_t addend; int32_t delta_timestamp; /* compute pts from timestamp with received ntp_time */ /* Cast to int32_t to handle timestamp wraparound correctly */ - delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp); + delta_timestamp = (int32_t)(timestamp - s->last_sr.rtp_timestamp); /* convert to the PTS timebase */ - addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time, + addend = av_rescale(s->last_sr.ntp_timestamp - s->first_rtcp_ntp_time, s->st->time_base.den, (uint64_t) s->st->time_base.num << 32); pkt->pts = s->range_start_offset + s->rtcp_ts_offset + addend + |