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
333 int flags;333 int flags;
334} AVProducerReferenceTime;334} AVProducerReferenceTime;
335 335
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 */
342typedef 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
336/**350/**
337 * Encode extradata length to a buffer. Used by xiph codecs.351 * Encode extradata length to a buffer. Used by xiph codecs.
338 *352 *
libavformat/rtpdec.c+20−14
@@ -192,14 +192,20 @@ static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, · 191 unmodified lines
192 return AVERROR_INVALIDDATA;192 return AVERROR_INVALIDDATA;
193 }193 }
194 194
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;
195 s->last_rtcp_reception_time = av_gettime_relative();202 s->last_rtcp_reception_time = av_gettime_relative();
196 s->last_rtcp_ntp_time = AV_RB64(buf + 8);203
197 s->last_rtcp_timestamp = AV_RB32(buf + 16);
198 if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) {204 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;
200 if (!s->base_timestamp)206 if (!s->base_timestamp)
201 s->base_timestamp = s->last_rtcp_timestamp;207 s->base_timestamp = s->last_sr.rtp_timestamp;
202 s->rtcp_ts_offset = (int32_t)(s->last_rtcp_timestamp - s->base_timestamp);208 s->rtcp_ts_offset = (int32_t)(s->last_sr.rtp_timestamp - s->base_timestamp);
203 }209 }
204 210
205 break;211 break;
@@ -367,11 +373,11 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, · 161 unmodified lines
367 avio_wb32(pb, extended_max); /* max sequence received */373 avio_wb32(pb, extended_max); /* max sequence received */
368 avio_wb32(pb, stats->jitter >> 4); /* jitter */374 avio_wb32(pb, stats->jitter >> 4); /* jitter */
369 375
370 if (s->last_rtcp_ntp_time == AV_NOPTS_VALUE) {376 if (s->last_sr.ntp_timestamp == AV_NOPTS_VALUE) {
371 avio_wb32(pb, 0); /* last SR timestamp */377 avio_wb32(pb, 0); /* last SR timestamp */
372 avio_wb32(pb, 0); /* delay since last SR */378 avio_wb32(pb, 0); /* delay since last SR */
373 } else {379 } 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?
375 uint32_t delay_since_last = av_rescale(av_gettime_relative() - s->last_rtcp_reception_time,381 uint32_t delay_since_last = av_rescale(av_gettime_relative() - s->last_rtcp_reception_time,
376 65536, AV_TIME_BASE);382 65536, AV_TIME_BASE);
377 383
@@ -538,7 +544,7 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, · 160 unmodified lines
538 if (!s)544 if (!s)
539 return NULL;545 return NULL;
540 s->payload_type = payload_type;546 s->payload_type = payload_type;
541 s->last_rtcp_ntp_time = AV_NOPTS_VALUE;547 s->last_sr.ntp_timestamp = AV_NOPTS_VALUE;
542 s->first_rtcp_ntp_time = AV_NOPTS_VALUE;548 s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
543 s->ic = s1;549 s->ic = s1;
544 s->st = st;550 s->st = st;
@@ -596,9 +602,9 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { · 51 unmodified lines
596 if (!prft)602 if (!prft)
597 return AVERROR(ENOMEM);603 return AVERROR(ENOMEM);
598 604
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;
600 /* Cast to int32_t to handle timestamp wraparound correctly */606 /* 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);
602 delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q);608 delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q);
603 609
604 prft->wallclock = rtcp_time + delta_time;610 prft->wallclock = rtcp_time + delta_time;
@@ -617,21 +623,21 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam · 12 unmodified lines
617 if (timestamp == RTP_NOTS_VALUE)623 if (timestamp == RTP_NOTS_VALUE)
618 return;624 return;
619 625
620 if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {626 if (s->last_sr.ntp_timestamp != AV_NOPTS_VALUE) {
621 if (rtp_set_prft(s, pkt, timestamp) < 0) {627 if (rtp_set_prft(s, pkt, timestamp) < 0) {
622 av_log(s->ic, AV_LOG_WARNING, "rtpdec: failed to set prft");628 av_log(s->ic, AV_LOG_WARNING, "rtpdec: failed to set prft");
623 }629 }
624 }630 }
625 631
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) {
627 int64_t addend;633 int64_t addend;
628 int32_t delta_timestamp;634 int32_t delta_timestamp;
629 635
630 /* compute pts from timestamp with received ntp_time */636 /* compute pts from timestamp with received ntp_time */
631 /* Cast to int32_t to handle timestamp wraparound correctly */637 /* 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);
633 /* convert to the PTS timebase */639 /* 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,
635 s->st->time_base.den,641 s->st->time_base.den,
636 (uint64_t) s->st->time_base.num << 32);642 (uint64_t) s->st->time_base.num << 32);
637 pkt->pts = s->range_start_offset + s->rtcp_ts_offset + addend +643 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
173 /*@}*/173 /*@}*/
174 174
175 /* rtcp sender statistics receive */175 /* rtcp sender statistics receive */
176 uint64_t last_rtcp_ntp_time;
177 int64_t last_rtcp_reception_time;176 int64_t last_rtcp_reception_time;
178 uint64_t first_rtcp_ntp_time;177 uint64_t first_rtcp_ntp_time;
179 uint32_t last_rtcp_timestamp;
180 int64_t rtcp_ts_offset;178 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
181 181
182 /* rtcp sender statistics */182 /* rtcp sender statistics */
183 unsigned int packet_count;183 unsigned int packet_count;
libavformat/rtspdec.c+1−1
@@ -553,7 +553,7 @@ static int rtsp_read_play(AVFormatContext *s) · 552 unmodified lines
553 if (!rtpctx)553 if (!rtpctx)
554 continue;554 continue;
555 ff_rtp_reset_packet_queue(rtpctx);555 ff_rtp_reset_packet_queue(rtpctx);
556 rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE;556 rtpctx->last_sr.ntp_timestamp = AV_NOPTS_VALUE;
557 rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE;557 rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE;
558 rtpctx->base_timestamp = 0;558 rtpctx->base_timestamp = 0;
559 rtpctx->timestamp = 0;559 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