1 /*****************************************************************************
2 * video_output.c : video output thread
4 * This module describes the programming interface for video output threads.
5 * It includes functions allowing to open a new thread, send pictures to a
6 * thread, and destroy a previously oppened video output thread.
7 *****************************************************************************
8 * Copyright (C) 2000-2004 the VideoLAN team
11 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * Gildas Bazin <gbazin@videolan.org>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
29 /*****************************************************************************
31 *****************************************************************************/
34 #include <stdlib.h> /* free() */
38 #ifdef HAVE_SYS_TIMES_H
39 # include <sys/times.h>
42 #include "vlc_video.h"
43 #include "video_output.h"
45 #include <vlc/input.h> /* for input_thread_t and i_pts_delay */
46 #include "vlc_playlist.h"
48 #include "vlc_filter.h"
49 #include <vlc/sout.h> /* sout_CfgParse */
51 #if defined( __APPLE__ )
52 #include "darwin_specific.h"
55 /*****************************************************************************
57 *****************************************************************************/
58 static int InitThread ( vout_thread_t * );
59 static void RunThread ( vout_thread_t * );
60 static void ErrorThread ( vout_thread_t * );
61 static void EndThread ( vout_thread_t * );
62 static void DestroyThread ( vout_thread_t * );
64 static void AspectRatio ( int, int *, int * );
65 static int BinaryLog ( uint32_t );
66 static void MaskToShift ( int *, int *, uint32_t );
68 /* Object variables callbacks */
69 static int DeinterlaceCallback( vlc_object_t *, char const *,
70 vlc_value_t, vlc_value_t, void * );
71 static int FilterCallback( vlc_object_t *, char const *,
72 vlc_value_t, vlc_value_t, void * );
73 static int VideoFilter2Callback( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
76 /* From vout_intf.c */
77 int vout_Snapshot( vout_thread_t *, picture_t * );
79 /* Video filter2 parsing */
80 static int ParseVideoFilter2Chain( vout_thread_t *, char * );
81 static void RemoveVideoFilters2( vout_thread_t *p_vout );
83 /*****************************************************************************
84 * Video Filter2 functions
85 *****************************************************************************/
86 struct filter_owner_sys_t
88 vout_thread_t *p_vout;
91 static picture_t *video_new_buffer_filter( filter_t *p_filter )
94 vout_thread_t *p_vout = p_filter->p_owner->p_vout;
96 p_picture = vout_CreatePicture( p_vout, 0, 0, 0 );
101 static void video_del_buffer_filter( filter_t *p_filter, picture_t *p_pic )
103 vout_DestroyPicture( p_filter->p_owner->p_vout, p_pic );
106 /*****************************************************************************
107 * vout_Request: find a video output thread, create one, or destroy one.
108 *****************************************************************************
109 * This function looks for a video output thread matching the current
110 * properties. If not found, it spawns a new one.
111 *****************************************************************************/
112 vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout,
113 video_format_t *p_fmt )
117 /* Reattach video output to playlist before bailing out */
120 playlist_t *p_playlist = pl_Yield( p_this );
121 spu_Attach( p_vout->p_spu, p_this, VLC_FALSE );
122 vlc_object_detach( p_vout );
123 vlc_object_attach( p_vout, p_playlist );
124 pl_Release( p_this );
129 /* If a video output was provided, lock it, otherwise look for one. */
132 vlc_object_yield( p_vout );
136 p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT, FIND_CHILD );
140 playlist_t *p_playlist = pl_Yield( p_this );
141 vlc_mutex_lock( &p_playlist->gc_lock );
142 p_vout = vlc_object_find( p_playlist,
143 VLC_OBJECT_VOUT, FIND_CHILD );
144 /* only first children of p_input for unused vout */
145 if( p_vout && p_vout->p_parent != (vlc_object_t *)p_playlist )
147 vlc_object_release( p_vout );
150 vlc_mutex_unlock( &p_playlist->gc_lock );
151 pl_Release( p_this );
155 /* If we now have a video output, check it has the right properties */
158 char *psz_filter_chain;
161 /* We don't directly check for the "vout-filter" variable for obvious
162 * performance reasons. */
163 if( p_vout->b_filter_change )
165 var_Get( p_vout, "vout-filter", &val );
166 psz_filter_chain = val.psz_string;
168 if( psz_filter_chain && !*psz_filter_chain )
170 free( psz_filter_chain );
171 psz_filter_chain = NULL;
173 if( p_vout->psz_filter_chain && !*p_vout->psz_filter_chain )
175 free( p_vout->psz_filter_chain );
176 p_vout->psz_filter_chain = NULL;
179 if( !psz_filter_chain && !p_vout->psz_filter_chain )
181 p_vout->b_filter_change = VLC_FALSE;
184 if( psz_filter_chain ) free( psz_filter_chain );
187 if( ( p_vout->fmt_render.i_width != p_fmt->i_width ) ||
188 ( p_vout->fmt_render.i_height != p_fmt->i_height ) ||
189 ( p_vout->fmt_render.i_chroma != p_fmt->i_chroma ) ||
190 ( p_vout->fmt_render.i_aspect != p_fmt->i_aspect ) ||
191 p_vout->b_filter_change )
193 /* We are not interested in this format, close this vout */
194 vlc_object_detach( p_vout );
195 vlc_object_release( p_vout );
196 vout_Destroy( p_vout );
201 /* This video output is cool! Hijack it. */
202 vlc_object_detach( p_vout );
203 spu_Attach( p_vout->p_spu, p_this, VLC_TRUE );
204 vlc_object_attach( p_vout, p_this );
205 vlc_object_release( p_vout );
211 msg_Dbg( p_this, "no usable vout present, spawning one" );
213 p_vout = vout_Create( p_this, p_fmt );
219 /*****************************************************************************
220 * vout_Create: creates a new video output thread
221 *****************************************************************************
222 * This function creates a new video output thread, and returns a pointer
223 * to its description. On error, it returns NULL.
224 *****************************************************************************/
225 vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
227 vout_thread_t * p_vout; /* thread descriptor */
228 input_thread_t * p_input_thread;
229 int i_index; /* loop variable */
231 vlc_value_t val, text;
233 unsigned int i_width = p_fmt->i_width;
234 unsigned int i_height = p_fmt->i_height;
235 vlc_fourcc_t i_chroma = p_fmt->i_chroma;
236 unsigned int i_aspect = p_fmt->i_aspect;
238 /* Allocate descriptor */
239 p_vout = vlc_object_create( p_parent, VLC_OBJECT_VOUT );
242 msg_Err( p_parent, "out of memory" );
246 /* Initialize pictures - translation tables and functions
247 * will be initialized later in InitThread */
248 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++)
250 p_vout->p_picture[i_index].pf_lock = NULL;
251 p_vout->p_picture[i_index].pf_unlock = NULL;
252 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
253 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
254 p_vout->p_picture[i_index].b_slow = 0;
257 /* No images in the heap */
258 p_vout->i_heap_size = 0;
260 /* Initialize the rendering heap */
261 I_RENDERPICTURES = 0;
263 vlc_ureduce( &p_fmt->i_sar_num, &p_fmt->i_sar_den,
264 p_fmt->i_sar_num, p_fmt->i_sar_den, 50000 );
265 p_vout->fmt_render = *p_fmt; /* FIXME palette */
266 p_vout->fmt_in = *p_fmt; /* FIXME palette */
268 p_vout->render.i_width = i_width;
269 p_vout->render.i_height = i_height;
270 p_vout->render.i_chroma = i_chroma;
271 p_vout->render.i_aspect = i_aspect;
273 p_vout->render.i_rmask = 0;
274 p_vout->render.i_gmask = 0;
275 p_vout->render.i_bmask = 0;
277 p_vout->render.i_last_used_pic = -1;
278 p_vout->render.b_allow_modify_pics = 1;
280 /* Zero the output heap */
281 I_OUTPUTPICTURES = 0;
282 p_vout->output.i_width = 0;
283 p_vout->output.i_height = 0;
284 p_vout->output.i_chroma = 0;
285 p_vout->output.i_aspect = 0;
287 p_vout->output.i_rmask = 0;
288 p_vout->output.i_gmask = 0;
289 p_vout->output.i_bmask = 0;
291 /* Initialize misc stuff */
292 p_vout->i_changes = 0;
294 p_vout->b_grayscale = 0;
296 p_vout->b_interface = 0;
298 p_vout->b_fullscreen = 0;
299 p_vout->i_alignment = 0;
300 p_vout->render_time = 10;
301 p_vout->c_fps_samples = 0;
302 p_vout->b_filter_change = 0;
303 p_vout->pf_control = 0;
304 p_vout->p_parent_intf = 0;
305 p_vout->i_par_num = p_vout->i_par_den = 1;
307 /* Initialize locks */
308 vlc_mutex_init( p_vout, &p_vout->picture_lock );
309 vlc_mutex_init( p_vout, &p_vout->change_lock );
311 /* Mouse coordinates */
312 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
313 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
314 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
315 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
316 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
318 /* Initialize subpicture unit */
319 p_vout->p_spu = spu_Create( p_vout );
320 spu_Attach( p_vout->p_spu, p_parent, VLC_TRUE );
322 /* Attach the new object now so we can use var inheritance below */
323 vlc_object_attach( p_vout, p_parent );
325 spu_Init( p_vout->p_spu );
327 /* Take care of some "interface/control" related initialisations */
328 vout_IntfInit( p_vout );
330 /* If the parent is not a VOUT object, that means we are at the start of
331 * the video output pipe */
332 if( p_parent->i_object_type != VLC_OBJECT_VOUT )
334 /* Look for the default filter configuration */
335 var_Create( p_vout, "vout-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
336 var_Get( p_vout, "vout-filter", &val );
337 p_vout->psz_filter_chain = val.psz_string;
339 /* Apply video filter2 objects on the first vout */
340 var_Create( p_vout, "video-filter",
341 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
342 var_Get( p_vout, "video-filter", &val );
343 ParseVideoFilter2Chain( p_vout, val.psz_string );
344 free( val.psz_string );
348 /* continue the parent's filter chain */
351 psz_end = strchr( ((vout_thread_t *)p_parent)->psz_filter_chain, ':' );
352 if( psz_end && *(psz_end+1) )
353 p_vout->psz_filter_chain = strdup( psz_end+1 );
354 else p_vout->psz_filter_chain = NULL;
356 /* Create a video filter2 var ... but don't inherit values */
357 var_Create( p_vout, "video-filter", VLC_VAR_STRING );
358 ParseVideoFilter2Chain( p_vout, NULL );
361 var_AddCallback( p_vout, "video-filter", VideoFilter2Callback, NULL );
362 p_vout->b_vfilter_change = VLC_TRUE;
363 p_vout->i_vfilters = 0;
365 /* Choose the video output module */
366 if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
368 var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
369 var_Get( p_vout, "vout", &val );
370 psz_plugin = val.psz_string;
374 /* the filter chain is a string list of filters separated by double
378 psz_end = strchr( p_vout->psz_filter_chain, ':' );
380 psz_plugin = strndup( p_vout->psz_filter_chain,
381 psz_end - p_vout->psz_filter_chain );
382 else psz_plugin = strdup( p_vout->psz_filter_chain );
385 /* Create the vout thread */
386 p_vout->p_module = module_Need( p_vout,
387 ( p_vout->psz_filter_chain && *p_vout->psz_filter_chain ) ?
388 "video filter" : "video output", psz_plugin, 0 );
390 if( psz_plugin ) free( psz_plugin );
391 if( p_vout->p_module == NULL )
393 msg_Err( p_vout, "no suitable vout module" );
394 vlc_object_detach( p_vout );
395 vlc_object_destroy( p_vout );
399 /* Create a few object variables for interface interaction */
400 var_Create( p_vout, "deinterlace", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
401 text.psz_string = _("Deinterlace");
402 var_Change( p_vout, "deinterlace", VLC_VAR_SETTEXT, &text, NULL );
403 val.psz_string = ""; text.psz_string = _("Disable");
404 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
405 val.psz_string = "discard"; text.psz_string = _("Discard");
406 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
407 val.psz_string = "blend"; text.psz_string = _("Blend");
408 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
409 val.psz_string = "mean"; text.psz_string = _("Mean");
410 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
411 val.psz_string = "bob"; text.psz_string = _("Bob");
412 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
413 val.psz_string = "linear"; text.psz_string = _("Linear");
414 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
415 val.psz_string = "x"; text.psz_string = "X";
416 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
418 if( var_Get( p_vout, "deinterlace-mode", &val ) == VLC_SUCCESS )
420 var_Set( p_vout, "deinterlace", val );
421 if( val.psz_string ) free( val.psz_string );
423 var_AddCallback( p_vout, "deinterlace", DeinterlaceCallback, NULL );
426 var_Create( p_vout, "vout-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
427 text.psz_string = _("Filters");
428 var_Change( p_vout, "vout-filter", VLC_VAR_SETTEXT, &text, NULL );
429 var_AddCallback( p_vout, "vout-filter", FilterCallback, NULL );
431 /* Calculate delay created by internal caching */
432 p_input_thread = (input_thread_t *)vlc_object_find( p_vout,
433 VLC_OBJECT_INPUT, FIND_ANYWHERE );
436 p_vout->i_pts_delay = p_input_thread->i_pts_delay;
437 vlc_object_release( p_input_thread );
441 p_vout->i_pts_delay = DEFAULT_PTS_DELAY;
444 if( vlc_thread_create( p_vout, "video output", RunThread,
445 VLC_THREAD_PRIORITY_OUTPUT, VLC_TRUE ) )
447 msg_Err( p_vout, "out of memory" );
448 module_Unneed( p_vout, p_vout->p_module );
449 vlc_object_detach( p_vout );
450 vlc_object_destroy( p_vout );
454 if( p_vout->b_error )
456 msg_Err( p_vout, "video output creation failed" );
458 /* Make sure the thread is destroyed */
459 p_vout->b_die = VLC_TRUE;
461 vlc_thread_join( p_vout );
463 vlc_object_detach( p_vout );
464 vlc_object_destroy( p_vout );
471 /*****************************************************************************
472 * vout_Destroy: destroys a previously created video output
473 *****************************************************************************
474 * Destroy a terminated thread.
475 * The function will request a destruction of the specified thread. If pi_error
476 * is NULL, it will return once the thread is destroyed. Else, it will be
477 * update using one of the THREAD_* constants.
478 *****************************************************************************/
479 void vout_Destroy( vout_thread_t *p_vout )
481 vout_thread_t *p_another_vout;
482 playlist_t *p_playlist = pl_Yield( p_vout );
484 /* Request thread destruction */
485 p_vout->b_die = VLC_TRUE;
486 vlc_thread_join( p_vout );
488 var_Destroy( p_vout, "intf-change" );
490 if( p_vout->psz_filter_chain ) free( p_vout->psz_filter_chain );
493 vlc_object_destroy( p_vout );
495 p_another_vout = vlc_object_find( p_playlist,
496 VLC_OBJECT_VOUT, FIND_ANYWHERE );
497 if( p_another_vout == NULL )
500 val.b_bool = VLC_TRUE;
501 var_Set( p_playlist, "intf-show", val );
505 vlc_object_release( p_another_vout );
507 vlc_object_release( p_playlist );
510 /*****************************************************************************
511 * InitThread: initialize video output thread
512 *****************************************************************************
513 * This function is called from RunThread and performs the second step of the
514 * initialization. It returns 0 on success. Note that the thread's flag are not
515 * modified inside this function.
516 *****************************************************************************/
517 static int InitThread( vout_thread_t *p_vout )
519 int i, i_aspect_x, i_aspect_y;
521 vlc_mutex_lock( &p_vout->change_lock );
527 /* Initialize output method, it allocates direct buffers for us */
528 if( p_vout->pf_init( p_vout ) )
530 vlc_mutex_unlock( &p_vout->change_lock );
534 if( !I_OUTPUTPICTURES )
536 msg_Err( p_vout, "plugin was unable to allocate at least "
537 "one direct buffer" );
538 p_vout->pf_end( p_vout );
539 vlc_mutex_unlock( &p_vout->change_lock );
543 if( I_OUTPUTPICTURES > VOUT_MAX_PICTURES )
545 msg_Err( p_vout, "plugin allocated too many direct buffers, "
546 "our internal buffers must have overflown." );
547 p_vout->pf_end( p_vout );
548 vlc_mutex_unlock( &p_vout->change_lock );
552 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
554 AspectRatio( p_vout->fmt_render.i_aspect, &i_aspect_x, &i_aspect_y );
556 msg_Dbg( p_vout, "picture in %ix%i (%i,%i,%ix%i), "
557 "chroma %4.4s, ar %i:%i, sar %i:%i",
558 p_vout->fmt_render.i_width, p_vout->fmt_render.i_height,
559 p_vout->fmt_render.i_x_offset, p_vout->fmt_render.i_y_offset,
560 p_vout->fmt_render.i_visible_width,
561 p_vout->fmt_render.i_visible_height,
562 (char*)&p_vout->fmt_render.i_chroma,
563 i_aspect_x, i_aspect_y,
564 p_vout->fmt_render.i_sar_num, p_vout->fmt_render.i_sar_den );
566 AspectRatio( p_vout->fmt_in.i_aspect, &i_aspect_x, &i_aspect_y );
568 msg_Dbg( p_vout, "picture user %ix%i (%i,%i,%ix%i), "
569 "chroma %4.4s, ar %i:%i, sar %i:%i",
570 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
571 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
572 p_vout->fmt_in.i_visible_width,
573 p_vout->fmt_in.i_visible_height,
574 (char*)&p_vout->fmt_in.i_chroma,
575 i_aspect_x, i_aspect_y,
576 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
578 if( !p_vout->fmt_out.i_width || !p_vout->fmt_out.i_height )
580 p_vout->fmt_out.i_width = p_vout->fmt_out.i_visible_width =
581 p_vout->output.i_width;
582 p_vout->fmt_out.i_height = p_vout->fmt_out.i_visible_height =
583 p_vout->output.i_height;
584 p_vout->fmt_out.i_x_offset = p_vout->fmt_out.i_y_offset = 0;
586 p_vout->fmt_out.i_aspect = p_vout->output.i_aspect;
587 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
589 if( !p_vout->fmt_out.i_sar_num || !p_vout->fmt_out.i_sar_num )
591 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_aspect *
592 p_vout->fmt_out.i_height;
593 p_vout->fmt_out.i_sar_den = VOUT_ASPECT_FACTOR *
594 p_vout->fmt_out.i_width;
597 vlc_ureduce( &p_vout->fmt_out.i_sar_num, &p_vout->fmt_out.i_sar_den,
598 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den, 0 );
600 AspectRatio( p_vout->fmt_out.i_aspect, &i_aspect_x, &i_aspect_y );
602 msg_Dbg( p_vout, "picture out %ix%i (%i,%i,%ix%i), "
603 "chroma %4.4s, ar %i:%i, sar %i:%i",
604 p_vout->fmt_out.i_width, p_vout->fmt_out.i_height,
605 p_vout->fmt_out.i_x_offset, p_vout->fmt_out.i_y_offset,
606 p_vout->fmt_out.i_visible_width,
607 p_vout->fmt_out.i_visible_height,
608 (char*)&p_vout->fmt_out.i_chroma,
609 i_aspect_x, i_aspect_y,
610 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den );
612 /* Calculate shifts from system-updated masks */
613 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
614 p_vout->output.i_rmask );
615 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
616 p_vout->output.i_gmask );
617 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
618 p_vout->output.i_bmask );
620 /* Check whether we managed to create direct buffers similar to
621 * the render buffers, ie same size and chroma */
622 if( ( p_vout->output.i_width == p_vout->render.i_width )
623 && ( p_vout->output.i_height == p_vout->render.i_height )
624 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) ) )
626 /* Cool ! We have direct buffers, we can ask the decoder to
627 * directly decode into them ! Map the first render buffers to
628 * the first direct buffers, but keep the first direct buffer
629 * for memcpy operations */
630 p_vout->b_direct = 1;
632 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
634 if( p_vout->p_picture[ i ].i_type != DIRECT_PICTURE &&
635 I_RENDERPICTURES >= VOUT_MIN_DIRECT_PICTURES - 1 &&
636 p_vout->p_picture[ i - 1 ].i_type == DIRECT_PICTURE )
638 /* We have enough direct buffers so there's no need to
639 * try to use system memory buffers. */
642 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
646 msg_Dbg( p_vout, "direct render, mapping "
647 "render pictures 0-%i to system pictures 1-%i",
648 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
652 /* Rats... Something is wrong here, we could not find an output
653 * plugin able to directly render what we decode. See if we can
654 * find a chroma plugin to do the conversion */
655 p_vout->b_direct = 0;
657 /* Choose the best module */
658 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
660 if( p_vout->chroma.p_module == NULL )
662 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
663 (char*)&p_vout->render.i_chroma,
664 (char*)&p_vout->output.i_chroma );
665 p_vout->pf_end( p_vout );
666 vlc_mutex_unlock( &p_vout->change_lock );
670 msg_Dbg( p_vout, "indirect render, mapping "
671 "render pictures 0-%i to system pictures %i-%i",
672 VOUT_MAX_PICTURES - 1, I_OUTPUTPICTURES,
673 I_OUTPUTPICTURES + VOUT_MAX_PICTURES - 1 );
675 /* Append render buffers after the direct buffers */
676 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
678 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
681 /* Check if we have enough render pictures */
682 if( I_RENDERPICTURES == VOUT_MAX_PICTURES )
687 /* Link pictures back to their heap */
688 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
690 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
693 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
695 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
698 /* XXX XXX mark thread ready */
702 /*****************************************************************************
703 * RunThread: video output thread
704 *****************************************************************************
705 * Video output thread. This function does only returns when the thread is
706 * terminated. It handles the pictures arriving in the video heap and the
707 * display device events.
708 *****************************************************************************/
709 static void RunThread( vout_thread_t *p_vout)
711 int i_index; /* index in heap */
712 int i_idle_loops = 0; /* loops without displaying a picture */
713 mtime_t current_date; /* current date */
714 mtime_t display_date; /* display date */
716 picture_t * p_picture; /* picture pointer */
717 picture_t * p_last_picture = NULL; /* last picture */
718 picture_t * p_directbuffer; /* direct buffer to display */
720 subpicture_t * p_subpic = NULL; /* subpicture pointer */
722 input_thread_t *p_input = NULL ; /* Parent input, if it exists */
725 vlc_bool_t b_drop_late;
727 int i_displayed = 0, i_lost = 0, i_loops = 0;
732 p_vout->b_error = InitThread( p_vout );
734 var_Create( p_vout, "drop-late-frames", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
735 var_Get( p_vout, "drop-late-frames", &val );
736 b_drop_late = val.b_bool;
738 /* signal the creation of the vout */
739 vlc_thread_ready( p_vout );
741 if( p_vout->b_error )
743 /* Destroy thread structures allocated by Create and InitThread */
744 DestroyThread( p_vout );
749 * Main loop - it is not executed if an error occurred during
752 while( (!p_vout->b_die) && (!p_vout->b_error) )
754 /* Initialize loop variables */
757 current_date = mdate();
759 if( p_input && p_input->b_die )
761 vlc_object_release( p_input );
766 if( i_loops % 20 == 0 )
770 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT,
775 vlc_mutex_lock( &p_input->counters.counters_lock );
776 stats_UpdateInteger( p_vout, p_input->counters.p_lost_pictures,
778 stats_UpdateInteger( p_vout,
779 p_input->counters.p_displayed_pictures,
781 i_displayed = i_lost = 0;
782 vlc_mutex_unlock( &p_input->counters.counters_lock );
787 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
789 msg_Dbg( p_vout, "picture heap: %d/%d",
790 I_RENDERPICTURES, p_vout->i_heap_size );
795 * Find the picture to display (the one with the earliest date).
796 * This operation does not need lock, since only READY_PICTUREs
798 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
800 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
801 && ( (p_picture == NULL) ||
802 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
804 p_picture = PP_RENDERPICTURE[i_index];
805 display_date = p_picture->date;
811 /* If we met the last picture, parse again to see whether there is
812 * a more appropriate one. */
813 if( p_picture == p_last_picture )
815 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
817 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
818 && (PP_RENDERPICTURE[i_index] != p_last_picture)
819 && ((p_picture == p_last_picture) ||
820 (PP_RENDERPICTURE[i_index]->date < display_date)) )
822 p_picture = PP_RENDERPICTURE[i_index];
823 display_date = p_picture->date;
828 /* If we found better than the last picture, destroy it */
829 if( p_last_picture && p_picture != p_last_picture )
831 vlc_mutex_lock( &p_vout->picture_lock );
832 if( p_last_picture->i_refcount )
834 p_last_picture->i_status = DISPLAYED_PICTURE;
838 p_last_picture->i_status = DESTROYED_PICTURE;
839 p_vout->i_heap_size--;
841 vlc_mutex_unlock( &p_vout->picture_lock );
842 p_last_picture = NULL;
845 /* Compute FPS rate */
846 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
849 if( !p_picture->b_force &&
850 p_picture != p_last_picture &&
851 display_date < current_date + p_vout->render_time &&
854 /* Picture is late: it will be destroyed and the thread
855 * will directly choose the next picture */
856 vlc_mutex_lock( &p_vout->picture_lock );
857 if( p_picture->i_refcount )
859 /* Pretend we displayed the picture, but don't destroy
860 * it since the decoder might still need it. */
861 p_picture->i_status = DISPLAYED_PICTURE;
865 /* Destroy the picture without displaying it */
866 p_picture->i_status = DESTROYED_PICTURE;
867 p_vout->i_heap_size--;
869 msg_Warn( p_vout, "late picture skipped ("I64Fd")",
870 current_date - display_date );
872 vlc_mutex_unlock( &p_vout->picture_lock );
878 current_date + p_vout->i_pts_delay + VOUT_BOGUS_DELAY )
880 /* Picture is waaay too early: it will be destroyed */
881 vlc_mutex_lock( &p_vout->picture_lock );
882 if( p_picture->i_refcount )
884 /* Pretend we displayed the picture, but don't destroy
885 * it since the decoder might still need it. */
886 p_picture->i_status = DISPLAYED_PICTURE;
890 /* Destroy the picture without displaying it */
891 p_picture->i_status = DESTROYED_PICTURE;
892 p_vout->i_heap_size--;
895 msg_Warn( p_vout, "vout warning: early picture skipped "
896 "("I64Fd")", display_date - current_date
897 - p_vout->i_pts_delay );
898 vlc_mutex_unlock( &p_vout->picture_lock );
903 if( display_date > current_date + VOUT_DISPLAY_DELAY )
905 /* A picture is ready to be rendered, but its rendering date
906 * is far from the current one so the thread will perform an
907 * empty loop as if no picture were found. The picture state
912 else if( p_picture == p_last_picture )
914 /* We are asked to repeat the previous picture, but we first
915 * wait for a couple of idle loops */
916 if( i_idle_loops < 4 )
923 /* We set the display date to something high, otherwise
924 * we'll have lots of problems with late pictures */
925 display_date = current_date + p_vout->render_time;
930 if( p_picture == NULL )
935 /* Video Filter2 stuff */
936 if( p_vout->b_vfilter_change == VLC_TRUE )
939 RemoveVideoFilters2( p_vout );
940 for( i = 0; i < p_vout->i_vfilters_cfg; i++ )
942 filter_t *p_vfilter =
943 p_vout->pp_vfilters[p_vout->i_vfilters] =
944 vlc_object_create( p_vout, VLC_OBJECT_FILTER );
946 vlc_object_attach( p_vfilter, p_vout );
948 p_vfilter->pf_vout_buffer_new = video_new_buffer_filter;
949 p_vfilter->pf_vout_buffer_del = video_del_buffer_filter;
951 if( !p_vout->i_vfilters )
953 p_vfilter->fmt_in.video = p_vout->fmt_render;
957 p_vfilter->fmt_in.video = (p_vfilter-1)->fmt_out.video;
959 /* TODO: one day filters in the middle of the chain might
960 * have a different fmt_out.video than fmt_render ... */
961 p_vfilter->fmt_out.video = p_vout->fmt_render;
963 p_vfilter->p_cfg = p_vout->p_vfilters_cfg[i];
964 p_vfilter->p_module = module_Need( p_vfilter, "video filter2",
965 p_vout->psz_vfilters[i], 0 );
967 if( p_vfilter->p_module )
970 malloc( sizeof( filter_owner_sys_t ) );
971 p_vfilter->p_owner->p_vout = p_vout;
972 p_vout->i_vfilters++;
973 msg_Dbg( p_vout, "video filter found (%s)",
974 p_vout->psz_vfilters[i] );
978 msg_Err( p_vout, "no video filter found (%s)",
979 p_vout->psz_vfilters[i] );
980 vlc_object_detach( p_vfilter );
981 vlc_object_destroy( p_vfilter );
984 p_vout->b_vfilter_change = VLC_FALSE;
990 for( i = 0; i < p_vout->i_vfilters; i++ )
992 picture_t *p_old = p_picture;
993 p_picture = p_vout->pp_vfilters[i]->pf_video_filter(
994 p_vout->pp_vfilters[i], p_picture );
999 /* FIXME: this is kind of wrong
1000 * if you have 2 or more vfilters and the 2nd breaks,
1001 * on the next loop the 1st one will be applied again */
1003 /* if p_old and p_picture are the same (ie the filter
1004 * worked on the old picture), then following code is
1005 * still alright since i_status gets changed back to
1006 * the right value */
1007 if( p_old->i_refcount )
1009 p_old->i_status = DISPLAYED_PICTURE;
1013 p_old->i_status = DESTROYED_PICTURE;
1015 p_picture->i_status = READY_PICTURE;
1019 if( p_picture && p_vout->b_snapshot )
1021 p_vout->b_snapshot = VLC_FALSE;
1022 vout_Snapshot( p_vout, p_picture );
1026 * Check for subpictures to display
1028 if( display_date > 0 )
1032 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT,
1035 p_subpic = spu_SortSubpictures( p_vout->p_spu, display_date,
1036 p_input ? var_GetBool( p_input, "state" ) == PAUSE_S : VLC_FALSE );
1043 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
1046 * Call the plugin-specific rendering method if there is one
1048 if( p_picture != NULL && p_directbuffer != NULL && p_vout->pf_render )
1050 /* Render the direct buffer returned by vout_RenderPicture */
1051 p_vout->pf_render( p_vout, p_directbuffer );
1057 if( display_date != 0 && p_directbuffer != NULL )
1059 mtime_t current_render_time = mdate() - current_date;
1060 /* if render time is very large we don't include it in the mean */
1061 if( current_render_time < p_vout->render_time +
1062 VOUT_DISPLAY_DELAY )
1064 /* Store render time using a sliding mean weighting to
1065 * current value in a 3 to 1 ratio*/
1066 p_vout->render_time *= 3;
1067 p_vout->render_time += current_render_time;
1068 p_vout->render_time >>= 2;
1072 /* Give back change lock */
1073 vlc_mutex_unlock( &p_vout->change_lock );
1075 /* Sleep a while or until a given date */
1076 if( display_date != 0 )
1078 /* If there are filters in the chain, better give them the picture
1080 if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
1082 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1087 msleep( VOUT_IDLE_SLEEP );
1090 /* On awakening, take back lock and send immediately picture
1092 vlc_mutex_lock( &p_vout->change_lock );
1095 * Display the previously rendered picture
1097 if( p_picture != NULL && p_directbuffer != NULL )
1099 /* Display the direct buffer returned by vout_RenderPicture */
1100 if( p_vout->pf_display )
1102 p_vout->pf_display( p_vout, p_directbuffer );
1105 /* Tell the vout this was the last picture and that it does not
1106 * need to be forced anymore. */
1107 p_last_picture = p_picture;
1108 p_last_picture->b_force = 0;
1111 if( p_picture != NULL )
1113 /* Reinitialize idle loop count */
1118 * Check events and manage thread
1120 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
1122 /* A fatal error occurred, and the thread must terminate
1123 * immediately, without displaying anything - setting b_error to 1
1124 * causes the immediate end of the main while() loop. */
1125 p_vout->b_error = 1;
1128 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
1130 /* this must only happen when the vout plugin is incapable of
1131 * rescaling the picture itself. In this case we need to destroy
1132 * the current picture buffers and recreate new ones with the right
1136 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
1138 p_vout->pf_end( p_vout );
1139 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1140 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
1142 I_OUTPUTPICTURES = 0;
1143 if( p_vout->pf_init( p_vout ) )
1145 msg_Err( p_vout, "cannot resize display" );
1146 /* FIXME: pf_end will be called again in EndThread() */
1147 p_vout->b_error = 1;
1150 /* Need to reinitialise the chroma plugin */
1151 if( p_vout->chroma.p_module )
1153 if( p_vout->chroma.p_module->pf_deactivate )
1154 p_vout->chroma.p_module->pf_deactivate( VLC_OBJECT(p_vout) );
1155 p_vout->chroma.p_module->pf_activate( VLC_OBJECT(p_vout) );
1159 if( p_vout->i_changes & VOUT_PICTURE_BUFFERS_CHANGE )
1161 /* This happens when the picture buffers need to be recreated.
1162 * This is useful on multimonitor displays for instance.
1164 * Warning: This only works when the vout creates only 1 picture
1166 p_vout->i_changes &= ~VOUT_PICTURE_BUFFERS_CHANGE;
1168 if( !p_vout->b_direct )
1170 module_Unneed( p_vout, p_vout->chroma.p_module );
1173 vlc_mutex_lock( &p_vout->picture_lock );
1175 p_vout->pf_end( p_vout );
1177 I_OUTPUTPICTURES = I_RENDERPICTURES = 0;
1179 p_vout->b_error = InitThread( p_vout );
1181 vlc_mutex_unlock( &p_vout->picture_lock );
1187 vlc_object_release( p_input );
1191 * Error loop - wait until the thread destruction is requested
1193 if( p_vout->b_error )
1195 ErrorThread( p_vout );
1199 EndThread( p_vout );
1201 /* Destroy thread structures allocated by CreateThread */
1202 DestroyThread( p_vout );
1205 /*****************************************************************************
1206 * ErrorThread: RunThread() error loop
1207 *****************************************************************************
1208 * This function is called when an error occurred during thread main's loop.
1209 * The thread can still receive feed, but must be ready to terminate as soon
1211 *****************************************************************************/
1212 static void ErrorThread( vout_thread_t *p_vout )
1214 /* Wait until a `die' order */
1215 while( !p_vout->b_die )
1218 msleep( VOUT_IDLE_SLEEP );
1222 /*****************************************************************************
1223 * EndThread: thread destruction
1224 *****************************************************************************
1225 * This function is called when the thread ends after a sucessful
1226 * initialization. It frees all resources allocated by InitThread.
1227 *****************************************************************************/
1228 static void EndThread( vout_thread_t *p_vout )
1230 int i_index; /* index in heap */
1234 struct tms cpu_usage;
1235 times( &cpu_usage );
1237 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
1238 cpu_usage.tms_utime, cpu_usage.tms_stime );
1242 if( !p_vout->b_direct )
1244 module_Unneed( p_vout, p_vout->chroma.p_module );
1247 /* Destroy all remaining pictures */
1248 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++ )
1250 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
1252 free( p_vout->p_picture[i_index].p_data_orig );
1256 /* Destroy subpicture unit */
1257 spu_Attach( p_vout->p_spu, VLC_OBJECT(p_vout), VLC_FALSE );
1258 spu_Destroy( p_vout->p_spu );
1260 /* Destroy the video filters2 */
1261 RemoveVideoFilters2( p_vout );
1263 /* Destroy translation tables */
1264 p_vout->pf_end( p_vout );
1266 /* Release the change lock */
1267 vlc_mutex_unlock( &p_vout->change_lock );
1270 /*****************************************************************************
1271 * DestroyThread: thread destruction
1272 *****************************************************************************
1273 * This function is called when the thread ends. It frees all ressources
1274 * allocated by CreateThread. Status is available at this stage.
1275 *****************************************************************************/
1276 static void DestroyThread( vout_thread_t *p_vout )
1278 /* Destroy the locks */
1279 vlc_mutex_destroy( &p_vout->picture_lock );
1280 vlc_mutex_destroy( &p_vout->change_lock );
1282 /* Release the module */
1283 if( p_vout && p_vout->p_module )
1285 module_Unneed( p_vout, p_vout->p_module );
1289 /* following functions are local */
1291 static int ReduceHeight( int i_ratio )
1293 int i_dummy = VOUT_ASPECT_FACTOR;
1301 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
1302 while( !(i_ratio & 1) && !(i_dummy & 1) )
1309 while( !(i_ratio % 3) && !(i_dummy % 3) )
1316 while( !(i_ratio % 5) && !(i_dummy % 5) )
1326 static void AspectRatio( int i_aspect, int *i_aspect_x, int *i_aspect_y )
1328 unsigned int i_pgcd = ReduceHeight( i_aspect );
1329 *i_aspect_x = i_aspect / i_pgcd;
1330 *i_aspect_y = VOUT_ASPECT_FACTOR / i_pgcd;
1333 /*****************************************************************************
1334 * BinaryLog: computes the base 2 log of a binary value
1335 *****************************************************************************
1336 * This functions is used by MaskToShift, to get a bit index from a binary
1338 *****************************************************************************/
1339 static int BinaryLog( uint32_t i )
1343 if( i == 0 ) return -31337;
1345 if( i & 0xffff0000 ) i_log += 16;
1346 if( i & 0xff00ff00 ) i_log += 8;
1347 if( i & 0xf0f0f0f0 ) i_log += 4;
1348 if( i & 0xcccccccc ) i_log += 2;
1349 if( i & 0xaaaaaaaa ) i_log += 1;
1354 /*****************************************************************************
1355 * MaskToShift: transform a color mask into right and left shifts
1356 *****************************************************************************
1357 * This function is used for obtaining color shifts from masks.
1358 *****************************************************************************/
1359 static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
1361 uint32_t i_low, i_high; /* lower hand higher bits of the mask */
1365 *pi_left = *pi_right = 0;
1370 i_low = i_high = i_mask;
1372 i_low &= - (int32_t)i_low; /* lower bit of the mask */
1373 i_high += i_low; /* higher bit of the mask */
1375 /* Transform bits into an index. Also deal with i_high overflow, which
1376 * is faster than changing the BinaryLog code to handle 64 bit integers. */
1377 i_low = BinaryLog (i_low);
1378 i_high = i_high ? BinaryLog (i_high) : 32;
1380 /* Update pointers and return */
1382 *pi_right = (8 - i_high + i_low);
1385 /*****************************************************************************
1386 * vout_VarCallback: generic callback for intf variables
1387 *****************************************************************************/
1388 int vout_VarCallback( vlc_object_t * p_this, const char * psz_variable,
1389 vlc_value_t old_value, vlc_value_t new_value,
1392 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1394 val.b_bool = VLC_TRUE;
1395 var_Set( p_vout, "intf-change", val );
1399 /*****************************************************************************
1400 * Helper thread for object variables callbacks.
1401 * Only used to avoid deadlocks when using the video embedded mode.
1402 *****************************************************************************/
1403 typedef struct suxor_thread_t
1406 input_thread_t *p_input;
1410 static void SuxorRestartVideoES( suxor_thread_t *p_this )
1414 vlc_thread_ready( p_this );
1416 /* Now restart current video stream */
1417 var_Get( p_this->p_input, "video-es", &val );
1418 if( val.i_int >= 0 )
1421 val_es.i_int = -VIDEO_ES;
1422 var_Set( p_this->p_input, "video-es", val_es );
1423 var_Set( p_this->p_input, "video-es", val );
1426 vlc_object_release( p_this->p_input );
1429 CloseHandle( p_this->thread_id );
1432 vlc_object_destroy( p_this );
1435 /*****************************************************************************
1436 * object variables callbacks: a bunch of object variables are used by the
1437 * interfaces to interact with the vout.
1438 *****************************************************************************/
1439 static int DeinterlaceCallback( vlc_object_t *p_this, char const *psz_cmd,
1440 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1442 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1443 input_thread_t *p_input;
1446 char *psz_mode = newval.psz_string;
1447 char *psz_filter, *psz_deinterlace = NULL;
1449 var_Get( p_vout, "vout-filter", &val );
1450 psz_filter = val.psz_string;
1451 if( psz_filter ) psz_deinterlace = strstr( psz_filter, "deinterlace" );
1453 if( !psz_mode || !*psz_mode )
1455 if( psz_deinterlace )
1457 char *psz_src = psz_deinterlace + sizeof("deinterlace") - 1;
1458 if( psz_src[0] == ':' ) psz_src++;
1459 memmove( psz_deinterlace, psz_src, strlen(psz_src) + 1 );
1462 else if( !psz_deinterlace )
1464 psz_filter = realloc( psz_filter, strlen( psz_filter ) +
1465 sizeof(":deinterlace") );
1466 if( psz_filter && *psz_filter ) strcat( psz_filter, ":" );
1467 strcat( psz_filter, "deinterlace" );
1470 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1472 if( !p_input ) return VLC_EGENERIC;
1474 if( psz_mode && *psz_mode )
1476 /* Modify input as well because the vout might have to be restarted */
1477 val.psz_string = psz_mode;
1478 var_Create( p_input, "deinterlace-mode", VLC_VAR_STRING );
1479 var_Set( p_input, "deinterlace-mode", val );
1481 vlc_object_release( p_input );
1483 val.b_bool = VLC_TRUE;
1484 var_Set( p_vout, "intf-change", val );
1486 val.psz_string = psz_filter;
1487 var_Set( p_vout, "vout-filter", val );
1488 if( psz_filter ) free( psz_filter );
1493 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
1494 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1496 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1497 input_thread_t *p_input;
1500 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1504 msg_Err( p_vout, "Input not found" );
1505 return( VLC_EGENERIC );
1508 val.b_bool = VLC_TRUE;
1509 var_Set( p_vout, "intf-change", val );
1511 /* Modify input as well because the vout might have to be restarted */
1512 val.psz_string = newval.psz_string;
1513 var_Create( p_input, "vout-filter", VLC_VAR_STRING );
1515 var_Set( p_input, "vout-filter", val );
1517 /* Now restart current video stream */
1518 var_Get( p_input, "video-es", &val );
1519 if( val.i_int >= 0 )
1521 suxor_thread_t *p_suxor =
1522 vlc_object_create( p_vout, sizeof(suxor_thread_t) );
1523 p_suxor->p_input = p_input;
1524 p_vout->b_filter_change = VLC_TRUE;
1525 vlc_object_yield( p_input );
1526 vlc_thread_create( p_suxor, "suxor", SuxorRestartVideoES,
1527 VLC_THREAD_PRIORITY_LOW, VLC_FALSE );
1530 vlc_object_release( p_input );
1535 /*****************************************************************************
1536 * Video Filter2 stuff
1537 *****************************************************************************/
1538 static int ParseVideoFilter2Chain( vout_thread_t *p_vout, char *psz_vfilters )
1541 for( i = 0; i < p_vout->i_vfilters_cfg; i++ )
1543 /* FIXME: this should be moved in a separate function */
1544 struct sout_cfg_t *p_cfg =
1545 p_vout->p_vfilters_cfg[p_vout->i_vfilters_cfg];
1548 struct sout_cfg_t *p_next = p_cfg->p_next;
1549 free( p_cfg->psz_name );
1550 free( p_cfg->psz_value );
1556 free( p_vout->psz_vfilters[p_vout->i_vfilters_cfg] );
1558 p_vout->i_vfilters_cfg = 0;
1559 if( psz_vfilters && *psz_vfilters )
1561 char *psz_parser = psz_vfilters;
1563 while( psz_parser && *psz_parser )
1565 psz_parser = sout_CfgCreate(
1566 &p_vout->psz_vfilters[p_vout->i_vfilters_cfg],
1567 &p_vout->p_vfilters_cfg[p_vout->i_vfilters_cfg],
1569 msg_Dbg( p_vout, "adding vfilter: %s\n",
1570 p_vout->psz_vfilters[p_vout->i_vfilters_cfg] );
1571 p_vout->i_vfilters_cfg++;
1572 if( psz_parser && psz_parser )
1574 if( p_vout->i_vfilters_cfg == MAX_VFILTERS )
1577 "maximum number of video filters reached. \"%s\" discarded",
1587 static int VideoFilter2Callback( vlc_object_t *p_this, char const *psz_cmd,
1588 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1590 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1592 ParseVideoFilter2Chain( p_vout, newval.psz_string );
1593 p_vout->b_vfilter_change = VLC_TRUE;
1598 static void RemoveVideoFilters2( vout_thread_t *p_vout )
1601 for( i = 0; i < p_vout->i_vfilters; i++ )
1603 vlc_object_detach( p_vout->pp_vfilters[i] );
1604 if( p_vout->pp_vfilters[i]->p_module )
1606 module_Unneed( p_vout->pp_vfilters[i],
1607 p_vout->pp_vfilters[i]->p_module );
1610 free( p_vout->pp_vfilters[i]->p_owner );
1611 vlc_object_destroy( p_vout->pp_vfilters[i] );
1613 p_vout->i_vfilters = 0;