#include <vlc_memory.h>
#include <ctype.h>
+#include <math.h>
#include <vlc_demux.h>
#include <vlc_charset.h>
/* Get the FPS */
f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" ); /* FIXME */
- if( f_fps >= 1.0 )
- p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
+ if( f_fps >= 1.f )
+ p_sys->i_microsecperframe = llroundf( 1000000.f / f_fps );
- msg_Dbg( p_demux, "Movie fps: %f", f_fps );
+ msg_Dbg( p_demux, "Movie fps: %f", (double) f_fps );
/* Check for override of the fps */
f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
- if( f_fps >= 1.0 )
+ if( f_fps >= 1.f )
{
- p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
- msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
+ p_sys->i_microsecperframe = llroundf( 1000000.f / f_fps );
+ msg_Dbg( p_demux, "Override subtitle fps %f", (double) f_fps );
}
/* Get or probe the type */
for( i = 0; i < p_sys->i_subtitles; i++ )
free( p_sys->subtitle[i].psz_text );
free( p_sys->subtitle );
+ free( p_sys->psz_header );
free( p_sys );
}
if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
{
- float f_fps;
if( i_start != 1 || i_stop != 1 )
break;
/* We found a possible setting of the framerate "{1}{1}23.976" */
/* Check if it's usable, and if the sub-fps is not set */
- f_fps = us_strtod( psz_text, NULL );
- if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
- p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
+ float f_fps = us_strtof( psz_text, NULL );
+ if( f_fps > 0.f && var_GetFloat( p_demux, "sub-fps" ) <= 0.f )
+ p_sys->i_microsecperframe = llroundf(1000000.f / f_fps);
}
free( psz_text );
}
{
demux_sys_t *p_sys = p_demux->p_sys;
text_t *txt = &p_sys->txt;
+ size_t header_len = 0;
for( ;; )
{
free( psz_text );
/* All the other stuff we add to the header field */
- char *psz_header;
- if( asprintf( &psz_header, "%s%s\n",
- p_sys->psz_header ? p_sys->psz_header : "", s ) == -1 )
+ size_t s_len = strlen( s );
+ p_sys->psz_header = realloc_or_free( p_sys->psz_header, header_len + s_len + 2 );
+ if( !p_sys->psz_header )
return VLC_ENOMEM;
- p_sys->psz_header = psz_header;
+ snprintf( p_sys->psz_header + header_len, s_len + 2, "%s\n", s );
+ header_len += s_len + 1;
}
}
for( ;; )
{
- float f1, f2;
char p_dummy;
char *psz_temp;
if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
{
- float f_fps;
- f_fps = us_strtod( psz_temp, NULL );
- if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
+ float f_fps = us_strtof( psz_temp, NULL );
+
+ if( f_fps > 0.f && var_GetFloat( p_demux, "sub-fps" ) <= 0.f )
var_SetFloat( p_demux, "sub-fps", f_fps );
- p_sys->mpsub.f_factor = 1.0;
+ p_sys->mpsub.f_factor = 1.f;
free( psz_temp );
break;
}
free( psz_temp );
}
+
/* Data Lines */
- f1 = us_strtod( s, &psz_temp );
+ float f1 = us_strtof( s, &psz_temp );
if( *psz_temp )
{
- f2 = us_strtod( psz_temp, NULL );
+ float f2 = us_strtof( psz_temp, NULL );
p_sys->mpsub.f_total += f1 * p_sys->mpsub.f_factor;
- p_subtitle->i_start = (int64_t)(10000.0 * p_sys->mpsub.f_total);
+ p_subtitle->i_start = llroundf(10000.f * p_sys->mpsub.f_total);
p_sys->mpsub.f_total += f2 * p_sys->mpsub.f_factor;
- p_subtitle->i_stop = (int64_t)(10000.0 * p_sys->mpsub.f_total);
+ p_subtitle->i_stop = llroundf(10000.f * p_sys->mpsub.f_total);
break;
}
}