From patchwork Mon Sep 13 13:53:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30210 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp4020894iov; Mon, 13 Sep 2021 06:54:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSkXiAToV7Nd81orGV1Zp4gNMvbU3HdeQGu7StaS5LEUZwOU2MXuKeaxlJQc2cMAmoJeLO X-Received: by 2002:a1c:9a85:: with SMTP id c127mr11254578wme.174.1631541248138; Mon, 13 Sep 2021 06:54:08 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s27si7139787edy.251.2021.09.13.06.54.07; Mon, 13 Sep 2021 06:54:08 -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=@outlook.com header.s=selector1 header.b=YBhEAFy+; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A137768ADF2; Mon, 13 Sep 2021 16:53:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075032.outbound.protection.outlook.com [40.92.75.32]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6ABB668ADDB for ; Mon, 13 Sep 2021 16:53:51 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gcp1dr/I1iR6VY7sdD3zr019B+aP6GlOu4sIvPJXjmIbk42VXSPfyTTHRB9TSWBQ/0/R628azbJFnyAObDonTuxw6UDKBgtMeq1mhfcEe58rtCFYJxpdnlLglFhzmMmjs5duYCNZIM9Xcbaq3zq1v/+M6YEjNoWdjfIFNPIkMVA+a1dulC0gKINE8H9tVGfjGDAJ+fP3Q36YEvVHhFhHCy9LEYssG6YYQoLRbHdez+e58mHmZd7b6X0ag+e84GfDonctQFNtYy10uMGqbPF6VejrpMp3TpFA2kEBG0VP06rIFmoIMhV6v+YtlZ1exEWQKSXrX8Vr2CWnWwj+jkAYFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xbvn8JRcy+0n135Ra8xHomgC5HzHgKdkguRQDtBQ51o=; b=hbRyB1GH2in7+KGI3BqN7hR1hdmHVNbcxqVPqDR8CAts2wElJkzANv0O3KXLfTQ5X2q0QTSunQP8lFT7JErmx2fp+pdAhfBoRH69Cmui2iNeF7FCOu8nWQ7J4qYksOVjU3tz9GXdH0uLcpMie+q/VCQgvhHg2HPFAbuTKpDvGZMRG9IMR4L9y2qGD//AzWSWwsk/N3SzKc3cdZjmmd39P9ycye5e+hi86bq9Ggwi1dL4kAKDw0Fzu5vbc8YGCAZ6fIKAh2+aD2BoL7CsQs3mKOUcHXS/ZgiaeREqkr5OcCqRSek3+21AAd6RjIdOf6IURoZHPf0oy6L7jal5+RCIHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xbvn8JRcy+0n135Ra8xHomgC5HzHgKdkguRQDtBQ51o=; b=YBhEAFy+vfbaCk2D0nuhmwI8r2dbaMgQHUjIaTaWXiZijBC/hFcLc1zobKfcs1lfRWht/AlSwbrAt/dtkdTB2MmvH12TujBvwTi7tIjsTBZ0FV1n01H7VzxXOC2Gjd1ooAs+6vPiUUH+85rUvvXSqH5xXJ0ZCcftCNaYOYZGR+PHaJviyS0XUTLgMKjKHATY9tWvPzHGWXHUmToXkBYsoLVgiHeraCAHY1yKz3DfDT11rgWSNxSkUotjou2Z1WZ9adJmSwhA9CSNwAzaC37WTtAYRCLRCNMVKFuRSD9tPC2YjzGX1dHU3Jyxcf0Sp+tGcvx/K2I49YhmIXaKKXReCA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5299.eurprd03.prod.outlook.com (2603:10a6:20b:c4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 13:53:50 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00%4]) with mapi id 15.20.4500.018; Mon, 13 Sep 2021 13:53:50 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Sep 2021 15:53:29 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [5OnJfHB1m4d7Q4Zy2ZoLEnofgxiO9QfE] X-ClientProxiedBy: AM4PR07CA0023.eurprd07.prod.outlook.com (2603:10a6:205:1::36) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210913135336.2804405-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR07CA0023.eurprd07.prod.outlook.com (2603:10a6:205:1::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.8 via Frontend Transport; Mon, 13 Sep 2021 13:53:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9188c6a0-0908-47b7-5acd-08d976bdea17 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXSr2fKdz7sYpLFthH+Nsypl+U7fg11j1qFb9w76QluIIJFHTxEn3unPwL84up6ZH4j8oIKXK6KEYcUwnh7ldjkY03JAk70n0Dj6s6pw4cVG/EAMJsqjwceg/4seKrliTsfQuFY/KCmbyRmKK9e8C0UF/6uquZ18aLSvVvuR5pi4V8GOTXYQE1wEVx4Lp1uhoQGbX1So8RaYSGXf8Q4v10ySXziRkKDgTd7GVkGF7MNgdCI18Uf2d3eTc5wjSW/WGEI1FEaONgzDHPuhoj8stUOX9rVtK1eOr68Lmm+gl/fNLnLFX9ggOhUjGurvLAqEeUy9iaCfjSuQQ/Iyzb1mZIUtpFNc76GK4gMYzoGjQyDlnn/hvjaNF5pEQS49nc+m0XUo42ibbAAsSR1BnUPnJ7OHbor4kzpH0o969pqXBjZsXpgqg6Yi62l9e48oAAFJt+f8sFjAHNuA6fGBRmLxEivalaQNB5jIlMo4UyfcPHeLcgcn81d7hm4/BUNqWaYwYyXyQClXQr2nA/las53VN5ihLl+3Qq2gRkgDEHAbNVK4oiA4y4h9wM60dsdsXLlEsYooJ3VbcRTWjSF3NCOd2Or/QOehtWvBrzND6E6kpoTPO+Q1y0nYyrw9JjqxUu+sjcsVsePi2PkVT1tu2x5pYhSes6DiFTo7mDll5bwlc32YuaNrY+jtH2XvkPobD9ehL51wfOtQLQU03F8IrcxbxVt9Ozmdap6fm0= X-MS-TrafficTypeDiagnostic: AM6PR03MB5299: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ow6/mZfIzuf7aPw90i+cBTq5fMSear2KjYX5IIEVTMTnlY77fj1l+vbcbqbS30rPI9dmXNHEFJt5d/rl5C+jRqBISr05YGpUVmF1sQ5tN6Jrvoae8N7+CsU95go27+nZCbBSFzGkjrjLQVWyXnY0lOVrbLt0rUJo/mvKVRhIwubQVcamvnvewwCbIUkEqmlNceEGIKhonnSWX9/YgjoC1atdBHz8q6xx5usq6rA34YvAlkY2rCPwmLASGxVc9w6dL7s4MQOcpeyKf+CU/EexLK9pCYQ9VVobsTsnJoQYmQ9KReVtfORimHB7CGoE0cGVZa/mTXuVmb6syBOV5UUbN3LtWErlbutEG282vtrJ+ut9WHoKscbj93fKAgYGxCUYQeo1n3CuVETDi8qNBwmjeyn9CvRIfSCIU+/ordAjv1qa50VvKwlnA8ehCrGRXWJ9 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sJ74tezm2zx43UYRwuB0nTAIzkvHeTWhwGVQvnJ7anmk0/Ez5RQ15+ZQ48BThssl0hWW5yhVukM+hSJVdrj9huAkyWfxHSMFlIWMfiQmv691UIDeyYm4ZAMXBsT/qIo1XEUj790Us48W4jnsoOCHDA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9188c6a0-0908-47b7-5acd-08d976bdea17 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 13:53:50.0729 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR03MB5299 Subject: [FFmpeg-devel] [PATCH 03/10] avcodec/(h263|mpeg4?video)_parser: Make *_find_frame_end() static 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uGuTgphUVb0o Signed-off-by: Andreas Rheinhardt --- Could be merged into the preceding commit. libavcodec/h263_parser.c | 11 ++++++ libavcodec/mpeg12.c | 2 + libavcodec/mpeg12.h | 2 + libavcodec/mpeg4video_parser.c | 15 ++++++++ libavcodec/mpegvideo.h | 2 + libavcodec/mpegvideo_parser.c | 70 ++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+) diff --git a/libavcodec/h263_parser.c b/libavcodec/h263_parser.c index e05b8a4ac4..7a742caa80 100644 --- a/libavcodec/h263_parser.c +++ b/libavcodec/h263_parser.c @@ -25,9 +25,16 @@ */ #include "parser.h" +#if FF_API_FLAG_TRUNCATED +/* Nuke this header when removing FF_API_FLAG_TRUNCATED */ #include "h263_parser.h" int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ +#else + +static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +{ +#endif int vop_found, i; uint32_t state; @@ -73,7 +80,11 @@ static int h263_parse(AVCodecParserContext *s, if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { next = buf_size; } else { +#if FF_API_FLAG_TRUNCATED next= ff_h263_find_frame_end(pc, buf, buf_size); +#else + next = h263_find_frame_end(pc, buf, buf_size); +#endif if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 1aacd07e41..58e03c05d4 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -168,6 +168,7 @@ av_cold void ff_mpeg12_init_vlcs(void) ff_thread_once(&init_static_once, mpeg12_init_vlcs); } +#if FF_API_FLAG_TRUNCATED /** * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 @@ -231,6 +232,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, pc->state = state; return END_NOT_FOUND; } +#endif #define MAX_INDEX (64 - 1) diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h index a7b94c132a..fb2b37e7c8 100644 --- a/libavcodec/mpeg12.h +++ b/libavcodec/mpeg12.h @@ -70,7 +70,9 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, int16_t *block, int index, int qscale); void ff_mpeg1_clean_buffers(MpegEncContext *s); +#if FF_API_FLAG_TRUNCATED int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s); +#endif void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c index 1b0e2555da..c68c966259 100644 --- a/libavcodec/mpeg4video_parser.c +++ b/libavcodec/mpeg4video_parser.c @@ -26,7 +26,10 @@ #include "parser.h" #include "mpegvideo.h" #include "mpeg4video.h" +#if FF_API_FLAG_TRUNCATED +/* Nuke this header when removing FF_API_FLAG_TRUNCATED */ #include "mpeg4video_parser.h" +#endif struct Mp4vParseContext { ParseContext pc; @@ -34,7 +37,15 @@ struct Mp4vParseContext { int first_picture; }; +#if FF_API_FLAG_TRUNCATED int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +#else +/** + * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +static int mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +#endif { int vop_found, i; uint32_t state; @@ -138,7 +149,11 @@ static int mpeg4video_parse(AVCodecParserContext *s, if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { next = buf_size; } else { +#if FF_API_FLAG_TRUNCATED next = ff_mpeg4_find_frame_end(pc, buf, buf_size); +#else + next = mpeg4_find_frame_end(pc, buf, buf_size); +#endif if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 8dfa904577..e90669b776 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -49,7 +49,9 @@ #include "pixblockdsp.h" #include "put_bits.h" #include "ratecontrol.h" +#if FF_API_FLAG_TRUNCATED #include "parser.h" +#endif #include "mpegutils.h" #include "mpeg12data.h" #include "qpeldsp.h" diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 7864224643..39b9f2e43a 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -31,6 +31,72 @@ struct MpvParseContext { int width, height; }; +#if !FF_API_FLAG_TRUNCATED +/** + * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, + int buf_size, AVCodecParserContext *s) +{ + int i; + uint32_t state = pc->state; + + /* EOF considered as end of frame */ + if (buf_size == 0) + return 0; + +/* + 0 frame start -> 1/4 + 1 first_SEQEXT -> 0/2 + 2 first field start -> 3/0 + 3 second_SEQEXT -> 2/0 + 4 searching end +*/ + + for (i = 0; i < buf_size; i++) { + av_assert1(pc->frame_start_found >= 0 && pc->frame_start_found <= 4); + if (pc->frame_start_found & 1) { + if (state == EXT_START_CODE && (buf[i] & 0xF0) != 0x80) + pc->frame_start_found--; + else if (state == EXT_START_CODE + 2) { + if ((buf[i] & 3) == 3) + pc->frame_start_found = 0; + else + pc->frame_start_found = (pc->frame_start_found + 1) & 3; + } + state++; + } else { + i = avpriv_find_start_code(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; + } + if (state == SEQ_END_CODE) { + pc->frame_start_found = 0; + pc->state = -1; + return i + 1; + } + if (pc->frame_start_found == 2 && state == SEQ_START_CODE) + 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 (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) { + pc->frame_start_found = 0; + pc->state = -1; + return i - 3; + } + } + if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) { + ff_fetch_timestamp(s, i - 3, 1, i > 3); + } + } + } + pc->state = state; + return END_NOT_FOUND; +} +#endif static void mpegvideo_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, @@ -192,7 +258,11 @@ static int mpegvideo_parse(AVCodecParserContext *s, if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ next= buf_size; }else{ +#if FF_API_FLAG_TRUNCATED next= ff_mpeg1_find_frame_end(pc, buf, buf_size, s); +#else + next = mpeg1_find_frame_end(pc, buf, buf_size, s); +#endif if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL;