Hi

On Mon, Apr 06, 2015 at 07:37:14AM +0100, JULIAN GARDNER wrote:
[...]
> >On 4/5/2015 11:34 PM, Michael Niedermayer wrote:
> >> this is missing documentation about the units in which sdt_period is.
> >> as is this depends on "mux_rate > 1"
> >> if its intended to stay that way, then this should be documented
> >
> >Yes it depends on muxrate.
> >
> >I'll rework these soon.
> >
> >
> >- Derek
> >_____________________
> 
> Funny seeing all this going on, i had the exact same patch set rejected 4 
> years ago, its still in my personal build.
> 
> 
> http://ffmpeg.org/pipermail/ffmpeg-devel/2011-May/111964.html

I think there was a misunderstanding there somewhere in that thread
i dont see where anyone rejected the patchset

as far as iam concerned IIRC i was waiting for a cleaned up version
to be posted

either way, the patchset is attached for reference, each patch needs
the previous to be applied and they dont apply anymore to head
but can be applied to 8146d16b60ec84aae93cfc4a9444d879f9d5bbfc

[....]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have often repented speaking, but never of holding my tongue.
-- Xenocrates
From aadea97cb45791f6030748ff97e05200566f1f40 Mon Sep 17 00:00:00 2001
From: JULIAN GARDNER <joo...@btinternet.com>
Date: Wed, 18 May 2011 19:52:08 +0100
Subject: [PATCH 1/3] change PAT/PMT/SDT playout to be dependant on PTS and
 not a number of packets.

Signed-off-by: Michael Niedermayer <michae...@gmx.at>
---
 libavformat/mpegtsenc.c |   55 +++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index e7d7001..39185bb 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -56,10 +56,11 @@ typedef struct MpegTSWrite {
     MpegTSSection pat; /* MPEG2 pat table */
     MpegTSSection sdt; /* MPEG2 sdt table context */
     MpegTSService **services;
-    int sdt_packet_count;
-    int sdt_packet_period;
-    int pat_packet_count;
-    int pat_packet_period;
+
+    int64_t sdt_pts;
+    int64_t pmt_pts;
+    int64_t pat_pts;
+
     int nb_services;
     int onid;
     int tsid;
@@ -189,8 +190,9 @@ static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
 
 /* we retransmit the SI info at this rate */
-#define SDT_RETRANS_TIME 500
-#define PAT_RETRANS_TIME 100
+#define SDT_RETRANS_TIME 1250
+#define PAT_RETRANS_TIME 250
+#define PMT_RETRANS_TIME 375
 #define PCR_RETRANS_TIME 20
 
 typedef struct MpegTSWriteStream {
@@ -537,19 +539,17 @@ static int mpegts_write_header(AVFormatContext *s)
 
     ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
 
+    ts->sdt_pts = -1;
+    ts->pmt_pts = -1;
+    ts->pat_pts = -1;
+
     if (ts->mux_rate > 1) {
         service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) /
             (TS_PACKET_SIZE * 8 * 1000);
-        ts->sdt_packet_period      = (ts->mux_rate * SDT_RETRANS_TIME) /
-            (TS_PACKET_SIZE * 8 * 1000);
-        ts->pat_packet_period      = (ts->mux_rate * PAT_RETRANS_TIME) /
-            (TS_PACKET_SIZE * 8 * 1000);
 
         ts->first_pcr = av_rescale(s->max_delay, PCR_TIME_BASE, AV_TIME_BASE);
     } else {
         /* Arbitrary values, PAT/PMT could be written on key frames */
-        ts->sdt_packet_period = 200;
-        ts->pat_packet_period = 40;
         if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
             if (!pcr_st->codec->frame_size) {
                 av_log(s, AV_LOG_WARNING, "frame size not set\n");
@@ -568,17 +568,15 @@ static int mpegts_write_header(AVFormatContext *s)
 
     // output a PCR as soon as possible
     service->pcr_packet_count = service->pcr_packet_period;
-    ts->pat_packet_count = ts->pat_packet_period-1;
-    ts->sdt_packet_count = ts->sdt_packet_period-1;
 
     if (ts->mux_rate == 1)
         av_log(s, AV_LOG_INFO, "muxrate VBR, ");
     else
         av_log(s, AV_LOG_INFO, "muxrate %d, ", ts->mux_rate);
     av_log(s, AV_LOG_INFO, "pcr every %d pkts, "
-           "sdt every %d, pat/pmt every %d pkts\n",
+           "sdt every %d, pat %d, pmt every %d pkts\n",
            service->pcr_packet_period,
-           ts->sdt_packet_period, ts->pat_packet_period);
+           SDT_RETRANS_TIME, PAT_RETRANS_TIME, PMT_RETRANS_TIME);
 
     avio_flush(s->pb);
 
@@ -594,21 +592,28 @@ static int mpegts_write_header(AVFormatContext *s)
 }
 
 /* send SDT, PAT and PMT tables regulary */
-static void retransmit_si_info(AVFormatContext *s)
+static void retransmit_si_info(AVFormatContext *s, int64_t pts)
 {
     MpegTSWrite *ts = s->priv_data;
     int i;
+    int64_t temp_pts;
 
-    if (++ts->sdt_packet_count == ts->sdt_packet_period) {
-        ts->sdt_packet_count = 0;
+    temp_pts = 90*SDT_RETRANS_TIME;
+    if (ts->sdt_pts==-1 || (abs(ts->sdt_pts-pts)>temp_pts)) {
         mpegts_write_sdt(s);
+        ts->sdt_pts = pts;
     }
-    if (++ts->pat_packet_count == ts->pat_packet_period) {
-        ts->pat_packet_count = 0;
+    temp_pts = 90*PAT_RETRANS_TIME;
+    if (ts->pat_pts==-1 || (abs(ts->pat_pts-pts)>temp_pts)) {
         mpegts_write_pat(s);
+        ts->pat_pts = pts;
+    }
+    temp_pts = 90*PMT_RETRANS_TIME;
+    if (ts->pmt_pts==-1 || (abs(ts->pmt_pts-pts)>temp_pts)) {
         for(i = 0; i < ts->nb_services; i++) {
             mpegts_write_pmt(s, ts->services[i]);
         }
+        ts->pmt_pts = pts;
     }
 }
 
@@ -643,7 +648,10 @@ static void mpegts_insert_null_packet(AVFormatContext *s)
     *q++ = 0x00 | 0x1f;
     *q++ = 0xff;
     *q++ = 0x10;
+
+    /* stuffing bytes */
     memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf));
+
     avio_write(s->pb, buf, TS_PACKET_SIZE);
 }
 
