]> git.sesse.net Git - vlc/blobdiff - modules/demux/subtitle_asa.c
mp4: fix a memory leak and an invalid release in MacOS code.
[vlc] / modules / demux / subtitle_asa.c
index cce80daf55749a52503ec0693571189960e64d41..63bf9f717004bb4ad37619f04e3ef5097e68643e 100644 (file)
  * Preamble
  *****************************************************************************/
 #include "config.h"
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_input.h>
-
-
-#include <errno.h>
-#ifdef HAVE_SYS_TYPES_H
-#   include <sys/types.h>
-#endif
-#include <ctype.h>
+#include <vlc_memory.h>
 
 #include <vlc_demux.h>
-#include <vlc_charset.h>
 
 #include "asademux.h"
 
@@ -59,24 +53,24 @@ static void Close( vlc_object_t *p_this );
 #define SUB_TYPE_LONGTEXT \
     N_("Force the subtiles format. Use \"auto\", the set of supported values varies.")
 
-vlc_module_begin();
-    set_shortname( _("Subtitles (asa demuxer)"));
-    set_description( _("Text subtitles parser") );
-    set_capability( "demux", 50 );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_DEMUX );
+vlc_module_begin ()
+    set_shortname( N_("Subtitles (asa demuxer)"))
+    set_description( N_("Text subtitles parser") )
+    set_capability( "demux", 50 )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_DEMUX )
     add_float( "sub-fps", 0.0, NULL,
                N_("Frames per second"),
-               SUB_FPS_LONGTEXT, true );
+               SUB_FPS_LONGTEXT, true )
     add_integer( "sub-delay", 0, NULL,
                N_("Subtitles delay"),
-               SUB_DELAY_LONGTEXT, true );
+               SUB_DELAY_LONGTEXT, true )
     add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
-                SUB_TYPE_LONGTEXT, true );
-    set_callbacks( Open, Close );
+                SUB_TYPE_LONGTEXT, true )
+    set_callbacks( Open, Close )
 
-    add_shortcut( "asademux" );
-vlc_module_end();
+    add_shortcut( "asademux" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Prototypes:
@@ -123,7 +117,6 @@ static int Open ( vlc_object_t *p_this )
     demux_t        *p_demux = (demux_t*)p_this;
     demux_sys_t    *p_sys;
     es_format_t    fmt;
-    input_thread_t *p_input;
     float          f_fps;
     char           *psz_type;
     int64_t        i_ssize;
@@ -132,13 +125,14 @@ static int Open ( vlc_object_t *p_this )
 
     if( strcmp( p_demux->psz_demux, "asademux" ) )
     {
-        msg_Dbg( p_demux, "asademux discarded" );
         return VLC_EGENERIC;
     }
 
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;
     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+    if( !p_sys  )
+        return VLC_ENOMEM;
     p_sys->psz_header         = NULL;
     p_sys->i_subtitle         = 0;
     p_sys->i_subtitles        = 0;
@@ -147,16 +141,11 @@ static int Open ( vlc_object_t *p_this )
     p_sys->i_microsecperframe = 40000;
 
     /* Get the FPS */
-    p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
-    if( p_input )
-    {
-        f_fps = var_GetFloat( p_input, "sub-original-fps" );
-        if( f_fps >= 1.0 )
-            p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
+    f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" );
+    if( f_fps >= 1.0 )
+        p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
 
-        msg_Dbg( p_demux, "Movie fps: %f", f_fps );
-        vlc_object_release( p_input );
-    }
+    msg_Dbg( p_demux, "Movie fps: %f", f_fps );
 
     /* Check for override of the fps */
     f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
@@ -209,7 +198,7 @@ static int Open ( vlc_object_t *p_this )
     }
     if( !p_detect->fmt )
     {
-        msg_Err( p_demux, "detected %s subtitle format, no asa support" );
+        msg_Err( p_demux, "detected %s subtitle format, no asa support", p_detect->name );
         free( p_sys );
         return VLC_EGENERIC;
     }
@@ -219,7 +208,6 @@ static int Open ( vlc_object_t *p_this )
     p_data = malloc( i_ssize );
     if( !p_data )
     {
-        msg_Err( p_demux, "out of memory");
         free( p_sys );
         return VLC_ENOMEM;
     }
@@ -245,17 +233,17 @@ static int Open ( vlc_object_t *p_this )
         p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
         /* +1 to avoid 0 */
         if( p_sys->i_length <= 0 )
-            p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
+            p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start + VLC_TS_0;
     }
 
     /* *** add subtitle ES *** */
     if( p_detect->fmt->target == ASAI_TARGET_SSA )
     {
-        es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
+        es_format_Init( &fmt, SPU_ES, VLC_CODEC_SSA );
     }
     else
     {
-        es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
+        es_format_Init( &fmt, SPU_ES, VLC_CODEC_SUBT );
     }
     p_sys->es = es_out_Add( p_demux->out, &fmt );
 
@@ -274,13 +262,14 @@ static int ProcessLine( demux_t *p_demux, void *p_arg,
     subtitle_t *p_subtitle;
     char *psz_text;
 
+    VLC_UNUSED(p_arg);
+
     if( p_sys->i_subtitles >= p_sys->i_subs_alloc )
     {
         p_sys->i_subs_alloc += 500;
-        if( !( p_sys->subtitle = realloc( p_sys->subtitle, sizeof(subtitle_t)
-                                          * p_sys->i_subs_alloc ) ) )
+        if( !( p_sys->subtitle = realloc_or_free( p_sys->subtitle,
+                                sizeof(subtitle_t) * p_sys->i_subs_alloc ) ) )
         {
-            msg_Err( p_demux, "out of memory");
             return VLC_ENOMEM;
         }
     }
@@ -444,9 +433,9 @@ static int Demux( demux_t *p_demux )
             continue;
         }
 
-        p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
-        p_block->i_dts = p_block->i_pts;
-        if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
+        p_block->i_pts = VLC_TS_0 + p_sys->subtitle[p_sys->i_subtitle].i_start;
+        p_block->i_dts = VLC_TS_0 + p_block->i_pts;
+        if( p_sys->subtitle[p_sys->i_subtitle].i_stop >= 0 )
         {
             p_block->i_length =
                 p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
@@ -454,7 +443,7 @@ static int Demux( demux_t *p_demux )
 
         memcpy( p_block->p_buffer,
                 p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
-        if( p_block->i_pts > 0 )
+        if( p_block->i_pts > VLC_TS_INVALID )
         {
             es_out_Send( p_demux->out, p_sys->es, p_block );
         }