]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/mosaic_bridge.c
Use filter chain in mosaic bridge too.
[vlc] / modules / stream_out / mosaic_bridge.c
index db1e8dc3e510319a954d204a3b127d72809d5b79..147d4d0881ae43cb61edd86c798e691aa15c00d1 100644 (file)
@@ -31,7 +31,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_block.h>
 #include <vlc_codec.h>
@@ -41,6 +42,8 @@
 
 #include "../video_filter/mosaic.h"
 
+#include <assert.h>
+
 /*****************************************************************************
  * Local structures
  *****************************************************************************/
@@ -54,12 +57,11 @@ struct sout_stream_sys_t
     int i_height, i_width;
     unsigned int i_sar_num, i_sar_den;
     char *psz_id;
-    vlc_bool_t b_inited;
+    bool b_inited;
 
     int i_chroma; /* force image format chroma */
 
-    filter_t **pp_vfilters;
-    int i_vfilters;
+    filter_chain_t *p_vf2;
 };
 
 #define PICTURE_RING_SIZE 4
@@ -74,21 +76,22 @@ struct decoder_owner_sys_t
 typedef void (* pf_release_t)( picture_t * );
 static void ReleasePicture( picture_t *p_pic )
 {
-    p_pic->i_refcount--;
+    assert( p_pic );
+
+    if( --p_pic->i_refcount > 0 )
+        return;
 
-    if ( p_pic->i_refcount <= 0 )
+    assert( p_pic->p_sys );
+    if( p_pic->p_sys )
     {
-        if ( p_pic->p_sys != NULL )
-        {
-            pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
-            p_pic->p_sys = NULL;
-            pf_release( p_pic );
-        }
-        else
-        {
-            if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
-            if( p_pic ) free( p_pic );
-        }
+        pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
+        p_pic->p_sys = NULL;
+        pf_release( p_pic );
+    }
+    else
+    {
+        free( p_pic->p_data_orig );
+        free( p_pic );
     }
 }
 
@@ -112,8 +115,17 @@ static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
 
 static void video_link_picture_decoder( decoder_t *, picture_t * );
 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
