<div dir="ltr">Patch with indentations and debug messages are removed<div><br></div><div><div>From 9c110f8a1336dd1ab2795215204ab34c85bab2ba 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 | 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..9fdba23 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,41 @@ 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>{</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,11 +99,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 +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>@@ -108,19 +150,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 +220,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:25 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">Hello,<br>
<br>
<br>
On 23 Mar, Sushma Reddy wrote :<br>
<span class="">> Subject: [PATCH] Added parsing for subtitle with time and displaying<br>
> subtiles<br>
<br>
</span>I'm not sure it's really for this mailing list, but thanks.<br>
<span class=""><br>
> + case DEMUX_GET_TIME:<br>
> + pi64 = (int64_t*)va_arg( args, int64_t * );<br>
> + if(p_sys->i_length)<br>
> + *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;<br>
> + return VLC_SUCCESS;<br>
> + return VLC_EGENERIC;<br>
<br>
</span>Be careful about your indentation.<br>
<span class=""><br>
> - {<br>
> + {<br>
> const char* psz_text = NULL;<br>
> + int i_len = 0;<br>
> + subtitle_t *p_subtitle = &p_sys->subtitle[p_sys->i_subtitle];<br>
> + p_subtitle = malloc (sizeof(subtitle_t));<br>
<br>
</span>Same here.<br>
<span class=""><br>
> -<br>
> + msg_Dbg(p_demux,"debuging demux enter1");<br>
> p_demux->pf_demux = Demux;<br>
> p_demux->pf_control = Control;<br>
><br>
> @@ -170,6 +227,7 @@ static int Open( vlc_object_t* p_this )<br>
> p_sys->p_es = es_out_Add( p_demux->out, &fmt );<br>
> es_format_Clean( &fmt );<br>
><br>
> +msg_Dbg(p_demux,"debuging open enter2");<br>
> /* Initialize things here */<br>
<br>
</span>Debug messages should not be on a commit.<br>
<br>
With my kindest regards,<br>
<span class="HOEnZb"><font color="#888888"><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>
</font></span></blockquote></div><br></div>