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 */
35 #include <vlc_plugin.h>
37 #include <vlc_block.h>
38 #include <vlc_codec.h>
40 #include <vlc_image.h>
41 #include <vlc_filter.h>
43 #include "../video_filter/mosaic.h"
45 /*****************************************************************************
47 *****************************************************************************/
48 struct sout_stream_sys_t
54 image_handler_t *p_image; /* filter for resizing */
55 int i_height, i_width;
56 unsigned int i_sar_num, i_sar_den;
60 int i_chroma; /* force image format chroma */
62 filter_t **pp_vfilters;
66 #define PICTURE_RING_SIZE 4
67 struct decoder_owner_sys_t
69 picture_t *pp_pics[PICTURE_RING_SIZE];
71 /* Current format in use by the output */
75 typedef void (* pf_release_t)( picture_t * );
76 static void ReleasePicture( picture_t *p_pic )
80 if ( p_pic->i_refcount <= 0 )
82 if ( p_pic->p_sys != NULL )
84 pf_release_t pf_release = (pf_release_t)p_pic->p_sys;
92 free( p_pic->p_data_orig );
99 /*****************************************************************************
101 *****************************************************************************/
102 static int Open ( vlc_object_t * );
103 static void Close ( vlc_object_t * );
104 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
105 static int Del ( sout_stream_t *, sout_stream_id_t * );
106 static int Send( sout_stream_t *, sout_stream_id_t *, block_t * );
108 inline static void video_del_buffer_decoder( decoder_t *, picture_t * );
109 inline static void video_del_buffer_filter( filter_t *, picture_t * );
110 static void video_del_buffer( picture_t * );
112 inline static picture_t *video_new_buffer_decoder( decoder_t * );
113 inline static picture_t *video_new_buffer_filter( filter_t * );
114 static picture_t *video_new_buffer( vlc_object_t *, decoder_owner_sys_t *,
115 es_format_t *, void (*)( picture_t * ) );
117 static void video_link_picture_decoder( decoder_t *, picture_t * );
118 static void video_unlink_picture_decoder( decoder_t *, picture_t * );
120 static int HeightCallback( vlc_object_t *, char const *,
121 vlc_value_t, vlc_value_t, void * );
122 static int WidthCallback( vlc_object_t *, char const *,
123 vlc_value_t, vlc_value_t, void * );
124 static int alphaCallback( vlc_object_t *, char const *,
125 vlc_value_t, vlc_value_t, void * );
126 static int xCallback( vlc_object_t *, char const *,
127 vlc_value_t, vlc_value_t, void * );
128 static int yCallback( vlc_object_t *, char const *,
129 vlc_value_t, vlc_value_t, void * );
131 /*****************************************************************************
133 *****************************************************************************/
134 #define ID_TEXT N_("ID")
135 #define ID_LONGTEXT N_( \
136 "Specify an identifier string for this subpicture" )
138 #define WIDTH_TEXT N_("Video width")
139 #define WIDTH_LONGTEXT N_( \
140 "Output video width." )
141 #define HEIGHT_TEXT N_("Video height")
142 #define HEIGHT_LONGTEXT N_( \
143 "Output video height." )
144 #define RATIO_TEXT N_("Sample aspect ratio")
145 #define RATIO_LONGTEXT N_( \
146 "Sample aspect ratio of the destination (1:1, 3:4, 2:3)." )
148 #define VFILTER_TEXT N_("Video filter")
149 #define VFILTER_LONGTEXT N_( \
150 "Video filters will be applied to the video stream." )
152 #define CHROMA_TEXT N_("Image chroma")
153 #define CHROMA_LONGTEXT N_( \
154 "Force the use of a specific chroma. Use YUVA if you're planning " \
155 "to use the Alphamask or Bluescreen video filter." )
157 #define ALPHA_TEXT N_("Transparency")
158 #define ALPHA_LONGTEXT N_( \
159 "Transparency of the mosaic picture." )
161 #define X_TEXT N_("X offset")
162 #define X_LONGTEXT N_( \
163 "X coordinate of the upper left corner in the mosaic if non negative." )
165 #define Y_TEXT N_("Y offset")
166 #define Y_LONGTEXT N_( \
167 "Y coordinate of the upper left corner in the mosaic if non negative." )
169 #define CFG_PREFIX "sout-mosaic-bridge-"
172 set_shortname( _( "Mosaic bridge" ) );
173 set_description(_("Mosaic bridge stream output") );
174 set_capability( "sout stream", 0 );
175 add_shortcut( "mosaic-bridge" );
177 add_string( CFG_PREFIX "id", "Id", NULL, ID_TEXT, ID_LONGTEXT,
179 add_integer( CFG_PREFIX "width", 0, NULL, WIDTH_TEXT,
180 WIDTH_LONGTEXT, true );
181 add_integer( CFG_PREFIX "height", 0, NULL, HEIGHT_TEXT,
182 HEIGHT_LONGTEXT, true );
183 add_string( CFG_PREFIX "sar", "1:1", NULL, RATIO_TEXT,
184 RATIO_LONGTEXT, false );
185 add_string( CFG_PREFIX "chroma", 0, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
188 add_module_list( CFG_PREFIX "vfilter", "video filter2",
189 NULL, NULL, VFILTER_TEXT, VFILTER_LONGTEXT, false );
191 add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255, NULL,
192 ALPHA_TEXT, ALPHA_LONGTEXT, false );
193 add_integer( CFG_PREFIX "x", -1, NULL, X_TEXT, X_LONGTEXT, false );
194 add_integer( CFG_PREFIX "y", -1, NULL, Y_TEXT, Y_LONGTEXT, false );
196 set_callbacks( Open, Close );
199 static const char *ppsz_sout_options[] = {
200 "id", "width", "height", "sar", "vfilter", "chroma", "alpha", "x", "y", NULL
203 /*****************************************************************************
205 *****************************************************************************/
206 static int Open( vlc_object_t *p_this )
208 sout_stream_t *p_stream = (sout_stream_t *)p_this;
209 sout_stream_sys_t *p_sys;
210 vlc_object_t *p_libvlc = VLC_OBJECT( p_this->p_libvlc );
213 config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
216 p_sys = malloc( sizeof( sout_stream_sys_t ) );
222 p_stream->p_sys = p_sys;
223 p_sys->b_inited = false;
225 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
226 var_Get( p_libvlc, "mosaic-lock", &val );
227 p_sys->p_lock = val.p_address;
229 var_Get( p_stream, CFG_PREFIX "id", &val );
230 p_sys->psz_id = val.psz_string;
233 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "height" );
234 var_AddCallback( p_stream, CFG_PREFIX "height", HeightCallback, p_stream );
237 var_CreateGetIntegerCommand( p_stream, CFG_PREFIX "width" );
238 var_AddCallback( p_stream, CFG_PREFIX "width", WidthCallback, p_stream );
240 var_Get( p_stream, CFG_PREFIX "sar", &val );
241 if ( val.psz_string )
243 char *psz_parser = strchr( val.psz_string, ':' );
247 *psz_parser++ = '\0';
248 p_sys->i_sar_num = atoi( val.psz_string );
249 p_sys->i_sar_den = atoi( psz_parser );
250 vlc_ureduce( &p_sys->i_sar_num, &p_sys->i_sar_den,
251 p_sys->i_sar_num, p_sys->i_sar_den, 0 );
255 msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
256 p_sys->i_sar_num = p_sys->i_sar_den = 1;
259 free( val.psz_string );
263 p_sys->i_sar_num = p_sys->i_sar_den = 1;
267 val.psz_string = var_GetNonEmptyString( p_stream, CFG_PREFIX "chroma" );
268 if( val.psz_string && strlen( val.psz_string ) >= 4 )
270 memcpy( &p_sys->i_chroma, val.psz_string, 4 );
271 msg_Dbg( p_stream, "Forcing image chroma to 0x%.8x (%4.4s)", p_sys->i_chroma, (char*)&p_sys->i_chroma );
274 #define INT_COMMAND( a ) \
275 var_Create( p_stream, CFG_PREFIX #a, \
276 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND ); \
277 var_AddCallback( p_stream, CFG_PREFIX #a, a ## Callback, \
283 p_stream->pf_add = Add;
284 p_stream->pf_del = Del;
285 p_stream->pf_send = Send;
287 p_stream->p_sout->i_out_pace_nocontrol++;
292 /*****************************************************************************
294 *****************************************************************************/
295 static void Close( vlc_object_t * p_this )
297 sout_stream_t *p_stream = (sout_stream_t*)p_this;
298 sout_stream_sys_t *p_sys = p_stream->p_sys;
300 p_stream->p_sout->i_out_pace_nocontrol--;
302 free( p_sys->psz_id );
307 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
309 sout_stream_sys_t *p_sys = p_stream->p_sys;
312 char *psz_chain, *psz_parser;
315 if ( p_sys->b_inited )
320 /* Create decoder object */
321 p_sys->p_decoder = vlc_object_create( p_stream, VLC_OBJECT_DECODER );
322 vlc_object_attach( p_sys->p_decoder, p_stream );
323 p_sys->p_decoder->p_module = NULL;
324 p_sys->p_decoder->fmt_in = *p_fmt;
325 p_sys->p_decoder->b_pace_control = false;
326 p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in;
327 p_sys->p_decoder->fmt_out.i_extra = 0;
328 p_sys->p_decoder->fmt_out.p_extra = 0;
329 p_sys->p_decoder->pf_decode_video = 0;
330 p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
331 p_sys->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
332 p_sys->p_decoder->pf_picture_link = video_link_picture_decoder;
333 p_sys->p_decoder->pf_picture_unlink = video_unlink_picture_decoder;
334 p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
335 for( i = 0; i < PICTURE_RING_SIZE; i++ )
336 p_sys->p_decoder->p_owner->pp_pics[i] = 0;
337 p_sys->p_decoder->p_owner->video = p_fmt->video;
338 //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
340 p_sys->p_decoder->p_module =
341 module_Need( p_sys->p_decoder, "decoder", "$codec", 0 );
343 if( !p_sys->p_decoder->p_module )
345 msg_Err( p_stream, "cannot find decoder" );
346 vlc_object_detach( p_sys->p_decoder );
347 vlc_object_release( p_sys->p_decoder );
351 p_sys->b_inited = true;
352 vlc_mutex_lock( p_sys->p_lock );
354 p_bridge = GetBridge( p_stream );
355 if ( p_bridge == NULL )
357 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
360 p_bridge = malloc( sizeof( bridge_t ) );
362 var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS );
363 val.p_address = p_bridge;
364 var_Set( p_libvlc, "mosaic-struct", val );
366 p_bridge->i_es_num = 0;
367 p_bridge->pp_es = NULL;
370 for ( i = 0; i < p_bridge->i_es_num; i++ )
372 if ( p_bridge->pp_es[i]->b_empty )
376 if ( i == p_bridge->i_es_num )
378 p_bridge->pp_es = realloc( p_bridge->pp_es,
379 (p_bridge->i_es_num + 1)
380 * sizeof(bridged_es_t *) );
381 p_bridge->i_es_num++;
382 p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
385 p_sys->p_es = p_es = p_bridge->pp_es[i];
387 p_es->i_alpha = var_GetInteger( p_stream, CFG_PREFIX "alpha" );
388 p_es->i_x = var_GetInteger( p_stream, CFG_PREFIX "x" );
389 p_es->i_y = var_GetInteger( p_stream, CFG_PREFIX "y" );
391 //p_es->fmt = *p_fmt;
392 p_es->psz_id = p_sys->psz_id;
393 p_es->p_picture = NULL;
394 p_es->pp_last = &p_es->p_picture;
395 p_es->b_empty = false;
397 vlc_mutex_unlock( p_sys->p_lock );
399 if ( p_sys->i_height || p_sys->i_width )
401 p_sys->p_image = image_HandlerCreate( p_stream );
405 p_sys->p_image = NULL;
408 msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i );
410 /* Create user specified video filters */
411 psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" );
412 msg_Dbg( p_stream, "psz_chain: %s\n", psz_chain );
414 config_chain_t *p_cfg;
415 for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
417 msg_Dbg( p_stream, " - %s\n", p_cfg->psz_value );
420 p_sys->i_vfilters = 0;
421 p_sys->pp_vfilters = NULL;
422 psz_parser = psz_chain;
423 while( psz_parser && *psz_parser )
425 config_chain_t *p_cfg;
427 filter_t **pp_vfilter;
428 psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
431 (filter_t **)realloc( p_sys->pp_vfilters,
432 p_sys->i_vfilters * sizeof(filter_t *) );
433 pp_vfilter = p_sys->pp_vfilters+(p_sys->i_vfilters - 1);
434 *pp_vfilter = vlc_object_create( p_stream, VLC_OBJECT_FILTER );
435 vlc_object_attach( *pp_vfilter, p_stream );
436 (*pp_vfilter)->pf_vout_buffer_new = video_new_buffer_filter;
437 (*pp_vfilter)->pf_vout_buffer_del = video_del_buffer_filter;
438 (*pp_vfilter)->fmt_in = p_sys->p_decoder->fmt_out;
439 if( p_sys->i_chroma )
440 (*pp_vfilter)->fmt_in.video.i_chroma = p_sys->i_chroma;
441 (*pp_vfilter)->fmt_out = (*pp_vfilter)->fmt_in;
442 (*pp_vfilter)->p_cfg = p_cfg;
443 (*pp_vfilter)->p_module =
444 module_Need( *pp_vfilter, "video filter2", psz_name, true );
445 if( (*pp_vfilter)->p_module )
448 (*pp_vfilter)->p_owner = (filter_owner_sys_t *)
449 p_sys->p_decoder->p_owner;
450 msg_Err( p_stream, "Added video filter %s to the chain",
455 /* Crap ... we didn't find a filter */
457 "no video filter matching name \"%s\" found",
459 vlc_object_detach( *pp_vfilter );
460 vlc_object_release( *pp_vfilter );
466 return (sout_stream_id_t *)p_sys;
469 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
472 sout_stream_sys_t *p_sys = p_stream->p_sys;
475 bool b_last_es = true;
476 filter_t **pp_vfilter, **pp_end;
479 if ( !p_sys->b_inited )
484 if ( p_sys->p_decoder != NULL )
486 picture_t **pp_ring = p_sys->p_decoder->p_owner->pp_pics;
488 if( p_sys->p_decoder->p_module )
489 module_Unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
490 vlc_object_detach( p_sys->p_decoder );
491 vlc_object_release( p_sys->p_decoder );
493 for( i = 0; i < PICTURE_RING_SIZE; i++ )
495 if ( pp_ring[i] != NULL )
497 free( pp_ring[i]->p_data_orig );
498 free( pp_ring[i]->p_sys );
504 /* Destroy user specified video filters */
505 pp_vfilter = p_sys->pp_vfilters;
506 pp_end = pp_vfilter + p_sys->i_vfilters;
507 for( ; pp_vfilter < pp_end; pp_vfilter++ )
509 vlc_object_detach( *pp_vfilter );
510 if( (*pp_vfilter)->p_module )
511 module_Unneed( *pp_vfilter, (*pp_vfilter)->p_module );
512 vlc_object_release( *pp_vfilter );
514 free( p_sys->pp_vfilters );
516 vlc_mutex_lock( p_sys->p_lock );
518 p_bridge = GetBridge( p_stream );
521 p_es->b_empty = true;
522 while ( p_es->p_picture )
524 picture_t *p_next = p_es->p_picture->p_next;
525 p_es->p_picture->pf_release( p_es->p_picture );
526 p_es->p_picture = p_next;
529 for ( i = 0; i < p_bridge->i_es_num; i++ )
531 if ( !p_bridge->pp_es[i]->b_empty )
540 vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
541 for ( i = 0; i < p_bridge->i_es_num; i++ )
542 free( p_bridge->pp_es[i] );
543 free( p_bridge->pp_es );
545 var_Destroy( p_libvlc, "mosaic-struct" );
548 vlc_mutex_unlock( p_sys->p_lock );
550 if ( p_sys->p_image )
552 image_HandlerDelete( p_sys->p_image );
555 p_sys->b_inited = false;
560 /*****************************************************************************
561 * PushPicture : push a picture in the mosaic-struct structure
562 *****************************************************************************/
563 static void PushPicture( sout_stream_t *p_stream, picture_t *p_picture )
565 sout_stream_sys_t *p_sys = p_stream->p_sys;
566 bridged_es_t *p_es = p_sys->p_es;
568 vlc_mutex_lock( p_sys->p_lock );
570 *p_es->pp_last = p_picture;
571 p_picture->p_next = NULL;
572 p_es->pp_last = &p_picture->p_next;
574 vlc_mutex_unlock( p_sys->p_lock );
577 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
580 sout_stream_sys_t *p_sys = p_stream->p_sys;
583 if ( (sout_stream_sys_t *)id != p_sys )
585 block_ChainRelease( p_buffer );
589 while ( (p_pic = p_sys->p_decoder->pf_decode_video( p_sys->p_decoder,
592 picture_t *p_new_pic;
594 if( p_sys->i_height || p_sys->i_width )
596 video_format_t fmt_out, fmt_in;
598 memset( &fmt_in, 0, sizeof(video_format_t) );
599 memset( &fmt_out, 0, sizeof(video_format_t) );
600 fmt_in = p_sys->p_decoder->fmt_out.video;
603 if( p_sys->i_chroma )
604 fmt_out.i_chroma = p_sys->i_chroma;
606 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
608 if ( !p_sys->i_height )
610 fmt_out.i_width = p_sys->i_width;
611 fmt_out.i_height = (p_sys->i_width * VOUT_ASPECT_FACTOR
612 * p_sys->i_sar_num / p_sys->i_sar_den / fmt_in.i_aspect)
615 else if ( !p_sys->i_width )
617 fmt_out.i_height = p_sys->i_height;
618 fmt_out.i_width = (p_sys->i_height * fmt_in.i_aspect
619 * p_sys->i_sar_den / p_sys->i_sar_num / VOUT_ASPECT_FACTOR)
624 fmt_out.i_width = p_sys->i_width;
625 fmt_out.i_height = p_sys->i_height;
627 fmt_out.i_visible_width = fmt_out.i_width;
628 fmt_out.i_visible_height = fmt_out.i_height;
630 p_new_pic = image_Convert( p_sys->p_image,
631 p_pic, &fmt_in, &fmt_out );
632 if ( p_new_pic == NULL )
634 msg_Err( p_stream, "image conversion failed" );
640 /* TODO: chroma conversion if needed */
642 p_new_pic = (picture_t*)malloc( sizeof(picture_t) );
643 if( p_new_pic == NULL )
645 msg_Err( p_stream, "image conversion failed" );
649 if( vout_AllocatePicture(
650 p_stream, p_new_pic, p_pic->format.i_chroma,
651 p_pic->format.i_width, p_pic->format.i_height,
652 p_sys->p_decoder->fmt_out.video.i_aspect )
656 msg_Err( p_stream, "image allocation failed" );
660 vout_CopyPicture( p_stream, p_new_pic, p_pic );
663 p_new_pic->i_refcount = 1;
664 p_new_pic->i_status = DESTROYED_PICTURE;
665 p_new_pic->i_type = DIRECT_PICTURE;
666 p_new_pic->p_sys = (picture_sys_t *)p_new_pic->pf_release;
667 p_new_pic->pf_release = ReleasePicture;
668 p_new_pic->date = p_pic->date;
669 p_pic->pf_release( p_pic );
671 if( p_sys->pp_vfilters )
673 /* Apply user specified video filters */
674 filter_t **pp_vfilter = p_sys->pp_vfilters;
675 filter_t **pp_end = pp_vfilter + p_sys->i_vfilters;
676 for( ; pp_vfilter < pp_end; pp_vfilter++ )
678 (*pp_vfilter)->fmt_in.i_codec = p_new_pic->format.i_chroma;
679 (*pp_vfilter)->fmt_out.i_codec = p_new_pic->format.i_chroma;
680 (*pp_vfilter)->fmt_in.video = p_new_pic->format;
681 (*pp_vfilter)->fmt_out.video = p_new_pic->format;
682 p_new_pic = (*pp_vfilter)->pf_video_filter( *pp_vfilter,
686 msg_Err( p_stream, "video filter failed" );
690 if( !p_new_pic ) continue;
693 PushPicture( p_stream, p_new_pic );
701 vlc_object_t *p_owner;
705 static void video_release_buffer_decoder( picture_t *p_pic )
707 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
709 video_del_buffer_decoder( (decoder_t *)p_pic->p_sys->p_owner, p_pic );
711 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
714 static void video_release_buffer_filter( picture_t *p_pic )
716 if( p_pic && !p_pic->i_refcount && p_pic->pf_release && p_pic->p_sys )
718 video_del_buffer_filter( (filter_t *)p_pic->p_sys->p_owner, p_pic );
720 else if( p_pic && p_pic->i_refcount > 0 ) p_pic->i_refcount--;
723 inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
725 return video_new_buffer( VLC_OBJECT( p_dec ),
726 (decoder_owner_sys_t *)p_dec->p_owner,
728 video_release_buffer_decoder );
731 inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
733 return video_new_buffer( VLC_OBJECT( p_filter ),
734 (decoder_owner_sys_t *)p_filter->p_owner,
736 video_release_buffer_filter );
739 static picture_t *video_new_buffer( vlc_object_t *p_this,
740 decoder_owner_sys_t *p_sys,
741 es_format_t *fmt_out,
742 void ( *pf_release )( picture_t * ) )
744 picture_t **pp_ring = p_sys->pp_pics;
748 if( fmt_out->video.i_width != p_sys->video.i_width ||
749 fmt_out->video.i_height != p_sys->video.i_height ||
750 fmt_out->video.i_chroma != p_sys->video.i_chroma ||
751 fmt_out->video.i_aspect != p_sys->video.i_aspect )
753 if( !fmt_out->video.i_sar_num ||
754 !fmt_out->video.i_sar_den )
756 fmt_out->video.i_sar_num =
757 fmt_out->video.i_aspect * fmt_out->video.i_height;
759 fmt_out->video.i_sar_den =
760 VOUT_ASPECT_FACTOR * fmt_out->video.i_width;
763 vlc_ureduce( &fmt_out->video.i_sar_num,
764 &fmt_out->video.i_sar_den,
765 fmt_out->video.i_sar_num,
766 fmt_out->video.i_sar_den, 0 );
768 if( !fmt_out->video.i_visible_width ||
769 !fmt_out->video.i_visible_height )
771 fmt_out->video.i_visible_width = fmt_out->video.i_width;
772 fmt_out->video.i_visible_height = fmt_out->video.i_height;
775 fmt_out->video.i_chroma = fmt_out->i_codec;
776 p_sys->video = fmt_out->video;
778 for( i = 0; i < PICTURE_RING_SIZE; i++ )
780 if ( pp_ring[i] != NULL )
782 if ( pp_ring[i]->i_status == DESTROYED_PICTURE )
784 free( pp_ring[i]->p_data_orig );
785 free( pp_ring[i]->p_sys );
790 pp_ring[i]->p_sys->b_dead = true;
797 /* Find an empty space in the picture ring buffer */
798 for( i = 0; i < PICTURE_RING_SIZE; i++ )
800 if( pp_ring[i] != NULL && pp_ring[i]->i_status == DESTROYED_PICTURE )
802 pp_ring[i]->i_status = RESERVED_PICTURE;
806 for( i = 0; i < PICTURE_RING_SIZE; i++ )
808 if( pp_ring[i] == NULL ) break;
811 if( i == PICTURE_RING_SIZE )
813 msg_Err( p_this, "decoder/filter is leaking pictures, "
814 "resetting its ring buffer" );
816 for( i = 0; i < PICTURE_RING_SIZE; i++ )
818 pp_ring[i]->pf_release( pp_ring[i] );
824 p_pic = malloc( sizeof(picture_t) );
825 if( !p_pic ) return NULL;
826 fmt_out->video.i_chroma = fmt_out->i_codec;
827 vout_AllocatePicture( p_this, p_pic,
828 fmt_out->video.i_chroma,
829 fmt_out->video.i_width,
830 fmt_out->video.i_height,
831 fmt_out->video.i_aspect );
833 if( !p_pic->i_planes )
839 p_pic->pf_release = pf_release;
840 p_pic->p_sys = malloc( sizeof(picture_sys_t) );
841 p_pic->p_sys->p_owner = p_this;
842 p_pic->p_sys->b_dead = false;
843 p_pic->i_status = RESERVED_PICTURE;
850 inline static void video_del_buffer_decoder( decoder_t *p_this,
854 video_del_buffer( p_pic );
857 inline static void video_del_buffer_filter( filter_t *p_this,
861 video_del_buffer( p_pic );
864 static void video_del_buffer( picture_t *p_pic )
866 p_pic->i_refcount = 0;
867 p_pic->i_status = DESTROYED_PICTURE;
868 if ( p_pic->p_sys->b_dead )
870 free( p_pic->p_data_orig );
871 free( p_pic->p_sys );
876 static void video_link_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
882 static void video_unlink_picture_decoder( decoder_t *p_dec, picture_t *p_pic )
885 video_release_buffer_decoder( p_pic );
889 /**********************************************************************
890 * Callback to update (some) params on the fly
891 **********************************************************************/
892 static int HeightCallback( vlc_object_t *p_this, char const *psz_var,
893 vlc_value_t oldval, vlc_value_t newval,
896 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
897 sout_stream_t *p_stream = (sout_stream_t *)p_data;
898 sout_stream_sys_t *p_sys = p_stream->p_sys;
900 /* We create the handler before updating the value in p_sys
901 * so we don't have to worry about locking */
902 if( !p_sys->p_image && newval.i_int )
903 p_sys->p_image = image_HandlerCreate( p_stream );
904 p_sys->i_height = newval.i_int;
909 static int WidthCallback( vlc_object_t *p_this, char const *psz_var,
910 vlc_value_t oldval, vlc_value_t newval,
913 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
914 sout_stream_t *p_stream = (sout_stream_t *)p_data;
915 sout_stream_sys_t *p_sys = p_stream->p_sys;
917 /* We create the handler before updating the value in p_sys
918 * so we don't have to worry about locking */
919 if( !p_sys->p_image && newval.i_int )
920 p_sys->p_image = image_HandlerCreate( p_stream );
921 p_sys->i_width = newval.i_int;
926 static int alphaCallback( vlc_object_t *p_this, char const *psz_var,
927 vlc_value_t oldval, vlc_value_t newval,
930 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
931 sout_stream_t *p_stream = (sout_stream_t *)p_data;
932 sout_stream_sys_t *p_sys = p_stream->p_sys;
935 p_sys->p_es->i_alpha = newval.i_int;
940 static int xCallback( vlc_object_t *p_this, char const *psz_var,
941 vlc_value_t oldval, vlc_value_t newval,
944 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
945 sout_stream_t *p_stream = (sout_stream_t *)p_data;
946 sout_stream_sys_t *p_sys = p_stream->p_sys;
949 p_sys->p_es->i_x = newval.i_int;
954 static int yCallback( vlc_object_t *p_this, char const *psz_var,
955 vlc_value_t oldval, vlc_value_t newval,
958 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
959 sout_stream_t *p_stream = (sout_stream_t *)p_data;
960 sout_stream_sys_t *p_sys = p_stream->p_sys;
963 p_sys->p_es->i_y = newval.i_int;