From patchwork Tue Nov 12 21:28:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 16225 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EFDF644A5E4 for ; Tue, 12 Nov 2019 23:29:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CCC9168A4AB; Tue, 12 Nov 2019 23:29:20 +0200 (EET) 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 A949B68A323 for ; Tue, 12 Nov 2019 23:29:14 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 58287E3E42; Tue, 12 Nov 2019 22:29:14 +0100 (CET) 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 7cwHQMm9PdJk; Tue, 12 Nov 2019 22:29:12 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DCE26E3E2F; Tue, 12 Nov 2019 22:29:11 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Nov 2019 22:28:57 +0100 Message-Id: <20191112212906.18539-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH 01/10] avformat/mpegtsenc: allow any sensible PID for elementary and pmt pids X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also make sure that assigned PID numbers are valid and fix the error message for the previous PID collision checks. Signed-off-by: Marton Balint --- doc/muxers.texi | 7 ++++--- libavformat/mpegts.h | 4 ++++ libavformat/mpegtsenc.c | 21 ++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 09ded7d48a..c36ae60f19 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1582,11 +1582,12 @@ Advanced Codec Digital HDTV service. @end table @item mpegts_pmt_start_pid @var{integer} -Set the first PID for PMT. Default is @code{0x1000}. Max is @code{0x1f00}. +Set the first PID for PMTs. Default is @code{0x1000}, minimum is @code{0x0010}, +maximum is @code{0x1ffe}. @item mpegts_start_pid @var{integer} -Set the first PID for data packets. Default is @code{0x0100}. Max is -@code{0x0f00}. +Set the first PID for elementary streams. Default is @code{0x0100}, minimum is +@code{0x0010}, maximum is @code{0x1ffe}. @item mpegts_m2ts_mode @var{boolean} Enable m2ts mode if set to @code{1}. Default value is @code{-1} which diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h index ecc3d3374c..9a7f2c1d11 100644 --- a/libavformat/mpegts.h +++ b/libavformat/mpegts.h @@ -63,6 +63,10 @@ * streams and other data tables */ #define NULL_PID 0x1FFF /* Null packet (used for fixed bandwidth padding) */ +/* PMT and elementary stream PID range */ +#define FIRST_OTHER_PID 0x0010 +#define LAST_OTHER_PID 0x1FFE + /* table ids */ #define PAT_TID 0x00 /* Program Association section */ #define CAT_TID 0x01 /* Conditional Access section */ diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 9f8f1715c9..fbc7305dc1 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -912,19 +912,26 @@ static int mpegts_init(AVFormatContext *s) /* MPEG pid values < 16 are reserved. Applications which set st->id in * this range are assigned a calculated pid. */ - if (st->id < 16) { + if (st->id < FIRST_OTHER_PID) { ts_st->pid = ts->start_pid + i; - } else if (st->id < 0x1FFF) { - ts_st->pid = st->id; } else { + ts_st->pid = st->id; + } + if (ts_st->pid > LAST_OTHER_PID) { av_log(s, AV_LOG_ERROR, - "Invalid stream id %d, must be less than 8191\n", st->id); + "Invalid stream id %d, must be less than %d\n", st->id, LAST_OTHER_PID + 1); ret = AVERROR(EINVAL); goto fail; } for (j = 0; j < ts->nb_services; j++) { + if (ts->services[j]->pmt.pid > LAST_OTHER_PID) { + av_log(s, AV_LOG_ERROR, + "Invalid PMT PID %d, must be less than %d\n", ts->services[j]->pmt.pid, LAST_OTHER_PID + 1); + ret = AVERROR(EINVAL); + goto fail; + } if (ts_st->pid == ts->services[j]->pmt.pid) { - av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", ts_st->pid); + av_log(s, AV_LOG_ERROR, "PID %d cannot be both elementary and PMT PID\n", ts_st->pid); ret = AVERROR(EINVAL); goto fail; } @@ -1888,10 +1895,10 @@ static const AVOption options[] = { AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" }, { "mpegts_pmt_start_pid", "Set the first pid of the PMT.", offsetof(MpegTSWrite, pmt_start_pid), AV_OPT_TYPE_INT, - { .i64 = 0x1000 }, 0x0010, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM }, + { .i64 = 0x1000 }, FIRST_OTHER_PID, LAST_OTHER_PID, AV_OPT_FLAG_ENCODING_PARAM }, { "mpegts_start_pid", "Set the first pid.", offsetof(MpegTSWrite, start_pid), AV_OPT_TYPE_INT, - { .i64 = 0x0100 }, 0x0010, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM }, + { .i64 = 0x0100 }, FIRST_OTHER_PID, LAST_OTHER_PID, AV_OPT_FLAG_ENCODING_PARAM }, { "mpegts_m2ts_mode", "Enable m2ts mode.", offsetof(MpegTSWrite, m2ts_mode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, AV_OPT_FLAG_ENCODING_PARAM },