From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 07C694FBFC for ; Sat, 28 Jun 2025 14:27:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 20DD768E33A; Sat, 28 Jun 2025 17:27:41 +0300 (EEST) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id C4D0D68E339 for ; Sat, 28 Jun 2025 17:27:34 +0300 (EEST) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-45348bff79fso7768935e9.2 for ; Sat, 28 Jun 2025 07:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751120854; x=1751725654; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ScBnblEyhklCl0LPEJVvwp6K4+tE1or+i4mNRSSsbFo=; b=LMA37Az9gx9ZSmKJ1Nw3L78mi8ag/vi3OXJkpzez/ENCs7W7Fi8uC44DQvIOMtrThk JVFta1UFHHs/pr9e9rPMDTNES5bzVikv+2FF6sgv6uelNp4nWssu0w3r/YmxEvhTPgIF OwWzvdIuGjtckVCzq40Nw9VJJe4Eb0z59ZEGbOonvLJVTxelbnq1LoYq8htZmvZF63Dd +engREhQp974nXQZ9b+3y78+dKR+DCRM9ANjTooUlF+zLfeY2Ozkw0ZcPdDJSUpDPgMg NmlCZb43XN8j5iiOGI/7y+smCrXT76PGMDdg2siZlbp2p3lexN/2Wm4yqEi9lFSFRXDd 4BvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751120854; x=1751725654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ScBnblEyhklCl0LPEJVvwp6K4+tE1or+i4mNRSSsbFo=; b=BvH2f4UXSMDv1n+1mXXiq8GtG3wYWg8/yrmqIYHOkRzJyPJr4h8MA3EMW9p+dQMdAE bsxlx4rW6BMGWrb+eXW5+sB5ebPPf9Fkuko+39YRs44DhGwBVy/0xL25hVoIL3QrSHmN S55TuPjWG2V5rANVhG2KOiy39DkKD71XNaNRApNNoasWAoAunYStLkmJOmv4/d7066In rWvp9uTXa7bcaWq+6phqgJus8AmiD5W/aDO3VFXqqfafvJgpUn44KXv3OzP2wL3T8/nj dujMXHkClWsdVrnULXluLDliTFACNi3uUekz41i/uYKZqFjfxBbjsn38ysV2tI2/NVcZ oM3Q== X-Gm-Message-State: AOJu0YxSsdozYUIB+ZvvO616V2p2CjKEf+qUTlSFAjts5p8VxqSc/BAG pPZ48eP4kzYoVweUSBjUQUal+u8xKNFvaeYZABHPYwyIUra+UBXIEmv1N9nUHw== X-Gm-Gg: ASbGncv7rUWli9ja8k9CEYAf3aiqBsgALPZ0zgwCyXvVMQd0VWv0V333lh780fHestF Qgn+B5UKcrZgC8w0nzKzM2rHIK528UyYGySW9g+OobYsQSlZ8VSShuupCXD60eLn616KGum4ZuS KzKhTnveYJjyFn7HUHGi/ZElPcYnY8jZMaPMyquxmtXor0sMuA4O8cTR5MEFlUHDIcgvJb/fRV3 YmHV92YTjX9fkesz8bzUKG1ZW4bVktaUCD96b2VSMlmnAYb12UfWVxOPfhVfM+NmDi9QEKrqn1F FVGCUU8xTN4PJ9PYe2bGf128yo6InqSrLKQctUi4STAlCyzGfy0Gr7h0KBcrovLSqJ4LsDDfcWa 35vE1DfjNFZiSSomUcv+vUlLS3G1IIhNTMfWyfx2B/+qCVfbtWabUi2SZpvH2kWor2zRBNhghkP 63S9yhaOtKTHeAvTw= X-Google-Smtp-Source: AGHT+IFtzGps2a6/3+Uv0Oa0meNAO3wBqv3aBuSSfm1MRrDOv9Y6KRJDdnkK8uZqX+p/ZfNjSLrylw== X-Received: by 2002:a05:600c:1c8b:b0:442:f4d4:522 with SMTP id 5b1f17b1804b1-45391431c04mr61143555e9.5.1751120853799; Sat, 28 Jun 2025 07:27:33 -0700 (PDT) Received: from ArmedBeast.fritz.box (p2003010237004500d82e3c7de7372df5.dip0.t-ipconnect.de. [2003:102:3700:4500:d82e:3c7d:e737:2df5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4538f754326sm53366975e9.18.2025.06.28.07.27.32 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Jun 2025 07:27:33 -0700 (PDT) From: Marvin Scholz To: ffmpeg-devel@ffmpeg.org Date: Sat, 28 Jun 2025 16:27:24 +0200 Message-Id: <20250628142725.26651-2-epirat07@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250628142725.26651-1-epirat07@gmail.com> References: <20250624180202.15430-1-epirat07@gmail.com> <20250628142725.26651-1-epirat07@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/3] lavf: add and use AVRTCPSenderReport struct X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This will be used in a future commit to expose the SR as side-data. --- libavcodec/defs.h | 14 ++++++++++++++ libavformat/rtpdec.c | 34 ++++++++++++++++++++-------------- libavformat/rtpdec.h | 4 ++-- libavformat/rtspdec.c | 2 +- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/libavcodec/defs.h b/libavcodec/defs.h index e0df60213b..8ce5d424c9 100644 --- a/libavcodec/defs.h +++ b/libavcodec/defs.h @@ -333,6 +333,20 @@ typedef struct AVProducerReferenceTime { int flags; } AVProducerReferenceTime; +/** + * RTCP SR (Sender Report) information + * + * The received sender report information for an RTSP + * stream, exposed as AV_PKT_DATA_RTCP_SR side data. + */ +typedef struct AVRTCPSenderReport { + uint32_t ssrc; ///< Synchronization source identifier + uint64_t ntp_timestamp; ///< NTP time when the report was sent + uint32_t rtp_timestamp; ///< RTP time when the report was sent + uint32_t sender_nb_packets; ///< Total number of packets sent + uint32_t sender_nb_bytes; ///< Total number of bytes sent (excluding headers or padding) +} AVRTCPSenderReport; + /** * Encode extradata length to a buffer. Used by xiph codecs. * 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 + diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h index 5a02e72dc2..c06f44b86c 100644 --- a/libavformat/rtpdec.h +++ b/libavformat/rtpdec.h @@ -173,11 +173,11 @@ struct RTPDemuxContext { /*@}*/ /* rtcp sender statistics receive */ - uint64_t last_rtcp_ntp_time; int64_t last_rtcp_reception_time; uint64_t first_rtcp_ntp_time; - uint32_t last_rtcp_timestamp; int64_t rtcp_ts_offset; + AVRTCPSenderReport last_sr; ///< Last RTCP SR data + int pending_sr; ///< Indicates if there is a SR pending to be attached as sidedata /* rtcp sender statistics */ unsigned int packet_count; diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index 10078ce2fa..88a57b01ef 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -553,7 +553,7 @@ static int rtsp_read_play(AVFormatContext *s) if (!rtpctx) continue; ff_rtp_reset_packet_queue(rtpctx); - rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE; + rtpctx->last_sr.ntp_timestamp = AV_NOPTS_VALUE; rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE; rtpctx->base_timestamp = 0; rtpctx->timestamp = 0; -- 2.39.5 (Apple Git-154) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".