From patchwork Thu Feb 3 18:44:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2742009iov; Thu, 3 Feb 2022 10:47:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxACV7P3h4dFgFtm+c4BHnI60PrgRdk4J/2yP+DpfQPWcJGmalCy6pWe7D2xRRKhvNWeR76 X-Received: by 2002:a17:907:3e8b:: with SMTP id hs11mr30579061ejc.757.1643914052340; Thu, 03 Feb 2022 10:47:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914052; cv=none; d=google.com; s=arc-20160816; b=oWjnSa+ohXRcoCsHym/CbX5bnDVtfyEWHJxnz4rU8mDfOxVfuzKFtPMX/2RWWW08U7 ZjWy+j1f3AbyALT8apTxBKi/Ctvxa9BSaCljTHKjFAnFG07L0M/kDiXq+lkAWzkCxD2d MAdMpdX37dLb58unjKY9sxTwXgBT9ahs+PfDQDI/SWmtqlJ4aUk+WeUk+ADRmbgFKIu8 QP/CCShnA8RtESYx7X+vwYSNAcKdoRgFDTOlaY1FQTNRmkO4SaHBM7TNTUNTP4OcKbYc kAdKlu6qP3xyBozh232AnKJ8PUZE66g4WzRWr6JUBDlgwDD1jx3qnVsR08dE/9qzgKQx 3OxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=GRWBKItgzL4hcYOHgsg2ROrtekyxv+85E+LbY+t+3es=; b=LFQRFK/+BmzE4rwHeB+i7W2ie9oH0ifNMLrFf0TWooUOZwye/qsE/2yuf7BV9PLG6X Ye2PFoNzW9PQGaU9gmQ1yhH65ahRPvsS4CKma0eOujKInGfqcNvdb2ruco7wQX3A832j c2rU9q09zmjWdA1fWGLUb3X81JD4bf4DnqbJYfyzbjhU4tgMYVS7GfeONQ1fqPHJ6bxg RzT08D3QnlXSA+kfkrRLYjSIFLGVMfMMWhCa0O1eE7Wi3lulfEST9XFt63NH+yT0QqRq KiBXLprELETh+oudWYHrKQVS3Iyl3YYng4y5+Uf9sRyFcCV9r1Q21m4NZa4kKAoom57V Xtog== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=O+GGtpN2; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j13si14897550edw.594.2022.02.03.10.47.31; Thu, 03 Feb 2022 10:47:32 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=O+GGtpN2; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DEA5A68B1CA; Thu, 3 Feb 2022 20:45:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FcdoOi2eptjq 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; }