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( 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_release( 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_release( *pp_vfilter );
426 return (sout_stream_id_t *)p_sys;
429 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
432 sout_stream_sys_t *p_sys = p_stream->p_sys;
435 vlc_bool_t b_last_es = VLC_TRUE;
436 filter_t **pp_vfilter, **pp_end;
439 if ( !p_sys->b_inited )
444 if ( p_sys->p_decoder != NULL )
446 picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
448 if( p_sys->p_decoder->p_module )
449 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
450 vlc_object_detach( p_sys->p_decoder );
451 vlc_object_release( p_sys->p_decoder );
453 for( i = 0; i < PICTURE_RING_SIZE; i++ )
455 if ( pp_ring[i] != NULL )
457 if ( pp_ring[i]->p_data_orig != NULL )
458 free( pp_ring[i]->p_data_orig );
459 free( pp_ring[i]->p_sys );
465 /* Destroy user specified video filters */
466 pp_vfilter = p_sys->pp_vfilters;
467 pp_end = pp_vfilter + p_sys->i_vfilters;
468 for( ; pp_vfilter < pp_end; pp_vfilter++ )
470 vlc_object_detach( *pp_vfilter );
471 if( (*pp_vfilter)->p_module )
472 module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
473 vlc_object_release( *pp_vfilter );
475 free( p_sys->pp_vfilters );
477 vlc_mutex_lock( p_sys->p_lock );
479 p_bridge = GetBridge( p_stream );
482 p_es->b_empty = VLC_TRUE;
483 while ( p_es->p_picture )
485 picture_t *p_next = p_es->p_picture->p_next;
486 p_es->p_picture->pf_release( p_es->p_picture );
487 p_es->p_picture = p_next;
490 for ( i = 0; i < p_bridge->i_es_num; i++ )
492 if ( !p_bridge->pp_es[i]->b_empty )
494 b_last_es = VLC_FALSE;
501 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
502 for ( i = 0; i < p_bridge->i_es_num; i++ )
503 free( p_bridge->pp_es[i] );
504 free( p_bridge->pp_es );
506 var_Destroy( p_libvlc, "mosaic-struct" );
509 vlc_mutex_unlock( p_sys->p_lock );
511 if ( p_sys->p_image )
513 image_HandlerDelete( p_sys->p_image );
516 p_sys->b_inited = VLC_FALSE;
521 /*****************************************************************************
522 * PushPicture : push a picture in the mosaic-struct structure
523 *****************************************************************************/
524 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
526 sout_stream_sys_t *p_sys = p_stream->p_sys;
527 bridged_es_t *p_es = p_sys->p_es;
529 vlc_mutex_lock( p_sys->p_lock );
531 *p_es->pp_last = p_picture;
532 p_picture->p_next = NULL;
533 p_es->pp_last = &p_picture->p_next;
535 vlc_mutex_unlock( p_sys->p_lock );
538 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
541 sout_stream_sys_t *p_sys = p_stream->p_sys;
544 if ( (sout_stream_sys_t *)id != p_sys )
546 block_ChainRelease( p_buffer );
550 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
553 picture_t *p_new_pic;
555 if( p_sys->i_height || p_sys->i_width )
557 video_format_t fmt_out, fmt_in;
559 memset( &fmt_in, 0, sizeof(video_format_t) );
560 memset( &fmt_out, 0, sizeof(video_format_t) );
561 fmt_in = p_sys->p_decoder->fmt_out.video;
564 if( p_sys->i_chroma )
565 fmt_out.i_chroma = p_sys->i_chroma;
567 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
569 if ( !p_sys->i_height )
571 fmt_out.i_width = p_sys->i_width;
572 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
573 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
576 else if ( !p_sys->i_width )
578 fmt_out.i_height = p_sys->i_height;
579 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
580 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
585 fmt_out.i_width = p_sys->i_width;
586 fmt_out.i_height = p_sys->i_height;
588 fmt_out.i_visible_width = fmt_out.i_width;
589 fmt_out.i_visible_height = fmt_out.i_height;
591 p_new_pic = image_Convert( p_sys->p_image,
592 p_pic, &fmt_in, &fmt_out );
593 if ( p_new_pic == NULL )
595 msg_Err( p_stream, "image conversion failed" );
601 /* TODO: chroma conversion if needed */
603 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
604 if( p_new_pic == NULL )
606 msg_Err( p_stream, "image conversion failed" );
610 if( vout_AllocatePicture(
611 p_stream, p_new_pic, p_pic->format.i_chroma,
612 p_pic->format.i_width, p_pic->format.i_height,
613 p_sys->p_decoder->fmt_out.video.i_aspect )
617 msg_Err( p_stream, "image allocation failed" );
621 vout_CopyPicture( p_stream, p_new_pic, p_pic );
624 p_new_pic->i_refcount = 1;
625 p_new_pic->i_status = DESTROYED_PICTURE;
626 p_new_pic->i_type = DIRECT_PICTURE;
627 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
628 p_new_pic->pf_release = ReleasePicture;
629 p_new_pic->date = p_pic->date;
630 p_pic->pf_release( p_pic );
632 if( p_sys->pp_vfilters )
634 /* Apply user specified video filters */
635 filter_t **pp_vfilter = p_sys->pp_vfilters;
636 filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
637 for( ; pp_vfilter < pp_end; pp_vfilter++ )
639 (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
640 (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
641 (*pp_vfilter)->fmt_in.video = p_new_pic->format;
642 (*pp_vfilter)->fmt_out.video = p_new_pic->format;
643 p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
647 msg_Err( p_stream, "video filter failed" );
651 if( !p_new_pic ) continue;
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 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
670 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
672 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
675 static void video_release_buffer_filter( picture_t *p_pic )
677 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
679 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
681 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
684 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
686 return video_new_buffer( VLC_OBJECT( p_dec ),
687 (decoder_owner_sys_t *)p_dec->p_owner,
689 video_release_buffer_decoder );
692 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
694 return video_new_buffer( VLC_OBJECT( p_filter ),
695 (decoder_owner_sys_t *)p_filter->p_owner,
697 video_release_buffer_filter );
700 static picture_t *video_new_buffer( vlc_object_t *p_this,
701 decoder_owner_sys_t *p_sys,
702 es_format_t *fmt_out,
703 void ( *pf_release )( picture_t * ) )
705 picture_t **pp_ring = p_sys->pp_pics;
709 if( fmt_out->video.i_width != p_sys->video.i_width ||
710 fmt_out->video.i_height != p_sys->video.i_height ||
711 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
712 fmt_out->video.i_aspect != p_sys->video.i_aspect )
714 if( !fmt_out->video.i_sar_num ||
715 !fmt_out->video.i_sar_den )
717 fmt_out->video.i_sar_num =
718 fmt_out->video.i_aspect * fmt_out->video.i_height;
720 fmt_out->video.i_sar_den =
721 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
724 vlc_ureduce( &fmt_out->video.i_sar_num,
725 &fmt_out->video.i_sar_den,
726 fmt_out->video.i_sar_num,
727 fmt_out->video.i_sar_den, 0 );
729 if( !fmt_out->video.i_visible_width ||
730 !fmt_out->video.i_visible_height )
732 fmt_out->video.i_visible_width = fmt_out->video.i_width;
733 fmt_out->video.i_visible_height = fmt_out->video.i_height;
736 fmt_out->video.i_chroma = fmt_out->i_codec;
737 p_sys->video = fmt_out->video;
739 for( i = 0; i < PICTURE_RING_SIZE; i++ )
741 if ( pp_ring[i] != NULL )
743 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
745 if ( pp_ring[i]->p_data_orig != NULL )
746 free( pp_ring[i]->p_data_orig );
747 free( pp_ring[i]->p_sys );
752 pp_ring[i]->p_sys->b_dead = VLC_TRUE;
759 /* Find an empty space in the picture ring buffer */
760 for( i = 0; i < PICTURE_RING_SIZE; i++ )
762 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
764 pp_ring[i]->i_status = RESERVED_PICTURE;
768 for( i = 0; i < PICTURE_RING_SIZE; i++ )
770 if( pp_ring[i] == NULL ) break;
773 if( i == PICTURE_RING_SIZE )
775 msg_Err( p_this, "decoder/filter is leaking pictures, "
776 "resetting its ring buffer" );
778 for( i = 0; i < PICTURE_RING_SIZE; i++ )
780 pp_ring[i]->pf_release( pp_ring[i] );
786 p_pic = malloc( sizeof(picture_t) );
787 if( !p_pic ) return NULL;
788 fmt_out->video.i_chroma = fmt_out->i_codec;
789 vout_AllocatePicture( p_this, p_pic,
790 fmt_out->video.i_chroma,
791 fmt_out->video.i_width,
792 fmt_out->video.i_height,
793 fmt_out->video.i_aspect );
795 if( !p_pic->i_planes )
801 p_pic->pf_release = pf_release;
802 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
803 p_pic->p_sys->p_owner = p_this;
804 p_pic->p_sys->b_dead = VLC_FALSE;
805 p_pic->i_status = RESERVED_PICTURE;
812 inline static void video_del_buffer_decoder( decoder_t *p_this,
816 video_del_buffer( p_pic );
819 inline static void video_del_buffer_filter( filter_t *p_this,
823 video_del_buffer( p_pic );
826 static void video_del_buffer( picture_t *p_pic )
828 p_pic->i_refcount = 0;
829 p_pic->i_status = DESTROYED_PICTURE;
830 if ( p_pic->p_sys->b_dead )
832 if ( p_pic->p_data_orig != NULL )
833 free( p_pic->p_data_orig );
834 free( p_pic->p_sys );
839 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
845 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
848 video_release_buffer_decoder( p_pic );
852 /**********************************************************************
853 * Callback to update (some) params on the fly
854 **********************************************************************/
855 static int MosaicBridgeCallback( vlc_object_t *p_this, char const *psz_var,
856 vlc_value_t oldval, vlc_value_t newval,
859 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
860 sout_stream_t *p_stream = (sout_stream_t *)p_data;
861 sout_stream_sys_t *p_sys = p_stream->p_sys;
862 int i_ret = VLC_SUCCESS;
864 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
865 if( VAR_IS( "height" ) )
867 /* We create the handler before updating the value in p_sys
868 * so we don't have to worry about locking */
869 if( !p_sys->p_image && newval.i_int )
870 p_sys->p_image = image_HandlerCreate( p_stream );
871 p_sys->i_height = newval.i_int;
873 else if( VAR_IS( "width" ) )
875 /* We create the handler before updating the value in p_sys
876 * so we don't have to worry about locking */
877 if( !p_sys->p_image && newval.i_int )
878 p_sys->p_image = image_HandlerCreate( p_stream );
879 p_sys->i_width = newval.i_int;