From patchwork Wed Sep 22 17:29:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 30457 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp753336iob; Wed, 22 Sep 2021 10:29:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmsYCPVrfv5XgFVDXtuPHF7aH7jVn9F8GU+07aVkG5RyM3jDKiX8Kan6rdhtGfQ6fMmxIz X-Received: by 2002:a17:906:4ed2:: with SMTP id i18mr360442ejv.528.1632331794860; Wed, 22 Sep 2021 10:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632331794; cv=none; d=google.com; s=arc-20160816; b=ga7x7Q0Ar+uUDz6OOTCMviU0/V1bC74HhisP7v9DVo7SDpQgXrmJjAeFVe6brzvzLj IO51KK82l7qyHnpCZiQUpfySl0Fhje+Gm9roAhPwqoeNKI5GqcvBjGckuRItXr3hvUTA R1S7L6Tw8bl694TUozACk6zQ9T/ppi9Qtvet5BBMc3DAhSSVKRdyeAI3TeLyKJ/qr51G Z7qe8OIPid86hwto78qQkvHUrNYy2S+vf1xeGYiZoiwgxqGdmMbfM+AHVW59tcIrN3Ps QhJEy3eny7wgxcBRUEEpaIHhsicjyv/VaEaPuazzuhYaZCu+6QYxRVBu8V15wLx6iTBm r/FQ== 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:delivered-to; bh=NFUcEoDnWs+Oo84W037ZAaV58vIcX6MF87QTluh0pAY=; b=m55OKb6fZ8vvQNoyX3HoAjvJvra5u3Gu2XQ8owYO0/JXm+5Et/MSAkMLBhMPd+DO5/ ngk/DG3FP+4UlO8/viqeg+BigTKhn8lLx3SNZH57ojxlX1ClaLh199x8vZgHTslXreRT 8I5tAqQpECES/Mw7rzwB9UmZeqxkpoK+6N2tg5RTrytp/hmTOyP5wUarYBHJZZKKA/Mo 3uzYtUOvsJp24lqr1Ylkvl8X27xtowxt4UgxQqsv1sFiBhyU3N81FFDENfkUpp8eRB2y 7btXGe1iwpurjpX0oH09JZ+9+DDCAdpvCbzQkaBikM1g3I4rrnqG7akQBvtRngjjfrSo zpNw== 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 m27si3579829ejn.5.2021.09.22.10.29.54; Wed, 22 Sep 2021 10:29:54 -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; 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 870D268AC14; Wed, 22 Sep 2021 20:29:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F12A568AB98 for ; Wed, 22 Sep 2021 20:29:24 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D9622E5E83; Wed, 22 Sep 2021 19:29:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ArksvD1NUdIe; Wed, 22 Sep 2021 19:29:23 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 46F8FE5E82; Wed, 22 Sep 2021 19:29:23 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Sep 2021 19:29:13 +0200 Message-Id: <20210922172914.17914-3-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210922172914.17914-1-cus@passwd.hu> References: <20210922172914.17914-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avformat/mpegts: rename PES total_size to PES_packet_length 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qQ959mpHp7lm This renames PESContext->total_size to PESContext->PES_packet_length and keeps it 0 for unbound packets, so its name and semantics will match the standard. There should be no change in functionality. Signed-off-by: Marton Balint --- libavformat/mpegts.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 2620e79f57..7d2e7407c1 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -254,7 +254,7 @@ typedef struct PESContext { /* used to get the format */ int data_index; int flags; /**< copied to the AVPacket flags */ - int total_size; + int PES_packet_length; int pes_header_size; int extended_stream_id; uint8_t stream_id; @@ -998,8 +998,8 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt) pkt->data = pes->buffer->data; pkt->size = pes->data_index; - if (pes->total_size != MAX_PES_PAYLOAD && - pes->pes_header_size + pes->data_index != pes->total_size + + if (pes->PES_packet_length && + pes->pes_header_size + pes->data_index != pes->PES_packet_length + PES_START_SIZE) { av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n"); pes->flags |= AV_PKT_FLAG_CORRUPT; @@ -1183,11 +1183,8 @@ static int mpegts_push_data(MpegTSFilter *filter, mpegts_set_stream_info(pes->st, pes, 0, 0); } - pes->total_size = AV_RB16(pes->header + 4); - /* NOTE: a zero total size means the PES size is - * unbounded */ - if (!pes->total_size) - pes->total_size = MAX_PES_PAYLOAD; + pes->PES_packet_length = AV_RB16(pes->header + 4); + /* NOTE: zero length means the PES size is unbounded */ if (pes->stream_id != STREAM_ID_PROGRAM_STREAM_MAP && pes->stream_id != STREAM_ID_PRIVATE_STREAM_2 && @@ -1360,22 +1357,27 @@ skip: break; case MPEGTS_PAYLOAD: do { + int max_packet_size = MAX_PES_PAYLOAD; + if (pes->PES_packet_length) + max_packet_size = pes->PES_packet_length; + if (pes->data_index > 0 && - pes->data_index + buf_size > pes->total_size) { + pes->data_index + buf_size > max_packet_size) { ret = new_pes_packet(pes, ts->pkt); if (ret < 0) return ret; - pes->total_size = MAX_PES_PAYLOAD; + pes->PES_packet_length = 0; + max_packet_size = MAX_PES_PAYLOAD; ts->stop_parse = 1; } else if (pes->data_index == 0 && - buf_size > pes->total_size) { + buf_size > max_packet_size) { // pes packet size is < ts size packet and pes data is padded with 0xff // not sure if this is legal in ts but see issue #2392 - buf_size = pes->total_size; + buf_size = max_packet_size; } if (!pes->buffer) { - pes->buffer = buffer_pool_get(ts, pes->total_size); + pes->buffer = buffer_pool_get(ts, max_packet_size); if (!pes->buffer) return AVERROR(ENOMEM); } @@ -1384,11 +1386,9 @@ skip: pes->data_index += buf_size; /* emit complete packets with known packet size * decreases demuxer delay for infrequent packets like subtitles from - * a couple of seconds to milliseconds for properly muxed files. - * total_size is the number of bytes following pes_packet_length - * in the pes header, i.e. not counting the first PES_START_SIZE bytes */ - if (!ts->stop_parse && pes->total_size < MAX_PES_PAYLOAD && - pes->pes_header_size + pes->data_index == pes->total_size + PES_START_SIZE) { + * a couple of seconds to milliseconds for properly muxed files. */ + if (!ts->stop_parse && pes->PES_packet_length && + pes->pes_header_size + pes->data_index == pes->PES_packet_length + PES_START_SIZE) { ts->stop_parse = 1; ret = new_pes_packet(pes, ts->pkt); pes->state = MPEGTS_SKIP;