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 */
36 #include <vlc_block.h>
37 #include <vlc_codec.h>
39 #include <vlc_image.h>
40 #include <vlc_filter.h>
42 #include "../video_filter/mosaic.h"
44 /*****************************************************************************
46 *****************************************************************************/
47 struct sout_stream_sys_t
53 image_handler_t *p_image; /* filter for resizing */
54 int i_height, i_width;
55 unsigned int i_sar_num, i_sar_den;
59 int i_chroma; /* force image format chroma */
61 filter_t **pp_vfilters;
65 #define PICTURE_RING_SIZE 4
66 struct decoder_owner_sys_t
68 picture_t *pp_pics[PICTURE_RING_SIZE];
70 /* Current format in use by the output */
74 typedef void (* pf_release_t)( picture_t * );
75 static void ReleasePicture( picture_t *p_pic )
79 if ( p_pic->i_refcount <= 0 )
81 if ( p_pic->p_sys != NULL )
83 pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
89 if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
90 if( p_pic ) free( p_pic );
95 /*****************************************************************************
97 *****************************************************************************/
98 static int Open ( vlc_object_t * );
99 static void Close ( vlc_object_t * );
100 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
101 static int Del ( sout_stream_t *, sout_stream_id_t * );
102 static int Send( sout_stream_t *, sout_stream_id_t *, block_t * );
104 inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
105 inline static void video_del_buffer_filter( filter_t *, picture_t * );
106 static void video_del_buffer( vlc_object_t *, picture_t * );
108 inline static picture_t *video_new_buffer_decoder( decoder_t * );
109 inline static picture_t *video_new_buffer_filter( filter_t * );
110 static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
111 es_format_t *, void (*)( picture_t * ) );
113 static void video_link_picture_decoder( decoder_t *, picture_t * );
114 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
115 static int MosaicBridgeCallback( vlc_object_t *, char const *,
116 vlc_value_t, vlc_value_t, void * );
118 /*****************************************************************************
120 *****************************************************************************/
121 #define ID_TEXT N_("ID")
122 #define ID_LONGTEXT N_( \
123 "Specify an identifier string for this subpicture" )
125 #define WIDTH_TEXT N_("Video width")
126 #define WIDTH_LONGTEXT N_( \
127 "Output video width." )
128 #define HEIGHT_TEXT N_("Video height")
129 #define HEIGHT_LONGTEXT N_( \
130 "Output video height." )
131 #define RATIO_TEXT N_("Sample aspect ratio")
132 #define RATIO_LONGTEXT N_( \
133 "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
135 #define VFILTER_TEXT N_("Video filter")
136 #define VFILTER_LONGTEXT N_( \
137 "Video filters will be applied to the video stream." )
139 #define CHROMA_TEXT N_("Image chroma")
140 #define CHROMA_LONGTEXT N_( \
141 "Force the use of a specific chroma. Use YUVA if you're planning " \
142 "to use the Alphamask or Bluescreen video filter." )
144 #define CFG_PREFIX "sout-mosaic-bridge-"
147 set_shortname( _( "Mosaic bridge" ) );
148 set_description(_("Mosaic bridge stream output") );
149 set_capability( "sout stream", 0 );
150 add_shortcut( "mosaic-bridge" );
152 add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
154 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
155 WIDTH_LONGTEXT, VLC_TRUE );
156 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
157 HEIGHT_LONGTEXT, VLC_TRUE );
158 add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
159 RATIO_LONGTEXT, VLC_FALSE );
160 add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
163 add_module_list( CFG_PREFIX "vfilter", "video filter2",
164 NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );
166 set_callbacks( Open, Close );
169 static const char *ppsz_sout_options[] = {
170 "id", "width", "height", "sar", "vfilter", "chroma", NULL
173 /*****************************************************************************
175 *****************************************************************************/
176 static int Open( vlc_object_t *p_this )
178 sout_stream_t *p_stream = (sout_stream_t *)p_this;
179 sout_stream_sys_t *p_sys;
180 vlc_object_t *p_libvlc = VLC_OBJECT( p_this->p_libvlc );
183 config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
186 p_sys = malloc( sizeof( sout_stream_sys_t ) );
192 p_stream->p_sys = p_sys;
193 p_sys->b_inited = VLC_FALSE;
195 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
196 var_Get( p_libvlc, "mosaic-lock", &val );
197 p_sys->p_lock = val.p_address;
199 var_Get( p_stream, CFG_PREFIX "id", &val );
200 p_sys->psz_id = val.psz_string;
203 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
204 var_AddCallback( p_stream, CFG_PREFIX "height", MosaicBridgeCallback,
208 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
209 var_AddCallback( p_stream, CFG_PREFIX "width", MosaicBridgeCallback,
212 var_Get( p_stream, CFG_PREFIX "sar", &val );
213 if ( val.psz_string )
215 char *psz_parser = strchr( val.psz_string, ':' );
219 *psz_parser++ = '\0';
220 p_sys->i_sar_num = atoi( val.psz_string );
221 p_sys->i_sar_den = atoi( psz_parser );
222 vlc_ureduce( &p_sys->i_sar_num, &p_sys->i_sar_den,
223 p_sys->i_sar_num, p_sys->i_sar_den, 0 );
227 msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
228 p_sys->i_sar_num = p_sys->i_sar_den = 1;
231 free( val.psz_string );
235 p_sys->i_sar_num = p_sys->i_sar_den = 1;
239 val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
240 if( val.psz_string && strlen( val.psz_string ) >= 4 )
242 memcpy( &p_sys->i_chroma, val.psz_string, 4 );
243 msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
246 p_stream->pf_add = Add;
247 p_stream->pf_del = Del;
248 p_stream->pf_send = Send;
250 p_stream->p_sout->i_out_pace_nocontrol++;
255 /*****************************************************************************
257 *****************************************************************************/
258 static void Close( vlc_object_t * p_this )
260 sout_stream_t *p_stream = (sout_stream_t*)p_this;
261 sout_stream_sys_t *p_sys = p_stream->p_sys;
263 p_stream->p_sout->i_out_pace_nocontrol--;
266 free( p_sys->psz_id );
271 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
273 sout_stream_sys_t *p_sys = p_stream->p_sys;
276 char *psz_chain, *psz_parser;
279 if ( p_sys->b_inited )
284 /* Create decoder object */
285 p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
286 vlc_object_attach( p_sys->p_decoder, p_stream );
287 p_sys->p_decoder->p_module = NULL;
288 p_sys->p_decoder->fmt_in = *p_fmt;
289 p_sys->p_decoder->b_pace_control = VLC_FALSE;
290 p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
291 p_sys->p_decoder->fmt_out.i_extra = 0;
292 p_sys->p_decoder->fmt_out.p_extra = 0;
293 p_sys->p_decoder->pf_decode_video = 0;
294 p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
295 p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
296 p_sys->p_decoder->pf_picture_link = video_link_picture_decoder;
297 p_sys->p_decoder->pf_picture_unlink = video_unlink_picture_decoder;
298 p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
299 for( i = 0; i < PICTURE_RING_SIZE; i++ )
300 p_sys->p_decoder->p_owner->pp_pics[i] = 0;
301 p_sys->p_decoder->p_owner->video = p_fmt->video;
302 //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
304 p_sys->p_decoder->p_module =
305 module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
307 if( !p_sys->p_decoder->p_module )
309 msg_Err( p_stream, "cannot find decoder" );
310 vlc_object_detach( p_sys->p_decoder );
311 vlc_object_destroy( p_sys->p_decoder );
315 p_sys->b_inited = VLC_TRUE;
316 vlc_mutex_lock( p_sys->p_lock );
318 p_bridge = GetBridge( p_stream );
319 if ( p_bridge == NULL )
321 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
324 p_bridge = malloc( sizeof( bridge_t ) );
326 var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );
327 val.p_address = p_bridge;
328 var_Set( p_libvlc, "mosaic-struct", val );
330 p_bridge->i_es_num = 0;
331 p_bridge->pp_es = NULL;
334 for ( i = 0; i < p_bridge->i_es_num; i++ )
336 if ( p_bridge->pp_es[i]->b_empty )
340 if ( i == p_bridge->i_es_num )
342 p_bridge->pp_es = realloc( p_bridge->pp_es,
343 (p_bridge->i_es_num + 1)
344 * sizeof(bridged_es_t *) );
345 p_bridge->i_es_num++;
346 p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
349 p_sys->p_es = p_es = p_bridge->pp_es[i];
351 //p_es->fmt = *p_fmt;
352 p_es->psz_id = p_sys->psz_id;
353 p_es->p_picture = NULL;
354 p_es->pp_last = &p_es->p_picture;
355 p_es->b_empty = VLC_FALSE;
357 vlc_mutex_unlock( p_sys->p_lock );
359 if ( p_sys->i_height || p_sys->i_width )
361 p_sys->p_image = image_HandlerCreate( p_stream );
365 p_sys->p_image = NULL;
368 msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
370 /* Create user specified video filters */
371 psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
372 msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
374 config_chain_t *p_cfg;
375 for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
377 msg_Dbg( p_stream, " - %s\n", p_cfg->psz_value );
380 p_sys->i_vfilters = 0;
381 p_sys->pp_vfilters = NULL;
382 psz_parser = psz_chain;
383 while( psz_parser && *psz_parser )
385 config_chain_t *p_cfg;
387 filter_t **pp_vfilter;
388 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
391 (filter_t **)realloc( p_sys->pp_vfilters,
392 p_sys->i_vfilters * sizeof(filter_t *) );
393 pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
394 *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
395 vlc_object_attach( *pp_vfilter, p_stream );
396 (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
397 (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
398 (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
399 if( p_sys->i_chroma )
400 (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
401 (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
402 (*pp_vfilter)->p_cfg = p_cfg;
403 (*pp_vfilter)->p_module =
404 module_Need( *pp_vfilter, "video filter2", psz_name, VLC_TRUE );
405 if( (*pp_vfilter)->p_module )
408 (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
409 p_sys->p_decoder->p_owner;
410 msg_Err( p_stream, "Added video filter %s to the chain",
415 /* Crap ... we didn't find a filter */
417 "no video filter matching name \"%s\" found",
419 vlc_object_detach( *pp_vfilter );
420 vlc_object_destroy( *pp_vfilter );
426 return (sout_stream_id_t *)p_sys;
429 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
431 sout_stream_sys_t *p_sys = p_stream->p_sys;
434 vlc_bool_t b_last_es = VLC_TRUE;
435 filter_t **pp_vfilter, **pp_end;
438 if ( !p_sys->b_inited )
443 if ( p_sys->p_decoder != NULL )
445 picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
447 if( p_sys->p_decoder->p_module )
448 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
449 vlc_object_detach( p_sys->p_decoder );
450 vlc_object_destroy( p_sys->p_decoder );
452 for( i = 0; i < PICTURE_RING_SIZE; i++ )
454 if ( pp_ring[i] != NULL )
456 if ( pp_ring[i]->p_data_orig != NULL )
457 free( pp_ring[i]->p_data_orig );
458 free( pp_ring[i]->p_sys );
464 /* Destroy user specified video filters */
465 pp_vfilter = p_sys->pp_vfilters;
466 pp_end = pp_vfilter + p_sys->i_vfilters;
467 for( ; pp_vfilter < pp_end; pp_vfilter++ )
469 vlc_object_detach( *pp_vfilter );
470 if( (*pp_vfilter)->p_module )
471 module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
472 vlc_object_destroy( *pp_vfilter );
474 free( p_sys->pp_vfilters );
476 vlc_mutex_lock( p_sys->p_lock );
478 p_bridge = GetBridge( p_stream );
481 p_es->b_empty = VLC_TRUE;
482 while ( p_es->p_picture )
484 picture_t *p_next = p_es->p_picture->p_next;
485 p_es->p_picture->pf_release( p_es->p_picture );
486 p_es->p_picture = p_next;
489 for ( i = 0; i < p_bridge->i_es_num; i++ )
491 if ( !p_bridge->pp_es[i]->b_empty )
493 b_last_es = VLC_FALSE;
500 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
501 for ( i = 0; i < p_bridge->i_es_num; i++ )
502 free( p_bridge->pp_es[i] );
503 free( p_bridge->pp_es );
505 var_Destroy( p_libvlc, "mosaic-struct" );
508 vlc_mutex_unlock( p_sys->p_lock );
510 if ( p_sys->p_image )
512 image_HandlerDelete( p_sys->p_image );
515 p_sys->b_inited = VLC_FALSE;
520 /*****************************************************************************
521 * PushPicture : push a picture in the mosaic-struct structure
522 *****************************************************************************/
523 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
525 sout_stream_sys_t *p_sys = p_stream->p_sys;
526 bridged_es_t *p_es = p_sys->p_es;
528 vlc_mutex_lock( p_sys->p_lock );
530 *p_es->pp_last = p_picture;
531 p_picture->p_next = NULL;
532 p_es->pp_last = &p_picture->p_next;
534 vlc_mutex_unlock( p_sys->p_lock );
537 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
540 sout_stream_sys_t *p_sys = p_stream->p_sys;
543 if ( (sout_stream_sys_t *)id != p_sys )
545 block_ChainRelease( p_buffer );
549 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
552 picture_t *p_new_pic;
554 if( p_sys->i_height || p_sys->i_width )
556 video_format_t fmt_out, fmt_in;
558 memset( &fmt_in, 0, sizeof(video_format_t) );
559 memset( &fmt_out, 0, sizeof(video_format_t) );
560 fmt_in = p_sys->p_decoder->fmt_out.video;
563 if( p_sys->i_chroma )
564 fmt_out.i_chroma = p_sys->i_chroma;
566 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
568 if ( !p_sys->i_height )
570 fmt_out.i_width = p_sys->i_width;
571 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
572 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
575 else if ( !p_sys->i_width )
577 fmt_out.i_height = p_sys->i_height;
578 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
579 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
584 fmt_out.i_width = p_sys->i_width;
585 fmt_out.i_height = p_sys->i_height;
587 fmt_out.i_visible_width = fmt_out.i_width;
588 fmt_out.i_visible_height = fmt_out.i_height;
590 p_new_pic = image_Convert( p_sys->p_image,
591 p_pic, &fmt_in, &fmt_out );
592 if ( p_new_pic == NULL )
594 msg_Err( p_stream, "image conversion failed" );
600 /* TODO: chroma conversion if needed */
602 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
603 if( p_new_pic == NULL )
605 msg_Err( p_stream, "image conversion failed" );
609 if( vout_AllocatePicture(
610 p_stream, p_new_pic, p_pic->format.i_chroma,
611 p_pic->format.i_width, p_pic->format.i_height,
612 p_sys->p_decoder->fmt_out.video.i_aspect )
616 msg_Err( p_stream, "image allocation failed" );
620 vout_CopyPicture( p_stream, p_new_pic, p_pic );
623 p_new_pic->i_refcount = 1;
624 p_new_pic->i_status = DESTROYED_PICTURE;
625 p_new_pic->i_type = DIRECT_PICTURE;
626 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
627 p_new_pic->pf_release = ReleasePicture;
628 p_new_pic->date = p_pic->date;
629 p_pic->pf_release( p_pic );
631 if( p_sys->pp_vfilters )
633 /* Apply user specified video filters */
634 filter_t **pp_vfilter = p_sys->pp_vfilters;
635 filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
636 for( ; pp_vfilter < pp_end; pp_vfilter++ )
638 (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
639 (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
640 (*pp_vfilter)->fmt_in.video = p_new_pic->format;
641 (*pp_vfilter)->fmt_out.video = p_new_pic->format;
642 p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
646 msg_Err( p_stream, "video filter failed" );
650 if( !p_new_pic ) continue;
653 PushPicture( p_stream, p_new_pic );
661 vlc_object_t *p_owner;
665 static void video_release_buffer_decoder( picture_t *p_pic )
667 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
669 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
671 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
674 static void video_release_buffer_filter( picture_t *p_pic )
676 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
678 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
680 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
683 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
685 return video_new_buffer( VLC_OBJECT( p_dec ),
686 (decoder_owner_sys_t *)p_dec->p_owner,
688 video_release_buffer_decoder );
691 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
693 return video_new_buffer( VLC_OBJECT( p_filter ),
694 (decoder_owner_sys_t *)p_filter->p_owner,
696 video_release_buffer_filter );
699 static picture_t *video_new_buffer( vlc_object_t *p_this,
700 decoder_owner_sys_t *p_sys,
701 es_format_t *fmt_out,
702 void ( *pf_release )( picture_t * ) )
704 picture_t **pp_ring = p_sys->pp_pics;
708 if( fmt_out->video.i_width != p_sys->video.i_width ||
709 fmt_out->video.i_height != p_sys->video.i_height ||
710 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
711 fmt_out->video.i_aspect != p_sys->video.i_aspect )
713 if( !fmt_out->video.i_sar_num ||
714 !fmt_out->video.i_sar_den )
716 fmt_out->video.i_sar_num =
717 fmt_out->video.i_aspect * fmt_out->video.i_height;
719 fmt_out->video.i_sar_den =
720 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
723 vlc_ureduce( &fmt_out->video.i_sar_num,
724 &fmt_out->video.i_sar_den,
725 fmt_out->video.i_sar_num,
726 fmt_out->video.i_sar_den, 0 );
728 if( !fmt_out->video.i_visible_width ||
729 !fmt_out->video.i_visible_height )
731 fmt_out->video.i_visible_width = fmt_out->video.i_width;
732 fmt_out->video.i_visible_height = fmt_out->video.i_height;
735 fmt_out->video.i_chroma = fmt_out->i_codec;
736 p_sys->video = fmt_out->video;
738 for( i = 0; i < PICTURE_RING_SIZE; i++ )
740 if ( pp_ring[i] != NULL )
742 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
744 if ( pp_ring[i]->p_data_orig != NULL )
745 free( pp_ring[i]->p_data_orig );
746 free( pp_ring[i]->p_sys );
751 pp_ring[i]->p_sys->b_dead = VLC_TRUE;
758 /* Find an empty space in the picture ring buffer */
759 for( i = 0; i < PICTURE_RING_SIZE; i++ )
761 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
763 pp_ring[i]->i_status = RESERVED_PICTURE;
767 for( i = 0; i < PICTURE_RING_SIZE; i++ )
769 if( pp_ring[i] == NULL ) break;
772 if( i == PICTURE_RING_SIZE )
774 msg_Err( p_this, "decoder/filter is leaking pictures, "
775 "resetting its ring buffer" );
777 for( i = 0; i < PICTURE_RING_SIZE; i++ )
779 pp_ring[i]->pf_release( pp_ring[i] );
785 p_pic = malloc( sizeof(picture_t) );
786 fmt_out->video.i_chroma = fmt_out->i_codec;
787 vout_AllocatePicture( p_this, p_pic,
788 fmt_out->video.i_chroma,
789 fmt_out->video.i_width,
790 fmt_out->video.i_height,
791 fmt_out->video.i_aspect );
793 if( !p_pic->i_planes )
799 p_pic->pf_release = pf_release;
800 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
801 p_pic->p_sys->p_owner = p_this;
802 p_pic->p_sys->b_dead = VLC_FALSE;
803 p_pic->i_status = RESERVED_PICTURE;
810 inline static void video_del_buffer_decoder( decoder_t *p_this,
813 video_del_buffer( VLC_OBJECT( p_this ), p_pic );
816 inline static void video_del_buffer_filter( filter_t *p_this,
819 video_del_buffer( VLC_OBJECT( p_this ), p_pic );
822 static void video_del_buffer( vlc_object_t *p_this, picture_t *p_pic )
824 p_pic->i_refcount = 0;
825 p_pic->i_status = DESTROYED_PICTURE;
826 if ( p_pic->p_sys->b_dead )
828 if ( p_pic->p_data_orig != NULL )
829 free( p_pic->p_data_orig );
830 free( p_pic->p_sys );
835 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
840 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
842 video_release_buffer_decoder( p_pic );
846 /**********************************************************************
847 * Callback to update (some) params on the fly
848 **********************************************************************/
849 static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
850 vlc_value_t oldval, vlc_value_t newval,
853 sout_stream_t *p_stream = (sout_stream_t *)p_data;
854 sout_stream_sys_t *p_sys = p_stream->p_sys;
855 int i_ret = VLC_SUCCESS;
857 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
858 if( VAR_IS( "height" ) )
860 /* We create the handler before updating the value in p_sys
861 * so we don't have to worry about locking */
862 if( !p_sys->p_image && newval.i_int )
863 p_sys->p_image = image_HandlerCreate( p_stream );
864 p_sys->i_height = newval.i_int;
866 else if( VAR_IS( "width" ) )
868 /* We create the handler before updating the value in p_sys
869 * so we don't have to worry about locking */
870 if( !p_sys->p_image && newval.i_int )
871 p_sys->p_image = image_HandlerCreate( p_stream );
872 p_sys->i_width = newval.i_int;