From patchwork Wed Sep 22 17:29:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 30458 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp753022iob; Wed, 22 Sep 2021 10:29:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI2is5HIVK73PQqpFO6h3tEGaxBpW3KXuIMRbtla8gyBb4iLQoAg6sueDFB2kCow4M+fhQ X-Received: by 2002:a17:906:cc0e:: with SMTP id ml14mr309900ejb.395.1632331772725; Wed, 22 Sep 2021 10:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632331772; cv=none; d=google.com; s=arc-20160816; b=ysHp/E/yGDHVcd5pVb3oR2eAKLOkVG/FWP7lBrYVhoxz++eoc1/phg4+JkLvg2NOJl 3+IoSZaHVkIgmfYXxLKX5sHUiTnZHMRCqWLsfWlgXtB7fOiwzqA5VbHa7broKB6jZkJv hKqLf9Hxg8N5nJJuYkfVp8oaoOwgCzIkwVa+TnPQmvGzQi2vVfILNwPIydSVJkB62pZ5 K5xoZyKIxcfy8Qgq06DdCEVwoZBtKP3ZfxjMqLtbfzre7sbypoy5l6gJHws/jTa2VSFH 8i2Ii6zXBjmPrju9eBb4N+ZUjjtCyffW7PvKMjDiIPqFwBW/jMs0qPC4FbPeoCGRBwFF Xn5g== 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:message-id:date:to:from :delivered-to; bh=D5buqOjgRKxxUMEAWLNZ+q0VPE9/NZimGepRFIOwA4g=; b=xSAGqkPbxQhnrtP0+A60n8ZrGygUDfF8qpEB83wBJaPA9Z6miMK/2pTL++PGiLjEtX ttq0OhDfAsBfocsTL7eRSgzYaxc2EsbJoiKaCnswL3P4PGoxAqAbStdSMAIzZwrKxY0L uHrQ2RyHGHcpDa1Fi+WklqS0AInUFIdTXe/t3kKW66gW3Pr51vbwEdIR8aXtoBkjKkNr XgYEA7a+EQLUKOI2lFPwVMvfYJvhtOl1ULU1CbC5f1wFsETjreO+7t+5702DX6ZJ8OVf sUplw8Mjn0sL5wv4den43P4O59BdcRypQ/JBa/0NUxAcEL6m+u0dreLJiNhpR2eZdlOA 3jKw== 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 w3si3205572edi.35.2021.09.22.10.29.31; Wed, 22 Sep 2021 10:29:32 -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 6EDC168A7DE; Wed, 22 Sep 2021 20:29:27 +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 E03CF68A7DE for ; Wed, 22 Sep 2021 20:29:19 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 67EF9E5E81; Wed, 22 Sep 2021 19:29:19 +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 emb2IvTpVTBW; Wed, 22 Sep 2021 19:29:18 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 05030E5CFC; Wed, 22 Sep 2021 19:29:18 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Sep 2021 19:29:11 +0200 Message-Id: <20210922172914.17914-1-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avformat/mpegts: use named constants for stream_id types 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: yMGocxA23bdX Signed-off-by: Marton Balint --- libavformat/mpegts.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index da8eee2414..fcb32ecd28 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1126,7 +1126,7 @@ static int mpegts_push_data(MpegTSFilter *filter, PESContext *pes = filter->u.pes_filter.opaque; MpegTSContext *ts = pes->ts; const uint8_t *p; - int ret, len, code; + int ret, len; if (!ts->pkt) return 0; @@ -1160,15 +1160,13 @@ static int mpegts_push_data(MpegTSFilter *filter, if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && pes->header[2] == 0x01) { /* it must be an MPEG-2 PES stream */ - code = pes->header[3] | 0x100; - av_log(pes->stream, AV_LOG_TRACE, "pid=%x pes_code=%#x\n", pes->pid, - code); pes->stream_id = pes->header[3]; + av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_id=%#x\n", pes->pid, pes->stream_id); if ((pes->st && pes->st->discard == AVDISCARD_ALL && (!pes->sub_st || pes->sub_st->discard == AVDISCARD_ALL)) || - code == 0x1be) /* padding_stream */ + pes->stream_id == STREAM_ID_PADDING_STREAM) goto skip; /* stream not present in PMT */ @@ -1196,10 +1194,13 @@ static int mpegts_push_data(MpegTSFilter *filter, if (!pes->buffer) return AVERROR(ENOMEM); - if (code != 0x1bc && code != 0x1bf && /* program_stream_map, private_stream_2 */ - code != 0x1f0 && code != 0x1f1 && /* ECM, EMM */ - code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ - code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ + if (pes->stream_id != STREAM_ID_PROGRAM_STREAM_MAP && + pes->stream_id != STREAM_ID_PRIVATE_STREAM_2 && + pes->stream_id != STREAM_ID_ECM_STREAM && + pes->stream_id != STREAM_ID_EMM_STREAM && + pes->stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY && + pes->stream_id != STREAM_ID_DSMCC_STREAM && + pes->stream_id != STREAM_ID_TYPE_E_STREAM) { FFStream *const pes_sti = ffstream(pes->st); pes->state = MPEGTS_PESHEADER; if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes_sti->request_probe) { From patchwork Wed Sep 22 17:29:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 30460 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp753180iob; Wed, 22 Sep 2021 10:29:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcueyn/f7e89gKd0ksO8RpuEFsALZBWq8UZhrgkFhC39XglNbXGG5Wi8t7JzFG3j+AjR+7 X-Received: by 2002:a17:907:6004:: with SMTP id fs4mr298417ejc.567.1632331784641; Wed, 22 Sep 2021 10:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632331784; cv=none; d=google.com; s=arc-20160816; b=yHRD31dxtEg0XsrLSo8NqlUVhCGAJZk9/QNYDPO4KWLnQCI/fvrC/9k1RjuNvjw3Hf 6ULzw1seNs0MN55BJPLAisJ7Gt8yQUDiZ+Krblf29uVbL76hKcJJF0qcStBhJZVaiYju b5VMwzUbrej2JRY6Bd7YA6pOf9YLvWZkrqr+mupNoYEJY8WyFH2u/YTQWk4QDzAj5+aA 5zD+FqhQy4y868S/843VMtFd5uRDolRCwYPYibjINUKBlLNohv0GkKkz/DF0K2I+X1w6 7MJTcI1Y2Et00KC4aOcwQUkfAnlA0Dqw25a2JFwpMtmLhIvpfzKMHth6EB2cyLDvMGSj 7Y7A== 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=nN/0amMk62Ep4coEU9va41y4sRMnis1KJ4yAiTzguPE=; b=TY8e0OxO7T89AYxaw4HhGj8Y9VwBdfAMZkA37k3MWF8VOCMaCfZOycGQIja81uZvx4 P+97i4mIQSVBrvisjNv3M+Dp+EKhtnSX3vSafB8BrWR34zRsgWJpx2WZall3DJ0Gx6On 2C2rOKq/NiHWiuljEJ7RPourmHqAoa+UdrM2UbeWnYN9Vhn50hyOkyDOf5viM8MTW1rP oOw25Wr4JYHrQI6PoDINKrWnDndCJ75zBkO3/LKsynI2/X0aLXtzzEUoeIfsqo51jwiG yUCAqkyGdwhQf6O1zh5GvmsVBXUmm3aiYI/x2RgYMKWXqJK3+ze7ZIQFcF+oJI9VNCzU wbog== 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 co23si258317edb.449.2021.09.22.10.29.43; Wed, 22 Sep 2021 10:29:44 -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 7E6C968AB0D; Wed, 22 Sep 2021 20:29:29 +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 C2EAD68AB1D for ; Wed, 22 Sep 2021 20:29:22 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 2E8EAE5CFC; Wed, 22 Sep 2021 19:29:22 +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 8QQZMmcqIQld; Wed, 22 Sep 2021 19:29:20 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A45B1E5E82; Wed, 22 Sep 2021 19:29:20 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Sep 2021 19:29:12 +0200 Message-Id: <20210922172914.17914-2-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 2/4] avformat/mpegts: delay allocation of PES buffer 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: Ijc8fykJFI5m This allows us to allocate the buffer in a single code path. Signed-off-by: Marton Balint --- libavformat/mpegts.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index fcb32ecd28..2620e79f57 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1189,11 +1189,6 @@ static int mpegts_push_data(MpegTSFilter *filter, if (!pes->total_size) pes->total_size = MAX_PES_PAYLOAD; - /* allocate pes buffer */ - pes->buffer = buffer_pool_get(ts, pes->total_size); - if (!pes->buffer) - return AVERROR(ENOMEM); - if (pes->stream_id != STREAM_ID_PROGRAM_STREAM_MAP && pes->stream_id != STREAM_ID_PRIVATE_STREAM_2 && pes->stream_id != STREAM_ID_ECM_STREAM && @@ -1364,16 +1359,13 @@ skip: } break; case MPEGTS_PAYLOAD: - if (pes->buffer) { + do { if (pes->data_index > 0 && pes->data_index + buf_size > pes->total_size) { ret = new_pes_packet(pes, ts->pkt); if (ret < 0) return ret; pes->total_size = MAX_PES_PAYLOAD; - pes->buffer = buffer_pool_get(ts, pes->total_size); - if (!pes->buffer) - return AVERROR(ENOMEM); ts->stop_parse = 1; } else if (pes->data_index == 0 && buf_size > pes->total_size) { @@ -1381,6 +1373,13 @@ skip: // not sure if this is legal in ts but see issue #2392 buf_size = pes->total_size; } + + if (!pes->buffer) { + pes->buffer = buffer_pool_get(ts, pes->total_size); + if (!pes->buffer) + return AVERROR(ENOMEM); + } + memcpy(pes->buffer->data + pes->data_index, p, buf_size); pes->data_index += buf_size; /* emit complete packets with known packet size @@ -1392,10 +1391,11 @@ skip: pes->pes_header_size + pes->data_index == pes->total_size + PES_START_SIZE) { ts->stop_parse = 1; ret = new_pes_packet(pes, ts->pkt); + pes->state = MPEGTS_SKIP; if (ret < 0) return ret; } - } + } while (0); buf_size = 0; break; case MPEGTS_SKIP: 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; From patchwork Wed Sep 22 17:29:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 30459 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp753539iob; Wed, 22 Sep 2021 10:30:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA295/tLYQKzmnTTRgVDdyVNzih1xErjlCmLC7SJLyitBtHpjbviMic0/WYcLBmmu+WQfz X-Received: by 2002:a17:906:dbf2:: with SMTP id yd18mr358656ejb.536.1632331806880; Wed, 22 Sep 2021 10:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632331806; cv=none; d=google.com; s=arc-20160816; b=TQ7My16oRUtqAL8+/St+XLZ53o2ODz6A2kxzbg2G2orbxDQjO3+5PV50YEZ8yWEJkI q31ELha0piMUkFGUnP84dK3TMcaUdqmhx8+MUT3f6lUlDZ+EmlErEDRU/novCbqCqpj5 pGqYRJ7jVkyBTiM0xOhWlRusIJ4vu4T8a+6ArElTTWvwhCixGF+fSpH+LJQe3tnHDbZE Y509zRplh45vB4VbjuCGHvv0A56V5Lp46x+nukyp78UVJF8pajCFT8Kty3vAONf0i66S tZaMVHHouT/Td0mhCVDEvOdPywrKipHYadTf5KN8DdWVL0DdTo8AD4fhsRxTsx0mGJZA eVMg== 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=yvEBP4si4hLoild8Rj0enFgkVyfx0kNCaRZKFOEk5PY=; b=A0+CiNYvKj/DFUeQEAafJk7QSCPwSmLcsJ1LhohKddrUXNrgeghEpRjdFUkf0Bv7oa AWtQ8zWpgOWyaSALuh9vSYhKdfVrwO5OfW2qgneDprECqYFfM3SnfIR4P6HSJk8qrQhT D9gH2+FkZI07t8t7p2TbABYi1/uTi9BeJXfVRsGsu5JycEyP0u40MaDndtsdJM5CK2O5 RcFURM4D0uj2am6z7I1u037Wol5uIdqFiKASECSqpaH9mbdFVjS9ST0Q/atzSHpSUm+b RK/SNkgwKs/nAx0FaqZi9td6+LmHHdmMGIzESf2Rkt324rBSmEEFltr0aqC0EWbRyGoN 4Rew== 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 eb10si2234330edb.16.2021.09.22.10.30.06; Wed, 22 Sep 2021 10:30:06 -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 8422468ACF8; Wed, 22 Sep 2021 20:29:34 +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 D0C4868AB51 for ; Wed, 22 Sep 2021 20:29:27 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BC0E0E5E81; Wed, 22 Sep 2021 19:29:27 +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 ZwJToZTedDE6; Wed, 22 Sep 2021 19:29:26 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id F37DAE5E85; Wed, 22 Sep 2021 19:29:25 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Sep 2021 19:29:14 +0200 Message-Id: <20210922172914.17914-4-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 4/4] avformat/mpegts: fix max_packet_size in mpegts payload parsing 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: BBU45jLqcFjO The maximum allowed useful PES payload data was set to PES_packet_length, but it is in fact smaller by the length of the PES header. This changes how corrupt streams are packetized: - If PES header length is bigger than PES_packet_length then the PES packet payload will be handled as an unbound packet - PES packets with payload across multiple MPEGTS packets will always be splitted if with the next chunk of data the payload should exceed PES_packet_length, previously a PES_header_length amount of excess was allowed. Fixes ticket #9355. Signed-off-by: Marton Balint --- libavformat/mpegts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 7d2e7407c1..0029c4ca76 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1358,8 +1358,8 @@ skip: 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->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; if (pes->data_index > 0 && pes->data_index + buf_size > max_packet_size) {