]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/mosaic_bridge.c
avcodec: free extradata after closing the context
[vlc] / modules / stream_out / mosaic_bridge.c
index d39990f7011533e27e23ada8e0513f0bfa5d8c0b..ae20ef46cb1b61314082a234da8905293e0fbd08 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * mosaic_bridge.c:
  *****************************************************************************
- * Copyright (C) 2004-2007 the VideoLAN team
+ * Copyright (C) 2004-2007 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Antoine Cellerier <dionoea@videolan.org>
  *          Christophe Massiot <massiot@via.ecp.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -39,6 +39,7 @@
 
 #include <vlc_image.h>
 #include <vlc_filter.h>
+#include <vlc_modules.h>
 
 #include "../video_filter/mosaic.h"
 
@@ -48,7 +49,6 @@
 struct sout_stream_sys_t
 {
     bridged_es_t *p_es;
-    vlc_mutex_t *p_lock;
 
     decoder_t       *p_decoder;
     image_handler_t *p_image; /* filter for resizing */
@@ -73,9 +73,9 @@ struct decoder_owner_sys_t
  *****************************************************************************/
 static int  Open    ( vlc_object_t * );
 static void Close   ( vlc_object_t * );
-static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
-static int               Del ( sout_stream_t *, sout_stream_id_t * );
-static int               Send( sout_stream_t *, sout_stream_id_t *, block_t * );
+static sout_stream_id_sys_t *Add ( sout_stream_t *, es_format_t * );
+static int               Del ( sout_stream_t *, sout_stream_id_sys_t * );
+static int               Send( sout_stream_t *, sout_stream_id_sys_t *, block_t * );
 
 inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
 inline static void video_del_buffer_filter( filter_t *, picture_t * );
@@ -145,24 +145,24 @@ vlc_module_begin ()
     set_capability( "sout stream", 0 )
     add_shortcut( "mosaic-bridge" )
 
-    add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
+    add_string( CFG_PREFIX "id", "Id", ID_TEXT, ID_LONGTEXT,
                 false )
-    add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
+    add_integer( CFG_PREFIX "width", 0, WIDTH_TEXT,
                  WIDTH_LONGTEXT, true )
-    add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
+    add_integer( CFG_PREFIX "height", 0, HEIGHT_TEXT,
                  HEIGHT_LONGTEXT, true )
-    add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
+    add_string( CFG_PREFIX "sar", "1:1", RATIO_TEXT,
                 RATIO_LONGTEXT, false )
-    add_string( CFG_PREFIX "chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
+    add_string( CFG_PREFIX "chroma", NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
                 false )
 
     add_module_list( CFG_PREFIX "vfilter", "video filter2",
-                     NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, false )
+                     NULL, VFILTER_TEXT, VFILTER_LONGTEXT, false )
 
-    add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255, NULL,
+    add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255,
                             ALPHA_TEXT, ALPHA_LONGTEXT, false )
-    add_integer( CFG_PREFIX "x", -1, NULL, X_TEXT, X_LONGTEXT, false )
-    add_integer( CFG_PREFIX "y", -1, NULL, Y_TEXT, Y_LONGTEXT, false )
+    add_integer( CFG_PREFIX "x", -1, X_TEXT, X_LONGTEXT, false )
+    add_integer( CFG_PREFIX "y", -1, Y_TEXT, Y_LONGTEXT, false )
 
     set_callbacks( Open, Close )
 vlc_module_end ()
@@ -178,7 +178,6 @@ static int Open( vlc_object_t *p_this )
 {
     sout_stream_t        *p_stream = (sout_stream_t *)p_this;
     sout_stream_sys_t    *p_sys;
-    vlc_object_t         *p_libvlc = VLC_OBJECT( p_this->p_libvlc );
     vlc_value_t           val;
 
     config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
@@ -191,10 +190,6 @@ static int Open( vlc_object_t *p_this )
     p_stream->p_sys = p_sys;
     p_sys->b_inited = false;
 
-    var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
-    var_Get( p_libvlc, "mosaic-lock", &val );
-    p_sys->p_lock = val.p_address;
-
     p_sys->psz_id = var_CreateGetString( p_stream, CFG_PREFIX "id" );
 
     p_sys->i_height =
@@ -254,8 +249,7 @@ static int Open( vlc_object_t *p_this )
     p_stream->pf_add    = Add;
     p_stream->pf_del    = Del;
     p_stream->pf_send   = Send;
-
-    p_stream->p_sout->i_out_pace_nocontrol++;
+    p_stream->pace_nocontrol = true;
 
     return VLC_SUCCESS;
 }
@@ -275,22 +269,12 @@ static void Close( vlc_object_t * p_this )
     var_DelCallback( p_stream, CFG_PREFIX "x", xCallback, p_stream );
     var_DelCallback( p_stream, CFG_PREFIX "y", yCallback, p_stream );
 
