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 */
29 #include <stdlib.h> /* free() */
30 #include <string.h> /* strerror() */
34 #include <vlc_block.h>
35 #include <vlc_codec.h>
37 #include <vlc_image.h>
38 #include <vlc_filter.h>
40 #include "../video_filter/mosaic.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 struct sout_stream_sys_t
51 image_handler_t *p_image; /* filter for resizing */
52 int i_height, i_width;
53 unsigned int i_sar_num, i_sar_den;
57 int i_chroma; /* force image format chroma */
59 filter_t **pp_vfilters;
63 #define PICTURE_RING_SIZE 4
64 struct decoder_owner_sys_t
66 picture_t *pp_pics[PICTURE_RING_SIZE];
68 /* Current format in use by the output */
72 typedef void (* pf_release_t)( picture_t * );
73 static void ReleasePicture( picture_t *p_pic )
77 if ( p_pic->i_refcount <= 0 )
79 if ( p_pic->p_sys != NULL )
81 pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
87 if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
88 if( p_pic ) free( p_pic );
93 /*****************************************************************************
95 *****************************************************************************/
96 static int Open ( vlc_object_t * );
97 static void Close ( vlc_object_t * );
98 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
99 static int Del ( sout_stream_t *, sout_stream_id_t * );
100 static int Send( sout_stream_t *, sout_stream_id_t *, block_t * );
102 inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
103 inline static void video_del_buffer_filter( filter_t *, picture_t * );
104 static void video_del_buffer( vlc_object_t *, picture_t * );
106 inline static picture_t *video_new_buffer_decoder( decoder_t * );
107 inline static picture_t *video_new_buffer_filter( filter_t * );
108 static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
109 es_format_t *, void (*)( picture_t * ) );
111 static void video_link_picture_decoder( decoder_t *, picture_t * );
112 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
113 static int MosaicBridgeCallback( vlc_object_t *, char const *,
114 vlc_value_t, vlc_value_t, void * );
116 /*****************************************************************************
118 *****************************************************************************/
119 #define ID_TEXT N_("ID")
120 #define ID_LONGTEXT N_( \
121 "Specify an identifier string for this subpicture" )
123 #define WIDTH_TEXT N_("Video width")
124 #define WIDTH_LONGTEXT N_( \
125 "Output video width." )
126 #define HEIGHT_TEXT N_("Video height")
127 #define HEIGHT_LONGTEXT N_( \
128 "Output video height." )
129 #define RATIO_TEXT N_("Sample aspect ratio")
130 #define RATIO_LONGTEXT N_( \
131 "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
133 #define VFILTER_TEXT N_("Video filter")
134 #define VFILTER_LONGTEXT N_( \
135 "Video filters will be applied to the video stream." );
137 #define CHROMA_TEXT N_("Image chroma")
138 #define CHROMA_LONGTEXT N_( \
139 "Force the use of a specific chroma. Use YUVA if you're planning " \
140 "to use the Alphamask or Bluescreen video filter." );
142 #define CFG_PREFIX "sout-mosaic-bridge-"
145 set_shortname( _( "Mosaic bridge" ) );
146 set_description(_("Mosaic bridge stream output") );
147 set_capability( "sout stream", 0 );
148 add_shortcut( "mosaic-bridge" );
150 add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
152 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
153 WIDTH_LONGTEXT, VLC_TRUE );
154 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
155 HEIGHT_LONGTEXT, VLC_TRUE );
156 add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
157 RATIO_LONGTEXT, VLC_FALSE );
158 add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
161 add_module_list( CFG_PREFIX "vfilter", "video filter2",
162 NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );
164 set_callbacks( Open, Close );
167 static const char *ppsz_sout_options[] = {
168 "id", "width", "height", "sar", "vfilter", "chroma", NULL
171 /*****************************************************************************
173 *****************************************************************************/
174 static int Open( vlc_object_t *p_this )
176 sout_stream_t *p_stream = (sout_stream_t *)p_this;
177 sout_stream_sys_t *p_sys;
178 vlc_object_t *p_libvlc = p_this->p_libvlc;
181 config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
184 p_sys = malloc( sizeof( sout_stream_sys_t ) );
190 p_stream->p_sys = p_sys;
191 p_sys->b_inited = VLC_FALSE;
193 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
194 var_Get( p_libvlc, "mosaic-lock", &val );
195 p_sys->p_lock = val.p_address;
197 var_Get( p_stream, CFG_PREFIX "id", &val );
198 p_sys->psz_id = val.psz_string;
201 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
202 var_AddCallback( p_stream, CFG_PREFIX "height", MosaicBridgeCallback,
206 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
207 var_AddCallback( p_stream, CFG_PREFIX "width", MosaicBridgeCallback,
210 var_Get( p_stream, CFG_PREFIX "sar", &val );
211 if ( val.psz_string )
213 char *psz_parser = strchr( val.psz_string, ':' );
217 *psz_parser++ = '\0';
218 p_sys->i_sar_num = atoi( val.psz_string );
219 p_sys->i_sar_den = atoi( psz_parser );
220 vlc_ureduce( &p_sys->i_sar_num, &p_sys->i_sar_den,
221 p_sys->i_sar_num, p_sys->i_sar_den, 0 );
225 msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
226 p_sys->i_sar_num = p_sys->i_sar_den = 1;
229 free( val.psz_string );
233 p_sys->i_sar_num = p_sys->i_sar_den = 1;
237 val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
238 if( val.psz_string && strlen( val.psz_string ) >= 4 )
240 memcpy( &p_sys->i_chroma, val.psz_string, 4 );
241 msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
244 p_stream->pf_add = Add;
245 p_stream->pf_del = Del;
246 p_stream->pf_send = Send;
248 p_stream->p_sout->i_out_pace_nocontrol++;
253 /*****************************************************************************
255 *****************************************************************************/
256 static void Close( vlc_object_t * p_this )
258 sout_stream_t *p_stream = (sout_stream_t*)p_this;
259 sout_stream_sys_t *p_sys = p_stream->p_sys;
261 p_stream->p_sout->i_out_pace_nocontrol--;
264 free( p_sys->psz_id );
269 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
271 sout_stream_sys_t *p_sys = p_stream->p_sys;
274 char *psz_chain, *psz_parser;
277 if ( p_sys->b_inited )
282 /* Create decoder object */
283 p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
284 vlc_object_attach( p_sys->p_decoder, p_stream );
285 p_sys->p_decoder->p_module = NULL;
286 p_sys->p_decoder->fmt_in = *p_fmt;
287 p_sys->p_decoder->b_pace_control = VLC_FALSE;
288 p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
289 p_sys->p_decoder->fmt_out.i_extra = 0;
290 p_sys->p_decoder->fmt_out.p_extra = 0;
291 p_sys->p_decoder->pf_decode_video = 0;
292 p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
293 p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
294 p_sys->p_decoder->pf_picture_link = video_link_picture_decoder;
295 p_sys->p_decoder->pf_picture_unlink = video_unlink_picture_decoder;
296 p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
297 for( i = 0; i < PICTURE_RING_SIZE; i++ )
298 p_sys->p_decoder->p_owner->pp_pics[i] = 0;
299 p_sys->p_decoder->p_owner->video = p_fmt->video;
300 //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
302 p_sys->p_decoder->p_module =
303 module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
305 if( !p_sys->p_decoder->p_module )
307 msg_Err( p_stream, "cannot find decoder" );
308 vlc_object_detach( p_sys->p_decoder );
309 vlc_object_destroy( p_sys->p_decoder );
313 p_sys->b_inited = VLC_TRUE;
314 vlc_mutex_lock( p_sys->p_lock );
316 p_bridge = GetBridge( p_stream );
317 if ( p_bridge == NULL )
319 vlc_object_t *p_libvlc = p_stream->p_libvlc;
322 p_bridge = malloc( sizeof( bridge_t ) );
324 var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );
325 val.p_address = p_bridge;
326 var_Set( p_libvlc, "mosaic-struct", val );
328 p_bridge->i_es_num = 0;
329 p_bridge->pp_es = NULL;
332 for ( i = 0; i < p_bridge->i_es_num; i++ )
334 if ( p_bridge->pp_es[i]->b_empty )
338 if ( i == p_bridge->i_es_num )
340 p_bridge->pp_es = realloc( p_bridge->pp_es,
341 (p_bridge->i_es_num + 1)
342 * sizeof(bridged_es_t *) );
343 p_bridge->i_es_num++;
344 p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
347 p_sys->p_es = p_es = p_bridge->pp_es[i];
349 //p_es->fmt = *p_fmt;
350 p_es->psz_id = p_sys->psz_id;
351 p_es->p_picture = NULL;
352 p_es->pp_last = &p_es->p_picture;
353 p_es->b_empty = VLC_FALSE;
355 vlc_mutex_unlock( p_sys->p_lock );
357 if ( p_sys->i_height || p_sys->i_width )
359 p_sys->p_image = image_HandlerCreate( p_stream );
363 p_sys->p_image = NULL;
366 msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
368 /* Create user specified video filters */
369 psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
370 msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
372 config_chain_t *p_cfg;
373 for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
375 msg_Dbg( p_stream, " - %s\n", p_cfg->psz_value );
378 p_sys->i_vfilters = 0;
379 p_sys->pp_vfilters = NULL;
380 psz_parser = psz_chain;
381 while( psz_parser && *psz_parser )
383 config_chain_t *p_cfg;
385 filter_t **pp_vfilter;
386 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
389 (filter_t **)realloc( p_sys->pp_vfilters,
390 p_sys->i_vfilters * sizeof(filter_t *) );
391 pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
392 *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
393 vlc_object_attach( *pp_vfilter, p_stream );
394 (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
395 (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
396 (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
397 if( p_sys->i_chroma )
398 (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
399 (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
400 (*pp_vfilter)->p_cfg = p_cfg;
401 (*pp_vfilter)->p_module =
402 module_Need( *pp_vfilter, "video filter2", psz_name, VLC_TRUE );
403 if( (*pp_vfilter)->p_module )
406 (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
407 p_sys->p_decoder->p_owner;
408 msg_Err( p_stream, "Added video filter %s to the chain",
413 /* Crap ... we didn't find a filter */
415 "no video filter matching name \"%s\" found",
417 vlc_object_detach( *pp_vfilter );
418 vlc_object_destroy( *pp_vfilter );
424 return (sout_stream_id_t *)p_sys;
427 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
429 sout_stream_sys_t *p_sys = p_stream->p_sys;
432 vlc_bool_t b_last_es = VLC_TRUE;
433 filter_t **pp_vfilter, **pp_end;
436 if ( !p_sys->b_inited )
441 if ( p_sys->p_decoder != NULL )
443 picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
445 if( p_sys->p_decoder->p_module )
446 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
447 vlc_object_detach( p_sys->p_decoder );
448 vlc_object_destroy( p_sys->p_decoder );
450 for( i = 0; i < PICTURE_RING_SIZE; i++ )
452 if ( pp_ring[i] != NULL )
454 if ( pp_ring[i]->p_data_orig != NULL )
455 free( pp_ring[i]->p_data_orig );
456 free( pp_ring[i]->p_sys );
462 /* Destroy user specified video filters */
463 pp_vfilter = p_sys->pp_vfilters;
464 pp_end = pp_vfilter + p_sys->i_vfilters;
465 for( ; pp_vfilter < pp_end; pp_vfilter++ )
467 vlc_object_detach( *pp_vfilter );
468 if( (*pp_vfilter)->p_module )
469 module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
470 vlc_object_destroy( *pp_vfilter );
472 free( p_sys->pp_vfilters );
474 vlc_mutex_lock( p_sys->p_lock );
476 p_bridge = GetBridge( p_stream );
479 p_es->b_empty = VLC_TRUE;
480 while ( p_es->p_picture )
482 picture_t *p_next = p_es->p_picture->p_next;
483 p_es->p_picture->pf_release( p_es->p_picture );
484 p_es->p_picture = p_next;
487 for ( i = 0; i < p_bridge->i_es_num; i++ )
489 if ( !p_bridge->pp_es[i]->b_empty )
491 b_last_es = VLC_FALSE;
498 vlc_object_t *p_libvlc = p_stream->p_libvlc;
499 for ( i = 0; i < p_bridge->i_es_num; i++ )
500 free( p_bridge->pp_es[i] );
501 free( p_bridge->pp_es );
503 var_Destroy( p_libvlc, "mosaic-struct" );
506 vlc_mutex_unlock( p_sys->p_lock );
508 if ( p_sys->p_image )
510 image_HandlerDelete( p_sys->p_image );
513 p_sys->b_inited = VLC_FALSE;
518 /*****************************************************************************
519 * PushPicture : push a picture in the mosaic-struct structure
520 *****************************************************************************/
521 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
523 sout_stream_sys_t *p_sys = p_stream->p_sys;
524 bridged_es_t *p_es = p_sys->p_es;
526 vlc_mutex_lock( p_sys->p_lock );
528 *p_es->pp_last = p_picture;
529 p_picture->p_next = NULL;
530 p_es->pp_last = &p_picture->p_next;
532 vlc_mutex_unlock( p_sys->p_lock );
535 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
538 sout_stream_sys_t *p_sys = p_stream->p_sys;
541 if ( (sout_stream_sys_t *)id != p_sys )
543 block_ChainRelease( p_buffer );
547 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
550 picture_t *p_new_pic;
552 if( p_sys->i_height || p_sys->i_width )
554 video_format_t fmt_out, fmt_in;
556 memset( &fmt_in, 0, sizeof(video_format_t) );
557 memset( &fmt_out, 0, sizeof(video_format_t) );
558 fmt_in = p_sys->p_decoder->fmt_out.video;
561 if( p_sys->i_chroma )
562 fmt_out.i_chroma = p_sys->i_chroma;
564 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
566 if ( !p_sys->i_height )
568 fmt_out.i_width = p_sys->i_width;
569 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
570 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
573 else if ( !p_sys->i_width )
575 fmt_out.i_height = p_sys->i_height;
576 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
577 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
582 fmt_out.i_width = p_sys->i_width;
583 fmt_out.i_height = p_sys->i_height;
585 fmt_out.i_visible_width = fmt_out.i_width;
586 fmt_out.i_visible_height = fmt_out.i_height;
588 p_new_pic = image_Convert( p_sys->p_image,
589 p_pic, &fmt_in, &fmt_out );
590 if ( p_new_pic == NULL )
592 msg_Err( p_stream, "image conversion failed" );
598 /* TODO: chroma conversion if needed */
600 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
601 if( p_new_pic == NULL )
603 msg_Err( p_stream, "image conversion failed" );
607 if( vout_AllocatePicture(
608 p_stream, p_new_pic, p_pic->format.i_chroma,
609 p_pic->format.i_width, p_pic->format.i_height,
610 p_sys->p_decoder->fmt_out.video.i_aspect )
614 msg_Err( p_stream, "image allocation failed" );
618 vout_CopyPicture( p_stream, p_new_pic, p_pic );
621 p_new_pic->i_refcount = 1;
622 p_new_pic->i_status = DESTROYED_PICTURE;
623 p_new_pic->i_type = DIRECT_PICTURE;
624 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
625 p_new_pic->pf_release = ReleasePicture;
626 p_new_pic->date = p_pic->date;
627 p_pic->pf_release( p_pic );
629 if( p_sys->pp_vfilters )
631 /* Apply user specified video filters */
632 filter_t **pp_vfilter = p_sys->pp_vfilters;
633 filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
634 for( ; pp_vfilter < pp_end; pp_vfilter++ )
636 (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
637 (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
638 (*pp_vfilter)->fmt_in.video = p_new_pic->format;
639 (*pp_vfilter)->fmt_out.video = p_new_pic->format;
640 p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
644 msg_Err( p_stream, "video filter failed" );
648 if( !p_new_pic ) continue;
651 PushPicture( p_stream, p_new_pic );
659 vlc_object_t *p_owner;
663 static void video_release_buffer_decoder( picture_t *p_pic )
665 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
667 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
669 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
672 static void video_release_buffer_filter( picture_t *p_pic )
674 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
676 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
678 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
681 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
683 return video_new_buffer( VLC_OBJECT( p_dec ),
684 (decoder_owner_sys_t *)p_dec->p_owner,
686 video_release_buffer_decoder );
689 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
691 return video_new_buffer( VLC_OBJECT( p_filter ),
692 (decoder_owner_sys_t *)p_filter->p_owner,
694 video_release_buffer_filter );
697 static picture_t *video_new_buffer( vlc_object_t *p_this,
698 decoder_owner_sys_t *p_sys,
699 es_format_t *fmt_out,
700 void ( *pf_release )( picture_t * ) )
702 picture_t **pp_ring = p_sys->pp_pics;
706 if( fmt_out->video.i_width != p_sys->video.i_width ||
707 fmt_out->video.i_height != p_sys->video.i_height ||
708 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
709 fmt_out->video.i_aspect != p_sys->video.i_aspect )
711 if( !fmt_out->video.i_sar_num ||
712 !fmt_out->video.i_sar_den )
714 fmt_out->video.i_sar_num =
715 fmt_out->video.i_aspect * fmt_out->video.i_height;
717 fmt_out->video.i_sar_den =
718 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
721 vlc_ureduce( &fmt_out->video.i_sar_num,
722 &fmt_out->video.i_sar_den,
723 fmt_out->video.i_sar_num,
724 fmt_out->video.i_sar_den, 0 );
726 if( !fmt_out->video.i_visible_width ||
727 !fmt_out->video.i_visible_height )
729 fmt_out->video.i_visible_width = fmt_out->video.i_width;
730 fmt_out->video.i_visible_height = fmt_out->video.i_height;
733 fmt_out->video.i_chroma = fmt_out->i_codec;
734 p_sys->video = fmt_out->video;
736 for( i = 0; i < PICTURE_RING_SIZE; i++ )
738 if ( pp_ring[i] != NULL )
740 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
742 if ( pp_ring[i]->p_data_orig != NULL )
743 free( pp_ring[i]->p_data_orig );
744 free( pp_ring[i]->p_sys );
749 pp_ring[i]->p_sys->b_dead = VLC_TRUE;
756 /* Find an empty space in the picture ring buffer */
757 for( i = 0; i < PICTURE_RING_SIZE; i++ )
759 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
761 pp_ring[i]->i_status = RESERVED_PICTURE;
765 for( i = 0; i < PICTURE_RING_SIZE; i++ )
767 if( pp_ring[i] == NULL ) break;
770 if( i == PICTURE_RING_SIZE )
772 msg_Err( p_this, "decoder/filter is leaking pictures, "
773 "resetting its ring buffer" );
775 for( i = 0; i < PICTURE_RING_SIZE; i++ )
777 pp_ring[i]->pf_release( pp_ring[i] );
783 p_pic = malloc( sizeof(picture_t) );
784 fmt_out->video.i_chroma = fmt_out->i_codec;
785 vout_AllocatePicture( p_this, p_pic,
786 fmt_out->video.i_chroma,
787 fmt_out->video.i_width,
788 fmt_out->video.i_height,
789 fmt_out->video.i_aspect );
791 if( !p_pic->i_planes )
797 p_pic->pf_release = pf_release;
798 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
799 p_pic->p_sys->p_owner = p_this;
800 p_pic->p_sys->b_dead = VLC_FALSE;
801 p_pic->i_status = RESERVED_PICTURE;
808 inline static void video_del_buffer_decoder( decoder_t *p_this,
811 video_del_buffer( VLC_OBJECT( p_this ), p_pic );
814 inline static void video_del_buffer_filter( filter_t *p_this,
817 video_del_buffer( VLC_OBJECT( p_this ), p_pic );
820 static void video_del_buffer( vlc_object_t *p_this, picture_t *p_pic )
822 p_pic->i_refcount = 0;
823 p_pic->i_status = DESTROYED_PICTURE;
824 if ( p_pic->p_sys->b_dead )
826 if ( p_pic->p_data_orig != NULL )
827 free( p_pic->p_data_orig );
828 free( p_pic->p_sys );
833 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
838 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
840 video_release_buffer_decoder( p_pic );
844 /**********************************************************************
845 * Callback to update (some) params on the fly
846 **********************************************************************/
847 static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
848 vlc_value_t oldval, vlc_value_t newval,
851 sout_stream_t *p_stream = (sout_stream_t *)p_data;
852 sout_stream_sys_t *p_sys = p_stream->p_sys;
853 int i_ret = VLC_SUCCESS;
855 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
856 if( VAR_IS( "height" ) )
858 /* We create the handler before updating the value in p_sys
859 * so we don't have to worry about locking */
860 if( !p_sys->p_image && newval.i_int )
861 p_sys->p_image = image_HandlerCreate( p_stream );
862 p_sys->i_height = newval.i_int;
864 else if( VAR_IS( "width" ) )
866 /* We create the handler before updating the value in p_sys
867 * so we don't have to worry about locking */
868 if( !p_sys->p_image && newval.i_int )
869 p_sys->p_image = image_HandlerCreate( p_stream );
870 p_sys->i_width = newval.i_int;