[vlc-devel] [PATCH] ttml.c : Added parsing of time and displaying subtitle
Sushma Reddy
sushma.reddy at research.iiit.ac.in
Tue Mar 24 10:35:34 CET 2015
Replaced tab with spaces
>From 65f3062906ad1816af01e9c9fa86a1351c5ebdd9 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 research.iiit.ac.in>
---
modules/demux/ttml.c | 96
++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 81 insertions(+), 15 deletions(-)
diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c
index 8b3ab5d..c4143b0 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,38 @@ vlc_module_begin ()
add_shortcut( "ttml", "subtitle" )
vlc_module_end ()
-struct demux_sys_t
+
+typedef struct
{
- xml_t* p_xml;
- xml_reader_t* p_reader;
+ int64_t i_start;
+ int64_t i_stop;
+ char *psz_text;
+} subtitle_t;
- es_out_id_t* p_es;
+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;
+ 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,12 +96,36 @@ 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 );
if ( i_type == XML_READER_ENDELEM && !strcasecmp( psz_name, "tt" ) )
@@ -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 )
@@ -107,20 +147,47 @@ static int Demux( demux_t* p_demux )
else if ( !strcasecmp( psz_attr_name, "end" ) )
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 ) )
- {
+ {
+ 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
);
- 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_sys->i_subtitle++;
}
}
}
@@ -161,7 +228,6 @@ static int Open( vlc_object_t* p_this )
Close( p_demux );
return VLC_EGENERIC;
}
-
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
--
1.9.1
On Tue, Mar 24, 2015 at 4:13 AM, Jean-Baptiste Kempf <jb at videolan.org>
wrote:
> On 24 Mar, Sushma Reddy wrote :
> > +
> > +typedef struct
> > +{
> > + int64_t i_start;
> > + int64_t i_stop;
> > + char *psz_text;
> > +} subtitle_t;
> > +
>
> Indentatio is still not 4 spaces wide.
>
> > 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;
>
> Indentation is completely off.
> You cannot use tabs!
>
> > if ( psz_begin && psz_end )
> > {
> > - const char* psz_text = NULL;
> > + 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++;
> > + }
> > +
>
> All this indentation is wrong.
>
> With my kindest regards,
>
> --
> Jean-Baptiste Kempf
> http://www.jbkempf.com/ - +33 672 704 734
> Sent from my Electronic Device
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150324/b010cc75/attachment.html>
More information about the vlc-devel
mailing list