1 /*****************************************************************************
2 * deinterlace.c : deinterlacer plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
5 * $Id: deinterlace.c,v 1.16 2003/11/05 00:39:17 gbazin Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
34 #include "../filter_common.h"
36 #define DEINTERLACE_DISCARD 1
37 #define DEINTERLACE_MEAN 2
38 #define DEINTERLACE_BLEND 3
39 #define DEINTERLACE_BOB 4
40 #define DEINTERLACE_LINEAR 5
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Create ( vlc_object_t * );
46 static void Destroy ( vlc_object_t * );
48 static int Init ( vout_thread_t * );
49 static void End ( vout_thread_t * );
50 static void Render ( vout_thread_t *, picture_t * );
52 static void RenderDiscard( vout_thread_t *, picture_t *, picture_t *, int );
53 static void RenderBob ( vout_thread_t *, picture_t *, picture_t *, int );
54 static void RenderMean ( vout_thread_t *, picture_t *, picture_t * );
55 static void RenderBlend ( vout_thread_t *, picture_t *, picture_t * );
56 static void RenderLinear ( vout_thread_t *, picture_t *, picture_t *, int );
58 static void Merge ( void *, const void *, const void *, size_t );
60 static int SendEvents ( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
63 static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method );
64 static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout );
66 /*****************************************************************************
68 *****************************************************************************/
69 static int FilterCallback ( vlc_object_t *, char const *,
70 vlc_value_t, vlc_value_t, void * );
72 /*****************************************************************************
74 *****************************************************************************/
75 #define MODE_TEXT N_("Deinterlace mode")
76 #define MODE_LONGTEXT N_("You can choose the default deinterlace mode")
78 static char *mode_list[] = { "discard", "blend", "mean", "bob", "linear" };
79 static char *mode_list_text[] = { N_("discard"), N_("Blend"), N_("Mean"),
80 N_("Bob"), N_("Linear") };
83 add_category_hint( N_("Deinterlace"), NULL, VLC_FALSE );
84 add_string( "deinterlace-mode", "discard", NULL, MODE_TEXT,
85 MODE_LONGTEXT, VLC_FALSE );
86 change_string_list( mode_list, mode_list_text, 0 );
87 set_description( _("video deinterlacing filter") );
88 set_capability( "video filter", 0 );
89 add_shortcut( "deinterlace" );
90 set_callbacks( Create, Destroy );
93 /*****************************************************************************
94 * vout_sys_t: Deinterlace video output method descriptor
95 *****************************************************************************
96 * This structure is part of the video output thread descriptor.
97 * It describes the Deinterlace specific properties of an output thread.
98 *****************************************************************************/
101 int i_mode; /* Deinterlace mode */
102 vlc_bool_t b_double_rate; /* Shall we double the framerate? */
107 vout_thread_t *p_vout;
109 vlc_mutex_t filter_lock;
112 /*****************************************************************************
113 * Create: allocates Deinterlace video thread output method
114 *****************************************************************************
115 * This function allocates and initializes a Deinterlace vout method.
116 *****************************************************************************/
117 static int Create( vlc_object_t *p_this )
119 vout_thread_t *p_vout = (vout_thread_t *)p_this;
122 /* Allocate structure */
123 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
124 if( p_vout->p_sys == NULL )
126 msg_Err( p_vout, "out of memory" );
130 p_vout->pf_init = Init;
131 p_vout->pf_end = End;
132 p_vout->pf_manage = NULL;
133 p_vout->pf_render = Render;
134 p_vout->pf_display = NULL;
136 p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
137 p_vout->p_sys->b_double_rate = 0;
138 p_vout->p_sys->last_date = 0;
139 vlc_mutex_init( p_vout, &p_vout->p_sys->filter_lock );
141 /* Look what method was requested */
142 var_Create( p_vout, "deinterlace-mode", VLC_VAR_STRING );
143 var_Change( p_vout, "deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL );
145 if( val.psz_string == NULL )
147 msg_Err( p_vout, "configuration variable deinterlace-mode empty" );
148 msg_Err( p_vout, "no deinterlace mode provided, using \"discard\"" );
150 val.psz_string = strdup( "discard" );
153 msg_Dbg( p_vout, "using %s deinterlace mode", val.psz_string );
155 SetFilterMethod( p_vout, val.psz_string );
157 free( val.psz_string );
159 var_AddCallback( p_vout, "deinterlace-mode", FilterCallback, NULL );
164 /*****************************************************************************
165 * SetFilterMethod: setup the deinterlace method to use.
166 *****************************************************************************/
167 static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method )
169 if( !strcmp( psz_method, "discard" ) )
171 p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
172 p_vout->p_sys->b_double_rate = 0;
174 else if( !strcmp( psz_method, "mean" ) )
176 p_vout->p_sys->i_mode = DEINTERLACE_MEAN;
177 p_vout->p_sys->b_double_rate = 0;
179 else if( !strcmp( psz_method, "blend" )
180 || !strcmp( psz_method, "average" )
181 || !strcmp( psz_method, "combine-fields" ) )
183 p_vout->p_sys->i_mode = DEINTERLACE_BLEND;
184 p_vout->p_sys->b_double_rate = 0;
186 else if( !strcmp( psz_method, "bob" )
187 || !strcmp( psz_method, "progressive-scan" ) )
189 p_vout->p_sys->i_mode = DEINTERLACE_BOB;
190 p_vout->p_sys->b_double_rate = 1;
192 else if( !strcmp( psz_method, "linear" ) )
194 p_vout->p_sys->i_mode = DEINTERLACE_LINEAR;
195 p_vout->p_sys->b_double_rate = 1;
199 msg_Err( p_vout, "no valid deinterlace mode provided, "
200 "using \"discard\"" );
203 msg_Dbg( p_vout, "using %s deinterlace method", psz_method );
206 /*****************************************************************************
207 * Init: initialize Deinterlace video thread output method
208 *****************************************************************************/
209 static int Init( vout_thread_t *p_vout )
214 I_OUTPUTPICTURES = 0;
216 /* Initialize the output structure, full of directbuffers since we want
217 * the decoder to output directly to our structures. */
218 switch( p_vout->render.i_chroma )
220 case VLC_FOURCC('I','4','2','0'):
221 case VLC_FOURCC('I','Y','U','V'):
222 case VLC_FOURCC('Y','V','1','2'):
223 case VLC_FOURCC('I','4','2','2'):
224 p_vout->output.i_chroma = p_vout->render.i_chroma;
225 p_vout->output.i_width = p_vout->render.i_width;
226 p_vout->output.i_height = p_vout->render.i_height;
227 p_vout->output.i_aspect = p_vout->render.i_aspect;
231 return VLC_EGENERIC; /* unknown chroma */
235 /* Try to open the real video output */
236 p_vout->p_sys->p_vout = SpawnRealVout( p_vout );
238 if( p_vout->p_sys->p_vout == NULL )
240 /* Everything failed */
241 msg_Err( p_vout, "cannot open vout, aborting" );
246 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
248 ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
250 ADD_PARENT_CALLBACKS( SendEventsToChild );
255 /*****************************************************************************
256 * SpawnRealVout: spawn the real video output.
257 *****************************************************************************/
258 static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout )
260 vout_thread_t *p_real_vout = NULL;
262 msg_Dbg( p_vout, "spawning the real video output" );
264 switch( p_vout->render.i_chroma )
266 case VLC_FOURCC('I','4','2','0'):
267 case VLC_FOURCC('I','Y','U','V'):
268 case VLC_FOURCC('Y','V','1','2'):
269 switch( p_vout->p_sys->i_mode )
271 case DEINTERLACE_MEAN:
272 case DEINTERLACE_DISCARD:
275 p_vout->output.i_width, p_vout->output.i_height / 2,
276 p_vout->output.i_chroma, p_vout->output.i_aspect );
279 case DEINTERLACE_BOB:
280 case DEINTERLACE_BLEND:
281 case DEINTERLACE_LINEAR:
284 p_vout->output.i_width, p_vout->output.i_height,
285 p_vout->output.i_chroma, p_vout->output.i_aspect );
290 case VLC_FOURCC('I','4','2','2'):
293 p_vout->output.i_width, p_vout->output.i_height,
294 VLC_FOURCC('I','4','2','0'), p_vout->output.i_aspect );
304 /*****************************************************************************
305 * End: terminate Deinterlace video thread output method
306 *****************************************************************************/
307 static void End( vout_thread_t *p_vout )
311 /* Free the fake output buffers we allocated */
312 for( i_index = I_OUTPUTPICTURES ; i_index ; )
315 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
319 /*****************************************************************************
320 * Destroy: destroy Deinterlace video thread output method
321 *****************************************************************************
322 * Terminate an output method created by DeinterlaceCreateOutputMethod
323 *****************************************************************************/
324 static void Destroy( vlc_object_t *p_this )
326 vout_thread_t *p_vout = (vout_thread_t *)p_this;
328 DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
330 vlc_object_detach( p_vout->p_sys->p_vout );
331 vout_Destroy( p_vout->p_sys->p_vout );
333 DEL_PARENT_CALLBACKS( SendEventsToChild );
335 free( p_vout->p_sys );
338 /*****************************************************************************
339 * Render: displays previously rendered output
340 *****************************************************************************
341 * This function send the currently rendered image to Deinterlace image,
342 * waits until it is displayed and switch the two rendering buffers, preparing
344 *****************************************************************************/
345 static void Render ( vout_thread_t *p_vout, picture_t *p_pic )
347 picture_t *pp_outpic[2];
349 vlc_mutex_lock( &p_vout->p_sys->filter_lock );
351 /* Get a new picture */
352 while( ( pp_outpic[0] = vout_CreatePicture( p_vout->p_sys->p_vout,
356 if( p_vout->b_die || p_vout->b_error )
358 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
361 msleep( VOUT_OUTMEM_SLEEP );
364 vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[0], p_pic->date );
366 /* If we are using double rate, get an additional new picture */
367 if( p_vout->p_sys->b_double_rate )
369 while( ( pp_outpic[1] = vout_CreatePicture( p_vout->p_sys->p_vout,
373 if( p_vout->b_die || p_vout->b_error )
375 vout_DestroyPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
376 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
379 msleep( VOUT_OUTMEM_SLEEP );
382 /* 20ms is a bit arbitrary, but it's only for the first image we get */
383 if( !p_vout->p_sys->last_date )
385 vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
386 p_pic->date + 20000 );
390 vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
391 (3 * p_pic->date - p_vout->p_sys->last_date) / 2 );
393 p_vout->p_sys->last_date = p_pic->date;
396 switch( p_vout->p_sys->i_mode )
398 case DEINTERLACE_DISCARD:
399 RenderDiscard( p_vout, pp_outpic[0], p_pic, 0 );
400 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
403 case DEINTERLACE_BOB:
404 RenderBob( p_vout, pp_outpic[0], p_pic, 0 );
405 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
406 RenderBob( p_vout, pp_outpic[1], p_pic, 1 );
407 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
410 case DEINTERLACE_LINEAR:
411 RenderLinear( p_vout, pp_outpic[0], p_pic, 0 );
412 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
413 RenderLinear( p_vout, pp_outpic[1], p_pic, 1 );
414 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
417 case DEINTERLACE_MEAN:
418 RenderMean( p_vout, pp_outpic[0], p_pic );
419 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
422 case DEINTERLACE_BLEND:
423 RenderBlend( p_vout, pp_outpic[0], p_pic );
424 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
428 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
431 /*****************************************************************************
432 * RenderDiscard: only keep TOP or BOTTOM field, discard the other.
433 *****************************************************************************/
434 static void RenderDiscard( vout_thread_t *p_vout,
435 picture_t *p_outpic, picture_t *p_pic, int i_field )
439 /* Copy image and skip lines */
440 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
442 uint8_t *p_in, *p_out_end, *p_out;
445 p_in = p_pic->p[i_plane].p_pixels
446 + i_field * p_pic->p[i_plane].i_pitch;
448 p_out = p_outpic->p[i_plane].p_pixels;
449 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
450 * p_outpic->p[i_plane].i_lines;
452 switch( p_vout->render.i_chroma )
454 case VLC_FOURCC('I','4','2','0'):
455 case VLC_FOURCC('I','Y','U','V'):
456 case VLC_FOURCC('Y','V','1','2'):
458 for( ; p_out < p_out_end ; )
460 p_vout->p_vlc->pf_memcpy( p_out, p_in,
461 p_pic->p[i_plane].i_pitch );
463 p_out += p_pic->p[i_plane].i_pitch;
464 p_in += 2 * p_pic->p[i_plane].i_pitch;
468 case VLC_FOURCC('I','4','2','2'):
470 i_increment = 2 * p_pic->p[i_plane].i_pitch;
472 if( i_plane == Y_PLANE )
474 for( ; p_out < p_out_end ; )
476 p_vout->p_vlc->pf_memcpy( p_out, p_in,
477 p_pic->p[i_plane].i_pitch );
478 p_out += p_pic->p[i_plane].i_pitch;
479 p_vout->p_vlc->pf_memcpy( p_out, p_in,
480 p_pic->p[i_plane].i_pitch );
481 p_out += p_pic->p[i_plane].i_pitch;
487 for( ; p_out < p_out_end ; )
489 p_vout->p_vlc->pf_memcpy( p_out, p_in,
490 p_pic->p[i_plane].i_pitch );
491 p_out += p_pic->p[i_plane].i_pitch;
503 /*****************************************************************************
504 * RenderBob: renders a BOB picture - simple copy
505 *****************************************************************************/
506 static void RenderBob( vout_thread_t *p_vout,
507 picture_t *p_outpic, picture_t *p_pic, int i_field )
511 /* Copy image and skip lines */
512 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
514 uint8_t *p_in, *p_out_end, *p_out;
516 p_in = p_pic->p[i_plane].p_pixels;
517 p_out = p_outpic->p[i_plane].p_pixels;
518 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
519 * p_outpic->p[i_plane].i_lines;
521 /* For BOTTOM field we need to add the first line */
524 p_vout->p_vlc->pf_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
525 p_in += p_pic->p[i_plane].i_pitch;
526 p_out += p_pic->p[i_plane].i_pitch;
529 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
531 for( ; p_out < p_out_end ; )
533 p_vout->p_vlc->pf_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
535 p_out += p_pic->p[i_plane].i_pitch;
537 p_vout->p_vlc->pf_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
539 p_in += 2 * p_pic->p[i_plane].i_pitch;
540 p_out += p_pic->p[i_plane].i_pitch;
543 p_vout->p_vlc->pf_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
545 /* For TOP field we need to add the last line */
548 p_in += p_pic->p[i_plane].i_pitch;
549 p_out += p_pic->p[i_plane].i_pitch;
550 p_vout->p_vlc->pf_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
555 /*****************************************************************************
556 * RenderLinear: BOB with linear interpolation
557 *****************************************************************************/
558 static void RenderLinear( vout_thread_t *p_vout,
559 picture_t *p_outpic, picture_t *p_pic, int i_field )
563 /* Copy image and skip lines */
564 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
566 uint8_t *p_in, *p_out_end, *p_out;
568 p_in = p_pic->p[i_plane].p_pixels;
569 p_out = p_outpic->p[i_plane].p_pixels;
570 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
571 * p_outpic->p[i_plane].i_lines;
573 /* For BOTTOM field we need to add the first line */
576 p_vout->p_vlc->pf_memcpy( p_out, p_in,
577 p_pic->p[i_plane].i_pitch );
578 p_in += p_pic->p[i_plane].i_pitch;
579 p_out += p_pic->p[i_plane].i_pitch;
582 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
584 for( ; p_out < p_out_end ; )
586 p_vout->p_vlc->pf_memcpy( p_out, p_in,
587 p_pic->p[i_plane].i_pitch );
589 p_out += p_pic->p[i_plane].i_pitch;
591 Merge( p_out, p_in, p_in + 2 * p_pic->p[i_plane].i_pitch,
592 p_pic->p[i_plane].i_pitch );
594 p_in += 2 * p_pic->p[i_plane].i_pitch;
595 p_out += p_pic->p[i_plane].i_pitch;
598 p_vout->p_vlc->pf_memcpy( p_out, p_in,
599 p_pic->p[i_plane].i_pitch );
601 /* For TOP field we need to add the last line */
604 p_in += p_pic->p[i_plane].i_pitch;
605 p_out += p_pic->p[i_plane].i_pitch;
606 p_vout->p_vlc->pf_memcpy( p_out, p_in,
607 p_pic->p[i_plane].i_pitch );
612 static void RenderMean( vout_thread_t *p_vout,
613 picture_t *p_outpic, picture_t *p_pic )
617 /* Copy image and skip lines */
618 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
620 uint8_t *p_in, *p_out_end, *p_out;
622 p_in = p_pic->p[i_plane].p_pixels;
624 p_out = p_outpic->p[i_plane].p_pixels;
625 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
626 * p_outpic->p[i_plane].i_lines;
628 /* All lines: mean value */
629 for( ; p_out < p_out_end ; )
631 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
632 p_pic->p[i_plane].i_pitch );
634 p_out += p_pic->p[i_plane].i_pitch;
635 p_in += 2 * p_pic->p[i_plane].i_pitch;
640 static void RenderBlend( vout_thread_t *p_vout,
641 picture_t *p_outpic, picture_t *p_pic )
645 /* Copy image and skip lines */
646 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
648 uint8_t *p_in, *p_out_end, *p_out;
650 p_in = p_pic->p[i_plane].p_pixels;
652 p_out = p_outpic->p[i_plane].p_pixels;
653 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
654 * p_outpic->p[i_plane].i_lines;
656 /* First line: simple copy */
657 p_vout->p_vlc->pf_memcpy( p_out, p_in,
658 p_pic->p[i_plane].i_pitch );
659 p_out += p_pic->p[i_plane].i_pitch;
661 /* Remaining lines: mean value */
662 for( ; p_out < p_out_end ; )
664 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
665 p_pic->p[i_plane].i_pitch );
667 p_out += p_pic->p[i_plane].i_pitch;
668 p_in += p_pic->p[i_plane].i_pitch;
673 static void Merge( void *_p_dest, const void *_p_s1,
674 const void *_p_s2, size_t i_bytes )
676 uint8_t* p_dest = (uint8_t*)_p_dest;
677 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
678 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
679 uint8_t* p_end = p_dest + i_bytes - 8;
681 while( p_dest < p_end )
683 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
684 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
685 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
686 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
687 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
688 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
689 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
690 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
695 while( p_dest < p_end )
697 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
701 /*****************************************************************************
702 * SendEvents: forward mouse and keyboard events to the parent p_vout
703 *****************************************************************************/
704 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
705 vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
707 vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
708 vlc_value_t sentval = newval;
710 if( !strcmp( psz_var, "mouse-y" ) )
712 switch( p_vout->p_sys->i_mode )
714 case DEINTERLACE_MEAN:
715 case DEINTERLACE_DISCARD:
721 var_Set( p_vout, psz_var, sentval );
726 /*****************************************************************************
727 * FilterCallback: called when changing the deinterlace method on the fly.
728 *****************************************************************************/
729 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
730 vlc_value_t oldval, vlc_value_t newval,
733 vout_thread_t * p_vout = (vout_thread_t *)p_this;
734 int i_old_mode = p_vout->p_sys->i_mode;
736 msg_Dbg( p_vout, "using %s deinterlace mode", newval.psz_string );
738 vlc_mutex_lock( &p_vout->p_sys->filter_lock );
740 SetFilterMethod( p_vout, newval.psz_string );
742 switch( p_vout->render.i_chroma )
744 case VLC_FOURCC('I','4','2','2'):
745 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
749 case VLC_FOURCC('I','4','2','0'):
750 case VLC_FOURCC('I','Y','U','V'):
751 case VLC_FOURCC('Y','V','1','2'):
752 switch( p_vout->p_sys->i_mode )
754 case DEINTERLACE_MEAN:
755 case DEINTERLACE_DISCARD:
756 if( ( i_old_mode == DEINTERLACE_MEAN )
757 || ( i_old_mode == DEINTERLACE_DISCARD ) )
759 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
764 case DEINTERLACE_BOB:
765 case DEINTERLACE_BLEND:
766 case DEINTERLACE_LINEAR:
767 if( ( i_old_mode == DEINTERLACE_BOB )
768 || ( i_old_mode == DEINTERLACE_BLEND )
769 || ( i_old_mode == DEINTERLACE_LINEAR ) )
771 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
782 /* We need to kill the old vout */
784 DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
786 vlc_object_detach( p_vout->p_sys->p_vout );
787 vout_Destroy( p_vout->p_sys->p_vout );
789 /* Try to open a new video output */
790 p_vout->p_sys->p_vout = SpawnRealVout( p_vout );
792 if( p_vout->p_sys->p_vout == NULL )
794 /* Everything failed */
795 msg_Err( p_vout, "cannot open vout, aborting" );
797 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
801 ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
803 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
807 /*****************************************************************************
808 * SendEventsToChild: forward events to the child/children vout
809 *****************************************************************************/
810 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
811 vlc_value_t oldval, vlc_value_t newval, void *p_data )
813 vout_thread_t *p_vout = (vout_thread_t *)p_this;
814 var_Set( p_vout->p_sys->p_vout, psz_var, newval );