From patchwork Thu Sep 9 13:34:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 30085 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp521171iov; Thu, 9 Sep 2021 06:34:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeyHlJVDHxcnZQg3jfusyHPUbWIHajEd9xkQsohPVeER7GJABat1WfJVmUyWlaL6CllPUx X-Received: by 2002:a05:6402:104a:: with SMTP id e10mr3241399edu.139.1631194466640; Thu, 09 Sep 2021 06:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631194466; cv=none; d=google.com; s=arc-20160816; b=TDWFOcYtA2Af2PAXTYF6XFcHEVsIH8UPofsm1Kzgb+tOBGQpQuQwpUv6DnBqLSQVBk 2rEVEUD5ubWeSbBkl8cdY6J47NvRfoAipw7TEH4EFVrR6XS/EHzRlMswaZdegHeHhP9o m9cd0zMWbvwknZ6nuBr6hRa0mMQOJ09MgW0oIk3XcH8ITYJT8tR2i4i2/Zqh2C9o5djT ob2SMHbM3gaqqZ+y+S4vtQZmGyu9U+RdPKt7hPzAa8L50a+xGxOcglkz20wChYYUzGhs Jq1MqXDcO+03BLBgLwugOml0wkEsVAzi//Eb8rRSbPX0avXiA7jNrppvi2DbXR+Qiwpd appQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=Jj8l9Fuub6W16fsZ46H2lk/kZnNMDOVwmmOu/8GVtws=; b=H1mmX7rpGuEnDaS6kD5pAdxSARB+Z3gYVMm3VnyM0O3aJTS8DJNDSYNagezQzPA+iO qtpOYLzHo1/qQgyMnfsI+1rJHwYvK7oYf4l4wPLQIkdo6j3SlHu9iPJOkfuYUyoXlR19 Sv5f+QWEB4f/NkoJAa/P4u8I9CMUPvlh6eCWCl082g+jRDruPaJJT9U0ECyXmyqLR5nN CgFrH78wtFqyks9kEiTQacYrIBuaT1gI+q4G0Fg3Y7wAkFtC9M5FMhkGFcGjffUMzIP2 LVj0wPdQK/pQ5cVwcxyf8cJbMmBJa94/BqWwyA22bDoa63c/otTI8F7bmkWhq7CRPhxm l+4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c24si1967320ejj.646.2021.09.09.06.34.16; Thu, 09 Sep 2021 06:34:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0E5AB68A603; Thu, 9 Sep 2021 16:34:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 465E968A603 for ; Thu, 9 Sep 2021 16:34:06 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 189DY5e1001106 for ; Thu, 9 Sep 2021 15:34:05 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 456D5EB5C6; Thu, 9 Sep 2021 15:34:05 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Sep 2021 15:34:02 +0200 Message-Id: <20210909133402.1597006-1-george@nsup.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 09 Sep 2021 15:34:05 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH] lavc/packet: deprecate AVPacket.time_base 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YQ8rEfXFiKXx The contents of AVPacket can only make sense with some extra information. In FFmpeg, this information is carried by AVStream. Applications can use AVStream or define their own data structure for that. There is no reason to carry one of these informations everywhere along with the packet. Furthermore, since this field is only set by libavformat and never used by any part of the code, we have absolutely no test coverage. That means it can become out of sync with what it should be and we would not notice. As a general principle, having the same redundant information in several data structures and expecting it to stay in sync is a bad and risky practice. Signed-off-by: Nicolas George --- libavcodec/avpacket.c | 12 ++++++++++++ libavcodec/packet.h | 7 +++++++ libavcodec/version.h | 3 +++ libavformat/mux.c | 8 ++++++++ 4 files changed, 30 insertions(+) Please believe that I am not sending this patch to be contrarian. I genuinely believe it is a bad idea, and the paragraphs above explain why. This field has been added only recently, that means we can remove it without a lot of damage. It also means we have managed without it for years, and if we could, then applications should be able too. They just have to do what we do: include a time_base field in their data structure describing stream. diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index d8d8fef3b9..79ff35dd68 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -47,7 +47,11 @@ void av_init_packet(AVPacket *pkt) pkt->side_data_elems = 0; pkt->opaque = NULL; pkt->opaque_ref = NULL; +#if FF_API_PACKET_TIMEBASE +FF_DISABLE_DEPRECATION_WARNINGS pkt->time_base = av_make_q(0, 1); +FF_ENABLE_DEPRECATION_WARNINGS +#endif } #endif @@ -58,7 +62,11 @@ static void get_packet_defaults(AVPacket *pkt) pkt->pts = AV_NOPTS_VALUE; pkt->dts = AV_NOPTS_VALUE; pkt->pos = -1; +#if FF_API_PACKET_TIMEBASE +FF_DISABLE_DEPRECATION_WARNINGS pkt->time_base = av_make_q(0, 1); +FF_ENABLE_DEPRECATION_WARNINGS +#endif } AVPacket *av_packet_alloc(void) @@ -388,7 +396,11 @@ int av_packet_copy_props(AVPacket *dst, const AVPacket *src) dst->flags = src->flags; dst->stream_index = src->stream_index; dst->opaque = src->opaque; +#if FF_API_PACKET_TIMEBASE +FF_DISABLE_DEPRECATION_WARNINGS dst->time_base = src->time_base; +FF_ENABLE_DEPRECATION_WARNINGS +#endif dst->opaque_ref = NULL; dst->side_data = NULL; dst->side_data_elems = 0; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index 9baff24635..e411fad06b 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -408,10 +408,17 @@ typedef struct AVPacket { */ AVBufferRef *opaque_ref; +#if FF_API_PACKET_TIMEBASE /** * Time base of the packet's timestamps. + * Deprecated: the time base is specified by AVStream->time_base; + * applications need to propagate it if they separate a packet from its + * stream. */ + attribute_deprecated AVRational time_base; +#endif + } AVPacket; #if FF_API_INIT_PACKET diff --git a/libavcodec/version.h b/libavcodec/version.h index 4b4fe543ab..c84267243d 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -81,5 +81,8 @@ #ifndef FF_API_MPEGVIDEO_OPTS #define FF_API_MPEGVIDEO_OPTS (LIBAVCODEC_VERSION_MAJOR < 60) #endif +#ifndef FF_API_PACKET_TIMEBASE +#define FF_API_PACKET_TIMEBASE (LIBAVCODEC_VERSION_MAJOR < 60) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavformat/mux.c b/libavformat/mux.c index 6ba1306f2b..6e9b2e7538 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1293,7 +1293,11 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, { int64_t pts = pkt->pts, dts = pkt->dts, duration = pkt->duration; int stream_index = pkt->stream_index; +#if FF_API_PACKET_TIMEBASE +FF_DISABLE_DEPRECATION_WARNINGS AVRational time_base = pkt->time_base; +FF_ENABLE_DEPRECATION_WARNINGS +#endif int ret; pkt->stream_index = dst_stream; @@ -1311,7 +1315,11 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, pkt->dts = dts; pkt->duration = duration; pkt->stream_index = stream_index; +#if FF_API_PACKET_TIMEBASE +FF_DISABLE_DEPRECATION_WARNINGS pkt->time_base = time_base; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } else ret = av_interleaved_write_frame(dst, pkt);