From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 45F084CCF1
	for <ffmpegdev@gitmailbox.com>; Sun, 13 Apr 2025 15:57:11 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DB97F687CAF;
	Sun, 13 Apr 2025 18:57:06 +0300 (EEST)
Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com
 [209.85.215.177])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1FBEE687C6B
 for <ffmpeg-devel@ffmpeg.org>; Sun, 13 Apr 2025 18:57:01 +0300 (EEST)
Received: by mail-pg1-f177.google.com with SMTP id
 41be03b00d2f7-b074d908e56so422103a12.2
 for <ffmpeg-devel@ffmpeg.org>; Sun, 13 Apr 2025 08:57:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1744559818; x=1745164618; darn=ffmpeg.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=867PxtWBCnEIA4MwIHvVbSof5LCGXUKkutci3ZdVyyY=;
 b=BSMfEyOI3huPdewJzQlkYGx7ePociqTNK4sEqI5+9AXpEC86DUYx4PuxIjFdXUP0Z2
 moCx/moaXyPwpuaL6razxSm3MtA0bmkWstZIQ5guPHACawKToLDfo1huDsVO0rh4EKef
 VlM59v/yX5NBNv81I9rVl8XJ25OwF7N+K5cdYOCVHaEiD6bL3XFFTl22++5CuU9J7HEe
 lKarD3z6SrboVL1L7VGIPcp1keDEDArRYu6yhfW2109raPPfF43bxH/oZW1eH3MruUDm
 BZqRaxeoCWkqSRAblQdoOpT6Quv65WfFIDMQaCZKE+HD5ipe13VCFmviAqxgDAy9vdtx
 0+YQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1744559818; x=1745164618;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=867PxtWBCnEIA4MwIHvVbSof5LCGXUKkutci3ZdVyyY=;
 b=P/NYrDElMiwjbOop6gcueJYEr1WwYTWEITqSNpEmg0aATyEIupett0RRMLYbMJiHCi
 vRi2RSLV4GY9aw7qsegtB6eoogqE6qRNJrOYIzClu+93wML/dm2uolNzKPXITrfS2J1k
 yYvEvvhsvIg/9iljPcqfx7OJTIokwaiOV+FXawjiKVZ5uliAXUFrfKdw9rIxkctdnsh8
 fqVfSfwbKfmbpQY8nTvur51gFKOcjC+2MLVDkLy57zI8puG9JMzz+AwMiVyA1ZAMqD5r
 fUeK5JwG0l8mBnvpoMwayrpDS88yWinPGqNoXTsOerUCwaFe6Tfj25lcVL3TSOAvgfrr
 Fxlw==
X-Gm-Message-State: AOJu0Yz9lWZWgiOc222iReeF8HMeK9Lqv+mgaoh1A1qXcpD/YGymGG3m
 z1ufsC3IhXJLtj1dwhb7XkeG3KeysZmclE6ymtJmwbxoWb4kMf2JIC8WVhmT
X-Gm-Gg: ASbGncs/0zoU76PrlLca0+ORwt+HYknxQZ2yPNvueF4Xf/VGvQ7RaCEEMMdNN2Be2MQ
 rkTgY8j2wFMVfJnVCK53j9OpAy3qHixtawvRDhAX56AhgR7LZ+HGicZ/JzKNx23TSTDvk1Ac8C3
 4HGU5kjvpg/t6qhByMvMCJazadWME7KJZG/nuXTSH/NzrfwOVSrcTQg9aVUBiF0HpPRpPDW4JY4
 aHYPLvAhNQs+K9RBSIFBDHN8eOPLmcnNraUbsQB+5BiIuzpwVLuEAIJwN84kceFLWkdvSqmYbRS
 aise0otI8kO+hR59ivp7wuW5JirKqoyU6Dn2ix+xX0Vfu0mOC8Jz3tl5tiVgcw6hezcfrU9mFI9
 JpKkV4lnN7JedkPE=
X-Google-Smtp-Source: AGHT+IGJFb8Dw9sHb3qX4yq/f5fe2pMQaeUVBn0TGj9FSc+C55cJl2xcPba/IM2XcKdMQINaHAbHBQ==
X-Received: by 2002:a17:90b:4d0c:b0:2f7:4cce:ae37 with SMTP id
 98e67ed59e1d1-30823642aa0mr15797978a91.18.1744559818408; 
 Sun, 13 Apr 2025 08:56:58 -0700 (PDT)
