[vlc-commits] demux: ts: convert metadata handler to stream processor

Francois Cartegnie git at videolan.org
Wed Jun 21 21:34:16 CEST 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jun 20 11:13:30 2017 +0200| [428dee0f6156ade76f6109f798ac384716425328] | committer: Francois Cartegnie

demux: ts: convert metadata handler to stream processor

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

 modules/demux/mpeg/ts.c          |  6 ----
 modules/demux/mpeg/ts_metadata.c | 62 ++++++++++++++++++++++++++++++++++++----
 modules/demux/mpeg/ts_metadata.h |  2 +-
 modules/demux/mpeg/ts_psi.c      |  8 ++++--
 4 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/modules/demux/mpeg/ts.c b/modules/demux/mpeg/ts.c
index de8d18a823..51383c57dc 100644
--- a/modules/demux/mpeg/ts.c
+++ b/modules/demux/mpeg/ts.c
@@ -1570,12 +1570,6 @@ static void ParsePESDataChain( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
                         ts_stream_processor_Reset( pid->u.p_stream->p_proc );
                     p_block = ts_stream_processor_Push( pid->u.p_stream->p_proc, i_stream_id, p_block );
                 }
-                /* METADATA in PES */
-                else if( pid->u.p_stream->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 );
-                }
                 else
                 /* Some codecs might need xform or AU splitting */
                 {
diff --git a/modules/demux/mpeg/ts_metadata.c b/modules/demux/mpeg/ts_metadata.c
index 7af21b50cc..906a0a9fcb 100644
--- a/modules/demux/mpeg/ts_metadata.c
+++ b/modules/demux/mpeg/ts_metadata.c
@@ -23,8 +23,13 @@
 #include <vlc_common.h>
 #include <vlc_meta.h>
 #include <vlc_es_out.h>
+#include <vlc_block.h>
 
+#include "ts_pid.h"
+#include "ts_streams.h"
+#include "ts_streams_private.h"
 #include "ts_metadata.h"
+
 #include "../meta_engine/ID3Tag.h"
 #include "../meta_engine/ID3Meta.h"
 
@@ -38,17 +43,64 @@ static int ID3TAG_Parse_Handler( uint32_t i_tag, const uint8_t *p_payload,
     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 )
+typedef struct
+{
+    es_out_t *out;
+    ts_stream_t *p_stream;
+
+} Metadata_stream_processor_context_t;
+
+static void Metadata_stream_processor_Delete( ts_stream_processor_t *h )
+{
+    Metadata_stream_processor_context_t *ctx = (Metadata_stream_processor_context_t *) h->priv;
+    free( ctx );
+    free( h );
+}
+
+static block_t * Metadata_stream_processor_Push( ts_stream_processor_t *h, uint8_t i_stream_id, block_t *p_block )
 {
-    if( i_format == VLC_FOURCC('I', 'D', '3', ' ') )
+    Metadata_stream_processor_context_t *ctx = (Metadata_stream_processor_context_t *) h->priv;
+    ts_es_t *p_es = ctx->p_stream->p_es;
+
+    if( i_stream_id != 0xbd )
+    {
+        block_Release( p_block );
+        return NULL;
+    }
+
+    if( p_es->metadata.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 );
+            (void) ID3TAG_Parse( p_block->p_buffer, p_block->i_buffer, ID3TAG_Parse_Handler, p_meta );
+            es_out_Control( ctx->out, ES_OUT_SET_GROUP_META, p_es->p_program->i_number, p_meta );
             vlc_meta_Delete( p_meta );
         }
     }
+
+    return p_block;
+}
+
+ts_stream_processor_t *Metadata_stream_processor_New( ts_stream_t *p_stream, es_out_t *out )
+{
+    ts_stream_processor_t *h = malloc(sizeof(*h));
+    if(!h)
+        return NULL;
+
+    Metadata_stream_processor_context_t *ctx = malloc( sizeof(Metadata_stream_processor_context_t) );
+    if(!ctx)
+    {
+        free(h);
+        return NULL;
+    }
+    ctx->out = out;
+    ctx->p_stream = p_stream;
+
+    h->priv = ctx;
+    h->pf_delete = Metadata_stream_processor_Delete;
+    h->pf_push = Metadata_stream_processor_Push;
+    h->pf_reset = NULL;
+
+    return h;
 }
diff --git a/modules/demux/mpeg/ts_metadata.h b/modules/demux/mpeg/ts_metadata.h
index 4657b5eb03..0757c7f988 100644
--- a/modules/demux/mpeg/ts_metadata.h
+++ b/modules/demux/mpeg/ts_metadata.h
@@ -19,6 +19,6 @@
 #ifndef VLC_TS_METADATA_H
 #define VLC_TS_METADATA_H
 
-void ProcessMetadata( es_out_t *, uint32_t, uint16_t, const uint8_t *, size_t );
+ts_stream_processor_t *Metadata_stream_processor_New( ts_stream_t *, es_out_t * );
 
 #endif
diff --git a/modules/demux/mpeg/ts_psi.c b/modules/demux/mpeg/ts_psi.c
index 290d678059..61cd723347 100644
--- a/modules/demux/mpeg/ts_psi.c
+++ b/modules/demux/mpeg/ts_psi.c
@@ -51,6 +51,7 @@
 #include "ts_scte.h"
 #include "ts_psip.h"
 #include "ts_si.h"
+#include "ts_metadata.h"
 
 #include "../access/dtv/en50221_capmt.h"
 
@@ -492,8 +493,9 @@ static void SetupISO14496Descriptors( demux_t *p_demux, ts_stream_t *p_pes,
     }
 }
 
-static void SetupMetadataDescriptors( demux_t *p_demux, ts_es_t *p_es, const dvbpsi_pmt_es_t *p_dvbpsies )
+static void SetupMetadataDescriptors( demux_t *p_demux, ts_stream_t *p_stream, const dvbpsi_pmt_es_t *p_dvbpsies )
 {
+    ts_es_t *p_es = p_stream->p_es;
     const dvbpsi_descriptor_t *p_dr = PMTEsFindDescriptor( p_dvbpsies, 0x26 );
     if( p_dr && p_dr->i_length >= 13 )
     {
@@ -508,6 +510,8 @@ static void SetupMetadataDescriptors( demux_t *p_demux, ts_es_t *p_es, const dvb
             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] );
+            if( !p_stream->p_proc )
+                p_stream->p_proc = Metadata_stream_processor_New( p_stream, p_demux->out );
         }
     }
 }
@@ -1463,7 +1467,7 @@ static void FillPESFromDvbpsiES( demux_t *p_demux,
             SetupISO14496Descriptors( p_demux, p_pes, p_pmt, p_dvbpsies );
             break;
         case 0x15:
-            SetupMetadataDescriptors( p_demux, p_pes->p_es, p_dvbpsies );
+            SetupMetadataDescriptors( p_demux, p_pes, p_dvbpsies );
             break;
         case 0x1b:
             SetupAVCDescriptors( p_demux, p_pes->p_es, p_dvbpsies );



More information about the vlc-commits mailing list