From patchwork Thu Feb 3 18:44:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34107 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741753iov; Thu, 3 Feb 2022 10:47:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHAFBk+4VY5m+Dy5XgThhIzZemxpeJg1neKRaanCM7XMooLYWEQU754AIB9XnFlKUYoLRc X-Received: by 2002:a50:eb46:: with SMTP id z6mr36260409edp.229.1643914025636; Thu, 03 Feb 2022 10:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914025; cv=none; d=google.com; s=arc-20160816; b=Qd97X7G2/f6mlCQ8xALxXTJZbD8C4WcpJiqiqt7Z4C/W7SrZymzDvsx+6Jv48rDz21 Az4xMtF+dSul7rtnEBsMGwzhfPhfAN0+q5qXjk+MUAW2C43nSEyeoEY/6TsW3S4AJ/Pp aR/S4v17or3W9/9z6KM3gQCh38RvQRQ9SJP3LZjD4a6uZi4HkpfPHDbhIsSVSzzFgUZh Eu2co7MqFwsWDNu/KBUzSNB306Y+XlgKXqcynsSX6QsIw78+8tjprfxn2rEr1BZOsCnh 2V0S2Odr9rJybdUp236pXinRWaLROdSfu9P7I/VFys8zaFCim9D6DjidZm5kxs+59G5C 0maw== 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=GVt1HtpQXGu+ejPZO4kAOxk56MpA0lzcVUpQKb5cyU4=; b=hPZpa1x44uhupQm32ONwo9/sL7HjGAC4a2Cd53EWD+rZ4BILf3Zu1qQX3WZSbrbKtY srYDnPw6O7J+nBQsd5xVjLSg1ZuLBZOOu7r17RDjUKJkF5cq4WgglZzDFTzFHZFAMNEp Il5pMLtNjpMerU02YJmq/NUTfA5w+PDLcQoZ6axkQs8WYq788oOEMt/klDxfja7B3pmx UfAq0ui8/jS2LBqCOS89iYgbEbhntdcEEQS4hKm9W966sB3OCjMIfZSYv0irIcOwOsmy B2Beptf4oYwLKoENLzeH2WnLziGa0W3Vvgu1j7Ov/3F23+a2RVq4Qa6+q+DdbJExurrt zS7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=JJpbatqx; 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 ds4si13684366ejc.828.2022.02.03.10.47.05; Thu, 03 Feb 2022 10:47:05 -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=JJpbatqx; 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 E204668B1B8; Thu, 3 Feb 2022 20:45:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1317C68B167 for ; Thu, 3 Feb 2022 20:45:39 +0200 (EET) Received: by mail-qk1-f177.google.com with SMTP id 200so2812442qki.2 for ; Thu, 03 Feb 2022 10:45:39 -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=q2P9k1DB7hIUUGK0URLx7nAfY6Ik2vkcHFdj9MmuvMA=; b=JJpbatqxg4FXXGwP+0OSGtGDm/upPx3NzktGi8SxOicENccfKat7skPimn1XWei5RT JzDWwfENa1SSo3hNbQJ2ThPhrjo67jDMvmYha3KJXGt+cV7ZluusXwMjnhXvPqg5QsLn +LSnjp8o5VWWvHddmjGYCho35GEpEzOGBfr2nTWL3OivQG3Gol4/2lTaA7JhBAl4mVjC 5erTdSoKWyBDIKMQqm8Pd29ReuCmDAn317lmQIWKhTWYDuF8CaSMn/q4ln7g8jGzse93 oETWpixzayvOcYJzu0B11EJbobGrCUc2Ivlx+LR7iCYHC5z8PGDhea88BfLGvIAS0YfW p4oA== 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=q2P9k1DB7hIUUGK0URLx7nAfY6Ik2vkcHFdj9MmuvMA=; b=R2aPNgHYLuoLuwmabT4a+Y4WCCCs2tJ5l5SVxHNjP4xkeyV1gaCUpVtzPOKr7xuNAb 1u0i0ZiPLqXzSSvlRkxQvmsaiz34qOWB+6723TG7pW3DAJbhj164h22uQwnxyXbYLGyu CeYoyR98naFvbO0gP4hgZUEIpXnivosSNogVu740i8bGihm75DoaExseTHzpKDmWBLlh ZhEwYRCHVsj2nfc5A6kN2UBCXZt9eEHiDikJzddKKQOIj7J0NGRxYasY4uVG3VOJ/U41 gIvBPnzLoASC5onEe5+9eM3mCDBn+XlCl9Uzbv6YZJ8nXFVhwi5l3CgBhd874239k+ay VqDw== X-Gm-Message-State: AOAM532CS5HYQfGzQX5RP6SlNB0m2yk652bvhBqXsRYahS4yyoQaAD0F 21ijZQy+CEo71M55/RJpH24zHUuKI36IYg== X-Received: by 2002:a05:620a:75b:: with SMTP id i27mr4519171qki.593.1643913938220; Thu, 03 Feb 2022 10:45:38 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:37 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:48 -0500 Message-Id: <20220203184450.5491-12-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 11/13] cbs_mpeg2.c: improve readability of start code search (part 1) 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: NojGDeVste6k ff_cbs_insert_unit_data() does not modify the data or data_size fields of the CodedBitstreamFragment. It also does not modify the value pointed to by start. (We don't need that byte in this function anymore, anyway.) --- libavcodec/cbs_mpeg2.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index afe78eef9a..f2efedde5d 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -144,23 +144,24 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header) { - const uint8_t *start, *end; + const uint8_t *start = frag->data, *end; + const uint8_t * const buf_end = frag->data + frag->data_size; CodedBitstreamUnitType unit_type; uint32_t start_code = -1; size_t unit_size; - int err, i = 0, final = 0; + int err, final = 0; + int i = -1; // offset for pre-increment - start = avpriv_find_start_code(frag->data, frag->data + frag->data_size, - &start_code, 1); + start = avpriv_find_start_code(start, buf_end, &start_code, 1); if (!avpriv_start_code_is_valid(start_code)) { // No start code found. return AVERROR_INVALIDDATA; } - while (!final) { + do { unit_type = start_code & 0xff; - if (start == frag->data + frag->data_size) { + 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 @@ -168,10 +169,9 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, start_code = 0; } - end = avpriv_find_start_code(start--, frag->data + frag->data_size, - &start_code, 0); - - // start points to the byte containing the start_code_identifier + end = avpriv_find_start_code(start, buf_end, &start_code, 0); + 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 // following the byte containing the start code identifier (or to // the end of fragment->data). @@ -185,14 +185,14 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, final = 1; } - err = ff_cbs_insert_unit_data(frag, i, unit_type, (uint8_t*)start, + err = ff_cbs_insert_unit_data(frag, ++i, unit_type, + (uint8_t*)start /* cast away the const to match parameter type */, unit_size, frag->data_ref); if (err < 0) return err; start = end; - i++; - } + } while (!final); return 0; }