1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2007 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
8 * Christophe Massiot <massiot@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <errno.h> /* ENOMEM */
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
38 #include <vlc_block.h>
39 #include <vlc_codec.h>
41 #include <vlc_image.h>
42 #include <vlc_filter.h>
44 #include "../video_filter/mosaic.h"
48 /*****************************************************************************
50 *****************************************************************************/
51 struct sout_stream_sys_t
57 image_handler_t *p_image; /* filter for resizing */
58 int i_height, i_width;
59 unsigned int i_sar_num, i_sar_den;
63 int i_chroma; /* force image format chroma */
65 filter_chain_t *p_vf2;
68 #define PICTURE_RING_SIZE 4
69 struct decoder_owner_sys_t
71 picture_t *pp_pics[PICTURE_RING_SIZE];
73 /* Current format in use by the output */
77 typedef void (* pf_release_t)( picture_t * );
78 static void ReleasePicture( picture_t *p_pic )
82 if( --p_pic->i_refcount > 0 )
87 pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
93 free( p_pic->p_data_orig );
98 /*****************************************************************************
100 *****************************************************************************/
101 static int Open ( vlc_object_t * );
102 static void Close ( vlc_object_t * );
103 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
104 static int Del ( sout_stream_t *, sout_stream_id_t * );
105 static int Send( sout_stream_t *, sout_stream_id_t *, block_t * );
107 inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
108 inline static void video_del_buffer_filter( filter_t *, picture_t * );
109 static void video_del_buffer( picture_t * );
111 inline static picture_t *video_new_buffer_decoder( decoder_t * );
112 inline static picture_t *video_new_buffer_filter( filter_t * );
113 static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
114 es_format_t *, void (*)( picture_t * ) );
116 static void video_link_picture_decoder( decoder_t *, picture_t * );
117 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
119 static int HeightCallback( vlc_object_t *, char const *,
120 vlc_value_t, vlc_value_t, void * );
121 static int WidthCallback( vlc_object_t *, char const *,
122 vlc_value_t, vlc_value_t, void * );
123 static int alphaCallback( vlc_object_t *, char const *,
124 vlc_value_t, vlc_value_t, void * );
125 static int xCallback( vlc_object_t *, char const *,
126 vlc_value_t, vlc_value_t, void * );
127 static int yCallback( vlc_object_t *, char const *,
128 vlc_value_t, vlc_value_t, void * );
130 /*****************************************************************************
132 *****************************************************************************/
133 #define ID_TEXT N_("ID")
134 #define ID_LONGTEXT N_( \
135 "Specify an identifier string for this subpicture" )
137 #define WIDTH_TEXT N_("Video width")
138 #define WIDTH_LONGTEXT N_( \
139 "Output video width." )
140 #define HEIGHT_TEXT N_("Video height")
141 #define HEIGHT_LONGTEXT N_( \
142 "Output video height." )
143 #define RATIO_TEXT N_("Sample aspect ratio")
144 #define RATIO_LONGTEXT N_( \
145 "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
147 #define VFILTER_TEXT N_("Video filter")
148 #define VFILTER_LONGTEXT N_( \
149 "Video filters will be applied to the video stream." )
151 #define CHROMA_TEXT N_("Image chroma")
152 #define CHROMA_LONGTEXT N_( \
153 "Force the use of a specific chroma. Use YUVA if you're planning " \
154 "to use the Alphamask or Bluescreen video filter." )
156 #define ALPHA_TEXT N_("Transparency")
157 #define ALPHA_LONGTEXT N_( \
158 "Transparency of the mosaic picture." )
160 #define X_TEXT N_("X offset")
161 #define X_LONGTEXT N_( \
162 "X coordinate of the upper left corner in the mosaic if non negative." )
164 #define Y_TEXT N_("Y offset")
165 #define Y_LONGTEXT N_( \
166 "Y coordinate of the upper left corner in the mosaic if non negative." )
168 #define CFG_PREFIX "sout-mosaic-bridge-"
171 set_shortname( N_( "Mosaic bridge" ) );
172 set_description(N_("Mosaic bridge stream output") );
173 set_capability( "sout stream", 0 );
174 add_shortcut( "mosaic-bridge" );
176 add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
178 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
179 WIDTH_LONGTEXT, true );
180 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
181 HEIGHT_LONGTEXT, true );
182 add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
183 RATIO_LONGTEXT, false );
184 add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
187 add_module_list( CFG_PREFIX "vfilter", "video filter2",
188 NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, false );
190 add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255, NULL,
191 ALPHA_TEXT, ALPHA_LONGTEXT, false );
192 add_integer( CFG_PREFIX "x", -1, NULL, X_TEXT, X_LONGTEXT, false );
193 add_integer( CFG_PREFIX "y", -1, NULL, Y_TEXT, Y_LONGTEXT, false );
195 set_callbacks( Open, Close );
198 static const char *const ppsz_sout_options[] = {
199 "id", "width", "height", "sar", "vfilter", "chroma", "alpha", "x", "y", NULL
202 /*****************************************************************************
204 *****************************************************************************/
205 static int Open( vlc_object_t *p_this )
207 sout_stream_t *p_stream = (sout_stream_t *)p_this;
208 sout_stream_sys_t *p_sys;
209 vlc_object_t *p_libvlc = VLC_OBJECT( p_this->p_libvlc );
212 config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
215 p_sys = malloc( sizeof( sout_stream_sys_t ) );
219 p_stream->p_sys = p_sys;
220 p_sys->b_inited = false;
222 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
223 var_Get( p_libvlc, "mosaic-lock", &val );
224 p_sys->p_lock = val.p_address;
226 p_sys->psz_id = var_CreateGetString( p_stream, CFG_PREFIX "id" );
229 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
230 var_AddCallback( p_stream, CFG_PREFIX "height", HeightCallback, p_stream );
233 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
234 var_AddCallback( p_stream, CFG_PREFIX "width", WidthCallback, p_stream );
236 var_Get( p_stream, CFG_PREFIX "sar", &val );
239 char *psz_parser = strchr( val.psz_string, ':' );
243 *psz_parser++ = '\0';
244 p_sys->i_sar_num = atoi( val.psz_string );
245 p_sys->i_sar_den = atoi( psz_parser );
246 vlc_ureduce( &p_sys->i_sar_num, &p_sys->i_sar_den,
247 p_sys->i_sar_num, p_sys->i_sar_den, 0 );
251 msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
252 p_sys->i_sar_num = p_sys->i_sar_den = 1;
255 free( val.psz_string );
259 p_sys->i_sar_num = p_sys->i_sar_den = 1;
263 val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
264 if( val.psz_string && strlen( val.psz_string ) >= 4 )
266 memcpy( &p_sys->i_chroma, val.psz_string, 4 );
267 msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
270 #define INT_COMMAND( a ) do { \
271 var_Create( p_stream, CFG_PREFIX #a, \
272 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND ); \
273 var_AddCallback( p_stream, CFG_PREFIX #a, a ## Callback, \
274 p_stream ); } while(0)
275 INT_COMMAND( alpha );
281 p_stream->pf_add = Add;
282 p_stream->pf_del = Del;
283 p_stream->pf_send = Send;
285 p_stream->p_sout->i_out_pace_nocontrol++;
290 /*****************************************************************************
292 *****************************************************************************/
293 static void Close( vlc_object_t * p_this )
295 sout_stream_t *p_stream = (sout_stream_t*)p_this;
296 sout_stream_sys_t *p_sys = p_stream->p_sys;
298 p_stream->p_sout->i_out_pace_nocontrol--;
300 free( p_sys->psz_id );
305 static int video_filter_buffer_allocation_init( filter_t *p_filter, void *p_data )
307 p_filter->pf_vout_buffer_new = video_new_buffer_filter;
308 p_filter->pf_vout_buffer_del = video_del_buffer_filter;
309 p_filter->p_owner = p_data;
313 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
315 sout_stream_sys_t *p_sys = p_stream->p_sys;
321 if( p_sys->b_inited || p_fmt->i_cat != VIDEO_ES )
324 /* Create decoder object */
325 p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
326 if( !p_sys->p_decoder )
328 vlc_object_attach( p_sys->p_decoder, p_stream );
329 p_sys->p_decoder->p_module = NULL;
330 p_sys->p_decoder->fmt_in = *p_fmt;
331 p_sys->p_decoder->b_pace_control = false;
332 p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
333 p_sys->p_decoder->fmt_out.i_extra = 0;
334 p_sys->p_decoder->fmt_out.p_extra = 0;
335 p_sys->p_decoder->pf_decode_video = 0;
336 p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
337 p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
338 p_sys->p_decoder->pf_picture_link = video_link_picture_decoder;
339 p_sys->p_decoder->pf_picture_unlink = video_unlink_picture_decoder;
340 p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
341 if( !p_sys->p_decoder->p_owner )
343 vlc_object_detach( p_sys->p_decoder );
344 vlc_object_release( p_sys->p_decoder );
348 for( i = 0; i < PICTURE_RING_SIZE; i++ )
349 p_sys->p_decoder->p_owner->pp_pics[i] = NULL;
350 p_sys->p_decoder->p_owner->video = p_fmt->video;
351 //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
353 p_sys->p_decoder->p_module =
354 module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
356 if( !p_sys->p_decoder->p_module || !p_sys->p_decoder->pf_decode_video )
358 if( p_sys->p_decoder->p_module )
360 msg_Err( p_stream, "instanciated a non video decoder" );
361 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
365 msg_Err( p_stream, "cannot find decoder" );
367 free( p_sys->p_decoder->p_owner );
368 vlc_object_detach( p_sys->p_decoder );
369 vlc_object_release( p_sys->p_decoder );
373 p_sys->b_inited = true;
374 vlc_mutex_lock( p_sys->p_lock );
376 p_bridge = GetBridge( p_stream );
377 if ( p_bridge == NULL )
379 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
382 p_bridge = malloc( sizeof( bridge_t ) );
384 var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );
385 val.p_address = p_bridge;
386 var_Set( p_libvlc, "mosaic-struct", val );
388 p_bridge->i_es_num = 0;
389 p_bridge->pp_es = NULL;
392 for ( i = 0; i < p_bridge->i_es_num; i++ )
394 if ( p_bridge->pp_es[i]->b_empty )
398 if ( i == p_bridge->i_es_num )
400 p_bridge->pp_es = realloc( p_bridge->pp_es,
401 (p_bridge->i_es_num + 1)
402 * sizeof(bridged_es_t *) );
403 p_bridge->i_es_num++;
404 p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
407 p_sys->p_es = p_es = p_bridge->pp_es[i];
409 p_es->i_alpha = var_GetInteger( p_stream, CFG_PREFIX "alpha" );
410 p_es->i_x = var_GetInteger( p_stream, CFG_PREFIX "x" );
411 p_es->i_y = var_GetInteger( p_stream, CFG_PREFIX "y" );
413 //p_es->fmt = *p_fmt;
414 p_es->psz_id = p_sys->psz_id;
415 p_es->p_picture = NULL;
416 p_es->pp_last = &p_es->p_picture;
417 p_es->b_empty = false;
419 vlc_mutex_unlock( p_sys->p_lock );
421 if ( p_sys->i_height || p_sys->i_width )
423 p_sys->p_image = image_HandlerCreate( p_stream );
427 p_sys->p_image = NULL;
430 msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
432 /* Create user specified video filters */
433 psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
434 msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
437 p_sys->p_vf2 = filter_chain_New( p_stream, "video filter2", false,
438 video_filter_buffer_allocation_init,
439 NULL, p_sys->p_decoder->p_owner );
441 es_format_Copy( &fmt, &p_sys->p_decoder->fmt_out );
442 if( p_sys->i_chroma )
443 fmt.video.i_chroma = p_sys->i_chroma;
444 filter_chain_Reset( p_sys->p_vf2, &fmt, &fmt );
445 filter_chain_AppendFromString( p_sys->p_vf2, psz_chain );
453 return (sout_stream_id_t *)p_sys;
456 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
459 sout_stream_sys_t *p_sys = p_stream->p_sys;
462 bool b_last_es = true;
465 if( !p_sys->b_inited )
468 if( p_sys->p_decoder != NULL )
470 decoder_owner_sys_t *p_owner = p_sys->p_decoder->p_owner;
472 if( p_sys->p_decoder->p_module )
473 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
474 vlc_object_detach( p_sys->p_decoder );
475 vlc_object_release( p_sys->p_decoder );
477 picture_t **pp_ring = p_owner->pp_pics;
478 for( i = 0; i < PICTURE_RING_SIZE; i++ )
480 if ( pp_ring[i] != NULL )
482 free( pp_ring[i]->p_data_orig );
483 free( pp_ring[i]->p_sys );
490 /* Destroy user specified video filters */
492 filter_chain_Delete( p_sys->p_vf2 );
494 vlc_mutex_lock( p_sys->p_lock );
496 p_bridge = GetBridge( p_stream );
499 p_es->b_empty = true;
500 while ( p_es->p_picture )
502 picture_t *p_next = p_es->p_picture->p_next;
503 p_es->p_picture->pf_release( p_es->p_picture );
504 p_es->p_picture = p_next;
507 for ( i = 0; i < p_bridge->i_es_num; i++ )
509 if ( !p_bridge->pp_es[i]->b_empty )
518 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
519 for ( i = 0; i < p_bridge->i_es_num; i++ )
520 free( p_bridge->pp_es[i] );
521 free( p_bridge->pp_es );
523 var_Destroy( p_libvlc, "mosaic-struct" );
526 vlc_mutex_unlock( p_sys->p_lock );
528 if ( p_sys->p_image )
530 image_HandlerDelete( p_sys->p_image );
533 p_sys->b_inited = false;
538 /*****************************************************************************
539 * PushPicture : push a picture in the mosaic-struct structure
540 *****************************************************************************/
541 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
543 sout_stream_sys_t *p_sys = p_stream->p_sys;
544 bridged_es_t *p_es = p_sys->p_es;
546 vlc_mutex_lock( p_sys->p_lock );
548 *p_es->pp_last = p_picture;
549 p_picture->p_next = NULL;
550 p_es->pp_last = &p_picture->p_next;
552 vlc_mutex_unlock( p_sys->p_lock );
555 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
558 sout_stream_sys_t *p_sys = p_stream->p_sys;
561 if ( (sout_stream_sys_t *)id != p_sys )
563 block_ChainRelease( p_buffer );
567 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
570 picture_t *p_new_pic;
572 if( p_sys->i_height || p_sys->i_width )
574 video_format_t fmt_out, fmt_in;
576 memset( &fmt_in, 0, sizeof(video_format_t) );
577 memset( &fmt_out, 0, sizeof(video_format_t) );
578 fmt_in = p_sys->p_decoder->fmt_out.video;
581 if( p_sys->i_chroma )
582 fmt_out.i_chroma = p_sys->i_chroma;
584 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
586 if ( !p_sys->i_height )
588 fmt_out.i_width = p_sys->i_width;
589 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
590 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
593 else if ( !p_sys->i_width )
595 fmt_out.i_height = p_sys->i_height;
596 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
597 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
602 fmt_out.i_width = p_sys->i_width;
603 fmt_out.i_height = p_sys->i_height;
605 fmt_out.i_visible_width = fmt_out.i_width;
606 fmt_out.i_visible_height = fmt_out.i_height;
608 p_new_pic = image_Convert( p_sys->p_image,
609 p_pic, &fmt_in, &fmt_out );
610 if ( p_new_pic == NULL )
612 msg_Err( p_stream, "image conversion failed" );
613 picture_Release( p_pic );
619 /* TODO: chroma conversion if needed */
621 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
622 if( p_new_pic == NULL )
624 msg_Err( p_stream, "image conversion failed" );
628 if( vout_AllocatePicture(
629 p_stream, p_new_pic, p_pic->format.i_chroma,
630 p_pic->format.i_width, p_pic->format.i_height,
631 p_sys->p_decoder->fmt_out.video.i_aspect )
634 picture_Release( p_pic );
636 msg_Err( p_stream, "image allocation failed" );
640 vout_CopyPicture( p_stream, p_new_pic, p_pic );
643 p_new_pic->i_refcount = 1;
644 p_new_pic->i_status = DESTROYED_PICTURE;
645 p_new_pic->i_type = DIRECT_PICTURE;
646 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
647 p_new_pic->pf_release = ReleasePicture;
648 p_new_pic->date = p_pic->date;
649 picture_Release( p_pic );
652 p_new_pic = filter_chain_VideoFilter( p_sys->p_vf2, p_new_pic );
654 PushPicture( p_stream, p_new_pic );
662 vlc_object_t *p_owner;
666 static void video_release_buffer_decoder( picture_t *p_pic )
668 assert( p_pic && p_pic->p_sys );
670 if( --p_pic->i_refcount > 0 )
673 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
676 static void video_release_buffer_filter( picture_t *p_pic )
680 if( --p_pic->i_refcount > 0 )
683 assert( p_pic->p_sys );
685 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
688 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
690 return video_new_buffer( VLC_OBJECT( p_dec ),
691 (decoder_owner_sys_t *)p_dec->p_owner,
693 video_release_buffer_decoder );
696 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
698 return video_new_buffer( VLC_OBJECT( p_filter ),
699 (decoder_owner_sys_t *)p_filter->p_owner,
701 video_release_buffer_filter );
704 static picture_t *video_new_buffer( vlc_object_t *p_this,
705 decoder_owner_sys_t *p_sys,
706 es_format_t *fmt_out,
707 void ( *pf_release )( picture_t * ) )
709 picture_t **pp_ring = p_sys->pp_pics;
713 if( fmt_out->video.i_width != p_sys->video.i_width ||
714 fmt_out->video.i_height != p_sys->video.i_height ||
715 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
716 fmt_out->video.i_aspect != p_sys->video.i_aspect )
718 if( !fmt_out->video.i_sar_num ||
719 !fmt_out->video.i_sar_den )
721 fmt_out->video.i_sar_num =
722 fmt_out->video.i_aspect * fmt_out->video.i_height;
724 fmt_out->video.i_sar_den =
725 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
728 vlc_ureduce( &fmt_out->video.i_sar_num,
729 &fmt_out->video.i_sar_den,
730 fmt_out->video.i_sar_num,
731 fmt_out->video.i_sar_den, 0 );
733 if( !fmt_out->video.i_visible_width ||
734 !fmt_out->video.i_visible_height )
736 fmt_out->video.i_visible_width = fmt_out->video.i_width;
737 fmt_out->video.i_visible_height = fmt_out->video.i_height;
740 fmt_out->video.i_chroma = fmt_out->i_codec;
741 p_sys->video = fmt_out->video;
743 for( i = 0; i < PICTURE_RING_SIZE; i++ )
745 if ( pp_ring[i] != NULL )
747 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
749 free( pp_ring[i]->p_data_orig );
750 free( pp_ring[i]->p_sys );
755 pp_ring[i]->p_sys->b_dead = true;
762 /* Find an empty space in the picture ring buffer */
763 for( i = 0; i < PICTURE_RING_SIZE; i++ )
765 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
767 pp_ring[i]->i_status = RESERVED_PICTURE;
768 pp_ring[i]->i_refcount = 1;
772 for( i = 0; i < PICTURE_RING_SIZE; i++ )
774 if( pp_ring[i] == NULL ) break;
777 if( i == PICTURE_RING_SIZE )
779 msg_Err( p_this, "decoder/filter is leaking pictures, "
780 "resetting its ring buffer" );
782 for( i = 0; i < PICTURE_RING_SIZE; i++ )
784 pp_ring[i]->p_sys->b_dead = true;
785 pp_ring[i]->pf_release( pp_ring[i] );
792 p_pic = malloc( sizeof(picture_t) );
793 if( !p_pic ) return NULL;
794 fmt_out->video.i_chroma = fmt_out->i_codec;
795 if( vout_AllocatePicture( p_this, p_pic,
796 fmt_out->video.i_chroma,
797 fmt_out->video.i_width,
798 fmt_out->video.i_height,
799 fmt_out->video.i_aspect ) != VLC_SUCCESS )
805 if( !p_pic->i_planes )
811 p_pic->pf_release = pf_release;
812 p_pic->i_refcount = 1;
813 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
814 p_pic->p_sys->p_owner = p_this;
815 p_pic->p_sys->b_dead = false;
816 p_pic->i_status = RESERVED_PICTURE;
823 inline static void video_del_buffer_decoder( decoder_t *p_this,
827 video_del_buffer( p_pic );
830 inline static void video_del_buffer_filter( filter_t *p_this,
834 video_del_buffer( p_pic );
837 static void video_del_buffer( picture_t *p_pic )
839 p_pic->i_refcount = 0;
840 p_pic->i_status = DESTROYED_PICTURE;
841 if ( p_pic->p_sys->b_dead )
843 free( p_pic->p_data_orig );
844 free( p_pic->p_sys );
849 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
855 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
858 video_release_buffer_decoder( p_pic );
862 /**********************************************************************
863 * Callback to update (some) params on the fly
864 **********************************************************************/
865 static int HeightCallback( vlc_object_t *p_this, char const *psz_var,
866 vlc_value_t oldval, vlc_value_t newval,
869 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
870 sout_stream_t *p_stream = (sout_stream_t *)p_data;
871 sout_stream_sys_t *p_sys = p_stream->p_sys;
873 /* We create the handler before updating the value in p_sys
874 * so we don't have to worry about locking */
875 if( !p_sys->p_image && newval.i_int )
876 p_sys->p_image = image_HandlerCreate( p_stream );
877 p_sys->i_height = newval.i_int;
882 static int WidthCallback( vlc_object_t *p_this, char const *psz_var,
883 vlc_value_t oldval, vlc_value_t newval,
886 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
887 sout_stream_t *p_stream = (sout_stream_t *)p_data;
888 sout_stream_sys_t *p_sys = p_stream->p_sys;
890 /* We create the handler before updating the value in p_sys
891 * so we don't have to worry about locking */
892 if( !p_sys->p_image && newval.i_int )
893 p_sys->p_image = image_HandlerCreate( p_stream );
894 p_sys->i_width = newval.i_int;
899 static int alphaCallback( vlc_object_t *p_this, char const *psz_var,
900 vlc_value_t oldval, vlc_value_t newval,
903 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
904 sout_stream_t *p_stream = (sout_stream_t *)p_data;
905 sout_stream_sys_t *p_sys = p_stream->p_sys;
908 p_sys->p_es->i_alpha = newval.i_int;
913 static int xCallback( vlc_object_t *p_this, char const *psz_var,
914 vlc_value_t oldval, vlc_value_t newval,
917 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
918 sout_stream_t *p_stream = (sout_stream_t *)p_data;
919 sout_stream_sys_t *p_sys = p_stream->p_sys;
922 p_sys->p_es->i_x = newval.i_int;
927 static int yCallback( vlc_object_t *p_this, char const *psz_var,
928 vlc_value_t oldval, vlc_value_t newval,
931 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
932 sout_stream_t *p_stream = (sout_stream_t *)p_data;
933 sout_stream_sys_t *p_sys = p_stream->p_sys;
936 p_sys->p_es->i_y = newval.i_int;