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-2007 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 *****************************************************************************/
36 #include <vlc_common.h>
38 #include <stdlib.h> /* free() */
42 #ifdef HAVE_SYS_TIMES_H
43 # include <sys/times.h>
47 #include <vlc_playlist.h>
49 #include <vlc_filter.h>
52 #if defined( __APPLE__ )
53 /* Include darwin_specific.h here if needed */
56 /** FIXME This is quite ugly but needed while we don't have counters
58 #include "input/input_internal.h"
60 #include "modules/modules.h"
62 /*****************************************************************************
64 *****************************************************************************/
65 static int InitThread ( vout_thread_t * );
66 static void RunThread ( vout_thread_t * );
67 static void ErrorThread ( vout_thread_t * );
68 static void EndThread ( vout_thread_t * );
70 static void AspectRatio ( int, int *, int * );
71 static int BinaryLog ( uint32_t );
72 static void MaskToShift ( int *, int *, uint32_t );
74 static void vout_Destructor ( vlc_object_t * p_this );
76 /* Object variables callbacks */
77 static int DeinterlaceCallback( vlc_object_t *, char const *,
78 vlc_value_t, vlc_value_t, void * );
79 static int FilterCallback( vlc_object_t *, char const *,
80 vlc_value_t, vlc_value_t, void * );
81 static int VideoFilter2Callback( vlc_object_t *, char const *,
82 vlc_value_t, vlc_value_t, void * );
84 /* From vout_intf.c */
85 int vout_Snapshot( vout_thread_t *, picture_t * );
87 /* Video filter2 parsing */
88 static int ParseVideoFilter2Chain( vout_thread_t *, char * );
89 static void RemoveVideoFilters2( vout_thread_t *p_vout );
91 /* Display media title in OSD */
92 static void DisplayTitleOnOSD( vout_thread_t *p_vout );
94 /*****************************************************************************
95 * Video Filter2 functions
96 *****************************************************************************/
97 struct filter_owner_sys_t
99 vout_thread_t *p_vout;
102 static picture_t *video_new_buffer_filter( filter_t *p_filter )
104 picture_t *p_picture;
105 vout_thread_t *p_vout = p_filter->p_owner->p_vout;
107 p_picture = vout_CreatePicture( p_vout, 0, 0, 0 );
112 static void video_del_buffer_filter( filter_t *p_filter, picture_t *p_pic )
114 vout_DestroyPicture( p_filter->p_owner->p_vout, p_pic );
117 /*****************************************************************************
118 * vout_Request: find a video output thread, create one, or destroy one.
119 *****************************************************************************
120 * This function looks for a video output thread matching the current
121 * properties. If not found, it spawns a new one.
122 *****************************************************************************/
123 vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout,
124 video_format_t *p_fmt )
128 /* Reattach video output to playlist before bailing out */
131 spu_Attach( p_vout->p_spu, p_this, false );
132 vlc_object_detach( p_vout );
133 vlc_object_attach( p_vout, p_this->p_libvlc );
138 /* If a video output was provided, lock it, otherwise look for one. */
141 vlc_object_yield( p_vout );
145 p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT, FIND_CHILD );
149 p_vout = vlc_object_find( p_this->p_libvlc,
150 VLC_OBJECT_VOUT, FIND_CHILD );
151 /* only first children of p_input for unused vout */
152 if( p_vout && p_vout->p_parent != VLC_OBJECT(p_this->p_libvlc) )
154 vlc_object_release( p_vout );
158 vlc_object_detach( p_vout ); /* Remove it from the GC */
162 /* If we now have a video output, check it has the right properties */
165 char *psz_filter_chain;
168 /* We don't directly check for the "vout-filter" variable for obvious
169 * performance reasons. */
170 if( p_vout->b_filter_change )
172 var_Get( p_vout, "vout-filter", &val );
173 psz_filter_chain = val.psz_string;
175 if( psz_filter_chain && !*psz_filter_chain )
177 free( psz_filter_chain );
178 psz_filter_chain = NULL;
180 if( p_vout->psz_filter_chain && !*p_vout->psz_filter_chain )
182 free( p_vout->psz_filter_chain );
183 p_vout->psz_filter_chain = NULL;
186 if( !psz_filter_chain && !p_vout->psz_filter_chain )
188 p_vout->b_filter_change = false;
191 free( psz_filter_chain );
194 if( ( p_vout->fmt_render.i_width != p_fmt->i_width ) ||
195 ( p_vout->fmt_render.i_height != p_fmt->i_height ) ||
196 ( p_vout->fmt_render.i_aspect != p_fmt->i_aspect ) ||
197 p_vout->b_filter_change )
199 /* We are not interested in this format, close this vout */
200 vlc_object_release( p_vout );
201 vlc_object_release( p_vout );
206 /* This video output is cool! Hijack it. */
207 spu_Attach( p_vout->p_spu, p_this, true );
208 vlc_object_attach( p_vout, p_this );
209 if( p_vout->b_title_show )
210 DisplayTitleOnOSD( p_vout );
211 vlc_object_release( p_vout );
217 msg_Dbg( p_this, "no usable vout present, spawning one" );
219 p_vout = vout_Create( p_this, p_fmt );
225 /*****************************************************************************
226 * vout_Create: creates a new video output thread
227 *****************************************************************************
228 * This function creates a new video output thread, and returns a pointer
229 * to its description. On error, it returns NULL.
230 *****************************************************************************/
231 vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
233 vout_thread_t * p_vout; /* thread descriptor */
234 input_thread_t * p_input_thread;
235 int i_index; /* loop variable */
236 vlc_value_t val, text;
238 unsigned int i_width = p_fmt->i_width;
239 unsigned int i_height = p_fmt->i_height;
240 vlc_fourcc_t i_chroma = p_fmt->i_chroma;
241 unsigned int i_aspect = p_fmt->i_aspect;
243 config_chain_t *p_cfg;
247 /* Allocate descriptor */
248 p_vout = vlc_object_create( p_parent, VLC_OBJECT_VOUT );
251 msg_Err( p_parent, "out of memory" );
255 /* Initialize pictures - translation tables and functions
256 * will be initialized later in InitThread */
257 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++)
259 p_vout->p_picture[i_index].pf_lock = NULL;
260 p_vout->p_picture[i_index].pf_unlock = NULL;
261 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
262 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
263 p_vout->p_picture[i_index].b_slow = 0;
266 /* No images in the heap */
267 p_vout->i_heap_size = 0;
269 /* Initialize the rendering heap */
270 I_RENDERPICTURES = 0;
272 vlc_ureduce( &p_fmt->i_sar_num, &p_fmt->i_sar_den,
273 p_fmt->i_sar_num, p_fmt->i_sar_den, 50000 );
274 p_vout->fmt_render = *p_fmt; /* FIXME palette */
275 p_vout->fmt_in = *p_fmt; /* FIXME palette */
277 p_vout->render.i_width = i_width;
278 p_vout->render.i_height = i_height;
279 p_vout->render.i_chroma = i_chroma;
280 p_vout->render.i_aspect = i_aspect;
282 p_vout->render.i_rmask = 0;
283 p_vout->render.i_gmask = 0;
284 p_vout->render.i_bmask = 0;
286 p_vout->render.i_last_used_pic = -1;
287 p_vout->render.b_allow_modify_pics = 1;
289 /* Zero the output heap */
290 I_OUTPUTPICTURES = 0;
291 p_vout->output.i_width = 0;
292 p_vout->output.i_height = 0;
293 p_vout->output.i_chroma = 0;
294 p_vout->output.i_aspect = 0;
296 p_vout->output.i_rmask = 0;
297 p_vout->output.i_gmask = 0;
298 p_vout->output.i_bmask = 0;
300 /* Initialize misc stuff */
301 p_vout->i_changes = 0;
303 p_vout->b_grayscale = 0;
305 p_vout->b_interface = 0;
307 p_vout->b_fullscreen = 0;
308 p_vout->i_alignment = 0;
309 p_vout->render_time = 10;
310 p_vout->c_fps_samples = 0;
311 p_vout->b_filter_change = 0;
312 p_vout->pf_control = 0;
313 p_vout->p_parent_intf = 0;
314 p_vout->i_par_num = p_vout->i_par_den = 1;
316 /* Initialize locks */
317 vlc_mutex_init( &p_vout->picture_lock );
318 vlc_mutex_init( &p_vout->change_lock );
319 vlc_mutex_init( &p_vout->vfilter_lock );
321 /* Mouse coordinates */
322 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
323 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
324 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
325 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
326 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
328 /* Initialize subpicture unit */
329 p_vout->p_spu = spu_Create( p_vout );
330 spu_Attach( p_vout->p_spu, p_parent, true );
332 /* Attach the new object now so we can use var inheritance below */
333 vlc_object_attach( p_vout, p_parent );
335 spu_Init( p_vout->p_spu );
337 /* Take care of some "interface/control" related initialisations */
338 vout_IntfInit( p_vout );
340 /* If the parent is not a VOUT object, that means we are at the start of
341 * the video output pipe */
342 if( p_parent->i_object_type != VLC_OBJECT_VOUT )
344 /* Look for the default filter configuration */
345 var_Create( p_vout, "vout-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
346 var_Get( p_vout, "vout-filter", &val );
347 p_vout->psz_filter_chain = val.psz_string;
349 /* Apply video filter2 objects on the first vout */
350 var_Create( p_vout, "video-filter",
351 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
352 var_Get( p_vout, "video-filter", &val );
353 ParseVideoFilter2Chain( p_vout, val.psz_string );
354 free( val.psz_string );
358 /* continue the parent's filter chain */
361 /* Ugly hack to jump to our configuration chain */
362 p_vout->psz_filter_chain
363 = ((vout_thread_t *)p_parent)->psz_filter_chain;
364 p_vout->psz_filter_chain
365 = config_ChainCreate( &psz_tmp, &p_cfg, p_vout->psz_filter_chain );
366 config_ChainDestroy( p_cfg );
369 /* Create a video filter2 var ... but don't inherit values */
370 var_Create( p_vout, "video-filter", VLC_VAR_STRING );
371 ParseVideoFilter2Chain( p_vout, NULL );
374 var_AddCallback( p_vout, "video-filter", VideoFilter2Callback, NULL );
375 p_vout->b_vfilter_change = true;
376 p_vout->i_vfilters = 0;
378 /* Choose the video output module */
379 if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
381 var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
382 var_Get( p_vout, "vout", &val );
383 psz_parser = val.psz_string;
387 psz_parser = strdup( p_vout->psz_filter_chain );
390 /* Create the vout thread */
391 config_ChainCreate( &psz_name, &p_cfg, psz_parser );
393 p_vout->p_cfg = p_cfg;
394 p_vout->p_module = module_Need( p_vout,
395 ( p_vout->psz_filter_chain && *p_vout->psz_filter_chain ) ?
396 "video filter" : "video output", psz_name, p_vout->psz_filter_chain && *p_vout->psz_filter_chain );
399 if( p_vout->p_module == NULL )
401 msg_Err( p_vout, "no suitable vout module" );
402 vlc_object_detach( p_vout );
403 vlc_object_release( p_vout );
407 /* Create a few object variables for interface interaction */
408 var_Create( p_vout, "deinterlace", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
409 text.psz_string = _("Deinterlace");
410 var_Change( p_vout, "deinterlace", VLC_VAR_SETTEXT, &text, NULL );
411 val.psz_string = (char *)""; text.psz_string = _("Disable");
412 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
413 val.psz_string = (char *)"discard"; text.psz_string = _("Discard");
414 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
415 val.psz_string = (char *)"blend"; text.psz_string = _("Blend");
416 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
417 val.psz_string = (char *)"mean"; text.psz_string = _("Mean");
418 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
419 val.psz_string = (char *)"bob"; text.psz_string = _("Bob");
420 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
421 val.psz_string = (char *)"linear"; text.psz_string = _("Linear");
422 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
423 val.psz_string = (char *)"x"; text.psz_string = (char *)"X";
424 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
426 if( var_Get( p_vout, "deinterlace-mode", &val ) == VLC_SUCCESS )
428 var_Set( p_vout, "deinterlace", val );
429 free( val.psz_string );
431 var_AddCallback( p_vout, "deinterlace", DeinterlaceCallback, NULL );
433 var_Create( p_vout, "vout-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
434 text.psz_string = _("Filters");
435 var_Change( p_vout, "vout-filter", VLC_VAR_SETTEXT, &text, NULL );
436 var_AddCallback( p_vout, "vout-filter", FilterCallback, NULL );
438 /* Calculate delay created by internal caching */
439 p_input_thread = (input_thread_t *)vlc_object_find( p_vout,
440 VLC_OBJECT_INPUT, FIND_ANYWHERE );
443 p_vout->i_pts_delay = p_input_thread->i_pts_delay;
444 vlc_object_release( p_input_thread );
448 p_vout->i_pts_delay = DEFAULT_PTS_DELAY;
451 if( vlc_thread_create( p_vout, "video output", RunThread,
452 VLC_THREAD_PRIORITY_OUTPUT, true ) )
454 msg_Err( p_vout, "out of memory" );
455 module_Unneed( p_vout, p_vout->p_module );
456 vlc_object_release( p_vout );
460 if( p_vout->b_error )
462 msg_Err( p_vout, "video output creation failed" );
464 /* Make sure the thread is destroyed */
465 vlc_object_release( p_vout );
469 vlc_object_set_destructor( p_vout, vout_Destructor );
474 static void vout_Destructor( vlc_object_t * p_this )
476 vout_thread_t *p_vout = (vout_thread_t *)p_this;
478 /* Destroy the locks */
479 vlc_mutex_destroy( &p_vout->picture_lock );
480 vlc_mutex_destroy( &p_vout->change_lock );
481 vlc_mutex_destroy( &p_vout->vfilter_lock );
483 /* Release the module */
484 if( p_vout->p_module )
486 module_Unneed( p_vout, p_vout->p_module );
489 free( p_vout->psz_filter_chain );
491 config_ChainDestroy( p_vout->p_cfg );
494 vout_thread_t *p_another_vout;
496 /* This is a dirty hack mostly for Linux, where there is no way to get the
497 * GUI back if you closed it while playing video. This is solved in
498 * Mac OS X, where we have this novelty called menubar, that will always
499 * allow you access to the applications main functionality. They should try
500 * that on linux sometime. */
501 p_another_vout = vlc_object_find( p_this->p_libvlc,
502 VLC_OBJECT_VOUT, FIND_ANYWHERE );
503 if( p_another_vout == NULL )
504 var_SetBool( p_this->p_libvlc, "intf-show", true );
506 vlc_object_release( p_another_vout );
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 picture_t *get_pic( filter_t *p_filter )
519 picture_t *p_pic = (picture_t *)p_filter->p_owner;
520 p_filter->p_owner = NULL;
524 static int InitThread( vout_thread_t *p_vout )
526 int i, i_aspect_x, i_aspect_y;
528 vlc_mutex_lock( &p_vout->change_lock );
534 /* Initialize output method, it allocates direct buffers for us */
535 if( p_vout->pf_init( p_vout ) )
537 vlc_mutex_unlock( &p_vout->change_lock );
541 if( !I_OUTPUTPICTURES )
543 msg_Err( p_vout, "plugin was unable to allocate at least "
544 "one direct buffer" );
545 p_vout->pf_end( p_vout );
546 vlc_mutex_unlock( &p_vout->change_lock );
550 if( I_OUTPUTPICTURES > VOUT_MAX_PICTURES )
552 msg_Err( p_vout, "plugin allocated too many direct buffers, "
553 "our internal buffers must have overflown." );
554 p_vout->pf_end( p_vout );
555 vlc_mutex_unlock( &p_vout->change_lock );
559 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
561 AspectRatio( p_vout->fmt_render.i_aspect, &i_aspect_x, &i_aspect_y );
563 msg_Dbg( p_vout, "picture in %ix%i (%i,%i,%ix%i), "
564 "chroma %4.4s, ar %i:%i, sar %i:%i",
565 p_vout->fmt_render.i_width, p_vout->fmt_render.i_height,
566 p_vout->fmt_render.i_x_offset, p_vout->fmt_render.i_y_offset,
567 p_vout->fmt_render.i_visible_width,
568 p_vout->fmt_render.i_visible_height,
569 (char*)&p_vout->fmt_render.i_chroma,
570 i_aspect_x, i_aspect_y,
571 p_vout->fmt_render.i_sar_num, p_vout->fmt_render.i_sar_den );
573 AspectRatio( p_vout->fmt_in.i_aspect, &i_aspect_x, &i_aspect_y );
575 msg_Dbg( p_vout, "picture user %ix%i (%i,%i,%ix%i), "
576 "chroma %4.4s, ar %i:%i, sar %i:%i",
577 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
578 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
579 p_vout->fmt_in.i_visible_width,
580 p_vout->fmt_in.i_visible_height,
581 (char*)&p_vout->fmt_in.i_chroma,
582 i_aspect_x, i_aspect_y,
583 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
585 if( !p_vout->fmt_out.i_width || !p_vout->fmt_out.i_height )
587 p_vout->fmt_out.i_width = p_vout->fmt_out.i_visible_width =
588 p_vout->output.i_width;
589 p_vout->fmt_out.i_height = p_vout->fmt_out.i_visible_height =
590 p_vout->output.i_height;
591 p_vout->fmt_out.i_x_offset = p_vout->fmt_out.i_y_offset = 0;
593 p_vout->fmt_out.i_aspect = p_vout->output.i_aspect;
594 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
596 if( !p_vout->fmt_out.i_sar_num || !p_vout->fmt_out.i_sar_num )
598 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_aspect *
599 p_vout->fmt_out.i_height;
600 p_vout->fmt_out.i_sar_den = VOUT_ASPECT_FACTOR *
601 p_vout->fmt_out.i_width;
604 vlc_ureduce( &p_vout->fmt_out.i_sar_num, &p_vout->fmt_out.i_sar_den,
605 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den, 0 );
607 AspectRatio( p_vout->fmt_out.i_aspect, &i_aspect_x, &i_aspect_y );
609 msg_Dbg( p_vout, "picture out %ix%i (%i,%i,%ix%i), "
610 "chroma %4.4s, ar %i:%i, sar %i:%i",
611 p_vout->fmt_out.i_width, p_vout->fmt_out.i_height,
612 p_vout->fmt_out.i_x_offset, p_vout->fmt_out.i_y_offset,
613 p_vout->fmt_out.i_visible_width,
614 p_vout->fmt_out.i_visible_height,
615 (char*)&p_vout->fmt_out.i_chroma,
616 i_aspect_x, i_aspect_y,
617 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den );
619 /* Calculate shifts from system-updated masks */
620 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
621 p_vout->output.i_rmask );
622 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
623 p_vout->output.i_gmask );
624 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
625 p_vout->output.i_bmask );
627 /* Check whether we managed to create direct buffers similar to
628 * the render buffers, ie same size and chroma */
629 if( ( p_vout->output.i_width == p_vout->render.i_width )
630 && ( p_vout->output.i_height == p_vout->render.i_height )
631 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) ) )
633 /* Cool ! We have direct buffers, we can ask the decoder to
634 * directly decode into them ! Map the first render buffers to
635 * the first direct buffers, but keep the first direct buffer
636 * for memcpy operations */
637 p_vout->b_direct = 1;
639 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
641 if( p_vout->p_picture[ i ].i_type != DIRECT_PICTURE &&
642 I_RENDERPICTURES >= VOUT_MIN_DIRECT_PICTURES - 1 &&
643 p_vout->p_picture[ i - 1 ].i_type == DIRECT_PICTURE )
645 /* We have enough direct buffers so there's no need to
646 * try to use system memory buffers. */
649 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
653 msg_Dbg( p_vout, "direct render, mapping "
654 "render pictures 0-%i to system pictures 1-%i",
655 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
659 /* Rats... Something is wrong here, we could not find an output
660 * plugin able to directly render what we decode. See if we can
661 * find a chroma plugin to do the conversion */
662 p_vout->b_direct = 0;
664 /* Choose the best module */
665 p_vout->p_chroma = vlc_object_create( p_vout, VLC_OBJECT_FILTER );
666 filter_t *p_chroma = p_vout->p_chroma;
667 vlc_object_attach( p_chroma, p_vout );
668 /* TODO: Set the fmt_in and fmt_out stuff here */
669 p_chroma->fmt_in.video = p_vout->fmt_render;
670 p_chroma->fmt_out.video = p_vout->fmt_out;
672 /* TODO: put in a function */
673 p_chroma->fmt_out.video.i_rmask = p_vout->output.i_rmask;
674 p_chroma->fmt_out.video.i_gmask = p_vout->output.i_gmask;
675 p_chroma->fmt_out.video.i_bmask = p_vout->output.i_bmask;
676 p_chroma->fmt_out.video.i_rrshift = p_vout->output.i_rrshift;
677 p_chroma->fmt_out.video.i_lrshift = p_vout->output.i_lrshift;
678 p_chroma->fmt_out.video.i_rgshift = p_vout->output.i_rgshift;
679 p_chroma->fmt_out.video.i_lgshift = p_vout->output.i_lgshift;
680 p_chroma->fmt_out.video.i_rbshift = p_vout->output.i_rbshift;
681 p_chroma->fmt_out.video.i_lbshift = p_vout->output.i_lbshift;
682 msg_Err( p_vout, "HOLA! %4.4s", (char*)&p_chroma->fmt_in.video.i_chroma );
683 msg_Err( p_vout, "HOLA! %4.4s", (char*)&p_chroma->fmt_out.video.i_chroma );
684 p_chroma->p_module = module_Need( p_chroma, "video filter2", NULL, 0 );
686 if( p_chroma->p_module == NULL )
688 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
689 (char*)&p_vout->render.i_chroma,
690 (char*)&p_vout->output.i_chroma );
691 vlc_object_detach( p_vout->p_chroma );
692 p_vout->p_chroma = NULL;
693 p_vout->pf_end( p_vout );
694 vlc_mutex_unlock( &p_vout->change_lock );
697 p_chroma->pf_vout_buffer_new = get_pic;
699 msg_Dbg( p_vout, "indirect render, mapping "
700 "render pictures 0-%i to system pictures %i-%i",
701 VOUT_MAX_PICTURES - 1, I_OUTPUTPICTURES,
702 I_OUTPUTPICTURES + VOUT_MAX_PICTURES - 1 );
704 /* Append render buffers after the direct buffers */
705 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
707 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
710 /* Check if we have enough render pictures */
711 if( I_RENDERPICTURES == VOUT_MAX_PICTURES )
716 /* Link pictures back to their heap */
717 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
719 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
722 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
724 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
727 /* XXX XXX mark thread ready */
731 /*****************************************************************************
732 * RunThread: video output thread
733 *****************************************************************************
734 * Video output thread. This function does only returns when the thread is
735 * terminated. It handles the pictures arriving in the video heap and the
736 * display device events.
737 *****************************************************************************/
738 static void RunThread( vout_thread_t *p_vout)
740 int i_index; /* index in heap */
741 int i_idle_loops = 0; /* loops without displaying a picture */
742 mtime_t current_date; /* current date */
743 mtime_t display_date; /* display date */
745 picture_t * p_picture; /* picture pointer */
746 picture_t * p_last_picture = NULL; /* last picture */
747 picture_t * p_directbuffer; /* direct buffer to display */
749 subpicture_t * p_subpic = NULL; /* subpicture pointer */
751 input_thread_t *p_input = NULL ; /* Parent input, if it exists */
756 int i_displayed = 0, i_lost = 0, i_loops = 0;
761 p_vout->b_error = InitThread( p_vout );
763 var_Create( p_vout, "drop-late-frames", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
764 var_Get( p_vout, "drop-late-frames", &val );
765 b_drop_late = val.b_bool;
767 /* signal the creation of the vout */
768 vlc_thread_ready( p_vout );
770 if( p_vout->b_error )
773 vlc_object_lock( p_vout );
775 if( p_vout->b_title_show )
776 DisplayTitleOnOSD( p_vout );
779 * Main loop - it is not executed if an error occurred during
782 while( (vlc_object_alive( p_vout )) && (!p_vout->b_error) )
784 /* Initialize loop variables */
787 current_date = mdate();
792 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT,
797 vlc_mutex_lock( &p_input->p->counters.counters_lock );
798 stats_UpdateInteger( p_vout, p_input->p->counters.p_lost_pictures,
800 stats_UpdateInteger( p_vout,
801 p_input->p->counters.p_displayed_pictures,
803 i_displayed = i_lost = 0;
804 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
805 vlc_object_release( p_input );
810 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
812 msg_Dbg( p_vout, "picture heap: %d/%d",
813 I_RENDERPICTURES, p_vout->i_heap_size );
818 * Find the picture to display (the one with the earliest date).
819 * This operation does not need lock, since only READY_PICTUREs
821 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
823 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
824 && ( (p_picture == NULL) ||
825 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
827 p_picture = PP_RENDERPICTURE[i_index];
828 display_date = p_picture->date;
834 /* If we met the last picture, parse again to see whether there is
835 * a more appropriate one. */
836 if( p_picture == p_last_picture )
838 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
840 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
841 && (PP_RENDERPICTURE[i_index] != p_last_picture)
842 && ((p_picture == p_last_picture) ||
843 (PP_RENDERPICTURE[i_index]->date < display_date)) )
845 p_picture = PP_RENDERPICTURE[i_index];
846 display_date = p_picture->date;
851 /* If we found better than the last picture, destroy it */
852 if( p_last_picture && p_picture != p_last_picture )
854 vlc_mutex_lock( &p_vout->picture_lock );
855 if( p_last_picture->i_refcount )
857 p_last_picture->i_status = DISPLAYED_PICTURE;
861 p_last_picture->i_status = DESTROYED_PICTURE;
862 p_vout->i_heap_size--;
864 vlc_mutex_unlock( &p_vout->picture_lock );
865 p_last_picture = NULL;
868 /* Compute FPS rate */
869 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
872 if( !p_picture->b_force &&
873 p_picture != p_last_picture &&
874 display_date < current_date + p_vout->render_time &&
877 /* Picture is late: it will be destroyed and the thread
878 * will directly choose the next picture */
879 vlc_mutex_lock( &p_vout->picture_lock );
880 if( p_picture->i_refcount )
882 /* Pretend we displayed the picture, but don't destroy
883 * it since the decoder might still need it. */
884 p_picture->i_status = DISPLAYED_PICTURE;
888 /* Destroy the picture without displaying it */
889 p_picture->i_status = DESTROYED_PICTURE;
890 p_vout->i_heap_size--;
892 msg_Warn( p_vout, "late picture skipped (%"PRId64")",
893 current_date - display_date );
895 vlc_mutex_unlock( &p_vout->picture_lock );
901 current_date + p_vout->i_pts_delay + VOUT_BOGUS_DELAY )
903 /* Picture is waaay too early: it will be destroyed */
904 vlc_mutex_lock( &p_vout->picture_lock );
905 if( p_picture->i_refcount )
907 /* Pretend we displayed the picture, but don't destroy
908 * it since the decoder might still need it. */
909 p_picture->i_status = DISPLAYED_PICTURE;
913 /* Destroy the picture without displaying it */
914 p_picture->i_status = DESTROYED_PICTURE;
915 p_vout->i_heap_size--;
918 msg_Warn( p_vout, "vout warning: early picture skipped "
919 "(%"PRId64")", display_date - current_date
920 - p_vout->i_pts_delay );
921 vlc_mutex_unlock( &p_vout->picture_lock );
926 if( display_date > current_date + VOUT_DISPLAY_DELAY )
928 /* A picture is ready to be rendered, but its rendering date
929 * is far from the current one so the thread will perform an
930 * empty loop as if no picture were found. The picture state
935 else if( p_picture == p_last_picture )
937 /* We are asked to repeat the previous picture, but we first
938 * wait for a couple of idle loops */
939 if( i_idle_loops < 4 )
946 /* We set the display date to something high, otherwise
947 * we'll have lots of problems with late pictures */
948 display_date = current_date + p_vout->render_time;
953 if( p_picture == NULL )
958 /* Video Filter2 stuff */
959 if( p_vout->b_vfilter_change == true )
962 vlc_mutex_lock( &p_vout->vfilter_lock );
963 RemoveVideoFilters2( p_vout );
964 for( i = 0; i < p_vout->i_vfilters_cfg; i++ )
966 filter_t *p_vfilter =
967 p_vout->pp_vfilters[p_vout->i_vfilters] =
968 vlc_object_create( p_vout, VLC_OBJECT_FILTER );
970 vlc_object_attach( p_vfilter, p_vout );
972 p_vfilter->pf_vout_buffer_new = video_new_buffer_filter;
973 p_vfilter->pf_vout_buffer_del = video_del_buffer_filter;
975 if( !p_vout->i_vfilters )
977 p_vfilter->fmt_in.video = p_vout->fmt_render;
981 p_vfilter->fmt_in.video = (p_vfilter-1)->fmt_out.video;
983 /* TODO: one day filters in the middle of the chain might
984 * have a different fmt_out.video than fmt_render ... */
985 p_vfilter->fmt_out.video = p_vout->fmt_render;
987 p_vfilter->p_cfg = p_vout->p_vfilters_cfg[i];
988 p_vfilter->p_module = module_Need( p_vfilter, "video filter2",
989 p_vout->psz_vfilters[i],
992 if( p_vfilter->p_module )
995 malloc( sizeof( filter_owner_sys_t ) );
996 p_vfilter->p_owner->p_vout = p_vout;
997 p_vout->i_vfilters++;
998 msg_Dbg( p_vout, "video filter found (%s)",
999 p_vout->psz_vfilters[i] );
1003 msg_Err( p_vout, "no video filter found (%s)",
1004 p_vout->psz_vfilters[i] );
1005 vlc_object_detach( p_vfilter );
1006 vlc_object_release( p_vfilter );
1009 p_vout->b_vfilter_change = false;
1010 vlc_mutex_unlock( &p_vout->vfilter_lock );
1016 for( i = 0; i < p_vout->i_vfilters; i++ )
1018 picture_t *p_old = p_picture;
1019 p_picture = p_vout->pp_vfilters[i]->pf_video_filter(
1020 p_vout->pp_vfilters[i], p_picture );
1025 /* FIXME: this is kind of wrong
1026 * if you have 2 or more vfilters and the 2nd breaks,
1027 * on the next loop the 1st one will be applied again */
1029 /* if p_old and p_picture are the same (ie the filter
1030 * worked on the old picture), then following code is
1031 * still alright since i_status gets changed back to
1032 * the right value */
1033 if( p_old->i_refcount )
1035 p_old->i_status = DISPLAYED_PICTURE;
1039 p_old->i_status = DESTROYED_PICTURE;
1041 p_picture->i_status = READY_PICTURE;
1045 if( p_picture && p_vout->b_snapshot )
1047 p_vout->b_snapshot = false;
1048 vout_Snapshot( p_vout, p_picture );
1052 * Check for subpictures to display
1054 if( display_date > 0 )
1058 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT,
1061 p_subpic = spu_SortSubpictures( p_vout->p_spu, display_date,
1062 p_input ? var_GetBool( p_input, "state" ) == PAUSE_S : false );
1064 vlc_object_release( p_input );
1072 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
1075 * Call the plugin-specific rendering method if there is one
1077 if( p_picture != NULL && p_directbuffer != NULL && p_vout->pf_render )
1079 /* Render the direct buffer returned by vout_RenderPicture */
1080 p_vout->pf_render( p_vout, p_directbuffer );
1086 if( display_date != 0 && p_directbuffer != NULL )
1088 mtime_t current_render_time = mdate() - current_date;
1089 /* if render time is very large we don't include it in the mean */
1090 if( current_render_time < p_vout->render_time +
1091 VOUT_DISPLAY_DELAY )
1093 /* Store render time using a sliding mean weighting to
1094 * current value in a 3 to 1 ratio*/
1095 p_vout->render_time *= 3;
1096 p_vout->render_time += current_render_time;
1097 p_vout->render_time >>= 2;
1101 /* Give back change lock */
1102 vlc_mutex_unlock( &p_vout->change_lock );
1104 vlc_object_unlock( p_vout );
1106 /* Sleep a while or until a given date */
1107 if( display_date != 0 )
1109 /* If there are filters in the chain, better give them the picture
1111 if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
1113 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1118 msleep( VOUT_IDLE_SLEEP );
1121 /* On awakening, take back lock and send immediately picture
1123 vlc_object_lock( p_vout );
1124 /* Note: vlc_object_alive() could be false here, and we
1126 vlc_mutex_lock( &p_vout->change_lock );
1129 * Display the previously rendered picture
1131 if( p_picture != NULL && p_directbuffer != NULL )
1133 /* Display the direct buffer returned by vout_RenderPicture */
1134 if( p_vout->pf_display )
1136 p_vout->pf_display( p_vout, p_directbuffer );
1139 /* Tell the vout this was the last picture and that it does not
1140 * need to be forced anymore. */
1141 p_last_picture = p_picture;
1142 p_last_picture->b_force = 0;
1145 if( p_picture != NULL )
1147 /* Reinitialize idle loop count */
1152 * Check events and manage thread
1154 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
1156 /* A fatal error occurred, and the thread must terminate
1157 * immediately, without displaying anything - setting b_error to 1
1158 * causes the immediate end of the main while() loop. */
1159 p_vout->b_error = 1;
1162 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
1164 /* this must only happen when the vout plugin is incapable of
1165 * rescaling the picture itself. In this case we need to destroy
1166 * the current picture buffers and recreate new ones with the right
1170 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
1172 p_vout->pf_end( p_vout );
1173 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1174 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
1176 I_OUTPUTPICTURES = 0;
1177 if( p_vout->pf_init( p_vout ) )
1179 msg_Err( p_vout, "cannot resize display" );
1180 /* FIXME: pf_end will be called again in EndThread() */
1181 p_vout->b_error = 1;
1184 /* Need to reinitialise the chroma plugin */
1185 if( p_vout->p_chroma->p_module )
1187 if( p_vout->p_chroma->p_module->pf_deactivate )
1188 p_vout->p_chroma->p_module->pf_deactivate( VLC_OBJECT(p_vout->p_chroma) );
1189 p_vout->p_chroma->p_module->pf_activate( VLC_OBJECT(p_vout->p_chroma) );
1193 if( p_vout->i_changes & VOUT_PICTURE_BUFFERS_CHANGE )
1195 /* This happens when the picture buffers need to be recreated.
1196 * This is useful on multimonitor displays for instance.
1198 * Warning: This only works when the vout creates only 1 picture
1200 p_vout->i_changes &= ~VOUT_PICTURE_BUFFERS_CHANGE;
1202 if( !p_vout->b_direct )
1204 module_Unneed( p_vout->p_chroma, p_vout->p_chroma->p_module );
1205 p_vout->p_chroma = NULL;
1208 vlc_mutex_lock( &p_vout->picture_lock );
1210 p_vout->pf_end( p_vout );
1212 I_OUTPUTPICTURES = I_RENDERPICTURES = 0;
1214 p_vout->b_error = InitThread( p_vout );
1216 vlc_mutex_unlock( &p_vout->picture_lock );
1223 vlc_object_release( p_input );
1227 * Error loop - wait until the thread destruction is requested
1229 if( p_vout->b_error )
1231 ErrorThread( p_vout );
1235 EndThread( p_vout );
1236 vlc_object_unlock( p_vout );
1239 /*****************************************************************************
1240 * ErrorThread: RunThread() error loop
1241 *****************************************************************************
1242 * This function is called when an error occurred during thread main's loop.
1243 * The thread can still receive feed, but must be ready to terminate as soon
1245 *****************************************************************************/
1246 static void ErrorThread( vout_thread_t *p_vout )
1248 /* Wait until a `die' order */
1249 while( !p_vout->b_die )
1252 msleep( VOUT_IDLE_SLEEP );
1256 /*****************************************************************************
1257 * EndThread: thread destruction
1258 *****************************************************************************
1259 * This function is called when the thread ends after a sucessful
1260 * initialization. It frees all resources allocated by InitThread.
1261 *****************************************************************************/
1262 static void EndThread( vout_thread_t *p_vout )
1264 int i_index; /* index in heap */
1268 struct tms cpu_usage;
1269 times( &cpu_usage );
1271 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
1272 cpu_usage.tms_utime, cpu_usage.tms_stime );
1276 if( !p_vout->b_direct )
1278 module_Unneed( p_vout->p_chroma, p_vout->p_chroma->p_module );
1279 p_vout->p_chroma->p_module = NULL;
1282 /* Destroy all remaining pictures */
1283 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++ )
1285 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
1287 free( p_vout->p_picture[i_index].p_data_orig );
1291 /* Destroy subpicture unit */
1292 spu_Attach( p_vout->p_spu, VLC_OBJECT(p_vout), false );
1293 spu_Destroy( p_vout->p_spu );
1295 /* Destroy the video filters2 */
1296 RemoveVideoFilters2( p_vout );
1298 /* Destroy translation tables */
1299 p_vout->pf_end( p_vout );
1301 /* Release the change lock */
1302 vlc_mutex_unlock( &p_vout->change_lock );
1305 /* following functions are local */
1307 static int ReduceHeight( int i_ratio )
1309 int i_dummy = VOUT_ASPECT_FACTOR;
1317 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
1318 while( !(i_ratio & 1) && !(i_dummy & 1) )
1325 while( !(i_ratio % 3) && !(i_dummy % 3) )
1332 while( !(i_ratio % 5) && !(i_dummy % 5) )
1342 static void AspectRatio( int i_aspect, int *i_aspect_x, int *i_aspect_y )
1344 unsigned int i_pgcd = ReduceHeight( i_aspect );
1345 *i_aspect_x = i_aspect / i_pgcd;
1346 *i_aspect_y = VOUT_ASPECT_FACTOR / i_pgcd;
1349 /*****************************************************************************
1350 * BinaryLog: computes the base 2 log of a binary value
1351 *****************************************************************************
1352 * This functions is used by MaskToShift, to get a bit index from a binary
1354 *****************************************************************************/
1355 static int BinaryLog( uint32_t i )
1359 if( i == 0 ) return -31337;
1361 if( i & 0xffff0000 ) i_log += 16;
1362 if( i & 0xff00ff00 ) i_log += 8;
1363 if( i & 0xf0f0f0f0 ) i_log += 4;
1364 if( i & 0xcccccccc ) i_log += 2;
1365 if( i & 0xaaaaaaaa ) i_log += 1;
1370 /*****************************************************************************
1371 * MaskToShift: transform a color mask into right and left shifts
1372 *****************************************************************************
1373 * This function is used for obtaining color shifts from masks.
1374 *****************************************************************************/
1375 static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
1377 uint32_t i_low, i_high; /* lower hand higher bits of the mask */
1381 *pi_left = *pi_right = 0;
1386 i_low = i_high = i_mask;
1388 i_low &= - (int32_t)i_low; /* lower bit of the mask */
1389 i_high += i_low; /* higher bit of the mask */
1391 /* Transform bits into an index. Also deal with i_high overflow, which
1392 * is faster than changing the BinaryLog code to handle 64 bit integers. */
1393 i_low = BinaryLog (i_low);
1394 i_high = i_high ? BinaryLog (i_high) : 32;
1396 /* Update pointers and return */
1398 *pi_right = (8 - i_high + i_low);
1401 /*****************************************************************************
1402 * vout_VarCallback: generic callback for intf variables
1403 *****************************************************************************/
1404 int vout_VarCallback( vlc_object_t * p_this, const char * psz_variable,
1405 vlc_value_t oldval, vlc_value_t newval,
1408 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1410 (void)psz_variable; (void)newval; (void)oldval; (void)p_data;
1412 var_Set( p_vout, "intf-change", val );
1416 /*****************************************************************************
1417 * Helper thread for object variables callbacks.
1418 * Only used to avoid deadlocks when using the video embedded mode.
1419 *****************************************************************************/
1420 typedef struct suxor_thread_t
1423 input_thread_t *p_input;
1427 static void SuxorRestartVideoES( suxor_thread_t *p_this )
1431 vlc_thread_ready( p_this );
1433 /* Now restart current video stream */
1434 var_Get( p_this->p_input, "video-es", &val );
1435 if( val.i_int >= 0 )
1438 val_es.i_int = -VIDEO_ES;
1439 var_Set( p_this->p_input, "video-es", val_es );
1440 var_Set( p_this->p_input, "video-es", val );
1443 vlc_object_release( p_this->p_input );
1445 vlc_object_release( p_this );
1448 /*****************************************************************************
1449 * object variables callbacks: a bunch of object variables are used by the
1450 * interfaces to interact with the vout.
1451 *****************************************************************************/
1452 static int DeinterlaceCallback( vlc_object_t *p_this, char const *psz_cmd,
1453 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1455 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1456 input_thread_t *p_input;
1459 char *psz_mode = newval.psz_string;
1460 char *psz_filter, *psz_deinterlace = NULL;
1461 (void)psz_cmd; (void)oldval; (void)p_data;
1463 var_Get( p_vout, "vout-filter", &val );
1464 psz_filter = val.psz_string;
1465 if( psz_filter ) psz_deinterlace = strstr( psz_filter, "deinterlace" );
1467 if( !psz_mode || !*psz_mode )
1469 if( psz_deinterlace )
1471 char *psz_src = psz_deinterlace + sizeof("deinterlace") - 1;
1472 if( psz_src[0] == ':' ) psz_src++;
1473 memmove( psz_deinterlace, psz_src, strlen(psz_src) + 1 );
1476 else if( !psz_deinterlace )
1478 psz_filter = realloc( psz_filter, strlen( psz_filter ) +
1479 sizeof(":deinterlace") );
1480 if( psz_filter && *psz_filter ) strcat( psz_filter, ":" );
1481 strcat( psz_filter, "deinterlace" );
1484 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1486 if( !p_input ) return VLC_EGENERIC;
1488 if( psz_mode && *psz_mode )
1490 /* Modify input as well because the vout might have to be restarted */
1491 val.psz_string = psz_mode;
1492 var_Create( p_input, "deinterlace-mode", VLC_VAR_STRING );
1493 var_Set( p_input, "deinterlace-mode", val );
1495 vlc_object_release( p_input );
1498 var_Set( p_vout, "intf-change", val );
1500 val.psz_string = psz_filter;
1501 var_Set( p_vout, "vout-filter", val );
1507 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
1508 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1510 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1511 input_thread_t *p_input;
1513 (void)psz_cmd; (void)oldval; (void)p_data;
1515 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1519 msg_Err( p_vout, "Input not found" );
1520 return( VLC_EGENERIC );
1524 var_Set( p_vout, "intf-change", val );
1526 /* Modify input as well because the vout might have to be restarted */
1527 val.psz_string = newval.psz_string;
1528 var_Create( p_input, "vout-filter", VLC_VAR_STRING );
1530 var_Set( p_input, "vout-filter", val );
1532 /* Now restart current video stream */
1533 var_Get( p_input, "video-es", &val );
1534 if( val.i_int >= 0 )
1536 suxor_thread_t *p_suxor =
1537 vlc_object_create( p_vout, sizeof(suxor_thread_t) );
1538 p_suxor->p_input = p_input;
1539 p_vout->b_filter_change = true;
1540 vlc_object_yield( p_input );
1541 vlc_thread_create( p_suxor, "suxor", SuxorRestartVideoES,
1542 VLC_THREAD_PRIORITY_LOW, false );
1545 vlc_object_release( p_input );
1550 /*****************************************************************************
1551 * Video Filter2 stuff
1552 *****************************************************************************/
1553 static int ParseVideoFilter2Chain( vout_thread_t *p_vout, char *psz_vfilters )
1556 for( i = 0; i < p_vout->i_vfilters_cfg; i++ )
1558 struct config_chain_t *p_cfg =
1559 p_vout->p_vfilters_cfg[p_vout->i_vfilters_cfg];
1560 config_ChainDestroy( p_cfg );
1561 free( p_vout->psz_vfilters[p_vout->i_vfilters_cfg] );
1562 p_vout->psz_vfilters[p_vout->i_vfilters_cfg] = NULL;
1564 p_vout->i_vfilters_cfg = 0;
1565 if( psz_vfilters && *psz_vfilters )
1567 char *psz_parser = psz_vfilters;
1569 while( psz_parser && *psz_parser )
1571 psz_parser = config_ChainCreate(
1572 &p_vout->psz_vfilters[p_vout->i_vfilters_cfg],
1573 &p_vout->p_vfilters_cfg[p_vout->i_vfilters_cfg],
1575 msg_Dbg( p_vout, "adding vfilter: %s",
1576 p_vout->psz_vfilters[p_vout->i_vfilters_cfg] );
1577 p_vout->i_vfilters_cfg++;
1578 if( psz_parser && *psz_parser )
1580 if( p_vout->i_vfilters_cfg == MAX_VFILTERS )
1583 "maximum number of video filters reached. \"%s\" discarded",
1593 static int VideoFilter2Callback( vlc_object_t *p_this, char const *psz_cmd,
1594 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1596 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1597 (void)psz_cmd; (void)oldval; (void)p_data;
1599 vlc_mutex_lock( &p_vout->vfilter_lock );
1600 ParseVideoFilter2Chain( p_vout, newval.psz_string );
1601 p_vout->b_vfilter_change = true;
1602 vlc_mutex_unlock( &p_vout->vfilter_lock );
1607 static void RemoveVideoFilters2( vout_thread_t *p_vout )
1610 for( i = 0; i < p_vout->i_vfilters; i++ )
1612 vlc_object_detach( p_vout->pp_vfilters[i] );
1613 if( p_vout->pp_vfilters[i]->p_module )
1615 module_Unneed( p_vout->pp_vfilters[i],
1616 p_vout->pp_vfilters[i]->p_module );
1619 free( p_vout->pp_vfilters[i]->p_owner );
1620 vlc_object_release( p_vout->pp_vfilters[i] );
1622 p_vout->i_vfilters = 0;
1625 static void DisplayTitleOnOSD( vout_thread_t *p_vout )
1627 input_thread_t *p_input;
1628 mtime_t i_now, i_stop;
1630 p_input = (input_thread_t *)vlc_object_find( p_vout,
1631 VLC_OBJECT_INPUT, FIND_ANYWHERE );
1635 i_stop = i_now + (mtime_t)(p_vout->i_title_timeout * 1000);
1636 char *psz_nowplaying =
1637 input_item_GetNowPlaying( input_GetItem( p_input ) );
1638 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
1639 char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
1640 if( EMPTY_STR( psz_name ) )
1643 psz_name = input_item_GetName( input_GetItem( p_input ) );
1645 if( !EMPTY_STR( psz_nowplaying ) )
1647 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1648 psz_nowplaying, NULL,
1649 p_vout->i_title_position,
1650 30 + p_vout->fmt_in.i_width
1651 - p_vout->fmt_in.i_visible_width
1652 - p_vout->fmt_in.i_x_offset,
1653 20 + p_vout->fmt_in.i_y_offset,
1656 else if( !EMPTY_STR( psz_artist ) )
1658 char *psz_string = NULL;
1659 if( asprintf( &psz_string, "%s - %s", psz_name, psz_artist ) != -1 )
1661 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1663 p_vout->i_title_position,
1664 30 + p_vout->fmt_in.i_width
1665 - p_vout->fmt_in.i_visible_width
1666 - p_vout->fmt_in.i_x_offset,
1667 20 + p_vout->fmt_in.i_y_offset,
1674 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1676 p_vout->i_title_position,
1677 30 + p_vout->fmt_in.i_width
1678 - p_vout->fmt_in.i_visible_width
1679 - p_vout->fmt_in.i_x_offset,
1680 20 + p_vout->fmt_in.i_y_offset,
1683 vlc_object_release( p_input );
1686 free( psz_nowplaying );