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 A30324FA19 for ; Tue, 24 Jun 2025 18:02:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 41A5C68CF9B; Tue, 24 Jun 2025 21:02:18 +0300 (EEST) Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id BDA0868CEFC for ; Tue, 24 Jun 2025 21:02:11 +0300 (EEST) Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-442fda876a6so51413975e9.0 for ; Tue, 24 Jun 2025 11:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750788131; x=1751392931; 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=y2Ws948XZOiPkTAAd4f0B1QFPOa0QjzG/mA98Mn56hw=; b=m0pNgDVRbjdeZYoeTSnGsGJV9t4OZO7PasdA6wcQ6WkkbTzW8l9Xy43shVhyoXpH3B 0233EVeC4/m1mhAQ30mGRVf5FaZvqpziZlt9eAuX97bVghYmHbttJFMkIhaVEO5wCyPc DxcubJYP8ag/OecbFdqwOR2NQwLX0vQeMcCY622uq0LTVErUxc4I6B+nR9yWDvMKMOHP TL0UcS2wSM6FFNYgtB0vPXxHSfZftk8/bAOtKKLF3egW6ODZ41/eZK4Hn0kBD0m0dlT+ OkYpKRaPEmvBau2M/TazIs8MzeHXAGZ1SUwEBI70sPXnVUpMtKsoEBXbdJ1/ifZvPDam 2NIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750788131; x=1751392931; 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=y2Ws948XZOiPkTAAd4f0B1QFPOa0QjzG/mA98Mn56hw=; b=ZsR1W2tf3EZttWNINcUi2TkamfpOlHXaGhjHVXG89phcUtsFFN8sq/kwT2AMt+TgFu Og5OTGAcLusGpp3zx4AG9tVYqor3yK9t4u9+lDYXi7MRlHWrKG01dO1kSB87eYJHCNm/ d7/5Vwlho2c25BbjCEVvZj7RwhFJLMywD3k9nEt4igIdNOiOQFU7j4yoMK7v1gySTzat Wd1/vpSWBEOlW8b8QfPm/av8a3AgSHhliuYWQMV03aaxrcd+enpgZVq+1P6abfZhGkKS HCpVevaxjm4fU2vJ029UTAYq1czr9fqHFMCAusG4REZr4SUVdxP0nHRDDPwOSLxlrSWG 4+Vw== X-Gm-Message-State: AOJu0YzQN1Yz9HWn3hnzhS+YPoIM2x85hMmsiE9K3rCUPOM+W6AKIcM+ fu3hOgoX+hMIggIJuvGMXyCpFQPMYsUJzz09UQorS2vq/Y2wR1RqLn3DMAmukw== X-Gm-Gg: ASbGnctQIJBQKLoGDu/0Pd6pmGyYJZ5ztza2uc9wPooPRWcEfEQryLkkrfaHeQtC9Jy xgHTyziq7fCy8pnCJFdLrxvzuxTb6cP3BcuRlFsshoqt4AlNhALT5HEMpbNR1tgvbrm0TOkGOyC uZspJJ2Y42TITZQlMYC7bLxP4vWJGAT5qZammDEFxbMXZsBuitpbmhD9wDyHiUd755rFmYlPpqa TcCuFmruBWdvlQWtJU8yhWm3HQkwvFwNTHBvgxaMo/38GeyKzRzdyKwMXU8YxdL9UDLDPNzU0I+ dwrJjO0uB4DlFaoiJEA5r2GIsjoa8nFMHpaJGsEXctjjAA+kXSzY+6pnPs7qt3DTIJMjbNtKwBl 5Frt5QI7V4kg83FC+Jj/budSqLnT5UYbmvluRof6uzlXhxWrjl+2WnMZ1MVIeI70Z17SgYywKPz n/YuY= X-Google-Smtp-Source: AGHT+IG7cfH3WbYUAv6lz+ln06X/xAVJmZ/cYMPsO2VPcMKpsYu+ZMUJ1TtlJzcns3FRQGgS4pdnbg== X-Received: by 2002:a05:600c:3b97:b0:442:ccf0:41e6 with SMTP id 5b1f17b1804b1-45381aa53fcmr126395e9.3.1750788128854; Tue, 24 Jun 2025 11:02:08 -0700 (PDT) Received: from ArmedBeast.fritz.box (p20030102370045006de90db78179531b.dip0.t-ipconnect.de. [2003:102:3700:4500:6de9:db7:8179:531b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-453803fe596sm14228255e9.24.2025.06.24.11.02.08 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Jun 2025 11:02:08 -0700 (PDT) From: Marvin Scholz To: ffmpeg-devel@ffmpeg.org Date: Tue, 24 Jun 2025 20:02:01 +0200 Message-Id: <20250624180202.15430-2-epirat07@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250624180202.15430-1-epirat07@gmail.com> References: <20250624180202.15430-1-epirat07@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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 97aabcf542..9c9d66f33d 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,8 +602,8 @@ 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; - delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp); + rtcp_time = ff_parse_ntp_time(s->last_sr.ntp_timestamp) - NTP_OFFSET_US; + 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; @@ -616,20 +622,20 @@ 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; int delta_timestamp; /* compute pts from timestamp with received ntp_time */ - delta_timestamp = timestamp - s->last_rtcp_timestamp; + delta_timestamp = 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".