1 /*****************************************************************************
2 * deinterlace.c : deinterlacer plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
7 * Author: Sam 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() */
38 #include "filter_common.h"
40 #define DEINTERLACE_DISCARD 1
41 #define DEINTERLACE_MEAN 2
42 #define DEINTERLACE_BLEND 3
43 #define DEINTERLACE_BOB 4
44 #define DEINTERLACE_LINEAR 5
46 /*****************************************************************************
48 *****************************************************************************/
49 static int Create ( vlc_object_t * );
50 static void Destroy ( vlc_object_t * );
52 static int Init ( vout_thread_t * );
53 static void End ( vout_thread_t * );
54 static void Render ( vout_thread_t *, picture_t * );
56 static void RenderDiscard( vout_thread_t *, picture_t *, picture_t *, int );
57 static void RenderBob ( vout_thread_t *, picture_t *, picture_t *, int );
58 static void RenderMean ( vout_thread_t *, picture_t *, picture_t * );
59 static void RenderBlend ( vout_thread_t *, picture_t *, picture_t * );
60 static void RenderLinear ( vout_thread_t *, picture_t *, picture_t *, int );
62 static void MergeGeneric ( void *, const void *, const void *, size_t );
63 #if defined(CAN_COMPILE_C_ALTIVEC)
64 static void MergeAltivec ( void *, const void *, const void *, size_t );
66 #if defined(CAN_COMPILE_MMXEXT)
67 static void MergeMMX ( void *, const void *, const void *, size_t );
69 #if defined(CAN_COMPILE_SSE)
70 static void MergeSSE2 ( void *, const void *, const void *, size_t );
72 #if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)
73 static void EndMMX ( void );
76 static int SendEvents ( vlc_object_t *, char const *,
77 vlc_value_t, vlc_value_t, void * );
79 static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method );
80 static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout );
82 /*****************************************************************************
84 *****************************************************************************/
85 static int FilterCallback ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
88 /*****************************************************************************
90 *****************************************************************************/
91 #define MODE_TEXT N_("Deinterlace mode")
92 #define MODE_LONGTEXT N_("You can choose the default deinterlace mode")
94 static char *mode_list[] = { "discard", "blend", "mean", "bob", "linear" };
95 static char *mode_list_text[] = { N_("Discard"), N_("Blend"), N_("Mean"),
96 N_("Bob"), N_("Linear") };
99 set_description( _("Deinterlacing video filter") );
100 set_capability( "video filter", 0 );
101 set_category( CAT_VIDEO );
102 set_subcategory( SUBCAT_VIDEO_VFILTER );
104 add_string( "deinterlace-mode", "discard", NULL, MODE_TEXT,
105 MODE_LONGTEXT, VLC_FALSE );
106 change_string_list( mode_list, mode_list_text, 0 );
108 add_shortcut( "deinterlace" );
109 set_callbacks( Create, Destroy );
112 /*****************************************************************************
113 * vout_sys_t: Deinterlace video output method descriptor
114 *****************************************************************************
115 * This structure is part of the video output thread descriptor.
116 * It describes the Deinterlace specific properties of an output thread.
117 *****************************************************************************/
120 int i_mode; /* Deinterlace mode */
121 vlc_bool_t b_double_rate; /* Shall we double the framerate? */
126 vout_thread_t *p_vout;
128 vlc_mutex_t filter_lock;
130 void (*pf_merge) ( void *, const void *, const void *, size_t );
131 void (*pf_end_merge) ( void );
134 /*****************************************************************************
135 * Control: control facility for the vout (forwards to child vout)
136 *****************************************************************************/
137 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
139 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
142 /*****************************************************************************
143 * Create: allocates Deinterlace video thread output method
144 *****************************************************************************
145 * This function allocates and initializes a Deinterlace vout method.
146 *****************************************************************************/
147 static int Create( vlc_object_t *p_this )
149 vout_thread_t *p_vout = (vout_thread_t *)p_this;
152 /* Allocate structure */
153 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
154 if( p_vout->p_sys == NULL )
156 msg_Err( p_vout, "out of memory" );
160 p_vout->pf_init = Init;
161 p_vout->pf_end = End;
162 p_vout->pf_manage = NULL;
163 p_vout->pf_render = Render;
164 p_vout->pf_display = NULL;
165 p_vout->pf_control = Control;
167 p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
168 p_vout->p_sys->b_double_rate = 0;
169 p_vout->p_sys->last_date = 0;
170 p_vout->p_sys->p_vout = 0;
171 vlc_mutex_init( p_vout, &p_vout->p_sys->filter_lock );
173 #if defined(CAN_COMPILE_C_ALTIVEC)
174 if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC )
176 p_vout->p_sys->pf_merge = MergeAltivec;
177 p_vout->p_sys->pf_end_merge = NULL;
181 #if defined(CAN_COMPILE_SSE)
182 if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_SSE2 )
184 p_vout->p_sys->pf_merge = MergeSSE2;
185 p_vout->p_sys->pf_end_merge = EndMMX;
189 #if defined(CAN_COMPILE_MMXEXT)
190 if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_MMX )
192 p_vout->p_sys->pf_merge = MergeMMX;
193 p_vout->p_sys->pf_end_merge = EndMMX;
198 p_vout->p_sys->pf_merge = MergeGeneric;
199 p_vout->p_sys->pf_end_merge = NULL;
202 /* Look what method was requested */
203 var_Create( p_vout, "deinterlace-mode", VLC_VAR_STRING );
204 var_Change( p_vout, "deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL );
206 if( val.psz_string == NULL )
208 msg_Err( p_vout, "configuration variable deinterlace-mode empty" );
209 msg_Err( p_vout, "no deinterlace mode provided, using \"discard\"" );
211 val.psz_string = strdup( "discard" );
214 msg_Dbg( p_vout, "using %s deinterlace mode", val.psz_string );
216 SetFilterMethod( p_vout, val.psz_string );
218 free( val.psz_string );
220 var_AddCallback( p_vout, "deinterlace-mode", FilterCallback, NULL );
225 /*****************************************************************************
226 * SetFilterMethod: setup the deinterlace method to use.
227 *****************************************************************************/
228 static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method )
230 if( !strcmp( psz_method, "discard" ) )
232 p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
233 p_vout->p_sys->b_double_rate = 0;
235 else if( !strcmp( psz_method, "mean" ) )
237 p_vout->p_sys->i_mode = DEINTERLACE_MEAN;
238 p_vout->p_sys->b_double_rate = 0;
240 else if( !strcmp( psz_method, "blend" )
241 || !strcmp( psz_method, "average" )
242 || !strcmp( psz_method, "combine-fields" ) )
244 p_vout->p_sys->i_mode = DEINTERLACE_BLEND;
245 p_vout->p_sys->b_double_rate = 0;
247 else if( !strcmp( psz_method, "bob" )
248 || !strcmp( psz_method, "progressive-scan" ) )
250 p_vout->p_sys->i_mode = DEINTERLACE_BOB;
251 p_vout->p_sys->b_double_rate = 1;
253 else if( !strcmp( psz_method, "linear" ) )
255 p_vout->p_sys->i_mode = DEINTERLACE_LINEAR;
256 p_vout->p_sys->b_double_rate = 1;
260 msg_Err( p_vout, "no valid deinterlace mode provided, "
261 "using \"discard\"" );
264 msg_Dbg( p_vout, "using %s deinterlace method", psz_method );
267 /*****************************************************************************
268 * Init: initialize Deinterlace video thread output method
269 *****************************************************************************/
270 static int Init( vout_thread_t *p_vout )
275 I_OUTPUTPICTURES = 0;
277 /* Initialize the output structure, full of directbuffers since we want
278 * the decoder to output directly to our structures. */
279 switch( p_vout->render.i_chroma )
281 case VLC_FOURCC('I','4','2','0'):
282 case VLC_FOURCC('I','Y','U','V'):
283 case VLC_FOURCC('Y','V','1','2'):
284 case VLC_FOURCC('I','4','2','2'):
285 p_vout->output.i_chroma = p_vout->render.i_chroma;
286 p_vout->output.i_width = p_vout->render.i_width;
287 p_vout->output.i_height = p_vout->render.i_height;
288 p_vout->output.i_aspect = p_vout->render.i_aspect;
292 return VLC_EGENERIC; /* unknown chroma */
296 /* Try to open the real video output */
297 p_vout->p_sys->p_vout = SpawnRealVout( p_vout );
299 if( p_vout->p_sys->p_vout == NULL )
301 /* Everything failed */
302 msg_Err( p_vout, "cannot open vout, aborting" );
307 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
309 ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
311 ADD_PARENT_CALLBACKS( SendEventsToChild );
316 /*****************************************************************************
317 * SpawnRealVout: spawn the real video output.
318 *****************************************************************************/
319 static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout )
321 vout_thread_t *p_real_vout = NULL;
323 msg_Dbg( p_vout, "spawning the real video output" );
325 switch( p_vout->render.i_chroma )
327 case VLC_FOURCC('I','4','2','0'):
328 case VLC_FOURCC('I','Y','U','V'):
329 case VLC_FOURCC('Y','V','1','2'):
330 switch( p_vout->p_sys->i_mode )
332 case DEINTERLACE_MEAN:
333 case DEINTERLACE_DISCARD:
336 p_vout->output.i_width, p_vout->output.i_height / 2,
337 p_vout->output.i_chroma, p_vout->output.i_aspect );
340 case DEINTERLACE_BOB:
341 case DEINTERLACE_BLEND:
342 case DEINTERLACE_LINEAR:
345 p_vout->output.i_width, p_vout->output.i_height,
346 p_vout->output.i_chroma, p_vout->output.i_aspect );
351 case VLC_FOURCC('I','4','2','2'):
354 p_vout->output.i_width, p_vout->output.i_height,
355 VLC_FOURCC('I','4','2','0'), p_vout->output.i_aspect );
365 /*****************************************************************************
366 * End: terminate Deinterlace video thread output method
367 *****************************************************************************/
368 static void End( vout_thread_t *p_vout )
372 /* Free the fake output buffers we allocated */
373 for( i_index = I_OUTPUTPICTURES ; i_index ; )
376 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
380 /*****************************************************************************
381 * Destroy: destroy Deinterlace video thread output method
382 *****************************************************************************
383 * Terminate an output method created by DeinterlaceCreateOutputMethod
384 *****************************************************************************/
385 static void Destroy( vlc_object_t *p_this )
387 vout_thread_t *p_vout = (vout_thread_t *)p_this;
389 if( p_vout->p_sys->p_vout )
391 DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
392 vlc_object_detach( p_vout->p_sys->p_vout );
393 vout_Destroy( p_vout->p_sys->p_vout );
396 DEL_PARENT_CALLBACKS( SendEventsToChild );
398 free( p_vout->p_sys );
401 /*****************************************************************************
402 * Render: displays previously rendered output
403 *****************************************************************************
404 * This function send the currently rendered image to Deinterlace image,
405 * waits until it is displayed and switch the two rendering buffers, preparing
407 *****************************************************************************/
408 static void Render ( vout_thread_t *p_vout, picture_t *p_pic )
410 picture_t *pp_outpic[2];
412 vlc_mutex_lock( &p_vout->p_sys->filter_lock );
414 /* Get a new picture */
415 while( ( pp_outpic[0] = vout_CreatePicture( p_vout->p_sys->p_vout,
419 if( p_vout->b_die || p_vout->b_error )
421 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
424 msleep( VOUT_OUTMEM_SLEEP );
427 vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[0], p_pic->date );
429 /* If we are using double rate, get an additional new picture */
430 if( p_vout->p_sys->b_double_rate )
432 while( ( pp_outpic[1] = vout_CreatePicture( p_vout->p_sys->p_vout,
436 if( p_vout->b_die || p_vout->b_error )
438 vout_DestroyPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
439 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
442 msleep( VOUT_OUTMEM_SLEEP );
445 /* 20ms is a bit arbitrary, but it's only for the first image we get */
446 if( !p_vout->p_sys->last_date )
448 vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
449 p_pic->date + 20000 );
453 vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
454 (3 * p_pic->date - p_vout->p_sys->last_date) / 2 );
456 p_vout->p_sys->last_date = p_pic->date;
459 switch( p_vout->p_sys->i_mode )
461 case DEINTERLACE_DISCARD:
462 RenderDiscard( p_vout, pp_outpic[0], p_pic, 0 );
463 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
466 case DEINTERLACE_BOB:
467 RenderBob( p_vout, pp_outpic[0], p_pic, 0 );
468 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
469 RenderBob( p_vout, pp_outpic[1], p_pic, 1 );
470 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
473 case DEINTERLACE_LINEAR:
474 RenderLinear( p_vout, pp_outpic[0], p_pic, 0 );
475 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
476 RenderLinear( p_vout, pp_outpic[1], p_pic, 1 );
477 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
480 case DEINTERLACE_MEAN:
481 RenderMean( p_vout, pp_outpic[0], p_pic );
482 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
485 case DEINTERLACE_BLEND:
486 RenderBlend( p_vout, pp_outpic[0], p_pic );
487 vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
491 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
494 /*****************************************************************************
495 * RenderDiscard: only keep TOP or BOTTOM field, discard the other.
496 *****************************************************************************/
497 static void RenderDiscard( vout_thread_t *p_vout,
498 picture_t *p_outpic, picture_t *p_pic, int i_field )
502 /* Copy image and skip lines */
503 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
505 uint8_t *p_in, *p_out_end, *p_out;
508 p_in = p_pic->p[i_plane].p_pixels
509 + i_field * p_pic->p[i_plane].i_pitch;
511 p_out = p_outpic->p[i_plane].p_pixels;
512 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
513 * p_outpic->p[i_plane].i_visible_lines;
515 switch( p_vout->render.i_chroma )
517 case VLC_FOURCC('I','4','2','0'):
518 case VLC_FOURCC('I','Y','U','V'):
519 case VLC_FOURCC('Y','V','1','2'):
521 for( ; p_out < p_out_end ; )
523 p_vout->p_vlc->pf_memcpy( p_out, p_in,
524 p_pic->p[i_plane].i_pitch );
526 p_out += p_pic->p[i_plane].i_pitch;
527 p_in += 2 * p_pic->p[i_plane].i_pitch;
531 case VLC_FOURCC('I','4','2','2'):
533 i_increment = 2 * p_pic->p[i_plane].i_pitch;
535 if( i_plane == Y_PLANE )
537 for( ; p_out < p_out_end ; )
539 p_vout->p_vlc->pf_memcpy( p_out, p_in,
540 p_pic->p[i_plane].i_pitch );
541 p_out += p_pic->p[i_plane].i_pitch;
542 p_vout->p_vlc->pf_memcpy( p_out, p_in,
543 p_pic->p[i_plane].i_pitch );
544 p_out += p_pic->p[i_plane].i_pitch;
550 for( ; p_out < p_out_end ; )
552 p_vout->p_vlc->pf_memcpy( p_out, p_in,
553 p_pic->p[i_plane].i_pitch );
554 p_out += p_pic->p[i_plane].i_pitch;
566 /*****************************************************************************
567 * RenderBob: renders a BOB picture - simple copy
568 *****************************************************************************/
569 static void RenderBob( vout_thread_t *p_vout,
570 picture_t *p_outpic, picture_t *p_pic, int i_field )
574 /* Copy image and skip lines */
575 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
577 uint8_t *p_in, *p_out_end, *p_out;
579 p_in = p_pic->p[i_plane].p_pixels;
580 p_out = p_outpic->p[i_plane].p_pixels;
581 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
582 * p_outpic->p[i_plane].i_visible_lines;
584 switch( p_vout->render.i_chroma )
586 case VLC_FOURCC('I','4','2','0'):
587 case VLC_FOURCC('I','Y','U','V'):
588 case VLC_FOURCC('Y','V','1','2'):
589 /* For BOTTOM field we need to add the first line */
592 p_vout->p_vlc->pf_memcpy( p_out, p_in,
593 p_pic->p[i_plane].i_pitch );
594 p_in += p_pic->p[i_plane].i_pitch;
595 p_out += p_pic->p[i_plane].i_pitch;
598 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
600 for( ; p_out < p_out_end ; )
602 p_vout->p_vlc->pf_memcpy( p_out, p_in,
603 p_pic->p[i_plane].i_pitch );
605 p_out += p_pic->p[i_plane].i_pitch;
607 p_vout->p_vlc->pf_memcpy( p_out, p_in,
608 p_pic->p[i_plane].i_pitch );
610 p_in += 2 * p_pic->p[i_plane].i_pitch;
611 p_out += p_pic->p[i_plane].i_pitch;
614 p_vout->p_vlc->pf_memcpy( p_out, p_in,
615 p_pic->p[i_plane].i_pitch );
617 /* For TOP field we need to add the last line */
620 p_in += p_pic->p[i_plane].i_pitch;
621 p_out += p_pic->p[i_plane].i_pitch;
622 p_vout->p_vlc->pf_memcpy( p_out, p_in,
623 p_pic->p[i_plane].i_pitch );
627 case VLC_FOURCC('I','4','2','2'):
628 /* For BOTTOM field we need to add the first line */
631 p_vout->p_vlc->pf_memcpy( p_out, p_in,
632 p_pic->p[i_plane].i_pitch );
633 p_in += p_pic->p[i_plane].i_pitch;
634 p_out += p_pic->p[i_plane].i_pitch;
637 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
639 if( i_plane == Y_PLANE )
641 for( ; p_out < p_out_end ; )
643 p_vout->p_vlc->pf_memcpy( p_out, p_in,
644 p_pic->p[i_plane].i_pitch );
646 p_out += p_pic->p[i_plane].i_pitch;
648 p_vout->p_vlc->pf_memcpy( p_out, p_in,
649 p_pic->p[i_plane].i_pitch );
651 p_in += 2 * p_pic->p[i_plane].i_pitch;
652 p_out += p_pic->p[i_plane].i_pitch;
657 for( ; p_out < p_out_end ; )
659 p_vout->p_vlc->pf_memcpy( p_out, p_in,
660 p_pic->p[i_plane].i_pitch );
662 p_out += p_pic->p[i_plane].i_pitch;
663 p_in += 2 * p_pic->p[i_plane].i_pitch;
667 p_vout->p_vlc->pf_memcpy( p_out, p_in,
668 p_pic->p[i_plane].i_pitch );
670 /* For TOP field we need to add the last line */
673 p_in += p_pic->p[i_plane].i_pitch;
674 p_out += p_pic->p[i_plane].i_pitch;
675 p_vout->p_vlc->pf_memcpy( p_out, p_in,
676 p_pic->p[i_plane].i_pitch );
683 #define Merge p_vout->p_sys->pf_merge
684 #define EndMerge if(p_vout->p_sys->pf_end_merge) p_vout->p_sys->pf_end_merge
686 /*****************************************************************************
687 * RenderLinear: BOB with linear interpolation
688 *****************************************************************************/
689 static void RenderLinear( vout_thread_t *p_vout,
690 picture_t *p_outpic, picture_t *p_pic, int i_field )
694 /* Copy image and skip lines */
695 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
697 uint8_t *p_in, *p_out_end, *p_out;
699 p_in = p_pic->p[i_plane].p_pixels;
700 p_out = p_outpic->p[i_plane].p_pixels;
701 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
702 * p_outpic->p[i_plane].i_visible_lines;
704 /* For BOTTOM field we need to add the first line */
707 p_vout->p_vlc->pf_memcpy( p_out, p_in,
708 p_pic->p[i_plane].i_pitch );
709 p_in += p_pic->p[i_plane].i_pitch;
710 p_out += p_pic->p[i_plane].i_pitch;
713 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
715 for( ; p_out < p_out_end ; )
717 p_vout->p_vlc->pf_memcpy( p_out, p_in,
718 p_pic->p[i_plane].i_pitch );
720 p_out += p_pic->p[i_plane].i_pitch;
722 Merge( p_out, p_in, p_in + 2 * p_pic->p[i_plane].i_pitch,
723 p_pic->p[i_plane].i_pitch );
725 p_in += 2 * p_pic->p[i_plane].i_pitch;
726 p_out += p_pic->p[i_plane].i_pitch;
729 p_vout->p_vlc->pf_memcpy( p_out, p_in,
730 p_pic->p[i_plane].i_pitch );
732 /* For TOP field we need to add the last line */
735 p_in += p_pic->p[i_plane].i_pitch;
736 p_out += p_pic->p[i_plane].i_pitch;
737 p_vout->p_vlc->pf_memcpy( p_out, p_in,
738 p_pic->p[i_plane].i_pitch );
744 static void RenderMean( vout_thread_t *p_vout,
745 picture_t *p_outpic, picture_t *p_pic )
749 /* Copy image and skip lines */
750 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
752 uint8_t *p_in, *p_out_end, *p_out;
754 p_in = p_pic->p[i_plane].p_pixels;
756 p_out = p_outpic->p[i_plane].p_pixels;
757 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
758 * p_outpic->p[i_plane].i_visible_lines;
760 /* All lines: mean value */
761 for( ; p_out < p_out_end ; )
763 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
764 p_pic->p[i_plane].i_pitch );
766 p_out += p_pic->p[i_plane].i_pitch;
767 p_in += 2 * p_pic->p[i_plane].i_pitch;
773 static void RenderBlend( vout_thread_t *p_vout,
774 picture_t *p_outpic, picture_t *p_pic )
778 /* Copy image and skip lines */
779 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
781 uint8_t *p_in, *p_out_end, *p_out;
783 p_in = p_pic->p[i_plane].p_pixels;
785 p_out = p_outpic->p[i_plane].p_pixels;
786 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
787 * p_outpic->p[i_plane].i_visible_lines;
789 switch( p_vout->render.i_chroma )
791 case VLC_FOURCC('I','4','2','0'):
792 case VLC_FOURCC('I','Y','U','V'):
793 case VLC_FOURCC('Y','V','1','2'):
794 /* First line: simple copy */
795 p_vout->p_vlc->pf_memcpy( p_out, p_in,
796 p_pic->p[i_plane].i_pitch );
797 p_out += p_pic->p[i_plane].i_pitch;
799 /* Remaining lines: mean value */
800 for( ; p_out < p_out_end ; )
802 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
803 p_pic->p[i_plane].i_pitch );
805 p_out += p_pic->p[i_plane].i_pitch;
806 p_in += p_pic->p[i_plane].i_pitch;
810 case VLC_FOURCC('I','4','2','2'):
811 /* First line: simple copy */
812 p_vout->p_vlc->pf_memcpy( p_out, p_in,
813 p_pic->p[i_plane].i_pitch );
814 p_out += p_pic->p[i_plane].i_pitch;
816 /* Remaining lines: mean value */
817 if( i_plane == Y_PLANE )
819 for( ; p_out < p_out_end ; )
821 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
822 p_pic->p[i_plane].i_pitch );
824 p_out += p_pic->p[i_plane].i_pitch;
825 p_in += p_pic->p[i_plane].i_pitch;
831 for( ; p_out < p_out_end ; )
833 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
834 p_pic->p[i_plane].i_pitch );
836 p_out += p_pic->p[i_plane].i_pitch;
837 p_in += 2*p_pic->p[i_plane].i_pitch;
848 static void MergeGeneric( void *_p_dest, const void *_p_s1,
849 const void *_p_s2, size_t i_bytes )
851 uint8_t* p_dest = (uint8_t*)_p_dest;
852 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
853 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
854 uint8_t* p_end = p_dest + i_bytes - 8;
856 while( p_dest < p_end )
858 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
859 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
860 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
861 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
862 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
863 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
864 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
865 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
870 while( p_dest < p_end )
872 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
876 #if defined(CAN_COMPILE_MMXEXT)
877 static void MergeMMX( void *_p_dest, const void *_p_s1, const void *_p_s2,
880 uint8_t* p_dest = (uint8_t*)_p_dest;
881 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
882 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
883 uint8_t* p_end = p_dest + i_bytes - 8;
884 while( p_dest < p_end )
886 __asm__ __volatile__( "movq %2,%%mm1;"
888 "movq %%mm1, %0" :"=m" (*p_dest):
898 while( p_dest < p_end )
900 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
905 #if defined(CAN_COMPILE_SSE)
906 static void MergeSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
909 uint8_t* p_dest = (uint8_t*)_p_dest;
910 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
911 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
913 while( (int)p_s1 % 16 )
915 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
917 p_end = p_dest + i_bytes - 16;
918 while( p_dest < p_end )
920 __asm__ __volatile__( "movdqu %2,%%xmm1;"
922 "movdqu %%xmm1, %0" :"=m" (*p_dest):
932 while( p_dest < p_end )
934 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
939 #if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)
940 static void EndMMX( void )
942 __asm__ __volatile__( "emms" :: );
946 #ifdef CAN_COMPILE_C_ALTIVEC
947 static void MergeAltivec( void *_p_dest, const void *_p_s1,
948 const void *_p_s2, size_t i_bytes )
950 uint8_t *p_dest = (uint8_t *)_p_dest;
951 uint8_t *p_s1 = (uint8_t *)_p_s1;
952 uint8_t *p_s2 = (uint8_t *)_p_s2;
953 uint8_t *p_end = p_dest + i_bytes - 15;
955 /* Use C until the first 16-bytes aligned destination pixel */
956 while( (int)p_dest & 0xF )
958 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
961 if( ( (int)p_s1 & 0xF ) | ( (int)p_s2 & 0xF ) )
963 /* Unaligned source */
964 vector unsigned char s1v, s2v, destv;
965 vector unsigned char s1oldv, s2oldv, s1newv, s2newv;
966 vector unsigned char perm1v, perm2v;
968 perm1v = vec_lvsl( 0, p_s1 );
969 perm2v = vec_lvsl( 0, p_s2 );
970 s1oldv = vec_ld( 0, p_s1 );
971 s2oldv = vec_ld( 0, p_s2 );
973 while( p_dest < p_end )
975 s1newv = vec_ld( 16, p_s1 );
976 s2newv = vec_ld( 16, p_s2 );
977 s1v = vec_perm( s1oldv, s1newv, perm1v );
978 s2v = vec_perm( s2oldv, s2newv, perm2v );
981 destv = vec_avg( s1v, s2v );
982 vec_st( destv, 0, p_dest );
992 vector unsigned char s1v, s2v, destv;
994 while( p_dest < p_end )
996 s1v = vec_ld( 0, p_s1 );
997 s2v = vec_ld( 0, p_s2 );
998 destv = vec_avg( s1v, s2v );
999 vec_st( destv, 0, p_dest );
1009 while( p_dest < p_end )
1011 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
1016 /*****************************************************************************
1017 * SendEvents: forward mouse and keyboard events to the parent p_vout
1018 *****************************************************************************/
1019 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
1020 vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
1022 vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
1023 vlc_value_t sentval = newval;
1025 if( !strcmp( psz_var, "mouse-y" ) )
1027 switch( p_vout->p_sys->i_mode )
1029 case DEINTERLACE_MEAN:
1030 case DEINTERLACE_DISCARD:
1036 var_Set( p_vout, psz_var, sentval );
1041 /*****************************************************************************
1042 * FilterCallback: called when changing the deinterlace method on the fly.
1043 *****************************************************************************/
1044 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
1045 vlc_value_t oldval, vlc_value_t newval,
1048 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1049 int i_old_mode = p_vout->p_sys->i_mode;
1051 msg_Dbg( p_vout, "using %s deinterlace mode", newval.psz_string );
1053 vlc_mutex_lock( &p_vout->p_sys->filter_lock );
1055 SetFilterMethod( p_vout, newval.psz_string );
1057 switch( p_vout->render.i_chroma )
1059 case VLC_FOURCC('I','4','2','2'):
1060 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
1064 case VLC_FOURCC('I','4','2','0'):
1065 case VLC_FOURCC('I','Y','U','V'):
1066 case VLC_FOURCC('Y','V','1','2'):
1067 switch( p_vout->p_sys->i_mode )
1069 case DEINTERLACE_MEAN:
1070 case DEINTERLACE_DISCARD:
1071 if( ( i_old_mode == DEINTERLACE_MEAN )
1072 || ( i_old_mode == DEINTERLACE_DISCARD ) )
1074 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
1079 case DEINTERLACE_BOB:
1080 case DEINTERLACE_BLEND:
1081 case DEINTERLACE_LINEAR:
1082 if( ( i_old_mode == DEINTERLACE_BOB )
1083 || ( i_old_mode == DEINTERLACE_BLEND )
1084 || ( i_old_mode == DEINTERLACE_LINEAR ) )
1086 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
1097 /* We need to kill the old vout */
1099 DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
1101 vlc_object_detach( p_vout->p_sys->p_vout );
1102 vout_Destroy( p_vout->p_sys->p_vout );
1104 /* Try to open a new video output */
1105 p_vout->p_sys->p_vout = SpawnRealVout( p_vout );
1107 if( p_vout->p_sys->p_vout == NULL )
1109 /* Everything failed */
1110 msg_Err( p_vout, "cannot open vout, aborting" );
1112 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
1113 return VLC_EGENERIC;
1116 ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
1118 vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
1122 /*****************************************************************************
1123 * SendEventsToChild: forward events to the child/children vout
1124 *****************************************************************************/
1125 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
1126 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1128 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1129 var_Set( p_vout->p_sys->p_vout, psz_var, newval );