From patchwork Thu Feb 3 18:44:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34101 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741041iov; Thu, 3 Feb 2022 10:45:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHl+pvgQtmhLgHdMkZUDyWbsdmZTb54WIIpBoGIqvcI0/RMzFcaWUBtQoE6kxjJ9KdrZXW X-Received: by 2002:a17:906:1e0e:: with SMTP id g14mr30918785ejj.363.1643913953918; Thu, 03 Feb 2022 10:45:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643913953; cv=none; d=google.com; s=arc-20160816; b=LBvz+QRfMauC188+tcSF3JGfFYh8dYlAs/AjoLIVj2uOGPsp0airImX0HLxntbszEa 0Z4Dwh6qiB176EGrKB5vOr+WxwOclOn8RZBBXze6g/7vzzf+twsV8+gkHOp2nymR+PUU IsSPiwI1pTrPABMc2ozT25Q9fZKhTAmgbhjsZFA76Pb8y6gZ+hv63PHPG8ZyoJHdvbOx oH2BFk8RRfi0rfecxaghhVKPgVsJTQECjipLV3Yufn9r3c6T/xPNLVOH1hkxjgFoK1tu vRH1+HgeL7aIfcT4wXiYHsrQOr4ZhQUMbX+kN2CUH3aO485qw/6p+iyULh0eJdT0+1gd VgIg== 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=jC0rfvHBE50NJsZNU+IhgFMtKiJBjJssSf4nwcrMjg8=; b=RF9tansknyJUN9aHAGGe9mshnjNpbzoMqzzfYQC2SR17P0mFVVihlM9FCYu6vmdOcq DCYK5UiJRxjdb2ZS1DqhlqselGOgPWoyDeHKYETTEAnhLHMKuGQFhcsNufV+Fr3Z4Csu k/hKkQsUb7KwHMARJkLKLoe5L50sLujT4FR1cs+DmIosBFN4bpA4/18q3MG6aMUPJ4Zm xDwjGpxvLmoKNRUIGXqBUrsuFuqwktwO7MidZukATwmV+zunEKHs7CrpYdLO087oW2Oi 63s3NMheSpxSUfqQmQ+ilN6LOP7Ul5ZhUqmqB17qA/AUHDkbSnJ/W9AnDh1cvIcROaFQ KXag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="FHXyvQ/c"; 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 g6si12914924eds.557.2022.02.03.10.45.53; Thu, 03 Feb 2022 10:45:53 -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="FHXyvQ/c"; 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 ABF3968B148; Thu, 3 Feb 2022 20:45:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5EC5968A9FC for ; Thu, 3 Feb 2022 20:45:31 +0200 (EET) Received: by mail-qk1-f176.google.com with SMTP id b35so2793606qkp.6 for ; Thu, 03 Feb 2022 10:45:31 -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=Jh+6luRY9/AhiPFra+YZXuXASuAOLC5d0IGITN4MDdY=; b=FHXyvQ/ciVczhgEMXKuiUDfaoPk9D493jyf8b3C8/n8O3JOKXzrFagTPu3brZyZNd/ OD94yYLwqfGfqbYDxQhryY6nVFCb+4ZKxxkGaWNdyqL9qgqi14yz0IbNDJcvD7ar7g1Q 33uwdLya6Zopsf43O5MQlQSp5ivkf2CmXB7w/c4ZR9yphMda7Bgug8XEpc+Q/FW64Eq7 abw9NKjeRIUgrouKuqmIrWhlSuR1lp8qQeCQ9kPZZ08kwlC6jjMsyOin5nIGKAL4B/Ld xHOFsgORWX4IvoHt67dpRrEMtg+icTbvwkgvodKKTmBQoCkVULGsWguSvBnQqO9paN7F VuAg== 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=Jh+6luRY9/AhiPFra+YZXuXASuAOLC5d0IGITN4MDdY=; b=h/iElYoLUue/E7AZCRwJ5uwzn3FvgboyUHL7dRTLxDsVEnR4yo0mV+3uXjNqzmUeT9 qnlP0qF1AXDoSM4m6341UhZqbBYhnEQp9OXFYhtmQfXJCoZqnKO/SW+8uTt+h8DnchTw ng+Vq5XLJIYNY9PkoOMQns30/QBaaA94Vb8vBXNCwoKzpQn+4O9KJYCpNaC9a+B9h117 h335rVzIXdbxGukXmOXmByPMpIVJkpDqlk19fifhhiO/8ovmBF9PO5M83XF8yf7LZlQH Oim28zg8xzF+sEVnMbsQcxcMpB4FeUVN4Eipv/4D0wz5Q3rROGrtn0a/nq7CCqGILLro eIWA== X-Gm-Message-State: AOAM5329EenfVDVhIC3M+dZFK6hxx/F6jmMkPtaqNt8WwBFkmRZpu+7l OcxeFje+oFTMFnUQqU4+bQor7Jn4u0Xa+g== X-Received: by 2002:a05:620a:2450:: with SMTP id h16mr24667738qkn.429.1643913929658; Thu, 03 Feb 2022 10:45:29 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:29 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:38 -0500 Message-Id: <20220203184450.5491-2-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 01/13] avcodec/internal.h: create avpriv_start_code_is_valid() 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: GGNmKECw9oih --- libavcodec/cavsdec.c | 2 +- libavcodec/cbs_mpeg2.c | 4 ++-- libavcodec/extract_extradata_bsf.c | 2 +- libavcodec/internal.h | 15 +++++++++++++++ libavcodec/mpeg12.c | 2 +- libavcodec/mpeg12dec.c | 2 +- libavcodec/mpegvideo_parser.c | 2 +- libavcodec/remove_extradata_bsf.c | 8 +++----- libavcodec/vaapi_vc1.c | 2 +- libavcodec/vc1_common.h | 4 +--- libavcodec/vc1dec.c | 2 +- libavformat/avs2dec.c | 4 ++-- libavformat/avs3dec.c | 4 ++-- libavformat/cavsvideodec.c | 2 +- libavformat/mpegvideodec.c | 2 +- libavformat/rtpenc_mpv.c | 2 +- 16 files changed, 35 insertions(+), 24 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 692c77eb39..a62177d520 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -1249,7 +1249,7 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, buf_end = buf + buf_size; for(;;) { buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc); - if ((stc & 0xFFFFFE00) || buf_ptr == buf_end) { + if (!avpriv_start_code_is_valid(stc) || buf_ptr == buf_end) { if (!h->stc) av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n"); return FFMAX(0, buf_ptr - buf); diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 26400f279f..eb45929132 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -152,7 +152,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, start = avpriv_find_start_code(frag->data, frag->data + frag->data_size, &start_code); - if (start_code >> 8 != 0x000001) { + if (!avpriv_start_code_is_valid(start_code)) { // No start code found. return AVERROR_INVALIDDATA; } @@ -175,7 +175,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, // (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). - if (start_code >> 8 == 0x000001) { + if (avpriv_start_code_is_valid(start_code)) { // Unit runs from start to the beginning of the start code // pointed to by end (including any padding zeroes). unit_size = (end - 4) - start; diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index dbcb8508b0..4df1c97139 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -240,7 +240,7 @@ static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, ptr = avpriv_find_start_code(ptr, end, &state); if (state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT) { has_extradata = 1; - } else if (has_extradata && IS_MARKER(state)) { + } else if (has_extradata && avpriv_start_code_is_valid(state)) { extradata_size = ptr - 4 - pkt->data; break; } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 72ca1553f6..005f308b70 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -285,6 +285,21 @@ int ff_thread_can_start_frame(AVCodecContext *avctx); int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); +/** + * @brief Test whether a start code found by avpriv_find_start_code() is valid. + * + * Use this to test the validity of a start code especially if a start code can + * be at the end of the buffer, where testing the return value of avpriv_find_start_code() + * would incorrectly imply that the start code is invalid (since the returned value + * equals @c end ). + * + * @param[in] start_code The start code to test. + * @return A boolean that is true if and only if @p start_code is valid + */ +static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) { + return (start_code & 0xFFFFFF00) == 0x100; +} + const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 58e03c05d4..e45bc74479 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -217,7 +217,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, pc->frame_start_found = 0; if (pc->frame_start_found < 4 && state == EXT_START_CODE) pc->frame_start_found++; - if (pc->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) { + if (pc->frame_start_found == 4 && avpriv_start_code_is_valid(state)) { if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) { pc->frame_start_found = 0; pc->state = -1; diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 4a7bd6d466..65b66d11f8 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2477,7 +2477,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, /* find next start code */ uint32_t start_code = -1; buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &start_code); - if (start_code > 0x1ff) { + if (!avpriv_start_code_is_valid(start_code)) { if (!skip_frame) { if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) && diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index c5dc867d24..f0897e7e2c 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -82,7 +82,7 @@ static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, pc->frame_start_found = 0; if (pc->frame_start_found < 4 && state == EXT_START_CODE) pc->frame_start_found++; - if (pc->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) { + if (pc->frame_start_found == 4 && avpriv_start_code_is_valid(state)) { if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) { pc->frame_start_found = 0; pc->state = -1; diff --git a/libavcodec/remove_extradata_bsf.c b/libavcodec/remove_extradata_bsf.c index 1d5f193f89..0e42174912 100644 --- a/libavcodec/remove_extradata_bsf.c +++ b/libavcodec/remove_extradata_bsf.c @@ -35,8 +35,6 @@ enum RemoveFreq { REMOVE_FREQ_NONKEYFRAME, }; -#define START_CODE 0x000001 - typedef struct RemoveExtradataContext { const AVClass *class; int freq; @@ -73,7 +71,7 @@ static int h264_split(const uint8_t *buf, int buf_size) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &state); - if ((state & 0xFFFFFF00) != 0x100) + if (!avpriv_start_code_is_valid(state)) break; nalu_type = state & 0x1F; if (nalu_type == H264_NAL_SPS) { @@ -111,7 +109,7 @@ static int hevc_split(const uint8_t *buf, int buf_size) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &state); - if ((state >> 8) != START_CODE) + if (!avpriv_start_code_is_valid(state)) break; nut = (state >> 1) & 0x3F; if (nut == HEVC_NAL_VPS) @@ -171,7 +169,7 @@ static int vc1_split(const uint8_t *buf, int buf_size) ptr = avpriv_find_start_code(ptr, end, &state); if (state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT) { charged = 1; - } else if (charged && IS_MARKER(state)) + } else if (charged && avpriv_start_code_is_valid(state)) return ptr - 4 - buf; } diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c index 4e9607d9be..379104f688 100644 --- a/libavcodec/vaapi_vc1.c +++ b/libavcodec/vaapi_vc1.c @@ -471,7 +471,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, int err; /* Current bit buffer is beyond any marker for VC-1, so skip it */ - if (avctx->codec_id == AV_CODEC_ID_VC1 && IS_MARKER(AV_RB32(buffer))) { + if (avctx->codec_id == AV_CODEC_ID_VC1 && avpriv_start_code_is_valid(AV_RB32(buffer))) { buffer += 4; size -= 4; } diff --git a/libavcodec/vc1_common.h b/libavcodec/vc1_common.h index b46c33f7e2..483f86a4ee 100644 --- a/libavcodec/vc1_common.h +++ b/libavcodec/vc1_common.h @@ -41,8 +41,6 @@ enum VC1Code { }; //@} -#define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0) - /** Available Profiles */ //@{ enum Profile { @@ -61,7 +59,7 @@ static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, cons if (end - src >= 4) { uint32_t mrk = 0xFFFFFFFF; src = avpriv_find_start_code(src, end, &mrk); - if (IS_MARKER(mrk)) + if (avpriv_start_code_is_valid(mrk)) return src - 4; } return end; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 7ed5133cfa..86749e5973 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -664,7 +664,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, if (!buf2) return AVERROR(ENOMEM); - if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */ + if (avpriv_start_code_is_valid(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */ const uint8_t *start, *end, *next; int size; diff --git a/libavformat/avs2dec.c b/libavformat/avs2dec.c index 51908d2b63..bdeb746fc7 100644 --- a/libavformat/avs2dec.c +++ b/libavformat/avs2dec.c @@ -42,8 +42,8 @@ static int avs2_probe(const AVProbeData *p) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &code); - state = code & 0xFF; - if ((code & 0xffffff00) == 0x100) { + if (avpriv_start_code_is_valid(code)) { + state = code & 0xFF; if (AVS2_ISUNIT(state)) { if (sqb && !hds) { hds = ptr - sqb; diff --git a/libavformat/avs3dec.c b/libavformat/avs3dec.c index 253caa7c1d..2daccd3d15 100644 --- a/libavformat/avs3dec.c +++ b/libavformat/avs3dec.c @@ -36,8 +36,8 @@ static int avs3video_probe(const AVProbeData *p) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &code); - state = code & 0xFF; - if ((code & 0xFFFFFF00) == 0x100) { + if (avpriv_start_code_is_valid(code)) { + state = code & 0xFF; if (state < AVS3_SEQ_START_CODE) { if (code < slice_pos) return 0; diff --git a/libavformat/cavsvideodec.c b/libavformat/cavsvideodec.c index 8900b97597..1d007708cc 100644 --- a/libavformat/cavsvideodec.c +++ b/libavformat/cavsvideodec.c @@ -38,7 +38,7 @@ static int cavsvideo_probe(const AVProbeData *p) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &code); - if ((code & 0xffffff00) == 0x100) { + if (avpriv_start_code_is_valid(code)) { if(code < CAVS_SEQ_START_CODE) { /* slices have to be consecutive */ if(code < slice_pos) diff --git a/libavformat/mpegvideodec.c b/libavformat/mpegvideodec.c index 2d6f81aaa1..a9829dc1df 100644 --- a/libavformat/mpegvideodec.c +++ b/libavformat/mpegvideodec.c @@ -44,7 +44,7 @@ static int mpegvideo_probe(const AVProbeData *p) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &code); - if ((code & 0xffffff00) == 0x100) { + if (avpriv_start_code_is_valid(code)) { switch(code){ case SEQ_START_CODE: if (!(ptr[3 + 1 + 2] & 0x20)) diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index 4b45f51772..05a77fa11c 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -57,7 +57,7 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) while (1) { start_code = -1; r = avpriv_find_start_code(r1, end, &start_code); - if((start_code & 0xFFFFFF00) == 0x100) { + if (avpriv_start_code_is_valid(start_code)) { /* New start code found */ if (start_code == 0x100) { frame_type = (r[1] & 0x38) >> 3; From patchwork Thu Feb 3 18:44:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34102 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741143iov; Thu, 3 Feb 2022 10:46:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsN2mVXLrUSnTXRUGrlYpdkWFHkI2Cd7f8HyeESTtysRjzfyDwiayC+IbCrxzCvFDY3sLp X-Received: by 2002:a05:6402:528a:: with SMTP id en10mr36357020edb.209.1643913964639; Thu, 03 Feb 2022 10:46:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643913964; cv=none; d=google.com; s=arc-20160816; b=yn+82YJZVJVlOPPu78ha0EZJeQ2BPz+tR9UNQaO5Xu6VePXhrzLp+XsOeNZnrYOI9R YdWEjq05rjrKNm/3uq6EInozvc2RhocWyJL2v93Qt7RUOkU+uPffqrlmkOvkGm+Yyv+n gZ86vGpCYpwR4kQnyGYw7K708batJwktu9IIYPuGYcAotUJ/8gDqNSPjxPQB8+LBQU+v v+t+sCXd75W/RrfAX9aF0dq18FPXtya30xYN98lae1GpZ4LimOsQ4CRmpmQuoE2+Kbyi Y7KVAmQgrEeHPAyClWZvTfHUKowe2zEd3Itbb7MLeYKZkMuHtQLWRLBYL9E3SEg+VDDL WCRw== 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=gDFxUlqMl/nlgv0K0EZRbzuLDvMBAwlQCpM0vkdZ1Rg=; b=aeyF0wYSRtWV8bqahnRICIC9jwPn4XryjoMFFuH/jAQdLbxUsXs6xy5K5CbV2rXVTS /CndiYEVTQaZbqk19KlYWNeqrGrt/+58XhqjL4LmUnY0uMwAaFhpDFvTq1WLQYwbw3RA fDZbnffvq8htXWDnbwIzXDLURqqWTrur4uYjs7lJnBDiNSrosgURXnJOw6QKAwqLhp2u t21gYE2pqMH4xbnED59K+TgCroc/olI3j48MvSiCIE1J7WVjk+xuUAJyUM1OoGO2eMcR p0cZOWYNNn6ITBPV7swHqdFWi0R+LxZ7GsiyfYCkABdeitZOsuj3Xs6G05OrpY5M1XkS B1kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Uk57xrwO; 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 n14si15949322edx.94.2022.02.03.10.46.04; Thu, 03 Feb 2022 10:46:04 -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=Uk57xrwO; 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 C5E7968B0E7; Thu, 3 Feb 2022 20:45:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37ABC68B0E7 for ; Thu, 3 Feb 2022 20:45:32 +0200 (EET) Received: by mail-qv1-f49.google.com with SMTP id g13so3372225qvw.4 for ; Thu, 03 Feb 2022 10:45:32 -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=9dy4aYoVFlHLEy5HO7CVsCAQrO5cMvHaBQi63n/yq/0=; b=Uk57xrwOtUrZgnkBn8hWm17OScITVfByyN9E/exL/s4kocg/frYmxnmQS0kMxog1wJ Vr2zIBSEaPDJqcvdB2EcERlnmLzbbB1lZU0Kf6bnqCaPRliYKJoOArJNmOinkGtg9XU+ Bb/hiXuIoJqi2CRkHtBzXR6ixQLLmhq+m7Mm0JR314HdgTAM/hLH1pYKc/8l4efnRPxP f6TDAEQZp87QffZR4EyYxt0LdAXL4beN4M5lU/uOiHALhv9K+0/guUJn1feEqa37gFJI QfBNJ5dmzdFP4wrqd3/827K14zG8wrDCm9F0joQ737Wtrpjlbm2WN7PYPVq2yRENw0mL YO+w== 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=9dy4aYoVFlHLEy5HO7CVsCAQrO5cMvHaBQi63n/yq/0=; b=brMZzNp2rFdXPVHTNThT5JANHSTx70G1jDANq0kxmLs24EmHOqTkozwn4V93oNPl4l fOJFPZw1y4CpAwKe7Lf2C0d8vRfjWtU5Mib8k18uXvXWJmz7WL45YTGAO9hl0+hVS7pR HQ1Opp5+7r/YKSByc1LhcnAVEjA8sE21p8fSnMAb+29Kwj6w6jeIxaMEtxzljO3GX98O +QfJG1U8cRkZ9T/sWEvkjA3St3xtQU6XPYDhqtHlw8j+HaZhY+pC4R0KIXOEqPOCZRqo I78uS3vBzzMDIQ17I5HXXad1ZACKPx2vjLNdcYltNCpiYEvCYNva0jALPQbm2diOrVaS v1mw== X-Gm-Message-State: AOAM530GHzkE8yBdrnA8QR8hkTee4ikfwcJHxlCJCD7llC4zZ4blve1K 1ZQYLeh+ETDOtDOOfGL2j6uik4JOEE9Hpg== X-Received: by 2002:ad4:5ca5:: with SMTP id q5mr31919579qvh.105.1643913930542; Thu, 03 Feb 2022 10:45:30 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:29 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:39 -0500 Message-Id: <20220203184450.5491-3-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 02/13] avpriv_find_start_code(): readability enhancement 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: c5ntrA/4knSg No functional change. --- libavcodec/utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index b19befef21..cb4437edc2 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -967,10 +967,14 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, } } - p = FFMIN(p, end) - 4; - *state = AV_RB32(p); + if (p > end) + p = end; + // this will cause the last 4 bytes before end to be read, + // i.e. no out of bounds memory access occurs - return p + 4; + *state = AV_RB32(p - 4); // read the previous 4 bytes + + return p; } AVCPBProperties *av_cpb_properties_alloc(size_t *size) From patchwork Thu Feb 3 18:44:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34103 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741235iov; Thu, 3 Feb 2022 10:46:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4XoBdPMQtLvDEDM2toseWxuSKgCXP5GF///JJw/w+ZbO+WlC6UBjMmlS6METyopw8ZB7I X-Received: by 2002:a17:907:1c94:: with SMTP id nb20mr30669684ejc.144.1643913975041; Thu, 03 Feb 2022 10:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643913975; cv=none; d=google.com; s=arc-20160816; b=xnUz943pFkg5t26JvX953YMEtNkVVp8sOXiM6BMVZUdYp5A7afW0XjZRXKypunRWyC TXf1a/Xy6I8cd3mDboPFPaRKQ9MU5t5VReNoWCcJzWT+ttMEJYJAsSXhX4irCFNuMDkg wEr44C5V2LJq5AzrNk0u6hCm6Da/cCC0v7eeUyy2y2ZRThEhwn+16XTsx3CIst10CfCs L1c2COqSlEEEbbO0Dh5qLneQbuH1xLRAyTTbSGWL3yXVVZG+56u7EP21vGESJFIHuF+I vu/OYsR8c3cXVfz6IAQ8HJ4VMOWiSENxwri7MLO0eC0w4bTZQ8fOjY/zPUwPJg6VaIKL GhJA== 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=JNJlWV4ddWSffqpp00W67EU+gtTsrz29DSviJxasJlc=; b=SQT3iAjO7xpdTaqV71CAq/93BDUXOBoHJfVeT6mUPJPQrTbOaPNZ3zkTeIfDvGVrSc 8rKLtvONLWhDRTYpkAD7mUJYXChqNQj6Ew3lcMDU513DYD3yHCM8n0w1WsvajH/Us3ML EcR/MPHJyWMHkKPCvFea8vrb9JpWRTqFxF0D1M1qLKJfoSH91qyJl3sUX36iM6CwNoWL NFEaZ7j7AGAhYRA6pCnkwcvJ7eTDKIL3Gm7/dnTB8NbzQv8yolz6T91XDihTvalBE/ZZ EYiUkWKzWvI1ltryGJKpjg06i1rxo1EtzovibZ3fwUg6bEbq57OVOQkL9/TUHVVTcrBC zADA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=JFFjdW6D; 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 en5si12493571edb.335.2022.02.03.10.46.14; Thu, 03 Feb 2022 10:46:15 -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=JFFjdW6D; 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 DD34268B143; Thu, 3 Feb 2022 20:45:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E38C968A9FC for ; Thu, 3 Feb 2022 20:45:32 +0200 (EET) Received: by mail-qv1-f52.google.com with SMTP id e20so3354409qvu.7 for ; Thu, 03 Feb 2022 10:45:32 -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=XIVZ8HK7u2tn2hE58ekTiYEL7VIfeF314J8YecgtM0s=; b=JFFjdW6DVOL4uo8IYsGMBvmNQFr57Sjbjec5UxV9NgJL7AGfSSveEMlct9yA93WmwS 9vL8KnLH8GW25+wfs8/fDZ6hVio6WXhxhAKAfS0Wjanqq+FirwrFo+uzZFYyXX0PRsk2 OJNAOSaX/wE3rfBYKAwnSq3zaeqmHxxUeuFKSY7DrJ8qcVvdHJvHsVyhbuOmclI1YQeq /b7BcBpL/Dknx1hqgk7YtG9mARTPsvoM9Dknno1OyJKjLoF5SXeGmx7KlJrKePBR4zbq 4QenRi0SpmBgIOdVlJxorf0Chnbl57u+6/sC97tQdwCvLZYwSemfr9EvjpKav6rDpOBV PNww== 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=XIVZ8HK7u2tn2hE58ekTiYEL7VIfeF314J8YecgtM0s=; b=Gvmj+bnQUAnBGj+O7LiD8SCbKe8xRjOHB/RFUSLtulx3gIFMLBr3Cmtr+8rG9i960Q YH2Jdt4V6WuMSlCQFoeuBkNJJctC/cnAjRMW338Hqtvn0gWbYBnlcpO40aZf26R24PyY +0Io1ZH7upqM6vjWEYIcPGKOLrejBqWEUbOFEEGBoTnG/9Nfp8OApnHbtf3qSkE41Oo9 jyTo+AX22AUcLobxBILPPSoydsJky/y2csqwaGOvOptGZHzLcUYqmG//q5wJF//zNujL SG/8tdazHvuuhZAwTEJx+o3b8ETsG/zp9zHx0Nh+IGXBNr4q3H5WaMu8g8WvR96TMwJD 49WA== X-Gm-Message-State: AOAM532gQwL3F+C6GzBrSAoLS9HNmLywRupGSm6kIBWbqB5bMg0faR+C FapPSDtpMviQdbW9XPdL4UYWXdbEiuTjKA== X-Received: by 2002:a05:6214:d0c:: with SMTP id 12mr31954388qvh.66.1643913931287; Thu, 03 Feb 2022 10:45:31 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:30 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:40 -0500 Message-Id: <20220203184450.5491-4-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 03/13] avpriv_find_start_code(): rewrite while loop and add comments for clarity 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: 6QmnC4mr2IPz The expected number of iterations may increase by one for an input of alternating 0 and 1 bytes. Instead of incrementing by 2 everytime, it now alternates between incrementing by 1 and by 3. No functional change, but now much clearer. For the check p[-2] != 0: Also reduce the number of iterations by correctly starting with three new bytes on the next iteration, instead of keeping byte p[-3] which is invalid, i.e. known to be 01 when it must be 00. --- libavcodec/utils.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cb4437edc2..8f8cc820bd 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -957,12 +957,26 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, return p; } + /* with memory address increasing left to right, we are looking for (in hexadecimal): + * 00 00 01 XX + * p points at the address which should have the value of XX + */ while (p < end) { - if (p[-1] > 1 ) p += 3; - else if (p[-2] ) p += 2; - else if (p[-3]|(p[-1]-1)) p++; + // UU UU UU + if (p[-1] > 1) p += 3; // start check over with 3 new bytes + else if (p[-1] == 0) p++; // could be in a start code, so check next byte + // this should be one comparison against 1 since p is unsigned, + // i.e. p[-1] == 0 is equivalent to p[-1] < 1 + + // UU UU 01 + else if (p[-2] != 0) p += 3; // we have UU YY 01, so increment by 3 + // to start check over with 3 new bytes + // UU 00 01 + else if (p[-3] != 0) p += 3; // we have YY 00 01, so increment by 3 + // to start check over with 3 new bytes + // 00 00 01 else { - p++; + p++; // p now points at the address following the start code value XX break; } } @@ -972,7 +986,8 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // this will cause the last 4 bytes before end to be read, // i.e. no out of bounds memory access occurs - *state = AV_RB32(p - 4); // read the previous 4 bytes + *state = AV_RB32(p - 4); + // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} return p; } From patchwork Thu Feb 3 18:44:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34104 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741340iov; Thu, 3 Feb 2022 10:46:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzg8kkxvxvK/OPux6FX7PE3N+35y8MoqVxLZ8bXR84wat7usLDoBlcSfESks3/rL37HNcXS X-Received: by 2002:aa7:d949:: with SMTP id l9mr36919343eds.153.1643913986488; Thu, 03 Feb 2022 10:46:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643913986; cv=none; d=google.com; s=arc-20160816; b=qVlqQmX5SlUXupalzcf+lI/tuBywfQgvOQxsHBrUxCgSZjRIxQs9BrmMxjoAVfRt82 JjLBVin+XQzoWmPy3Wt++e1SVWrocO7zQhfNfbW4+Lcxi1cRbmaZR7U92MJiCkcruaKY Ps7Os8bJUgVzCOTDH94qoPJ2t+hem3jMaKRCh1qw6uhl/SN1/u1G6c/Oj2M8vvo/v0wV 5BXZPQqPIb5+e4ElI7nZ9iM5SJVp7Y88WNFaw71xlQZDTMCr1as3m2AkfHWuUerELeLs t3fEaeDMpH+pgI2eD+N0dkcHJeSa3YS5DswrK3XSc+DbnB1Rx8aXxHbjkHN08Re0TfPs buVw== 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=F9Glul8mhQ/TeY6efOU7OLCTLePLqBNxKCACS88+AxU=; b=tFcC/XE4zvFdEmOgI7bwGvsmBsBtL+Rr9OlL9cY8vleOvX7AFRqKFk2+CoSQJfkEHK O/I7zhNLqkVPE83Xq8vjKVHeJxjb/yp39JFfXUOtEsqR0w265BN0KPCZz9Xos8zX5LdS cYyQK/Jxa7PdsUIgNDKpHu9jNfN6O6QbbBQJxplC3rvYD14w/1pxpHedLSFfWKE/WLGE Vc08mybuss48BC03X0GQoHxhi6S8u5hAnBP4bl553yhYkxNlPwVZahPeeb3cBqPJF99Q 8R9Wuy2pFy9AmDnLpxKQqTosN+7AOJ/eFQuiC1DEuEKPonsKA4ekXKc1NQoMF8ytQfxq a+Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=jo3kxc84; 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 go33si14946893ejc.465.2022.02.03.10.46.26; Thu, 03 Feb 2022 10:46:26 -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=jo3kxc84; 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 D7F9B68B18B; Thu, 3 Feb 2022 20:45:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7BCE468B148 for ; Thu, 3 Feb 2022 20:45:33 +0200 (EET) Received: by mail-qv1-f49.google.com with SMTP id s7so712732qvb.0 for ; Thu, 03 Feb 2022 10:45:33 -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=RDVpNu+d/1V4UdxuuE3cqLrUdn5wcMxN8wvetm30qXI=; b=jo3kxc84zPTYUIls0uJU8jIo+ONw8xkumJgZCPqZdNq9mLmkRZnWZndY1lmZITB4Ys i7YgmKWdFUZc0AgMs7ysZ3o0sTjZhvK3dGE+HykYFMxH99XI0zpzJWYWNcXM3EUZxIv4 PDyUAznWiJ8Jxi0cl1IMNHyzNUCEUQ8aM8D31GO83q7ULGueYcOtNw4GC7NeMasEJzzL LENCLkzfaDvmSD563MlMH/HpJe9A/Y+xJhLxknbcoPQ1od3EyGZ2Ev7yav7lcOlaaY6e Psh4Oyv57n6BkSvkg3o3OU0GHUNmMucTUwmWVT22Ag3ChRI2VISUf8UJjRUXZKyoWCYo RooA== 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=RDVpNu+d/1V4UdxuuE3cqLrUdn5wcMxN8wvetm30qXI=; b=7H0M2SgOHAAmOf5QONFHuwn+kV/uBV5IpXjRzXugLVvhk/l9fo8d17yqhk5biKcnfc 13HBRdXkugzkw80e3PtDAGz9kIYgv1qS17lAG2DTcjCCjkFbbf37RLe/S0soC+pWCuJ0 p0ZTcwsLKl7hI2xsrYVg9Dcp/Rtir3Njd84IyJ2PPfvS6XtsK11JcOTX+u6gN6wz83we 5ldC/vpUzevQpCQgkACaISYT9vJ3MAbfR96BmMcPOoGof3GlWFE8ZgQ93TnQmkHY6nic WrmNkWAMcZpQw9xL8IvLcFcGi/+c+cc4sNgCopxXGPUx9rhem3I3IUamRMyuxI7uM6yt 9+Jg== X-Gm-Message-State: AOAM53140nYExzJa8YSPcHKfscJPYKNyaBiYrXzvQUxTRhRT0nFzg71D Y8b9Z/fq2sGg9dUg2WVC6jdtFAqiTy9mhw== X-Received: by 2002:a05:6214:2524:: with SMTP id gg4mr32428191qvb.27.1643913932189; Thu, 03 Feb 2022 10:45:32 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:31 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:41 -0500 Message-Id: <20220203184450.5491-5-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 04/13] avpriv_find_start_code(): rewrite for loop for clarity 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: Rbf4Fa+Vhtg9 --- libavcodec/utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 8f8cc820bd..1a806b9fa8 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -944,18 +944,20 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, uint32_t *av_restrict state) { - int i; - av_assert0(p <= end); if (p >= end) return end; - for (i = 0; i < 3; i++) { - uint32_t tmp = *state << 8; - *state = tmp + *(p++); - if (tmp == 0x100 || p == end) + // read up to the first three bytes in p to enable reading a start code across + // two (to four) buffers + for (int i = 0; i < 3; i++) { + *state <<= 8; + *state += *p; + p++; + if (avpriv_start_code_is_valid(*state) || p == end) return p; } + // p is now properly incremented for the negative indices in the while loop /* with memory address increasing left to right, we are looking for (in hexadecimal): * 00 00 01 XX From patchwork Thu Feb 3 18:44:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34105 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741579iov; Thu, 3 Feb 2022 10:46:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWTigx2BLNnyCrALL4Na9CGTlVGWhWm+Eyx8I/9JRnbiJeD7DKje2pXmvq8kNrYvYYgyrd X-Received: by 2002:a17:906:7956:: with SMTP id l22mr31560924ejo.438.1643914007810; Thu, 03 Feb 2022 10:46:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914007; cv=none; d=google.com; s=arc-20160816; b=cR06pjdAgHHK9WlVGWUYYBiKxd0yz6fs8SPuTk+as2mQ/Pex2+C68LKselv5pNES9l GQyaepKXjeUQfaXMguub76YI9xPeiBehR1dVMJtuj+/tmJCCXnp9U+HnJzuCZE8vfvv2 C+OdgnGAwwzjSBSVMcrl1cfcOcdS4L2bXV+lJCHc8B5BnBF1FFvq28mfKckO3yMPSq/B lrEf0GpG3rVLUey7F1R/R5xHEAloNUSz4hzFTSSgu23S2X9IwMJx8vUKa0yc6HGsvRvM g8E2I6lJLjUmnxbHoldlx1qv0oxTCjUlIjDStdbn7ZCE8Uw5wVjV+pnRPNG4yNX9dZE/ cL4w== 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=HcV1gLmNzQhhBLzJUrIldPTOTnP5ZtHDLfa9TUloE3I=; b=S2YGX9jF4vDpECR79B1vt9pN0YHfeZqXEkSS4angLTJBguJw+pwYaL+dZyZ1fvzJ2v +obt9/+6r90xaTQQv5kY3yhMAIIgaBEKRc4+El9UVUs6II9JIkqw8ZzoOLTY39DJgHAS J6vT9eubM0M5IBHye7m+ATms/8hRtgqWOaVVCe358wA5Oju6H1auIZ/ISFP2ohOiLHsr zG2ZrXY0Jtaobd2xDcaSBh1rniOpbhJEa6f48SaNoBJYTl/iP/MjujMBtWOtzrBrtOaI iuWBPYA8Z/bwC8ruZKZqXy88LbUh+AuaIdkDfw28+/FDmcuT1sJFvnJ3MALn2a9hgiDh CAHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=V6VHrRMa; 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 sd25si13929697ejc.815.2022.02.03.10.46.47; Thu, 03 Feb 2022 10:46:47 -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=V6VHrRMa; 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 D1B1B68B170; Thu, 3 Feb 2022 20:45:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4FF2268B15F for ; Thu, 3 Feb 2022 20:45:34 +0200 (EET) Received: by mail-qv1-f41.google.com with SMTP id g13so3372316qvw.4 for ; Thu, 03 Feb 2022 10:45:34 -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=5I2fol/ah3v7gwWgwk8FAPHZ2qJr6BJBdyD94lpM/wA=; b=V6VHrRMaSrsS+Nkd5iA5Nfsl/3UEvc9GG6UMjfgSFRoAAaXr1BM0U3jF9nNhKqoMiX wal4957sT59jTd1egW0Xtdx2+3aINxoCNfZDbnUH0eRG9VIBvy9nm1lSKOHxZD1AP3uA J4esi/g0V8i8KEIDXfK5lySgwZ+n7W9qY5ieQdkT24DXem7rFW7ckZHpNuBqMvTJGfDR C8luG8euxpPTwfdLqRtPRl7/50cSimIok8WM8dG0+54Az4OA7A33Qo2yIplLP9pWLQtG Yy8Yt3hsonwF2C32nDqiXBibaJH5m1eOSi0KhSzi/zsUXgQRwqc4otxqVYbD4R+o1Yh3 GMfg== 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=5I2fol/ah3v7gwWgwk8FAPHZ2qJr6BJBdyD94lpM/wA=; b=k9ilLYEwWHgILu74h8u2G6U9IA27++ldwfcnKQbatJfkKFwWj7Xd5wRI2c/q6zqzwO nQ8js/Zss3QIyTclrfZO2tERbOWWeAIDaY2NS8zQEIuYJGPGy2Eob/OX6+VwrOZgG3cV YxDiTrAvQp6A7pOOi7TZN4B9dKwkC8YF7EIeHhKIe/UUUggZVh3a7w8ARayRCPS1pp21 5ldyc7CGeqEjVHoW3qOuA1igUYNnxpJVAt77KGaHG5wgQY2Au/IYgk08aOwkXyTJEnmR h5Hr8XueFARYUqoTJM+ujPjb9EOoRCbc88OYPPyrvVC6x0EpM9D4InfMEeXo8uXwwtKq TVUA== X-Gm-Message-State: AOAM532zjl31W9t7weVxOmbAHe8VGgxFp34fSA3GH0C7QxQe06q7TaMD knczHP62LCieD5inMO2Rc35svvVYamhpZw== X-Received: by 2002:a05:6214:2386:: with SMTP id fw6mr31956765qvb.89.1643913932890; Thu, 03 Feb 2022 10:45:32 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:32 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:42 -0500 Message-Id: <20220203184450.5491-6-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 05/13] avpriv_find_start_code(): add doxygen comment and rename a parameter 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: jigfdLUBhYts --- libavcodec/internal.h | 26 +++++++++++++++++++++++++- libavcodec/utils.c | 10 +++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 005f308b70..94c41aef0b 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -300,9 +300,33 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) { return (start_code & 0xFFFFFF00) == 0x100; } +/** + * @brief Find the first start code in the buffer @p p. + * + * A start code is a sequence of 4 bytes with the hexadecimal value 00 00 01 XX , + * where XX represents any value and memory address increases left to right. + * + * By preserving the @p start_code value between subsequent calls, the caller can + * detect start codes across buffer boundaries. + * + * @param[in] p A pointer to the start of the memory buffer to scan. + * @param[in] end A pointer to the past-the-end memory address for the buffer + * given by @p p. @p p must be ≤ @p end. + * + * @param[in,out] start_code A reference to a mutable @c uint32_t.
+ * As input: For no history preset to @c ~0 , otherwise preset to the last + * returned start code to enable detecting start codes across + * buffer boundaries.
+ * On output: Set to the found start code if it exists or an invalid + * start code (the 4 bytes prior to the returned value, + * using the input history if @f$ p - end < 4 @f$). + * + * @return A pointer to the memory address following the found start code, or @p end + * if no start code was found. + */ const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, - uint32_t *state); + uint32_t *start_code); int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 1a806b9fa8..80ccde023f 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -942,7 +942,7 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, - uint32_t *av_restrict state) + uint32_t *av_restrict start_code) { av_assert0(p <= end); if (p >= end) @@ -951,10 +951,10 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // read up to the first three bytes in p to enable reading a start code across // two (to four) buffers for (int i = 0; i < 3; i++) { - *state <<= 8; - *state += *p; + *start_code <<= 8; + *start_code += *p; p++; - if (avpriv_start_code_is_valid(*state) || p == end) + if (avpriv_start_code_is_valid(*start_code) || p == end) return p; } // p is now properly incremented for the negative indices in the while loop @@ -988,7 +988,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // this will cause the last 4 bytes before end to be read, // i.e. no out of bounds memory access occurs - *state = AV_RB32(p - 4); + *start_code = AV_RB32(p - 4); // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} return p; From patchwork Thu Feb 3 18:44:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34106 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741665iov; Thu, 3 Feb 2022 10:46:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4V24RkeA3dXD5rueT6SYo/qu1f3AmGf35zedG3PpMZZ5l4zN9u5UgDHvhGKkzvAoEu2rD X-Received: by 2002:a17:907:6d97:: with SMTP id sb23mr30925581ejc.17.1643914016788; Thu, 03 Feb 2022 10:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914016; cv=none; d=google.com; s=arc-20160816; b=qRVi+LlaGDJyjFtn9BoZNsXgZPJrYNphzmEJY/BqswiG81pvYcC9rj8prMWovMxjS3 wmDQ95+CtxDog4Mq6ZAICvTW5nFL+nfQcKg888D632ahoYMCv/DnaEom4mey6iyIBrk1 Zxks7NaxeUjv+4gBNOJ7h+MZTm5kcQRrJF16RYiZkIRyRuoxGQ+mVklQOyY9nyQFEhLR M9eyv0d+BXA4O0D35rpXa5SOU2cL3mHLYkBTqhv0xYMwwbK68OaqAFCO4OpyZZDk/CWh Npd+w8h31qXyMeTzzHTKzvy9Mg+TbbXTonvUqjJT2jAU/diz/ys5A0ZP3KmwgCoeoPmO LuzQ== 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=CWb2cKpqjHq6AOqgkyUUg6uMoOlxCC2FVNDHHQaMOIg=; b=a/qT0nokLeHV0e/sR470/3PEdRRlP+QBOJW0b48RALCKmWPdmb3qFWp38FR9m5EfZD oD0sraeK1ZacSieggMI7EEZc/HAaHG4r/KNfH+PaTW3yXqREjJeUUEc+qkvRv8aGYCnk 5aZmX6gW8Fl/oMp5HxMo3fjXESLbjxb58rkOVieb1l2SRyHVUR0NTW2AcmoDQZMl0AxM oWqM7hp+GUvzsPUMTppehHE3CRfGKVOh1Qxp2KzISPDOVmMX8Rww2lQ2nYwqilmDgP+q rOwDVKnRv2geoQHU8QO1aX5gzkSnBnsZrhDn4sB/wsNvRGbLChaDPits1mDDFT8N8x7G fi8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="JOTJ/6YT"; 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 d1si14242031edo.142.2022.02.03.10.46.56; Thu, 03 Feb 2022 10:46:56 -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="JOTJ/6YT"; 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 E62FF68B0E8; Thu, 3 Feb 2022 20:45:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0659E68B143 for ; Thu, 3 Feb 2022 20:45:35 +0200 (EET) Received: by mail-qv1-f44.google.com with SMTP id o9so3319670qvy.13 for ; Thu, 03 Feb 2022 10:45:34 -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=Szv76eCvdT2ogyZw0JAi9eTdiMBsNUyEjOMGevN1vIY=; b=JOTJ/6YTqXUCXLpbe9v6ul6MaH21jJTXq6AOv+cdlDDIqelAHezM197KtBKyKI9ZoS 4Hs9LuxOBw2XUdGhNK23wYQ7IE0whZl7THa1aGhl75w458UIFFyrE1C7LoVWzxVspdPA b492do7d6SiqY+YjH4Aj8PfZDxrfgi6UmK0Qr+flDkey99ee2S2XzGYkJE8mx/8sc5jx ES2jA+zSYYHivQfatjXgKWgdsSU6/NAeFmJFb6Eys4C042+LxNmznALfgNJz9qakkdjy pa46eLPzSIdmlPfYZbOr/qWkC5rC2TpOAWfd+s8dT0Rycea2VQOTxxnJ3vLkwblGiGZT wtBA== 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=Szv76eCvdT2ogyZw0JAi9eTdiMBsNUyEjOMGevN1vIY=; b=f7bL4qItnew+QvCKmdKNBFzmAtvP6YWrZktLN+GZ0wpdVZB/E3D16aecTQeXxIesXz dean2SkM8ZuxWv4DieSBgIcDLymavRG/xBB/7aFAsrZpAl19KJNjO1qZSzk5Yel8DV6b FxsK0KsAN2soYNsgTNJmaVXNbZ69Ew1MIcGYVRMdTmyXy2Xg5VHm6FBVKoupb/sX5sMS CY/VKmMoyp/FmINNRFhRqBngUsd+so7nwf5a5JKNxIJwgRgeR+3wdW6f9NxBrlJIUFEs +oHCTb1ZwyiPW+15DGRbT8quQ46dhVCMVmDKpmOsLxmFOmMqW6dscbF7CfdH7Z3KglRh N+tg== X-Gm-Message-State: AOAM532Jv6YNPNdSQTmY7OYhTK3OYDyth7UBoh1oSk+0XHN9oXXI8Oci G2x75FNRUf6O5rfEWkkA3/leZvL4xwhU0w== X-Received: by 2002:a05:6214:2428:: with SMTP id gy8mr32766190qvb.122.1643913933608; Thu, 03 Feb 2022 10:45:33 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:33 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:43 -0500 Message-Id: <20220203184450.5491-7-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 06/13] avpriv_find_start_code(): correct type of start_code parameter 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: Dg1l5FRlpsGJ --- libavcodec/mpeg12dec.c | 2 +- libavformat/rtpenc_mpv.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 65b66d11f8..6b0b84ae64 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1770,7 +1770,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, if (avctx->hwaccel && avctx->hwaccel->decode_slice) { const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ - int start_code = -1; + uint32_t start_code = ~0; buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code); if (buf_end < *buf + buf_size) buf_end -= 4; diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index 05a77fa11c..91c07574bb 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -51,11 +51,10 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) end_of_slice = 1; } else { const uint8_t *r, *r1; - int start_code; r1 = buf1; while (1) { - start_code = -1; + uint32_t start_code = ~0; r = avpriv_find_start_code(r1, end, &start_code); if (avpriv_start_code_is_valid(start_code)) { /* New start code found */ From patchwork Thu Feb 3 18:44:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34109 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741925iov; Thu, 3 Feb 2022 10:47:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJytyuHibFMKUQUpxLBvnikbmAVq+BUu+OyAhTOSCQBBSZs+JJl98yUhMlmjF4qbBaI1A7wp X-Received: by 2002:a17:907:30d6:: with SMTP id vl22mr29919640ejb.453.1643914043422; Thu, 03 Feb 2022 10:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914043; cv=none; d=google.com; s=arc-20160816; b=K4hGM+PW6sA33C66ld8iInb+2UN8zqMfsqrVE0yCFi1d51l1cYYV3FfMrSEiyEluqW wlMp+Z/wHnEI+IuDivDVjewATn3NEl9OlnX7R1SKi9vCb0TttzDg5uL7cF1+szYnMMUk p0AKckqTrvEnMgRyqqX44ZfkF6eusczM/dBWUFbi86OjNPedwlFpPIX75id2jBWh0Pfx Xfxx5+N63dzcj6/1ZlQsmeX7rDGArae11eTj0qYvGZCD/im7py3KjsEB+XAmgj7obbwS OIWMTFD24i0br4k/LLrlsxdCfPDtvSennC8NwrfdG8QleBPeChT+bJh+qjnzq3aUf4pI yxKA== 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=uzgyWecZrn0og22OblTyOssX4sYEXdtQV4aOmm9KJvk=; b=ryRkq62caHBTrk212a1B7MPwsEDr+Eo5a+5bgdACv4hhdEkxAkqvARDq+rbi59BxBY 8nR1IjJa+O900X51+dUGYZqeUz8zXegcjuMVweboEaSlZezndQTTo1YUfEOTQ3Q1Rmd5 N3t5EM42jMdxkYvHtl61KssOqt+EqmL5jJmIo04/VZWieDY3zYdmkv/6r+CTKRa1dqL9 psaMco1rdaRHTXn3dTj2dy1URtfpzBSXtCY491ZvLLh5bGDyWlhKIXliHJQG6jHFSiIK OcraV9faaklsXW+flq7NREdWTAFMq3Z2Dmn9TPLPyZxw21QLiOUoIYpJqdl/6behvCjX EoxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=P3asLeX5; 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 ne16si16756146ejc.424.2022.02.03.10.47.23; Thu, 03 Feb 2022 10:47:23 -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=P3asLeX5; 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 E533C68B14F; Thu, 3 Feb 2022 20:45:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 177B368B0E8 for ; Thu, 3 Feb 2022 20:45:36 +0200 (EET) Received: by mail-qv1-f53.google.com with SMTP id g13so3372379qvw.4 for ; Thu, 03 Feb 2022 10:45:36 -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=AKkYzlg+78s7MGuoLWPhP8jZ1HhkpPMIQn+22ovBIK0=; b=P3asLeX5aD20UjY4mqE2rTcl65n9dMeEtz28bleyRFFNm/+9EHO4etkh0Nb3osFKQV lEYMM1nqmZlW8uRFXhkXQTo9JJVUw+QwF5Gk9C4mvRGyIhRESenKd9kHcVucG6nHkxzm Py8fdhSeDAozfleMFdxuvlNd15Yh3TyjFn8lCQpvJRL1XblK+CIjdVnio2Pf3XDpxMzU ngi4K+T9SjNRhNTGj9RpvRdi6AH4hULDWlXDi38zQ0CJdzXFBIA4lDl9DOm/w4xRxJx2 rgCYERSzU9U/46SLNFTvfZl+t+qJ3ld7YJupe+S1xrR07U66gPD6afoJSo/BXYQLdekT o29Q== 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=AKkYzlg+78s7MGuoLWPhP8jZ1HhkpPMIQn+22ovBIK0=; b=hhBKfZZxVfposgpXSc8x/g12EdQQEfQE8/PDfuPo/s7i6t5KKHzVJ9lGHB/Qx2MeWe zXlMcab0XPTjc2DwlfybzI/3wutYgSmhBqXz+y69DCwv+eMvUggSHKX1J+/DGw2zixL9 o0Iaw7AJi/UmH7oXncv4X+tIchZc262D/F1+j0FHQsLVBuJzUjPK4EEYKQVewWibyzKw cVEhsr60nuC6bA15xkVC5+VGhHdpvWC3yCD3392w/TSxIp6R9rPHDIb3ZRU3gDc6dPnL IxKMH/MA8KeVXh12kWrqBgDO8esGPvLyg6nv56Yjd8gIxJJvlg0+ErSw2ukEolr4mz7R 39PQ== X-Gm-Message-State: AOAM532F1JBlgKt7CiC47uJos5iJseX7sHwv9B4GdihgAVfAs8Zl0R+i W06jiuCmh6qPEt3HQcQN0j5GZoawCjlG+A== X-Received: by 2002:a05:6214:1cce:: with SMTP id g14mr13031823qvd.108.1643913934386; Thu, 03 Feb 2022 10:45:34 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:33 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:44 -0500 Message-Id: <20220203184450.5491-8-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 07/13] avpriv_find_start_code(): constify pointer parameters 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: XJfnvMAr2JJc Have the compiler enforce not changing the addresses these parameters point to. No functional change. --- libavcodec/internal.h | 6 +++--- libavcodec/utils.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 94c41aef0b..dadd8d4a10 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -313,7 +313,7 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) { * @param[in] end A pointer to the past-the-end memory address for the buffer * given by @p p. @p p must be ≤ @p end. * - * @param[in,out] start_code A reference to a mutable @c uint32_t.
+ * @param[in,out] start_code A constant pointer (reference) to a mutable @c uint32_t.
* As input: For no history preset to @c ~0 , otherwise preset to the last * returned start code to enable detecting start codes across * buffer boundaries.
@@ -325,8 +325,8 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) { * if no start code was found. */ const uint8_t *avpriv_find_start_code(const uint8_t *p, - const uint8_t *end, - uint32_t *start_code); + const uint8_t * const end, + uint32_t * const start_code); int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 80ccde023f..cf92d29f67 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -941,8 +941,8 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in #endif const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, - const uint8_t *end, - uint32_t *av_restrict start_code) + const uint8_t * const end, + uint32_t * const av_restrict start_code) { av_assert0(p <= end); if (p >= end) From patchwork Thu Feb 3 18:44:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34099 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2742110iov; Thu, 3 Feb 2022 10:47:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+XqnoRKnzQliUGgyCHVl0URsjbRDHnQxrs2mXQx0i4RZHQshQK5jvstvL8CnUnIffXstM X-Received: by 2002:a17:907:9491:: with SMTP id dm17mr30112747ejc.47.1643914062074; Thu, 03 Feb 2022 10:47:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914062; cv=none; d=google.com; s=arc-20160816; b=ZKWmgLpVQvqujKwGrFk6ph/MDUab4TBfnu4tpJgB4bYL5fOfjjm1JeA/xaGbhnLS4n nAda885MlG95dJx6zqsx0j+EOInBeve29ngpnvT/2CSigG4r4hyj9mCI3Ge3dZreDMH6 8urNFV+MbQE2Z88eRmJy2vpoxJdUzIwc+qZDSWOtCExZCwptJ9+F+Zv4y8wKHK08XUIy NmAogRifz3jLr9my+sC+2/nABzkb6RJIeHTYfJn6jLB8VkDVj6D5UPV+tEunb34uzmhe PiP1Wflz5ZqxnZdYXJKxEp6hiKUvbnGOzRUprzSPXD5Ic7jKxFdhsyL6yRxLHzx1I69n f65w== 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=MFSk7V3GWBDuicU6/BfWmRKWPjGusu2t1blFq0RgWhY=; b=KhYhOFVHVsZHkubGrht3SChR9S3UpBUod9oGYj4M0jguyKEP+z8vEQZENA6HwffbCG v/2Cv+5IAsPzYpoMf/dVr0vfK6CnfFK9LlgdaPd1BHK80X5qvZzr1/xiQsK1IH2OhZWZ UuB2QPfhTIeeafESQ7YzOC0kKjNWZ8j5Qt2L2boITlenWo1fn2oKcwZrFxgB2ksd7KVn MXWc1RvCAoqj/QFDS1oC56t7/C0jfkZK6Gloh/Jh54cdAM7FXy3IzIdrOcf+61DN6Jwy NPEQtaGfOl/Rdatjq3TqcFmK+sbsyi4I6InORah71YoACSUyK5pHU0S9YibARf9mZxsX q3DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="CYKB7mQ/"; 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 hp33si18716574ejc.701.2022.02.03.10.47.41; Thu, 03 Feb 2022 10:47:42 -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="CYKB7mQ/"; 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 BFEFB68B1D1; Thu, 3 Feb 2022 20:45:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 181C768B196 for ; Thu, 3 Feb 2022 20:45:37 +0200 (EET) Received: by mail-qt1-f182.google.com with SMTP id b5so3614621qtq.11 for ; Thu, 03 Feb 2022 10:45:37 -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=2n3Iu1cvqcEhUlpQ78i1xLTYMo6GYEVrPoL5ELCDlrw=; b=CYKB7mQ/nc+r5VHzpUyXsW98UgtDBAXd6nJn4bTFQR/SgNoG63YCXHQr7GbVJnxOkJ fmEejpz221r2K3zV1CxtqUVrgzllWP2YBRCxbkMZoHrtElwt6UwB7TPfoBAxnQcXepHh eHWO1PhMjnkVNs+XE9JwY2IfMuET94gFdtaf98sYbU6fvvTn4PfnwGmGfh7ZWIibO+Dr VagTpfFVDj2oYjD8kFhN1cSjDcXkbct5sJKuLlqQWn+pjlphzuZhCp3UqGvbmml+wg+Z Pr6U74NwwpDCUgm1oTAJWATL/ZyyM11OsRbdl/M8likiG5WQbW83HvBAHj6xf3SmJiO9 WrGw== 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=2n3Iu1cvqcEhUlpQ78i1xLTYMo6GYEVrPoL5ELCDlrw=; b=hkS+/ydp7YUULmMMvZTD6+I8jaobm0nQXqoy8ZL7u7sbgFI6t9xdzyUWAdITBI/fpV 3SWxr0fZFbQPQqTrvjK8XYJOQSNRlUQwoJQuvoWb5kwud+rN9eJOTxEo7SXNHbpvlf/z Bn6XH587aCCY//LkabjKjA7Se5VCXTzMO+f09gNFbJCSHiRpIP97OT8fo2ZIlU0XkatO b9Y1hHoIfc7CE8WOAw1z7YbDjKNMgWycjrfO7dTSsHLSY8ALHx4rTfwQr2OYgRZ4eU03 g4u6cnif7FaagyqMRDUsvWYxRr88D2alM0wgaGUUU2ymT8lvmv8ncpD/4TkYBJvJElce WpEQ== X-Gm-Message-State: AOAM5329V24Vb4Tf/MXvhr5Q8pL9X7NBkZNXrTGDEZQw3ldBqu1BypZS fFL4EnDi1IlaIyVq7HrilV8JoyRKHI6VLw== X-Received: by 2002:a05:622a:1b9e:: with SMTP id bp30mr13577196qtb.403.1643913935334; Thu, 03 Feb 2022 10:45:35 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:34 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:45 -0500 Message-Id: <20220203184450.5491-9-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 08/13] avpriv_find_start_code(): add parameter for ignoring history 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: DB3MRCszr/yM If true, this skips the for loop at the beginning of avpriv_find_start_code(). If the state/start_code input is a local variable and only one buffer is used, then no history is needed. In loops and inline functions: if ignoring history, don't initialize start_code, so it isn't reset twice each time. cbs_mpeg2.c needs further changes to use output_only = true. Use output_only = 0 for no functional change. For example, if the state/start_code is passed into the function calling avpriv_find_start_code(). --- libavcodec/cavsdec.c | 2 +- libavcodec/cbs_mpeg2.c | 4 ++-- libavcodec/extract_extradata_bsf.c | 4 ++-- libavcodec/h264_parser.c | 2 +- libavcodec/internal.h | 9 ++++++++- libavcodec/mpeg12.c | 2 +- libavcodec/mpeg12dec.c | 9 ++++----- libavcodec/mpeg4_unpack_bframes_bsf.c | 3 +-- libavcodec/mpegvideo_parser.c | 5 ++--- libavcodec/remove_extradata_bsf.c | 8 ++++---- libavcodec/utils.c | 14 +++++++++++++- libavcodec/vc1_common.h | 4 ++-- libavformat/avidec.c | 6 +++--- libavformat/avs2dec.c | 2 +- libavformat/avs3dec.c | 2 +- libavformat/cavsvideodec.c | 2 +- libavformat/mpegtsenc.c | 4 ++-- libavformat/mpegvideodec.c | 2 +- libavformat/mxfenc.c | 2 +- libavformat/rtpenc_mpv.c | 4 ++-- 20 files changed, 53 insertions(+), 37 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index a62177d520..c4c78cd534 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -1248,7 +1248,7 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, buf_ptr = buf; buf_end = buf + buf_size; for(;;) { - buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc); + buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc, 1); if (!avpriv_start_code_is_valid(stc) || buf_ptr == buf_end) { if (!h->stc) av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n"); diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index eb45929132..d41477620e 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -151,7 +151,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, int err, i, final = 0; start = avpriv_find_start_code(frag->data, frag->data + frag->data_size, - &start_code); + &start_code, 1); if (!avpriv_start_code_is_valid(start_code)) { // No start code found. return AVERROR_INVALIDDATA; @@ -169,7 +169,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, } end = avpriv_find_start_code(start--, frag->data + frag->data_size, - &start_code); + &start_code, 0); // start points to the byte containing the start_code_identifier // (may be the last byte of fragment->data); end points to the byte diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index 4df1c97139..1a3ddceff2 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -237,7 +237,7 @@ static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, int has_extradata = 0, extradata_size = 0; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); + ptr = avpriv_find_start_code(ptr, end, &state, 1); if (state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT) { has_extradata = 1; } else if (has_extradata && avpriv_start_code_is_valid(state)) { @@ -300,7 +300,7 @@ static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt, uint32_t state = UINT32_MAX; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); + ptr = avpriv_find_start_code(ptr, end, &state, 1); if (state == 0x1B3 || state == 0x1B6) { if (ptr - pkt->data > 4) { *size = ptr - 4 - pkt->data; diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 4002bcad77..0ca411c592 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -72,7 +72,7 @@ static int find_start_code(const uint8_t *buf, int buf_size, { uint32_t state = -1; - buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, &state) - buf - 1; + buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, &state, 1) - buf - 1; return FFMIN(buf_index, buf_size); } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index dadd8d4a10..57e2816a95 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -309,6 +309,9 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) { * By preserving the @p start_code value between subsequent calls, the caller can * detect start codes across buffer boundaries. * + * If @p output_only is true, @p start_code is reset to @c ~0 + * if @f$ p - end < 4 @f$. + * * @param[in] p A pointer to the start of the memory buffer to scan. * @param[in] end A pointer to the past-the-end memory address for the buffer * given by @p p. @p p must be ≤ @p end. @@ -321,12 +324,16 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) { * start code (the 4 bytes prior to the returned value, * using the input history if @f$ p - end < 4 @f$). * + * @param[in] output_only Boolean that if true makes @p start_code an + * output only parameter. + * * @return A pointer to the memory address following the found start code, or @p end * if no start code was found. */ const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t * const end, - uint32_t * const start_code); + uint32_t * const start_code, + int output_only); int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index e45bc74479..d788aeb9e2 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -203,7 +203,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, } state++; } else { - i = avpriv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1; + i = avpriv_find_start_code(buf + i, buf + buf_size, &state, 0) - buf - 1; if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { i++; pc->frame_start_found = 4; diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 6b0b84ae64..cad17d1b1a 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1771,7 +1771,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, if (avctx->hwaccel && avctx->hwaccel->decode_slice) { const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ uint32_t start_code = ~0; - buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code); + buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code, 1); if (buf_end < *buf + buf_size) buf_end -= 4; s->mb_y = mb_y; @@ -2020,8 +2020,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) if (s->mb_y == s->end_mb_y) return 0; - start_code = -1; - buf = avpriv_find_start_code(buf, s->gb.buffer_end, &start_code); + buf = avpriv_find_start_code(buf, s->gb.buffer_end, &start_code, 1); if (start_code < SLICE_MIN_START_CODE || start_code > SLICE_MAX_START_CODE) return AVERROR_INVALIDDATA; mb_y = start_code - SLICE_MIN_START_CODE; @@ -2475,8 +2474,8 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, for (;;) { /* find next start code */ - uint32_t start_code = -1; - buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &start_code); + uint32_t start_code; + buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &start_code, 1); if (!avpriv_start_code_is_valid(start_code)) { if (!skip_frame) { if (HAVE_THREADS && diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index 6f8595713d..37fb0e4b66 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -36,8 +36,7 @@ static void scan_buffer(const uint8_t *buf, int buf_size, const uint8_t *end = buf + buf_size, *pos = buf; while (pos < end) { - startcode = -1; - pos = avpriv_find_start_code(pos, end, &startcode); + pos = avpriv_find_start_code(pos, end, &startcode, 1); if (startcode == USER_DATA_STARTCODE && pos_p) { /* check if the (DivX) userdata string ends with 'p' (packed) */ diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index f0897e7e2c..14e350eaea 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -68,7 +68,7 @@ static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, } state++; } else { - i = avpriv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1; + i = avpriv_find_start_code(buf + i, buf + buf_size, &state, 0) - buf - 1; if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { i++; pc->frame_start_found = 4; @@ -120,8 +120,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, s->repeat_pict = 0; while (buf < buf_end) { - start_code= -1; - buf= avpriv_find_start_code(buf, buf_end, &start_code); + buf = avpriv_find_start_code(buf, buf_end, &start_code, 1); bytes_left = buf_end - buf; switch(start_code) { case PICTURE_START_CODE: diff --git a/libavcodec/remove_extradata_bsf.c b/libavcodec/remove_extradata_bsf.c index 0e42174912..46e914053d 100644 --- a/libavcodec/remove_extradata_bsf.c +++ b/libavcodec/remove_extradata_bsf.c @@ -70,7 +70,7 @@ static int h264_split(const uint8_t *buf, int buf_size) int nalu_type; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); + ptr = avpriv_find_start_code(ptr, end, &state, 1); if (!avpriv_start_code_is_valid(state)) break; nalu_type = state & 0x1F; @@ -108,7 +108,7 @@ static int hevc_split(const uint8_t *buf, int buf_size) int nut; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); + ptr = avpriv_find_start_code(ptr, end, &state, 1); if (!avpriv_start_code_is_valid(state)) break; nut = (state >> 1) & 0x3F; @@ -151,7 +151,7 @@ static int mpeg4video_split(const uint8_t *buf, int buf_size) uint32_t state = -1; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); + ptr = avpriv_find_start_code(ptr, end, &state, 1); if (state == 0x1B3 || state == 0x1B6) return ptr - 4 - buf; } @@ -166,7 +166,7 @@ static int vc1_split(const uint8_t *buf, int buf_size) int charged = 0; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); + ptr = avpriv_find_start_code(ptr, end, &state, 1); if (state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT) { charged = 1; } else if (charged && avpriv_start_code_is_valid(state)) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cf92d29f67..da057bad3e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -942,9 +942,20 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t * const end, - uint32_t * const av_restrict start_code) + uint32_t * const av_restrict start_code, + const int output_only) { av_assert0(p <= end); + if (output_only) { + // minimum length for a start code + if (p + 4 > end) { + *start_code = ~0; // set to an invalid start code + return end; + } + + p += 3; // offset for negative indices in while loop + } + else { if (p >= end) return end; @@ -958,6 +969,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, return p; } // p is now properly incremented for the negative indices in the while loop + } /* with memory address increasing left to right, we are looking for (in hexadecimal): * 00 00 01 XX diff --git a/libavcodec/vc1_common.h b/libavcodec/vc1_common.h index 483f86a4ee..453dec34c6 100644 --- a/libavcodec/vc1_common.h +++ b/libavcodec/vc1_common.h @@ -57,8 +57,8 @@ enum Profile { static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end) { if (end - src >= 4) { - uint32_t mrk = 0xFFFFFFFF; - src = avpriv_find_start_code(src, end, &mrk); + uint32_t mrk; + src = avpriv_find_start_code(src, end, &mrk, 1); if (avpriv_start_code_is_valid(mrk)) return src - 4; } diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 86f857b1e3..674f313e84 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -1530,12 +1530,12 @@ resync: if (index >= 0 && e->timestamp == ast->frame_offset) { if (index == sti->nb_index_entries-1) { int key=1; - uint32_t state=-1; if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256); while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &state); - if (state == 0x1B6 && ptr < end) { + uint32_t start_code; + ptr = avpriv_find_start_code(ptr, end, &start_code, 1); + if (start_code == 0x1B6 && ptr < end) { key = !(*ptr & 0xC0); break; } diff --git a/libavformat/avs2dec.c b/libavformat/avs2dec.c index bdeb746fc7..f2349dde45 100644 --- a/libavformat/avs2dec.c +++ b/libavformat/avs2dec.c @@ -41,7 +41,7 @@ static int avs2_probe(const AVProbeData *p) } while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &code); + ptr = avpriv_find_start_code(ptr, end, &code, 1); if (avpriv_start_code_is_valid(code)) { state = code & 0xFF; if (AVS2_ISUNIT(state)) { diff --git a/libavformat/avs3dec.c b/libavformat/avs3dec.c index 2daccd3d15..2238193ff4 100644 --- a/libavformat/avs3dec.c +++ b/libavformat/avs3dec.c @@ -35,7 +35,7 @@ static int avs3video_probe(const AVProbeData *p) int ret = 0; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &code); + ptr = avpriv_find_start_code(ptr, end, &code, 1); if (avpriv_start_code_is_valid(code)) { state = code & 0xFF; if (state < AVS3_SEQ_START_CODE) { diff --git a/libavformat/cavsvideodec.c b/libavformat/cavsvideodec.c index 1d007708cc..8f4004acea 100644 --- a/libavformat/cavsvideodec.c +++ b/libavformat/cavsvideodec.c @@ -37,7 +37,7 @@ static int cavsvideo_probe(const AVProbeData *p) const uint8_t *ptr = p->buf, *end = p->buf + p->buf_size; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &code); + ptr = avpriv_find_start_code(ptr, end, &code, 1); if (avpriv_start_code_is_valid(code)) { if(code < CAVS_SEQ_START_CODE) { /* slices have to be consecutive */ diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 92b4cc8087..483c65be17 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1881,7 +1881,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) extradd = 0; do { - p = avpriv_find_start_code(p, buf_end, &state); + p = avpriv_find_start_code(p, buf_end, &state, 1); av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f); if ((state & 0x1f) == 7) extradd = 0; @@ -1947,7 +1947,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) extradd = 0; do { - p = avpriv_find_start_code(p, buf_end, &state); + p = avpriv_find_start_code(p, buf_end, &state, 1); av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", (state & 0x7e)>>1); if ((state & 0x7e) == 2*32) extradd = 0; diff --git a/libavformat/mpegvideodec.c b/libavformat/mpegvideodec.c index a9829dc1df..840d3565af 100644 --- a/libavformat/mpegvideodec.c +++ b/libavformat/mpegvideodec.c @@ -43,7 +43,7 @@ static int mpegvideo_probe(const AVProbeData *p) int j; while (ptr < end) { - ptr = avpriv_find_start_code(ptr, end, &code); + ptr = avpriv_find_start_code(ptr, end, &code, 1); if (avpriv_start_code_is_valid(code)) { switch(code){ case SEQ_START_CODE: diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 5e068c8220..8cec44e89c 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2242,7 +2242,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, int i, frame_size, slice_type, has_sps = 0, intra_only = 0, ret; for (;;) { - buf = avpriv_find_start_code(buf, buf_end, &state); + buf = avpriv_find_start_code(buf, buf_end, &state, 1); if (buf >= buf_end) break; diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index 91c07574bb..3c7168c482 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -54,8 +54,8 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) r1 = buf1; while (1) { - uint32_t start_code = ~0; - r = avpriv_find_start_code(r1, end, &start_code); + uint32_t start_code; + r = avpriv_find_start_code(r1, end, &start_code, 1); if (avpriv_start_code_is_valid(start_code)) { /* New start code found */ if (start_code == 0x100) { From patchwork Thu Feb 3 18:44:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34111 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2742197iov; Thu, 3 Feb 2022 10:47:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJQiQSxkngyU0/rvO0Lo1XkmzZKSWajp5Zy5MEtbMh5983Qg7Vl5MzY6u1HFCkxu3tmNT5 X-Received: by 2002:a17:906:e2c4:: with SMTP id gr4mr30600613ejb.393.1643914071979; Thu, 03 Feb 2022 10:47:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914071; cv=none; d=google.com; s=arc-20160816; b=lkF8s/TxqR/SG+ZbIZI4feLBxpAt7QD/tvHlv+am/7NAkuG2ongtUo0Yn7p8uEevn5 Y+vqf8QiXlaRMwYilfU2D2/k/J5x+eeB5QuDf6Gq5Lp2STbMinmKywE8PeQ3mUgvZKcK CXhh4rgrC6U76e39OY9u2EdL3oYWs5s7d3hBbBNtWOqXdF0tqValxEsl7tLVzWPmmdtV IFPcoRsApjb71ngNLCx7ge98fcuzJSAwvBY64OZqynrkWBdkwmKJ+wzPZb5OdbJ3a3Gz 9bHZoTEvKyNHco+P+zLR0RBGiYoHHTcghgQDP3QTNxc86tEZsZCETXAOytey25+aWHmG R4uw== 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=BRhvjPkB4X8k4aTI0DZrbh45GLneapx21FIurMSYmdQ=; b=nL9fwdLJo1K0R9mpLdKUMRSGLxDfcFCtqgvKrGPY0mctFA+pAfI6JneN5KlQp4zd6z hjY/5fhGEsojyD0x91Km+x3UrU8Y37b/IXmUUp2l+t/a9y1xV9Rls28rN2M6rA58iwkj 4/1zejBXqkZofRFX4+R7Ms8Z6Ss/POf0k3mNKprw8KsMfpw1sDH4Q5v5OsF2xj4qhdQA igcyCA/ox4SQiTeHKnA21YeMUbZII4yYElI7j4GL0gKXqJ3MwfBJsu3o6oFi7mfOCRQ2 RjyxnfU/Jl93HbXTiGpSZmhzVt/Kb5S3SvpeqzM8MHAinFt1G9TcTn8kGGNZ0VVPSfm4 VHCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Y+Bfi1Jv; 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 dd21si11942013ejc.160.2022.02.03.10.47.50; Thu, 03 Feb 2022 10:47:51 -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=Y+Bfi1Jv; 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 BD12168B1D6; Thu, 3 Feb 2022 20:45:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B8ACA68B1A5 for ; Thu, 3 Feb 2022 20:45:37 +0200 (EET) Received: by mail-qt1-f170.google.com with SMTP id t17so3510515qto.1 for ; Thu, 03 Feb 2022 10:45:37 -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=pyxGzPGI382WvorQ98CTZqZcEziBz1Sw/t7CIyV7+JM=; b=Y+Bfi1Jv9cZpxt99wgqtmWvpP0s759qH3dixxXkZ1CFItiLKSE0nOz6a7w5+3c1Ykn r3YCEqEdKe704G9jPqP7TG/U7ytFmPl/ZrkT7rWsF99fDYhSK41Kj4bVd+Nfm27yj1rw 4BBqTrIuNCaWLhOX3mNopsL+bKE4tqbtEUKbgm8w30B8nNsdnAx+XdJ7O3pO/9wJpCX0 LVKOl1df0qz787xGJXVRCTYnf/MBThVj8+CKTyOwZuIuNnuwTAOjOQJDKIaZKT6iAObA IBqq5KiExL5febSOMXZnCr4xs/X37X3f9uln76wLwcjoiFNtLcAFO37V1WZBLYuewnNW 3Whg== 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=pyxGzPGI382WvorQ98CTZqZcEziBz1Sw/t7CIyV7+JM=; b=7+Au9+CUctYSnlYbKvXh5PlX7oK/yrAbXQ3CirgZ9tFdm6j7jCnbYXKndTleffcFtf lQyQSrq92n24KCIlKeQzJapk+gKEQHeYPN5iNWjQtp0+60h0l+jAOY2oAgG+oC3JWY04 Q1fjxEHAh01OeE3n50cBDCqkXYHxIsaRJaiz8zEk/qvZn/aMCrXwUDHGL6xx5S0AY4RM 77N3zIngQruL9sW5Entyr1EAfH1oEnwO9D8U56cb9k63Fp9peo+CrD6Vo9R6lthmK773 pRmbIbmUB6MRIygvXdCULRO+LzVGvkzx1Sm6gi6RoPhnVAu3tKPHfrSvMQjGCzSo7jbA MzbQ== X-Gm-Message-State: AOAM530QHOY1oHSZO+6r93AHneecRNO626xfnPXoYcBWd9H6vzDbaMUi /pYLg7DlY+cAU+cGcQF/loWBso7/dYfB6A== X-Received: by 2002:a05:622a:11ca:: with SMTP id n10mr28068114qtk.42.1643913936304; Thu, 03 Feb 2022 10:45:36 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:35 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:46 -0500 Message-Id: <20220203184450.5491-10-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 09/13] avpriv_find_start_code(): fix indent from previous commit 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: Z6bH0p7pIeZr Whitespace change only. Separate so the previous diff is clearer. --- libavcodec/utils.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index da057bad3e..255c133737 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -956,19 +956,19 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, p += 3; // offset for negative indices in while loop } else { - if (p >= end) - return end; - - // read up to the first three bytes in p to enable reading a start code across - // two (to four) buffers - for (int i = 0; i < 3; i++) { - *start_code <<= 8; - *start_code += *p; - p++; - if (avpriv_start_code_is_valid(*start_code) || p == end) - return p; - } - // p is now properly incremented for the negative indices in the while loop + if (p >= end) + return end; + + // read up to the first three bytes in p to enable reading a start code across + // two (to four) buffers + for (int i = 0; i < 3; i++) { + *start_code <<= 8; + *start_code += *p; + p++; + if (avpriv_start_code_is_valid(*start_code) || p == end) + return p; + } + // p is now properly incremented for the negative indices in the while loop } /* with memory address increasing left to right, we are looking for (in hexadecimal): 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; } From patchwork Thu Feb 3 18:44:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 34108 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp2741842iov; Thu, 3 Feb 2022 10:47:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJydoKqwWO2FiOfLCDlU4aABJbj9dEtTTSps02CaHkHBF0USPunAXyzXg3i3U7HWj1gaGoZJ X-Received: by 2002:a17:907:9491:: with SMTP id dm17mr30111475ejc.47.1643914034390; Thu, 03 Feb 2022 10:47:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643914034; cv=none; d=google.com; s=arc-20160816; b=BiStlddMFmJiP8B2KTd6wTzXS6UHvKO7O+RQwTjKhAKTjy2naoPHTbzb1SlZSfj2wR ppO33E+qWOK6J9tDdZXxZWaeVM9TmBdU+9Uabyj1yH1rSXG5C5j1ZA44ciaiYMX7miqN Io91NxlHkmKhBwhqgKHL4IH0uuQj2mwAlhI5NfwSg6UlrdWKmOuIVxoiG9lUeyS7hZ3W qs7uOqUgmBonCj4+lY7Z8+JNG/gmUJk8HU88t0Yz1GbNGIbHcyRhvp0J0xf4UL+UEtqw jT5PPw9ZofJ4geMy6dvGCimsiu2kWdrlsANJaiQXA3YaolhWDJRxRV+TzOJIZYCnGX2J zqGg== 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=8gwV9nKA84iOrHCtVZ7JYtpl6KeKualrsBbQ6g2UES8=; b=ggG6BIv1dC2xuWZSwd6awbKA4LKaFocU2Em7BO5SjTzLsoGPAvcLXxbJZl2hPmyX+1 e1winbGGFNiaxTidIhpvznf/j0Al13EQOVlSSV7w9gN2/kgGcX7X6UYMLSfyWB8mFRiA 1e0wrgJ5pytkdokFE2XuERWjxKJRX771hJn7AwezycRvq0/kilGUBBJb13xGg50z5ZFG LOpuNN3n0NBQRNfUwtjf4EXwA0ginZ6dwZqe4aUfgS4Z/OQYzOw5ZqIeC8zqrtSZPGJo 3aT4rbhByZUz5B0CehJqeD937omw55c6lVFvvP93Db1Lq+DrAj5XbnEd64dml4H1C2eI qQVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=lPLoK4dy; 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 i10si14390089ejd.170.2022.02.03.10.47.14; Thu, 03 Feb 2022 10:47:14 -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=lPLoK4dy; 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 16E3768B1C1; Thu, 3 Feb 2022 20:45:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D58AA68B0E8 for ; Thu, 3 Feb 2022 20:45:40 +0200 (EET) Received: by mail-qt1-f173.google.com with SMTP id b5so3614783qtq.11 for ; Thu, 03 Feb 2022 10:45:40 -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=mTUaY35F2RxD50O0GlBvVMsr0cRTZ8FkCrrqhCbjJZ8=; b=lPLoK4dyboqSKUrLN5uGSMPK9p/avDZQy2uDRSXixlR08BOZbhpo5DIWtnMr+XK0GZ hzo5l6JIiK9RafS9TusISNw7imbIskBAzWIJ0PXGqU6lXPP10WmwKqEGsSpwAqIk42nA 5Nnyg83jAdeiMQKTlZRmwdS0rMvadfstJLqNDdalHZpxb91TU62yqKqXBoBko3mKBuO/ OvoZAXOHeYCVf+RtziHil8u4Eo7n45zI1cckjuPzS2yRMlD+MKmpAGt/FT/KJ5WLI/V2 OP9igSUTIiYszunoOV7VlhewW4lVnTPPMnmR+6TK0Sx9qx3xGQh6dOsufakC+1FHai+a t+Jg== 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=mTUaY35F2RxD50O0GlBvVMsr0cRTZ8FkCrrqhCbjJZ8=; b=Cwv49JX1J93aSkHoneH0d9n3ejN22KyuS0iH6oEUyTQwLDqVNiONX6eb8MityOAmkn zX4ZBrN38k5AgiTKyo8KzZVh/vblz7w0EPAXgjtxLTC91YuCbHSY9OM0dfu2maG9mBbj L/91B+Vi5fki7mQffZuHSGd363eu02GpvpNOiO/2EHof261bmzNGLMLQWeMGAZ63sr+f 3lHuSRRJ7EvB+8Bxl8EUrDJHQd/TC8LwYYnRJ3alAZmBWZmgQnttXu8iCmDjttX0S66B Qj5Ns+rC7y3c+SDHYltKEM7TpY6a1r8Ex2PwAE2vE8EMRWiyaOEQohhPTHossmjKz9Rn ijEA== X-Gm-Message-State: AOAM531DpNBSFwrE9bWsdV7qDye4/aw45W4fzZ9GYFIRKNSJaASq60cH 7nt4ZCVcD35/GI3pjx3n6LkBrnkwh9VPJQ== X-Received: by 2002:a05:622a:20a:: with SMTP id b10mr27432850qtx.291.1643913939093; Thu, 03 Feb 2022 10:45:39 -0800 (PST) Received: from localhost.localdomain ([151.200.235.219]) by smtp.gmail.com with ESMTPSA id f16sm5947887qtk.8.2022.02.03.10.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:45:38 -0800 (PST) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Feb 2022 13:44:49 -0500 Message-Id: <20220203184450.5491-13-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 12/13] cbs_mpeg2.c: improve readability of start code search (part 2) 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: qKQq+s7WHpXZ If the last four bytes form a valid start code, the loop would run another time. Since (start == buf_end), start_code is invalidated so the loop terminates. However, calling avpriv_find_start_code() with p == end, it will immediately return due to the zero size buffer. Thus the history is not needed. --- libavcodec/cbs_mpeg2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index f2efedde5d..bf95fb7546 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -168,8 +168,9 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, // the next unit will be treated as the last unit. start_code = 0; } - - end = avpriv_find_start_code(start, buf_end, &start_code, 0); + else { + 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 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; }