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 *****************************************************************************/
28 #include <errno.h> /* ENOMEM */
32 #include <vlc_block.h>
33 #include <vlc_codec.h>
35 #include <vlc_image.h>
36 #include <vlc_filter.h>
38 #include "../video_filter/mosaic.h"
40 /*****************************************************************************
42 *****************************************************************************/
43 struct sout_stream_sys_t
49 image_handler_t *p_image; /* filter for resizing */
50 int i_height, i_width;
51 unsigned int i_sar_num, i_sar_den;
55 int i_chroma; /* force image format chroma */
57 filter_t **pp_vfilters;
61 #define PICTURE_RING_SIZE 4
62 struct decoder_owner_sys_t
64 picture_t *pp_pics[PICTURE_RING_SIZE];
66 /* Current format in use by the output */
70 typedef void (* pf_release_t)( picture_t * );
71 static void ReleasePicture( picture_t *p_pic )
75 if ( p_pic->i_refcount <= 0 )
77 if ( p_pic->p_sys != NULL )
79 pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
85 if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
86 if( p_pic ) free( p_pic );
91 /*****************************************************************************
93 *****************************************************************************/
94 static int Open ( vlc_object_t * );
95 static void Close ( vlc_object_t * );
96 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
97 static int Del ( sout_stream_t *, sout_stream_id_t * );
98 static int Send( sout_stream_t *, sout_stream_id_t *, block_t * );
100 inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
101 inline static void video_del_buffer_filter( filter_t *, picture_t * );
102 static void video_del_buffer( vlc_object_t *, picture_t * );
104 inline static picture_t *video_new_buffer_decoder( decoder_t * );
105 inline static picture_t *video_new_buffer_filter( filter_t * );
106 static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
107 es_format_t *, void (*)( picture_t * ) );
109 static void video_link_picture_decoder( decoder_t *, picture_t * );
110 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
111 static int MosaicBridgeCallback( vlc_object_t *, char const *,
112 vlc_value_t, vlc_value_t, void * );
114 /*****************************************************************************
116 *****************************************************************************/
117 #define ID_TEXT N_("ID")
118 #define ID_LONGTEXT N_( \
119 "Specify an identifier string for this subpicture" )
121 #define WIDTH_TEXT N_("Video width")
122 #define WIDTH_LONGTEXT N_( \
123 "Output video width." )
124 #define HEIGHT_TEXT N_("Video height")
125 #define HEIGHT_LONGTEXT N_( \
126 "Output video height." )
127 #define RATIO_TEXT N_("Sample aspect ratio")
128 #define RATIO_LONGTEXT N_( \
129 "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
131 #define VFILTER_TEXT N_("Video filter")
132 #define VFILTER_LONGTEXT N_( \
133 "Video filters will be applied to the video stream." );
135 #define CHROMA_TEXT N_("Image chroma")
136 #define CHROMA_LONGTEXT N_( \
137 "Force the use of a specific chroma. Use YUVA if you're planning " \
138 "to use the Alphamask or Bluescreen video filter." );
140 #define CFG_PREFIX "sout-mosaic-bridge-"
143 set_shortname( _( "Mosaic bridge" ) );
144 set_description(_("Mosaic bridge stream output") );
145 set_capability( "sout stream", 0 );
146 add_shortcut( "mosaic-bridge" );
148 add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
150 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
151 WIDTH_LONGTEXT, VLC_TRUE );
152 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
153 HEIGHT_LONGTEXT, VLC_TRUE );
154 add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
155 RATIO_LONGTEXT, VLC_FALSE );
156 add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
159 add_module_list( CFG_PREFIX "vfilter", "video filter2",
160 NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );
162 set_callbacks( Open, Close );
165 static const char *ppsz_sout_options[] = {
166 "id", "width", "height", "sar", "vfilter", "chroma", NULL
169 /*****************************************************************************
171 *****************************************************************************/
172 static int Open( vlc_object_t *p_this )
174 sout_stream_t *p_stream = (sout_stream_t *)p_this;
175 sout_stream_sys_t *p_sys;
176 vlc_object_t *p_libvlc = p_this->p_libvlc;
179 config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
182 p_sys = malloc( sizeof( sout_stream_sys_t ) );
188 p_stream->p_sys = p_sys;
189 p_sys->b_inited = VLC_FALSE;
191 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
192 var_Get( p_libvlc, "mosaic-lock", &val );
193 p_sys->p_lock = val.p_address;
195 var_Get( p_stream, CFG_PREFIX "id", &val );
196 p_sys->psz_id = val.psz_string;
199 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
200 var_AddCallback( p_stream, CFG_PREFIX "height", MosaicBridgeCallback,
204 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
205 var_AddCallback( p_stream, CFG_PREFIX "width", MosaicBridgeCallback,
208 var_Get( p_stream, CFG_PREFIX "sar", &val );
209 if ( val.psz_string )
211 char *psz_parser = strchr( val.psz_string, ':' );
215 *psz_parser++ = '\0';
216 p_sys->i_sar_num = atoi( val.psz_string );
217 p_sys->i_sar_den = atoi( psz_parser );
218 vlc_ureduce( &p_sys->i_sar_num, &p_sys->i_sar_den,
219 p_sys->i_sar_num, p_sys->i_sar_den, 0 );
223 msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
224 p_sys->i_sar_num = p_sys->i_sar_den = 1;
227 free( val.psz_string );
231 p_sys->i_sar_num = p_sys->i_sar_den = 1;
235 val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
236 if( val.psz_string && strlen( val.psz_string ) >= 4 )
238 memcpy( &p_sys->i_chroma, val.psz_string, 4 );
239 msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
242 p_stream->pf_add = Add;
243 p_stream->pf_del = Del;
244 p_stream->pf_send = Send;
246 p_stream->p_sout->i_out_pace_nocontrol++;
251 /*****************************************************************************
253 *****************************************************************************/
254 static void Close( vlc_object_t * p_this )
256 sout_stream_t *p_stream = (sout_stream_t*)p_this;
257 sout_stream_sys_t *p_sys = p_stream->p_sys;
259 p_stream->p_sout->i_out_pace_nocontrol--;
262 free( p_sys->psz_id );
267 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
269 sout_stream_sys_t *p_sys = p_stream->p_sys;
272 char *psz_chain, *psz_parser;
275 if ( p_sys->b_inited )
280 /* Create decoder object */
281 p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
282 vlc_object_attach( p_sys->p_decoder, p_stream );
283 p_sys->p_decoder->p_module = NULL;
284 p_sys->p_decoder->fmt_in = *p_fmt;
285 p_sys->p_decoder->b_pace_control = VLC_FALSE;
286 p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
287 p_sys->p_decoder->fmt_out.i_extra = 0;
288 p_sys->p_decoder->fmt_out.p_extra = 0;
289 p_sys->p_decoder->pf_decode_video = 0;
290 p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
291 p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
292 p_sys->p_decoder->pf_picture_link = video_link_picture_decoder;
293 p_sys->p_decoder->pf_picture_unlink = video_unlink_picture_decoder;
294 p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
295 for( i = 0; i < PICTURE_RING_SIZE; i++ )
296 p_sys->p_decoder->p_owner->pp_pics[i] = 0;
297 p_sys->p_decoder->p_owner->video = p_fmt->video;
298 //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
300 p_sys->p_decoder->p_module =
301 module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
303 if( !p_sys->p_decoder->p_module )
305 msg_Err( p_stream, "cannot find decoder" );
306 vlc_object_detach( p_sys->p_decoder );
307 vlc_object_destroy( p_sys->p_decoder );
311 p_sys->b_inited = VLC_TRUE;
312 vlc_mutex_lock( p_sys->p_lock );
314 p_bridge = GetBridge( p_stream );
315 if ( p_bridge == NULL )
317 vlc_object_t *p_libvlc = p_stream->p_libvlc;
320 p_bridge = malloc( sizeof( bridge_t ) );
322 var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );
323 val.p_address = p_bridge;
324 var_Set( p_libvlc, "mosaic-struct", val );
326 p_bridge->i_es_num = 0;
327 p_bridge->pp_es = NULL;
330 for ( i = 0; i < p_bridge->i_es_num; i++ )
332 if ( p_bridge->pp_es[i]->b_empty )
336 if ( i == p_bridge->i_es_num )
338 p_bridge->pp_es = realloc( p_bridge->pp_es,
339 (p_bridge->i_es_num + 1)
340 * sizeof(bridged_es_t *) );
341 p_bridge->i_es_num++;
342 p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
345 p_sys->p_es = p_es = p_bridge->pp_es[i];
347 //p_es->fmt = *p_fmt;
348 p_es->psz_id = p_sys->psz_id;
349 p_es->p_picture = NULL;
350 p_es->pp_last = &p_es->p_picture;
351 p_es->b_empty = VLC_FALSE;
353 vlc_mutex_unlock( p_sys->p_lock );
355 if ( p_sys->i_height || p_sys->i_width )
357 p_sys->p_image = image_HandlerCreate( p_stream );
361 p_sys->p_image = NULL;
364 msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
366 /* Create user specified video filters */
367 psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
368 msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
370 config_chain_t *p_cfg;
371 for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
373 msg_Dbg( p_stream, " - %s\n", p_cfg->psz_value );
376 p_sys->i_vfilters = 0;
377 p_sys->pp_vfilters = NULL;
378 psz_parser = psz_chain;
379 while( psz_parser && *psz_parser )
381 config_chain_t *p_cfg;
383 filter_t **pp_vfilter;
384 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
387 (filter_t **)realloc( p_sys->pp_vfilters,
388 p_sys->i_vfilters * sizeof(filter_t *) );
389 pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
390 *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
391 vlc_object_attach( *pp_vfilter, p_stream );
392 (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
393 (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
394 (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
395 if( p_sys->i_chroma )
396 (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
397 (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
398 (*pp_vfilter)->p_cfg = p_cfg;
399 (*pp_vfilter)->p_module =
400 module_Need( *pp_vfilter, "video filter2", psz_name, VLC_TRUE );
401 if( (*pp_vfilter)->p_module )
404 (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
405 p_sys->p_decoder->p_owner;
406 msg_Err( p_stream, "Added video filter %s to the chain",
411 /* Crap ... we didn't find a filter */
413 "no video filter matching name \"%s\" found",
415 vlc_object_detach( *pp_vfilter );
416 vlc_object_destroy( *pp_vfilter );
422 return (sout_stream_id_t *)p_sys;
425 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
427 sout_stream_sys_t *p_sys = p_stream->p_sys;
430 vlc_bool_t b_last_es = VLC_TRUE;
431 filter_t **pp_vfilter, **pp_end;
434 if ( !p_sys->b_inited )
439 if ( p_sys->p_decoder != NULL )
441 picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
443 if( p_sys->p_decoder->p_module )
444 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
445 vlc_object_detach( p_sys->p_decoder );
446 vlc_object_destroy( p_sys->p_decoder );
448 for( i = 0; i < PICTURE_RING_SIZE; i++ )
450 if ( pp_ring[i] != NULL )
452 if ( pp_ring[i]->p_data_orig != NULL )
453 free( pp_ring[i]->p_data_orig );
454 free( pp_ring[i]->p_sys );
460 /* Destroy user specified video filters */
461 pp_vfilter = p_sys->pp_vfilters;
462 pp_end = pp_vfilter + p_sys->i_vfilters;
463 for( ; pp_vfilter < pp_end; pp_vfilter++ )
465 vlc_object_detach( *pp_vfilter );
466 if( (*pp_vfilter)->p_module )
467 module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
468 vlc_object_destroy( *pp_vfilter );
470 free( p_sys->pp_vfilters );
472 vlc_mutex_lock( p_sys->p_lock );
474 p_bridge = GetBridge( p_stream );
477 p_es->b_empty = VLC_TRUE;
478 while ( p_es->p_picture )
480 picture_t *p_next = p_es->p_picture->p_next;
481 p_es->p_picture->pf_release( p_es->p_picture );
482 p_es->p_picture = p_next;
485 for ( i = 0; i < p_bridge->i_es_num; i++ )
487 if ( !p_bridge->pp_es[i]->b_empty )
489 b_last_es = VLC_FALSE;
496 vlc_object_t *p_libvlc = p_stream->p_libvlc;
497 for ( i = 0; i < p_bridge->i_es_num; i++ )
498 free( p_bridge->pp_es[i] );
499 free( p_bridge->pp_es );
501 var_Destroy( p_libvlc, "mosaic-struct" );
504 vlc_mutex_unlock( p_sys->p_lock );
506 if ( p_sys->p_image )
508 image_HandlerDelete( p_sys->p_image );
511 p_sys->b_inited = VLC_FALSE;
516 /*****************************************************************************
517 * PushPicture : push a picture in the mosaic-struct structure
518 *****************************************************************************/
519 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
521 sout_stream_sys_t *p_sys = p_stream->p_sys;
522 bridged_es_t *p_es = p_sys->p_es;
524 vlc_mutex_lock( p_sys->p_lock );
526 *p_es->pp_last = p_picture;
527 p_picture->p_next = NULL;
528 p_es->pp_last = &p_picture->p_next;
530 vlc_mutex_unlock( p_sys->p_lock );
533 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
536 sout_stream_sys_t *p_sys = p_stream->p_sys;
539 if ( (sout_stream_sys_t *)id != p_sys )
541 block_ChainRelease( p_buffer );
545 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
548 picture_t *p_new_pic;
550 if( p_sys->i_height || p_sys->i_width )
552 video_format_t fmt_out, fmt_in;
554 memset( &fmt_in, 0, sizeof(video_format_t) );
555 memset( &fmt_out, 0, sizeof(video_format_t) );
556 fmt_in = p_sys->p_decoder->fmt_out.video;
559 if( p_sys->i_chroma )
560 fmt_out.i_chroma = p_sys->i_chroma;
562 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
564 if ( !p_sys->i_height )
566 fmt_out.i_width = p_sys->i_width;
567 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
568 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
571 else if ( !p_sys->i_width )
573 fmt_out.i_height = p_sys->i_height;
574 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
575 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
580 fmt_out.i_width = p_sys->i_width;
581 fmt_out.i_height = p_sys->i_height;
583 fmt_out.i_visible_width = fmt_out.i_width;
584 fmt_out.i_visible_height = fmt_out.i_height;
586 p_new_pic = image_Convert( p_sys->p_image,
587 p_pic, &fmt_in, &fmt_out );
588 if ( p_new_pic == NULL )
590 msg_Err( p_stream, "image conversion failed" );
596 /* TODO: chroma conversion if needed */
598 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
599 if( p_new_pic == NULL )
601 msg_Err( p_stream, "image conversion failed" );
605 if( vout_AllocatePicture(
606 p_stream, p_new_pic, p_pic->format.i_chroma,
607 p_pic->format.i_width, p_pic->format.i_height,
608 p_sys->p_decoder->fmt_out.video.i_aspect )
612 msg_Err( p_stream, "image allocation failed" );
616 vout_CopyPicture( p_stream, p_new_pic, p_pic );
619 p_new_pic->i_refcount = 1;
620 p_new_pic->i_status = DESTROYED_PICTURE;
621 p_new_pic->i_type = DIRECT_PICTURE;
622 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
623 p_new_pic->pf_release = ReleasePicture;
624 p_new_pic->date = p_pic->date;
625 p_pic->pf_release( p_pic );
627 if( p_sys->pp_vfilters )
629 /* Apply user specified video filters */
630 filter_t **pp_vfilter = p_sys->pp_vfilters;
631 filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
632 for( ; pp_vfilter < pp_end; pp_vfilter++ )
634 (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
635 (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
636 (*pp_vfilter)->fmt_in.video = p_new_pic->format;
637 (*pp_vfilter)->fmt_out.video = p_new_pic->format;
638 p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
642 msg_Err( p_stream, "video filter failed" );
646 if( !p_new_pic ) continue;
649 PushPicture( p_stream, p_new_pic );
657 vlc_object_t *p_owner;
661 static void video_release_buffer_decoder( picture_t *p_pic )
663 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
665 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
667 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
670 static void video_release_buffer_filter( picture_t *p_pic )
672 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
674 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
676 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
679 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
681 return video_new_buffer( VLC_OBJECT( p_dec ),
682 (decoder_owner_sys_t *)p_dec->p_owner,
684 video_release_buffer_decoder );
687 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
689 return video_new_buffer( VLC_OBJECT( p_filter ),
690 (decoder_owner_sys_t *)p_filter->p_owner,
692 video_release_buffer_filter );
695 static picture_t *video_new_buffer( vlc_object_t *p_this,
696 decoder_owner_sys_t *p_sys,
697 es_format_t *fmt_out,
698 void ( *pf_release )( picture_t * ) )
700 picture_t **pp_ring = p_sys->pp_pics;
704 if( fmt_out->video.i_width != p_sys->video.i_width ||
705 fmt_out->video.i_height != p_sys->video.i_height ||
706 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
707 fmt_out->video.i_aspect != p_sys->video.i_aspect )
709 if( !fmt_out->video.i_sar_num ||
710 !fmt_out->video.i_sar_den )
712 fmt_out->video.i_sar_num =
713 fmt_out->video.i_aspect * fmt_out->video.i_height;
715 fmt_out->video.i_sar_den =
716 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
719 vlc_ureduce( &fmt_out->video.i_sar_num,
720 &fmt_out->video.i_sar_den,
721 fmt_out->video.i_sar_num,
722 fmt_out->video.i_sar_den, 0 );
724 if( !fmt_out->video.i_visible_width ||
725 !fmt_out->video.i_visible_height )
727 fmt_out->video.i_visible_width = fmt_out->video.i_width;
728 fmt_out->video.i_visible_height = fmt_out->video.i_height;
731 fmt_out->video.i_chroma = fmt_out->i_codec;
732 p_sys->video = fmt_out->video;
734 for( i = 0; i < PICTURE_RING_SIZE; i++ )
736 if ( pp_ring[i] != NULL )
738 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
740 if ( pp_ring[i]->p_data_orig != NULL )
741 free( pp_ring[i]->p_data_orig );
742 free( pp_ring[i]->p_sys );
747 pp_ring[i]->p_sys->b_dead = VLC_TRUE;
754 /* Find an empty space in the picture ring buffer */
755 for( i = 0; i < PICTURE_RING_SIZE; i++ )
757 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
759 pp_ring[i]->i_status = RESERVED_PICTURE;
763 for( i = 0; i < PICTURE_RING_SIZE; i++ )
765 if( pp_ring[i] == NULL ) break;
768 if( i == PICTURE_RING_SIZE )
770 msg_Err( p_this, "decoder/filter is leaking pictures, "
771 "resetting its ring buffer" );
773 for( i = 0; i < PICTURE_RING_SIZE; i++ )
775 pp_ring[i]->pf_release( pp_ring[i] );
781 p_pic = malloc( sizeof(picture_t) );
782 fmt_out->video.i_chroma = fmt_out->i_codec;
783 vout_AllocatePicture( p_this, p_pic,
784 fmt_out->video.i_chroma,
785 fmt_out->video.i_width,
786 fmt_out->video.i_height,
787 fmt_out->video.i_aspect );
789 if( !p_pic->i_planes )
795 p_pic->pf_release = pf_release;
796 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
797 p_pic->p_sys->p_owner = p_this;
798 p_pic->p_sys->b_dead = VLC_FALSE;
799 p_pic->i_status = RESERVED_PICTURE;
806 inline static void video_del_buffer_decoder( decoder_t *p_this,
809 video_del_buffer( VLC_OBJECT( p_this ), p_pic );
812 inline static void video_del_buffer_filter( filter_t *p_this,
815 video_del_buffer( VLC_OBJECT( p_this ), p_pic );
818 static void video_del_buffer( vlc_object_t *p_this, picture_t *p_pic )
820 p_pic->i_refcount = 0;
821 p_pic->i_status = DESTROYED_PICTURE;
822 if ( p_pic->p_sys->b_dead )
824 if ( p_pic->p_data_orig != NULL )
825 free( p_pic->p_data_orig );
826 free( p_pic->p_sys );
831 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
836 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
838 video_release_buffer_decoder( p_pic );
842 /**********************************************************************
843 * Callback to update (some) params on the fly
844 **********************************************************************/
845 static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
846 vlc_value_t oldval, vlc_value_t newval,
849 sout_stream_t *p_stream = (sout_stream_t *)p_data;
850 sout_stream_sys_t *p_sys = p_stream->p_sys;
851 int i_ret = VLC_SUCCESS;
853 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
854 if( VAR_IS( "height" ) )
856 /* We create the handler before updating the value in p_sys
857 * so we don't have to worry about locking */
858 if( !p_sys->p_image && newval.i_int )
859 p_sys->p_image = image_HandlerCreate( p_stream );
860 p_sys->i_height = newval.i_int;
862 else if( VAR_IS( "width" ) )
864 /* We create the handler before updating the value in p_sys
865 * so we don't have to worry about locking */
866 if( !p_sys->p_image && newval.i_int )
867 p_sys->p_image = image_HandlerCreate( p_stream );
868 p_sys->i_width = newval.i_int;