-static int MosaicBridgeCallback( vlc_object_t *, char const *,
-                                 vlc_value_t, vlc_value_t, void * );
+
+static int HeightCallback( vlc_object_t *, char const *,
+                           vlc_value_t, vlc_value_t, void * );
+static int WidthCallback( vlc_object_t *, char const *,
+                          vlc_value_t, vlc_value_t, void * );
+static int alphaCallback( vlc_object_t *, char const *,
+                          vlc_value_t, vlc_value_t, void * );
+static int xCallback( vlc_object_t *, char const *,
+                      vlc_value_t, vlc_value_t, void * );
+static int yCallback( vlc_object_t *, char const *,
+                      vlc_value_t, vlc_value_t, void * );
 
 /*****************************************************************************
  * Module descriptor
@@ -141,33 +153,50 @@ static int MosaicBridgeCallback( vlc_object_t *, char const *,
     "Force the use of a specific chroma. Use YUVA if you're planning " \
     "to use the Alphamask or Bluescreen video filter." )
 
+#define ALPHA_TEXT N_("Transparency")
+#define ALPHA_LONGTEXT N_( \
+    "Transparency of the mosaic picture." )
+
+#define X_TEXT N_("X offset")
+#define X_LONGTEXT N_( \
+    "X coordinate of the upper left corner in the mosaic if non negative." )
+
+#define Y_TEXT N_("Y offset")
+#define Y_LONGTEXT N_( \
+    "Y coordinate of the upper left corner in the mosaic if non negative." )
+
 #define CFG_PREFIX "sout-mosaic-bridge-"
 
 vlc_module_begin();
-    set_shortname( _( "Mosaic bridge" ) );
-    set_description(_("Mosaic bridge stream output") );
+    set_shortname( N_( "Mosaic bridge" ) );
+    set_description(N_("Mosaic bridge stream output") );
     set_capability( "sout stream", 0 );
     add_shortcut( "mosaic-bridge" );
 
     add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
-                VLC_FALSE );
+                false );
     add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
-                 WIDTH_LONGTEXT, VLC_TRUE );
+                 WIDTH_LONGTEXT, true );
     add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
-                 HEIGHT_LONGTEXT, VLC_TRUE );
+                 HEIGHT_LONGTEXT, true );
     add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
-                RATIO_LONGTEXT, VLC_FALSE );
+                RATIO_LONGTEXT, false );
     add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                VLC_FALSE );
+                false );
 
     add_module_list( CFG_PREFIX "vfilter", "video filter2",
-                     NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );
+                     NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, false );
+
+    add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255, NULL,
+                            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 );
 
     set_callbacks( Open, Close );
 vlc_module_end();
 
-static const char *ppsz_sout_options[] = {
-    "id", "width", "height", "sar", "vfilter", "chroma", NULL
+static const char *const ppsz_sout_options[] = {
+    "id", "width", "height", "sar", "vfilter", "chroma", "alpha", "x", "y", NULL
 };
 
 /*****************************************************************************
@@ -190,7 +219,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     p_stream->p_sys = p_sys;
-    p_sys->b_inited = VLC_FALSE;
+    p_sys->b_inited = false;
 
     var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
     var_Get( p_libvlc, "mosaic-lock", &val );
@@ -201,13 +230,11 @@ static int Open( vlc_object_t *p_this )
 
     p_sys->i_height =
         var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
-    var_AddCallback( p_stream, CFG_PREFIX "height", MosaicBridgeCallback,
-                     p_stream );
+    var_AddCallback( p_stream, CFG_PREFIX "height", HeightCallback, p_stream );
 
     p_sys->i_width =
         var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
-    var_AddCallback( p_stream, CFG_PREFIX "width", MosaicBridgeCallback,
-                     p_stream );
+    var_AddCallback( p_stream, CFG_PREFIX "width", WidthCallback, p_stream );
 
     var_Get( p_stream, CFG_PREFIX "sar", &val );
     if ( val.psz_string )
@@ -243,6 +270,15 @@ static int Open( vlc_object_t *p_this )
         msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
     }
 
+#define INT_COMMAND( a ) \
+    var_Create( p_stream, CFG_PREFIX #a, \
+                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND ); \
+    var_AddCallback( p_stream, CFG_PREFIX #a, a ## Callback, \
+                     p_stream );
+    INT_COMMAND( alpha )
+    INT_COMMAND( x )
+    INT_COMMAND( y )
+
     p_stream->pf_add    = Add;
     p_stream->pf_del    = Del;
     p_stream->pf_send   = Send;
@@ -262,18 +298,25 @@ static void Close( vlc_object_t * p_this )
 
     p_stream->p_sout->i_out_pace_nocontrol--;
 
-    if ( p_sys->psz_id )
-        free( p_sys->psz_id );
+    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 )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     bridge_t *p_bridge;
     bridged_es_t *p_es;
-    char *psz_chain, *psz_parser;
+    char *psz_chain;
     int i;
 
     if ( p_sys->b_inited )
@@ -283,10 +326,12 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
     /* Create decoder object */
     p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
+    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 = VLC_FALSE;
+    p_sys->p_decoder->b_pace_control = false;
     p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
     p_sys->p_decoder->fmt_out.i_extra = 0;
     p_sys->p_decoder->fmt_out.p_extra = 0;
@@ -296,8 +341,15 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     p_sys->p_decoder->pf_picture_link    = video_link_picture_decoder;
     p_sys->p_decoder->pf_picture_unlink  = video_unlink_picture_decoder;
     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;
+    }
+
     for( i = 0; i < PICTURE_RING_SIZE; i++ )