Received: from DESKTOP-5E1KVU4.localdomain (212.50.247.90.16clouds.com.
 [212.50.247.90]) by smtp.gmail.com with ESMTPSA id
 98e67ed59e1d1-306dd12b622sm9627082a91.21.2025.04.13.08.56.56
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 13 Apr 2025 08:56:58 -0700 (PDT)
From: Parallelc <realparallelc@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Date: Sun, 13 Apr 2025 23:56:45 +0800
Message-ID: <20250413155645.805210-1-realparallelc@gmail.com>
X-Mailer: git-send-email 2.43.0
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH] avformat/rtpdec_av1: Fix fragment
 continuation check when OBU_HAS_SIZE_FIELD is set
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Parallelc <realparallelc@gmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250413155645.805210-1-realparallelc@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

When OBU_HAS_SIZE_FIELD is set in the OBU header, frag_obu_size remains 0.
The code used !frag_obu_size to check for unexpected fragment continuation,
which resulted in incorrect drops. Introduce expect_frag_cont to explicitly
track continuation expectation.

Signed-off-by: Parallelc <realparallelc@gmail.com>
---
 libavformat/rtpdec_av1.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtpdec_av1.c b/libavformat/rtpdec_av1.c
index 7cfc83b03c..87f8cd2b0b 100644
--- a/libavformat/rtpdec_av1.c
+++ b/libavformat/rtpdec_av1.c
@@ -53,6 +53,7 @@ struct PayloadContext {
     unsigned int frag_pkt_leb_pos;  ///< offset in buffer where OBU LEB starts
     unsigned int frag_lebs_res;     ///< number of bytes reserved for LEB
     unsigned int frag_header_size;  ///< size of OBU header (1 or 2)
+    int expect_frag_cont;           ///< expect fragment continuation in packet
     int needs_td;                   ///< indicates that a TD should be output
     int drop_fragment;              ///< drop all fragments until next frame
     int keyframe_seen;              ///< keyframe was seen
@@ -165,7 +166,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                    seq, expected_seq);
             goto drop_fragment;
         }
-        if (!pkt->size || !data->frag_obu_size) {
+        if (!pkt->size || !data->expect_frag_cont) {
             av_log(ctx, AV_LOG_WARNING, "Unexpected fragment continuation in AV1 RTP packet\n");
             goto drop_fragment; // avoid repeated output for the same fragment
         }
@@ -187,9 +188,11 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             av_log(ctx, AV_LOG_TRACE, "Timestamp changed to %u (or first pkt %d), forcing TD\n", *timestamp, is_first_pkt);
             data->needs_td = 1;
             data->frag_obu_size = 0; // new temporal unit might have been caused by dropped packets
+            data->expect_frag_cont = 0;
         }
-        if (data->frag_obu_size) {
+        if (data->expect_frag_cont) {
             data->frag_obu_size = 0; // make sure we recover
+            data->expect_frag_cont = 0;
             av_log(ctx, AV_LOG_ERROR, "Missing fragment continuation in AV1 RTP packet\n");
             return AVERROR_INVALIDDATA;
         }
@@ -362,6 +365,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             write_leb(lebptr, final_obu_size);
 
             data->frag_obu_size = 0; // signal end of fragment
+            data->expect_frag_cont = 0;
         } else if (is_last_fragmented && !rem_pkt_size) {
             // add to total OBU size, so we can fix that in OBU header
             // (but only if the OBU size was missing!)
@@ -370,6 +374,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
             }
             // fragment not yet finished!
             result = -1;
+            data->expect_frag_cont = 1;
         }
         is_frag_cont = 0;
 
@@ -391,6 +396,7 @@ static int av1_handle_packet(AVFormatContext *ctx, PayloadContext *data,
     if (!is_last_fragmented) {
         data->frag_obu_size = 0;
         data->frag_pkt_leb_pos = 0;
+        data->expect_frag_cont = 0;
     }
 
 #ifdef RTPDEC_AV1_VERBOSE_TRACE
@@ -409,6 +415,7 @@ drop_fragment:
     data->keyframe_seen = 0;
     data->drop_fragment = 1;
     data->frag_obu_size = 0;
+    data->expect_frag_cont = 0;
     data->needs_td = 1;
     if (pkt->size) {
         av_log(ctx, AV_LOG_TRACE, "Dumping current AV1 frame packet\n");
-- 
2.43.0

_______________________________________________
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".