[vlc-commits] demux: ts/hls: add support for metadata

Francois Cartegnie git at videolan.org
Sat Oct 15 23:16:13 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Oct  8 19:27:28 2016 +0200| [17acf2dc07f82c52d73d2a646f21b8031f60fd29] | committer: Francois Cartegnie

demux: ts/hls: add support for metadata

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

 modules/demux/Makefile.am               |  1 +
 modules/demux/mpeg/ts.c                 |  9 ++++++
 modules/demux/mpeg/ts_metadata.c        | 54 +++++++++++++++++++++++++++++++++
 modules/demux/mpeg/ts_metadata.h        | 24 +++++++++++++++
 modules/demux/mpeg/ts_psi.c             | 23 ++++++++++++++
 modules/demux/mpeg/ts_streams.c         |  2 ++
 modules/demux/mpeg/ts_streams_private.h |  6 ++++
 7 files changed, 119 insertions(+)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 22a2051..857f732 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -246,6 +246,7 @@ libts_plugin_la_SOURCES = demux/mpeg/ts.c demux/mpeg/ts.h \
         demux/mpeg/sections.c demux/mpeg/sections.h \
         demux/mpeg/mpeg4_iod.c demux/mpeg/mpeg4_iod.h \
         demux/mpeg/ts_sl.c demux/mpeg/ts_sl.h \
+        demux/mpeg/ts_metadata.c demux/mpeg/ts_metadata.h \
         demux/mpeg/ts_hotfixes.c demux/mpeg/ts_hotfixes.h \
         demux/mpeg/ts_strings.h demux/mpeg/ts_streams_private.h \
         demux/mpeg/pes.h \
diff --git a/modules/demux/mpeg/ts.c b/modules/demux/mpeg/ts.c
index 7c36598..8d47ad4 100644
--- a/modules/demux/mpeg/ts.c
+++ b/modules/demux/mpeg/ts.c
@@ -44,6 +44,7 @@
 
 #include "ts_hotfixes.h"
 #include "ts_sl.h"
+#include "ts_metadata.h"
 #include "sections.h"
 #include "pes.h"
 #include "timestamps.h"
@@ -1467,6 +1468,13 @@ static void ParsePES( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
                         p_block->i_pts += FROM_SCALE_NZ(p_pmt->pcr.i_pcroffset);
                 }
 
+                /* METADATA in PES */
+                if( pid->u.p_pes->i_stream_type == 0x15 && i_stream_id == 0xbd )
+                {
+                    ProcessMetadata( p_demux->out, p_es->metadata.i_format, p_pmt->i_number,
+                                     p_block->p_buffer, p_block->i_buffer );
+                }
+
                 /* SL in PES */
                 if( pid->u.p_pes->i_stream_type == 0x12 &&
                     ((i_stream_id & 0xFE) == 0xFA) /* 0xFA || 0xFB */ )
@@ -2486,6 +2494,7 @@ static bool PIDReferencedByProgram( const ts_pmt_t *p_pmt, uint16_t i_pid )
 static void DoCreateES( demux_t *p_demux, ts_pes_es_t *p_es, const ts_pes_es_t *p_parent_es )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
+
     for( ; p_es ; p_es = p_es->p_next )
     {
         if( !p_es->id )
diff --git a/modules/demux/mpeg/ts_metadata.c b/modules/demux/mpeg/ts_metadata.c
new file mode 100644
index 0000000..7af21b5
--- /dev/null
+++ b/modules/demux/mpeg/ts_metadata.c
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * ts_metadata.c : TS demuxer metadata handling
+ *****************************************************************************
+ * Copyright (C) 2016 - VideoLAN Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_meta.h>
+#include <vlc_es_out.h>
+
+#include "ts_metadata.h"
+#include "../meta_engine/ID3Tag.h"
+#include "../meta_engine/ID3Meta.h"
+
+static int ID3TAG_Parse_Handler( uint32_t i_tag, const uint8_t *p_payload,
+                                 size_t i_payload, void *p_priv )
+{
+    vlc_meta_t *p_meta = (vlc_meta_t *) p_priv;
+
+    (void) ID3HandleTag( p_payload, i_payload, i_tag, p_meta, NULL );
+
+    return VLC_SUCCESS;
+}
+
+void ProcessMetadata( es_out_t *out, uint32_t i_format, uint16_t i_program,
+                      const uint8_t *p_buffer, size_t i_buffer )
+{
+    if( i_format == VLC_FOURCC('I', 'D', '3', ' ') )
+    {
+        vlc_meta_t *p_meta = vlc_meta_New();
+        if( p_meta )
+        {
+            (void) ID3TAG_Parse( p_buffer, i_buffer, ID3TAG_Parse_Handler, p_meta );
+            es_out_Control( out, ES_OUT_SET_GROUP_META, i_program, p_meta );
+            vlc_meta_Delete( p_meta );
+        }
+    }
+}
diff --git a/modules/demux/mpeg/ts_metadata.h b/modules/demux/mpeg/ts_metadata.h
new file mode 100644
index 0000000..4657b5e
--- /dev/null
+++ b/modules/demux/mpeg/ts_metadata.h
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * ts_metadata.h : TS demuxer metadata handling
+ *****************************************************************************
+ * Copyright (C) 2016 - VideoLAN Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *****************************************************************************/
+#ifndef VLC_TS_METADATA_H
+#define VLC_TS_METADATA_H
+
+void ProcessMetadata( es_out_t *, uint32_t, uint16_t, const uint8_t *, size_t );
+
+#endif
diff --git a/modules/demux/mpeg/ts_psi.c b/modules/demux/mpeg/ts_psi.c
index 6fae02c..02ebf97 100644
--- a/modules/demux/mpeg/ts_psi.c
+++ b/modules/demux/mpeg/ts_psi.c
@@ -405,6 +405,26 @@ static void SetupISO14496Descriptors( demux_t *p_demux, ts_pes_t *p_pes,
     }
 }
 