-        p_sys->p_decoder->p_owner->pp_pics[i] = 0;
+        p_sys->p_decoder->p_owner->pp_pics[i] = NULL;
     p_sys->p_decoder->p_owner->video = p_fmt->video;
     //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
 
@@ -308,11 +360,11 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     {
         msg_Err( p_stream, "cannot find decoder" );
         vlc_object_detach( p_sys->p_decoder );
-        vlc_object_destroy( p_sys->p_decoder );
+        vlc_object_release( p_sys->p_decoder );
         return NULL;
     }
 
-    p_sys->b_inited = VLC_TRUE;
+    p_sys->b_inited = true;
     vlc_mutex_lock( p_sys->p_lock );
 
     p_bridge = GetBridge( p_stream );
@@ -348,11 +400,15 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
     p_sys->p_es = p_es = p_bridge->pp_es[i];
 
+    p_es->i_alpha = var_GetInteger( p_stream, CFG_PREFIX "alpha" );
+    p_es->i_x = var_GetInteger( p_stream, CFG_PREFIX "x" );
+    p_es->i_y = var_GetInteger( p_stream, CFG_PREFIX "y" );
+
     //p_es->fmt = *p_fmt;
     p_es->psz_id = p_sys->psz_id;
     p_es->p_picture = NULL;
     p_es->pp_last = &p_es->p_picture;
-    p_es->b_empty = VLC_FALSE;
+    p_es->b_empty = false;
 
     vlc_mutex_unlock( p_sys->p_lock );
 
@@ -370,58 +426,19 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     /* Create user specified video filters */
     psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
     msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
