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>
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"
61 #include "vout_pictures.h"
62 #include "vout_internal.h"
64 /*****************************************************************************
66 *****************************************************************************/
67 static int InitThread ( vout_thread_t * );
68 static void* RunThread ( vlc_object_t * );
69 static void ErrorThread ( vout_thread_t * );
70 static void CleanThread ( vout_thread_t * );
71 static void EndThread ( vout_thread_t * );
73 static void AspectRatio ( int, int *, int * );
75 static void VideoFormatImportRgb( video_format_t *, const picture_heap_t * );
76 static void PictureHeapFixRgb( picture_heap_t * );
78 static void vout_Destructor ( vlc_object_t * p_this );
80 /* Object variables callbacks */
81 static int DeinterlaceCallback( vlc_object_t *, char const *,
82 vlc_value_t, vlc_value_t, void * );
83 static int FilterCallback( vlc_object_t *, char const *,
84 vlc_value_t, vlc_value_t, void * );
85 static int VideoFilter2Callback( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
88 /* From vout_intf.c */
89 int vout_Snapshot( vout_thread_t *, picture_t * );
91 /* Display media title in OSD */
92 static void DisplayTitleOnOSD( vout_thread_t *p_vout );
95 static void DropPicture( vout_thread_t *p_vout, picture_t *p_picture );
97 /*****************************************************************************
98 * Video Filter2 functions
99 *****************************************************************************/
100 static picture_t *video_new_buffer_filter( filter_t *p_filter )
102 vout_thread_t *p_vout = (vout_thread_t*)p_filter->p_owner;
103 picture_t *p_picture = vout_CreatePicture( p_vout, 0, 0, 0 );
105 p_picture->i_status = READY_PICTURE;
110 static void video_del_buffer_filter( filter_t *p_filter, picture_t *p_pic )
112 vout_thread_t *p_vout = (vout_thread_t*)p_filter->p_owner;
114 DropPicture( p_vout, p_pic );
117 static int video_filter_buffer_allocation_init( filter_t *p_filter, void *p_data )
119 p_filter->pf_vout_buffer_new = video_new_buffer_filter;
120 p_filter->pf_vout_buffer_del = video_del_buffer_filter;
121 p_filter->p_owner = p_data; /* p_vout */
125 /*****************************************************************************
126 * vout_Request: find a video output thread, create one, or destroy one.
127 *****************************************************************************
128 * This function looks for a video output thread matching the current
129 * properties. If not found, it spawns a new one.
130 *****************************************************************************/
131 vout_thread_t *__vout_Request( vlc_object_t *p_this, vout_thread_t *p_vout,
132 video_format_t *p_fmt )
134 const bool b_vout_provided = p_vout != NULL;
137 /* Video output is no longer used.
138 * TODO: support for reusing video outputs with proper _thread-safe_
139 * reference handling. */
141 vout_CloseAndRelease( p_vout );
145 /* If a video output was provided, lock it, otherwise look for one. */
148 vlc_object_hold( p_vout );
151 /* TODO: find a suitable unused video output */
153 /* If we now have a video output, check it has the right properties */
156 char *psz_filter_chain;
159 vlc_mutex_lock( &p_vout->change_lock );
161 /* We don't directly check for the "vout-filter" variable for obvious
162 * performance reasons. */
163 if( p_vout->p->b_filter_change )
165 var_Get( p_vout, "vout-filter", &val );
166 psz_filter_chain = val.psz_string;
168 if( psz_filter_chain && !*psz_filter_chain )
170 free( psz_filter_chain );
171 psz_filter_chain = NULL;
173 if( p_vout->p->psz_filter_chain && !*p_vout->p->psz_filter_chain )
175 free( p_vout->p->psz_filter_chain );
176 p_vout->p->psz_filter_chain = NULL;
179 if( !psz_filter_chain && !p_vout->p->psz_filter_chain )
181 p_vout->p->b_filter_change = false;
184 free( psz_filter_chain );
187 if( p_vout->fmt_render.i_chroma != p_fmt->i_chroma ||
188 p_vout->fmt_render.i_width != p_fmt->i_width ||
189 p_vout->fmt_render.i_height != p_fmt->i_height ||
190 p_vout->p->b_filter_change )
192 vlc_mutex_unlock( &p_vout->change_lock );
194 /* We are not interested in this format, close this vout */
195 vout_CloseAndRelease( p_vout );
196 vlc_object_release( p_vout );
201 /* This video output is cool! Hijack it. */
202 if( p_vout->fmt_render.i_aspect != p_fmt->i_aspect )
204 /* Correct aspect ratio on change
205 * FIXME factorize this code with other aspect ration related code */
206 unsigned int i_sar_num;
207 unsigned int i_sar_den;
208 unsigned int i_aspect;
210 i_aspect = p_fmt->i_aspect;
211 vlc_ureduce( &i_sar_num, &i_sar_den,
212 p_fmt->i_sar_num, p_fmt->i_sar_den, 50000 );
214 /* What's that, it does not seems to be used correcly everywhere
215 * beside the previous p_vout->fmt_render.i_aspect != p_fmt->i_aspect
216 * should be fixed to use it too then */
217 if( p_vout->i_par_num > 0 && p_vout->i_par_den > 0 )
219 i_sar_num *= p_vout->i_par_den;
220 i_sar_den *= p_vout->i_par_num;
221 i_aspect = i_aspect * p_vout->i_par_den / p_vout->i_par_num;
225 if( i_sar_num > 0 && i_sar_den > 0 && i_aspect > 0 )
227 p_vout->fmt_in.i_sar_num = i_sar_num;
228 p_vout->fmt_in.i_sar_den = i_sar_den;
229 p_vout->fmt_in.i_aspect = i_aspect;
231 p_vout->fmt_render.i_sar_num = i_sar_num;
232 p_vout->fmt_render.i_sar_den = i_sar_den;
233 p_vout->fmt_render.i_aspect = i_aspect;
235 p_vout->render.i_aspect = i_aspect;
237 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
241 vlc_mutex_unlock( &p_vout->change_lock );
243 vlc_object_release( p_vout );
248 msg_Dbg( p_this, "reusing provided vout" );
250 spu_Attach( p_vout->p_spu, p_this, true );
252 vlc_object_detach( p_vout );
253 vlc_object_attach( p_vout, p_this );
255 /* Display title if we are not using the vout given to vout_Request.
256 * XXX for now b_vout_provided is always true at this stage */
257 if( p_vout->p->b_title_show && !b_vout_provided )
258 DisplayTitleOnOSD( p_vout );
264 msg_Dbg( p_this, "no usable vout present, spawning one" );
266 p_vout = vout_Create( p_this, p_fmt );
272 /*****************************************************************************
273 * vout_Create: creates a new video output thread
274 *****************************************************************************
275 * This function creates a new video output thread, and returns a pointer
276 * to its description. On error, it returns NULL.
277 *****************************************************************************/
278 vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
280 vout_thread_t * p_vout; /* thread descriptor */
281 input_thread_t * p_input_thread;
282 int i_index; /* loop variable */
283 vlc_value_t val, text;
285 unsigned int i_width = p_fmt->i_width;
286 unsigned int i_height = p_fmt->i_height;
287 vlc_fourcc_t i_chroma = p_fmt->i_chroma;
288 unsigned int i_aspect = p_fmt->i_aspect;
290 config_chain_t *p_cfg;
294 if( i_width <= 0 || i_height <= 0 || i_aspect <= 0 )
297 vlc_ureduce( &p_fmt->i_sar_num, &p_fmt->i_sar_den,
298 p_fmt->i_sar_num, p_fmt->i_sar_den, 50000 );
299 if( p_fmt->i_sar_num <= 0 || p_fmt->i_sar_den <= 0 )
302 /* Allocate descriptor */
303 static const char typename[] = "video output";
304 p_vout = vlc_custom_create( p_parent, sizeof( *p_vout ), VLC_OBJECT_VOUT,
310 p_vout->p = calloc( 1, sizeof(p_vout->p) );
313 vlc_object_release( p_vout );
317 /* Initialize pictures - translation tables and functions
318 * will be initialized later in InitThread */
319 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++)
321 p_vout->p_picture[i_index].pf_lock = NULL;
322 p_vout->p_picture[i_index].pf_unlock = NULL;
323 p_vout->p_picture[i_index].i_status = FREE_PICTURE;
324 p_vout->p_picture[i_index].i_type = EMPTY_PICTURE;
325 p_vout->p_picture[i_index].b_slow = 0;
328 /* No images in the heap */
329 p_vout->i_heap_size = 0;
331 /* Initialize the rendering heap */
332 I_RENDERPICTURES = 0;
334 p_vout->fmt_render = *p_fmt; /* FIXME palette */
335 p_vout->fmt_in = *p_fmt; /* FIXME palette */
337 p_vout->render.i_width = i_width;
338 p_vout->render.i_height = i_height;
339 p_vout->render.i_chroma = i_chroma;
340 p_vout->render.i_aspect = i_aspect;
342 p_vout->render.i_rmask = p_fmt->i_rmask;
343 p_vout->render.i_gmask = p_fmt->i_gmask;
344 p_vout->render.i_bmask = p_fmt->i_bmask;
346 p_vout->render.i_last_used_pic = -1;
347 p_vout->render.b_allow_modify_pics = 1;
349 /* Zero the output heap */
350 I_OUTPUTPICTURES = 0;
351 p_vout->output.i_width = 0;
352 p_vout->output.i_height = 0;
353 p_vout->output.i_chroma = 0;
354 p_vout->output.i_aspect = 0;
356 p_vout->output.i_rmask = 0;
357 p_vout->output.i_gmask = 0;
358 p_vout->output.i_bmask = 0;
360 /* Initialize misc stuff */
361 p_vout->i_changes = 0;
363 p_vout->b_fullscreen = 0;
364 p_vout->i_alignment = 0;
365 p_vout->p->render_time = 10;
366 p_vout->p->c_fps_samples = 0;
367 p_vout->p->b_filter_change = 0;
368 p_vout->pf_control = NULL;
369 p_vout->p_window = NULL;
370 p_vout->p->i_par_num =
371 p_vout->p->i_par_den = 1;
373 /* Initialize locks */
374 vlc_mutex_init( &p_vout->picture_lock );
375 vlc_mutex_init( &p_vout->change_lock );
376 vlc_mutex_init( &p_vout->p->vfilter_lock );
378 /* Mouse coordinates */
379 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
380 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
381 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
382 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
383 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
385 /* Initialize subpicture unit */
386 p_vout->p_spu = spu_Create( p_vout );
387 spu_Attach( p_vout->p_spu, p_parent, true );
389 /* Attach the new object now so we can use var inheritance below */
390 vlc_object_attach( p_vout, p_parent );
392 spu_Init( p_vout->p_spu );
394 /* Take care of some "interface/control" related initialisations */
395 vout_IntfInit( p_vout );
397 /* If the parent is not a VOUT object, that means we are at the start of
398 * the video output pipe */
399 if( p_parent->i_object_type != VLC_OBJECT_VOUT )
401 /* Look for the default filter configuration */
402 p_vout->p->psz_filter_chain =
403 var_CreateGetStringCommand( p_vout, "vout-filter" );
405 /* Apply video filter2 objects on the first vout */
407 var_CreateGetStringCommand( p_vout, "video-filter" );
411 /* continue the parent's filter chain */
414 /* Ugly hack to jump to our configuration chain */
415 p_vout->p->psz_filter_chain
416 = ((vout_thread_t *)p_parent)->p->psz_filter_chain;
417 p_vout->p->psz_filter_chain
418 = config_ChainCreate( &psz_tmp, &p_cfg, p_vout->p->psz_filter_chain );
419 config_ChainDestroy( p_cfg );
422 /* Create a video filter2 var ... but don't inherit values */
423 var_Create( p_vout, "video-filter",
424 VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
425 p_vout->p->psz_vf2 = var_GetString( p_vout, "video-filter" );
428 var_AddCallback( p_vout, "video-filter", VideoFilter2Callback, NULL );
429 p_vout->p->p_vf2_chain = filter_chain_New( p_vout, "video filter2",
430 false, video_filter_buffer_allocation_init, NULL, p_vout );
432 /* Choose the video output module */
433 if( !p_vout->p->psz_filter_chain || !*p_vout->p->psz_filter_chain )
435 var_Create( p_vout, "vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
436 var_Get( p_vout, "vout", &val );
437 psz_parser = val.psz_string;
441 psz_parser = strdup( p_vout->p->psz_filter_chain );
442 p_vout->p->b_title_show = false;
445 /* Create the vout thread */
446 char* psz_tmp = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
449 p_vout->p_cfg = p_cfg;
450 p_vout->p_module = module_need( p_vout,
451 ( p_vout->p->psz_filter_chain && *p_vout->p->psz_filter_chain ) ?
452 "video filter" : "video output", psz_name, p_vout->p->psz_filter_chain && *p_vout->p->psz_filter_chain );
455 if( p_vout->p_module == NULL )
457 msg_Err( p_vout, "no suitable vout module" );
458 // FIXME it's ugly but that's exactly the function that need to be called.
460 vlc_object_detach( p_vout );
461 vlc_object_release( p_vout );
465 /* Create a few object variables for interface interaction */
466 var_Create( p_vout, "deinterlace", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
467 text.psz_string = _("Deinterlace");
468 var_Change( p_vout, "deinterlace", VLC_VAR_SETTEXT, &text, NULL );
469 val.psz_string = (char *)""; text.psz_string = _("Disable");
470 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
471 val.psz_string = (char *)"discard"; text.psz_string = _("Discard");
472 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
473 val.psz_string = (char *)"blend"; text.psz_string = _("Blend");
474 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
475 val.psz_string = (char *)"mean"; text.psz_string = _("Mean");
476 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
477 val.psz_string = (char *)"bob"; text.psz_string = _("Bob");
478 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
479 val.psz_string = (char *)"linear"; text.psz_string = _("Linear");
480 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
481 val.psz_string = (char *)"x"; text.psz_string = (char *)"X";
482 var_Change( p_vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text );
484 if( var_Get( p_vout, "deinterlace-mode", &val ) == VLC_SUCCESS )
486 var_Set( p_vout, "deinterlace", val );
487 free( val.psz_string );
489 var_AddCallback( p_vout, "deinterlace", DeinterlaceCallback, NULL );
491 var_Create( p_vout, "vout-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
492 text.psz_string = _("Filters");
493 var_Change( p_vout, "vout-filter", VLC_VAR_SETTEXT, &text, NULL );
494 var_AddCallback( p_vout, "vout-filter", FilterCallback, NULL );
496 /* Calculate delay created by internal caching */
497 p_input_thread = (input_thread_t *)vlc_object_find( p_vout,
498 VLC_OBJECT_INPUT, FIND_ANYWHERE );
501 p_vout->p->i_pts_delay = p_input_thread->i_pts_delay;
502 vlc_object_release( p_input_thread );
506 p_vout->p->i_pts_delay = DEFAULT_PTS_DELAY;
509 if( vlc_thread_create( p_vout, "video output", RunThread,
510 VLC_THREAD_PRIORITY_OUTPUT, true ) )
512 module_unneed( p_vout, p_vout->p_module );
513 vlc_object_release( p_vout );
517 vlc_object_set_destructor( p_vout, vout_Destructor );
519 if( p_vout->b_error )
521 msg_Err( p_vout, "video output creation failed" );
522 vout_CloseAndRelease( p_vout );
529 /*****************************************************************************
530 * vout_Close: Close a vout created by vout_Create.
531 *****************************************************************************
532 * You HAVE to call it on vout created by vout_Create before vlc_object_release.
533 * You should NEVER call it on vout not obtained through vout_Create
534 * (like with vout_Request or vlc_object_find.)
535 * You can use vout_CloseAndRelease() as a convenient method.
536 *****************************************************************************/
537 void vout_Close( vout_thread_t *p_vout )
541 vlc_object_kill( p_vout );
542 vlc_thread_join( p_vout );
543 module_unneed( p_vout, p_vout->p_module );
544 p_vout->p_module = NULL;
548 static void vout_Destructor( vlc_object_t * p_this )
550 vout_thread_t *p_vout = (vout_thread_t *)p_this;
552 /* Make sure the vout was stopped first */
553 assert( !p_vout->p_module );
555 /* Destroy the locks */
556 vlc_mutex_destroy( &p_vout->picture_lock );
557 vlc_mutex_destroy( &p_vout->change_lock );
558 vlc_mutex_destroy( &p_vout->p->vfilter_lock );
560 free( p_vout->p->psz_filter_chain );
562 config_ChainDestroy( p_vout->p_cfg );
567 vout_thread_t *p_another_vout;
569 /* This is a dirty hack mostly for Linux, where there is no way to get the
570 * GUI back if you closed it while playing video. This is solved in
571 * Mac OS X, where we have this novelty called menubar, that will always
572 * allow you access to the applications main functionality. They should try
573 * that on linux sometime. */
574 p_another_vout = vlc_object_find( p_this->p_libvlc,
575 VLC_OBJECT_VOUT, FIND_ANYWHERE );
576 if( p_another_vout == NULL )
577 var_SetBool( p_this->p_libvlc, "intf-show", true );
579 vlc_object_release( p_another_vout );
583 /*****************************************************************************
584 * InitThread: initialize video output thread
585 *****************************************************************************
586 * This function is called from RunThread and performs the second step of the
587 * initialization. It returns 0 on success. Note that the thread's flag are not
588 * modified inside this function.
589 * XXX You have to enter it with change_lock taken.
590 *****************************************************************************/
591 static int ChromaCreate( vout_thread_t *p_vout );
592 static void ChromaDestroy( vout_thread_t *p_vout );
594 static bool ChromaIsEqual( const picture_heap_t *p_output, const picture_heap_t *p_render )
596 if( !vout_ChromaCmp( p_output->i_chroma, p_render->i_chroma ) )
599 if( p_output->i_chroma != FOURCC_RV15 &&
600 p_output->i_chroma != FOURCC_RV16 &&
601 p_output->i_chroma != FOURCC_RV24 &&
602 p_output->i_chroma != FOURCC_RV32 )
605 return p_output->i_rmask == p_render->i_rmask &&
606 p_output->i_gmask == p_render->i_gmask &&
607 p_output->i_bmask == p_render->i_bmask;
610 static int InitThread( vout_thread_t *p_vout )
612 int i, i_aspect_x, i_aspect_y;
618 /* Initialize output method, it allocates direct buffers for us */
619 if( p_vout->pf_init( p_vout ) )
622 if( !I_OUTPUTPICTURES )
624 msg_Err( p_vout, "plugin was unable to allocate at least "
625 "one direct buffer" );
626 p_vout->pf_end( p_vout );
630 if( I_OUTPUTPICTURES > VOUT_MAX_PICTURES )
632 msg_Err( p_vout, "plugin allocated too many direct buffers, "
633 "our internal buffers must have overflown." );
634 p_vout->pf_end( p_vout );
638 msg_Dbg( p_vout, "got %i direct buffer(s)", I_OUTPUTPICTURES );
640 AspectRatio( p_vout->fmt_render.i_aspect, &i_aspect_x, &i_aspect_y );
642 msg_Dbg( p_vout, "picture in %ix%i (%i,%i,%ix%i), "
643 "chroma %4.4s, ar %i:%i, sar %i:%i",
644 p_vout->fmt_render.i_width, p_vout->fmt_render.i_height,
645 p_vout->fmt_render.i_x_offset, p_vout->fmt_render.i_y_offset,
646 p_vout->fmt_render.i_visible_width,
647 p_vout->fmt_render.i_visible_height,
648 (char*)&p_vout->fmt_render.i_chroma,
649 i_aspect_x, i_aspect_y,
650 p_vout->fmt_render.i_sar_num, p_vout->fmt_render.i_sar_den );
652 AspectRatio( p_vout->fmt_in.i_aspect, &i_aspect_x, &i_aspect_y );
654 msg_Dbg( p_vout, "picture user %ix%i (%i,%i,%ix%i), "
655 "chroma %4.4s, ar %i:%i, sar %i:%i",
656 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
657 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
658 p_vout->fmt_in.i_visible_width,
659 p_vout->fmt_in.i_visible_height,
660 (char*)&p_vout->fmt_in.i_chroma,
661 i_aspect_x, i_aspect_y,
662 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
664 if( !p_vout->fmt_out.i_width || !p_vout->fmt_out.i_height )
666 p_vout->fmt_out.i_width = p_vout->fmt_out.i_visible_width =
667 p_vout->output.i_width;
668 p_vout->fmt_out.i_height = p_vout->fmt_out.i_visible_height =
669 p_vout->output.i_height;
670 p_vout->fmt_out.i_x_offset = p_vout->fmt_out.i_y_offset = 0;
672 p_vout->fmt_out.i_aspect = p_vout->output.i_aspect;
673 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
675 if( !p_vout->fmt_out.i_sar_num || !p_vout->fmt_out.i_sar_num )
677 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_aspect *
678 p_vout->fmt_out.i_height;
679 p_vout->fmt_out.i_sar_den = VOUT_ASPECT_FACTOR *
680 p_vout->fmt_out.i_width;
683 vlc_ureduce( &p_vout->fmt_out.i_sar_num, &p_vout->fmt_out.i_sar_den,
684 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den, 0 );
686 AspectRatio( p_vout->fmt_out.i_aspect, &i_aspect_x, &i_aspect_y );
688 msg_Dbg( p_vout, "picture out %ix%i (%i,%i,%ix%i), "
689 "chroma %4.4s, ar %i:%i, sar %i:%i",
690 p_vout->fmt_out.i_width, p_vout->fmt_out.i_height,
691 p_vout->fmt_out.i_x_offset, p_vout->fmt_out.i_y_offset,
692 p_vout->fmt_out.i_visible_width,
693 p_vout->fmt_out.i_visible_height,
694 (char*)&p_vout->fmt_out.i_chroma,
695 i_aspect_x, i_aspect_y,
696 p_vout->fmt_out.i_sar_num, p_vout->fmt_out.i_sar_den );
698 /* FIXME removed the need of both fmt_* and heap infos */
699 /* Calculate shifts from system-updated masks */
700 PictureHeapFixRgb( &p_vout->render );
701 VideoFormatImportRgb( &p_vout->fmt_render, &p_vout->render );
703 PictureHeapFixRgb( &p_vout->output );
704 VideoFormatImportRgb( &p_vout->fmt_out, &p_vout->output );
706 /* Check whether we managed to create direct buffers similar to
707 * the render buffers, ie same size and chroma */
708 if( ( p_vout->output.i_width == p_vout->render.i_width )
709 && ( p_vout->output.i_height == p_vout->render.i_height )
710 && ( ChromaIsEqual( &p_vout->output, &p_vout->render ) ) )
712 /* Cool ! We have direct buffers, we can ask the decoder to
713 * directly decode into them ! Map the first render buffers to
714 * the first direct buffers, but keep the first direct buffer
715 * for memcpy operations */
716 p_vout->p->b_direct = true;
718 for( i = 1; i < VOUT_MAX_PICTURES; i++ )
720 if( p_vout->p_picture[ i ].i_type != DIRECT_PICTURE &&
721 I_RENDERPICTURES >= VOUT_MIN_DIRECT_PICTURES - 1 &&
722 p_vout->p_picture[ i - 1 ].i_type == DIRECT_PICTURE )
724 /* We have enough direct buffers so there's no need to
725 * try to use system memory buffers. */
728 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
732 msg_Dbg( p_vout, "direct render, mapping "
733 "render pictures 0-%i to system pictures 1-%i",
734 VOUT_MAX_PICTURES - 2, VOUT_MAX_PICTURES - 1 );
738 /* Rats... Something is wrong here, we could not find an output
739 * plugin able to directly render what we decode. See if we can
740 * find a chroma plugin to do the conversion */
741 p_vout->p->b_direct = false;
743 if( ChromaCreate( p_vout ) )
745 p_vout->pf_end( p_vout );
749 msg_Dbg( p_vout, "indirect render, mapping "
750 "render pictures 0-%i to system pictures %i-%i",
751 VOUT_MAX_PICTURES - 1, I_OUTPUTPICTURES,
752 I_OUTPUTPICTURES + VOUT_MAX_PICTURES - 1 );
754 /* Append render buffers after the direct buffers */
755 for( i = I_OUTPUTPICTURES; i < 2 * VOUT_MAX_PICTURES; i++ )
757 PP_RENDERPICTURE[ I_RENDERPICTURES ] = &p_vout->p_picture[ i ];
760 /* Check if we have enough render pictures */
761 if( I_RENDERPICTURES == VOUT_MAX_PICTURES )
766 /* Link pictures back to their heap */
767 for( i = 0 ; i < I_RENDERPICTURES ; i++ )
769 PP_RENDERPICTURE[ i ]->p_heap = &p_vout->render;
772 for( i = 0 ; i < I_OUTPUTPICTURES ; i++ )
774 PP_OUTPUTPICTURE[ i ]->p_heap = &p_vout->output;
780 /*****************************************************************************
781 * RunThread: video output thread
782 *****************************************************************************
783 * Video output thread. This function does only returns when the thread is
784 * terminated. It handles the pictures arriving in the video heap and the
785 * display device events.
786 *****************************************************************************/
787 static void* RunThread( vlc_object_t *p_this )
789 vout_thread_t *p_vout = (vout_thread_t *)p_this;
790 int i_idle_loops = 0; /* loops without displaying a picture */
792 picture_t * p_last_picture = NULL; /* last picture */
794 subpicture_t * p_subpic = NULL; /* subpicture pointer */
798 int i_displayed = 0, i_lost = 0;
799 int canc = vlc_savecancel ();
804 vlc_mutex_lock( &p_vout->change_lock );
805 p_vout->b_error = InitThread( p_vout );
807 b_drop_late = var_CreateGetBool( p_vout, "drop-late-frames" );
809 /* signal the creation of the vout */
810 vlc_thread_ready( p_vout );
812 if( p_vout->b_error )
815 vlc_mutex_unlock( &p_vout->change_lock );
816 vlc_restorecancel (canc);
820 vlc_object_lock( p_vout );
822 if( p_vout->p->b_title_show )
823 DisplayTitleOnOSD( p_vout );
826 * Main loop - it is not executed if an error occurred during
829 while( vlc_object_alive( p_vout ) && !p_vout->b_error )
831 /* Initialize loop variables */
832 const mtime_t current_date = mdate();
833 picture_t *p_picture = NULL;
834 picture_t *p_filtered_picture;
835 mtime_t display_date = 0;
836 picture_t *p_directbuffer;
837 input_thread_t *p_input;
842 if( !(p_vout->c_loops % VOUT_STATS_NB_LOOPS) )
844 msg_Dbg( p_vout, "picture heap: %d/%d",
845 I_RENDERPICTURES, p_vout->i_heap_size );
849 /* Update statistics */
850 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
853 vlc_mutex_lock( &p_input->p->counters.counters_lock );
854 stats_UpdateInteger( p_vout, p_input->p->counters.p_lost_pictures,
856 stats_UpdateInteger( p_vout,
857 p_input->p->counters.p_displayed_pictures,
859 i_displayed = i_lost = 0;
860 vlc_mutex_unlock( &p_input->p->counters.counters_lock );
861 vlc_object_release( p_input );
865 * Find the picture to display (the one with the earliest date).
866 * This operation does not need lock, since only READY_PICTUREs
868 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
870 picture_t *p_pic = PP_RENDERPICTURE[i_index];
872 if( p_pic->i_status == READY_PICTURE &&
873 ( p_picture == NULL || p_pic->date < display_date ) )
876 display_date = p_picture->date;
882 /* If we met the last picture, parse again to see whether there is
883 * a more appropriate one. */
884 if( p_picture == p_last_picture )
886 for( i_index = 0; i_index < I_RENDERPICTURES; i_index++ )
888 picture_t *p_pic = PP_RENDERPICTURE[i_index];
890 if( p_pic->i_status == READY_PICTURE &&
891 p_pic != p_last_picture &&
892 ( p_picture == p_last_picture || p_pic->date < display_date ) )
895 display_date = p_picture->date;
900 /* If we found better than the last picture, destroy it */
901 if( p_last_picture && p_picture != p_last_picture )
903 DropPicture( p_vout, p_last_picture );
904 p_last_picture = NULL;
907 /* Compute FPS rate */
908 p_vout->p->p_fps_sample[ p_vout->p->c_fps_samples++ % VOUT_FPS_SAMPLES ]
911 if( !p_picture->b_force &&
912 p_picture != p_last_picture &&
913 display_date < current_date + p_vout->p->render_time &&
916 /* Picture is late: it will be destroyed and the thread
917 * will directly choose the next picture */
918 DropPicture( p_vout, p_picture );
920 msg_Warn( p_vout, "late picture skipped (%"PRId64")",
921 current_date - display_date );
926 current_date + p_vout->p->i_pts_delay + VOUT_BOGUS_DELAY )
928 /* Picture is waaay too early: it will be destroyed */
929 DropPicture( p_vout, p_picture );
931 msg_Warn( p_vout, "vout warning: early picture skipped "
932 "(%"PRId64")", display_date - current_date
933 - p_vout->p->i_pts_delay );
937 if( display_date > current_date + VOUT_DISPLAY_DELAY )
939 /* A picture is ready to be rendered, but its rendering date
940 * is far from the current one so the thread will perform an
941 * empty loop as if no picture were found. The picture state
946 else if( p_picture == p_last_picture )
948 /* We are asked to repeat the previous picture, but we first
949 * wait for a couple of idle loops */
950 if( i_idle_loops < 4 )
957 /* We set the display date to something high, otherwise
958 * we'll have lots of problems with late pictures */
959 display_date = current_date + p_vout->p->render_time;
964 if( p_picture == NULL )
967 p_filtered_picture = NULL;
969 p_filtered_picture = filter_chain_VideoFilter( p_vout->p->p_vf2_chain,
972 /* FIXME it is a bit ugly that b_snapshot is not locked but I do not
973 * know which lock to use (here and in the snapshot callback) */
974 const bool b_snapshot = p_vout->p->b_snapshot;
976 p_vout->p->b_snapshot = false;
979 * Check for subpictures to display
981 bool b_paused = false;
982 if( display_date > 0 )
984 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
985 b_paused = p_input && var_GetInteger( p_input, "state" ) == PAUSE_S;
987 vlc_object_release( p_input );
989 p_subpic = spu_SortSubpictures( p_vout->p_spu, display_date, b_paused, b_snapshot );
996 p_directbuffer = vout_RenderPicture( p_vout, p_filtered_picture, p_subpic, b_paused );
999 * Take a snapshot if requested
1001 if( p_directbuffer && b_snapshot )
1002 vout_Snapshot( p_vout, p_directbuffer );
1005 * Call the plugin-specific rendering method if there is one
1007 if( p_filtered_picture != NULL && p_directbuffer != NULL && p_vout->pf_render )
1009 /* Render the direct buffer returned by vout_RenderPicture */
1010 p_vout->pf_render( p_vout, p_directbuffer );
1016 if( display_date != 0 && p_directbuffer != NULL )
1018 mtime_t current_render_time = mdate() - current_date;
1019 /* if render time is very large we don't include it in the mean */
1020 if( current_render_time < p_vout->p->render_time +
1021 VOUT_DISPLAY_DELAY )
1023 /* Store render time using a sliding mean weighting to
1024 * current value in a 3 to 1 ratio*/
1025 p_vout->p->render_time *= 3;
1026 p_vout->p->render_time += current_render_time;
1027 p_vout->p->render_time >>= 2;
1031 /* Give back change lock */
1032 vlc_mutex_unlock( &p_vout->change_lock );
1034 vlc_object_unlock( p_vout );
1036 /* Sleep a while or until a given date */
1037 if( display_date != 0 )
1039 /* If there are filters in the chain, better give them the picture
1041 if( !p_vout->p->psz_filter_chain || !*p_vout->p->psz_filter_chain )
1043 mwait( display_date - VOUT_MWAIT_TOLERANCE );
1048 msleep( VOUT_IDLE_SLEEP );
1051 /* On awakening, take back lock and send immediately picture
1053 vlc_object_lock( p_vout );
1054 /* Note: vlc_object_alive() could be false here, and we
1056 vlc_mutex_lock( &p_vout->change_lock );
1059 * Display the previously rendered picture
1061 if( p_filtered_picture != NULL && p_directbuffer != NULL )
1063 /* Display the direct buffer returned by vout_RenderPicture */
1064 if( p_vout->pf_display )
1065 p_vout->pf_display( p_vout, p_directbuffer );
1067 /* Tell the vout this was the last picture and that it does not
1068 * need to be forced anymore. */
1069 p_last_picture = p_picture;
1070 p_last_picture->b_force = false;
1073 /* Drop the filtered picture if created by video filters */
1074 if( p_filtered_picture != NULL && p_filtered_picture != p_picture )
1075 DropPicture( p_vout, p_filtered_picture );
1077 if( p_picture != NULL )
1079 /* Reinitialize idle loop count */
1084 * Check events and manage thread
1086 if( p_vout->pf_manage && p_vout->pf_manage( p_vout ) )
1088 /* A fatal error occurred, and the thread must terminate
1089 * immediately, without displaying anything - setting b_error to 1
1090 * causes the immediate end of the main while() loop. */
1092 p_vout->b_error = 1;
1096 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
1098 /* this must only happen when the vout plugin is incapable of
1099 * rescaling the picture itself. In this case we need to destroy
1100 * the current picture buffers and recreate new ones with the right
1104 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
1106 assert( !p_vout->p->b_direct );
1108 ChromaDestroy( p_vout );
1110 vlc_mutex_lock( &p_vout->picture_lock );
1112 p_vout->pf_end( p_vout );
1114 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1115 p_vout->p_picture[ i ].i_status = FREE_PICTURE;
1117 I_OUTPUTPICTURES = 0;
1119 if( p_vout->pf_init( p_vout ) )
1121 msg_Err( p_vout, "cannot resize display" );
1122 /* FIXME: pf_end will be called again in EndThread() */
1123 p_vout->b_error = 1;
1126 vlc_mutex_unlock( &p_vout->picture_lock );
1128 /* Need to reinitialise the chroma plugin. Since we might need
1129 * resizing too and it's not sure that we already had it,
1130 * recreate the chroma plugin chain from scratch. */
1132 if( ChromaCreate( p_vout ) )
1134 msg_Err( p_vout, "WOW THIS SUCKS BIG TIME!!!!!" );
1135 p_vout->b_error = 1;
1137 if( p_vout->b_error )
1141 if( p_vout->i_changes & VOUT_PICTURE_BUFFERS_CHANGE )
1143 /* This happens when the picture buffers need to be recreated.
1144 * This is useful on multimonitor displays for instance.
1146 * Warning: This only works when the vout creates only 1 picture
1148 p_vout->i_changes &= ~VOUT_PICTURE_BUFFERS_CHANGE;
1150 if( !p_vout->p->b_direct )
1151 ChromaDestroy( p_vout );
1153 vlc_mutex_lock( &p_vout->picture_lock );
1155 p_vout->pf_end( p_vout );
1157 I_OUTPUTPICTURES = I_RENDERPICTURES = 0;
1159 p_vout->b_error = InitThread( p_vout );
1160 if( p_vout->b_error )
1161 msg_Err( p_vout, "InitThread after VOUT_PICTURE_BUFFERS_CHANGE failed\n" );
1163 vlc_mutex_unlock( &p_vout->picture_lock );
1165 if( p_vout->b_error )
1169 /* Check for "video filter2" changes */
1170 vlc_mutex_lock( &p_vout->p->vfilter_lock );
1171 if( p_vout->p->psz_vf2 )
1175 es_format_Init( &fmt, VIDEO_ES, p_vout->fmt_render.i_chroma );
1176 fmt.video = p_vout->fmt_render;
1177 filter_chain_Reset( p_vout->p->p_vf2_chain, &fmt, &fmt );
1179 if( filter_chain_AppendFromString( p_vout->p->p_vf2_chain,
1180 p_vout->p->psz_vf2 ) < 0 )
1181 msg_Err( p_vout, "Video filter chain creation failed" );
1183 free( p_vout->p->psz_vf2 );
1184 p_vout->p->psz_vf2 = NULL;
1186 vlc_mutex_unlock( &p_vout->p->vfilter_lock );
1190 * Error loop - wait until the thread destruction is requested
1192 if( p_vout->b_error )
1193 ErrorThread( p_vout );
1196 CleanThread( p_vout );
1197 EndThread( p_vout );
1198 vlc_mutex_unlock( &p_vout->change_lock );
1200 vlc_object_unlock( p_vout );
1201 vlc_restorecancel (canc);
1205 /*****************************************************************************
1206 * ErrorThread: RunThread() error loop
1207 *****************************************************************************
1208 * This function is called when an error occurred during thread main's loop.
1209 * The thread can still receive feed, but must be ready to terminate as soon
1211 *****************************************************************************/
1212 static void ErrorThread( vout_thread_t *p_vout )
1214 /* Wait until a `die' order */
1215 while( vlc_object_alive( p_vout ) )
1216 vlc_object_wait( p_vout );
1219 /*****************************************************************************
1220 * CleanThread: clean up after InitThread
1221 *****************************************************************************
1222 * This function is called after a sucessful
1223 * initialization. It frees all resources allocated by InitThread.
1224 * XXX You have to enter it with change_lock taken.
1225 *****************************************************************************/
1226 static void CleanThread( vout_thread_t *p_vout )
1228 int i_index; /* index in heap */
1230 if( !p_vout->p->b_direct )
1231 ChromaDestroy( p_vout );
1233 /* Destroy all remaining pictures */
1234 for( i_index = 0; i_index < 2 * VOUT_MAX_PICTURES + 1; i_index++ )
1236 if ( p_vout->p_picture[i_index].i_type == MEMORY_PICTURE )
1238 free( p_vout->p_picture[i_index].p_data_orig );
1242 /* Destroy translation tables */
1243 if( !p_vout->b_error )
1244 p_vout->pf_end( p_vout );
1247 /*****************************************************************************
1248 * EndThread: thread destruction
1249 *****************************************************************************
1250 * This function is called when the thread ends.
1251 * It frees all resources not allocated by InitThread.
1252 * XXX You have to enter it with change_lock taken.
1253 *****************************************************************************/
1254 static void EndThread( vout_thread_t *p_vout )
1258 struct tms cpu_usage;
1259 times( &cpu_usage );
1261 msg_Dbg( p_vout, "cpu usage (user: %d, system: %d)",
1262 cpu_usage.tms_utime, cpu_usage.tms_stime );
1266 /* FIXME does that function *really* need to be called inside the thread ? */
1268 /* Destroy subpicture unit */
1269 spu_Attach( p_vout->p_spu, VLC_OBJECT(p_vout), false );
1270 spu_Destroy( p_vout->p_spu );
1272 /* Destroy the video filters2 */
1273 filter_chain_Delete( p_vout->p->p_vf2_chain );
1276 /* Thread helpers */
1277 static picture_t *ChromaGetPicture( filter_t *p_filter )
1279 picture_t *p_pic = (picture_t *)p_filter->p_owner;
1280 p_filter->p_owner = NULL;
1284 static int ChromaCreate( vout_thread_t *p_vout )
1286 static const char typename[] = "chroma";
1289 /* Choose the best module */
1290 p_chroma = p_vout->p->p_chroma =
1291 vlc_custom_create( p_vout, sizeof(filter_t), VLC_OBJECT_GENERIC,
1294 vlc_object_attach( p_chroma, p_vout );
1296 /* TODO: Set the fmt_in and fmt_out stuff here */
1297 p_chroma->fmt_in.video = p_vout->fmt_render;
1298 p_chroma->fmt_out.video = p_vout->fmt_out;
1299 VideoFormatImportRgb( &p_chroma->fmt_in.video, &p_vout->render );
1300 VideoFormatImportRgb( &p_chroma->fmt_out.video, &p_vout->output );
1302 p_chroma->p_module = module_need( p_chroma, "video filter2", NULL, 0 );
1304 if( p_chroma->p_module == NULL )
1306 msg_Err( p_vout, "no chroma module for %4.4s to %4.4s i=%dx%d o=%dx%d",
1307 (char*)&p_vout->render.i_chroma,
1308 (char*)&p_vout->output.i_chroma,
1309 p_chroma->fmt_in.video.i_width, p_chroma->fmt_in.video.i_height,
1310 p_chroma->fmt_out.video.i_width, p_chroma->fmt_out.video.i_height
1313 vlc_object_release( p_vout->p->p_chroma );
1314 p_vout->p->p_chroma = NULL;
1316 return VLC_EGENERIC;
1318 p_chroma->pf_vout_buffer_new = ChromaGetPicture;
1322 static void ChromaDestroy( vout_thread_t *p_vout )
1324 assert( !p_vout->p->b_direct );
1326 if( !p_vout->p->p_chroma )
1329 module_unneed( p_vout->p->p_chroma, p_vout->p->p_chroma->p_module );
1330 vlc_object_release( p_vout->p->p_chroma );
1331 p_vout->p->p_chroma = NULL;
1334 static void DropPicture( vout_thread_t *p_vout, picture_t *p_picture )
1336 vlc_mutex_lock( &p_vout->picture_lock );
1337 if( p_picture->i_refcount )
1339 /* Pretend we displayed the picture, but don't destroy
1340 * it since the decoder might still need it. */
1341 p_picture->i_status = DISPLAYED_PICTURE;
1345 /* Destroy the picture without displaying it */
1346 p_picture->i_status = DESTROYED_PICTURE;
1347 p_vout->i_heap_size--;
1348 picture_CleanupQuant( p_picture );
1350 vlc_mutex_unlock( &p_vout->picture_lock );
1355 /* following functions are local */
1357 static int ReduceHeight( int i_ratio )
1359 int i_dummy = VOUT_ASPECT_FACTOR;
1367 /* VOUT_ASPECT_FACTOR is (2^7 * 3^3 * 5^3), we just check for 2, 3 and 5 */
1368 while( !(i_ratio & 1) && !(i_dummy & 1) )
1375 while( !(i_ratio % 3) && !(i_dummy % 3) )
1382 while( !(i_ratio % 5) && !(i_dummy % 5) )
1392 static void AspectRatio( int i_aspect, int *i_aspect_x, int *i_aspect_y )
1394 unsigned int i_pgcd = ReduceHeight( i_aspect );
1395 *i_aspect_x = i_aspect / i_pgcd;
1396 *i_aspect_y = VOUT_ASPECT_FACTOR / i_pgcd;
1400 * This function copies all RGB informations from a picture_heap_t into
1403 static void VideoFormatImportRgb( video_format_t *p_fmt, const picture_heap_t *p_heap )
1405 p_fmt->i_rmask = p_heap->i_rmask;
1406 p_fmt->i_gmask = p_heap->i_gmask;
1407 p_fmt->i_bmask = p_heap->i_bmask;
1408 p_fmt->i_rrshift = p_heap->i_rrshift;
1409 p_fmt->i_lrshift = p_heap->i_lrshift;
1410 p_fmt->i_rgshift = p_heap->i_rgshift;
1411 p_fmt->i_lgshift = p_heap->i_lgshift;
1412 p_fmt->i_rbshift = p_heap->i_rbshift;
1413 p_fmt->i_lbshift = p_heap->i_lbshift;
1417 * This funtion copes all RGB informations from a video_format_t into
1420 static void VideoFormatExportRgb( const video_format_t *p_fmt, picture_heap_t *p_heap )
1422 p_heap->i_rmask = p_fmt->i_rmask;
1423 p_heap->i_gmask = p_fmt->i_gmask;
1424 p_heap->i_bmask = p_fmt->i_bmask;
1425 p_heap->i_rrshift = p_fmt->i_rrshift;
1426 p_heap->i_lrshift = p_fmt->i_lrshift;
1427 p_heap->i_rgshift = p_fmt->i_rgshift;
1428 p_heap->i_lgshift = p_fmt->i_lgshift;
1429 p_heap->i_rbshift = p_fmt->i_rbshift;
1430 p_heap->i_lbshift = p_fmt->i_lbshift;
1434 * This function computes rgb shifts from masks
1436 static void PictureHeapFixRgb( picture_heap_t *p_heap )
1441 fmt.i_chroma = p_heap->i_chroma;
1442 VideoFormatImportRgb( &fmt, p_heap );
1445 video_format_FixRgb( &fmt );
1447 VideoFormatExportRgb( &fmt, p_heap );
1450 /*****************************************************************************
1451 * object variables callbacks: a bunch of object variables are used by the
1452 * interfaces to interact with the vout.
1453 *****************************************************************************/
1454 static int DeinterlaceCallback( vlc_object_t *p_this, char const *psz_cmd,
1455 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1457 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1458 input_thread_t *p_input;
1461 char *psz_mode = newval.psz_string;
1462 char *psz_filter, *psz_deinterlace = NULL;
1463 (void)psz_cmd; (void)oldval; (void)p_data;
1465 var_Get( p_vout, "vout-filter", &val );
1466 psz_filter = val.psz_string;
1467 if( psz_filter ) psz_deinterlace = strstr( psz_filter, "deinterlace" );
1469 if( !psz_mode || !*psz_mode )
1471 if( psz_deinterlace )
1473 char *psz_src = psz_deinterlace + sizeof("deinterlace") - 1;
1474 if( psz_src[0] == ':' ) psz_src++;
1475 memmove( psz_deinterlace, psz_src, strlen(psz_src) + 1 );
1478 else if( !psz_deinterlace )
1480 psz_filter = realloc( psz_filter, strlen( psz_filter ) +
1481 sizeof(":deinterlace") );
1482 if( psz_filter && *psz_filter ) strcat( psz_filter, ":" );
1483 strcat( psz_filter, "deinterlace" );
1486 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1488 if( !p_input ) return VLC_EGENERIC;
1490 if( psz_mode && *psz_mode )
1492 /* Modify input as well because the vout might have to be restarted */
1493 val.psz_string = psz_mode;
1494 var_Create( p_input, "deinterlace-mode", VLC_VAR_STRING );
1495 var_Set( p_input, "deinterlace-mode", val );
1497 vlc_object_release( p_input );
1500 var_Set( p_vout, "intf-change", val );
1502 val.psz_string = psz_filter;
1503 var_Set( p_vout, "vout-filter", val );
1509 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
1510 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1512 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1513 input_thread_t *p_input;
1515 (void)psz_cmd; (void)oldval; (void)p_data;
1517 p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
1521 msg_Err( p_vout, "Input not found" );
1522 return( VLC_EGENERIC );
1526 var_Set( p_vout, "intf-change", val );
1528 /* Modify input as well because the vout might have to be restarted */
1529 val.psz_string = newval.psz_string;
1530 var_Create( p_input, "vout-filter", VLC_VAR_STRING );
1532 var_Set( p_input, "vout-filter", val );
1534 /* Now restart current video stream */
1535 input_Control( p_input, INPUT_RESTART_ES, -VIDEO_ES );
1536 vlc_object_release( p_input );
1541 /*****************************************************************************
1542 * Video Filter2 stuff
1543 *****************************************************************************/
1544 static int VideoFilter2Callback( vlc_object_t *p_this, char const *psz_cmd,
1545 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1547 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1548 (void)psz_cmd; (void)oldval; (void)p_data;
1550 vlc_mutex_lock( &p_vout->p->vfilter_lock );
1551 p_vout->p->psz_vf2 = strdup( newval.psz_string );
1552 vlc_mutex_unlock( &p_vout->p->vfilter_lock );
1557 static void DisplayTitleOnOSD( vout_thread_t *p_vout )
1559 input_thread_t *p_input;
1560 mtime_t i_now, i_stop;
1562 if( !config_GetInt( p_vout, "osd" ) ) return;
1564 p_input = (input_thread_t *)vlc_object_find( p_vout,
1565 VLC_OBJECT_INPUT, FIND_ANYWHERE );
1569 i_stop = i_now + (mtime_t)(p_vout->p->i_title_timeout * 1000);
1570 char *psz_nowplaying =
1571 input_item_GetNowPlaying( input_GetItem( p_input ) );
1572 char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
1573 char *psz_name = input_item_GetTitle( input_GetItem( p_input ) );
1574 if( EMPTY_STR( psz_name ) )
1577 psz_name = input_item_GetName( input_GetItem( p_input ) );
1579 if( !EMPTY_STR( psz_nowplaying ) )
1581 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1582 psz_nowplaying, NULL,
1583 p_vout->p->i_title_position,
1584 30 + p_vout->fmt_in.i_width
1585 - p_vout->fmt_in.i_visible_width
1586 - p_vout->fmt_in.i_x_offset,
1587 20 + p_vout->fmt_in.i_y_offset,
1590 else if( !EMPTY_STR( psz_artist ) )
1592 char *psz_string = NULL;
1593 if( asprintf( &psz_string, "%s - %s", psz_name, psz_artist ) != -1 )
1595 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1597 p_vout->p->i_title_position,
1598 30 + p_vout->fmt_in.i_width
1599 - p_vout->fmt_in.i_visible_width
1600 - p_vout->fmt_in.i_x_offset,
1601 20 + p_vout->fmt_in.i_y_offset,
1608 vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
1610 p_vout->p->i_title_position,
1611 30 + p_vout->fmt_in.i_width
1612 - p_vout->fmt_in.i_visible_width
1613 - p_vout->fmt_in.i_x_offset,
1614 20 + p_vout->fmt_in.i_y_offset,
1617 vlc_object_release( p_input );
1620 free( psz_nowplaying );