+static void SetupMetadataDescriptors( demux_t *p_demux, ts_pes_es_t *p_es, const dvbpsi_pmt_es_t *p_dvbpsies )
+{
+    const dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_dvbpsies, 0x26 );
+    if( p_dr && p_dr->i_length >= 13 )
+    {
+        /* app format 0xFFFF
+         * metadata_application_format_identifier ID3\x20
+         * i_metadata_format 0xFF
+         * metadata_format_identifier ID3\x20 */
+        if( !memcmp( p_dr->p_data, "\xFF\xFFID3 \xFFID3 ", 11 ) &&
+            (p_dr->p_data[12] & 0xF0) == 0x00 )
+        {
+            p_es->metadata.i_format = VLC_FOURCC('I', 'D', '3', ' ');
+            p_es->metadata.i_service_id = p_dr->p_data[11];
+            msg_Dbg( p_demux, "     - found Metadata_descriptor type ID3 with service_id=0x%"PRIx8,
+                     p_dr->p_data[11] );
+        }
+    }
+}
+
 static void SetupAVCDescriptors( demux_t *p_demux, ts_pes_es_t *p_es, const dvbpsi_pmt_es_t *p_dvbpsies )
 {
     const dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_dvbpsies, 0x28 );
@@ -1335,6 +1355,9 @@ static void FillPESFromDvbpsiES( demux_t *p_demux,
         case 0x12:
             SetupISO14496Descriptors( p_demux, p_pes, p_pmt, p_dvbpsies );
             break;
+        case 0x15:
+            SetupMetadataDescriptors( p_demux, p_pes->p_es, p_dvbpsies );
+            break;
         case 0x1b:
             SetupAVCDescriptors( p_demux, p_pes->p_es, p_dvbpsies );
             break;
diff --git a/modules/demux/mpeg/ts_streams.c b/modules/demux/mpeg/ts_streams.c
index 379796e..5080698 100644
--- a/modules/demux/mpeg/ts_streams.c
+++ b/modules/demux/mpeg/ts_streams.c
@@ -174,6 +174,8 @@ ts_pes_es_t * ts_pes_es_New( ts_pmt_t *p_program )
         p_es->b_interlaced = false;
         es_format_Init( &p_es->fmt, UNKNOWN_ES, 0 );
         p_es->fmt.i_group = p_program->i_number;
+        p_es->metadata.i_format = 0;
+        p_es->metadata.i_service_id = 0;
     }
     return p_es;
 }
diff --git a/modules/demux/mpeg/ts_streams_private.h b/modules/demux/mpeg/ts_streams_private.h
index a01068d..25a8d55 100644
--- a/modules/demux/mpeg/ts_streams_private.h
+++ b/modules/demux/mpeg/ts_streams_private.h
@@ -85,6 +85,12 @@ struct ts_pes_es_t
     ts_pes_es_t *p_next; /* Next es on same pid from different pmt (shared pid) */
     /* J2K stuff */
     uint8_t  b_interlaced;
+    /* Metadata */
+    struct
+    {
+        uint8_t i_service_id;
+        uint32_t i_format;
+    } metadata;
 };
 
 typedef enum



More information about the vlc-commits mailing list