<div dir="ltr"><div>From 92f6de020b2f299121bbffcb4bf738b9cbd7db7f 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@reserch.iiit.ac.in">sushma.reddy@reserch.iiit.ac.in</a>></div><div>---</div><div> modules/demux/ttml.c | 92 ++++++++++++++++++++++++++++++++++++++++++----------</div><div> 1 file changed, 75 insertions(+), 17 deletions(-)</div><div><br></div><div>diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c</div><div>index 8b3ab5d..22b64c2 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,39 @@ vlc_module_begin ()</div><div>     add_shortcut( "ttml", "subtitle" )</div><div> vlc_module_end ()</div><div> </div><div>+</div><div>+typedef struct</div><div>+{</div><div>+   int64_t i_start;</div><div>+   int64_t i_stop;</div><div>+</div><div>+   char    *psz_text;</div><div>+} subtitle_t;</div><div>+</div><div> struct demux_sys_t</div><div> {</div><div>     xml_t* p_xml;</div><div>     xml_reader_t* p_reader;</div><div>-</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>+<span class="" style="white-space:pre">  </span>case DEMUX_GET_TIME:</div><div>+<span class="" style="white-space:pre">              </span>pi64 = (int64_t*)va_arg( args, int64_t * );</div><div>+<span class="" style="white-space:pre">               </span>if(p_sys->i_length)</div><div>+<span class="" style="white-space:pre">                    </span>*pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;</div><div>+<span class="" style="white-space:pre">                 </span>return VLC_SUCCESS;</div><div>+<span class="" style="white-space:pre">               </span>return VLC_EGENERIC;</div><div>         case DEMUX_GET_LENGTH:</div><div>         case DEMUX_SET_TIME:</div><div>         case DEMUX_GET_POSITION:</div><div>@@ -80,11 +97,34 @@ 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>     int i_type = xml_ReaderNextNode( p_sys->p_reader, &psz_name );</div><div> </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>@@ -108,19 +148,36 @@ static int Demux( demux_t* p_demux )</div><div>                 psz_end = strdup( psz_attr_value );</div><div>         }</div><div>         if ( psz_begin && psz_end )</div><div>-        {</div><div>+        { </div><div>             const char* psz_text = NULL;</div><div>+<span class="" style="white-space:pre">     </span>    int i_len = 0;</div><div>+ <span class="" style="white-space:pre">     </span>    subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];</div><div>+<span class="" style="white-space:pre">     </span>    p_subtitle = malloc (sizeof(subtitle_t));</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>+<span class="" style="white-space:pre">          </span>i_len = strlen(psz_text)+1;</div><div>+<span class="" style="white-space:pre">               </span>if( i_len <= 1<span class="" style="white-space:pre"> </span> )</div><div>+        <span class="" style="white-space:pre">    </span>{ </div><div>+            <span class="" style="white-space:pre">     </span>p_sys->i_subtitle++;</div><div>+        <span class="" style="white-space:pre">       </span>}</div><div>+</div><div>+        <span class="" style="white-space:pre">     </span>if( ( p_block = block_Alloc( i_len ) ) == NULL )</div><div>+        <span class="" style="white-space:pre">      </span>{ </div><div>+           <span class="" style="white-space:pre">       </span> p_sys->i_subtitle++;</div><div>+       <span class="" style="white-space:pre">                </span>}</div><div>                 if ( likely( p_block ) )</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>-                    es_out_Send( p_demux->out, p_sys->p_es, p_block );</div><div>+                { </div><div>+<span class="" style="white-space:pre">             </span>    p_subtitle->psz_text = psz_text;</div><div>+<span class="" style="white-space:pre">         </span>    Convert_time( &p_subtitle->i_start, psz_begin );</div><div>+<span class="" style="white-space:pre">             </span>    Convert_time( &p_subtitle->i_stop, psz_end );</div><div>+<span class="" style="white-space:pre">                </span>    p_block->i_dts =</div><div>+       <span class="" style="white-space:pre">               </span>    p_block->i_pts = VLC_TS_0 + p_subtitle->i_start;</div><div>+        <span class="" style="white-space:pre">  </span>    if( p_subtitle->i_stop >= 0 && p_subtitle->i_stop >= p_subtitle->i_start )</div><div>+            <span class="" style="white-space:pre">         </span>p_block->i_length = p_subtitle->i_stop - p_subtitle->i_start;</div><div>+<span class="" style="white-space:pre">            </span>    memcpy( p_block->p_buffer, psz_text, p_block->i_buffer );</div><div>+<span class="" style="white-space:pre">             </span>    es_out_Send( p_demux->out, p_sys->p_es, p_block );</div><div>+<span class="" style="white-space:pre">    </span>    <span class="" style="white-space:pre">    </span>    p_sys->i_subtitle++;</div><div>                 }</div><div>             }</div><div>         }</div><div>@@ -161,7 +218,7 @@ static int Open( vlc_object_t* p_this )</div><div>         Close( p_demux );</div><div>         return VLC_EGENERIC;</div><div>     }</div><div>-</div><div>+    msg_Dbg(p_demux,"debuging demux enter1");</div><div>     p_demux->pf_demux = Demux;</div><div>     p_demux->pf_control = Control;</div><div> </div><div>@@ -170,6 +227,7 @@ static int Open( vlc_object_t* p_this )</div><div>     p_sys->p_es = es_out_Add( p_demux->out, &fmt );</div><div>     es_format_Clean( &fmt );</div><div> </div><div>+msg_Dbg(p_demux,"debuging open enter2");</div><div>     /* Initialize things here */</div><div> </div><div>     return VLC_SUCCESS;</div><div>-- </div><div>1.9.1</div><div><br></div></div>