From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8059A40BBB for ; Sat, 5 Feb 2022 03:55:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F0F2F68B300; Sat, 5 Feb 2022 05:55:04 +0200 (EET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2070.outbound.protection.outlook.com [40.92.89.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 692FE68B1A8 for ; Sat, 5 Feb 2022 05:54:59 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VM5gRsMKrU7pv3h0vQZxgdLm/UzQAsnf1tDEj4UEhC5kvjcOYIMnyEGJnxJTB3TlRgy/4BVihQt23abzbMPYHse38n9adsJ14ZmC/wNRlTIsogjxIaQUHjdSmoUuMhhQZ1q1mbIKRoOTSiRT4bpAb0P+sQ7AgzfnzzZyB8aisGj0dlPy/kJiRkCM90W00QXGIlCuuOBAeg4MjT7oM3ABi0jK9zW3loOlAZyGW8VyLApLwKiPaYg7+w3NYyK6p5EB7QY8NJPwyesFQXy1H946GJDiM6dzNAYtTTWc0SpR7U5Yh0P+/kR2het4gHHrm3j9Qo9LPzsTM+n8PY82lYrzMA== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7Xr+E/Amsk5FmE3zgWViHCvuSO+/r5uF8kFt4arSRGg=; b=Baw7Wtox0F2ZWRw63KYZ9TazrP8wWzRVQS9NAZOQPj/tzVG1GtkZD6kJRL3+Is/mpWCILpEX3cjbMFLY3Moq+COg94WNfUeE2Yr4KFGwoKfwR9AufxEXKteuZmC9TFpCsmSKXQFk2LTZcKuhvPITOBacB4J6jVGCB+SNuO9ztigeu/ooYTa5U3EaKhqo4ejHXN5CMUB+m0WvbERi6+mphb4St6RSvPyqF0UEGkcfaijymN858g00RwOisbvmzevbWYgu/X7vbCQ72novXkX8G3AGEuctFNaAU9NiQis8CwRxb05VQ57IfTNr+WDo8GA0CrIPwnU2nlbv0YBux2NCBQ== 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=7Xr+E/Amsk5FmE3zgWViHCvuSO+/r5uF8kFt4arSRGg=; b=gnW5beM9VZpP+2TSAEULW3iY0/cAedNuf32fYaAfIJMLC1ucI/BZ+VfTTOipp0qewYp7+e3YOelEDqn0fF14zVGDn++z103Fled/yhDL1aE8yLTrV4RIklhNRH4jV8TJUM2TOBQJikte2cQs5sWFRlmMWya6pLTralrsGgx7eMU1SglGsG0OtL6C3K5ovMfBjcf1HOmdiZWHaejT9pjqC5jqXTIpvjRa7hIXiHgS2ciMI3JExDNo1yuF3V5QxPE7T77kPDXaLWazDdd553+g/V03yflJ9vkrDDi1/Et/T76mOwFeFw9uAOpZIgcR0dUMJa6YbZqC3y9rGuWH972mgw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by GV1PR03MB8127.eurprd03.prod.outlook.com (2603:10a6:150:22::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21; Sat, 5 Feb 2022 03:54:57 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%5]) with mapi id 15.20.4951.014; Sat, 5 Feb 2022 03:54:57 +0000 Message-ID: Date: Sat, 5 Feb 2022 04:54:56 +0100 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220201212056.29712-1-scott.the.elm@gmail.com> <20220203184450.5491-1-scott.the.elm@gmail.com> <20220203184450.5491-14-scott.the.elm@gmail.com> From: Andreas Rheinhardt In-Reply-To: <20220203184450.5491-14-scott.the.elm@gmail.com> X-TMN: [S+jKaGdqACMADNOdTvodwkDHDAJEGKrM] X-ClientProxiedBy: AM6PR04CA0036.eurprd04.prod.outlook.com (2603:10a6:20b:92::49) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <49a14833-1433-6d44-62cc-7205f0b4381b@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c5f61f4-7fa2-4b9f-1b9e-08d9e85b4677 X-MS-TrafficTypeDiagnostic: GV1PR03MB8127:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UIRh0eiNfi27u844bIxVva1cCZd+hZLsiE9OG2r7zGLDI38i2MEFk7zueeMaxsYREaSpVwHkwBHrqRVuUKFrgdcTIIVfqFQDabfYxKrQd8avfqJqTHnucpO1kRZq76VgQNV2ORkJLZLoCcB7SqxcpEGNl8wwuexJiZ8g6pUAGsAhE1nt6s5kyZMWkcPtKXw1zSBWpV3iJmfExmx0CA6eiVMcUy1QmIXwgwyQFXqF+Bs98QxxYWmzaVoVWzdxWkfUI2m1+xeTlhT5QMSduhmmUFzR6ooxZeDVM/volqlTXPvUEwkT5bv1FG+PdF8WUwkhKh3s+1NrdYAIdN4QwliP9iycEy8eyddkDJ0S2P1zm42gNgU+zAb32IH/Lh6PHaDYT65qsojDcc0ylsnERebOu4QOUOfuNeLleoQKGjt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kdaYkpNNnFCbUs3MktKbHZ1?= =?utf-8?B?UmRadXVyVXhqaGJUcXcxQzR2a1RqTUp4M1RoZkl2bTZnaCtPZC92MUFXVGFp?= =?utf-8?B?WmNNNjZqc2J4dzRRdEJ5QUJIZ3JoV280TEhUb3BWSTZxVlYzSXRlTXVkeTJW?= =?utf-8?B?WE9rRld5SkZ6ek5udktNblFjeERpL0ZUc0U0OWxHdXQ4L09YSkdVRVlHZG85?= =?utf-8?B?NkR4eit1RXBMNWd2a09MeDRtVWk2OWQ1SHB6RGJ3bGEzcmFPQzZXTEZFT2dx?= =?utf-8?B?ektibjlycVZETW9rbVEzbzFDT01iZndiSEhtbkFKUCs0bXg3dFFqdXFGWjRx?= =?utf-8?B?ZTNmTW4yU21tY2hRTnVnNTdKNkJaZHB6cUo1VW1la2pQNGFkS3lqWUFZSVd1?= =?utf-8?B?alJHOExaVG91c0dYKzJzWkNwY2NsSm9TeWFkU2s5VkNJWUMxcSsxQklib1hS?= =?utf-8?B?alA3THdYMzFTbVhheURoZjNua1FYM0JKVWkwcncxWHdmWUw5SUpsVG9HN0Iz?= =?utf-8?B?SGFhTjBZeWM3MFQzMklVRlQwTWF2NkhrYTdnTEpINWhlaVB3c3ZsVVBLQWU4?= =?utf-8?B?WnJONzluZ25PTWdwbUtYUmNzS0RFL01sY1RXNkFNeS95WGlrUT09?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5f61f4-7fa2-4b9f-1b9e-08d9e85b4677 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2022 03:54:57.3077 (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: GV1PR03MB8127 Subject: Re: [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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Scott Theisen: > 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; > } I disagree that this is the true loop condition that just needs to be revealed; in fact, this is basically the loop condition from before fd93d5efe64206d5f1bce8c702602353444c0c1a, just with an added block to deal with size one units at the end. I considered this and chose the current one because it leads to less code duplication for this special case. Anyway, now that I have taken another look at this and I finally found the true loop condition: Is there a unit that we have not added to the fragment yet? This is easily implementable if one always resets the start code, so that there being an outstanding unit is equivalent to the start code being valid. - Andreas _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".