[vlc-commits] mux: ts: move stream type/id settings

Francois Cartegnie git at videolan.org
Wed Dec 14 14:14:02 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Dec 14 13:20:49 2016 +0100| [9f1eaa9c618db8168e326f2b6d806c80ef7aeff0] | committer: Francois Cartegnie

mux: ts: move stream type/id settings

So it now applies to content created by demux's PMT hotfix

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9f1eaa9c618db8168e326f2b6d806c80ef7aeff0
---

 modules/demux/mpeg/ts_hotfixes.c |  14 +++-
 modules/mux/mpeg/tables.c        | 136 ++++++++++++++++++++++++++++++++++++
 modules/mux/mpeg/tables.h        |   4 ++
 modules/mux/mpeg/ts.c            | 145 +++------------------------------------
 4 files changed, 160 insertions(+), 139 deletions(-)

diff --git a/modules/demux/mpeg/ts_hotfixes.c b/modules/demux/mpeg/ts_hotfixes.c
index 76bac43..78b5662 100644
--- a/modules/demux/mpeg/ts_hotfixes.c
+++ b/modules/demux/mpeg/ts_hotfixes.c
@@ -313,6 +313,8 @@ void MissingPATPMTFixup( demux_t *p_demux )
         return;
     }
 
+    ts_mux_standard mux_standard = (p_sys->standard == TS_STANDARD_ATSC) ? TS_MUX_STANDARD_ATSC
+                                                                         : TS_MUX_STANDARD_DVB;
     struct esstreams_t
     {
         pes_stream_t pes;
@@ -332,8 +334,14 @@ void MissingPATPMTFixup( demux_t *p_demux )
                 p_pid->probed.i_type == -1 )
                 continue;
 
-            esstreams[j].pes.i_codec = p_pid->probed.i_fourcc;
-            esstreams[j].ts.i_stream_type = p_pid->probed.i_type;
+            esfmt.i_codec = p_pid->probed.i_fourcc;
+            if( VLC_SUCCESS !=
+                FillPMTESParams(mux_standard, &esfmt, &esstreams[j].ts, &esstreams[j].pes ) )
+                continue;
+
+            /* Important for correct remapping: Enforce probed PES stream id */
+            esstreams[j].pes.i_stream_id = p_pid->probed.i_stream_id;
+
             esstreams[j].ts.i_pid = p_pid->i_pid;
             mapped[j].pes = &esstreams[j].pes;
             mapped[j].ts = &esstreams[j].ts;