-    p_stream->p_sout->i_out_pace_nocontrol--;
-
     free( p_sys->psz_id );
 
     free( p_sys );
 }
 
-static int video_filter_buffer_allocation_init( filter_t *p_filter, void *p_data )
-{
-    p_filter->pf_vout_buffer_new = video_new_buffer_filter;
-    p_filter->pf_vout_buffer_del = video_del_buffer_filter;
-    p_filter->p_owner = p_data;
-    return VLC_SUCCESS;
-}
-
-static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_sys_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     bridge_t *p_bridge;
@@ -302,10 +286,9 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         return NULL;
 
     /* Create decoder object */
-    p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
+    p_sys->p_decoder = vlc_object_create( p_stream, sizeof( decoder_t ) );
     if( !p_sys->p_decoder )
         return NULL;
-    vlc_object_attach( p_sys->p_decoder, p_stream );
     p_sys->p_decoder->p_module = NULL;
     p_sys->p_decoder->fmt_in = *p_fmt;
     p_sys->p_decoder->b_pace_control = false;
@@ -320,7 +303,6 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
     if( !p_sys->p_decoder->p_owner )
     {
-        vlc_object_detach( p_sys->p_decoder );
         vlc_object_release( p_sys->p_decoder );
         return NULL;
     }
@@ -343,13 +325,12 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
             msg_Err( p_stream, "cannot find decoder" );
         }
         free( p_sys->p_decoder->p_owner );
-        vlc_object_detach( p_sys->p_decoder );
         vlc_object_release( p_sys->p_decoder );
         return NULL;
     }
 
     p_sys->b_inited = true;
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_global_lock( VLC_MOSAIC_MUTEX );
 
     p_bridge = GetBridge( p_stream );
     if ( p_bridge == NULL )
@@ -393,7 +374,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     p_es->pp_last = &p_es->p_picture;
     p_es->b_empty = false;
 
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_global_unlock( VLC_MOSAIC_MUTEX );
 
     if ( p_sys->i_height || p_sys->i_width )
     {
@@ -411,9 +392,15 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     msg_Dbg( p_stream, "psz_chain: %s", psz_chain );
     if( psz_chain )
     {
-        p_sys->p_vf2 = filter_chain_New( p_stream, "video filter2", false,
-                                         video_filter_buffer_allocation_init,
-                                         NULL, p_sys->p_decoder->p_owner );
+        filter_owner_t owner = {
+            .sys = p_sys->p_decoder->p_owner,
+            .video = {
+                .buffer_new = video_new_buffer_filter,
+                .buffer_del = video_del_buffer_filter,
+            },
+        };
+
+        p_sys->p_vf2 = filter_chain_NewVideo( p_stream, false, &owner );
         es_format_t fmt;
         es_format_Copy( &fmt, &p_sys->p_decoder->fmt_out );
         if( p_sys->i_chroma )
@@ -427,10 +414,10 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         p_sys->p_vf2 = NULL;
     }
 
-    return (sout_stream_id_t *)p_sys;
+    return (sout_stream_id_sys_t *)p_sys;
 }
 
-static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
+static int Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     VLC_UNUSED(id);
     sout_stream_sys_t *p_sys = p_stream->p_sys;
@@ -451,7 +438,6 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
         if( p_sys->p_decoder->p_description )
             vlc_meta_Delete( p_sys->p_decoder->p_description );
 
-        vlc_object_detach( p_sys->p_decoder );
         vlc_object_release( p_sys->p_decoder );
 
         free( p_owner );
@@ -461,7 +447,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
     if( p_sys->p_vf2 )
         filter_chain_Delete( p_sys->p_vf2 );
 
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_global_lock( VLC_MOSAIC_MUTEX );
 
     p_bridge = GetBridge( p_stream );
     p_es = p_sys->p_es;
@@ -493,7 +479,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
         var_Destroy( p_libvlc, "mosaic-struct" );
     }
 
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_global_unlock( VLC_MOSAIC_MUTEX );
 
     if ( p_sys->p_image )
     {
@@ -513,16 +499,16 @@ static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     bridged_es_t *p_es = p_sys->p_es;
 
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_global_lock( VLC_MOSAIC_MUTEX );
 
     *p_es->pp_last = p_picture;
     p_picture->p_next = NULL;
     p_es->pp_last = &p_picture->p_next;
 
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_global_unlock( VLC_MOSAIC_MUTEX );
 }
 
-static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
+static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
                  block_t *p_buffer )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
@@ -626,7 +612,7 @@ inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
 {
     return video_new_buffer( VLC_OBJECT( p_filter ),
-                             (decoder_owner_sys_t *)p_filter->p_owner,
+                             (decoder_owner_sys_t *)p_filter->owner.sys,
                              &p_filter->fmt_out );
 }