+    if( psz_chain )
     {
-        config_chain_t *p_cfg;
-        for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
-        {
-            msg_Dbg( p_stream, " - %s\n", p_cfg->psz_value );
-        }
-    }
-    p_sys->i_vfilters = 0;
-    p_sys->pp_vfilters = NULL;
-    psz_parser = psz_chain;
-    while( psz_parser && *psz_parser )
-    {
-        config_chain_t *p_cfg;
-        char *psz_name;
-        filter_t **pp_vfilter;
-        psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
-        p_sys->i_vfilters++;
-        p_sys->pp_vfilters =
-            (filter_t **)realloc( p_sys->pp_vfilters,
-                                  p_sys->i_vfilters * sizeof(filter_t *) );
-        pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
-        *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
-        vlc_object_attach( *pp_vfilter, p_stream );
-        (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
-        (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
-        (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
+        p_sys->p_vf2 = filter_chain_New( p_stream, "video filter2", false,
+                                         video_filter_buffer_allocation_init,
+                                         NULL, p_sys->p_decoder->p_owner );
+        es_format_t fmt;
+        es_format_Copy( &fmt, &p_sys->p_decoder->fmt_out );
         if( p_sys->i_chroma )
-            (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
-        (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
-        (*pp_vfilter)->p_cfg = p_cfg;
-        (*pp_vfilter)->p_module =
-            module_Need( *pp_vfilter, "video filter2", psz_name, VLC_TRUE );
-        if( (*pp_vfilter)->p_module )
-        {
-            /* It worked! */
-            (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
-                p_sys->p_decoder->p_owner;
-            msg_Err( p_stream, "Added video filter %s to the chain",
-                     psz_name );
-        }
-        else
-        {
-            /* Crap ... we didn't find a filter */
-            msg_Warn( p_stream,
-                      "no video filter matching name \"%s\" found",
-                      psz_name );
-            vlc_object_detach( *pp_vfilter );
-            vlc_object_destroy( *pp_vfilter );
-            p_sys->i_vfilters--;
-        }
+            fmt.video.i_chroma = p_sys->i_chroma;
+        filter_chain_Reset( p_sys->p_vf2, &fmt, &fmt );
+        filter_chain_AppendFromString( p_sys->p_vf2, psz_chain );
+        free( psz_chain );
     }
-    free( psz_chain );
 
     return (sout_stream_id_t *)p_sys;
 }
@@ -432,8 +449,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     bridge_t *p_bridge;
     bridged_es_t *p_es;
-    vlc_bool_t b_last_es = VLC_TRUE;
-    filter_t **pp_vfilter, **pp_end;
+    bool b_last_es = true;
     int i;
 
     if ( !p_sys->b_inited )
@@ -443,43 +459,35 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
 
     if ( p_sys->p_decoder != NULL )
     {
-        picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
+        decoder_owner_sys_t *p_owner = p_sys->p_decoder->p_owner;
 
         if( p_sys->p_decoder->p_module )
             module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
         vlc_object_detach( p_sys->p_decoder );
-        vlc_object_destroy( p_sys->p_decoder );
+        vlc_object_release( p_sys->p_decoder );
 
+        picture_t **pp_ring = p_owner->pp_pics;
         for( i = 0; i < PICTURE_RING_SIZE; i++ )
         {
             if ( pp_ring[i] != NULL )
             {
-                if ( pp_ring[i]->p_data_orig != NULL )
-                    free( pp_ring[i]->p_data_orig );
+                free( pp_ring[i]->p_data_orig );
                 free( pp_ring[i]->p_sys );
                 free( pp_ring[i] );
             }
         }
+        free( p_owner );
     }
 
     /* Destroy user specified video filters */
-    pp_vfilter = p_sys->pp_vfilters;
-    pp_end = pp_vfilter + p_sys->i_vfilters;
-    for( ; pp_vfilter < pp_end; pp_vfilter++ )
-    {
-        vlc_object_detach( *pp_vfilter );
-        if( (*pp_vfilter)->p_module )
-            module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
-        vlc_object_destroy( *pp_vfilter );
-    }
-    free( p_sys->pp_vfilters );
+    filter_chain_Delete( p_sys->p_vf2 );
 
     vlc_mutex_lock( p_sys->p_lock );
 
     p_bridge = GetBridge( p_stream );
     p_es = p_sys->p_es;
 
-    p_es->b_empty = VLC_TRUE;
+    p_es->b_empty = true;
     while ( p_es->p_picture )
     {
         picture_t *p_next = p_es->p_picture->p_next;
@@ -491,7 +499,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
     {
         if ( !p_bridge->pp_es[i]->b_empty )
         {
-            b_last_es = VLC_FALSE;
+            b_last_es = false;
             break;
         }
     }
@@ -513,7 +521,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
         image_HandlerDelete( p_sys->p_image );
     }
 
-    p_sys->b_inited = VLC_FALSE;
+    p_sys->b_inited = false;
 
     return VLC_SUCCESS;
 }
@@ -593,6 +601,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
             if ( p_new_pic == NULL )
             {
                 msg_Err( p_stream, "image conversion failed" );
+                p_pic->pf_release( p_pic );
                 continue;
             }
         }
@@ -613,6 +622,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
                                   p_sys->p_decoder->fmt_out.video.i_aspect )
                 != VLC_SUCCESS )
             {
+                p_pic->pf_release( p_pic );
                 free( p_new_pic );
                 msg_Err( p_stream, "image allocation failed" );
                 continue;
@@ -629,27 +639,8 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
         p_new_pic->date = p_pic->date;
         p_pic->pf_release( p_pic );
 
-        if( p_sys->pp_vfilters )
-        {
-            /* Apply user specified video filters */
-            filter_t **pp_vfilter = p_sys->pp_vfilters;
-            filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
-            for( ; pp_vfilter < pp_end; pp_vfilter++ )
-            {
-                (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
-                (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
-                (*pp_vfilter)->fmt_in.video = p_new_pic->format;
-                (*pp_vfilter)->fmt_out.video = p_new_pic->format;
-                p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
-                                                             p_new_pic );
-                if( !p_new_pic )
-                {
-                    msg_Err( p_stream, "video filter failed" );
-                    break;
-                }
-            }
-            if( !p_new_pic ) continue;
-        }
+        if( p_sys->p_vf2 )
+            p_new_pic = filter_chain_VideoFilter( p_sys->p_vf2, p_new_pic );
 
         PushPicture( p_stream, p_new_pic );
     }
@@ -660,25 +651,29 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
 struct picture_sys_t
 {
     vlc_object_t *p_owner;
-    vlc_bool_t b_dead;
+    bool b_dead;
 };
 
 static void video_release_buffer_decoder( picture_t *p_pic )
 {
-    if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
-    {
-        video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
-    }
-    else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
+    assert( p_pic && p_pic->p_sys );
+
+    if( --p_pic->i_refcount > 0 )
+        return;
+
+    video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
 }
 
 static void video_release_buffer_filter( picture_t *p_pic )
 {
-    if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
-    {
-        video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
-    }
-    else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
+    assert( p_pic );
+
+    if( --p_pic->i_refcount > 0 )
+        return;
+
+    assert( p_pic->p_sys );
+
+    video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
 }
 
 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
@@ -742,14 +737,13 @@ static picture_t *video_new_buffer( vlc_object_t *p_this,
             {
                 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
                 {
-                    if ( pp_ring[i]->p_data_orig != NULL )
-                        free( pp_ring[i]->p_data_orig );
+                    free( pp_ring[i]->p_data_orig );
                     free( pp_ring[i]->p_sys );
                     free( pp_ring[i] );
                 }
                 else
                 {
-                    pp_ring[i]->p_sys->b_dead = VLC_TRUE;
+                    pp_ring[i]->p_sys->b_dead = true;
                 }
                 pp_ring[i] = NULL;
             }
@@ -762,6 +756,7 @@ static picture_t *video_new_buffer( vlc_object_t *p_this,
         if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
         {
             pp_ring[i]->i_status = RESERVED_PICTURE;
+            pp_ring[i]->i_refcount = 1;
             return pp_ring[i];
         }
     }
@@ -777,19 +772,26 @@ static picture_t *video_new_buffer( vlc_object_t *p_this,
 
         for( i = 0; i < PICTURE_RING_SIZE; i++ )
         {
+            pp_ring[i]->p_sys->b_dead = true;
             pp_ring[i]->pf_release( pp_ring[i] );
+            pp_ring[i] = NULL;
         }
 
         i = 0;
     }
 
     p_pic = malloc( sizeof(picture_t) );
+    if( !p_pic ) return NULL;
     fmt_out->video.i_chroma = fmt_out->i_codec;
-    vout_AllocatePicture( p_this, p_pic,
+    if( vout_AllocatePicture( p_this, p_pic,
                           fmt_out->video.i_chroma,
                           fmt_out->video.i_width,
                           fmt_out->video.i_height,
-                          fmt_out->video.i_aspect );
+                          fmt_out->video.i_aspect ) != VLC_SUCCESS )
+    {
+        free( p_pic );
+        return NULL;
+    }
 
     if( !p_pic->i_planes )
     {
@@ -798,9 +800,10 @@ static picture_t *video_new_buffer( vlc_object_t *p_this,
     }
 
     p_pic->pf_release = pf_release;
+    p_pic->i_refcount = 1;
     p_pic->p_sys = malloc( sizeof(picture_sys_t) );
     p_pic->p_sys->p_owner = p_this;
-    p_pic->p_sys->b_dead = VLC_FALSE;
+    p_pic->p_sys->b_dead = false;
     p_pic->i_status = RESERVED_PICTURE;
 
     pp_ring[i] = p_pic;
@@ -828,8 +831,7 @@ static void video_del_buffer( picture_t *p_pic )
     p_pic->i_status = DESTROYED_PICTURE;
     if ( p_pic->p_sys->b_dead )
     {
-        if ( p_pic->p_data_orig != NULL )
-            free( p_pic->p_data_orig );
+        free( p_pic->p_data_orig );
         free( p_pic->p_sys );
         free( p_pic );
     }
@@ -851,33 +853,78 @@ static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
 /**********************************************************************
  * Callback to update (some) params on the fly
  **********************************************************************/
-static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
-                                 vlc_value_t oldval, vlc_value_t newval,
-                                 void *p_data )
+static int HeightCallback( vlc_object_t *p_this, char const *psz_var,
+                           vlc_value_t oldval, vlc_value_t newval,
+                           void *p_data )
 {
-    VLC_UNUSED(p_this); VLC_UNUSED(oldval);
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
     sout_stream_t *p_stream = (sout_stream_t *)p_data;
     sout_stream_sys_t *p_sys = p_stream->p_sys;
-    int i_ret = VLC_SUCCESS;
 
-#define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
-    if( VAR_IS( "height" ) )
-    {
-        /* We create the handler before updating the value in p_sys
-         * so we don't have to worry about locking */
-        if( !p_sys->p_image && newval.i_int )
-            p_sys->p_image = image_HandlerCreate( p_stream );
-        p_sys->i_height = newval.i_int;
-    }
-    else if( VAR_IS( "width" ) )
-    {
-        /* We create the handler before updating the value in p_sys
-         * so we don't have to worry about locking */
-        if( !p_sys->p_image && newval.i_int )
-            p_sys->p_image = image_HandlerCreate( p_stream );
-        p_sys->i_width = newval.i_int;
-    }
-#undef VAR_IS
+    /* We create the handler before updating the value in p_sys
+     * so we don't have to worry about locking */
+    if( !p_sys->p_image && newval.i_int )
+        p_sys->p_image = image_HandlerCreate( p_stream );
+    p_sys->i_height = newval.i_int;
+
+    return VLC_SUCCESS;
+}
+
+static int WidthCallback( vlc_object_t *p_this, char const *psz_var,
+                           vlc_value_t oldval, vlc_value_t newval,
+                           void *p_data )
+{
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
+    sout_stream_t *p_stream = (sout_stream_t *)p_data;
+    sout_stream_sys_t *p_sys = p_stream->p_sys;
+
+    /* We create the handler before updating the value in p_sys
+     * so we don't have to worry about locking */
+    if( !p_sys->p_image && newval.i_int )
+        p_sys->p_image = image_HandlerCreate( p_stream );
+    p_sys->i_width = newval.i_int;
 
-    return i_ret;
+    return VLC_SUCCESS;
+}
+
+static int alphaCallback( vlc_object_t *p_this, char const *psz_var,
+                          vlc_value_t oldval, vlc_value_t newval,
+                          void *p_data )
+{
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
+    sout_stream_t *p_stream = (sout_stream_t *)p_data;
+    sout_stream_sys_t *p_sys = p_stream->p_sys;
+
+    if( p_sys->p_es )
+        p_sys->p_es->i_alpha = newval.i_int;
+
+    return VLC_SUCCESS;
+}
+
+static int xCallback( vlc_object_t *p_this, char const *psz_var,
+                      vlc_value_t oldval, vlc_value_t newval,
+                      void *p_data )
+{
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
+    sout_stream_t *p_stream = (sout_stream_t *)p_data;
+    sout_stream_sys_t *p_sys = p_stream->p_sys;
+
+    if( p_sys->p_es )
+        p_sys->p_es->i_x = newval.i_int;
+
+    return VLC_SUCCESS;
+}
+
+static int yCallback( vlc_object_t *p_this, char const *psz_var,
+                      vlc_value_t oldval, vlc_value_t newval,
+                      void *p_data )
+{
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
+    sout_stream_t *p_stream = (sout_stream_t *)p_data;
+    sout_stream_sys_t *p_sys = p_stream->p_sys;
+
+    if( p_sys->p_es )
+        p_sys->p_es->i_y = newval.i_int;
+
+    return VLC_SUCCESS;
 }