@@ -342,7 +350,7 @@ void MissingPATPMTFixup( demux_t *p_demux )
         }
 
         BuildPMT( GetPID(p_sys, 0)->u.p_pat->handle, VLC_OBJECT(p_demux),
-                 p_sys->standard == TS_STANDARD_ATSC ? TS_MUX_STANDARD_ATSC : TS_MUX_STANDARD_DVB,
+                 mux_standard,
                 p_program_pid, BuildPMTCallback,
                 0, 1,
                 i_pcr_pid,
diff --git a/modules/mux/mpeg/tables.c b/modules/mux/mpeg/tables.c
index aeb40bc..59f7a81 100644
--- a/modules/mux/mpeg/tables.c
+++ b/modules/mux/mpeg/tables.c
@@ -41,6 +41,7 @@
 #include "tsutil.h"
 #include "tables.h"
 #include "bits.h"
+#include "pes.h"
 
 block_t *WritePSISection( dvbpsi_psi_section_t* p_section )
 {
@@ -603,5 +604,140 @@ void BuildPMT( dvbpsi_t *p_dvbpsi, vlc_object_t *p_object,
     }
 }
 
+int FillPMTESParams( ts_mux_standard standard, const es_format_t *fmt,
+                     ts_stream_t *ts, pes_stream_t *pes )
+{
+    switch( fmt->i_codec )
+    {
+    /* VIDEO */
+
+    case VLC_CODEC_MPGV:
+    case VLC_CODEC_MP2V:
+    case VLC_CODEC_MP1V:
+        /* TODO: do we need to check MPEG-I/II ? */
+        ts->i_stream_type = 0x02;
+        pes->i_stream_id = 0xe0;
+        break;
+    case VLC_CODEC_MP4V:
+        ts->i_stream_type = 0x10;
+        pes->i_stream_id = 0xe0;
+        pes->i_es_id = ts->i_pid;
+        break;
+    case VLC_CODEC_HEVC:
+        ts->i_stream_type = 0x24;
+        pes->i_stream_id = 0xe0;
+        break;
+    case VLC_CODEC_H264:
+        ts->i_stream_type = 0x1b;
+        pes->i_stream_id = 0xe0;
+        break;
+    /* XXX dirty dirty but somebody want crapy MS-codec XXX */
+    case VLC_CODEC_H263I:
+    case VLC_CODEC_H263:
+    case VLC_CODEC_WMV3:
+    case VLC_CODEC_WMV2:
+    case VLC_CODEC_WMV1:
+    case VLC_CODEC_DIV3:
+    case VLC_CODEC_DIV2:
+    case VLC_CODEC_DIV1:
+    case VLC_CODEC_MJPG:
+        ts->i_stream_type = 0xa0; /* private */
+        pes->i_stream_id = 0xa0;   /* beurk */
+        break;
+    case VLC_CODEC_DIRAC:
+        /* stream_id makes use of stream_id_extension */
+        pes->i_stream_id = (PES_EXTENDED_STREAM_ID << 8) | 0x60;
+        ts->i_stream_type = 0xd1;
+        break;
+
+    /* AUDIO */
+
+    case VLC_CODEC_MPGA:
+    case VLC_CODEC_MP3:
+        ts->i_stream_type = fmt->audio.i_rate >= 32000 ? 0x03 : 0x04;
+        pes->i_stream_id = 0xc0;
+        break;
+    case VLC_CODEC_A52:
+        pes->i_stream_id = 0xbd;
+        if( standard == TS_MUX_STANDARD_ATSC )
+        {
+            ts->i_stream_type = 0x81;
+        }
+        else
+        {
+            ts->i_stream_type = 0x06;
+        }
+        break;
+    case VLC_CODEC_DVD_LPCM:
+        ts->i_stream_type = 0x83;
+        pes->i_stream_id = 0xbd;
+        break;
+    case VLC_CODEC_OPUS:
+        if (fmt->audio.i_channels > 8)
+            return VLC_EGENERIC;
+        pes->i_stream_id = 0xbd;
+        pes->i_stream_id = 0x06;
+        break;
+    case VLC_CODEC_EAC3:
+        pes->i_stream_id = 0xbd;
+        if( standard == TS_MUX_STANDARD_ATSC )
+        {
+            /* FIXME: Mandatory EAC3 audio_descriptor */
+            ts->i_stream_type = 0x87;
+        }
+        else
+        {
+            ts->i_stream_type = 0x06;
+        }
+        break;
+    case VLC_CODEC_DTS:
+        if( standard == TS_MUX_STANDARD_ATSC )
+        {
+            return VLC_EGENERIC;
+        }
+        else
+        {
+            ts->i_stream_type = 0x06;
+            pes->i_stream_id = 0xbd;
+        }
+        break;
+    case VLC_CODEC_MP4A:
+        /* XXX: make that configurable in some way when LOAS
+         * is implemented for AAC in TS */
+        //ts->i_stream_type = 0x11; /* LOAS/LATM */
+        ts->i_stream_type = 0x0f; /* ADTS */
+        pes->i_stream_id = 0xc0;
+        pes->i_es_id = ts->i_pid;
+        break;
+
+    /* TEXT */
+
+    case VLC_CODEC_SPU:
+        ts->i_stream_type = 0x82;
+        pes->i_stream_id = 0xbd;
+        break;
+    case VLC_CODEC_SUBT:
+        ts->i_stream_type = 0x12;
+        pes->i_stream_id = 0xfa;
+        pes->i_es_id = ts->i_pid;
+        break;
+    case VLC_CODEC_DVBS:
+        ts->i_stream_type = 0x06;
+        pes->i_es_id = fmt->subs.dvb.i_id;
+        pes->i_stream_id = 0xbd;
+        break;
+    case VLC_CODEC_TELETEXT:
+        ts->i_stream_type = 0x06;
+        pes->i_stream_id = 0xbd; /* FIXME */
+        break;
+
+    default:
+        return VLC_EGENERIC;
+    }
+
+    pes->i_codec = fmt->i_codec;
+
+    return VLC_SUCCESS;
+}
 
 #endif
diff --git a/modules/mux/mpeg/tables.h b/modules/mux/mpeg/tables.h
index bb8166d..4aeba36 100644
--- a/modules/mux/mpeg/tables.h
+++ b/modules/mux/mpeg/tables.h
@@ -64,4 +64,8 @@ void BuildPMT( dvbpsi_t *p_dvbpsi, vlc_object_t *p_object,
                unsigned i_programs, ts_stream_t *p_pmt, const int *pi_programs_number,
                unsigned i_mapped_streams, const pes_mapped_stream_t *p_mapped_streams );
 
+
+int FillPMTESParams( ts_mux_standard, const es_format_t *,
+                   ts_stream_t *, pes_stream_t * );
+
 #endif
diff --git a/modules/mux/mpeg/ts.c b/modules/mux/mpeg/ts.c
index dae86d0..7f023e7 100644
--- a/modules/mux/mpeg/ts.c
+++ b/modules/mux/mpeg/ts.c
@@ -931,148 +931,21 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     else
         p_stream->ts.i_pid = AllocatePID( p_mux, p_input->p_fmt->i_cat );
 
-    p_stream->pes.i_codec = p_input->p_fmt->i_codec;
-    if( p_input->p_fmt->i_cat == VIDEO_ES )
-    {
-        p_stream->pes.i_width = p_input->fmt.video.i_width;
-        p_stream->pes.i_height = p_input->fmt.video.i_height;
-    }
-
-    p_stream->ts.i_stream_type = 0x00;
-    switch( p_input->p_fmt->i_codec )
-    {
-    /* VIDEO */
-
-    case VLC_CODEC_MPGV:
-    case VLC_CODEC_MP2V:
-    case VLC_CODEC_MP1V:
-        /* TODO: do we need to check MPEG-I/II ? */
-        p_stream->ts.i_stream_type = 0x02;
-        p_stream->pes.i_stream_id = 0xe0;
-        break;
-    case VLC_CODEC_MP4V:
-        p_stream->ts.i_stream_type = 0x10;
-        p_stream->pes.i_stream_id = 0xe0;
-        p_stream->pes.i_es_id = p_stream->ts.i_pid;
-        break;
-    case VLC_CODEC_HEVC:
-        p_stream->ts.i_stream_type = 0x24;
-        p_stream->pes.i_stream_id = 0xe0;
-        break;
-    case VLC_CODEC_H264:
-        p_stream->ts.i_stream_type = 0x1b;
-        p_stream->pes.i_stream_id = 0xe0;
-        break;
-    /* XXX dirty dirty but somebody want crapy MS-codec XXX */
-    case VLC_CODEC_H263I:
-    case VLC_CODEC_H263:
-    case VLC_CODEC_WMV3:
-    case VLC_CODEC_WMV2:
-    case VLC_CODEC_WMV1:
-    case VLC_CODEC_DIV3:
-    case VLC_CODEC_DIV2:
-    case VLC_CODEC_DIV1:
-    case VLC_CODEC_MJPG:
-        p_stream->ts.i_stream_type = 0xa0; /* private */
-        p_stream->pes.i_stream_id = 0xa0;   /* beurk */
-        break;
-    case VLC_CODEC_DIRAC:
-        /* stream_id makes use of stream_id_extension */
-        p_stream->pes.i_stream_id = (PES_EXTENDED_STREAM_ID << 8) | 0x60;
-        p_stream->ts.i_stream_type = 0xd1;
-        break;
-
-    /* AUDIO */
-
-    case VLC_CODEC_MPGA:
-    case VLC_CODEC_MP3:
-        p_stream->ts.i_stream_type =
-            p_input->p_fmt->audio.i_rate >= 32000 ? 0x03 : 0x04;
-        p_stream->pes.i_stream_id = 0xc0;
-        break;
-    case VLC_CODEC_A52:
-        p_stream->pes.i_stream_id = 0xbd;
-        if( p_sys->standard == TS_MUX_STANDARD_ATSC )
-        {
-            p_stream->ts.i_stream_type = 0x81;
-        }
-        else
-        {
-            p_stream->ts.i_stream_type = 0x06;
-        }
-        break;
-    case VLC_CODEC_DVD_LPCM:
-        p_stream->ts.i_stream_type = 0x83;
-        p_stream->pes.i_stream_id = 0xbd;
-        break;
-    case VLC_CODEC_OPUS:
-        if (p_input->p_fmt->audio.i_channels > 8) {
-            msg_Err(p_mux, "Too many opus channels (%d > 8)",
-                p_input->p_fmt->audio.i_channels);
-            break;
-        }
-    case VLC_CODEC_EAC3:
-        p_stream->pes.i_stream_id = 0xbd;
-        if( p_sys->standard == TS_MUX_STANDARD_ATSC )
-        {
-            /* FIXME: Mandatory EAC3 audio_descriptor */
-            p_stream->ts.i_stream_type = 0x87;
-        }
-        else
-        {
-            p_stream->ts.i_stream_type = 0x06;
-        }
-        break;
-    case VLC_CODEC_DTS:
-        if( p_sys->standard == TS_MUX_STANDARD_ATSC )
-        {
-            return VLC_EGENERIC;
-        }
-        else
-        {
-            p_stream->ts.i_stream_type = 0x06;
-            p_stream->pes.i_stream_id = 0xbd;
-        }
-        break;
-    case VLC_CODEC_MP4A:
-        /* XXX: make that configurable in some way when LOAS
-         * is implemented for AAC in TS */
-        //p_stream->ts.i_stream_type = 0x11; /* LOAS/LATM */
-        p_stream->ts.i_stream_type = 0x0f; /* ADTS */
-        p_stream->pes.i_stream_id = 0xc0;
-        p_stream->pes.i_es_id = p_stream->ts.i_pid;
-        break;
-
-    /* TEXT */
-
-    case VLC_CODEC_SPU:
-        p_stream->ts.i_stream_type = 0x82;
-        p_stream->pes.i_stream_id = 0xbd;
-        break;
-    case VLC_CODEC_SUBT:
-        p_stream->ts.i_stream_type = 0x12;
-        p_stream->pes.i_stream_id = 0xfa;
-        p_stream->pes.i_es_id = p_stream->ts.i_pid;
-        break;
-    case VLC_CODEC_DVBS:
-        p_stream->ts.i_stream_type = 0x06;
-        p_stream->pes.i_es_id = p_input->p_fmt->subs.dvb.i_id;
-        p_stream->pes.i_stream_id = 0xbd;
-        break;
-    case VLC_CODEC_TELETEXT:
-        p_stream->ts.i_stream_type = 0x06;
-        p_stream->pes.i_stream_id = 0xbd; /* FIXME */
-        break;
-    }
-
-    if (p_stream->ts.i_stream_type == 0x00)
+    if( FillPMTESParams( p_sys->standard, p_input->p_fmt,
+                        &p_stream->ts, &p_stream->pes ) != VLC_SUCCESS )
     {
         msg_Warn( p_mux, "rejecting stream with unsupported codec %4.4s",
-                  (char*)&p_stream->pes.i_codec );
+                  (char*)&p_input->fmt.i_codec );
         free( p_stream );
         return VLC_EGENERIC;
     }
 
+    if( p_input->p_fmt->i_cat == VIDEO_ES )
+    {
+        p_stream->pes.i_width = p_input->fmt.video.i_width;
+        p_stream->pes.i_height = p_input->fmt.video.i_height;
+    }
+
     p_stream->pes.i_langs = 1 + p_input->p_fmt->i_extra_languages;
     p_stream->pes.lang = calloc(1, p_stream->pes.i_langs * 4);
     if( !p_stream->pes.lang )



More information about the vlc-commits mailing list