[vlc-devel] [PATCH] ttml.c : Added parsing of time and displaying subtitle

Sushma Reddy sushma.reddy at research.iiit.ac.in
Mon Mar 23 18:51:35 CET 2015


>From 92f6de020b2f299121bbffcb4bf738b9cbd7db7f Mon Sep 17 00:00:00 2001
From: sushmareddy <sushma.reddy at reserch.iiit.ac.in>
Date: Mon, 23 Mar 2015 04:10:18 +0530
Subject: [PATCH] Added parsing for subtitle with time and displaying
subtiles

Signed-off-by: sushmareddy <sushma.reddy at reserch.iiit.ac.in>
---
 modules/demux/ttml.c | 92
++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 75 insertions(+), 17 deletions(-)

diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c
index 8b3ab5d..22b64c2 100644
--- a/modules/demux/ttml.c
+++ b/modules/demux/ttml.c
@@ -28,6 +28,8 @@
 #include <vlc_plugin.h>
 #include <vlc_demux.h>
 #include <vlc_xml.h>
+#include <vlc_charset.h>
+

 static int Open( vlc_object_t* p_this );
 static void Close( demux_t* p_demux );
@@ -42,24 +44,39 @@ vlc_module_begin ()
     add_shortcut( "ttml", "subtitle" )
 vlc_module_end ()

+
+typedef struct
+{
+   int64_t i_start;
+   int64_t i_stop;
+
+   char    *psz_text;
+} subtitle_t;
+
 struct demux_sys_t
 {
     xml_t* p_xml;
     xml_reader_t* p_reader;
-
+    int         i_subtitle;
+    int         i_subtitles;
+    subtitle_t  *subtitle;
     es_out_id_t* p_es;
+    int64_t     i_length;
 };

 static int Control( demux_t* p_demux, int i_query, va_list args )
 {
     int64_t *pi64, i64;
+    demux_sys_t *p_sys = p_demux->p_sys;

     switch( i_query )
     {
-        case DEMUX_GET_TIME:
-            pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = 0;
-            break;
+ case DEMUX_GET_TIME:
+ pi64 = (int64_t*)va_arg( args, int64_t * );
+ if(p_sys->i_length)
+ *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
+ return VLC_SUCCESS;
+ return VLC_EGENERIC;
         case DEMUX_GET_LENGTH:
         case DEMUX_SET_TIME:
         case DEMUX_GET_POSITION:
@@ -80,11 +97,34 @@ static int Control( demux_t* p_demux, int i_query,
va_list args )
     return VLC_EGENERIC;
 }

+static int Convert_time(int64_t *timing_value,const char *s)
+{
+    int h1, m1, s1, d1 = 0;
+
+    if ( sscanf( s, "%d:%d:%d,%d",
+                 &h1, &m1, &s1, &d1 ) == 4 ||
+         sscanf( s, "%d:%d:%d.%d",
+                 &h1, &m1, &s1, &d1 ) == 4 ||
+         sscanf( s, "%d:%d:%d",
+                 &h1, &m1, &s1) == 3 )
+    {
+        (*timing_value) = ( (int64_t)h1 * 3600 * 1000 +
+                            (int64_t)m1 * 60 * 1000 +
+                            (int64_t)s1 * 1000 +
+                            (int64_t)d1 ) * 1000;
+
+        return VLC_SUCCESS;
+    }
+
+    return VLC_EGENERIC;
+}
+
+
+
 static int Demux( demux_t* p_demux )
 {
     block_t *p_block = NULL;
     demux_sys_t* p_sys = p_demux->p_sys;
-
     const char* psz_name;
     int i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name );

@@ -97,7 +137,7 @@ static int Demux( demux_t* p_demux )
         char* psz_end = NULL;

         while ( !psz_begin || !psz_end )
-        {
+        {
             const char* psz_attr_value = NULL;
             const char* psz_attr_name = xml_ReaderNextAttr(
p_sys->p_reader, &psz_attr_value );
             if ( !psz_attr_name || !psz_attr_value )
@@ -108,19 +148,36 @@ static int Demux( demux_t* p_demux )
                 psz_end = strdup( psz_attr_value );
         }
         if ( psz_begin && psz_end )
-        {
+        {
             const char* psz_text = NULL;
+    int i_len = 0;
+     subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];
+    p_subtitle = malloc (sizeof(subtitle_t));
             i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_text );
             if ( i_type == XML_READER_TEXT && psz_text != NULL )
-            {
-                p_block = block_Alloc( strlen( psz_text ) );
+            {
+ i_len = strlen(psz_text)+1;
+ if( i_len <= 1 )
+         {
+             p_sys->i_subtitle++;
+         }
+
+         if( ( p_block = block_Alloc( i_len ) ) == NULL )
+         {
+            p_sys->i_subtitle++;
+       }
                 if ( likely( p_block ) )
-                {
-                    memcpy( p_block->p_buffer, psz_text, p_block->i_buffer
);
-                    p_block->p_buffer[p_block->i_buffer] = 0;
-                    //p_block->i_dts = p_block->i_pts = CONVERT( psz_begin
);
-                    //p_block->i_length = CONVERT( psz_end );
-                    es_out_Send( p_demux->out, p_sys->p_es, p_block );
+                {
+    p_subtitle->psz_text = psz_text;
+    Convert_time( &p_subtitle->i_start, psz_begin );
+    Convert_time( &p_subtitle->i_stop, psz_end );
+    p_block->i_dts =
+           p_block->i_pts = VLC_TS_0 + p_subtitle->i_start;
+            if( p_subtitle->i_stop >= 0 && p_subtitle->i_stop >=
p_subtitle->i_start )
+             p_block->i_length = p_subtitle->i_stop - p_subtitle->i_start;
+    memcpy( p_block->p_buffer, psz_text, p_block->i_buffer );
+    es_out_Send( p_demux->out, p_sys->p_es, p_block );
+        p_sys->i_subtitle++;
                 }
             }
         }
@@ -161,7 +218,7 @@ static int Open( vlc_object_t* p_this )
         Close( p_demux );
         return VLC_EGENERIC;
     }
-
+    msg_Dbg(p_demux,"debuging demux enter1");
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;

@@ -170,6 +227,7 @@ static int Open( vlc_object_t* p_this )
     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
     es_format_Clean( &fmt );

+msg_Dbg(p_demux,"debuging open enter2");
     /* Initialize things here */

     return VLC_SUCCESS;
-- 
1.9.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150323/f923753f/attachment.html>


More information about the vlc-devel mailing list