]> git.sesse.net Git - vlc/blobdiff - src/input/es_out.c
Check asprintf return value and fix a potential memleak.
[vlc] / src / input / es_out.c
index b5ac3dc5fda69570aa3737214f1a84ffa2398d92..c7dac8e5177460848284f14e5f9d84c73b5953ca 100644 (file)
@@ -29,7 +29,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include <stdio.h>
 
@@ -40,7 +40,6 @@
 
 #include "input_internal.h"
 
-#include "vlc_playlist.h"
 #include <vlc_iso_lang.h>
 /* FIXME we should find a better way than including that */
 #include "../text/iso-639_def.h"
@@ -178,12 +177,13 @@ static inline int EsOutGetClosedCaptionsChannel( vlc_fourcc_t fcc )
  *****************************************************************************/
 es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
 {
-    es_out_t     *out = malloc( sizeof( es_out_t ) );
-    es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
     vlc_value_t  val;
     int i;
 
+    es_out_t     *out = malloc( sizeof( es_out_t ) );
     if( !out ) return NULL;
+
+    es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
     if( !p_sys )
     {
         free( out );
@@ -195,7 +195,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
     out->pf_del     = EsOutDel;
     out->pf_control = EsOutControl;
     out->p_sys      = p_sys;
-    out->b_sout     = (p_input->p->p_sout != NULL ? true : false);
+    out->b_sout     = p_input->p->p_sout != NULL;
 
     p_sys->p_input = p_input;
 
@@ -423,6 +423,7 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt,
 {
     es_out_sys_t      *p_sys = out->p_sys;
     input_thread_t    *p_input = p_sys->p_input;
+    const  bool b_teletext = fmt->i_cat == SPU_ES && fmt->i_codec == VLC_FOURCC( 't', 'e', 'l', 'x' );
     vlc_value_t       val, text;
 
     const char *psz_var;
@@ -438,8 +439,12 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt,
 
     if( b_delete )
     {
+        if( b_teletext )
+            var_SetInteger( p_sys->p_input, "teletext-es", -1 );
+
         val.i_int = i_id;
         var_Change( p_input, psz_var, VLC_VAR_DELCHOICE, &val, NULL );
+
         var_SetBool( p_sys->p_input, "intf-change", true );
         return;
     }
@@ -472,17 +477,13 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt,
     {
         if( psz_language && *psz_language )
         {
-            char *temp;
-            text.psz_string = malloc( strlen( _("Track %i") )+
-                                      strlen( psz_language ) + 30 );
-            asprintf( &temp,  _("Track %i"), val.i_int );
-            sprintf( text.psz_string, "%s - [%s]", temp, psz_language );
-            free( temp );
+            if( asprintf( &text.psz_string, "%s %i - [%s]", _( "Track" ), val.i_int, psz_language ) == -1 )
+                text.psz_string = NULL;
         }
         else
         {
-            text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
-            sprintf( text.psz_string, _("Track %i"), val.i_int );
+            if( asprintf( &text.psz_string, "%s %i", _( "Track" ), val.i_int ) == -1 )
+                text.psz_string = NULL;
         }
     }
 
@@ -491,6 +492,9 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt,
 
     free( text.psz_string );
 
+    if( b_teletext )
+        var_SetInteger( p_sys->p_input, "teletext-es", i_id );
+
     var_SetBool( p_sys->p_input, "intf-change", true );
 }
 
@@ -551,6 +555,7 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
     var_Change( p_input, "audio-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
     var_Change( p_input, "video-es", VLC_VAR_CLEARCHOICES, NULL, NULL );
     var_Change( p_input, "spu-es",   VLC_VAR_CLEARCHOICES, NULL, NULL );
+    var_SetInteger( p_input, "teletext-es", -1 );
     for( i = 0; i < p_sys->i_es; i++ )
     {
         if( p_sys->es[i]->p_pgrm == p_sys->p_pgrm )
@@ -1057,8 +1062,7 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
     {
         if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
         {
-            if( !var_GetBool( p_input, "video" ) ||
-                ( p_input->p->p_sout && !var_GetBool( p_input, "sout-video" ) ) )
+            if( !var_GetBool( p_input, out->b_sout ? "sout-video" : "video" ) )
             {
                 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
                          es->i_id );
@@ -1068,8 +1072,7 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
         else if( es->fmt.i_cat == AUDIO_ES )
         {
             var_Get( p_input, "audio", &val );
-            if( !var_GetBool( p_input, "audio" ) ||
-                ( p_input->p->p_sout && !var_GetBool( p_input, "sout-audio" ) ) )
+            if( !var_GetBool( p_input, out->b_sout ? "sout-audio" : "audio" ) )
             {
                 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
                          es->i_id );
@@ -1079,8 +1082,7 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
         if( es->fmt.i_cat == SPU_ES )
         {
             var_Get( p_input, "spu", &val );
-            if( !var_GetBool( p_input, "spu" ) ||
-                ( p_input->p->p_sout && !var_GetBool( p_input, "sout-spu" ) ) )
+            if( !var_GetBool( p_input, out->b_sout ? "sout-spu" : "spu" ) )
             {
                 msg_Dbg( p_input, "spu is disabled, not selecting ES 0x%x",
                          es->i_id );
@@ -1692,17 +1694,9 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
                 }
             }
             {
-                /* FIXME: we don't want to depend on the playlist */
-                playlist_t * p_playlist = vlc_object_find( p_sys->p_input,
-                    VLC_OBJECT_PLAYLIST, FIND_PARENT );
-                if( p_playlist )
-                {
-                    PL_LOCK;
-                    p_playlist->gc_date = mdate();
-                    vlc_object_signal_unlocked( p_playlist );
-                    PL_UNLOCK;
-                    vlc_object_release( p_playlist );
-                }
+                vlc_event_t event;
+                event.type = vlc_InputSelectedStreamChanged;
+                vlc_event_send( &p_sys->p_input->p->event_manager, &event );
             }
             return VLC_SUCCESS;