From patchwork Wed Jan 12 15:12:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 33278 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4719041iog; Wed, 12 Jan 2022 07:12:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+aQ0YQajgh4Cr1xW66Ec0HyUDamja2S5wDXgo/FXOoP502rWb2CaigiufLR1n3beNAQCB X-Received: by 2002:a17:907:6e26:: with SMTP id sd38mr163678ejc.558.1642000372966; Wed, 12 Jan 2022 07:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642000372; cv=none; d=google.com; s=arc-20160816; b=pBrY23FhEZSxWwSMoIJlKAsDTJwaYo3cDBXx+eb6uyNQC1m/hPl9hASY/z8Jr7UtTe Y+LgcB7jORieXOOWhsTi43/HPCnqkghhwOf7fGrzNC1Xrs/1ySakzBfTaDbatEBIrN5n KZs0ZwO5qcKw4iWAQA7C951l4+V82XY5dTd8lCWJSvXNVwuSeVAFBzpFB9FVdF6cl49t BItc6n7uGlIwC0Fx4FA6IJ5GAgR4n18hP3rVHsxo4N1qyBpRlVlkHg3w0Q7gfyFnFJRp jaiJDqT8/0SR2Zopfxy0L1V3hhQvgPk6k62WjL3wF8kYgCfEmCyWjtIL7qYN3mwXU/k2 m5yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=wd1OdO+7aNtgw98fKozo7noMqYPSG7tP0tCAZttooeA=; b=cdPeCYU1DdZzShkuLKldgXrQFBBId4EpEmRBHkyzEyFEPYO65EAZ3M9rDV9ePgWCvs mY9OrzA5jQ5YvxiPwi5ehxjPMWh+Kungb5vb34jAPY2oJzx8x8+flaw4w2PIztmMRKac YX/+eZ8wPKTogskbmI9VqRa4aKQGrC8weGEHxuKasuJKHoOtr+x90zaYR/RGOvBjzcPc +MOU1T95fYI22wQuyaesBpZVeVBJtrUQxNJkuBXD6G/f1sy8s61FzZF5Wz58fYADK6qQ QKWaJCFBJA+JjzFyyG8nRQroLOqo/ZeFmTbeDaG1FzG8saTUnjpljXHYujqeCgBfeVHr RLvw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qf29si24169ejc.246.2022.01.12.07.12.51; Wed, 12 Jan 2022 07:12:52 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B29E368ABD1; Wed, 12 Jan 2022 17:12:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8462868004F for ; Wed, 12 Jan 2022 17:12:41 +0200 (EET) Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:105:465:1:3:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4JYrf01Nd2zQkjN for ; Wed, 12 Jan 2022 16:12:40 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 20:42:10 +0530 Message-Id: <20220112151210.63554-1-ffmpeg@gyani.pro> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mpegts: add option max_packet_size 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yefTJZQrzPtt Makes maximum size of emitted packet user-tunable. --- doc/demuxers.texi | 4 ++++ libavformat/mpegts.c | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 26ae768d7a..aa92f0eec8 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -777,6 +777,10 @@ Re-use existing streams when a PMT's version is updated and elementary streams move to different PIDs. Default value is 0. @end table +@item max_packet_size +Set maximum size, in bytes, of packet emitted by the demuxer. Payloads above this size +are split across multiple packets. Range is 0 to INT_MAX. Default is 204800 bytes. + @section mpjpeg MJPEG encapsulated in multi-part MIME demuxer. diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 2479cb6f7d..6e50893217 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -162,6 +162,7 @@ struct MpegTSContext { int resync_size; int merge_pmt_versions; + int max_packet_size; /******************************************/ /* private mpegts data */ @@ -198,6 +199,8 @@ static const AVOption options[] = { {.i64 = 0}, 0, 1, 0 }, {"skip_clear", "skip clearing programs", offsetof(MpegTSContext, skip_clear), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, 0 }, + {"max_packet_size", "maximum size of emitted packet", offsetof(MpegTSContext, max_packet_size), AV_OPT_TYPE_INT, + {.i64 = MAX_PES_PAYLOAD}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; @@ -1121,7 +1124,7 @@ static AVBufferRef *buffer_pool_get(MpegTSContext *ts, int size) { int index = av_log2(size + AV_INPUT_BUFFER_PADDING_SIZE); if (!ts->pools[index]) { - int pool_size = FFMIN(MAX_PES_PAYLOAD + AV_INPUT_BUFFER_PADDING_SIZE, 2 << index); + int pool_size = FFMIN(ts->max_packet_size + AV_INPUT_BUFFER_PADDING_SIZE, 2 << index); ts->pools[index] = av_buffer_pool_init(pool_size, NULL); if (!ts->pools[index]) return NULL; @@ -1368,7 +1371,7 @@ skip: break; case MPEGTS_PAYLOAD: do { - int max_packet_size = MAX_PES_PAYLOAD; + int max_packet_size = ts->max_packet_size; if (pes->PES_packet_length && pes->PES_packet_length + PES_START_SIZE > pes->pes_header_size) max_packet_size = pes->PES_packet_length + PES_START_SIZE - pes->pes_header_size; @@ -1378,7 +1381,7 @@ skip: if (ret < 0) return ret; pes->PES_packet_length = 0; - max_packet_size = MAX_PES_PAYLOAD; + max_packet_size = ts->max_packet_size; ts->stop_parse = 1; } else if (pes->data_index == 0 && buf_size > max_packet_size) {