]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/transcode.c
Clone video filter : fix potential memleak.
[vlc] / modules / stream_out / transcode.c
index af0c0c92a7b97a336cef286e0a74f83d4371c098..eceda3bd81e10c9df0a1be2ddbbd03aa867534f1 100644 (file)
@@ -739,10 +739,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
     id = malloc( sizeof( sout_stream_id_t ) );
     if( !id )
-    {
-        msg_Err( p_stream, "out of memory" );
         goto error;
-    }
     memset( id, 0, sizeof(sout_stream_id_t) );
 
     id->id = NULL;
@@ -752,10 +749,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     /* Create decoder object */
     id->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
     if( !id->p_decoder )
-    {
-        msg_Err( p_stream, "out of memory" );
         goto error;
-    }
     vlc_object_attach( id->p_decoder, p_stream );
     id->p_decoder->p_module = NULL;
     id->p_decoder->fmt_in = *p_fmt;
@@ -764,10 +758,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     /* Create encoder object */
     id->p_encoder = vlc_object_create( p_stream, VLC_OBJECT_ENCODER );
     if( !id->p_encoder )
-    {
-        msg_Err( p_stream, "out of memory" );
         goto error;
-    }
     vlc_object_attach( id->p_encoder, p_stream );
     id->p_encoder->p_module = NULL;
 
@@ -931,23 +922,26 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
     return id;
 
- error:
-    if( id->p_decoder )
+error:
+    if( id )
     {
-        vlc_object_detach( id->p_decoder );
-        vlc_object_release( id->p_decoder );
-        id->p_decoder = NULL;
-    }
+        if( id->p_decoder )
+        {
+            vlc_object_detach( id->p_decoder );
+            vlc_object_release( id->p_decoder );
+            id->p_decoder = NULL;
+        }
 
-    if( id->p_encoder )
-    {
-        vlc_object_detach( id->p_encoder );
-        es_format_Clean( &id->p_encoder->fmt_out );
-        vlc_object_release( id->p_encoder );
-        id->p_encoder = NULL;
-    }
+        if( id->p_encoder )
+        {
+            vlc_object_detach( id->p_encoder );
+            es_format_Clean( &id->p_encoder->fmt_out );
+            vlc_object_release( id->p_encoder );
+            id->p_encoder = NULL;
+        }
 
-    free( id );
+        free( id );
+    }
     return NULL;
 }
 
@@ -1152,7 +1146,7 @@ static int transcode_audio_new( sout_stream_t *p_stream,
                     id->p_decoder->fmt_out.i_codec );
     id->p_encoder->fmt_in.audio.i_format = id->p_decoder->fmt_out.i_codec;
 
-    id->p_encoder->fmt_in.audio.i_rate = fmt_last.audio.i_rate;//id->p_encoder->fmt_out.audio.i_rate;
+    id->p_encoder->fmt_in.audio.i_rate = id->p_encoder->fmt_out.audio.i_rate;
     id->p_encoder->fmt_in.audio.i_physical_channels =
         id->p_encoder->fmt_out.audio.i_physical_channels;
     id->p_encoder->fmt_in.audio.i_original_channels =
@@ -1672,11 +1666,15 @@ static void transcode_video_encoder_init( sout_stream_t *p_stream,
      f_aspect = f_aspect * i_dst_width / i_dst_height;
 
      /* Store calculated values */
-     id->p_encoder->fmt_out.video.i_width = i_dst_width;
-     id->p_encoder->fmt_out.video.i_height = i_dst_height;
+     id->p_encoder->fmt_out.video.i_width =
+     id->p_encoder->fmt_out.video.i_visible_width = i_dst_width;
+     id->p_encoder->fmt_out.video.i_height =
+     id->p_encoder->fmt_out.video.i_visible_height = i_dst_height;
 
-     id->p_encoder->fmt_in.video.i_width = i_dst_width;
-     id->p_encoder->fmt_in.video.i_height = i_dst_height;
+     id->p_encoder->fmt_in.video.i_width =
+     id->p_encoder->fmt_in.video.i_visible_width = i_dst_width;
+     id->p_encoder->fmt_in.video.i_height =
+     id->p_encoder->fmt_in.video.i_visible_height = i_dst_height;
 
      msg_Dbg( p_stream, "source %ix%i, destination %ix%i",
          i_src_width, i_src_height,
@@ -1920,7 +1918,7 @@ static int transcode_video_process( sout_stream_t *p_stream,
                                    transcode_video_filter_allocation_init,
                                    transcode_video_filter_allocation_clear,
                                    p_stream->p_sys );
-                filter_chain_Reset( id->p_uf_chain, &id->p_decoder->fmt_out,
+                filter_chain_Reset( id->p_uf_chain, &id->p_encoder->fmt_in,
                                     &id->p_encoder->fmt_in );
                 filter_chain_AppendFromString( id->p_uf_chain, p_sys->psz_vf2 );
                 p_fmt_out = filter_chain_GetFmtOut( id->p_uf_chain );
@@ -1982,7 +1980,10 @@ static int transcode_video_process( sout_stream_t *p_stream,
                 }
             }
 
-            fmt = filter_chain_GetFmtOut( id->p_f_chain )->video;
+            if( filter_chain_GetLength( id->p_f_chain ) > 0 )
+                fmt = filter_chain_GetFmtOut( id->p_f_chain )->video;
+            else
+                fmt = id->p_decoder->fmt_out.video;
 
             /* FIXME (shouldn't have to be done here) */
             fmt.i_sar_num = fmt.i_aspect * fmt.i_height / fmt.i_width;
@@ -2082,7 +2083,7 @@ static int EncoderThread( sout_stream_sys_t *p_sys )
     sout_stream_id_t *id = p_sys->id_video;
     picture_t *p_pic;
 
-    while( !p_sys->b_die && !p_sys->b_error )
+    while( vlc_object_alive (p_sys) && !p_sys->b_error )
     {
         block_t *p_block;
 
@@ -2090,9 +2091,9 @@ static int EncoderThread( sout_stream_sys_t *p_sys )
         while( p_sys->i_last_pic == p_sys->i_first_pic )
         {
             vlc_cond_wait( &p_sys->cond, &p_sys->lock_out );
-            if( p_sys->b_die || p_sys->b_error ) break;
+            if( !vlc_object_alive (p_sys) || p_sys->b_error ) break;
         }
-        if( p_sys->b_die || p_sys->b_error )
+        if( !vlc_object_alive (p_sys) || p_sys->b_error )
         {
             vlc_mutex_unlock( &p_sys->lock_out );
             break;