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;
91 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 * );
118 static int MosaicBridgeCallback( vlc_object_t *, char const *,
119 vlc_value_t, vlc_value_t, void * );
121 /*****************************************************************************
123 *****************************************************************************/
124 #define ID_TEXT N_("ID")
125 #define ID_LONGTEXT N_( \
126 "Specify an identifier string for this subpicture" )
128 #define WIDTH_TEXT N_("Video width")
129 #define WIDTH_LONGTEXT N_( \
130 "Output video width." )
131 #define HEIGHT_TEXT N_("Video height")
132 #define HEIGHT_LONGTEXT N_( \
133 "Output video height." )
134 #define RATIO_TEXT N_("Sample aspect ratio")
135 #define RATIO_LONGTEXT N_( \
136 "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
138 #define VFILTER_TEXT N_("Video filter")
139 #define VFILTER_LONGTEXT N_( \
140 "Video filters will be applied to the video stream." )
142 #define CHROMA_TEXT N_("Image chroma")
143 #define CHROMA_LONGTEXT N_( \
144 "Force the use of a specific chroma. Use YUVA if you're planning " \
145 "to use the Alphamask or Bluescreen video filter." )
147 #define CFG_PREFIX "sout-mosaic-bridge-"
150 set_shortname( _( "Mosaic bridge" ) );
151 set_description(_("Mosaic bridge stream output") );
152 set_capability( "sout stream", 0 );
153 add_shortcut( "mosaic-bridge" );
155 add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
157 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
158 WIDTH_LONGTEXT, VLC_TRUE );
159 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
160 HEIGHT_LONGTEXT, VLC_TRUE );
161 add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
162 RATIO_LONGTEXT, VLC_FALSE );
163 add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
166 add_module_list( CFG_PREFIX "vfilter", "video filter2",
167 NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, VLC_FALSE );
169 set_callbacks( Open, Close );
172 static const char *ppsz_sout_options[] = {
173 "id", "width", "height", "sar", "vfilter", "chroma", NULL
176 /*****************************************************************************
178 *****************************************************************************/
179 static int Open( vlc_object_t *p_this )
181 sout_stream_t *p_stream = (sout_stream_t *)p_this;
182 sout_stream_sys_t *p_sys;
183 vlc_object_t *p_libvlc = VLC_OBJECT( p_this->p_libvlc );
186 config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
189 p_sys = malloc( sizeof( sout_stream_sys_t ) );
195 p_stream->p_sys = p_sys;
196 p_sys->b_inited = VLC_FALSE;
198 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
199 var_Get( p_libvlc, "mosaic-lock", &val );
200 p_sys->p_lock = val.p_address;
202 var_Get( p_stream, CFG_PREFIX "id", &val );
203 p_sys->psz_id = val.psz_string;
206 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
207 var_AddCallback( p_stream, CFG_PREFIX "height", MosaicBridgeCallback,
211 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
212 var_AddCallback( p_stream, CFG_PREFIX "width", MosaicBridgeCallback,
215 var_Get( p_stream, CFG_PREFIX "sar", &val );
216 if ( val.psz_string )
218 char *psz_parser = strchr( val.psz_string, ':' );
222 *psz_parser++ = '\0';
223 p_sys->i_sar_num = atoi( val.psz_string );
224 p_sys->i_sar_den = atoi( psz_parser );
225 vlc_ureduce( &p_sys->i_sar_num, &p_sys->i_sar_den,
226 p_sys->i_sar_num, p_sys->i_sar_den, 0 );
230 msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
231 p_sys->i_sar_num = p_sys->i_sar_den = 1;
234 free( val.psz_string );
238 p_sys->i_sar_num = p_sys->i_sar_den = 1;
242 val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
243 if( val.psz_string && strlen( val.psz_string ) >= 4 )
245 memcpy( &p_sys->i_chroma, val.psz_string, 4 );
246 msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
249 p_stream->pf_add = Add;
250 p_stream->pf_del = Del;
251 p_stream->pf_send = Send;
253 p_stream->p_sout->i_out_pace_nocontrol++;
258 /*****************************************************************************
260 *****************************************************************************/
261 static void Close( vlc_object_t * p_this )
263 sout_stream_t *p_stream = (sout_stream_t*)p_this;
264 sout_stream_sys_t *p_sys = p_stream->p_sys;
266 p_stream->p_sout->i_out_pace_nocontrol--;
268 free( p_sys->psz_id );
273 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
275 sout_stream_sys_t *p_sys = p_stream->p_sys;
278 char *psz_chain, *psz_parser;
281 if ( p_sys->b_inited )
286 /* Create decoder object */
287 p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
288 vlc_object_attach( p_sys->p_decoder, p_stream );
289 p_sys->p_decoder->p_module = NULL;
290 p_sys->p_decoder->fmt_in = *p_fmt;
291 p_sys->p_decoder->b_pace_control = VLC_FALSE;
292 p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
293 p_sys->p_decoder->fmt_out.i_extra = 0;
294 p_sys->p_decoder->fmt_out.p_extra = 0;
295 p_sys->p_decoder->pf_decode_video = 0;
296 p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
297 p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
298 p_sys->p_decoder->pf_picture_link = video_link_picture_decoder;
299 p_sys->p_decoder->pf_picture_unlink = video_unlink_picture_decoder;
300 p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
301 for( i = 0; i < PICTURE_RING_SIZE; i++ )
302 p_sys->p_decoder->p_owner->pp_pics[i] = 0;
303 p_sys->p_decoder->p_owner->video = p_fmt->video;
304 //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
306 p_sys->p_decoder->p_module =
307 module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
309 if( !p_sys->p_decoder->p_module )
311 msg_Err( p_stream, "cannot find decoder" );
312 vlc_object_detach( p_sys->p_decoder );
313 vlc_object_release( p_sys->p_decoder );
317 p_sys->b_inited = VLC_TRUE;
318 vlc_mutex_lock( p_sys->p_lock );
320 p_bridge = GetBridge( p_stream );
321 if ( p_bridge == NULL )
323 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
326 p_bridge = malloc( sizeof( bridge_t ) );
328 var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );
329 val.p_address = p_bridge;
330 var_Set( p_libvlc, "mosaic-struct", val );
332 p_bridge->i_es_num = 0;
333 p_bridge->pp_es = NULL;
336 for ( i = 0; i < p_bridge->i_es_num; i++ )
338 if ( p_bridge->pp_es[i]->b_empty )
342 if ( i == p_bridge->i_es_num )
344 p_bridge->pp_es = realloc( p_bridge->pp_es,
345 (p_bridge->i_es_num + 1)
346 * sizeof(bridged_es_t *) );
347 p_bridge->i_es_num++;
348 p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
351 p_sys->p_es = p_es = p_bridge->pp_es[i];
353 //p_es->fmt = *p_fmt;
354 p_es->psz_id = p_sys->psz_id;
355 p_es->p_picture = NULL;
356 p_es->pp_last = &p_es->p_picture;
357 p_es->b_empty = VLC_FALSE;
359 vlc_mutex_unlock( p_sys->p_lock );
361 if ( p_sys->i_height || p_sys->i_width )
363 p_sys->p_image = image_HandlerCreate( p_stream );
367 p_sys->p_image = NULL;
370 msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
372 /* Create user specified video filters */
373 psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
374 msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
376 config_chain_t *p_cfg;
377 for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
379 msg_Dbg( p_stream, " - %s\n", p_cfg->psz_value );
382 p_sys->i_vfilters = 0;
383 p_sys->pp_vfilters = NULL;
384 psz_parser = psz_chain;
385 while( psz_parser && *psz_parser )
387 config_chain_t *p_cfg;
389 filter_t **pp_vfilter;
390 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
393 (filter_t **)realloc( p_sys->pp_vfilters,
394 p_sys->i_vfilters * sizeof(filter_t *) );
395 pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
396 *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
397 vlc_object_attach( *pp_vfilter, p_stream );
398 (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
399 (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
400 (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
401 if( p_sys->i_chroma )
402 (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
403 (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
404 (*pp_vfilter)->p_cfg = p_cfg;
405 (*pp_vfilter)->p_module =
406 module_Need( *pp_vfilter, "video filter2", psz_name, VLC_TRUE );
407 if( (*pp_vfilter)->p_module )
410 (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
411 p_sys->p_decoder->p_owner;
412 msg_Err( p_stream, "Added video filter %s to the chain",
417 /* Crap ... we didn't find a filter */
419 "no video filter matching name \"%s\" found",
421 vlc_object_detach( *pp_vfilter );
422 vlc_object_release( *pp_vfilter );
428 return (sout_stream_id_t *)p_sys;
431 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
434 sout_stream_sys_t *p_sys = p_stream->p_sys;
437 vlc_bool_t b_last_es = VLC_TRUE;
438 filter_t **pp_vfilter, **pp_end;
441 if ( !p_sys->b_inited )
446 if ( p_sys->p_decoder != NULL )
448 picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
450 if( p_sys->p_decoder->p_module )
451 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
452 vlc_object_detach( p_sys->p_decoder );
453 vlc_object_release( p_sys->p_decoder );
455 for( i = 0; i < PICTURE_RING_SIZE; i++ )
457 if ( pp_ring[i] != NULL )
459 if ( pp_ring[i]->p_data_orig != NULL )
460 free( pp_ring[i]->p_data_orig );
461 free( pp_ring[i]->p_sys );
467 /* Destroy user specified video filters */
468 pp_vfilter = p_sys->pp_vfilters;
469 pp_end = pp_vfilter + p_sys->i_vfilters;
470 for( ; pp_vfilter < pp_end; pp_vfilter++ )
472 vlc_object_detach( *pp_vfilter );
473 if( (*pp_vfilter)->p_module )
474 module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
475 vlc_object_release( *pp_vfilter );
477 free( p_sys->pp_vfilters );
479 vlc_mutex_lock( p_sys->p_lock );
481 p_bridge = GetBridge( p_stream );
484 p_es->b_empty = VLC_TRUE;
485 while ( p_es->p_picture )
487 picture_t *p_next = p_es->p_picture->p_next;
488 p_es->p_picture->pf_release( p_es->p_picture );
489 p_es->p_picture = p_next;
492 for ( i = 0; i < p_bridge->i_es_num; i++ )
494 if ( !p_bridge->pp_es[i]->b_empty )
496 b_last_es = VLC_FALSE;
503 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
504 for ( i = 0; i < p_bridge->i_es_num; i++ )
505 free( p_bridge->pp_es[i] );
506 free( p_bridge->pp_es );
508 var_Destroy( p_libvlc, "mosaic-struct" );
511 vlc_mutex_unlock( p_sys->p_lock );
513 if ( p_sys->p_image )
515 image_HandlerDelete( p_sys->p_image );
518 p_sys->b_inited = VLC_FALSE;
523 /*****************************************************************************
524 * PushPicture : push a picture in the mosaic-struct structure
525 *****************************************************************************/
526 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
528 sout_stream_sys_t *p_sys = p_stream->p_sys;
529 bridged_es_t *p_es = p_sys->p_es;
531 vlc_mutex_lock( p_sys->p_lock );
533 *p_es->pp_last = p_picture;
534 p_picture->p_next = NULL;
535 p_es->pp_last = &p_picture->p_next;
537 vlc_mutex_unlock( p_sys->p_lock );
540 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
543 sout_stream_sys_t *p_sys = p_stream->p_sys;
546 if ( (sout_stream_sys_t *)id != p_sys )
548 block_ChainRelease( p_buffer );
552 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
555 picture_t *p_new_pic;
557 if( p_sys->i_height || p_sys->i_width )
559 video_format_t fmt_out, fmt_in;
561 memset( &fmt_in, 0, sizeof(video_format_t) );
562 memset( &fmt_out, 0, sizeof(video_format_t) );
563 fmt_in = p_sys->p_decoder->fmt_out.video;
566 if( p_sys->i_chroma )
567 fmt_out.i_chroma = p_sys->i_chroma;
569 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
571 if ( !p_sys->i_height )
573 fmt_out.i_width = p_sys->i_width;
574 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
575 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
578 else if ( !p_sys->i_width )
580 fmt_out.i_height = p_sys->i_height;
581 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
582 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
587 fmt_out.i_width = p_sys->i_width;
588 fmt_out.i_height = p_sys->i_height;
590 fmt_out.i_visible_width = fmt_out.i_width;
591 fmt_out.i_visible_height = fmt_out.i_height;
593 p_new_pic = image_Convert( p_sys->p_image,
594 p_pic, &fmt_in, &fmt_out );
595 if ( p_new_pic == NULL )
597 msg_Err( p_stream, "image conversion failed" );
603 /* TODO: chroma conversion if needed */
605 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
606 if( p_new_pic == NULL )
608 msg_Err( p_stream, "image conversion failed" );
612 if( vout_AllocatePicture(
613 p_stream, p_new_pic, p_pic->format.i_chroma,
614 p_pic->format.i_width, p_pic->format.i_height,
615 p_sys->p_decoder->fmt_out.video.i_aspect )
619 msg_Err( p_stream, "image allocation failed" );
623 vout_CopyPicture( p_stream, p_new_pic, p_pic );
626 p_new_pic->i_refcount = 1;
627 p_new_pic->i_status = DESTROYED_PICTURE;
628 p_new_pic->i_type = DIRECT_PICTURE;
629 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
630 p_new_pic->pf_release = ReleasePicture;
631 p_new_pic->date = p_pic->date;
632 p_pic->pf_release( p_pic );
634 if( p_sys->pp_vfilters )
636 /* Apply user specified video filters */
637 filter_t **pp_vfilter = p_sys->pp_vfilters;
638 filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
639 for( ; pp_vfilter < pp_end; pp_vfilter++ )
641 (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
642 (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
643 (*pp_vfilter)->fmt_in.video = p_new_pic->format;
644 (*pp_vfilter)->fmt_out.video = p_new_pic->format;
645 p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
649 msg_Err( p_stream, "video filter failed" );
653 if( !p_new_pic ) continue;
656 PushPicture( p_stream, p_new_pic );
664 vlc_object_t *p_owner;
668 static void video_release_buffer_decoder( picture_t *p_pic )
670 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
672 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
674 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
677 static void video_release_buffer_filter( picture_t *p_pic )
679 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
681 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
683 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
686 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
688 return video_new_buffer( VLC_OBJECT( p_dec ),
689 (decoder_owner_sys_t *)p_dec->p_owner,
691 video_release_buffer_decoder );
694 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
696 return video_new_buffer( VLC_OBJECT( p_filter ),
697 (decoder_owner_sys_t *)p_filter->p_owner,
699 video_release_buffer_filter );
702 static picture_t *video_new_buffer( vlc_object_t *p_this,
703 decoder_owner_sys_t *p_sys,
704 es_format_t *fmt_out,
705 void ( *pf_release )( picture_t * ) )
707 picture_t **pp_ring = p_sys->pp_pics;
711 if( fmt_out->video.i_width != p_sys->video.i_width ||
712 fmt_out->video.i_height != p_sys->video.i_height ||
713 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
714 fmt_out->video.i_aspect != p_sys->video.i_aspect )
716 if( !fmt_out->video.i_sar_num ||
717 !fmt_out->video.i_sar_den )
719 fmt_out->video.i_sar_num =
720 fmt_out->video.i_aspect * fmt_out->video.i_height;
722 fmt_out->video.i_sar_den =
723 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
726 vlc_ureduce( &fmt_out->video.i_sar_num,
727 &fmt_out->video.i_sar_den,
728 fmt_out->video.i_sar_num,
729 fmt_out->video.i_sar_den, 0 );
731 if( !fmt_out->video.i_visible_width ||
732 !fmt_out->video.i_visible_height )
734 fmt_out->video.i_visible_width = fmt_out->video.i_width;
735 fmt_out->video.i_visible_height = fmt_out->video.i_height;
738 fmt_out->video.i_chroma = fmt_out->i_codec;
739 p_sys->video = fmt_out->video;
741 for( i = 0; i < PICTURE_RING_SIZE; i++ )
743 if ( pp_ring[i] != NULL )
745 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
747 if ( pp_ring[i]->p_data_orig != NULL )
748 free( pp_ring[i]->p_data_orig );
749 free( pp_ring[i]->p_sys );
754 pp_ring[i]->p_sys->b_dead = VLC_TRUE;
761 /* Find an empty space in the picture ring buffer */
762 for( i = 0; i < PICTURE_RING_SIZE; i++ )
764 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
766 pp_ring[i]->i_status = RESERVED_PICTURE;
770 for( i = 0; i < PICTURE_RING_SIZE; i++ )
772 if( pp_ring[i] == NULL ) break;
775 if( i == PICTURE_RING_SIZE )
777 msg_Err( p_this, "decoder/filter is leaking pictures, "
778 "resetting its ring buffer" );
780 for( i = 0; i < PICTURE_RING_SIZE; i++ )
782 pp_ring[i]->pf_release( pp_ring[i] );
788 p_pic = malloc( sizeof(picture_t) );
789 if( !p_pic ) return NULL;
790 fmt_out->video.i_chroma = fmt_out->i_codec;
791 vout_AllocatePicture( p_this, p_pic,
792 fmt_out->video.i_chroma,
793 fmt_out->video.i_width,
794 fmt_out->video.i_height,
795 fmt_out->video.i_aspect );
797 if( !p_pic->i_planes )
803 p_pic->pf_release = pf_release;
804 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
805 p_pic->p_sys->p_owner = p_this;
806 p_pic->p_sys->b_dead = VLC_FALSE;
807 p_pic->i_status = RESERVED_PICTURE;
814 inline static void video_del_buffer_decoder( decoder_t *p_this,
818 video_del_buffer( p_pic );
821 inline static void video_del_buffer_filter( filter_t *p_this,
825 video_del_buffer( p_pic );
828 static void video_del_buffer( picture_t *p_pic )
830 p_pic->i_refcount = 0;
831 p_pic->i_status = DESTROYED_PICTURE;
832 if ( p_pic->p_sys->b_dead )
834 free( p_pic->p_data_orig );
835 free( p_pic->p_sys );
840 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
846 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
849 video_release_buffer_decoder( p_pic );
853 /**********************************************************************
854 * Callback to update (some) params on the fly
855 **********************************************************************/
856 static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
857 vlc_value_t oldval, vlc_value_t newval,
860 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
861 sout_stream_t *p_stream = (sout_stream_t *)p_data;
862 sout_stream_sys_t *p_sys = p_stream->p_sys;
863 int i_ret = VLC_SUCCESS;
865 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
866 if( VAR_IS( "height" ) )
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_height = newval.i_int;
874 else if( VAR_IS( "width" ) )
876 /* We create the handler before updating the value in p_sys
877 * so we don't have to worry about locking */
878 if( !p_sys->p_image && newval.i_int )
879 p_sys->p_image = image_HandlerCreate( p_stream );
880 p_sys->i_width = newval.i_int;