History

lavf: add and use AVRTCPSenderReport struct

This will be used in a future commit to expose the SR as side-data.

Marvin Scholz committed 1 year ago

Commit 74aa7101 parent e0abe0a4 files · +37 −17Browse files

Unified · Split

4 files
  1. libavcodec/defs.h +14 −0
  2. libavformat/rtpdec.c +20 −14
  3. libavformat/rtpdec.h +2 −2
  4. libavformat/rtspdec.c +1 −1
libavcodec/defs.h+14−0
@@ -333,6 +333,20 @@ typedef struct AVProducerReferenceTime { · 332 unmodified lines
333333 int flags;
334334 } AVProducerReferenceTime;
335335
336+/**
337+ * RTCP SR (Sender Report) information
338+ *
339+ * The received sender report information for an RTSP
340+ * stream, exposed as AV_PKT_DATA_RTCP_SR side data.
341+ */
342+typedef struct AVRTCPSenderReport {
343+ uint32_t ssrc; ///< Synchronization source identifier
344+ uint64_t ntp_timestamp; ///< NTP time when the report was sent
345+ uint32_t rtp_timestamp; ///< RTP time when the report was sent
346+ uint32_t sender_nb_packets; ///< Total number of packets sent
347+ uint32_t sender_nb_bytes; ///< Total number of bytes sent (excluding headers or padding)
348+} AVRTCPSenderReport;
349+
336350 /**
337351 * Encode extradata length to a buffer. Used by xiph codecs.
338352 *
libavformat/rtpdec.c+20−14
@@ -192,14 +192,20 @@ static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, · 191 unmodified lines
192192 return AVERROR_INVALIDDATA;
193193 }
194194
195+ s->last_sr.ssrc = AV_RB32(buf + 4);
196+ s->last_sr.ntp_timestamp = AV_RB64(buf + 8);
197+ s->last_sr.rtp_timestamp = AV_RB32(buf + 16);
198+ s->last_sr.sender_nb_packets = AV_RB32(buf + 20);
199+ s->last_sr.sender_nb_bytes = AV_RB32(buf + 24);
200+
201+ s->pending_sr = 1;
195202 s->last_rtcp_reception_time = av_gettime_relative();
196− s->last_rtcp_ntp_time = AV_RB64(buf + 8);
197− s->last_rtcp_timestamp = AV_RB32(buf + 16);
203+
198204 if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) {
199− s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
205+ s->first_rtcp_ntp_time = s->last_sr.ntp_timestamp;
200206 if (!s->base_timestamp)
201− s->base_timestamp = s->last_rtcp_timestamp;
202− s->rtcp_ts_offset = (int32_t)(s->last_rtcp_timestamp - s->base_timestamp);
207+ s->base_timestamp = s->last_sr.rtp_timestamp;
208+ s->rtcp_ts_offset = (int32_t)(s->last_sr.rtp_timestamp - s->base_timestamp);
203209 }
204210
205211 break;
@@ -367,11 +373,11 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, · 161 unmodified lines
367373 avio_wb32(pb, extended_max); /* max sequence received */
368374 avio_wb32(pb, stats->jitter >> 4); /* jitter */
369375
370− if (s->last_rtcp_ntp_time == AV_NOPTS_VALUE) {
376+ if (s->last_sr.ntp_timestamp == AV_NOPTS_VALUE) {
371377 avio_wb32(pb, 0); /* last SR timestamp */
372378 avio_wb32(pb, 0); /* delay since last SR */
373379 } else {
374− uint32_t middle_32_bits = s->last_rtcp_ntp_time >> 16; // this is valid, right? do we need to handle 64 bit values special?
380+ uint32_t middle_32_bits = s->last_sr.ntp_timestamp >> 16; // this is valid, right? do we need to handle 64 bit values special?
375381 uint32_t delay_since_last = av_rescale(av_gettime_relative() - s->last_rtcp_reception_time,
376382 65536, AV_TIME_BASE);
377383
@@ -538,7 +544,7 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, · 160 unmodified lines
538544 if (!s)
539545 return NULL;
540546 s->payload_type = payload_type;
541− s->last_rtcp_ntp_time = AV_NOPTS_VALUE;
547+ s->last_sr.ntp_timestamp = AV_NOPTS_VALUE;
542548 s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
543549 s->ic = s1;
544550 s->st = st;
@@ -596,9 +602,9 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { · 51 unmodified lines
596602 if (!prft)
597603 return AVERROR(ENOMEM);
598604
599− rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US;
605+ rtcp_time = ff_parse_ntp_time(s->last_sr.ntp_timestamp) - NTP_OFFSET_US;
600606 /* Cast to int32_t to handle timestamp wraparound correctly */
601− delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);
607+ delta_timestamp = (int32_t)(timestamp - s->last_sr.rtp_timestamp);
602608 delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q);
603609
604610 prft->wallclock = rtcp_time + delta_time;
@@ -617,21 +623,21 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam · 12 unmodified lines
617623 if (timestamp == RTP_NOTS_VALUE)
618624 return;
619625
620− if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
626+ if (s->last_sr.ntp_timestamp != AV_NOPTS_VALUE) {
621627 if (rtp_set_prft(s, pkt, timestamp) < 0) {
622628 av_log(s->ic, AV_LOG_WARNING, "rtpdec: failed to set prft");
623629 }
624630 }
625631
626− if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) {
632+ if (s->last_sr.ntp_timestamp != AV_NOPTS_VALUE && s->ic->nb_streams > 1) {
627633 int64_t addend;
628634 int32_t delta_timestamp;
629635
630636 /* compute pts from timestamp with received ntp_time */
631637 /* Cast to int32_t to handle timestamp wraparound correctly */
632− delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);
638+ delta_timestamp = (int32_t)(timestamp - s->last_sr.rtp_timestamp);
633639 /* convert to the PTS timebase */
634− addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time,
640+ addend = av_rescale(s->last_sr.ntp_timestamp - s->first_rtcp_ntp_time,
635641 s->st->time_base.den,
636642 (uint64_t) s->st->time_base.num << 32);
637643 pkt->pts = s->range_start_offset + s->rtcp_ts_offset + addend +
libavformat/rtpdec.h+2−2
@@ -173,11 +173,11 @@ struct RTPDemuxContext { · 172 unmodified lines
173173 /*@}*/
174174
175175 /* rtcp sender statistics receive */
176− uint64_t last_rtcp_ntp_time;
177176 int64_t last_rtcp_reception_time;
178177 uint64_t first_rtcp_ntp_time;
179− uint32_t last_rtcp_timestamp;
180178 int64_t rtcp_ts_offset;
179+ AVRTCPSenderReport last_sr; ///< Last RTCP SR data
180+ int pending_sr; ///< Indicates if there is a SR pending to be attached as sidedata
181181
182182 /* rtcp sender statistics */
183183 unsigned int packet_count;
libavformat/rtspdec.c+1−1
@@ -553,7 +553,7 @@ static int rtsp_read_play(AVFormatContext *s) · 552 unmodified lines
553553 if (!rtpctx)
554554 continue;
555555 ff_rtp_reset_packet_queue(rtpctx);
556− rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE;
556+ rtpctx->last_sr.ntp_timestamp = AV_NOPTS_VALUE;
557557 rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE;
558558 rtpctx->base_timestamp = 0;
559559 rtpctx->timestamp = 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t