@@ -668,7 +676,8 @@ static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
     q = write_pcr_bits(q, get_pcr(ts, s->pb));
 
     /* stuffing bytes */
-    memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
+    memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf));
+
     avio_write(s->pb, buf, TS_PACKET_SIZE);
 }
 
@@ -706,7 +715,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
 
     is_start = 1;
     while (payload_size > 0) {
-        retransmit_si_info(s);
+        retransmit_si_info(s, pts);
 
         write_pcr = 0;
         if (ts_st->pid == ts_st->service->pcr_pid) {
-- 
1.7.9.5

From 3270fcd9200bd80a985f8e42dd7d57c54b6e5595 Mon Sep 17 00:00:00 2001
From: JULIAN GARDNER <joo...@btinternet.com>
Date: Fri, 20 May 2011 15:07:09 +0100
Subject: [PATCH 2/3] change PAT/PMT/SDT playout to be dependant on PTS and
 not a number of packets.

Signed-off-by: Michael Niedermayer <michae...@gmx.at>
---
 libavformat/mpegtsenc.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 39185bb..f96934e 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -58,8 +58,11 @@ typedef struct MpegTSWrite {
     MpegTSService **services;
 
     int64_t sdt_pts;
+    int sdt_timeout;
     int64_t pmt_pts;
+    int pmt_timeout;
     int64_t pat_pts;
+    int pat_timeout;
 
     int nb_services;
     int onid;
@@ -86,6 +89,12 @@ static const AVOption options[] = {
       offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, {.dbl = 0x1000 }, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM},
     { "mpegts_start_pid", "Set the first pid.",
       offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, {.dbl = 0x0100 }, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_pat_playout_rate", "Set the rate to playout the PAT in ms.",
+      offsetof(MpegTSWrite, pat_timeout), FF_OPT_TYPE_INT, {.dbl = 250 }, 125, 500, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_pmt_playout_rate", "Set the rate to playout the PMT in ms.",
+      offsetof(MpegTSWrite, pmt_timeout), FF_OPT_TYPE_INT, {.dbl = 375 }, 250, 750, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_sdt_playout_rate", "Set the rate to playout the SDT in ms.",
+      offsetof(MpegTSWrite, sdt_timeout), FF_OPT_TYPE_INT, {.dbl = 1250 }, 250, 10000, AV_OPT_FLAG_ENCODING_PARAM},
     { NULL },
 };
 
@@ -574,9 +583,9 @@ static int mpegts_write_header(AVFormatContext *s)
     else
         av_log(s, AV_LOG_INFO, "muxrate %d, ", ts->mux_rate);
     av_log(s, AV_LOG_INFO, "pcr every %d pkts, "
-           "sdt every %d, pat %d, pmt every %d pkts\n",
+           "sdt every %d, pat %d, pmt every %d ms\n",
            service->pcr_packet_period,
-           SDT_RETRANS_TIME, PAT_RETRANS_TIME, PMT_RETRANS_TIME);
+           ts->sdt_timeout, ts->pat_timeout, ts->pmt_timeout);
 
     avio_flush(s->pb);
 
@@ -596,20 +605,16 @@ static void retransmit_si_info(AVFormatContext *s, int64_t pts)
 {
     MpegTSWrite *ts = s->priv_data;
     int i;
-    int64_t temp_pts;
 
-    temp_pts = 90*SDT_RETRANS_TIME;
-    if (ts->sdt_pts==-1 || (abs(ts->sdt_pts-pts)>temp_pts)) {
+    if (ts->sdt_pts==-1 || (abs(ts->sdt_pts-pts)>(90*ts->sdt_timeout))) {
         mpegts_write_sdt(s);
         ts->sdt_pts = pts;
     }
-    temp_pts = 90*PAT_RETRANS_TIME;
-    if (ts->pat_pts==-1 || (abs(ts->pat_pts-pts)>temp_pts)) {
+    if (ts->pat_pts==-1 || (abs(ts->pat_pts-pts)>(90*ts->pat_timeout))) {
         mpegts_write_pat(s);
         ts->pat_pts = pts;
     }
-    temp_pts = 90*PMT_RETRANS_TIME;
-    if (ts->pmt_pts==-1 || (abs(ts->pmt_pts-pts)>temp_pts)) {
+    if (ts->pmt_pts==-1 || (abs(ts->pmt_pts-pts)>(90*ts->pmt_timeout))) {
         for(i = 0; i < ts->nb_services; i++) {
             mpegts_write_pmt(s, ts->services[i]);
         }
-- 
1.7.9.5

From 5832a5d5e69dcdb241453c4dd4fbb663d4e1bd12 Mon Sep 17 00:00:00 2001
From: JULIAN GARDNER <joo...@btinternet.com>
Date: Tue, 24 May 2011 13:38:52 +0100
Subject: [PATCH 3/3] change PAT/PMT/SDT playout to be dependant on PTS and
 not a number of packets.

Signed-off-by: Michael Niedermayer <michae...@gmx.at>
---
 libavformat/mpegtsenc.c |   10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index f96934e..1b211ce 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -548,10 +548,6 @@ static int mpegts_write_header(AVFormatContext *s)
 
     ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
 
-    ts->sdt_pts = -1;
-    ts->pmt_pts = -1;
-    ts->pat_pts = -1;
-
     if (ts->mux_rate > 1) {
         service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) /
             (TS_PACKET_SIZE * 8 * 1000);
@@ -606,15 +602,15 @@ static void retransmit_si_info(AVFormatContext *s, int64_t pts)
     MpegTSWrite *ts = s->priv_data;
     int i;
 
-    if (ts->sdt_pts==-1 || (abs(ts->sdt_pts-pts)>(90*ts->sdt_timeout))) {
+    if (abs(ts->sdt_pts-pts)>(90*ts->sdt_timeout)) {
         mpegts_write_sdt(s);
         ts->sdt_pts = pts;
     }
-    if (ts->pat_pts==-1 || (abs(ts->pat_pts-pts)>(90*ts->pat_timeout))) {
+    if (abs(ts->pat_pts-pts)>(90*ts->pat_timeout)) {
         mpegts_write_pat(s);
         ts->pat_pts = pts;
     }
-    if (ts->pmt_pts==-1 || (abs(ts->pmt_pts-pts)>(90*ts->pmt_timeout))) {
+    if (abs(ts->pmt_pts-pts)>(90*ts->pmt_timeout)) {
         for(i = 0; i < ts->nb_services; i++) {
             mpegts_write_pmt(s, ts->services[i]);
         }
-- 
1.7.9.5

Attachment: signature.asc
Description: Digital signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to