<div dir="ltr">Please check now <div><br></div><div><div>From 2a860f6a706e480b11ea564ed5290323eb7b07d2 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 | 104 ++++++++++++++++++++++++++++++++++++++++++---------</div><div> 1 file changed, 86 insertions(+), 18 deletions(-)</div><div><br></div><div>diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c</div><div>index 8b3ab5d..75d164f 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,40 @@ 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>+   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>    {</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>    }</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,12 +98,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 +139,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 +149,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>+<span class="" style="white-space:pre">     </span>     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>+</div><div>+<span class="" style="white-space:pre">    </span>     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>+<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 )</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>+</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>+</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>+</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>+</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>+</div><div>+<span class="" style="white-space:pre">            </span>    memcpy( p_block->p_buffer, psz_text, p_block->i_buffer );</div><div>+</div><div>+<span class="" style="white-space:pre">             </span>    es_out_Send( p_demux->out, p_sys->p_es, p_block );</div><div>+</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>@@ -132,7 +201,7 @@ static int Demux( demux_t* p_demux )</div><div> </div><div> static int Open( vlc_object_t* p_this )</div><div> {</div><div>-    demux_t     *p_demux = (demux_t*)p_this;</div><div>+    demux_t     *p_demux = ( demux_t* )p_this;</div><div>     demux_sys_t *p_sys;</div><div> </div><div>     /* Allocate the memory needed to store the decoder's structure */</div><div>@@ -161,7 +230,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><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 23, 2015 at 11:40 PM, 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"><span class="">On 23 Mar, Sushma Reddy wrote :<br>
</span><span class="">> Patch with indentations and debug messages are removed<br>
<br>
</span>Indentations are still not good.<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>