From patchwork Fri Sep 16 18:19:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37960 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139466pzh; Fri, 16 Sep 2022 11:20:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gvs1kQKCJmYP3SFKMP8tcexxFzbom9gsqdcn9A1uERqMu0H7ItgHbrO/bbXuLI5HC+qeV X-Received: by 2002:aa7:d883:0:b0:44e:bbbe:d661 with SMTP id u3-20020aa7d883000000b0044ebbbed661mr5022381edq.248.1663352429046; Fri, 16 Sep 2022 11:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352429; cv=none; d=google.com; s=arc-20160816; b=j2BxNlXUmFQxYu91q/hmVvZUCC1bnaCDDFPmBWcVWhNgfncBQYJy2ZIbRizWAcFf39 m8lXf01iH565UMHrIaWLRB2lHdPwWIGCRNYS728o/fqloJJOoF/m5lheuLwFtRCOm/8+ OgQ7cMe9HFou2expnmEzY5NMj/I9ikbltKvWTn6Sjn86g8cLepsIp+hRAbGS91PP5bBW UXaBMWkxlH1bgWgeYxxPhIftTJhqSrAkXzmJ46XX1rx/w2Zt3rX83tt5I9xOn3dlI8fm H5+157lQVxKencpucgB268B/Uu/rJqPrucBx14epzJUmy+aq5xzVnRplMP75HBtYrl30 hORw== 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=fNcR1KsoBYcon8659fmJ2mzFcweTCrNsbt8FBQXc+v0=; b=Xjhmn8UIFUbKD9QFleCevkBeqZWSUAT044TFzWSYjDKgYoHxdql/mYM/qwAk6JWX9U BBagRTaTzQfT5Lvw7OsXedOTVDhJxah5U1Y+y1/XDDaMopBjQWJ+M7w2RDmcKAx2vz+C FlfQxeyrFJtzn5QrPkaK9N91ACkMJkVMS6g1Dk7fhuv3Ft2SM55IbPF0E9MbyUU4Ko4Y FqHEzf10Wtq2A2ZojYf6zkf6tEBM057jTxye9q2Thpn41/ceL76phpWZVSo8aYqs4BqE Jt2pZfxMUGcEXBBl9fMTLgAuWziiVXJkHz7Tys4LgeZfjzkCv3AuRee1K+vuqFVvH6X6 3FNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=P6YweL0K; 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 di11-20020a170906730b00b00780afde0bb3si2083735ejc.70.2022.09.16.11.20.28; Fri, 16 Sep 2022 11:20:29 -0700 (PDT) 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=P6YweL0K; 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 0306C68BC3B; Fri, 16 Sep 2022 21:20:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25F1868BAEB for ; Fri, 16 Sep 2022 21:20:10 +0300 (EEST) Received: by mail-qk1-f169.google.com with SMTP id d17so15566074qko.13 for ; Fri, 16 Sep 2022 11:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ccmXZCu/hsDZvFg+vY7Vhhk0Jq50BcGjVu/mkJl/Y2g=; b=P6YweL0K0RLiHTQlYvd9QNAt5XzHvJbB1xSwiHz/ALsGSmxjNvkWrSum8oO7d/+hgm /lXcSPMID+qfVyo26a9xLHFPjcxYO17T8GmfrUyVYEjZUlmSJ8xkYl5gLc2hhP+C4eKL r377NI/Ps2QlU9YyqzqMuXuWDThxy0napRDBnO/qk4XE70vNc/BTu6IvQQwAsl7TkJv6 /rlKuJN0n4HFR/jsHIDfT0eiCUuAY3rf99pqqVEJW1yS3vDhRP5BUCj2LfVUDE7dGhBf Wixko7YJjcTMbo4RGO97K5G1M2lLmZ94bJFdTVXUiiuUEM8YuvdfZ2dfNCmrrYtQYiBW MNoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ccmXZCu/hsDZvFg+vY7Vhhk0Jq50BcGjVu/mkJl/Y2g=; b=6ZZrV7wFe0+f2wp3p1gEisu60CVuW8Pmtgxk+aLO4xvs6s4Al1qsg2ueKsN2QkICrs HsX52SzGLa9lT01fJKN1SxQlOiAlRlZUUdlSL40EkjjY4EqrzgJw1YfcL35pQMgoD/Kt QFExRyCjFATOUZJiKXgHNtnxrVsekKQoRVKR5K7QN5nxy6J+A2EksE+dsIxn2c4qNLIf MwaqL5O2X4pizbdBPfVjzXCU6zHscqoguuGBZe0MxpgVzf6EyeIqIHuGEZdrsMTuzZ/T uHGrmWa6kVrHEx/7gRGiJOkBH6PIwgdWQeONjGLPI6Y0XkBfhYYv17TN8bNgGYXqQWcI SUFg== X-Gm-Message-State: ACrzQf0W04AYj5DiD44OSTnFcaoB0euCuuTbR9EaFSmPYCv6b6i4uWPG INFc14wde2eEjvSphw+cQrKNtjDWCzA= X-Received: by 2002:a05:620a:2588:b0:6c9:2daa:9c6d with SMTP id x8-20020a05620a258800b006c92daa9c6dmr4964718qko.630.1663352408391; Fri, 16 Sep 2022 11:20:08 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:07 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:55 -0400 Message-Id: <20220916182002.122699-2-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/8] avcodec/startcode.h: create 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: reHV9HfSPjsn This slightly changes what is considered valid in the following cases: cavsdec.c: 0x000000XX is now considered invalid. mpeg12dec.c: 0x000000XX is now considered invalid. (where X is any value) IS_MARKER is equivalent since VC1_CODE_RES0 = 0x00000100 --- libavcodec/cavsdec.c | 2 +- libavcodec/cbs_mpeg2.c | 6 +++--- libavcodec/extract_extradata_bsf.c | 2 +- libavcodec/mpeg12.c | 2 +- libavcodec/mpeg12dec.c | 2 +- libavcodec/mpegvideo_parser.c | 2 +- libavcodec/remove_extradata_bsf.c | 8 +++----- libavcodec/startcode.h | 17 +++++++++++++++++ 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, 38 insertions(+), 25 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 3e8be65968..0c19d0e3f6 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -1257,7 +1257,7 @@ static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe, 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 (!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 04b0c7f87d..23839ca47b 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -150,7 +150,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 (!start_code_is_valid(start_code)) { // No start code found. return AVERROR_INVALIDDATA; } @@ -172,7 +172,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 (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; @@ -189,7 +189,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, start = end; // Do we have a further unit to add to the fragment? - } while ((start_code >> 8) == 0x000001); + } while (start_code_is_valid(start_code)); return 0; } diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index 329b1a6174..e698a2632e 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -239,7 +239,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 && start_code_is_valid(state)) { extradata_size = ptr - 4 - pkt->data; break; } diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index d78e25a777..5ff1830496 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -214,7 +214,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 && 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 7133696f3c..b857353ab8 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2446,7 +2446,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 (!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 ac6efb6909..f5afa95981 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -83,7 +83,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 && 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 66b7d00bd8..1914cf19d5 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 (!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 (!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 && start_code_is_valid(state)) return ptr - 4 - buf; } diff --git a/libavcodec/startcode.h b/libavcodec/startcode.h index 8b75832aaf..833754af09 100644 --- a/libavcodec/startcode.h +++ b/libavcodec/startcode.h @@ -27,6 +27,23 @@ #include +#include "libavutil/attributes.h" + +/** + * @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 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/vaapi_vc1.c b/libavcodec/vaapi_vc1.c index d82336a3b3..33de4a63c8 100644 --- a/libavcodec/vaapi_vc1.c +++ b/libavcodec/vaapi_vc1.c @@ -473,7 +473,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 && start_code_is_valid(AV_RB32(buffer))) { buffer += 4; size -= 4; } diff --git a/libavcodec/vc1_common.h b/libavcodec/vc1_common.h index c0f0c8c2eb..8ff9802a51 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 (start_code_is_valid(mrk)) return src - 4; } return end; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 9f32e82f9e..d98c15f2e4 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -667,7 +667,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, if (!buf2) return AVERROR(ENOMEM); - if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */ + if (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 0d5b23b65e..a5a7cee7d0 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 (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 2395df171b..112b28efa8 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 (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 b89851fbbb..398f1192dd 100644 --- a/libavformat/cavsvideodec.c +++ b/libavformat/cavsvideodec.c @@ -39,7 +39,7 @@ static int cavsvideo_probe(const AVProbeData *p) while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &code); - if ((code & 0xffffff00) == 0x100) { + if (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 33c5d79794..88966af72a 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 (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 c18c75082f..8b6987b7f2 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 (start_code_is_valid(start_code)) { /* New start code found */ if (start_code == 0x100) { frame_type = (r[1] & 0x38) >> 3; From patchwork Fri Sep 16 18:19:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37961 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139557pzh; Fri, 16 Sep 2022 11:20:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5KpuxxZFuljBwgJuuaQyvNnPaAcBuFlEPe/mQJxndV4GcFnTEsaYYBLriEb6lrjJuxOWuH X-Received: by 2002:a17:907:96a8:b0:780:3293:8e73 with SMTP id hd40-20020a17090796a800b0078032938e73mr4308647ejc.538.1663352440829; Fri, 16 Sep 2022 11:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352440; cv=none; d=google.com; s=arc-20160816; b=SGljS9FnvfsDPRvRbih1TSBPFhahYsRkaQN/11mes4YH0eGpxmj6qPmrHWA5MIT9Pp 8wIS2l+2m3T1k3RsV2lDxIzHPzss3Y73XbDNyI8Xp9Ssc/6iW5V/Z3+ZLPeM2/DEu/7z HMFly5dAM7ytvDs/HkPDsFUVvJBYYYLN20k5M81DGK+sdW6JxJpcBxqXl5KD9R95w02f nyPju/zISUfdLAAuWd+09JEm1JwAq0Puj3f+dgFbK9tqa5OuspkLmdxlwgq7jbB7/Kln BycU/3oVIXEAU95DGtzNrRMWEpmcpJpY/Cr6SRGCjFwLas+x2JYGVWGBgPFZWaS+w5XN I4vw== 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=cR43mMZMRdj8auJXmp1kop8LJzCgfGeH4t6RcPrVgFQ=; b=zK9qy224VMrasC8esaBHEhxMwe74uehaf0oyOIcqkMv7YQxChGvwdU1s59LWl7RCsq N+u1n1AKHxy6AfdtkBIaegLJw0ObtEYDxgkp2jXeQnthB8IIjWQCJxn2hMb1zOft7DVj zV3X4sl46G5nHKE9lEm2pImYWvlQhPHFieLwZ8YzfHpL822poit1+W4JaqEaydJk2uB0 z4P/d0WBwcGDff0oTtf3DjmHJJvdf1gGjwYTfhpSMrIhb8G8jC3O4uU7l/JkgRUCUbVo 118xOtqFVJQ/QKZXeFD1/fFSU8AocadoLCPzyoL8pTKhYfWB7s7OLY83Ay8lyM3C7oe2 4apQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=MeBO52Py; 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 j30-20020a508a9e000000b0045261ae8b8bsi2032106edj.504.2022.09.16.11.20.36; Fri, 16 Sep 2022 11:20:40 -0700 (PDT) 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=MeBO52Py; 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 1B5BB68BC34; Fri, 16 Sep 2022 21:20:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B65A568BBF4 for ; Fri, 16 Sep 2022 21:20:11 +0300 (EEST) Received: by mail-qv1-f45.google.com with SMTP id m9so17247591qvv.7 for ; Fri, 16 Sep 2022 11:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=0pRbvpZKHvYp+aRrC9WxdCO3h7/5O+mMKcWqXWIMK9k=; b=MeBO52Py0/exX7fc81s0c4mAawOG2wzlRPWQuHUBuDG+Z1GkXmbPxpikdM2VmW2I3X l5uXKoh3JWGocq07OskkZt1pBkY4cK64Ym5q3/kGLM63RCzXj9q0Mx0GOYQHBAbrJqol +PJVFZRNJaBDMzqvw7ZU123fcVo0usYmgiVbW0D4/Sw9ZTBdJDrt/As0RKMDf+VJh/+J nmQYLRjuPr7QJMbLxqh0fum1NHJAe8VV8mrbdTwFb+JDUglb8OMrCkdS1uuapkEXMaAH 2OgF72ZVnPDqQcdfJLrVCqyOFlGtXXmU6dMNDyG7aMFeBBbdG/udrGnqIhoJVFJKcMrW 5caA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=0pRbvpZKHvYp+aRrC9WxdCO3h7/5O+mMKcWqXWIMK9k=; b=6K5SdWEI/XG8Ad5lmXuAZ+ftR5M0wW1xbfmPm3GUQ3U2xE2j/K3QBG5Q///TyAyaJ9 v7BIWRCE0OfdmjQ94rvH5s5O+XLmfDUPEmZy1kE4TPcxqkG1oe9+GwjfL0daS2tLvPYo jV+HKmzY4i7ACZha/aC0mPaBeDq53nPVbjtgnrgPZDb7YFe53tj9utJdfaSdvXrwW1Un j15S+w73mrOCk/jAlmvV8eJ8OCLmJQ0Ue8NfoRWQ/ZVe+Illz2Iv4QuKYiRo/JOTFzXe DCjGJx3I1N0pvEjybGojQ1CK9aG/rQD3d0b1St0KgGfgkICNLRJIvedmX/TTZYhlgwGf bb8w== X-Gm-Message-State: ACrzQf3hX2uvvaGKuQ+gC4e++qegPNYiKb3B1zlwnS0YAtpO2+ghBpOy VupAdCUXJ5hM3SJ3a20MX0hpJrZRgdI= X-Received: by 2002:ad4:5c6a:0:b0:4a2:6356:e6b with SMTP id i10-20020ad45c6a000000b004a263560e6bmr5087976qvh.71.1663352409464; Fri, 16 Sep 2022 11:20:09 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:08 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:56 -0400 Message-Id: <20220916182002.122699-3-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 2/8] 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: 2z6ZDd1vK0+8 No functional change. --- libavcodec/utils.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 2f57418ff7..d6ab21b1a0 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1006,10 +1006,11 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, } } - p = FFMIN(p, end) - 4; - *state = AV_RB32(p); - - return p + 4; + if (p > end) + p = end; + // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} + *state = AV_RB32(p - 4); + return p; } AVCPBProperties *av_cpb_properties_alloc(size_t *size) From patchwork Fri Sep 16 18:19:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37962 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139596pzh; Fri, 16 Sep 2022 11:20:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GVeKMR4TUYLDQ4wBRBbC+B1GZpGtpANLFK2qeRBCPaRU/xO/3KOcEM1t0HH0+MiKHUA3K X-Received: by 2002:a05:6402:d05:b0:425:b7ab:776e with SMTP id eb5-20020a0564020d0500b00425b7ab776emr5222266edb.142.1663352444685; Fri, 16 Sep 2022 11:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352444; cv=none; d=google.com; s=arc-20160816; b=B5R51xOm5zfH6h4emDxHXnXW3bIhI0ijiK3FORn09sUcSkDxMNBgWvBCPf1L/ita3/ RYOFqppjwaY+7PbRoQ/lHGFv1EnIxiFw6TUMa9EpRMh8powL5wVd4LNgU7BNliiX1gbQ K/IDvYufKTIzoSoRA8WYWkpWIVVv+SUqdbuoEgNUVvSM9YP+afPkupLyVS95PYW1QSzO 37XJ8GbP06+NBGIVYHdGU0zV6r3zMzqf1Ls0XNR/ycCF8F0tKjtoAzZj7YmHOa+rmI7h IK+PiZZ3PH+fJEgV0kArAZfDx77hv67yi6/8p3iKfXfkGHlKlza+h9nkmoM0NHIfbzuu a+LA== 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=qIauUZRix8RS0hgyayuP8bVkYeZs+DR4cD0GHP1l2cQ=; b=z3fRxLn/1xDHJTbMjQJUFODQ5dlL+XfqzJIfpqEl2eOzlGbF+P7j0UKmiOqtudsnER j5crX7wiX+fWZ0mGMDSgKJKXh439EHmlXd3CphyMzWBolumrr/2mqT/AdE1S3Fr8ux0F D/Y+IGj3JXrV7Fdc2hJ7QyYLwuWxZphRdj4g2cyE/8ty8BgqbBDP7Hu6t8LnTMuzsbV+ adQ03P/rHHUqe2yWMnZsLTbrfGpGIOVlVQynjdXzSs47pLEz/Ye4F4zOfvv8MHZPnPaR vr9SAJmXCjlBVGwQ5o4hijbpQNf7s/1Avef1ZG4ZSH9LGzYBUHi+6YAR4hB9493TVK6m kYbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HJOnKK0r; 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 nc13-20020a1709071c0d00b0077e6bd32780si12719529ejc.779.2022.09.16.11.20.44; Fri, 16 Sep 2022 11:20:44 -0700 (PDT) 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=HJOnKK0r; 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 2CDAC68BC45; Fri, 16 Sep 2022 21:20:21 +0300 (EEST) 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 744CA68BBF4 for ; Fri, 16 Sep 2022 21:20:12 +0300 (EEST) Received: by mail-qv1-f53.google.com with SMTP id c6so17239380qvn.6 for ; Fri, 16 Sep 2022 11:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=kIWquZzIEQsa9jU4vI/flF82u8sxxCq/p+lt+JlRtoo=; b=HJOnKK0rL1O0a4c2G4JX2j6dlxzDxFr+p2P7e3/d8rZDbZD41fjULWecge2k2xVgJN nSR3m9O1A3N8uCBGUZ/qOhDlUDcY8MC1OSLaHjod8YJF0s/gxLnc7pHRzK1U0vaKEPf8 mv9fRYTstj0OH/b9we2t/jHr5GZfzKV+y1ZcR2oqFwBAB8dChHQhzkcZWRlI64gWM+bA JQitR899BerrKhq25LgyBwIPdA7p+7g7c7196ORrWJ2YhrTUzKIyCFSNywE+Kv88/O/j i6tRM0950+DYuFX7DOr1jrcbnEO3n6U6LjwiCLeYNLedGsSSBolNH8X8So9R0J7DPheG gmFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=kIWquZzIEQsa9jU4vI/flF82u8sxxCq/p+lt+JlRtoo=; b=mOXxoFZiW7hluMpR02xfCS0+qfKIVu768Wc+VhdsYOgDUQrc8AWM/eiWb+R78wS+h3 SoArF8gg6JLhoVzzs5BjC/agablVQqHXRBDASbuvusZ/PnfBfU+rqBnnKg2vJbzWHBSo Bn4nBw5qhLhOdz6u7TUPLLP3op0f/aRtFSWhPtuOS6H+oNsfD7SUORHkvrIhZK/7kxfQ yNIXIbzB5Wwi5y0ts/Lk1vZy8oj8I3+HBbLLaVAyR8kXryCjKu0zLUdcVMGDDUyYsTYS Grx++23jizEu1D3JNDwqlyF85aLWKBW7Kn3bBpWHxAt/BZJmxsnsKb6cUlR+zj4JHn54 FXWA== X-Gm-Message-State: ACrzQf1BXw9tUewBGCnDGt/OCp0y7aIL0A4pXxzEatxI0uWTUGUj2KIE vlIqKw7PaIJXzjvFWGfL8bue9hyaU9s= X-Received: by 2002:a05:6214:5298:b0:4ac:c9f9:9091 with SMTP id kj24-20020a056214529800b004acc9f99091mr5529980qvb.25.1663352410973; Fri, 16 Sep 2022 11:20:10 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:09 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:57 -0400 Message-Id: <20220916182002.122699-4-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/8] avpriv_find_start_code(): rewrite while loop 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: Fg0yeLEl6YAl 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. For the check p[-2] != 0: This slightly reduces the number of iterations by starting with three new bytes on the next iteration, instead of keeping byte p[-3] which is invalid, since it is now known to be 01 when it must be 00. No other observable change. --- libavcodec/utils.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index d6ab21b1a0..fc8cd87366 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -996,12 +996,24 @@ 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++; - else { + if (/* UU UU UU */ p[-1] < 1) { // equivalently p[-1] == 0 p++; + // could be in a start code, so check next byte + } + else if (/* UU UU UN */ p[-1] > 1 || + /* UU UU 01 */ p[-2] != 0 || + /* UU 00 01 */ p[-3] != 0) { + // start check over with 3 new bytes + p += 3; + } + else { /* 00 00 01 */ + p++; + // p now points at the address following the start code value XX break; } } From patchwork Fri Sep 16 18:19:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37963 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139658pzh; Fri, 16 Sep 2022 11:20:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Gh0/fcSsmW0K0TCyP8thdYEihtRJdXCZp8GZWwPVYzlTgy8hJWb5mpeInkRTRaZRQfp7D X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr4537712ejc.208.1663352452856; Fri, 16 Sep 2022 11:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352452; cv=none; d=google.com; s=arc-20160816; b=X9cC7RjXCm9g4vnyos8Kat/6YzIGhNVA6OMCwwb+Qs0gibK/tcYikYXe/3lzsV7dKA 3YxFP59Rj7ye1qjn074TzGVZQjReFpean6a1gb9Pgzeavv4VfgXElb3QQP3tiHYsHH5h Iqkyy0rzYrJkJC/fXBNK2GplY2mnK7Fh8m4B89pU2Z60q9QaY7Pmc/fgTXQqHVZF8imk 827LU1wzrl9YRZKZ27dWKdQKmNVgZ/JsZhdZ8Gyh2nReHfYArXAwzLKJC032Rs3FAhyJ iD1sxaQiT9i/UbMwka4OIOm7FMirX0YIZ2sJbJ9W09D0zxR4EdGIaBVX9Lleja5On7Dq g3Pg== 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=Wwsk8PkWNAZu1MbnpARYmH5je2mGLCO3xKNHs8/0fho=; b=NeYsjE3ALYMEdpC0kj+ZEGUVbAfw916PktXCS9y8xIqmJhwQqKVcs1FjoT//2Mfxro Iwn+QwrbNa0/R9MKXTu48zTc1+hHuOHKO1kMpmaARqFzpOU1cTb4ct8bxVDPL4Cdfg1K yMIpE+02EO6/M0GCXwsj03AkC6iMkVEJW4+eESj694hPzEWpNLIphy1rk9rWOv8OHwx3 6mK2gpWB0eE6uH7i0+j4Mg1EAURQjkGG7UJY+f9+CFvaUMrHLmO0uVEaspT5Ymtdk8na X9bXFi+gykOzd4v7R3642q2bGBhnzuUf1CfXStHayGD4ozqt6tAOoT3L7OhDeLyhs//o WsJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NMpluhwi; 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 v14-20020a056402348e00b004467fff4228si3139305edc.567.2022.09.16.11.20.52; Fri, 16 Sep 2022 11:20:52 -0700 (PDT) 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=NMpluhwi; 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 3249268BC46; Fri, 16 Sep 2022 21:20:22 +0300 (EEST) 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 69B8C68BC10 for ; Fri, 16 Sep 2022 21:20:13 +0300 (EEST) Received: by mail-qv1-f52.google.com with SMTP id l14so8798443qvq.8 for ; Fri, 16 Sep 2022 11:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=pZJvhZtBz1h2InTg2uBeMmZse3v1WPSkmDH2rb8K9jA=; b=NMpluhwiZWZ5KOOpL88P3hUDaqQXgDVpkUWxIxagdgyBBiIdTaW7AKR0c2Ax0Yb49y egWT2i/5n6jpR8oe6dji7koucAZpkK9UVG7zT32/bvI1+1et7MBXL2mJNL5Z1EDzrqo2 4/E5OF1Ez3xfZQt2RHB8njArgYfzGw/hyCEOQZsguFmrXCRUu1I7VRUdI3d8sPOtJOeW B6/4SLWhmVHFooRtNg2x89dXkF7ed+XuGnZOK4LyEgkLBNzIG78X5YNGuN99XBi024Cx 6WwLqdcIjS/w0yVrubQTjdbo8J3yBln4v096O9OIZkDDN+V3zrKYBnQ0vwQfvVd/8S1e UFLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=pZJvhZtBz1h2InTg2uBeMmZse3v1WPSkmDH2rb8K9jA=; b=iGjQMURL2VID/x8POr5LN4AB13t1SRsA3f9RnK5xG78ANmedKDC7Nq0A2g7uUS5T+a bRZqcYCh8kxzBjCI2bgz4Wpt2w8EayhtYuUfB+fixNFuBIp3T2ZJcv1wuvzeFQCUoLrp qz99SeazXLJpxiPEBaqLJswmbIV18X7+SZ/5Urev8JJjJsoPO4H6+1E87mP1HEnJ8jmV ADq3xA+EJNrPD+p7wnh2W3txPRriFGlJjyseoyJgelkSndviOOtiAKdoT/NrNZH1M/qZ 2i7L6CAagsZiYrQcKcF2cASEtscjoTCWo/wJHrj6H48WYB/9ol7NJOwJlZ3piKgiud+1 6B7w== X-Gm-Message-State: ACrzQf2H35hDin/X7pNm/vTdsO5f9rf/FuCSRi6yHQKos3KqcoN8+ki0 gCSqOqI6HEj8mMHKqYr38hiis1Grqc8= X-Received: by 2002:a0c:dd01:0:b0:4a9:35af:ea49 with SMTP id u1-20020a0cdd01000000b004a935afea49mr5555785qvk.29.1663352411820; Fri, 16 Sep 2022 11:20:11 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:11 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:58 -0400 Message-Id: <20220916182002.122699-5-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 4/8] 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: parY1DQ+2tR+ --- libavcodec/utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index fc8cd87366..83f7d8a01a 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -983,18 +983,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 (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 Fri Sep 16 18:19:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37964 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139731pzh; Fri, 16 Sep 2022 11:21:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NYlcJlLP7PY3Oawqf9Fp5cS91Bpp7GksohXqaKvfRNEll/NUV6Eqi7u4Zjj6hLJA6x6q5 X-Received: by 2002:a05:6402:3603:b0:451:fdda:dddd with SMTP id el3-20020a056402360300b00451fddaddddmr4901515edb.81.1663352461811; Fri, 16 Sep 2022 11:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352461; cv=none; d=google.com; s=arc-20160816; b=QSwIbVJkYC9vf89qFOiHv7QfnVT+ZpRBrHj4EfDOahHg5geCIpxGtlLHMZOh9CIeGk VPjb8f55I8rOydwaXlmiMWoZnn4rnczD40iOSG44wDGMWHhlPea/ZEjtdze7//6alYYw 2Egn0MFIEpuXSQdPqQpvX2YahwKxbX88Y5Dmj0OSusT3Nti2QvOSSMjmtsjwFFDEKBQN nwgMgV/k4Witn8NslKyN2UOnxHVKd3bO6GOTp1/h+K21ee2GHYMGoe0Ve2e3Xu67NcPo lCXYXMO1mm0UzJ5oetRo4asfWaGoYc+oL2YK+RwdDXHehp2ZJMfI71DRIqz53qcnvoFj TfPg== 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=eKJgJR3DwAM2QKxKuVf0TtzRWDRbuidTNY63iGR4NQU=; b=J5K5byIt6B5Hs78+wcqF/qG2HXO5hgfeaHCGcYktyTC5S/sSvm11JQmsa7fe1+5+7F CxMplE0FAYfnfxZ7qDp9VAdEzbpItKoa3DFVl+5TU9xCMoIN9dO5C0o4Vakgt/88dwic /bc21O9dOyfM1n5IQfxGfxOyMRzTNijSkz5v0qC24bDKviX/Jxf+D2GNCFecva9iLD6q sZVS+/EJ4/o/j4yTk2OgvHdnBo8DWrv3nUYY8u6csDHOyv2oKZ/aYeJgMrFO1fA3rGch 6+cRtLComAaGQS43mveN2xweGPZ8oCbH3GZPKynqLzybQ7ZrkW96zdkSHeLUizpgYO+z KcXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nNqsWrzR; 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 o14-20020a170906974e00b0076f0940cb28si18845914ejy.175.2022.09.16.11.21.01; Fri, 16 Sep 2022 11:21:01 -0700 (PDT) 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=nNqsWrzR; 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 2F27F68BC3D; Fri, 16 Sep 2022 21:20:23 +0300 (EEST) 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 3464168BC3C for ; Fri, 16 Sep 2022 21:20:14 +0300 (EEST) Received: by mail-qv1-f44.google.com with SMTP id y9so17239401qvo.4 for ; Fri, 16 Sep 2022 11:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=uD6/b9tjwEMPSw2SBahE04GAlu08JFfPkFc0VGn1WL0=; b=nNqsWrzRTpQvJgIoGpbdaUgxbJQKDQf73d4vVka+e+3/vptDWMjuCwYnzpu8iJrwWk sM1Vwn/5dMYH5tkXxRyWqsCu5rfPW6/k5QVCedsnVzDs4kQbi5IHsP+f4S6PgkN410ES Km7SkE2oUaZ8UHhfgd77u8aKt/dp/AC/r3uteABS1EXokygbW2hBQmS3QICZdl76tUzi q4eIxHwl8I3cxnou8WY77CfPAlszlO8EzAQF2shBsuFAvEF99wdMBvdkZGHw7oQ3NGwd uQ09IqSpVQn/qseu5D/gtRbHlhKmgjjfEgm9twh6a9uD3uPt0+02fG1L09IQF/suRdrJ N7sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=uD6/b9tjwEMPSw2SBahE04GAlu08JFfPkFc0VGn1WL0=; b=Jrz5FW9dZeqEBli+BGMy/YsDEQc3WZgl+KvuGIkQHDPzmFEou2rBL8aHL860bD3nIY ORtt2Y/GtS8Z66bKXsUr9wDQpW959tXKgSX/T++T3/YJUf4pmifXKe5mupJvj6dUqvG2 1n8LKk9st0DyX3Yk5cP+SBb6TR02vOF31WuewcjDKuz66/PyCQrvOb2QoGRkgK5QMVTC /hKo5ggkBtyJJy5/YEL8gY5pA5mnUG6pP5qjeR7QuVcaOgrLqWhsC+aWzDLY4Yymfpqy XbwXwhGQmnPAo4OrUSsMx+PWq1spYNI0JFOGI8STI4QOUPpnubHbqY/nkHfQtDbT70wr vtzw== X-Gm-Message-State: ACrzQf2TQF2iFm/ljr6supF0YQt96oZcrHvr9uANaoeeXiu5rAQgYNyg ohdr9/cOu6QFPEwTsUj2NB7k6LODaco= X-Received: by 2002:a05:6214:1c88:b0:472:a7e2:bef4 with SMTP id ib8-20020a0562141c8800b00472a7e2bef4mr5411690qvb.32.1663352412672; Fri, 16 Sep 2022 11:20:12 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:12 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:19:59 -0400 Message-Id: <20220916182002.122699-6-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 5/8] 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: gGTbS8ATqICP --- libavcodec/startcode.h | 26 +++++++++++++++++++++++++- libavcodec/utils.c | 10 +++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libavcodec/startcode.h b/libavcodec/startcode.h index 833754af09..69389c729c 100644 --- a/libavcodec/startcode.h +++ b/libavcodec/startcode.h @@ -44,9 +44,33 @@ static av_always_inline int 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 pointer 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$ end - p < 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 ff_startcode_find_candidate_c(const uint8_t *buf, int size); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 83f7d8a01a..63bf4b8cb7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -981,7 +981,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) @@ -990,10 +990,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 (start_code_is_valid(*state) || p == end) + if (start_code_is_valid(*start_code) || p == end) return p; } // p is now properly incremented for the negative indices in the while loop @@ -1023,7 +1023,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, if (p > end) p = end; // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} - *state = AV_RB32(p - 4); + *start_code = AV_RB32(p - 4); return p; } From patchwork Fri Sep 16 18:20:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37965 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139803pzh; Fri, 16 Sep 2022 11:21:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Qc6U4IGoB0gJJC2mS/uTyKbyexkkouKL1CHe0koctVJXjQ2GqNaK5/JatI0iS4MRIlO9d X-Received: by 2002:aa7:d5d0:0:b0:44e:f6cc:7107 with SMTP id d16-20020aa7d5d0000000b0044ef6cc7107mr4910466eds.371.1663352470323; Fri, 16 Sep 2022 11:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352470; cv=none; d=google.com; s=arc-20160816; b=Spfnp9G/hATXllQJYRqHbuXGyTWhZ5dlPHqfiEKyWTVhCrNuk4yyCLwG0vngN0hquQ 4H/mb6lMro+aa2WDFQ4AtlC0nJGb+id8cq8qkDw0DMM3ur2Ll0EZmHtvIbNZzhC8UPa8 FE/Y3F46nmoMxrIUOurT54gLtBZ3BZ6SlUlZZHigQXRUrHJTAepp37edGF/fUJxcVULf UnMiVDvM7NwGGDfGxSR9l5GWIJwciGienK11dZc179YN7u9Gh3LXVtVqzDBDoUtpywJC Pydq9B12BEmBxs4AxZPOvugErCfil6qQUm9jZ+VilA/tl97UgaFISChAzbiUuIcbrEnF zMow== 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=nP/o64dssqhvuARi7wHAHsJRPo75kzR/Ml94B9b2bXU=; b=ZfaXnEnIiaBXbhCfee6JYXmTc8CybsXtL7e+EBhMiq/4jTbYgLyzzGuZuETSRbA18/ RuAgQ6+bOHsyuzNuWimsSvStBbq0tv2H8/W9UAkqV6bQhU6JheT5CceQtfv/zBc7P2tQ Ht8z2yGx3oXtc7Ek+6jIbgVgHkcfSFSbdWeCAwZRUDQHYcH4sfak8NVUDRdyE+BnjWkb gAT5IRu6DVmwv8uCS6ifjmfB8K3nRuPbNzJMKHvSbX3NYwINzbWV4PvZIlS18c43XkeS MVIcdiOlUrvc4DglaNvhM5YBiZ8FYu4jz1xkyj2YczFMEZqgdjpbJZ3Ns57dVXOUi+Gn MHjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=aYoPKm0M; 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 ww4-20020a170907084400b0077fb99b8cfcsi10266082ejb.301.2022.09.16.11.21.09; Fri, 16 Sep 2022 11:21:10 -0700 (PDT) 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=aYoPKm0M; 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 34A4D68BC0F; Fri, 16 Sep 2022 21:20:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2694368BC41 for ; Fri, 16 Sep 2022 21:20:15 +0300 (EEST) Received: by mail-qk1-f171.google.com with SMTP id q11so13301587qkc.12 for ; Fri, 16 Sep 2022 11:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=U1sdmHzyX7mYQQj5No0iIsfHzOL3gLnOWImNF88p51A=; b=aYoPKm0Muta+OdRHSvPnrI/hp0s9snqSxetIVLhCaYX1bQ8z84mJhSHP7UFU/3NyQ9 cvq+pSq8hDOxX1il5e3Iz3YVCWqRRuI04pm6Tq8C5D2aCLcNGyBwKDViMWi6YH85E5mw xq9tv+BaS3mp/lgt5mqeHXBxr/lO75VhScMcWSMKbqvpXNRm2Zxmgk64b7s1NHu1cFU9 +i/Y+z4gcP5REVwpgjQQ6g93dK/V++lX+yeYCRy3dvxQgWt22wYzFGtMkfd6zQUYJHd+ tcMUdhLDOlGnHCsEdSE8s8OUXViIjEY5T/Mcz1aiYpgSKlzqq+jJCzrfjYtGeF/QQw96 AqWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=U1sdmHzyX7mYQQj5No0iIsfHzOL3gLnOWImNF88p51A=; b=rBGZBJx3CPj1yv20E0oipJn4zZeWYiZiNRYjH1s/mIUVE1wDPDBmafIlfQIDFwZCER iAFcP0oev4kEg3wzxlax15PW7lYBHGPZOOA2f4VBP2s7y6Tj6XeVvA3D8VV7s7Rr4obm lUdNtyUObApoQnB/rzbdI9lWcIx9GVB8OWfVeaKA18XmM+O1M7J9OzerBJi3sSSd8BoO MM0l8/iBdhRbno/Pen5Z162+jn2zKEDKutw98X+6N15lla3ZpNH1ymO2sWszFFvL5nSI 1YsHfm//sSsV+TNCEG8mSWqYiOpFb/mGO/BiHDVTqGQE8cD/4gwdsSEDYz2lX8IbCrxX XpRw== X-Gm-Message-State: ACrzQf07tcEGRe7euGnzGwekF/+XmRSALAfKuhIHNZ280jYOtOpNcp8E OTrMQ75ZN8CUieY7j/iPrJIdxC9eMTA= X-Received: by 2002:ae9:ed90:0:b0:6cd:ef01:d3fa with SMTP id c138-20020ae9ed90000000b006cdef01d3famr4898390qkg.168.1663352413554; Fri, 16 Sep 2022 11:20:13 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:13 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:20:00 -0400 Message-Id: <20220916182002.122699-7-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 6/8] 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: TSXd8JMO9M1K --- 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 b857353ab8..6a7af91fad 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1746,7 +1746,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 8b6987b7f2..9c0816ef95 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 (start_code_is_valid(start_code)) { /* New start code found */ From patchwork Fri Sep 16 18:20:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37966 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139877pzh; Fri, 16 Sep 2022 11:21:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4PdkFOfvxLvapZZa9Y+6Z6ax8RZuYnU2jX7VS7wfngpr6BkjQQQvG4Id97vFB+eu1f9MMB X-Received: by 2002:a05:6402:f27:b0:452:3d5f:d186 with SMTP id i39-20020a0564020f2700b004523d5fd186mr5077865eda.348.1663352477965; Fri, 16 Sep 2022 11:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352477; cv=none; d=google.com; s=arc-20160816; b=qr0b67kanL+JhucYacYdHozq1oK/Z5HpSn2U/l5EptVeLHaft1YNYPJhK1WjG/GEiS hW9TBmufnRUgwvWAW5ZcgC6MRHNPpUxncvSjBpoOQLcBHrXrTPKrBZ2r1AimKqLAXo3B A5eaOKz3pXIXXkFCpc68pfINYXed5GEZgpFM1Kv9xwXJpjp19MQ6RGCGINFAr6iC5+VW yLGJOwk6/Ez6Tn50F237Btm4F40EBI/LnGk2ituvhIHFIrYj9UcJL5iFQFNlAVaMwEKI P7SFeoOEaQ5SaMse7ifLo/sefjD1KqinrTQoyVNsVrbdBtVODhS2gRcvKaAgNoAoFQk7 PnxA== 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=86SGCXQCh2MEjo6ljWxPKm/EQAUZY+1g0sPT0pGvg+0=; b=UQMCGRFZjiZLtJobEEoNRrx/9buZ25h0+QinhAtMjcRYjvEyMi+yoCsJmHxIfljBXl fblJFFxSt/ZhRxXJgmIAXGB/Gc+TcU66YQEelqguL4Bdk9OufUxjMyxnIYmlLV6YKcrT d7aR6k0fSMMUCHgmxU8m5eNOnxx/CqRUXpedDeVWIm1+Dv+SqDUz69GXgnI7UCHmdbej DRmVNZYVG3Cwr8RZQ6bXzcviFMfMCGyFuBeO0hI9HDZb1agjsRhOf/0ArPL3cKSEoyUH 7y9G9mKHBSh36S7a+CeHfYbKSero6rTKJTuF81RJkfm/JgZNWKb9d+9FQl5/AFglgA85 8ESA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=mnynAPCR; 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 nb16-20020a1709071c9000b0077d79066580si12823864ejc.331.2022.09.16.11.21.17; Fri, 16 Sep 2022 11:21:17 -0700 (PDT) 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=mnynAPCR; 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 2EDFC68BC41; Fri, 16 Sep 2022 21:20:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0BCF368BC45 for ; Fri, 16 Sep 2022 21:20:16 +0300 (EEST) Received: by mail-qk1-f182.google.com with SMTP id g2so13508988qkk.1 for ; Fri, 16 Sep 2022 11:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ZPNrVnHsMAgaNqJ6bMlV3k25Y7Gxanjhy31HbviZkdE=; b=mnynAPCR5kCTPhJKdIXFoEog9Y/mDNTF765Q4tGsqOGJr6iBhKmaq+o+8a6NLktUW3 xjzJp69Id1vKQfwFxSgDNsEsKu6Sx5XxCpNijUw/FK9ETO7QKLqfK8vs7AiHBQnzPC7Z YOxfa04dBpeLwO0I+RbgT8qoEJYQ9NvnHmhn41ZB9qe4zNf5c3yIaU4x4Ji6DcxV2iwM Uq2ERRcCEP4BcjJRsF67p3q3p3Nnm5XFNtjiUfEEQBGQau4XPkX8xZZ+bbTzn8SZOeB6 ckXHlefVZXgN0artDSvS7bWsZItkDa4J2dlkBypFbj/Ls0s3JSv0FZ3Z/LAC6GEJYYob nnPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ZPNrVnHsMAgaNqJ6bMlV3k25Y7Gxanjhy31HbviZkdE=; b=dn+w5Pusuzw3PLfIhGQC9NpL8G3NW4dZWxJUGD8/WYbOIDoSvpAos2RxgtB1PsZQ/m 3dQpS20Dpov8aDVoK8cl/PhDXL5dmsdNGqB0K5inWRW2H59oXEiR4ayQV/FTZppt4lrD EnhJKBeNS9cIQ7ckKcgTSY6ELuBknVJvqH40jgyT34PBuzdPuCBIw135m62AxYtujz0o yRtVSxyWABSWhBE2A6pm45MYpzWDcum940wki7X06rT/M6ldkOWilujevatcUeT2LEfs 8bhuISBcHB9d4cANkW/hsfZwmL04nVOEUZ8a88+lAVjBSKUZ44zbSDryRMFr57IRhL6V D3uw== X-Gm-Message-State: ACrzQf0bl3WZKyAAEJb+BePr6v9qGwIqaG3ldx9qq98vKyELIPVAljgs 1UqFrOBDnmzgIJ0UfdZhThquYdF8j8Y= X-Received: by 2002:a05:620a:1721:b0:6ce:78a7:daca with SMTP id az33-20020a05620a172100b006ce78a7dacamr5044379qkb.487.1663352414520; Fri, 16 Sep 2022 11:20:14 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:13 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:20:01 -0400 Message-Id: <20220916182002.122699-8-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 7/8] 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: wfauQqjTi7o6 Have the compiler enforce not changing the addresses these parameters point to. No functional change. --- libavcodec/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 63bf4b8cb7..0635c5dcaa 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -980,8 +980,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 Fri Sep 16 18:20:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Scott Theisen X-Patchwork-Id: 37967 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1139966pzh; Fri, 16 Sep 2022 11:21:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5z/KG5ATXyHYpdhuugKiefazs1qr+Dhrn9U3oxMtWBnlrDn8m1WTylPuqsJ2qSlaL4W/1l X-Received: by 2002:a05:6402:540d:b0:450:bda7:f76e with SMTP id ev13-20020a056402540d00b00450bda7f76emr4911253edb.249.1663352486915; Fri, 16 Sep 2022 11:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663352486; cv=none; d=google.com; s=arc-20160816; b=aWazFgTB2r9a/UU0B74rVFv68jXNXv4OetetWEVDX3LRUGSsHNzCXE3J/dVUUNKniT /jfBVOTBkUK4WWijiTa4UUXrhQfv8nYNTobqX3ck4HivQOQV2YcEPowsj5ET4LwhxOFQ pkX33Q87wHAh1qJbAXaBWH9G29hrQsa959MJwSzb6iNeZo8SFmUz6G1gWpjAZmbbBSB7 O66SSoNRLd9uFx04j9txMwQdaVop114WFflWOJwvJHxODrEAvA2l4cHZmwN2Z4f2s4BR EDIGdZa7B7Cuod3f8Cyc0PBRpgkfWqPXbFJTt1wlZF8bvr37kyxjgYXSSxsyFXxSi5kr MaAA== 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=sHQ4CRcjZyRdW0VoSixzb0hSdKN7VzmPEqjoWI92SpQ=; b=ikyOREaJUsjnVYplgI1WObyadVVbVzWmyojymvD8Ma3kToq9IY9u42bUgBiwuYJ7EP 7ff/Kj+p//x0Xdkc+4qqkzkjV0gZDG/NK2oSIkS8wuJy+FEdfxT/yK4+rYslZPXc2xxH PfhgBLt/KhBehcYORZqJAmpzFZB9RopYgGF+vgLnlvb4fGL9P7hTc7ND29JPCP1jWTBf 9qZ74WtQEiuoeCGk0BHOqiNHkL2WjGHYEPe4fStz1TFpvMTKwetvwPy6kOkK7LwyYm2e yOfbyGh0pNlKXIRoKFH1i7Qk1Xrspa3E1TVEPOR5rN4G9Ept5e8Tm/8CTptYyKhzHs0j 5QeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dNEMv8kr; 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 qb25-20020a1709077e9900b0073d8a8fedbfsi17169114ejc.386.2022.09.16.11.21.26; Fri, 16 Sep 2022 11:21:26 -0700 (PDT) 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=dNEMv8kr; 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 1691668BC5F; Fri, 16 Sep 2022 21:20:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F286268BC4F for ; Fri, 16 Sep 2022 21:20:16 +0300 (EEST) Received: by mail-qk1-f169.google.com with SMTP id d15so16335046qka.9 for ; Fri, 16 Sep 2022 11:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=OZG+38/taxoWLn6M5z3ejPbiIbNKmtBIXLBQx+qsbPI=; b=dNEMv8krf+a6nT4oZmFwXFMdXotC88fPOU0U6Yox3MugEgDkICNbD4u4aPFzV2mkc7 J3aVXaOqETMJU3Txccy29Ik6YkajphnZA8ElkcQ+huwcus/ranENOOACsFg3F7eIjqwm MrYEsRWEV3pH6PUDK3r/bYKz9IfIDjPi54QJgbZNeZxK/5cuMkYKWNdnsa3thPxm3E/N rIbeEbofKqxIdso4cHFpZuTiCEo2Be3m5lqQP6XT8LsJ2hqIFw693LXDinuJK/xvQsVR HHF0E+Q7oJGCgt+A2TxoAd+Y7jZ+eK8dyRqX1S5jSYrNp1oFnnV6me+/yIuwkgLpnnDP 25bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=OZG+38/taxoWLn6M5z3ejPbiIbNKmtBIXLBQx+qsbPI=; b=pdy/W3p+NOtIfLvknhtukcypkF/1BrqQSrPPwFrSnqvALHeCBfUg1lyIZZNL86WMkj yYcMhNR/wHmZpUjUYhfN7XM41Za3IahD8ZJrwYtvUva5LdeLDJaMytQkzTP7L2Sa3q79 hviutgxZS20HJfkhmLp/JuC5bnhebf0qd9XWg1wGQF8/2hz8gkEByGjGW7qJ2FIESZuz iHbvEUo5EJSCzb6KWegDfHTR7Agnq6szfeXFKT0JmUa4paQEjeF1p00ideQWa5ZoHpN+ f+CchewDsriMepVeZ71cY1c7xfKsMrMWWDIj+pyk39k43ZWdadz9BNad85Blm+VMtsR1 8dcw== X-Gm-Message-State: ACrzQf2N420wOoS8EdBH7+N4f64phOeSdJI7vkWjIX1HH0l4uJRiL4Gd gysZWwm82VIAZUdkQfeiCrTTPjt6ZpA= X-Received: by 2002:a05:620a:129b:b0:6ce:6ba5:74fa with SMTP id w27-20020a05620a129b00b006ce6ba574famr4888656qki.85.1663352415470; Fri, 16 Sep 2022 11:20:15 -0700 (PDT) Received: from scott-desktop.. (pool-71-114-80-52.washdc.fios.verizon.net. [71.114.80.52]) by smtp.gmail.com with ESMTPSA id l10-20020ac8724a000000b0035cb9531851sm5148098qtp.65.2022.09.16.11.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:20:14 -0700 (PDT) From: Scott Theisen To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Sep 2022 14:20:02 -0400 Message-Id: <20220916182002.122699-9-scott.the.elm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220916182002.122699-1-scott.the.elm@gmail.com> References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220916182002.122699-1-scott.the.elm@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 8/8] avpriv_find_start_code(): make start_code output only 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: +Go6nUzWDTx9 The input/output functionality was used by only (ff_)mpeg1_find_frame_end(). 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. There is a slight functional change: 00 00 01 00 01 XX no longer incorrectly returns a start code at offset 7 that overlaps the start code at offset 4 if the start_code input is not modified between the two calls. --- libavcodec/cbs_mpeg2.c | 5 ---- libavcodec/h264_parser.c | 2 +- libavcodec/mpeg12.c | 41 +++++++++++++++++++++++++- libavcodec/mpeg4_unpack_bframes_bsf.c | 1 - libavcodec/mpegvideo_parser.c | 42 +++++++++++++++++++++++++-- libavcodec/startcode.h | 14 +++------ libavcodec/utils.c | 16 ++++------ libavcodec/vc1_common.h | 2 +- libavformat/rtpenc_mpv.c | 2 +- 9 files changed, 92 insertions(+), 33 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 23839ca47b..fd235a43a7 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -160,11 +160,6 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, const uint8_t *end; size_t unit_size; - // Reset start_code to ensure that avpriv_find_start_code() - // really reads a new start code and does not reuse the old - // start code in any way (as e.g. happens when there is a - // Sequence End unit at the very end of a packet). - start_code = UINT32_MAX; end = avpriv_find_start_code(start--, frag->data + frag->data_size, &start_code); diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 50810f1789..b67830d40e 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -69,7 +69,7 @@ typedef struct H264ParseContext { static int find_start_code(const uint8_t *buf, int buf_size, int buf_index, int next_avc) { - uint32_t state = -1; + uint32_t state; buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, &state) - buf - 1; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 5ff1830496..9e3c7e5814 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -166,6 +166,45 @@ av_cold void ff_mpeg12_init_vlcs(void) } #if FF_API_FLAG_TRUNCATED +/** + * By preserving the @p start_code value between subsequent calls, the caller can + * detect start codes across buffer boundaries. + * + * @param[in,out] start_code A pointer 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$ end - p < 4 @f$). + * + * @sa avpriv_find_start_code() + */ +static const uint8_t *find_start_code_truncated(const uint8_t *av_restrict p, + const uint8_t * const end, + uint32_t * const av_restrict start_code) +{ + av_assert0(p <= end); + if (p >= end) + return end; + + if (*start_code == 0x100) + *start_code = ~0; + // invalidate byte 0 so overlapping start codes are not erroneously detected + + // 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 (start_code_is_valid(*start_code) || p == end) + return p; + } + // buffer length is at least 4 + return avpriv_find_start_code(p - 3, end, start_code); +} + /** * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 @@ -200,7 +239,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 = find_start_code_truncated(buf + i, buf + buf_size, &state) - 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/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index 3a3aad795f..dd351d9d0f 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -36,7 +36,6 @@ 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); if (startcode == USER_DATA_STARTCODE && pos_p) { diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index f5afa95981..d76e8ba069 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -34,6 +34,45 @@ struct MpvParseContext { }; #if !FF_API_FLAG_TRUNCATED +/** + * By preserving the @p start_code value between subsequent calls, the caller can + * detect start codes across buffer boundaries. + * + * @param[in,out] start_code A pointer 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$ end - p < 4 @f$). + * + * @sa avpriv_find_start_code() + */ +static const uint8_t *find_start_code_truncated(const uint8_t *av_restrict p, + const uint8_t * const end, + uint32_t * const av_restrict start_code) +{ + av_assert0(p <= end); + if (p >= end) + return end; + + if (*start_code == 0x100) + *start_code = ~0; + // invalidate byte 0 so overlapping start codes are not erroneously detected + + // 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 (start_code_is_valid(*start_code) || p == end) + return p; + } + // buffer length is at least 4 + return avpriv_find_start_code(p - 3, end, start_code); +} + /** * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 @@ -69,7 +108,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 = find_start_code_truncated(buf + i, buf + buf_size, &state) - buf - 1; if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { i++; pc->frame_start_found = 4; @@ -121,7 +160,6 @@ 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); bytes_left = buf_end - buf; switch(start_code) { diff --git a/libavcodec/startcode.h b/libavcodec/startcode.h index 69389c729c..7e1df68a3b 100644 --- a/libavcodec/startcode.h +++ b/libavcodec/startcode.h @@ -50,20 +50,14 @@ static av_always_inline int start_code_is_valid(uint32_t start_code) { * 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 pointer 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$ end - p < 4 @f$). + * @param[out] start_code A pointer to a mutable @c uint32_t.
+ * Set to the found start code if it exists or an invalid start code + * (the 4 bytes prior to the returned value or @c ~0 if + * @f$ end - p < 4 @f$). * * @return A pointer to the memory address following the found start code, or @p end * if no start code was found. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0635c5dcaa..2a6067ca4e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -984,19 +984,13 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, uint32_t * const av_restrict start_code) { av_assert0(p <= end); - if (p >= end) + // minimum length for a start code + if (p + 4 > end) { + *start_code = ~0; // set to an invalid start code 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 (start_code_is_valid(*start_code) || p == end) - return p; } - // p is now properly incremented for the negative indices in the while loop + + p += 3; // offset for negative indices in 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 8ff9802a51..ac8dbe3fb6 100644 --- a/libavcodec/vc1_common.h +++ b/libavcodec/vc1_common.h @@ -57,7 +57,7 @@ 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; + uint32_t mrk; src = avpriv_find_start_code(src, end, &mrk); if (start_code_is_valid(mrk)) return src - 4; diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index 9c0816ef95..dbd4acd474 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -54,7 +54,7 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) r1 = buf1; while (1) { - uint32_t start_code = ~0; + uint32_t start_code; r = avpriv_find_start_code(r1, end, &start_code); if (start_code_is_valid(start_code)) { /* New start code found */