<div dir="ltr"><div>Replaced tab with spaces </div><div><br></div><div><br></div><div>From 65f3062906ad1816af01e9c9fa86a1351c5ebdd9 Mon Sep 17 00:00:00 2001</div><div>From: sushmareddy <<a href="mailto:sushma.reddy@reserch.iiit.ac.in">sushma.reddy@reserch.iiit.ac.in</a>></div><div>Date: Mon, 23 Mar 2015 04:10:18 +0530</div><div>Subject: [PATCH] Added parsing for subtitle with time and displaying subtiles</div><div><br></div><div>Signed-off-by: sushmareddy <<a href="mailto:sushma.reddy@research.iiit.ac.in">sushma.reddy@research.iiit.ac.in</a>></div><div>---</div><div> modules/demux/ttml.c | 96 ++++++++++++++++++++++++++++++++++++++++++++--------</div><div> 1 file changed, 81 insertions(+), 15 deletions(-)</div><div><br></div><div>diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c</div><div>index 8b3ab5d..c4143b0 100644</div><div>--- a/modules/demux/ttml.c</div><div>+++ b/modules/demux/ttml.c</div><div>@@ -28,6 +28,8 @@</div><div> #include <vlc_plugin.h></div><div> #include <vlc_demux.h></div><div> #include <vlc_xml.h></div><div>+#include <vlc_charset.h></div><div>+</div><div> </div><div> static int Open( vlc_object_t* p_this );</div><div> static void Close( demux_t* p_demux );</div><div>@@ -42,24 +44,38 @@ vlc_module_begin ()</div><div>     add_shortcut( "ttml", "subtitle" )</div><div> vlc_module_end ()</div><div> </div><div>-struct demux_sys_t</div><div>+</div><div>+typedef struct</div><div> {</div><div>-    xml_t* p_xml;</div><div>-    xml_reader_t* p_reader;</div><div>+   int64_t    i_start;</div><div>+   int64_t    i_stop;</div><div>+   char    *psz_text;</div><div>+} subtitle_t;</div><div> </div><div>-    es_out_id_t* p_es;</div><div>+struct demux_sys_t</div><div>+{</div><div>+    xml_t*    p_xml;</div><div>+    xml_reader_t*    p_reader;</div><div>+    int    i_subtitle;</div><div>+    int    i_subtitles;</div><div>+    subtitle_t    *subtitle;</div><div>+    es_out_id_t*    p_es;</div><div>+    int64_t    i_length;</div><div> };</div><div> </div><div> static int Control( demux_t* p_demux, int i_query, va_list args )</div><div> {</div><div>     int64_t *pi64, i64;</div><div>+    demux_sys_t *p_sys = p_demux->p_sys;</div><div> </div><div>     switch( i_query )</div><div>     {</div><div>         case DEMUX_GET_TIME:</div><div>             pi64 = (int64_t*)va_arg( args, int64_t * );</div><div>-            *pi64 = 0;</div><div>-            break;</div><div>+            if( p_sys->i_length )</div><div>+                *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;</div><div>+                return VLC_SUCCESS;</div><div>+            return VLC_EGENERIC;</div><div>         case DEMUX_GET_LENGTH:</div><div>         case DEMUX_SET_TIME:</div><div>         case DEMUX_GET_POSITION:</div><div>@@ -80,12 +96,36 @@ static int Control( demux_t* p_demux, int i_query, va_list args )</div><div>     return VLC_EGENERIC;</div><div> }</div><div> </div><div>+static int Convert_time(int64_t *timing_value,const char *s)</div><div>+{</div><div>+    int h1, m1, s1, d1 = 0;</div><div>+</div><div>+    if ( sscanf( s, "%d:%d:%d,%d",</div><div>+                 &h1, &m1, &s1, &d1 ) == 4 ||</div><div>+         sscanf( s, "%d:%d:%d.%d",</div><div>+                 &h1, &m1, &s1, &d1 ) == 4 ||</div><div>+         sscanf( s, "%d:%d:%d",</div><div>+                 &h1, &m1, &s1) == 3 )</div><div>+    {</div><div>+        (*timing_value) = ( (int64_t)h1 * 3600 * 1000 +</div><div>+                            (int64_t)m1 * 60 * 1000 +</div><div>+                            (int64_t)s1 * 1000 +</div><div>+                            (int64_t)d1 ) * 1000;</div><div>+</div><div>+        return VLC_SUCCESS;</div><div>+    }</div><div>+</div><div>+    return VLC_EGENERIC;</div><div>+}</div><div>+</div><div>+</div><div>+</div><div> static int Demux( demux_t* p_demux )</div><div> {</div><div>     block_t *p_block = NULL;</div><div>     demux_sys_t* p_sys = p_demux->p_sys;</div><div>-</div><div>     const char* psz_name;</div><div>+</div><div>     int i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name );</div><div> </div><div>     if ( i_type == XML_READER_ENDELEM && !strcasecmp( psz_name, "tt" ) )</div><div>@@ -97,7 +137,7 @@ static int Demux( demux_t* p_demux )</div><div>         char* psz_end = NULL;</div><div> </div><div>         while ( !psz_begin || !psz_end )</div><div>-        {</div><div>+        { </div><div>             const char* psz_attr_value = NULL;</div><div>             const char* psz_attr_name = xml_ReaderNextAttr( p_sys->p_reader, &psz_attr_value );</div><div>             if ( !psz_attr_name || !psz_attr_value )</div><div>@@ -107,20 +147,47 @@ static int Demux( demux_t* p_demux )</div><div>             else if ( !strcasecmp( psz_attr_name, "end" ) )</div><div>                 psz_end = strdup( psz_attr_value );</div><div>         }</div><div>+</div><div>         if ( psz_begin && psz_end )</div><div>         {</div><div>             const char* psz_text = NULL;</div><div>+            int i_len = 0;</div><div>+            subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];</div><div>+</div><div>+            p_subtitle = malloc ( sizeof ( subtitle_t ) );</div><div>+</div><div>             i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_text );</div><div>             if ( i_type == XML_READER_TEXT && psz_text != NULL )</div><div>-            {</div><div>-                p_block = block_Alloc( strlen( psz_text ) );</div><div>+            { <span class="" style="white-space:pre">                </span></div><div>+                i_len = strlen( psz_text ) + 1;</div><div>+                if( i_len <= 1 )</div><div>+                { </div><div>+                    p_sys->i_subtitle++;</div><div>+                }</div><div>+</div><div>+                if( ( p_block = block_Alloc( i_len ) ) == NULL )</div><div>+                { </div><div>+                    p_sys->i_subtitle++;</div><div>+                }</div><div>+</div><div>                 if ( likely( p_block ) )</div><div>-                {</div><div>+                { </div><div>+                    p_subtitle->psz_text = psz_text;</div><div>+</div><div>+                    Convert_time( &p_subtitle->i_start, psz_begin );</div><div>+                    Convert_time( &p_subtitle->i_stop, psz_end );</div><div>+</div><div>+                    p_block->i_dts =</div><div>+                    p_block->i_pts = VLC_TS_0 + p_subtitle->i_start;</div><div>+</div><div>+                    if( p_subtitle->i_stop >= 0 && p_subtitle->i_stop >= p_subtitle->i_start )</div><div>+                        p_block->i_length = p_subtitle->i_stop - p_subtitle->i_start;</div><div>+</div><div>                     memcpy( p_block->p_buffer, psz_text, p_block->i_buffer );</div><div>-                    p_block->p_buffer[p_block->i_buffer] = 0;</div><div>-                    //p_block->i_dts = p_block->i_pts = CONVERT( psz_begin );</div><div>-                    //p_block->i_length = CONVERT( psz_end );</div><div>+</div><div>                     es_out_Send( p_demux->out, p_sys->p_es, p_block );</div><div>+</div><div>+                    p_sys->i_subtitle++;</div><div>                 }</div><div>             }</div><div>         }</div><div>@@ -161,7 +228,6 @@ static int Open( vlc_object_t* p_this )</div><div>         Close( p_demux );</div><div>         return VLC_EGENERIC;</div><div>     }</div><div>-</div><div>     p_demux->pf_demux = Demux;</div><div>     p_demux->pf_control = Control;</div><div> </div><div>-- </div><div>1.9.1</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 24, 2015 at 4:13 AM, Jean-Baptiste Kempf <span dir="ltr"><<a href="mailto:jb@videolan.org" target="_blank">jb@videolan.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 24 Mar, Sushma Reddy wrote :<br>
<span class="">> +<br>
> +typedef struct<br>
> +{<br>
> +   int64_t i_start;<br>
> +   int64_t i_stop;<br>
> +   char    *psz_text;<br>
> +} subtitle_t;<br>
> +<br>
<br>
</span>Indentatio is still not 4 spaces wide.<br>
<span class=""><br>
>      switch( i_query )<br>
>      {<br>
> -        case DEMUX_GET_TIME:<br>
> -            pi64 = (int64_t*)va_arg( args, int64_t * );<br>
> -            *pi64 = 0;<br>
> -            break;<br>
> + case DEMUX_GET_TIME:<br>
> +    pi64 = (int64_t*)va_arg( args, int64_t * );<br>
> +    if( p_sys->i_length )<br>
> +    {<br>
> + *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;<br>
> + return VLC_SUCCESS;<br>
> +    }<br>
> +    return VLC_EGENERIC;<br>
<br>
</span>Indentation is completely off.<br>
You cannot use tabs!<br>
<span class=""><br>
>          if ( psz_begin && psz_end )<br>
>          {<br>
> -            const char* psz_text = NULL;<br>
> +     const char* psz_text = NULL;<br>
> +     int i_len = 0;<br>
> +      subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];<br>
> +<br>
> +     p_subtitle = malloc ( sizeof ( subtitle_t ) );<br>
> +<br>
>              i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_text );<br>
>              if ( i_type == XML_READER_TEXT && psz_text != NULL )<br>
> -            {<br>
> -                p_block = block_Alloc( strlen( psz_text ) );<br>
> +            {<br>
> + i_len = strlen( psz_text ) + 1;<br>
> + if( i_len <= 1 )<br>
> +         {<br>
> +                p_sys->i_subtitle++;<br>
> +         }<br>
> +<br>
> +         if( ( p_block = block_Alloc( i_len ) ) == NULL )<br>
> +         {<br>
> +               p_sys->i_subtitle++;<br>
> +       }<br>
> +<br>
<br>
</span>All this indentation is wrong.<br>
<div class="HOEnZb"><div class="h5"><br>
With my kindest regards,<br>
<br>
--<br>
Jean-Baptiste Kempf<br>
<a href="http://www.jbkempf.com/" target="_blank">http://www.jbkempf.com/</a> - <a href="tel:%2B33%20672%20704%20734" value="+33672704734">+33 672 704 734</a><br>
Sent from my Electronic Device<br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
</div></div></blockquote></div><br></div>