From patchwork Tue Nov 12 21:29:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 16233 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 E3DBB44A5E4 for ; Tue, 12 Nov 2019 23:29:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D2A4468AA4A; Tue, 12 Nov 2019 23:29:34 +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 569F268A8E4 for ; Tue, 12 Nov 2019 23:29:28 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3EDBFE3E44; Tue, 12 Nov 2019 22:29:28 +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 F28QZmQyo29g; Tue, 12 Nov 2019 22:29:26 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 182FFE3E45; Tue, 12 Nov 2019 22:29:26 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Nov 2019 22:29:04 +0100 Message-Id: <20191112212906.18539-8-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20191112212906.18539-1-cus@passwd.hu> References: <20191112212906.18539-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 08/10] avformat/mpegtsenc: simulate a CBR stream for m2ts mode 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" Signed-off-by: Marton Balint --- libavformat/mpegtsenc.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index a4b28f7d74..2191c134ac 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -35,6 +35,7 @@ #include "mpegts.h" #define PCR_TIME_BASE 27000000 +#define M2TS_DEFAULT_MUXRATE 54000000 /* write DVB SI sections */ @@ -869,8 +870,13 @@ static int mpegts_init(AVFormatContext *s) ts->m2ts_subtitle_pid = 0x1200; ts->m2ts_other_pid = 0x1300; // should not be needed - if (ts->m2ts_mode) + if (ts->m2ts_mode) { ts->pmt_start_pid = 0x0100; + if (ts->mux_rate <= 1) { + ts->mux_rate = M2TS_DEFAULT_MUXRATE; + av_log(s, AV_LOG_INFO, "Muxrate is not set for m2ts mode, using %d bps\n", ts->mux_rate); + } + } if (s->max_delay < 0) /* Not set by the caller */ s->max_delay = 0; @@ -1088,11 +1094,17 @@ static int write_pcr_bits(uint8_t *buf, int64_t pcr) } /* Write a single null transport stream packet */ -static void mpegts_insert_null_packet(AVFormatContext *s) +static void mpegts_insert_null_packet(AVFormatContext *s, int force) { + MpegTSWrite *ts = s->priv_data; uint8_t *q; uint8_t buf[TS_PACKET_SIZE]; + if (ts->m2ts_mode && !force) { + ts->nb_packets++; + return; + } + q = buf; *q++ = 0x47; *q++ = 0x00 | 0x1f; @@ -1251,7 +1263,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, if (write_pcr) mpegts_insert_pcr_only(s, st); else - mpegts_insert_null_packet(s); + mpegts_insert_null_packet(s, 0); /* recalculate write_pcr and possibly retransmit si_info */ continue; } @@ -1824,7 +1836,7 @@ static void mpegts_write_flush(AVFormatContext *s) if (ts->m2ts_mode) { int packets = (avio_tell(s->pb) / (TS_PACKET_SIZE + 4)) % 32; while (packets++ < 32) - mpegts_insert_null_packet(s); + mpegts_insert_null_packet(s, 1); } }