From patchwork Thu Sep 23 15:28:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30492 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp568235iob; Thu, 23 Sep 2021 08:32:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxkqn4Y7CZYcDRQgqTy2EZlHwQ29r31RBzC3PlEZva27wJhz5opITH28t2LitsZlK2rK5j X-Received: by 2002:a17:907:7785:: with SMTP id ky5mr5739878ejc.247.1632411134669; Thu, 23 Sep 2021 08:32:14 -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 c24si5907571edx.457.2021.09.23.08.32.14; Thu, 23 Sep 2021 08:32:14 -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=OmfxwO3e; 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 2277068ACB7; Thu, 23 Sep 2021 18:29:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073018.outbound.protection.outlook.com [40.92.73.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DFC9E68AE0F for ; Thu, 23 Sep 2021 18:29:46 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PBXD6iuxQEo9iZnkRwgj4h9PKq5km+wYwsSx41/6xiAPxg7k9iGYJEvVtT470qyHS2gUmWopV1rDMx9XSfjtHyNNasSJ3VdTwDTXo//x3+tOzHy2PfDCosyY8WMuL5Nm8YNBsYGakJLrofrU+nguaitTGfv9n+7ol/GaQM7YGycy98RtZytMZMDP7Ooy/bTYp3aYNo9URWRI15C6mIAkiUHzrxaNG3v9FD1bhKa6DRs/6ltCSaLmdOKc7o3XfAQq+uX7YX/a+XqLYVelqkLlbi8jRLAC9c6gyl0HPh9o0NDX0yUA7Se++3fGNwtWR+r0ZBbt1weYLEJRQvIYsu7AcA== 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=JdQaRSWi7wrNU20vDpsN0MXzMeePyZoP35WSX3ps9/4=; b=RQe/vGqiGBSqOSi4iFNyDntafkPqfQHqmTljM0i33D28VIL6852BXPT4gzGTkzp59pfkyNUmRkLauUAyXbCb+nrJHq7zWfJ/X7Dx6T0KtDmYWsqhvGQtHuPMndR4kGZljb5WRxAJkaC6b0wBmKXOcHeJifpJRMQ0YfvLxW0D+hRwQiXEwtrqK8BSOEuSU+5RVSzjnHRFbPyTqYJ4vmJBUim7Md6R0QuSYTHml0XuSyEKAWXr8tG2o+yZYy0sD43x2EetmHBU3US2fhUMjbyG30ZUNElYKsd2SHsHFwwCQywU2ttk0qQoRlyR3K34lTdd1nFg//Ldnu9q4Ff7ekpnuQ== 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=JdQaRSWi7wrNU20vDpsN0MXzMeePyZoP35WSX3ps9/4=; b=OmfxwO3edgkJ7ASZMusfQIR7b3jDSl3TtoXeWC1xdV3IKnvdvMJtvmp2YKEKRBTwVpG14ykHJGDBAUDottDHGi1XNToQ0u+ijs6r58h6ITVSvTKdlaV+xwvB4Lo1+d5zZZSTfCqeB5EMaM+LNS1QacCltnPqEu4Tt8pQtahPkBu0ZpHEf4s3TxykH39+AgKhfNB9hupz8ITmBcxq7jpTftSnRLB8LhhC8NIwGXdovRJogw59pLzJQqeqwj4TzLJRI/Z9ztRFlvLIejfObZXzWStrz6u/5NbuiUAsRc/+6+FAetdN48PdR+n9aZXYLhNtxjsDj79PslFjoOtPQZDn9g== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AS8PR03MB6807.eurprd03.prod.outlook.com (2603:10a6:20b:23f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Thu, 23 Sep 2021 15:29:45 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00%3]) with mapi id 15.20.4523.021; Thu, 23 Sep 2021 15:29:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Sep 2021 17:28:51 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [RCmPULWlmkWEFbPQT3TFRyOFS48IdN7m] X-ClientProxiedBy: AM0PR06CA0106.eurprd06.prod.outlook.com (2603:10a6:208:fa::47) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210923152902.42865-15-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR06CA0106.eurprd06.prod.outlook.com (2603:10a6:208:fa::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13 via Frontend Transport; Thu, 23 Sep 2021 15:29:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a5e28124-b5a6-49ca-7c81-08d97ea6f8c1 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSygBPrM25OmITrtIHMJgdSKsShyNf9XGYQwGaRDRdpKWqLGycdOhhNNIxDIPAhL3fOjOEbPYTcXjDSlIVm+EQT81gspNQlFew+vS2KdH5bw5SvYyTESZIf8+6Hpg6Imzb+5Wj+RZ4P3q930xyzzOtwefKE6Ixz04kSYLdy6Qo/ABgr0eRbEK+XW7luEHNlSWy9CILY5e/TzFaHF/RRd4zRpcpK3GtTbJN4XpEKbvcvW5cF+ekFqY3k1ic22N+XvnYHJGLhQH4/T6QD6Dt/7pi/NrluHBU5/DyzQJO/NELdK87DeuToLAMxxn4NmtCvxFLihKhM2UgJOGsbntUy4yOyL1Eh4jR/Lu0YUfdl7tCpnsNm/ACdoV5w0DXCgZmv1HLn1zrXh7DYj1poBvVPN5qI+d8ZFcGUj329TRWNenT5TGW5W38zJnWSuQ1k/SFHW07bgKos8t8FfJ/tsRMTQNBXNkAjRbiBqVRDvQIzKBfkszD3G5OxgN7ZR9oM3xSxgU62kcZzUb8L44FrL+ns5wokR7odepPTbmtS/CHKU0V/tBqejsK6c17shqy0VfoDYYqUvI/jcg/nYfwD9g6dEC4oCLgUDywIRLZ6RisoEg/e6zogEVrGWBSyqx6ZqHoxw2dIYym9tS4zs9969CKaCGUezTVmnhxydN/xMADI8FlSAaSn6tUlyqnwOpCF5xLUpoQKQDJOFxlN9eMS1aZdISVuAaHP/XEbydfxgOcYT8yqd0kus3vlzYBpAS5BQcDn6os= X-MS-TrafficTypeDiagnostic: AS8PR03MB6807: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BXjnPWIb/kgpbAjrMtmTBzgaUsGQgo8dIAUH/JtPIg/Ld2ku/H6XT9G3rBhGlLPaOyflRh7Pi733Zz3VqNVMFGvYv5Dv/zyZdRWFW/P6qBo/zlSRsUkdlZLaft0K8bmA3UAafGkofP1LTxNqFsW6Wf5g4jvElV22sAOqQKZHc8HZAr1VHoeYu4Ib37mA9nmCmyvjMI7CmW4T0KHWG9coLaASek2GKFTFDd09Ho4JgS2HArfujtrlhoiJS6cLo2byVOirZ4tLXpCqfr/8W7TOCOzzlydeNHFdUliOhDpTnKgdkjKzIVfi7PCyYk1X3/WAfBBlKPCKljnexR/MJJ35YygtSHwQnbUhjKvzkWbWHDfVi5o8bTekMRnsL3z2DgtWWYpa+VFbaZY6z7h3S/tm54eGD6pTnKmLKlmRmY7V2ntVJfWsoXWyTcIKkkWKIu/e X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZpSYuFHmdkE6TP5ZldJLo68FYS/y+bNuavYBRsGOj+JPhU8TOcV14JEqFbQcddl6wXQqBvb5pJW8zvX3OduJbuU6MkFyFAo9d4P3RUBrvxjxiOnqP/jzHAjadIb2F5uY+/00W89Vg3SeSvNLHsswSQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5e28124-b5a6-49ca-7c81-08d97ea6f8c1 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2021 15:29:45.4518 (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: AS8PR03MB6807 Subject: [FFmpeg-devel] [PATCH 16/27] avformat/mpegenc: Simplify writing padding/stuffing 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: 0251IIGTGj4U Signed-off-by: Andreas Rheinhardt --- libavformat/mpegenc.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 6aed527d50..b1d8bf9c38 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -30,6 +30,7 @@ #include "libavcodec/put_bits.h" #include "avformat.h" +#include "avio_internal.h" #include "internal.h" #include "mpeg.h" @@ -598,7 +599,6 @@ static void put_padding_packet(AVFormatContext *ctx, AVIOContext *pb, int packet_bytes) { MpegMuxContext *s = ctx->priv_data; - int i; avio_wb32(pb, PADDING_STREAM); avio_wb16(pb, packet_bytes - 6); @@ -608,8 +608,7 @@ static void put_padding_packet(AVFormatContext *ctx, AVIOContext *pb, } else packet_bytes -= 6; - for (i = 0; i < packet_bytes; i++) - avio_w8(pb, 0xff); + ffio_fill(pb, 0xff, packet_bytes); } static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len) @@ -634,7 +633,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, MpegMuxContext *s = ctx->priv_data; StreamInfo *stream = ctx->streams[stream_index]->priv_data; uint8_t *buf_ptr; - int size, payload_size, startcode, id, stuffing_size, i, header_len; + int size, payload_size, startcode, id, stuffing_size, header_len; int packet_size; uint8_t buffer[128]; int zero_trail_bytes = 0; @@ -685,14 +684,12 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, avio_wb32(ctx->pb, PRIVATE_STREAM_2); avio_wb16(ctx->pb, 0x03d4); // length avio_w8(ctx->pb, 0x00); // substream ID, 00=PCI - for (i = 0; i < 979; i++) - avio_w8(ctx->pb, 0x00); + ffio_fill(ctx->pb, 0x00, 979); avio_wb32(ctx->pb, PRIVATE_STREAM_2); avio_wb16(ctx->pb, 0x03fa); // length avio_w8(ctx->pb, 0x01); // substream ID, 01=DSI - for (i = 0; i < 1017; i++) - avio_w8(ctx->pb, 0x00); + ffio_fill(ctx->pb, 0x00, 1017); memset(buffer, 0, 128); buf_ptr = buffer; @@ -835,8 +832,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, avio_wb16(ctx->pb, packet_size); if (!s->is_mpeg2) - for (i = 0; i < stuffing_size; i++) - avio_w8(ctx->pb, 0xff); + ffio_fill(ctx->pb, 0xff, stuffing_size); if (s->is_mpeg2) { avio_w8(ctx->pb, 0x80); /* mpeg2 id */ @@ -891,8 +887,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, * to prevent accidental generation of start codes. */ avio_w8(ctx->pb, 0xff); - for (i = 0; i < stuffing_size; i++) - avio_w8(ctx->pb, 0xff); + ffio_fill(ctx->pb, 0xff, stuffing_size); } if (startcode == PRIVATE_STREAM_1) { @@ -925,8 +920,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, if (pad_packet_bytes > 0) put_padding_packet(ctx, ctx->pb, pad_packet_bytes); - for (i = 0; i < zero_trail_bytes; i++) - avio_w8(ctx->pb, 0x00); + ffio_fill(ctx->pb, 0x00, zero_trail_bytes); avio_write_marker(ctx->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); @@ -950,10 +944,8 @@ static void put_vcd_padding_sector(AVFormatContext *ctx) * So a 0-sector it is... */ MpegMuxContext *s = ctx->priv_data; - int i; - for (i = 0; i < s->packet_size; i++) - avio_w8(ctx->pb, 0); + ffio_fill(ctx->pb, 0, s->packet_size); s->vcd_padding_bytes_written += s->packet_size;