From patchwork Tue Mar 23 21:29:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alok Priyadarshi X-Patchwork-Id: 26577 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 68CA244B8F0 for ; Tue, 23 Mar 2021 23:30:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 43F0668A8FA; Tue, 23 Mar 2021 23:30:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 08390687F2A for ; Tue, 23 Mar 2021 23:30:01 +0200 (EET) Received: by mail-pj1-f41.google.com with SMTP id gb6so10679092pjb.0 for ; Tue, 23 Mar 2021 14:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4ZnRw9zBim8PUyVVNGOBHjBtPaDtUjdSuYsN7rAgTxc=; b=dDbG4xXtj+SKgR0xHWPTbpzAJu0QFJJ5ii1FiBAaKNobGyU7K4mIIKrsrkUTZhAcu9 he0Kt3CmBWq13BZZZTdWjbark8mCsd9ZoZdupEksetvDMxgPTlm2se+hDoCP++t8ddGK s8b3frlPVYbhzwKjARIWO48pcNBSzYhq+HKU4AK7n0pgO3DDNED4U2apie7ra/tbgZL+ rvmYb9HsvKomJnzG8OciRvKwAbw5RKDj/Cm0ofWxkcguqgoCIevk0RriIooTjuunXP0n JZoBEjLJVHPUHe9C/jTzzYv6cKBYFjf0nUw1RZuWuM2msujSjJwGpHF2CmLLNR4OJqu0 gR1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4ZnRw9zBim8PUyVVNGOBHjBtPaDtUjdSuYsN7rAgTxc=; b=uoWxftUudgjxZm1nXQlah3ug5pVWVoEprIB1KSzHa6T/wDCKQcXwHOIFFrR24sYKzj gIRUQK7FouRtBvPGp5HqyyzKB4ER+/pIHmX1Z+qMp5Odw1YMtP1XlX/S3S1QoCjF2txO dHJG/0D1uICpAfqUJNOATcWwkKZvLvkR0+eM2tMQWZ+sscUC2ti0WL7BL0rdDG1CsjVX WTqyH2+TOopviUkhD6wH05+egdsVZcb5623X8a8D3xhus/lDPoWDEhISObz6cD9xomFT 4cUH5PyGxqewfyMBX8ZmU31ToT4//Cgji6EBBDIA3VHjP/Ox4Ua+7rCVGIVFYk+WVUvQ 12MA== X-Gm-Message-State: AOAM533XkJ/O2BgRpijfEIs43nOdzlilPWQGAsqtC6tQC4CjwI7j6J40 VFKOkcgLvlw2xz0hJFnv/+apwsbbfU39yg== X-Google-Smtp-Source: ABdhPJxara851YoDSXRcHPL84+CyCu022ASH6PPr+2zjEBvAsCrkg7aURM6jn0EQC1qWMJFabHn+Rg== X-Received: by 2002:a17:90a:df91:: with SMTP id p17mr112849pjv.23.1616534999097; Tue, 23 Mar 2021 14:29:59 -0700 (PDT) Received: from localhost.localdomain (c-73-223-72-238.hsd1.ca.comcast.net. [73.223.72.238]) by smtp.gmail.com with ESMTPSA id gm9sm133041pjb.13.2021.03.23.14.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 14:29:58 -0700 (PDT) From: Alok Priyadarshi To: ffmpeg-devel@ffmpeg.org Date: Tue, 23 Mar 2021 14:29:48 -0700 Message-Id: <20210323212948.256616-1-alokpr@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/rtpdec: attach producer reference time if available X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Alok Priyadarshi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This produces true wallclock time at rtp source instead of the local wallclock time at rtp client. --- libavformat/internal.h | 8 ++++++++ libavformat/rtpdec.c | 20 ++++++++++++++++++++ libavformat/utils.c | 9 +++++++++ 3 files changed, 37 insertions(+) diff --git a/libavformat/internal.h b/libavformat/internal.h index 17a6ab07d3..1e10cde00e 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -254,6 +254,14 @@ uint64_t ff_ntp_time(void); */ uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us); +/** + * Parse the NTP time in micro seconds (since NTP epoch). + * + * @param ntp_ts NTP time stamp formatted as per the RFC-5905. + * @return the time in micro seconds (since NTP epoch) + */ +uint64_t ff_parse_ntp_time(uint64_t ntp_ts); + /** * Append the media-specific SDP fragment for the media stream c * to the buffer buff. diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 3d5b200099..b935dba1b8 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -30,6 +30,7 @@ #include "url.h" #include "rtpdec.h" #include "rtpdec_formats.h" +#include "internal.h" #define MIN_FEEDBACK_INTERVAL 200000 /* 200 ms in us */ @@ -583,6 +584,19 @@ void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, s->srtp_enabled = 1; } +static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { + AVProducerReferenceTime *prft = + (AVProducerReferenceTime *) av_packet_new_side_data( + pkt, AV_PKT_DATA_PRFT, sizeof(AVProducerReferenceTime)); + if (!prft) + return AVERROR(ENOMEM); + + prft->wallclock = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US + + timestamp - s->last_rtcp_timestamp; + prft->flags = 24; + return 0; +} + /** * This was the second switch in rtp_parse packet. * Normalizes time, if required, sets stream_index, etc. @@ -594,6 +608,12 @@ 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 (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) { int64_t addend; int delta_timestamp; diff --git a/libavformat/utils.c b/libavformat/utils.c index 7e5767ec60..569922beaf 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4734,6 +4734,15 @@ uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us) return ntp_ts; } +uint64_t ff_parse_ntp_time(uint64_t ntp_ts) +{ + uint64_t sec = ntp_ts >> 32; + uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL; + uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL; + + return (sec * 1000000) + usec; +} + int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags) { const char *p;