From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0A40740AA5 for ; Thu, 3 Feb 2022 18:47:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB08468B1C8; Thu, 3 Feb 2022 20:45:48 +0200 (EET) Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6692D68B0E8 for ; Thu, 3 Feb 2022 20:45:41 +0200 (EET) Received: by mail-qt1-f174.google.com with SMTP id t17so3510715qto.1 for ; Thu, 03 Feb 2022 10:45:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CR1zchsa7/BjNQLbxFWEssO6XwGjFIjV+gfba2f/KMM=; b=O+GGtpN2Ax9pRTCDVWnwUOW1gdSKYuWpoW0quPZsEJMyzYs0zdN/mjPUDIM4MxfKXj eOwUmr/CLJTA2WpidN7QnIhbxf5hTnMxSDcHSCzZkKAXxluRr+qa3VIK75Quh74HTFgo oItLtD7FThmgistAW4vV7vx+2ljI4LtqW3pi0euThD3cq4xcfR1d9uuNDs59OAGPF3xp LUg/ySTv9t1jsQ+QAlxlYfTo/KioI9hLmsyNLF9RVakmClOP/qXVlw4QQwtCmyj7F1gV n4iEpvQ86RWmpoVLG8sSBLVO6UuCgK10xvJlyIKdR/ywlzQtSM01WkT3cVaZDFf60lo+ Ehmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CR1zchsa7/BjNQLbxFWEssO6XwGjFIjV+gfba2f/KMM=; b=bWG+nGveLwf90zioD97lIQX+mEbNa/UdnqFL5uH8Ow3iwd5m7sP3l4Tr2W+yDzrlxG bjk+/+gk4tHCwqhZD+h0ALH3anwfCc/SPa/Dh5k77bAPONqUquBXoHZQxyCyFxO8b8e+ /JPLfmnkfjrvoz4ZaDV0vnd3tb3wZ4HoR7BUHFIHjEIi9kjl+bgklip2APwm63BxyDXM I25vQxIRGmFF4i4hBAx6t3ljpkcPGIVRY0jJl7H5Ro6hYf6TKnRRyp+lGmK3v0AM+J9z R/hy8Nv4KKE05irKQWCS592d3OQG9WLfCzs81UVxG6V9v5fIR/dClp9gV6/64nY+vWMI uxLA== X-Gm-Message-State: AOAM533tiTkz60zgZozWo1SHeaPDRb/uN07Tkp0DSFlV9QQhBW2ieON6 8rubY/+6h7dyQ/vb5MU4J8N9UA3oksLHYw== X-Google-Smtp-Source: ABdhPJzILpnl9SYmcuRKKUk+dYoO5zzkcVYXrzin/0+X7Hm4cqTGiJ/gKarhYLUTKc1VgKI/XQaqKw== X-Received: by 2002:ac8:7457:: with SMTP id h23mr27516043qtr.528.1643913940017; Thu, 03 Feb 2022 10:45:40 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:39 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:50 -0500 Message-Id: <20220203184450.5491-14-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220203184450.5491-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220203184450.5491-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 13/13] cbs_mpeg2.c: improve readability of start code search (part 3) 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 Cc: Scott Theisen 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: Separate from part 2 for a clearer diff. Now the true loop condition has been revealed: start < buf_end Clarify loop by moving the detection of sequence_end_codes out of the loop. See also commit fd93d5efe64206d5f1bce8c702602353444c0c1a regarding sequence_end_codes --- libavcodec/cbs_mpeg2.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index bf95fb7546..53aa0ed3f6 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -149,7 +149,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamUnitType unit_type; uint32_t start_code = -1; size_t unit_size; - int err, final = 0; + int err; int i = -1; // offset for pre-increment start = avpriv_find_start_code(start, buf_end, &start_code, 1); @@ -161,16 +161,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, do { unit_type = start_code & 0xff; - if (start == buf_end) { - // The last four bytes form a start code which constitutes - // a unit of its own. In this situation avpriv_find_start_code - // won't modify start_code at all so modify start_code so that - // the next unit will be treated as the last unit. - start_code = 0; - } - else { - end = avpriv_find_start_code(start, buf_end, &start_code, 1); - } + end = avpriv_find_start_code(start, buf_end, &start_code, 1); start--; // decrement so start points to the byte containing the start_code_identifier // (may be the last byte of fragment->data); end points to the byte @@ -182,8 +173,8 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, unit_size = (end - 4) - start; } else { // We didn't find a start code, so this is the final unit. + // There is no start code to remove from end, hence not (end - 4). unit_size = end - start; - final = 1; } err = ff_cbs_insert_unit_data(frag, ++i, unit_type, @@ -193,7 +184,21 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, return err; start = end; - } while (!final); + } while (start < buf_end); + + if (avpriv_start_code_is_valid(start_code)) { + // The last four bytes form a start code which constitutes + // a unit of its own, with size 1. + + start--; // since start == buf_end because of the loop condition, + // decrement so start points to the byte containing the start_code_identifier + err = ff_cbs_insert_unit_data(frag, ++i, start_code & 0xFF, + (uint8_t*)start /* cast away the const to match parameter type */, + 1, frag->data_ref); + if (err < 0) { + return err; + } + } return 0; } -- 2.32.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".