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>
48 #include <vlc_filter.h>
51 #if defined( __APPLE__ )
52 /* Include darwin_specific.h here if needed */
55 /** FIXME This is quite ugly but needed while we don't have counters
57 #include "input/input_internal.h"
59 #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 CleanThread ( vout_thread_t * );
69 static void EndThread ( vout_thread_t * );
71 static void AspectRatio ( int, int *, int * );
72 static int BinaryLog ( uint32_t );
73 static void MaskToShift ( int *, int *, uint32_t );
75 static void vout_Destructor ( vlc_object_t * p_this );
77 /* Object variables callbacks */
78 static int DeinterlaceCallback( vlc_object_t *, char const *,
79 vlc_value_t, vlc_value_t, void * );
80 static int FilterCallback( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
82 static int VideoFilter2Callback( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
85 /* From vout_intf.c */
86 int vout_Snapshot( vout_thread_t *, picture_t * );
88 /* Display media title in OSD */
89 static void DisplayTitleOnOSD( vout_thread_t *p_vout );
91 /*****************************************************************************
92 * Video Filter2 functions
93 *****************************************************************************/
94 static picture_t *video_new_buffer_filter( filter_t *p_filter )
97 vout_thread_t *p_vout = (vout_thread_t*)p_filter->p_owner;
99 p_picture = vout_CreatePicture( p_vout, 0, 0, 0 );
104 static void video_del_buffer_filter( filter_t *p_filter, picture_t *p_pic )
106 vout_DestroyPicture( (vout_thread_t*)p_filter->p_owner, p_pic );
109 static int video_filter_buffer_allocation_init( filter_t *p_filter, void *p_data )
111 p_filter->pf_vout_buffer_new = video_new_buffer_filter;
112 p_filter->pf_vout_buffer_del = video_del_buffer_filter;
113 p_filter->p_owner = p_data; /* p_vout */
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 the instance 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 static const char typename[] = "video output";
249 p_vout = vlc_custom_create( p_parent, sizeof( *p_vout ), VLC_OBJECT_VOUT,
254 /* Initialize pictures - translation tables and functions
255 * will be initialized later in InitThread */
256 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++)
258 p_vout->p_picture[i_index].pf_lock = NULL;
259 p_vout->p_picture[i_index].pf_unlock = NULL;
260 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
261 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
262 p_vout->p_picture[i_index].b_slow = 0;
265 /* No images in the heap */
266 p_vout->i_heap_size = 0;
268 /* Initialize the rendering heap */
269 I_RENDERPICTURES = 0;
271 vlc_ureduce( &p_fmt->i_sar_num, &p_fmt->i_sar_den,
272 p_fmt->i_sar_num, p_fmt->i_sar_den, 50000 );
273 p_vout->fmt_render = *p_fmt; /* FIXME palette */
274 p_vout->fmt_in = *p_fmt; /* FIXME palette */
276 p_vout->render.i_width = i_width;
277 p_vout->render.i_height = i_height;
278 p_vout->render.i_chroma = i_chroma;
279 p_vout->render.i_aspect = i_aspect;
281 p_vout->render.i_rmask = 0;
282 p_vout->render.i_gmask = 0;
283 p_vout->render.i_bmask = 0;
285 p_vout->render.i_last_used_pic = -1;
286 p_vout->render.b_allow_modify_pics = 1;
288 /* Zero the output heap */
289 I_OUTPUTPICTURES = 0;
290 p_vout->output.i_width = 0;
291 p_vout->output.i_height = 0;
292 p_vout->output.i_chroma = 0;
293 p_vout->output.i_aspect = 0;
295 p_vout->output.i_rmask = 0;
296 p_vout->output.i_gmask = 0;
297 p_vout->output.i_bmask = 0;
299 /* Initialize misc stuff */
300 p_vout->i_changes = 0;
302 p_vout->b_grayscale = 0;
304 p_vout->b_interface = 0;
306 p_vout->b_fullscreen = 0;
307 p_vout->i_alignment = 0;
308 p_vout->render_time = 10;
309 p_vout->c_fps_samples = 0;
310 p_vout->b_filter_change = 0;
311 p_vout->pf_control = NULL;
312 p_vout->p_window = NULL;
313 p_vout->i_par_num = p_vout->i_par_den = 1;
315 /* Initialize locks */
316 vlc_mutex_init( &p_vout->picture_lock );
317 vlc_mutex_init( &p_vout->change_lock );
318 vlc_mutex_init( &p_vout->vfilter_lock );
320 /* Mouse coordinates */
321 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
322 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
323 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
324 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
325 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
327 /* Initialize subpicture unit */
328 p_vout->p_spu = spu_Create( p_vout );
329 spu_Attach( p_vout->p_spu, p_parent, true );
331 /* Attach the new object now so we can use var inheritance below */
332 vlc_object_attach( p_vout, p_parent );
334 spu_Init( p_vout->p_spu );
336 /* Take care of some "interface/control" related initialisations */
337 vout_IntfInit( p_vout );
339 /* If the parent is not a VOUT object, that means we are at the start of
340 * the video output pipe */
341 if( p_parent->i_object_type != VLC_OBJECT_VOUT )
343 /* Look for the default filter configuration */
344 p_vout->psz_filter_chain =
345 var_CreateGetStringCommand( p_vout, "vout-filter" );
347 /* Apply video filter2 objects on the first vout */
349 var_CreateGetStringCommand( p_vout, "video-filter" );
353 /* continue the parent's filter chain */
356 /* Ugly hack to jump to our configuration chain */
357 p_vout->psz_filter_chain
358 = ((vout_thread_t *)p_parent)->psz_filter_chain;
359 p_vout->psz_filter_chain
360 = config_ChainCreate( &psz_tmp, &p_cfg, p_vout->psz_filter_chain );
361 config_ChainDestroy( p_cfg );
364 /* Create a video filter2 var ... but don't inherit values */
365 var_Create( p_vout, "video-filter",
366 VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
367 p_vout->psz_vf2 = var_GetString( p_vout, "video-filter" );
370 var_AddCallback( p_vout, "video-filter", VideoFilter2Callback, NULL );
371 p_vout->p_vf2_chain = filter_chain_New( p_vout, "video filter2",
372 false, video_filter_buffer_allocation_init, NULL, p_vout );
374 /* Choose the video output module */
375 if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
377 var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
378 var_Get( p_vout, "vout", &val );
379 psz_parser = val.psz_string;
383 psz_parser = strdup( p_vout->psz_filter_chain );
386 /* Create the vout thread */
387 config_ChainCreate( &psz_name, &p_cfg, psz_parser );
389 p_vout->p_cfg = p_cfg;
390 p_vout->p_module = module_Need( p_vout,
391 ( p_vout->psz_filter_chain && *p_vout->psz_filter_chain ) ?
392 "video filter" : "video output", psz_name, p_vout->psz_filter_chain && *p_vout->psz_filter_chain );
395 if( p_vout->p_module == NULL )
397 msg_Err( p_vout, "no suitable vout module" );
398 // FIXME it's ugly but that's exactly the function that need to be called.
400 vlc_object_detach( p_vout );
401 vlc_object_release( p_vout );
405 /* Create a few object variables for interface interaction */
406 var_Create( p_vout, "deinterlace", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
407 text.psz_string = _("Deinterlace");
408 var_Change( p_vout, "deinterlace", VLC_VAR_SETTEXT, &text, NULL );
409 val.psz_string = (char *)""; text.psz_string = _("Disable");
410 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
411 val.psz_string = (char *)"discard"; text.psz_string = _("Discard");
412 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
413 val.psz_string = (char *)"blend"; text.psz_string = _("Blend");
414 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
415 val.psz_string = (char *)"mean"; text.psz_string = _("Mean");
416 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
417 val.psz_string = (char *)"bob"; text.psz_string = _("Bob");
418 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
419 val.psz_string = (char *)"linear"; text.psz_string = _("Linear");
420 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
421 val.psz_string = (char *)"x"; text.psz_string = (char *)"X";
422 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
424 if( var_Get( p_vout, "deinterlace-mode", &val ) == VLC_SUCCESS )
426 var_Set( p_vout, "deinterlace", val );
427 free( val.psz_string );
429 var_AddCallback( p_vout, "deinterlace", DeinterlaceCallback, NULL );
431 var_Create( p_vout, "vout-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
432 text.psz_string = _("Filters");
433 var_Change( p_vout, "vout-filter", VLC_VAR_SETTEXT, &text, NULL );
434 var_AddCallback( p_vout, "vout-filter", FilterCallback, NULL );
436 /* Calculate delay created by internal caching */
437 p_input_thread = (input_thread_t *)vlc_object_find( p_vout,
438 VLC_OBJECT_INPUT, FIND_ANYWHERE );
441 p_vout->i_pts_delay = p_input_thread->i_pts_delay;
442 vlc_object_release( p_input_thread );
446 p_vout->i_pts_delay = DEFAULT_PTS_DELAY;
449 if( vlc_thread_create( p_vout, "video output", RunThread,
450 VLC_THREAD_PRIORITY_OUTPUT, true ) )
452 module_Unneed( p_vout, p_vout->p_module );
453 vlc_object_release( p_vout );
457 vlc_object_set_destructor( p_vout, vout_Destructor );
459 if( p_vout->b_error )
461 msg_Err( p_vout, "video output creation failed" );
463 /* Make sure the thread is destroyed and data released */
464 vlc_object_release( p_vout );
471 static void vout_Destructor( vlc_object_t * p_this )
473 vout_thread_t *p_vout = (vout_thread_t *)p_this;
475 /* Destroy the locks */
476 vlc_mutex_destroy( &p_vout->picture_lock );
477 vlc_mutex_destroy( &p_vout->change_lock );
478 vlc_mutex_destroy( &p_vout->vfilter_lock );
480 /* Release the module */
481 if( p_vout->p_module )
483 module_Unneed( p_vout, p_vout->p_module );
486 free( p_vout->psz_filter_chain );
488 config_ChainDestroy( p_vout->p_cfg );
491 vout_thread_t *p_another_vout;
493 /* This is a dirty hack mostly for Linux, where there is no way to get the
494 * GUI back if you closed it while playing video. This is solved in
495 * Mac OS X, where we have this novelty called menubar, that will always
496 * allow you access to the applications main functionality. They should try
497 * that on linux sometime. */
498 p_another_vout = vlc_object_find( p_this->p_libvlc,
499 VLC_OBJECT_VOUT, FIND_ANYWHERE );
500 if( p_another_vout == NULL )
501 var_SetBool( p_this->p_libvlc, "intf-show", true );
503 vlc_object_release( p_another_vout );
507 /*****************************************************************************
508 * InitThread: initialize video output thread
509 *****************************************************************************
510 * This function is called from RunThread and performs the second step of the
511 * initialization. It returns 0 on success. Note that the thread's flag are not
512 * modified inside this function.
513 * XXX You have to enter it with change_lock taken.
514 *****************************************************************************/
515 static int ChromaCreate( vout_thread_t *p_vout );
516 static void ChromaDestroy( vout_thread_t *p_vout );
518 static int InitThread( vout_thread_t *p_vout )
520 int i, i_aspect_x, i_aspect_y;
526 /* Initialize output method, it allocates direct buffers for us */
527 if( p_vout->pf_init( p_vout ) )
530 if( !I_OUTPUTPICTURES )
532 msg_Err( p_vout, "plugin was unable to allocate at least "
533 "one direct buffer" );
534 p_vout->pf_end( p_vout );
538 if( I_OUTPUTPICTURES > VOUT_MAX_PICTURES )
540 msg_Err( p_vout, "plugin allocated too many direct buffers, "
541 "our internal buffers must have overflown." );
542 p_vout->pf_end( p_vout );
546 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
548 AspectRatio( p_vout->fmt_render.i_aspect, &i_aspect_x, &i_aspect_y );
550 msg_Dbg( p_vout, "picture in %ix%i (%i,%i,%ix%i), "
551 "chroma %4.4s, ar %i:%i, sar %i:%i",
552 p_vout->fmt_render.i_width, p_vout->fmt_render.i_height,
553 p_vout->fmt_render.i_x_offset, p_vout->fmt_render.i_y_offset,
554 p_vout->fmt_render.i_visible_width,
555 p_vout->fmt_render.i_visible_height,
556 (char*)&p_vout->fmt_render.i_chroma,
557 i_aspect_x, i_aspect_y,
558 p_vout->fmt_render.i_sar_num, p_vout->fmt_render.i_sar_den );
560 AspectRatio( p_vout->fmt_in.i_aspect, &i_aspect_x, &i_aspect_y );
562 msg_Dbg( p_vout, "picture user %ix%i (%i,%i,%ix%i), "
563 "chroma %4.4s, ar %i:%i, sar %i:%i",
564 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
565 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
566 p_vout->fmt_in.i_visible_width,
567 p_vout->fmt_in.i_visible_height,
568 (char*)&p_vout->fmt_in.i_chroma,
569 i_aspect_x, i_aspect_y,
570 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
572 if( !p_vout->fmt_out.i_width || !p_vout->fmt_out.i_height )
574 p_vout->fmt_out.i_width = p_vout->fmt_out.i_visible_width =
575 p_vout->output.i_width;
576 p_vout->fmt_out.i_height = p_vout->fmt_out.i_visible_height =
577 p_vout->output.i_height;
578 p_vout->fmt_out.i_x_offset = p_vout->fmt_out.i_y_offset = 0;
580 p_vout->fmt_out.i_aspect = p_vout->output.i_aspect;
581 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
583 if( !p_vout->fmt_out.i_sar_num || !p_vout->fmt_out.i_sar_num )
585 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_aspect *
586 p_vout->fmt_out.i_height;
587 p_vout->fmt_out.i_sar_den = VOUT_ASPECT_FACTOR *
588 p_vout->fmt_out.i_width;
591 vlc_ureduce( &p_vout->fmt_out.i_sar_num, &p_vout->fmt_out.i_sar_den,
592 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den, 0 );
594 AspectRatio( p_vout->fmt_out.i_aspect, &i_aspect_x, &i_aspect_y );
596 msg_Dbg( p_vout, "picture out %ix%i (%i,%i,%ix%i), "
597 "chroma %4.4s, ar %i:%i, sar %i:%i",
598 p_vout->fmt_out.i_width, p_vout->fmt_out.i_height,
599 p_vout->fmt_out.i_x_offset, p_vout->fmt_out.i_y_offset,
600 p_vout->fmt_out.i_visible_width,
601 p_vout->fmt_out.i_visible_height,
602 (char*)&p_vout->fmt_out.i_chroma,
603 i_aspect_x, i_aspect_y,
604 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den );
606 /* Calculate shifts from system-updated masks */
607 MaskToShift( &p_vout->output.i_lrshift, &p_vout->output.i_rrshift,
608 p_vout->output.i_rmask );
609 MaskToShift( &p_vout->output.i_lgshift, &p_vout->output.i_rgshift,
610 p_vout->output.i_gmask );
611 MaskToShift( &p_vout->output.i_lbshift, &p_vout->output.i_rbshift,
612 p_vout->output.i_bmask );
614 /* Check whether we managed to create direct buffers similar to
615 * the render buffers, ie same size and chroma */
616 if( ( p_vout->output.i_width == p_vout->render.i_width )
617 && ( p_vout->output.i_height == p_vout->render.i_height )
618 && ( vout_ChromaCmp( p_vout->output.i_chroma, p_vout->render.i_chroma ) ) )
620 /* Cool ! We have direct buffers, we can ask the decoder to
621 * directly decode into them ! Map the first render buffers to
622 * the first direct buffers, but keep the first direct buffer
623 * for memcpy operations */
624 p_vout->b_direct = 1;
626 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
628 if( p_vout->p_picture[ i ].i_type != DIRECT_PICTURE &&
629 I_RENDERPICTURES >= VOUT_MIN_DIRECT_PICTURES - 1 &&
630 p_vout->p_picture[ i - 1 ].i_type == DIRECT_PICTURE )
632 /* We have enough direct buffers so there's no need to
633 * try to use system memory buffers. */
636 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
640 msg_Dbg( p_vout, "direct render, mapping "
641 "render pictures 0-%i to system pictures 1-%i",
642 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
646 /* Rats... Something is wrong here, we could not find an output
647 * plugin able to directly render what we decode. See if we can
648 * find a chroma plugin to do the conversion */
649 p_vout->b_direct = 0;
651 if( ChromaCreate( p_vout ) )
653 p_vout->pf_end( p_vout );
657 msg_Dbg( p_vout, "indirect render, mapping "
658 "render pictures 0-%i to system pictures %i-%i",
659 VOUT_MAX_PICTURES - 1, I_OUTPUTPICTURES,
660 I_OUTPUTPICTURES + VOUT_MAX_PICTURES - 1 );
662 /* Append render buffers after the direct buffers */
663 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
665 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
668 /* Check if we have enough render pictures */
669 if( I_RENDERPICTURES == VOUT_MAX_PICTURES )
674 /* Link pictures back to their heap */
675 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
677 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
680 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
682 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
688 /*****************************************************************************
689 * RunThread: video output thread
690 *****************************************************************************
691 * Video output thread. This function does only returns when the thread is
692 * terminated. It handles the pictures arriving in the video heap and the
693 * display device events.
694 *****************************************************************************/
695 static void RunThread( vout_thread_t *p_vout)
697 int i_index; /* index in heap */
698 int i_idle_loops = 0; /* loops without displaying a picture */
699 mtime_t current_date; /* current date */
700 mtime_t display_date; /* display date */
702 picture_t * p_picture; /* picture pointer */
703 picture_t * p_last_picture = NULL; /* last picture */
704 picture_t * p_directbuffer; /* direct buffer to display */
706 subpicture_t * p_subpic = NULL; /* subpicture pointer */
708 input_thread_t *p_input = NULL ; /* Parent input, if it exists */
713 int i_displayed = 0, i_lost = 0, i_loops = 0;
718 vlc_mutex_lock( &p_vout->change_lock );
719 p_vout->b_error = InitThread( p_vout );
721 var_Create( p_vout, "drop-late-frames", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
722 var_Get( p_vout, "drop-late-frames", &val );
723 b_drop_late = val.b_bool;
725 /* signal the creation of the vout */
726 vlc_thread_ready( p_vout );
728 if( p_vout->b_error )
731 vlc_mutex_unlock( &p_vout->change_lock );
735 vlc_object_lock( p_vout );
737 if( p_vout->b_title_show )
738 DisplayTitleOnOSD( p_vout );
741 * Main loop - it is not executed if an error occurred during
744 while( (vlc_object_alive( p_vout )) && (!p_vout->b_error) )
746 /* Initialize loop variables */
749 current_date = mdate();
754 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT,
759 vlc_mutex_lock( &p_input->p->counters.counters_lock );
760 stats_UpdateInteger( p_vout, p_input->p->counters.p_lost_pictures,
762 stats_UpdateInteger( p_vout,
763 p_input->p->counters.p_displayed_pictures,
765 i_displayed = i_lost = 0;
766 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
767 vlc_object_release( p_input );
772 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
774 msg_Dbg( p_vout, "picture heap: %d/%d",
775 I_RENDERPICTURES, p_vout->i_heap_size );
780 * Find the picture to display (the one with the earliest date).
781 * This operation does not need lock, since only READY_PICTUREs
783 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
785 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
786 && ( (p_picture == NULL) ||
787 (PP_RENDERPICTURE[i_index]->date < display_date) ) )
789 p_picture = PP_RENDERPICTURE[i_index];
790 display_date = p_picture->date;
796 /* If we met the last picture, parse again to see whether there is
797 * a more appropriate one. */
798 if( p_picture == p_last_picture )
800 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
802 if( (PP_RENDERPICTURE[i_index]->i_status == READY_PICTURE)
803 && (PP_RENDERPICTURE[i_index] != p_last_picture)
804 && ((p_picture == p_last_picture) ||
805 (PP_RENDERPICTURE[i_index]->date < display_date)) )
807 p_picture = PP_RENDERPICTURE[i_index];
808 display_date = p_picture->date;
813 /* If we found better than the last picture, destroy it */
814 if( p_last_picture && p_picture != p_last_picture )
816 vlc_mutex_lock( &p_vout->picture_lock );
817 if( p_last_picture->i_refcount )
819 p_last_picture->i_status = DISPLAYED_PICTURE;
823 p_last_picture->i_status = DESTROYED_PICTURE;
824 p_vout->i_heap_size--;
826 vlc_mutex_unlock( &p_vout->picture_lock );
827 p_last_picture = NULL;
830 /* Compute FPS rate */
831 p_vout->p_fps_sample[ p_vout->c_fps_samples++ % VOUT_FPS_SAMPLES ]
834 if( !p_picture->b_force &&
835 p_picture != p_last_picture &&
836 display_date < current_date + p_vout->render_time &&
839 /* Picture is late: it will be destroyed and the thread
840 * will directly choose the next picture */
841 vlc_mutex_lock( &p_vout->picture_lock );
842 if( p_picture->i_refcount )
844 /* Pretend we displayed the picture, but don't destroy
845 * it since the decoder might still need it. */
846 p_picture->i_status = DISPLAYED_PICTURE;
850 /* Destroy the picture without displaying it */
851 p_picture->i_status = DESTROYED_PICTURE;
852 p_vout->i_heap_size--;
854 msg_Warn( p_vout, "late picture skipped (%"PRId64")",
855 current_date - display_date );
857 vlc_mutex_unlock( &p_vout->picture_lock );
863 current_date + p_vout->i_pts_delay + VOUT_BOGUS_DELAY )
865 /* Picture is waaay too early: it will be destroyed */
866 vlc_mutex_lock( &p_vout->picture_lock );
867 if( p_picture->i_refcount )
869 /* Pretend we displayed the picture, but don't destroy
870 * it since the decoder might still need it. */
871 p_picture->i_status = DISPLAYED_PICTURE;
875 /* Destroy the picture without displaying it */
876 p_picture->i_status = DESTROYED_PICTURE;
877 p_vout->i_heap_size--;
880 msg_Warn( p_vout, "vout warning: early picture skipped "
881 "(%"PRId64")", display_date - current_date
882 - p_vout->i_pts_delay );
883 vlc_mutex_unlock( &p_vout->picture_lock );
888 if( display_date > current_date + VOUT_DISPLAY_DELAY )
890 /* A picture is ready to be rendered, but its rendering date
891 * is far from the current one so the thread will perform an
892 * empty loop as if no picture were found. The picture state
897 else if( p_picture == p_last_picture )
899 /* We are asked to repeat the previous picture, but we first
900 * wait for a couple of idle loops */
901 if( i_idle_loops < 4 )
908 /* We set the display date to something high, otherwise
909 * we'll have lots of problems with late pictures */
910 display_date = current_date + p_vout->render_time;
915 if( p_picture == NULL )
922 p_picture = filter_chain_VideoFilter( p_vout->p_vf2_chain,
926 if( p_picture && p_vout->b_snapshot )
928 p_vout->b_snapshot = false;
929 vout_Snapshot( p_vout, p_picture );
933 * Check for subpictures to display
935 if( display_date > 0 )
939 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT,
942 p_subpic = spu_SortSubpictures( p_vout->p_spu, display_date,
943 p_input ? var_GetBool( p_input, "state" ) == PAUSE_S : false );
945 vlc_object_release( p_input );
953 p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
956 * Call the plugin-specific rendering method if there is one
958 if( p_picture != NULL && p_directbuffer != NULL && p_vout->pf_render )
960 /* Render the direct buffer returned by vout_RenderPicture */
961 p_vout->pf_render( p_vout, p_directbuffer );
967 if( display_date != 0 && p_directbuffer != NULL )
969 mtime_t current_render_time = mdate() - current_date;
970 /* if render time is very large we don't include it in the mean */
971 if( current_render_time < p_vout->render_time +
974 /* Store render time using a sliding mean weighting to
975 * current value in a 3 to 1 ratio*/
976 p_vout->render_time *= 3;
977 p_vout->render_time += current_render_time;
978 p_vout->render_time >>= 2;
982 /* Give back change lock */
983 vlc_mutex_unlock( &p_vout->change_lock );
985 vlc_object_unlock( p_vout );
987 /* Sleep a while or until a given date */
988 if( display_date != 0 )
990 /* If there are filters in the chain, better give them the picture
992 if( !p_vout->psz_filter_chain || !*p_vout->psz_filter_chain )
994 mwait( display_date - VOUT_MWAIT_TOLERANCE );
999 msleep( VOUT_IDLE_SLEEP );
1002 /* On awakening, take back lock and send immediately picture
1004 vlc_object_lock( p_vout );
1005 /* Note: vlc_object_alive() could be false here, and we
1007 vlc_mutex_lock( &p_vout->change_lock );
1010 * Display the previously rendered picture
1012 if( p_picture != NULL && p_directbuffer != NULL )
1014 /* Display the direct buffer returned by vout_RenderPicture */
1015 if( p_vout->pf_display )
1017 p_vout->pf_display( p_vout, p_directbuffer );
1020 /* Tell the vout this was the last picture and that it does not
1021 * need to be forced anymore. */
1022 p_last_picture = p_picture;
1023 p_last_picture->b_force = 0;
1026 if( p_picture != NULL )
1028 /* Reinitialize idle loop count */
1033 * Check events and manage thread
1035 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
1037 /* A fatal error occurred, and the thread must terminate
1038 * immediately, without displaying anything - setting b_error to 1
1039 * causes the immediate end of the main while() loop. */
1041 p_vout->b_error = 1;
1045 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
1047 /* this must only happen when the vout plugin is incapable of
1048 * rescaling the picture itself. In this case we need to destroy
1049 * the current picture buffers and recreate new ones with the right
1053 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
1055 assert( !p_vout->b_direct );
1057 ChromaDestroy( p_vout );
1059 vlc_mutex_lock( &p_vout->picture_lock );
1061 p_vout->pf_end( p_vout );
1063 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1064 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
1066 I_OUTPUTPICTURES = 0;
1068 if( p_vout->pf_init( p_vout ) )
1070 msg_Err( p_vout, "cannot resize display" );
1071 /* FIXME: pf_end will be called again in EndThread() */
1072 p_vout->b_error = 1;
1075 vlc_mutex_unlock( &p_vout->picture_lock );
1077 /* Need to reinitialise the chroma plugin. Since we might need
1078 * resizing too and it's not sure that we already had it,
1079 * recreate the chroma plugin chain from scratch. */
1081 if( ChromaCreate( p_vout ) )
1083 msg_Err( p_vout, "WOW THIS SUCKS BIG TIME!!!!!" );
1084 p_vout->b_error = 1;
1086 if( p_vout->b_error )
1090 if( p_vout->i_changes & VOUT_PICTURE_BUFFERS_CHANGE )
1092 /* This happens when the picture buffers need to be recreated.
1093 * This is useful on multimonitor displays for instance.
1095 * Warning: This only works when the vout creates only 1 picture
1097 p_vout->i_changes &= ~VOUT_PICTURE_BUFFERS_CHANGE;
1099 if( !p_vout->b_direct )
1100 ChromaDestroy( p_vout );
1102 vlc_mutex_lock( &p_vout->picture_lock );
1104 p_vout->pf_end( p_vout );
1106 I_OUTPUTPICTURES = I_RENDERPICTURES = 0;
1108 p_vout->b_error = InitThread( p_vout );
1109 if( p_vout->b_error )
1110 msg_Err( p_vout, "InitThread after VOUT_PICTURE_BUFFERS_CHANGE failed\n" );
1112 vlc_mutex_unlock( &p_vout->picture_lock );
1114 if( p_vout->b_error )
1118 /* Check for "video filter2" changes */
1119 vlc_mutex_lock( &p_vout->vfilter_lock );
1120 if( p_vout->psz_vf2 )
1124 es_format_Init( &fmt, VIDEO_ES, p_vout->fmt_render.i_chroma );
1125 fmt.video = p_vout->fmt_render;
1126 filter_chain_Reset( p_vout->p_vf2_chain, &fmt, &fmt );
1128 if( filter_chain_AppendFromString( p_vout->p_vf2_chain,
1129 p_vout->psz_vf2 ) < 0 )
1130 msg_Err( p_vout, "Video filter chain creation failed" );
1132 free( p_vout->psz_vf2 );
1133 p_vout->psz_vf2 = NULL;
1135 vlc_mutex_unlock( &p_vout->vfilter_lock );
1141 vlc_object_release( p_input );
1145 * Error loop - wait until the thread destruction is requested
1147 if( p_vout->b_error )
1148 ErrorThread( p_vout );
1151 CleanThread( p_vout );
1152 EndThread( p_vout );
1153 vlc_mutex_unlock( &p_vout->change_lock );
1155 vlc_object_unlock( p_vout );
1158 /*****************************************************************************
1159 * ErrorThread: RunThread() error loop
1160 *****************************************************************************
1161 * This function is called when an error occurred during thread main's loop.
1162 * The thread can still receive feed, but must be ready to terminate as soon
1164 *****************************************************************************/
1165 static void ErrorThread( vout_thread_t *p_vout )
1167 /* Wait until a `die' order */
1168 while( vlc_object_alive( p_vout ) )
1169 vlc_object_wait( p_vout );
1172 /*****************************************************************************
1173 * CleanThread: clean up after InitThread
1174 *****************************************************************************
1175 * This function is called after a sucessful
1176 * initialization. It frees all resources allocated by InitThread.
1177 * XXX You have to enter it with change_lock taken.
1178 *****************************************************************************/
1179 static void CleanThread( vout_thread_t *p_vout )
1181 int i_index; /* index in heap */
1183 if( !p_vout->b_direct )
1184 ChromaDestroy( p_vout );
1186 /* Destroy all remaining pictures */
1187 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++ )
1189 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
1191 free( p_vout->p_picture[i_index].p_data_orig );
1195 /* Destroy translation tables */
1196 if( !p_vout->b_error )
1197 p_vout->pf_end( p_vout );
1200 /*****************************************************************************
1201 * EndThread: thread destruction
1202 *****************************************************************************
1203 * This function is called when the thread ends.
1204 * It frees all resources not allocated by InitThread.
1205 * XXX You have to enter it with change_lock taken.
1206 *****************************************************************************/
1207 static void EndThread( vout_thread_t *p_vout )
1211 struct tms cpu_usage;
1212 times( &cpu_usage );
1214 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
1215 cpu_usage.tms_utime, cpu_usage.tms_stime );
1219 /* FIXME does that function *really* need to be called inside the thread ? */
1221 /* Destroy subpicture unit */
1222 spu_Attach( p_vout->p_spu, VLC_OBJECT(p_vout), false );
1223 spu_Destroy( p_vout->p_spu );
1225 /* Destroy the video filters2 */
1226 filter_chain_Delete( p_vout->p_vf2_chain );
1229 /* Thread helpers */
1230 static picture_t *ChromaGetPicture( filter_t *p_filter )
1232 picture_t *p_pic = (picture_t *)p_filter->p_owner;
1233 p_filter->p_owner = NULL;
1237 static int ChromaCreate( vout_thread_t *p_vout )
1241 /* Choose the best module */
1242 p_chroma = p_vout->p_chroma = vlc_object_create( p_vout, sizeof(filter_t) );
1244 vlc_object_attach( p_chroma, p_vout );
1246 /* TODO: Set the fmt_in and fmt_out stuff here */
1247 p_chroma->fmt_in.video = p_vout->fmt_render;
1248 p_chroma->fmt_out.video = p_vout->fmt_out;
1250 p_chroma->fmt_out.video.i_rmask = p_vout->output.i_rmask;
1251 p_chroma->fmt_out.video.i_gmask = p_vout->output.i_gmask;
1252 p_chroma->fmt_out.video.i_bmask = p_vout->output.i_bmask;
1253 p_chroma->fmt_out.video.i_rrshift = p_vout->output.i_rrshift;
1254 p_chroma->fmt_out.video.i_lrshift = p_vout->output.i_lrshift;
1255 p_chroma->fmt_out.video.i_rgshift = p_vout->output.i_rgshift;
1256 p_chroma->fmt_out.video.i_lgshift = p_vout->output.i_lgshift;
1257 p_chroma->fmt_out.video.i_rbshift = p_vout->output.i_rbshift;
1258 p_chroma->fmt_out.video.i_lbshift = p_vout->output.i_lbshift;
1259 p_chroma->p_module = module_Need( p_chroma, "video filter2", NULL, 0 );
1261 if( p_chroma->p_module == NULL )
1263 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s i=%dx%d o=%dx%d",
1264 (char*)&p_vout->render.i_chroma,
1265 (char*)&p_vout->output.i_chroma,
1266 p_chroma->fmt_in.video.i_width, p_chroma->fmt_in.video.i_height,
1267 p_chroma->fmt_out.video.i_width, p_chroma->fmt_out.video.i_height
1270 vlc_object_release( p_vout->p_chroma );
1271 p_vout->p_chroma = NULL;
1272 return VLC_EGENERIC;
1274 p_chroma->pf_vout_buffer_new = ChromaGetPicture;
1278 static void ChromaDestroy( vout_thread_t *p_vout )
1280 assert( !p_vout->b_direct );
1282 if( !p_vout->p_chroma )
1285 module_Unneed( p_vout->p_chroma, p_vout->p_chroma->p_module );
1286 vlc_object_release( p_vout->p_chroma );
1287 p_vout->p_chroma = NULL;
1292 /* following functions are local */
1294 static int ReduceHeight( int i_ratio )
1296 int i_dummy = VOUT_ASPECT_FACTOR;
1304 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
1305 while( !(i_ratio & 1) && !(i_dummy & 1) )
1312 while( !(i_ratio % 3) && !(i_dummy % 3) )
1319 while( !(i_ratio % 5) && !(i_dummy % 5) )
1329 static void AspectRatio( int i_aspect, int *i_aspect_x, int *i_aspect_y )
1331 unsigned int i_pgcd = ReduceHeight( i_aspect );
1332 *i_aspect_x = i_aspect / i_pgcd;
1333 *i_aspect_y = VOUT_ASPECT_FACTOR / i_pgcd;
1336 /*****************************************************************************
1337 * BinaryLog: computes the base 2 log of a binary value
1338 *****************************************************************************
1339 * This functions is used by MaskToShift, to get a bit index from a binary
1341 *****************************************************************************/
1342 static int BinaryLog( uint32_t i )
1346 if( i == 0 ) return -31337;
1348 if( i & 0xffff0000 ) i_log += 16;
1349 if( i & 0xff00ff00 ) i_log += 8;
1350 if( i & 0xf0f0f0f0 ) i_log += 4;
1351 if( i & 0xcccccccc ) i_log += 2;
1352 if( i & 0xaaaaaaaa ) i_log += 1;
1357 /*****************************************************************************
1358 * MaskToShift: transform a color mask into right and left shifts
1359 *****************************************************************************
1360 * This function is used for obtaining color shifts from masks.
1361 *****************************************************************************/
1362 static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask )
1364 uint32_t i_low, i_high; /* lower hand higher bits of the mask */
1368 *pi_left = *pi_right = 0;
1373 i_low = i_high = i_mask;
1375 i_low &= - (int32_t)i_low; /* lower bit of the mask */
1376 i_high += i_low; /* higher bit of the mask */
1378 /* Transform bits into an index. Also deal with i_high overflow, which
1379 * is faster than changing the BinaryLog code to handle 64 bit integers. */
1380 i_low = BinaryLog (i_low);
1381 i_high = i_high ? BinaryLog (i_high) : 32;
1383 /* Update pointers and return */
1385 *pi_right = (8 - i_high + i_low);
1388 /*****************************************************************************
1389 * vout_VarCallback: generic callback for intf variables
1390 *****************************************************************************/
1391 int vout_VarCallback( vlc_object_t * p_this, const char * psz_variable,
1392 vlc_value_t oldval, vlc_value_t newval,
1395 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1397 (void)psz_variable; (void)newval; (void)oldval; (void)p_data;
1399 var_Set( p_vout, "intf-change", val );
1403 /*****************************************************************************
1404 * Helper thread for object variables callbacks.
1405 * Only used to avoid deadlocks when using the video embedded mode.
1406 *****************************************************************************/
1407 typedef struct suxor_thread_t
1410 input_thread_t *p_input;
1414 static void SuxorRestartVideoES( suxor_thread_t *p_this )
1416 /* Now restart current video stream */
1417 int val = var_GetInteger( p_this->p_input, "video-es" );
1420 var_SetInteger( p_this->p_input, "video-es", -VIDEO_ES );
1421 var_SetInteger( p_this->p_input, "video-es", val );
1424 vlc_object_release( p_this->p_input );
1426 vlc_object_release( p_this );
1429 /*****************************************************************************
1430 * object variables callbacks: a bunch of object variables are used by the
1431 * interfaces to interact with the vout.
1432 *****************************************************************************/
1433 static int DeinterlaceCallback( vlc_object_t *p_this, char const *psz_cmd,
1434 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1436 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1437 input_thread_t *p_input;
1440 char *psz_mode = newval.psz_string;
1441 char *psz_filter, *psz_deinterlace = NULL;
1442 (void)psz_cmd; (void)oldval; (void)p_data;
1444 var_Get( p_vout, "vout-filter", &val );
1445 psz_filter = val.psz_string;
1446 if( psz_filter ) psz_deinterlace = strstr( psz_filter, "deinterlace" );
1448 if( !psz_mode || !*psz_mode )
1450 if( psz_deinterlace )
1452 char *psz_src = psz_deinterlace + sizeof("deinterlace") - 1;
1453 if( psz_src[0] == ':' ) psz_src++;
1454 memmove( psz_deinterlace, psz_src, strlen(psz_src) + 1 );
1457 else if( !psz_deinterlace )
1459 psz_filter = realloc( psz_filter, strlen( psz_filter ) +
1460 sizeof(":deinterlace") );
1461 if( psz_filter && *psz_filter ) strcat( psz_filter, ":" );
1462 strcat( psz_filter, "deinterlace" );
1465 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1467 if( !p_input ) return VLC_EGENERIC;
1469 if( psz_mode && *psz_mode )
1471 /* Modify input as well because the vout might have to be restarted */
1472 val.psz_string = psz_mode;
1473 var_Create( p_input, "deinterlace-mode", VLC_VAR_STRING );
1474 var_Set( p_input, "deinterlace-mode", val );
1476 vlc_object_release( p_input );
1479 var_Set( p_vout, "intf-change", val );
1481 val.psz_string = psz_filter;
1482 var_Set( p_vout, "vout-filter", val );
1488 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
1489 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1491 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1492 input_thread_t *p_input;
1494 (void)psz_cmd; (void)oldval; (void)p_data;
1496 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1500 msg_Err( p_vout, "Input not found" );
1501 return( VLC_EGENERIC );
1505 var_Set( p_vout, "intf-change", val );
1507 /* Modify input as well because the vout might have to be restarted */
1508 val.psz_string = newval.psz_string;
1509 var_Create( p_input, "vout-filter", VLC_VAR_STRING );
1511 var_Set( p_input, "vout-filter", val );
1513 /* Now restart current video stream */
1514 var_Get( p_input, "video-es", &val );
1515 if( val.i_int >= 0 )
1517 suxor_thread_t *p_suxor =
1518 vlc_object_create( p_vout, sizeof(suxor_thread_t) );
1519 p_suxor->p_input = p_input;
1520 p_vout->b_filter_change = true;
1521 vlc_object_yield( p_input );
1522 vlc_thread_create( p_suxor, "suxor", SuxorRestartVideoES,
1523 VLC_THREAD_PRIORITY_LOW, false );
1526 vlc_object_release( p_input );
1531 /*****************************************************************************
1532 * Video Filter2 stuff
1533 *****************************************************************************/
1534 static int VideoFilter2Callback( vlc_object_t *p_this, char const *psz_cmd,
1535 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1537 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1538 (void)psz_cmd; (void)oldval; (void)p_data;
1540 vlc_mutex_lock( &p_vout->vfilter_lock );
1541 p_vout->psz_vf2 = strdup( newval.psz_string );
1542 vlc_mutex_unlock( &p_vout->vfilter_lock );
1547 static void DisplayTitleOnOSD( vout_thread_t *p_vout )
1549 input_thread_t *p_input;
1550 mtime_t i_now, i_stop;
1552 p_input = (input_thread_t *)vlc_object_find( p_vout,
1553 VLC_OBJECT_INPUT, FIND_ANYWHERE );
1557 i_stop = i_now + (mtime_t)(p_vout->i_title_timeout * 1000);
1558 char *psz_nowplaying =
1559 input_item_GetNowPlaying( input_GetItem( p_input ) );
1560 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
1561 char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
1562 if( EMPTY_STR( psz_name ) )
1565 psz_name = input_item_GetName( input_GetItem( p_input ) );
1567 if( !EMPTY_STR( psz_nowplaying ) )
1569 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1570 psz_nowplaying, NULL,
1571 p_vout->i_title_position,
1572 30 + p_vout->fmt_in.i_width
1573 - p_vout->fmt_in.i_visible_width
1574 - p_vout->fmt_in.i_x_offset,
1575 20 + p_vout->fmt_in.i_y_offset,
1578 else if( !EMPTY_STR( psz_artist ) )
1580 char *psz_string = NULL;
1581 if( asprintf( &psz_string, "%s - %s", psz_name, psz_artist ) != -1 )
1583 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1585 p_vout->i_title_position,
1586 30 + p_vout->fmt_in.i_width
1587 - p_vout->fmt_in.i_visible_width
1588 - p_vout->fmt_in.i_x_offset,
1589 20 + p_vout->fmt_in.i_y_offset,
1596 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1598 p_vout->i_title_position,
1599 30 + p_vout->fmt_in.i_width
1600 - p_vout->fmt_in.i_visible_width
1601 - p_vout->fmt_in.i_x_offset,
1602 20 + p_vout->fmt_in.i_y_offset,
1605 vlc_object_release( p_input );
1608 free( psz_nowplaying );