1 /*****************************************************************************
2 * xcommon.c: Functions common to the X11 and XVideo plugins
3 *****************************************************************************
4 * Copyright (C) 1998-2006 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Sam Hocevar <sam@zoy.org>
9 * David Kennedy <dkennedy@tinytoad.com>
10 * Gildas Bazin <gbazin@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_playlist.h>
37 #include <vlc_vout_window.h>
40 #ifdef HAVE_MACHINE_PARAM_H
42 # include <machine/param.h>
43 # include <sys/types.h> /* typedef ushort */
48 #include <X11/extensions/Xsp.h>
52 # include <sys/shm.h> /* shmget(), shmctl() */
56 #include <X11/Xproto.h>
58 #include <X11/Xutil.h>
60 # include <X11/extensions/XShm.h>
62 #ifdef DPMSINFO_IN_DPMS_H
63 # include <X11/extensions/dpms.h>
66 #ifdef MODULE_NAME_IS_glx
70 #ifdef MODULE_NAME_IS_xvmc
71 # include <X11/extensions/Xv.h>
72 # include <X11/extensions/Xvlib.h>
73 # include <X11/extensions/vldXvMC.h>
74 # include "../../codec/xvmc/accel_xvmc.h"
79 /*****************************************************************************
81 *****************************************************************************/
82 int Activate ( vlc_object_t * );
83 void Deactivate ( vlc_object_t * );
85 #ifndef MODULE_NAME_IS_glx
86 static int InitVideo ( vout_thread_t * );
87 static void EndVideo ( vout_thread_t * );
88 static void DisplayVideo ( vout_thread_t *, picture_t * );
90 static int ManageVideo ( vout_thread_t * );
91 static int Control ( vout_thread_t *, int, va_list );
93 static int InitDisplay ( vout_thread_t * );
95 static int CreateWindow ( vout_thread_t *, x11_window_t * );
96 static void DestroyWindow ( vout_thread_t *, x11_window_t * );
98 #ifndef MODULE_NAME_IS_glx
99 static int NewPicture ( vout_thread_t *, picture_t * );
100 static void FreePicture ( vout_thread_t *, picture_t * );
103 #ifdef HAVE_SYS_SHM_H
104 static int i_shm_major = 0;
107 static void ToggleFullScreen ( vout_thread_t * );
109 static void EnableXScreenSaver ( vout_thread_t * );
110 static void DisableXScreenSaver ( vout_thread_t * );
112 static void CreateCursor ( vout_thread_t * );
113 static void DestroyCursor ( vout_thread_t * );
114 static void ToggleCursor ( vout_thread_t * );
116 #if defined(MODULE_NAME_IS_xvmc)
117 static int XVideoGetPort ( vout_thread_t *, vlc_fourcc_t, picture_heap_t * );
118 static void RenderVideo ( vout_thread_t *, picture_t * );
119 //static int xvmc_check_yv12( Display *display, XvPortID port );
120 //static void xvmc_update_XV_DOUBLE_BUFFER( vout_thread_t *p_vout );
123 static int X11ErrorHandler( Display *, XErrorEvent * );
126 static void EnablePixelDoubling( vout_thread_t *p_vout );
127 static void DisablePixelDoubling( vout_thread_t *p_vout );
131 static const int i_backlight_on_interval = 300;
136 /*****************************************************************************
137 * Activate: allocate X11 video thread output method
138 *****************************************************************************
139 * This function allocate and initialize a X11 vout method. It uses some of the
140 * vout properties to choose the window size, and change them according to the
141 * actual properties of the display.
142 *****************************************************************************/
143 int Activate ( vlc_object_t *p_this )
145 vout_thread_t *p_vout = (vout_thread_t *)p_this;
147 #if defined(MODULE_NAME_IS_xvmc)
150 vlc_fourcc_t i_chroma = 0;
154 #ifndef MODULE_NAME_IS_glx
155 p_vout->pf_init = InitVideo;
156 p_vout->pf_end = EndVideo;
157 p_vout->pf_display = DisplayVideo;
159 #ifdef MODULE_NAME_IS_xvmc
160 p_vout->pf_render = RenderVideo;
162 p_vout->pf_render = NULL;
164 p_vout->pf_manage = ManageVideo;
165 p_vout->pf_control = Control;
167 /* Allocate structure */
168 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
169 if( p_vout->p_sys == NULL )
172 /* key and mouse event handling */
173 p_vout->p_sys->i_vout_event = var_CreateGetInteger( p_vout, "vout-event" );
175 /* Open display, using the "display" config variable or the DISPLAY
176 * environment variable */
177 psz_display = config_GetPsz( p_vout, MODULE_STRING "-display" );
179 p_vout->p_sys->p_display = XOpenDisplay( psz_display );
181 if( p_vout->p_sys->p_display == NULL ) /* error */
183 msg_Err( p_vout, "cannot open display %s",
184 XDisplayName( psz_display ) );
185 free( p_vout->p_sys );
191 /* Replace error handler so we can intercept some non-fatal errors */
192 XSetErrorHandler( X11ErrorHandler );
194 /* Get a screen ID matching the XOpenDisplay return value */
195 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
197 #if defined(MODULE_NAME_IS_xvmc)
198 psz_chroma = config_GetPsz( p_vout, "xvideo-chroma" );
201 if( strlen( psz_chroma ) >= 4 )
203 /* Do not use direct assignment because we are not sure of the
205 memcpy(&i_chroma, psz_chroma, 4);
214 msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
215 i_chroma, (char*)&i_chroma );
219 i_chroma = p_vout->render.i_chroma;
222 /* Check that we have access to an XVideo port providing this chroma */
223 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout, VLC2X11_FOURCC(i_chroma),
225 if( p_vout->p_sys->i_xvport < 0 )
227 /* If a specific chroma format was requested, then we don't try to
228 * be cleverer than the user. He knew pretty well what he wanted. */
231 XCloseDisplay( p_vout->p_sys->p_display );
232 free( p_vout->p_sys );
236 /* It failed, but it's not completely lost ! We try to open an
237 * XVideo port for an YUY2 picture. We'll need to do an YUV
238 * conversion, but at least it has got scaling. */
239 p_vout->p_sys->i_xvport =
240 XVideoGetPort( p_vout, X11_FOURCC('Y','U','Y','2'),
242 if( p_vout->p_sys->i_xvport < 0 )
244 /* It failed, but it's not completely lost ! We try to open an
245 * XVideo port for a simple 16bpp RGB picture. We'll need to do
246 * an YUV conversion, but at least it has got scaling. */
247 p_vout->p_sys->i_xvport =
248 XVideoGetPort( p_vout, X11_FOURCC('R','V','1','6'),
250 if( p_vout->p_sys->i_xvport < 0 )
252 XCloseDisplay( p_vout->p_sys->p_display );
253 free( p_vout->p_sys );
258 p_vout->output.i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, X112VLC_FOURCC(p_vout->output.i_chroma) );
259 #elif defined(MODULE_NAME_IS_glx)
261 int i_opcode, i_evt, i_err = 0;
262 int i_maj, i_min = 0;
264 /* Check for GLX extension */
265 if( !XQueryExtension( p_vout->p_sys->p_display, "GLX",
266 &i_opcode, &i_evt, &i_err ) )
268 msg_Err( p_this, "GLX extension not supported" );
269 XCloseDisplay( p_vout->p_sys->p_display );
270 free( p_vout->p_sys );
273 if( !glXQueryExtension( p_vout->p_sys->p_display, &i_err, &i_evt ) )
275 msg_Err( p_this, "glXQueryExtension failed" );
276 XCloseDisplay( p_vout->p_sys->p_display );
277 free( p_vout->p_sys );
281 /* Check GLX version */
282 if (!glXQueryVersion( p_vout->p_sys->p_display, &i_maj, &i_min ) )
284 msg_Err( p_this, "glXQueryVersion failed" );
285 XCloseDisplay( p_vout->p_sys->p_display );
286 free( p_vout->p_sys );
289 if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) )
291 p_vout->p_sys->b_glx13 = false;
292 msg_Dbg( p_this, "using GLX 1.2 API" );
296 p_vout->p_sys->b_glx13 = true;
297 msg_Dbg( p_this, "using GLX 1.3 API" );
302 /* Create blank cursor (for mouse cursor autohiding) */
303 p_vout->p_sys->i_time_mouse_last_moved = mdate();
304 p_vout->p_sys->i_mouse_hide_timeout =
305 var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
306 p_vout->p_sys->b_mouse_pointer_visible = 1;
307 CreateCursor( p_vout );
309 /* Set main window's size */
310 p_vout->p_sys->window.i_x = 0;
311 p_vout->p_sys->window.i_y = 0;
312 p_vout->p_sys->window.i_width = p_vout->i_window_width;
313 p_vout->p_sys->window.i_height = p_vout->i_window_height;
314 var_Create( p_vout, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
315 /* Spawn base window - this window will include the video output window,
316 * but also command buttons, subtitles and other indicators */
317 if( CreateWindow( p_vout, &p_vout->p_sys->window ) )
319 msg_Err( p_vout, "cannot create X11 window" );
320 DestroyCursor( p_vout );
321 XCloseDisplay( p_vout->p_sys->p_display );
322 free( p_vout->p_sys );
326 /* Open and initialize device. */
327 if( InitDisplay( p_vout ) )
329 msg_Err( p_vout, "cannot initialize X11 display" );
330 DestroyCursor( p_vout );
331 DestroyWindow( p_vout, &p_vout->p_sys->window );
332 XCloseDisplay( p_vout->p_sys->p_display );
333 free( p_vout->p_sys );
337 /* Disable screen saver */
338 DisableXScreenSaver( p_vout );
341 p_vout->p_sys->i_time_button_last_pressed = 0;
343 #ifdef MODULE_NAME_IS_xvmc
344 p_vout->p_sys->p_last_subtitle_save = NULL;
345 psz_value = config_GetPsz( p_vout, "xvmc-deinterlace-mode" );
347 /* Look what method was requested */
348 //var_Create( p_vout, "xvmc-deinterlace-mode", VLC_VAR_STRING );
349 //var_Change( p_vout, "xvmc-deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL );
352 if( (strcmp(psz_value, "bob") == 0) ||
353 (strcmp(psz_value, "blend") == 0) )
354 p_vout->p_sys->xvmc_deinterlace_method = 2;
355 else if (strcmp(psz_value, "discard") == 0)
356 p_vout->p_sys->xvmc_deinterlace_method = 1;
358 p_vout->p_sys->xvmc_deinterlace_method = 0;
362 p_vout->p_sys->xvmc_deinterlace_method = 0;
364 /* Look what method was requested */
365 //var_Create( p_vout, "xvmc-crop-style", VLC_VAR_STRING );
366 //var_Change( p_vout, "xvmc-crop-style", VLC_VAR_INHERITVALUE, &val, NULL );
367 psz_value = config_GetPsz( p_vout, "xvmc-crop-style" );
371 if( strncmp( psz_value, "eq", 2 ) == 0 )
372 p_vout->p_sys->xvmc_crop_style = 1;
373 else if( strncmp( psz_value, "4-16", 4 ) == 0)
374 p_vout->p_sys->xvmc_crop_style = 2;
375 else if( strncmp( psz_value, "16-4", 4 ) == 0)
376 p_vout->p_sys->xvmc_crop_style = 3;
378 p_vout->p_sys->xvmc_crop_style = 0;
382 p_vout->p_sys->xvmc_crop_style = 0;
384 msg_Dbg(p_vout, "Deinterlace = %d", p_vout->p_sys->xvmc_deinterlace_method);
385 msg_Dbg(p_vout, "Crop = %d", p_vout->p_sys->xvmc_crop_style);
387 if( checkXvMCCap( p_vout ) == VLC_EGENERIC )
389 msg_Err( p_vout, "no XVMC capability found" );
390 Deactivate( p_this );
393 subpicture_t sub_pic;
394 sub_pic.p_sys = NULL;
395 p_vout->p_sys->last_date = 0;
399 p_vout->p_sys->i_hw_scale = 1;
403 p_vout->p_sys->i_backlight_on_counter = i_backlight_on_interval;
404 p_vout->p_sys->p_octx = osso_initialize( "vlc", VERSION, 0, NULL );
405 if ( p_vout->p_sys->p_octx == NULL ) {
406 msg_Err( p_vout, "Could not get osso context" );
408 msg_Dbg( p_vout, "Initialized osso context" );
412 /* Variable to indicate if the window should be on top of others */
413 /* Trigger a callback right now */
414 var_TriggerCallback( p_vout, "video-on-top" );
419 /*****************************************************************************
420 * Deactivate: destroy X11 video thread output method
421 *****************************************************************************
422 * Terminate an output method created by Open
423 *****************************************************************************/
424 void Deactivate ( vlc_object_t *p_this )
426 vout_thread_t *p_vout = (vout_thread_t *)p_this;
428 /* Restore cursor if it was blanked */
429 if( !p_vout->p_sys->b_mouse_pointer_visible )
431 ToggleCursor( p_vout );
434 #if defined(MODULE_NAME_IS_xvmc)
435 if( p_vout->p_sys->xvmc_cap )
437 xvmc_context_writer_lock( &p_vout->p_sys->xvmc_lock );
438 xxmc_dispose_context( p_vout );
439 if( p_vout->p_sys->old_subpic )
441 xxmc_xvmc_free_subpicture( p_vout, p_vout->p_sys->old_subpic );
442 p_vout->p_sys->old_subpic = NULL;
444 if( p_vout->p_sys->new_subpic )
446 xxmc_xvmc_free_subpicture( p_vout, p_vout->p_sys->new_subpic );
447 p_vout->p_sys->new_subpic = NULL;
449 free( p_vout->p_sys->xvmc_cap );
450 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
455 DisablePixelDoubling(p_vout);
458 DestroyCursor( p_vout );
459 EnableXScreenSaver( p_vout );
460 DestroyWindow( p_vout, &p_vout->p_sys->window );
461 XCloseDisplay( p_vout->p_sys->p_display );
463 /* Destroy structure */
464 #ifdef MODULE_NAME_IS_xvmc
465 free_context_lock( &p_vout->p_sys->xvmc_lock );
469 if ( p_vout->p_sys->p_octx != NULL ) {
470 msg_Dbg( p_vout, "Deinitializing osso context" );
471 osso_deinitialize( p_vout->p_sys->p_octx );
475 free( p_vout->p_sys );
478 #ifdef MODULE_NAME_IS_xvmc
480 #define XINE_IMGFMT_YV12 (('2'<<24)|('1'<<16)|('V'<<8)|'Y')
484 static int xvmc_check_yv12( Display *display, XvPortID port )
486 XvImageFormatValues *formatValues;
490 formatValues = XvListImageFormats( display, port, &formats );
492 for( i = 0; i < formats; i++ )
494 if( ( formatValues[i].id == XINE_IMGFMT_YV12 ) &&
495 ( !( strncmp( formatValues[i].guid, "YV12", 4 ) ) ) )
497 XFree (formatValues);
502 XFree (formatValues);
508 static void xvmc_sync_surface( vout_thread_t *p_vout, XvMCSurface * srf )
510 XvMCSyncSurface( p_vout->p_sys->p_display, srf );
515 static void xvmc_update_XV_DOUBLE_BUFFER( vout_thread_t *p_vout )
518 int xv_double_buffer;
520 xv_double_buffer = 1;
522 XLockDisplay( p_vout->p_sys->p_display );
523 atom = XInternAtom( p_vout->p_sys->p_display, "XV_DOUBLE_BUFFER", False );
525 XvSetPortAttribute (p_vout->p_sys->p_display, p_vout->p_sys->i_xvport, atom, xv_double_buffer);
527 XvMCSetAttribute( p_vout->p_sys->p_display, &p_vout->p_sys->context, atom, xv_double_buffer );
528 XUnlockDisplay( p_vout->p_sys->p_display );
530 //xprintf(this->xine, XINE_VERBOSITY_DEBUG,
531 // "video_out_xxmc: double buffering mode = %d\n", xv_double_buffer);
535 static void RenderVideo( vout_thread_t *p_vout, picture_t *p_pic )
537 vlc_xxmc_t *xxmc = NULL;
539 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
541 xxmc = &p_pic->p_sys->xxmc_data;
542 if( (!xxmc->decoded ||
543 !xxmc_xvmc_surface_valid( p_vout, p_pic->p_sys->xvmc_surf )) )
545 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
550 vlc_mutex_lock( &p_vout->lastsubtitle_lock );
551 if (p_vout->p_sys->p_last_subtitle != NULL)
553 if( p_vout->p_sys->p_last_subtitle_save != p_vout->p_sys->p_last_subtitle )
555 p_vout->p_sys->new_subpic =
556 xxmc_xvmc_alloc_subpicture( p_vout, &p_vout->p_sys->context,
557 p_vout->p_sys->xvmc_width,
558 p_vout->p_sys->xvmc_height,
559 p_vout->p_sys->xvmc_cap[p_vout->p_sys->xvmc_cur_cap].subPicType.id );
561 if (p_vout->p_sys->new_subpic)
563 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
564 XvMCClearSubpicture( p_vout->p_sys->p_display,
565 p_vout->p_sys->new_subpic,
568 p_vout->p_sys->xvmc_width,
569 p_vout->p_sys->xvmc_height,
571 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
572 clear_xx44_palette( &p_vout->p_sys->palette );
574 if( sub_pic.p_sys == NULL )
576 sub_pic.p_sys = malloc( sizeof( picture_sys_t ) );
577 if( sub_pic.p_sys != NULL )
579 sub_pic.p_sys->p_vout = p_vout;
580 sub_pic.p_sys->xvmc_surf = NULL;
581 sub_pic.p_sys->p_image = p_vout->p_sys->subImage;
584 sub_pic.p_sys->p_image = p_vout->p_sys->subImage;
585 sub_pic.p->p_pixels = sub_pic.p_sys->p_image->data;
586 sub_pic.p->i_pitch = p_vout->output.i_width;
588 memset( p_vout->p_sys->subImage->data, 0,
589 (p_vout->p_sys->subImage->width * p_vout->p_sys->subImage->height) );
591 if (p_vout->p_last_subtitle != NULL)
593 blend_xx44( p_vout->p_sys->subImage->data,
594 p_vout->p_last_subtitle,
595 p_vout->p_sys->subImage->width,
596 p_vout->p_sys->subImage->height,
597 p_vout->p_sys->subImage->width,
598 &p_vout->p_sys->palette,
599 (p_vout->p_sys->subImage->id == FOURCC_IA44) );
602 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
603 XvMCCompositeSubpicture( p_vout->p_sys->p_display,
604 p_vout->p_sys->new_subpic,
605 p_vout->p_sys->subImage,
608 p_vout->output.i_width, /* overlay->width, */
609 p_vout->output.i_height, /* overlay->height */
612 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
613 if (p_vout->p_sys->old_subpic)
615 xxmc_xvmc_free_subpicture( p_vout,
616 p_vout->p_sys->old_subpic);
617 p_vout->p_sys->old_subpic = NULL;
619 if (p_vout->p_sys->new_subpic)
621 p_vout->p_sys->old_subpic = p_vout->p_sys->new_subpic;
622 p_vout->p_sys->new_subpic = NULL;
623 xx44_to_xvmc_palette( &p_vout->p_sys->palette,
624 p_vout->p_sys->xvmc_palette,
626 p_vout->p_sys->old_subpic->num_palette_entries,
627 p_vout->p_sys->old_subpic->entry_bytes,
628 p_vout->p_sys->old_subpic->component_order );
629 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
630 XvMCSetSubpicturePalette( p_vout->p_sys->p_display,
631 p_vout->p_sys->old_subpic,
632 p_vout->p_sys->xvmc_palette );
633 XvMCFlushSubpicture( p_vout->p_sys->p_display,
634 p_vout->p_sys->old_subpic);
635 XvMCSyncSubpicture( p_vout->p_sys->p_display,
636 p_vout->p_sys->old_subpic );
637 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
640 XVMCLOCKDISPLAY( p_vout->p_sys->p_display);
641 if (p_vout->p_sys->xvmc_backend_subpic )
643 XvMCBlendSubpicture( p_vout->p_sys->p_display,
644 p_pic->p_sys->xvmc_surf,
645 p_vout->p_sys->old_subpic,
648 p_vout->p_sys->xvmc_width,
649 p_vout->p_sys->xvmc_height,
652 p_vout->p_sys->xvmc_width,
653 p_vout->p_sys->xvmc_height );
657 XvMCBlendSubpicture2( p_vout->p_sys->p_display,
658 p_pic->p_sys->xvmc_surf,
659 p_pic->p_sys->xvmc_surf,
660 p_vout->p_sys->old_subpic,
663 p_vout->p_sys->xvmc_width,
664 p_vout->p_sys->xvmc_height,
667 p_vout->p_sys->xvmc_width,
668 p_vout->p_sys->xvmc_height );
670 XVMCUNLOCKDISPLAY(p_vout->p_sys->p_display);
675 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
676 if( p_vout->p_sys->xvmc_backend_subpic )
678 XvMCBlendSubpicture( p_vout->p_sys->p_display,
679 p_pic->p_sys->xvmc_surf,
680 p_vout->p_sys->old_subpic,
682 p_vout->p_sys->xvmc_width,
683 p_vout->p_sys->xvmc_height,
685 p_vout->p_sys->xvmc_width,
686 p_vout->p_sys->xvmc_height );
690 XvMCBlendSubpicture2( p_vout->p_sys->p_display,
691 p_pic->p_sys->xvmc_surf,
692 p_pic->p_sys->xvmc_surf,
693 p_vout->p_sys->old_subpic,
695 p_vout->p_sys->xvmc_width,
696 p_vout->p_sys->xvmc_height,
698 p_vout->p_sys->xvmc_width,
699 p_vout->p_sys->xvmc_height );
701 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
704 p_vout->p_sys->p_last_subtitle_save = p_vout->p_last_subtitle;
706 vlc_mutex_unlock( &p_vout->lastsubtitle_lock );
708 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
713 /*****************************************************************************
714 * EnablePixelDoubling: Enables pixel doubling
715 *****************************************************************************
716 * Checks if the double size image fits in current window, and enables pixel
717 * doubling accordingly. The i_hw_scale is the integer scaling factor.
718 *****************************************************************************/
719 static void EnablePixelDoubling( vout_thread_t *p_vout )
721 int i_hor_scale = ( p_vout->p_sys->window.i_width ) / p_vout->render.i_width;
722 int i_vert_scale = ( p_vout->p_sys->window.i_height ) / p_vout->render.i_height;
723 if ( ( i_hor_scale > 1 ) && ( i_vert_scale > 1 ) ) {
724 p_vout->p_sys->i_hw_scale = 2;
725 msg_Dbg( p_vout, "Enabling pixel doubling, scaling factor %d", p_vout->p_sys->i_hw_scale );
726 XSPSetPixelDoubling( p_vout->p_sys->p_display, 0, 1 );
730 /*****************************************************************************
731 * DisablePixelDoubling: Disables pixel doubling
732 *****************************************************************************
733 * The scaling factor i_hw_scale is reset to the no-scaling value 1.
734 *****************************************************************************/
735 static void DisablePixelDoubling( vout_thread_t *p_vout )
737 if ( p_vout->p_sys->i_hw_scale > 1 ) {
738 msg_Dbg( p_vout, "Disabling pixel doubling" );
739 XSPSetPixelDoubling( p_vout->p_sys->p_display, 0, 0 );
740 p_vout->p_sys->i_hw_scale = 1;
746 #if !defined(MODULE_NAME_IS_glx)
747 /*****************************************************************************
748 * InitVideo: initialize X11 video thread output method
749 *****************************************************************************
750 * This function create the XImages needed by the output thread. It is called
751 * at the beginning of the thread, but also each time the window is resized.
752 *****************************************************************************/
753 static int InitVideo( vout_thread_t *p_vout )
755 unsigned int i_index = 0;
758 I_OUTPUTPICTURES = 0;
760 #if defined(MODULE_NAME_IS_xvmc)
761 /* Initialize the output structure; we already found an XVideo port,
762 * and the corresponding chroma we will be using. Since we can
763 * arbitrary scale, stick to the coordinates and aspect. */
764 p_vout->output.i_width = p_vout->render.i_width;
765 p_vout->output.i_height = p_vout->render.i_height;
766 p_vout->output.i_aspect = p_vout->render.i_aspect;
768 p_vout->fmt_out = p_vout->fmt_in;
769 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
771 #if XvVersion < 2 || ( XvVersion == 2 && XvRevision < 2 )
772 switch( p_vout->output.i_chroma )
774 case VLC_CODEC_RGB16:
775 #if defined( WORDS_BIGENDIAN )
776 p_vout->output.i_rmask = 0xf800;
777 p_vout->output.i_gmask = 0x07e0;
778 p_vout->output.i_bmask = 0x001f;
780 p_vout->output.i_rmask = 0x001f;
781 p_vout->output.i_gmask = 0x07e0;
782 p_vout->output.i_bmask = 0xf800;
785 case VLC_CODEC_RGB15:
786 #if defined( WORDS_BIGENDIAN )
787 p_vout->output.i_rmask = 0x7c00;
788 p_vout->output.i_gmask = 0x03e0;
789 p_vout->output.i_bmask = 0x001f;
791 p_vout->output.i_rmask = 0x001f;
792 p_vout->output.i_gmask = 0x03e0;
793 p_vout->output.i_bmask = 0x7c00;
800 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
801 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
805 /* Find an empty picture slot */
806 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
808 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
810 p_pic = p_vout->p_picture + i_index;
815 /* Allocate the picture */
816 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
821 p_pic->i_status = DESTROYED_PICTURE;
822 p_pic->i_type = DIRECT_PICTURE;
824 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
829 if( p_vout->output.i_chroma == VLC_CODEC_YV12 )
831 /* U and V inverted compared to I420
832 * Fixme: this should be handled by the vout core */
833 p_vout->output.i_chroma = VLC_CODEC_I420;
834 p_vout->fmt_out.i_chroma = VLC_CODEC_I420;
840 /*****************************************************************************
841 * DisplayVideo: displays previously rendered output
842 *****************************************************************************
843 * This function sends the currently rendered image to X11 server.
844 * (The Xv extension takes care of "double-buffering".)
845 *****************************************************************************/
846 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
848 unsigned int i_width, i_height, i_x, i_y;
850 vout_PlacePicture( p_vout, p_vout->p_sys->window.i_width,
851 p_vout->p_sys->window.i_height,
852 &i_x, &i_y, &i_width, &i_height );
854 #ifdef MODULE_NAME_IS_xvmc
855 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
857 vlc_xxmc_t *xxmc = &p_pic->p_sys->xxmc_data;
858 if( !xxmc->decoded ||
859 !xxmc_xvmc_surface_valid( p_vout, p_pic->p_sys->xvmc_surf ) )
861 msg_Dbg( p_vout, "DisplayVideo decoded=%d\tsurfacevalid=%d",
863 xxmc_xvmc_surface_valid( p_vout, p_pic->p_sys->xvmc_surf ) );
864 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
868 int src_width = p_vout->output.i_width;
869 int src_height = p_vout->output.i_height;
872 if( p_vout->p_sys->xvmc_crop_style == 1 )
879 else if( p_vout->p_sys->xvmc_crop_style == 2 )
886 else if( p_vout->p_sys->xvmc_crop_style == 3 )
900 if( p_vout->p_sys->xvmc_deinterlace_method > 0 )
901 { /* BOB DEINTERLACE */
902 if( (p_pic->p_sys->nb_display == 0) ||
903 (p_vout->p_sys->xvmc_deinterlace_method == 1) )
905 first_field = (p_pic->b_top_field_first) ?
906 XVMC_BOTTOM_FIELD : XVMC_TOP_FIELD;
910 first_field = (p_pic->b_top_field_first) ?
911 XVMC_TOP_FIELD : XVMC_BOTTOM_FIELD;
916 first_field = XVMC_FRAME_PICTURE;
919 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
920 XvMCFlushSurface( p_vout->p_sys->p_display, p_pic->p_sys->xvmc_surf );
921 /* XvMCSyncSurface(p_vout->p_sys->p_display, p_picture->p_sys->xvmc_surf); */
922 XvMCPutSurface( p_vout->p_sys->p_display,
923 p_pic->p_sys->xvmc_surf,
924 p_vout->p_sys->window.video_window,
935 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
936 if( p_vout->p_sys->xvmc_deinterlace_method == 2 )
937 { /* BOB DEINTERLACE */
938 if( p_pic->p_sys->nb_display == 0 )/* && ((t2-t1) < 15000)) */
940 mtime_t last_date = p_pic->date;
942 vlc_mutex_lock( &p_vout->picture_lock );
943 if( !p_vout->p_sys->last_date )
945 p_pic->date += 20000;
949 p_pic->date = ((3 * p_pic->date -
950 p_vout->p_sys->last_date) / 2 );
952 p_vout->p_sys->last_date = last_date;
954 p_pic->p_sys->nb_display = 1;
955 vlc_mutex_unlock( &p_vout->picture_lock );
959 p_pic->p_sys->nb_display = 0;
963 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
966 #ifdef HAVE_SYS_SHM_H
967 if( p_vout->p_sys->i_shm_opcode )
969 /* Display rendered image using shared memory extension */
970 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
971 p_vout->p_sys->window.video_window,
972 p_vout->p_sys->window.gc, p_pic->p_sys->p_image,
973 p_vout->fmt_out.i_x_offset,
974 p_vout->fmt_out.i_y_offset,
975 p_vout->fmt_out.i_visible_width,
976 p_vout->fmt_out.i_visible_height,
977 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
978 False /* Don't put True here or you'll waste your CPU */ );
981 #endif /* HAVE_SYS_SHM_H */
983 /* Use standard XPutImage -- this is gonna be slow ! */
984 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
985 p_vout->p_sys->window.video_window,
986 p_vout->p_sys->window.gc, p_pic->p_sys->p_image,
987 p_vout->fmt_out.i_x_offset,
988 p_vout->fmt_out.i_y_offset,
989 p_vout->fmt_out.i_visible_width,
990 p_vout->fmt_out.i_visible_height,
991 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
994 /* Make sure the command is sent now - do NOT use XFlush !*/
995 XSync( p_vout->p_sys->p_display, False );
999 /*****************************************************************************
1000 * ManageVideo: handle X11 events
1001 *****************************************************************************
1002 * This function should be called regularly by video output thread. It manages
1003 * X11 events and allows window resizing. It returns a non null value on
1005 *****************************************************************************/
1006 static int ManageVideo( vout_thread_t *p_vout )
1008 XEvent xevent; /* X11 event */
1011 #ifdef MODULE_NAME_IS_xvmc
1012 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
1015 /* Handle events from the owner window */
1016 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1017 p_vout->p_sys->window.owner_window->handle.xid,
1018 StructureNotifyMask, &xevent ) == True )
1020 /* ConfigureNotify event: prepare */
1021 if( xevent.type == ConfigureNotify )
1022 /* Update dimensions */
1023 XResizeWindow( p_vout->p_sys->p_display,
1024 p_vout->p_sys->window.base_window,
1025 xevent.xconfigure.width,
1026 xevent.xconfigure.height );
1029 /* Handle X11 events: ConfigureNotify events are parsed to know if the
1030 * output window's size changed, MapNotify and UnmapNotify to know if the
1031 * window is mapped (and if the display is useful), and ClientMessages
1032 * to intercept window destruction requests */
1034 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1035 p_vout->p_sys->window.base_window,
1036 StructureNotifyMask |
1037 ButtonPressMask | ButtonReleaseMask |
1038 PointerMotionMask | Button1MotionMask , &xevent )
1041 /* ConfigureNotify event: prepare */
1042 if( xevent.type == ConfigureNotify )
1044 if( (unsigned int)xevent.xconfigure.width
1045 != p_vout->p_sys->window.i_width
1046 || (unsigned int)xevent.xconfigure.height
1047 != p_vout->p_sys->window.i_height )
1049 /* Update dimensions */
1050 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1051 p_vout->p_sys->window.i_width = xevent.xconfigure.width;
1052 p_vout->p_sys->window.i_height = xevent.xconfigure.height;
1056 else if( xevent.type == ButtonPress )
1058 switch( ((XButtonEvent *)&xevent)->button )
1061 var_Get( p_vout, "mouse-button-down", &val );
1063 var_Set( p_vout, "mouse-button-down", val );
1065 var_SetBool( p_vout->p_libvlc, "intf-popupmenu", false );
1067 /* detect double-clicks */
1068 if( ( ((XButtonEvent *)&xevent)->time -
1069 p_vout->p_sys->i_time_button_last_pressed ) < 300 )
1071 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1074 p_vout->p_sys->i_time_button_last_pressed =
1075 ((XButtonEvent *)&xevent)->time;
1078 var_Get( p_vout, "mouse-button-down", &val );
1080 var_Set( p_vout, "mouse-button-down", val );
1084 var_Get( p_vout, "mouse-button-down", &val );
1086 var_Set( p_vout, "mouse-button-down", val );
1087 var_SetBool( p_vout->p_libvlc, "intf-popupmenu", true );
1091 var_Get( p_vout, "mouse-button-down", &val );
1093 var_Set( p_vout, "mouse-button-down", val );
1097 var_Get( p_vout, "mouse-button-down", &val );
1099 var_Set( p_vout, "mouse-button-down", val );
1104 else if( xevent.type == ButtonRelease )
1106 switch( ((XButtonEvent *)&xevent)->button )
1110 var_Get( p_vout, "mouse-button-down", &val );
1112 var_Set( p_vout, "mouse-button-down", val );
1114 var_SetBool( p_vout, "mouse-clicked", true );
1120 var_Get( p_vout, "mouse-button-down", &val );
1122 var_Set( p_vout, "mouse-button-down", val );
1124 var_Get( p_vout->p_libvlc, "intf-show", &val );
1125 val.b_bool = !val.b_bool;
1126 var_Set( p_vout->p_libvlc, "intf-show", val );
1132 var_Get( p_vout, "mouse-button-down", &val );
1134 var_Set( p_vout, "mouse-button-down", val );
1140 var_Get( p_vout, "mouse-button-down", &val );
1142 var_Set( p_vout, "mouse-button-down", val );
1146 var_Get( p_vout, "mouse-button-down", &val );
1148 var_Set( p_vout, "mouse-button-down", val );
1154 else if( xevent.type == MotionNotify )
1156 unsigned int i_width, i_height, i_x, i_y;
1158 /* somewhat different use for vout_PlacePicture:
1159 * here the values are needed to give to mouse coordinates
1160 * in the original picture space */
1161 vout_PlacePicture( p_vout, p_vout->p_sys->window.i_width,
1162 p_vout->p_sys->window.i_height,
1163 &i_x, &i_y, &i_width, &i_height );
1165 /* Compute the x coordinate and check if the value is
1166 in [0,p_vout->fmt_in.i_visible_width] */
1167 val.i_int = ( xevent.xmotion.x - i_x ) *
1168 p_vout->fmt_in.i_visible_width / i_width +
1169 p_vout->fmt_in.i_x_offset;
1171 if( (int)(xevent.xmotion.x - i_x) < 0 )
1173 else if( (unsigned int)val.i_int > p_vout->fmt_in.i_visible_width )
1174 val.i_int = p_vout->fmt_in.i_visible_width;
1176 var_Set( p_vout, "mouse-x", val );
1178 /* compute the y coordinate and check if the value is
1179 in [0,p_vout->fmt_in.i_visible_height] */
1180 val.i_int = ( xevent.xmotion.y - i_y ) *
1181 p_vout->fmt_in.i_visible_height / i_height +
1182 p_vout->fmt_in.i_y_offset;
1184 if( (int)(xevent.xmotion.y - i_y) < 0 )
1186 else if( (unsigned int)val.i_int > p_vout->fmt_in.i_visible_height )
1187 val.i_int = p_vout->fmt_in.i_visible_height;
1189 var_Set( p_vout, "mouse-y", val );
1191 var_SetBool( p_vout, "mouse-moved", true );
1193 p_vout->p_sys->i_time_mouse_last_moved = mdate();
1194 if( ! p_vout->p_sys->b_mouse_pointer_visible )
1196 ToggleCursor( p_vout );
1199 else if( xevent.type == ReparentNotify /* XXX: why do we get this? */
1200 || xevent.type == MapNotify
1201 || xevent.type == UnmapNotify )
1203 /* Ignore these events */
1205 else /* Other events */
1207 msg_Warn( p_vout, "unhandled event %d received", xevent.type );
1211 /* Handle events for video output sub-window */
1212 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1213 p_vout->p_sys->window.video_window,
1214 ExposureMask, &xevent ) == True );
1216 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
1217 * are handled - according to the man pages, the format is always 32
1219 while( XCheckTypedEvent( p_vout->p_sys->p_display,
1220 ClientMessage, &xevent ) )
1222 if( (xevent.xclient.message_type == p_vout->p_sys->window.wm_protocols)
1223 && ((Atom)xevent.xclient.data.l[0]
1224 == p_vout->p_sys->window.wm_delete_window ) )
1226 /* the user wants to close the window */
1227 playlist_t * p_playlist = pl_Hold( p_vout );
1228 if( p_playlist != NULL )
1230 playlist_Stop( p_playlist );
1231 pl_Release( p_vout );
1239 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
1241 /* Update the object variable and trigger callback */
1242 var_SetBool( p_vout, "fullscreen", !p_vout->b_fullscreen );
1244 ToggleFullScreen( p_vout );
1245 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
1248 /* autoscale toggle */
1249 if( p_vout->i_changes & VOUT_SCALE_CHANGE )
1251 p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
1253 p_vout->b_autoscale = var_GetBool( p_vout, "autoscale" );
1254 p_vout->i_zoom = ZOOM_FP_FACTOR;
1256 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1259 /* scaling factor */
1260 if( p_vout->i_changes & VOUT_ZOOM_CHANGE )
1262 p_vout->i_changes &= ~VOUT_ZOOM_CHANGE;
1264 p_vout->b_autoscale = false;
1266 (int)( ZOOM_FP_FACTOR * var_GetFloat( p_vout, "scale" ) );
1268 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1271 if( p_vout->i_changes & VOUT_CROP_CHANGE ||
1272 p_vout->i_changes & VOUT_ASPECT_CHANGE )
1274 p_vout->i_changes &= ~VOUT_CROP_CHANGE;
1275 p_vout->i_changes &= ~VOUT_ASPECT_CHANGE;
1277 p_vout->fmt_out.i_x_offset = p_vout->fmt_in.i_x_offset;
1278 p_vout->fmt_out.i_y_offset = p_vout->fmt_in.i_y_offset;
1279 p_vout->fmt_out.i_visible_width = p_vout->fmt_in.i_visible_width;
1280 p_vout->fmt_out.i_visible_height = p_vout->fmt_in.i_visible_height;
1281 p_vout->fmt_out.i_aspect = p_vout->fmt_in.i_aspect;
1282 p_vout->fmt_out.i_sar_num = p_vout->fmt_in.i_sar_num;
1283 p_vout->fmt_out.i_sar_den = p_vout->fmt_in.i_sar_den;
1284 p_vout->output.i_aspect = p_vout->fmt_in.i_aspect;
1286 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1292 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
1293 * the size flag inside the fullscreen routine)
1295 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
1297 unsigned int i_width, i_height, i_x, i_y;
1299 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
1301 vout_PlacePicture( p_vout, p_vout->p_sys->window.i_width,
1302 p_vout->p_sys->window.i_height,
1303 &i_x, &i_y, &i_width, &i_height );
1305 XMoveResizeWindow( p_vout->p_sys->p_display,
1306 p_vout->p_sys->window.video_window,
1307 i_x, i_y, i_width, i_height );
1310 /* cursor hiding depending on --vout-event option
1312 * value = 1 (Fullsupport) (default value)
1313 * or value = 2 (Fullscreen-Only) and condition met
1315 bool b_vout_event = ( ( p_vout->p_sys->i_vout_event == 1 )
1316 || ( p_vout->p_sys->i_vout_event == 2 && p_vout->b_fullscreen )
1319 /* Autohide Cursour */
1320 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved >
1321 p_vout->p_sys->i_mouse_hide_timeout )
1323 /* Hide the mouse automatically */
1324 if( b_vout_event && p_vout->p_sys->b_mouse_pointer_visible )
1326 ToggleCursor( p_vout );
1330 #ifdef MODULE_NAME_IS_xvmc
1331 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1335 if ( p_vout->p_sys->p_octx != NULL ) {
1336 if ( p_vout->p_sys->i_backlight_on_counter == i_backlight_on_interval ) {
1337 if ( osso_display_blanking_pause( p_vout->p_sys->p_octx ) != OSSO_OK ) {
1338 msg_Err( p_vout, "Could not disable backlight blanking" );
1340 msg_Dbg( p_vout, "Backlight blanking disabled" );
1342 p_vout->p_sys->i_backlight_on_counter = 0;
1344 p_vout->p_sys->i_backlight_on_counter ++;
1351 #if !defined( MODULE_NAME_IS_glx )
1352 /*****************************************************************************
1353 * EndVideo: terminate X11 video thread output method
1354 *****************************************************************************
1355 * Destroy the X11 XImages created by Init. It is called at the end of
1356 * the thread, but also each time the window is resized.
1357 *****************************************************************************/
1358 static void EndVideo( vout_thread_t *p_vout )
1362 /* Free the direct buffers we allocated */
1363 for( i_index = I_OUTPUTPICTURES ; i_index ; )
1366 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
1371 /* following functions are local */
1373 /*****************************************************************************
1374 * CreateWindow: open and set-up X11 main window
1375 *****************************************************************************/
1376 static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1378 XSizeHints xsize_hints;
1379 XSetWindowAttributes xwindow_attributes;
1380 XGCValues xgcvalues;
1383 bool b_map_notify = false;
1385 /* Prepare window manager hints and properties */
1386 p_win->wm_protocols =
1387 XInternAtom( p_vout->p_sys->p_display, "WM_PROTOCOLS", True );
1388 p_win->wm_delete_window =
1389 XInternAtom( p_vout->p_sys->p_display, "WM_DELETE_WINDOW", True );
1391 /* Never have a 0-pixel-wide window */
1392 xsize_hints.min_width = 2;
1393 xsize_hints.min_height = 1;
1395 /* Prepare window attributes */
1396 xwindow_attributes.backing_store = Always; /* save the hidden part */
1397 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
1398 p_vout->p_sys->i_screen);
1399 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
1402 vout_window_cfg_t wnd_cfg;
1403 memset( &wnd_cfg, 0, sizeof(wnd_cfg) );
1404 wnd_cfg.type = VOUT_WINDOW_TYPE_XID;
1405 wnd_cfg.x = p_win->i_x;
1406 wnd_cfg.y = p_win->i_y;
1407 wnd_cfg.width = p_win->i_width;
1408 wnd_cfg.height = p_win->i_height;
1410 p_win->owner_window = vout_window_New( VLC_OBJECT(p_vout), NULL, &wnd_cfg );
1411 if( !p_win->owner_window )
1412 return VLC_EGENERIC;
1413 xsize_hints.base_width = xsize_hints.width = p_win->i_width;
1414 xsize_hints.base_height = xsize_hints.height = p_win->i_height;
1415 xsize_hints.flags = PSize | PMinSize;
1417 if( p_win->i_x >=0 || p_win->i_y >= 0 )
1419 xsize_hints.x = p_win->i_x;
1420 xsize_hints.y = p_win->i_y;
1421 xsize_hints.flags |= PPosition;
1424 /* Select events we are interested in. */
1425 XSelectInput( p_vout->p_sys->p_display,
1426 p_win->owner_window->handle.xid, StructureNotifyMask );
1428 /* Get the parent window's geometry information */
1429 XGetGeometry( p_vout->p_sys->p_display,
1430 p_win->owner_window->handle.xid,
1431 &(Window){ 0 }, &(int){ 0 }, &(int){ 0 },
1434 &(unsigned){ 0 }, &(unsigned){ 0 } );
1436 /* From man XSelectInput: only one client at a time can select a
1437 * ButtonPress event, so we need to open a new window anyway. */
1438 p_win->base_window =
1439 XCreateWindow( p_vout->p_sys->p_display,
1440 p_win->owner_window->handle.xid,
1442 p_win->i_width, p_win->i_height,
1444 0, CopyFromParent, 0,
1445 CWBackingStore | CWBackPixel | CWEventMask,
1446 &xwindow_attributes );
1449 if( (p_win->wm_protocols == None) /* use WM_DELETE_WINDOW */
1450 || (p_win->wm_delete_window == None)
1451 || !XSetWMProtocols( p_vout->p_sys->p_display, p_win->base_window,
1452 &p_win->wm_delete_window, 1 ) )
1454 /* WM_DELETE_WINDOW is not supported by window manager */
1455 msg_Warn( p_vout, "missing or bad window manager" );
1458 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1459 * event when using functions like XCopyArea */
1460 xgcvalues.graphics_exposures = False;
1461 p_win->gc = XCreateGC( p_vout->p_sys->p_display,
1463 GCGraphicsExposures, &xgcvalues );
1465 /* Wait till the window is mapped */
1466 XMapWindow( p_vout->p_sys->p_display, p_win->base_window );
1469 XWindowEvent( p_vout->p_sys->p_display, p_win->base_window,
1470 SubstructureNotifyMask | StructureNotifyMask, &xevent);
1471 if( (xevent.type == MapNotify)
1472 && (xevent.xmap.window == p_win->base_window) )
1474 b_map_notify = true;
1476 else if( (xevent.type == ConfigureNotify)
1477 && (xevent.xconfigure.window == p_win->base_window) )
1479 p_win->i_width = xevent.xconfigure.width;
1480 p_win->i_height = xevent.xconfigure.height;
1482 } while( !b_map_notify );
1484 /* key and mouse events handling depending on --vout-event option
1486 * value = 1 (Fullsupport) (default value)
1487 * or value = 2 (Fullscreen-Only) and condition met
1489 bool b_vout_event = ( ( p_vout->p_sys->i_vout_event == 1 )
1490 || ( p_vout->p_sys->i_vout_event == 2 && p_vout->b_fullscreen )
1493 XSelectInput( p_vout->p_sys->p_display, p_win->base_window,
1494 StructureNotifyMask |
1495 ButtonPressMask | ButtonReleaseMask |
1496 PointerMotionMask );
1498 /* Create video output sub-window. */
1499 p_win->video_window = XCreateSimpleWindow(
1500 p_vout->p_sys->p_display,
1501 p_win->base_window, 0, 0,
1502 p_win->i_width, p_win->i_height,
1504 BlackPixel( p_vout->p_sys->p_display,
1505 p_vout->p_sys->i_screen ),
1506 WhitePixel( p_vout->p_sys->p_display,
1507 p_vout->p_sys->i_screen ) );
1509 XSetWindowBackground( p_vout->p_sys->p_display, p_win->video_window,
1510 BlackPixel( p_vout->p_sys->p_display,
1511 p_vout->p_sys->i_screen ) );
1513 XMapWindow( p_vout->p_sys->p_display, p_win->video_window );
1514 XSelectInput( p_vout->p_sys->p_display, p_win->video_window,
1517 /* make sure the video window will be centered in the next ManageVideo() */
1518 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1520 /* If the cursor was formerly blank than blank it again */
1521 if( !p_vout->p_sys->b_mouse_pointer_visible )
1523 ToggleCursor( p_vout );
1524 ToggleCursor( p_vout );
1527 /* Do NOT use XFlush here ! */
1528 XSync( p_vout->p_sys->p_display, False );
1533 /*****************************************************************************
1534 * DestroyWindow: destroy the window
1535 *****************************************************************************
1537 *****************************************************************************/
1538 static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1540 /* Do NOT use XFlush here ! */
1541 XSync( p_vout->p_sys->p_display, False );
1543 if( p_win->video_window != None )
1544 XDestroyWindow( p_vout->p_sys->p_display, p_win->video_window );
1546 XFreeGC( p_vout->p_sys->p_display, p_win->gc );
1548 XUnmapWindow( p_vout->p_sys->p_display, p_win->base_window );
1549 XDestroyWindow( p_vout->p_sys->p_display, p_win->base_window );
1551 /* make sure base window is destroyed before proceeding further */
1552 bool b_destroy_notify = false;
1556 XWindowEvent( p_vout->p_sys->p_display, p_win->base_window,
1557 SubstructureNotifyMask | StructureNotifyMask, &xevent);
1558 if( (xevent.type == DestroyNotify)
1559 && (xevent.xmap.window == p_win->base_window) )
1561 b_destroy_notify = true;
1563 } while( !b_destroy_notify );
1565 vout_window_Delete( p_win->owner_window );
1568 /*****************************************************************************
1569 * NewPicture: allocate a picture
1570 *****************************************************************************
1571 * Returns 0 on success, -1 otherwise
1572 *****************************************************************************/
1573 #if !defined(MODULE_NAME_IS_glx)
1574 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1578 /* We know the chroma, allocate a buffer which will be used
1579 * directly by the decoder */
1580 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1582 if( p_pic->p_sys == NULL )
1587 #ifdef MODULE_NAME_IS_xvmc
1588 p_pic->p_sys->p_vout = p_vout;
1589 p_pic->p_sys->xvmc_surf = NULL;
1590 p_pic->p_sys->xxmc_data.decoded = 0;
1591 p_pic->p_sys->xxmc_data.proc_xxmc_update_frame = xxmc_do_update_frame;
1592 // p_pic->p_accel_data = &p_pic->p_sys->xxmc_data;
1593 p_pic->p_sys->nb_display = 0;
1596 /* Fill in picture_t fields */
1597 if( picture_Setup( p_pic, p_vout->output.i_chroma,
1598 p_vout->output.i_width, p_vout->output.i_height,
1599 p_vout->output.i_aspect ) )
1602 #ifdef HAVE_SYS_SHM_H
1603 if( p_vout->p_sys->i_shm_opcode )
1605 /* Create image using XShm extension */
1606 p_pic->p_sys->p_image =
1607 CreateShmImage( p_vout, p_vout->p_sys->p_display,
1608 p_vout->p_sys->i_xvport,
1609 VLC2X11_FOURCC(p_vout->output.i_chroma),
1610 &p_pic->p_sys->shminfo,
1611 p_vout->output.i_width, p_vout->output.i_height );
1614 if( !p_vout->p_sys->i_shm_opcode || !p_pic->p_sys->p_image )
1615 #endif /* HAVE_SYS_SHM_H */
1617 /* Create image without XShm extension */
1618 p_pic->p_sys->p_image =
1619 CreateImage( p_vout, p_vout->p_sys->p_display,
1620 p_vout->p_sys->i_xvport,
1621 VLC2X11_FOURCC(p_vout->output.i_chroma),
1622 p_pic->format.i_bits_per_pixel,
1623 p_vout->output.i_width, p_vout->output.i_height );
1625 #ifdef HAVE_SYS_SHM_H
1626 if( p_pic->p_sys->p_image && p_vout->p_sys->i_shm_opcode )
1628 msg_Warn( p_vout, "couldn't create SHM image, disabling SHM" );
1629 p_vout->p_sys->i_shm_opcode = 0;
1631 #endif /* HAVE_SYS_SHM_H */
1634 if( p_pic->p_sys->p_image == NULL )
1636 free( p_pic->p_sys );
1640 switch( p_vout->output.i_chroma )
1642 case VLC_CODEC_I420:
1643 case VLC_CODEC_YV12:
1644 case VLC_CODEC_Y211:
1645 case VLC_CODEC_YUYV:
1646 case VLC_CODEC_UYVY:
1647 case VLC_CODEC_RGB15:
1648 case VLC_CODEC_RGB16:
1649 case VLC_CODEC_RGB24: /* Fixme: pixel pitch == 4 ? */
1650 case VLC_CODEC_RGB32:
1652 for( i_plane = 0; i_plane < p_pic->p_sys->p_image->num_planes;
1655 p_pic->p[i_plane].p_pixels = (uint8_t*)p_pic->p_sys->p_image->data
1656 + p_pic->p_sys->p_image->offsets[i_plane];
1657 p_pic->p[i_plane].i_pitch =
1658 p_pic->p_sys->p_image->pitches[i_plane];
1660 if( p_vout->output.i_chroma == VLC_CODEC_YV12 )
1662 /* U and V inverted compared to I420
1663 * Fixme: this should be handled by the vout core */
1664 p_pic->U_PIXELS = (uint8_t*)p_pic->p_sys->p_image->data
1665 + p_pic->p_sys->p_image->offsets[2];
1666 p_pic->V_PIXELS = (uint8_t*)p_pic->p_sys->p_image->data
1667 + p_pic->p_sys->p_image->offsets[1];
1673 /* Unknown chroma, tell the guy to get lost */
1674 IMAGE_FREE( p_pic->p_sys->p_image );
1675 free( p_pic->p_sys );
1676 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1677 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1678 p_pic->i_planes = 0;
1684 /*****************************************************************************
1685 * FreePicture: destroy a picture allocated with NewPicture
1686 *****************************************************************************
1687 * Destroy XImage AND associated data. If using Shm, detach shared memory
1688 * segment from server and process, then free it. The XDestroyImage manpage
1689 * says that both the image structure _and_ the data pointed to by the
1690 * image structure are freed, so no need to free p_image->data.
1691 *****************************************************************************/
1692 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1694 /* The order of operations is correct */
1695 #ifdef HAVE_SYS_SHM_H
1696 if( p_vout->p_sys->i_shm_opcode )
1698 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1699 IMAGE_FREE( p_pic->p_sys->p_image );
1701 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1702 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1704 msg_Err( p_vout, "cannot detach shared memory (%m)" );
1710 IMAGE_FREE( p_pic->p_sys->p_image );
1713 #ifdef MODULE_NAME_IS_xvmc
1714 if( p_pic->p_sys->xvmc_surf != NULL )
1716 xxmc_xvmc_free_surface(p_vout , p_pic->p_sys->xvmc_surf);
1717 p_pic->p_sys->xvmc_surf = NULL;
1721 /* Do NOT use XFlush here ! */
1722 XSync( p_vout->p_sys->p_display, False );
1724 free( p_pic->p_sys );
1726 #endif /* !MODULE_NAME_IS_glx */
1728 /*****************************************************************************
1729 * ToggleFullScreen: Enable or disable full screen mode
1730 *****************************************************************************
1731 * This function will switch between fullscreen and window mode.
1732 *****************************************************************************/
1733 static void ToggleFullScreen ( vout_thread_t *p_vout )
1735 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1736 vout_window_SetFullScreen( p_vout->p_sys->window.owner_window,
1737 p_vout->b_fullscreen );
1740 if( p_vout->b_fullscreen )
1741 EnablePixelDoubling( p_vout );
1743 DisablePixelDoubling( p_vout );
1747 /*****************************************************************************
1748 * EnableXScreenSaver: enable screen saver
1749 *****************************************************************************
1750 * This function enables the screen saver on a display after it has been
1751 * disabled by XDisableScreenSaver.
1752 * FIXME: what happens if multiple vlc sessions are running at the same
1754 *****************************************************************************/
1755 static void EnableXScreenSaver( vout_thread_t *p_vout )
1757 #ifdef DPMSINFO_IN_DPMS_H
1761 if( p_vout->p_sys->i_ss_timeout )
1763 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1764 p_vout->p_sys->i_ss_interval,
1765 p_vout->p_sys->i_ss_blanking,
1766 p_vout->p_sys->i_ss_exposure );
1769 /* Restore DPMS settings */
1770 #ifdef DPMSINFO_IN_DPMS_H
1771 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1773 if( p_vout->p_sys->b_ss_dpms )
1775 DPMSEnable( p_vout->p_sys->p_display );
1781 /*****************************************************************************
1782 * DisableXScreenSaver: disable screen saver
1783 *****************************************************************************
1784 * See XEnableXScreenSaver
1785 *****************************************************************************/
1786 static void DisableXScreenSaver( vout_thread_t *p_vout )
1788 #ifdef DPMSINFO_IN_DPMS_H
1792 /* Save screen saver information */
1793 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1794 &p_vout->p_sys->i_ss_interval,
1795 &p_vout->p_sys->i_ss_blanking,
1796 &p_vout->p_sys->i_ss_exposure );
1798 /* Disable screen saver */
1799 if( p_vout->p_sys->i_ss_timeout )
1801 XSetScreenSaver( p_vout->p_sys->p_display, 0,
1802 p_vout->p_sys->i_ss_interval,
1803 p_vout->p_sys->i_ss_blanking,
1804 p_vout->p_sys->i_ss_exposure );
1808 #ifdef DPMSINFO_IN_DPMS_H
1809 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1812 /* Save DPMS current state */
1813 DPMSInfo( p_vout->p_sys->p_display, &unused,
1814 &p_vout->p_sys->b_ss_dpms );
1815 DPMSDisable( p_vout->p_sys->p_display );
1820 /*****************************************************************************
1821 * CreateCursor: create a blank mouse pointer
1822 *****************************************************************************/
1823 static void CreateCursor( vout_thread_t *p_vout )
1825 XColor cursor_color;
1827 p_vout->p_sys->cursor_pixmap =
1828 XCreatePixmap( p_vout->p_sys->p_display,
1829 DefaultRootWindow( p_vout->p_sys->p_display ),
1832 XParseColor( p_vout->p_sys->p_display,
1833 XCreateColormap( p_vout->p_sys->p_display,
1835 p_vout->p_sys->p_display ),
1837 p_vout->p_sys->p_display,
1838 p_vout->p_sys->i_screen ),
1840 "black", &cursor_color );
1842 p_vout->p_sys->blank_cursor =
1843 XCreatePixmapCursor( p_vout->p_sys->p_display,
1844 p_vout->p_sys->cursor_pixmap,
1845 p_vout->p_sys->cursor_pixmap,
1846 &cursor_color, &cursor_color, 1, 1 );
1849 /*****************************************************************************
1850 * DestroyCursor: destroy the blank mouse pointer
1851 *****************************************************************************/
1852 static void DestroyCursor( vout_thread_t *p_vout )
1854 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
1857 /*****************************************************************************
1858 * ToggleCursor: hide or show the mouse pointer
1859 *****************************************************************************
1860 * This function hides the X pointer if it is visible by setting the pointer
1861 * sprite to a blank one. To show it again, we disable the sprite.
1862 *****************************************************************************/
1863 static void ToggleCursor( vout_thread_t *p_vout )
1865 if( p_vout->p_sys->b_mouse_pointer_visible )
1867 XDefineCursor( p_vout->p_sys->p_display,
1868 p_vout->p_sys->window.base_window,
1869 p_vout->p_sys->blank_cursor );
1870 p_vout->p_sys->b_mouse_pointer_visible = 0;
1874 XUndefineCursor( p_vout->p_sys->p_display,
1875 p_vout->p_sys->window.base_window );
1876 p_vout->p_sys->b_mouse_pointer_visible = 1;
1880 #if defined(MODULE_NAME_IS_xvmc)
1881 /*****************************************************************************
1882 * XVideoGetPort: get YUV12 port
1883 *****************************************************************************/
1884 static int XVideoGetPort( vout_thread_t *p_vout,
1885 vlc_fourcc_t i_chroma, picture_heap_t *p_heap )
1887 XvAdaptorInfo *p_adaptor;
1889 unsigned int i_adaptor, i_num_adaptors;
1890 int i_requested_adaptor;
1891 int i_selected_port;
1893 switch( XvQueryExtension( p_vout->p_sys->p_display, &i, &i, &i, &i, &i ) )
1898 case XvBadExtension:
1899 msg_Warn( p_vout, "XvBadExtension" );
1903 msg_Warn( p_vout, "XvBadAlloc" );
1907 msg_Warn( p_vout, "XvQueryExtension failed" );
1911 switch( XvQueryAdaptors( p_vout->p_sys->p_display,
1912 DefaultRootWindow( p_vout->p_sys->p_display ),
1913 &i_num_adaptors, &p_adaptor ) )
1918 case XvBadExtension:
1919 msg_Warn( p_vout, "XvBadExtension for XvQueryAdaptors" );
1923 msg_Warn( p_vout, "XvBadAlloc for XvQueryAdaptors" );
1927 msg_Warn( p_vout, "XvQueryAdaptors failed" );
1931 i_selected_port = -1;
1932 i_requested_adaptor = config_GetInt( p_vout, "xvmc-adaptor" );
1933 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
1935 XvImageFormatValues *p_formats;
1936 int i_format, i_num_formats;
1939 /* If we requested an adaptor and it's not this one, we aren't
1941 if( i_requested_adaptor != -1 && ((int)i_adaptor != i_requested_adaptor) )
1946 /* If the adaptor doesn't have the required properties, skip it */
1947 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
1948 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
1953 /* Check that adaptor supports our requested format... */
1954 p_formats = XvListImageFormats( p_vout->p_sys->p_display,
1955 p_adaptor[i_adaptor].base_id,
1959 i_format < i_num_formats && ( i_selected_port == -1 );
1962 XvAttribute *p_attr;
1963 int i_attr, i_num_attributes;
1964 Atom autopaint = None, colorkey = None;
1966 /* If this is not the format we want, or at least a
1967 * similar one, forget it */
1968 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
1973 /* Look for the first available port supporting this format */
1974 for( i_port = p_adaptor[i_adaptor].base_id;
1975 ( i_port < (int)(p_adaptor[i_adaptor].base_id
1976 + p_adaptor[i_adaptor].num_ports) )
1977 && ( i_selected_port == -1 );
1980 if( XvGrabPort( p_vout->p_sys->p_display, i_port, CurrentTime )
1983 i_selected_port = i_port;
1984 p_heap->i_chroma = p_formats[ i_format ].id;
1985 #if XvVersion > 2 || ( XvVersion == 2 && XvRevision >= 2 )
1986 p_heap->i_rmask = p_formats[ i_format ].red_mask;
1987 p_heap->i_gmask = p_formats[ i_format ].green_mask;
1988 p_heap->i_bmask = p_formats[ i_format ].blue_mask;
1993 /* If no free port was found, forget it */
1994 if( i_selected_port == -1 )
1999 /* If we found a port, print information about it */
2000 msg_Dbg( p_vout, "adaptor %i, port %i, format 0x%x (%4.4s) %s",
2001 i_adaptor, i_selected_port, p_formats[ i_format ].id,
2002 (char *)&p_formats[ i_format ].id,
2003 ( p_formats[ i_format ].format == XvPacked ) ?
2004 "packed" : "planar" );
2006 /* Use XV_AUTOPAINT_COLORKEY if supported, otherwise we will
2007 * manually paint the colour key */
2008 p_attr = XvQueryPortAttributes( p_vout->p_sys->p_display,
2010 &i_num_attributes );
2012 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
2014 if( !strcmp( p_attr[i_attr].name, "XV_AUTOPAINT_COLORKEY" ) )
2016 autopaint = XInternAtom( p_vout->p_sys->p_display,
2017 "XV_AUTOPAINT_COLORKEY", False );
2018 XvSetPortAttribute( p_vout->p_sys->p_display,
2019 i_selected_port, autopaint, 1 );
2021 if( !strcmp( p_attr[i_attr].name, "XV_COLORKEY" ) )
2023 /* Find out the default colour key */
2024 colorkey = XInternAtom( p_vout->p_sys->p_display,
2025 "XV_COLORKEY", False );
2026 XvGetPortAttribute( p_vout->p_sys->p_display,
2027 i_selected_port, colorkey,
2028 &p_vout->p_sys->i_colourkey );
2031 p_vout->p_sys->b_paint_colourkey =
2032 autopaint == None && colorkey != None;
2034 if( p_attr != NULL )
2040 if( p_formats != NULL )
2047 if( i_num_adaptors > 0 )
2049 XvFreeAdaptorInfo( p_adaptor );
2052 if( i_selected_port == -1 )
2054 int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
2055 if( i_requested_adaptor == -1 )
2057 msg_Warn( p_vout, "no free XVideo port found for format "
2058 "0x%.8x (%4.4s)", i_chroma_tmp, (char*)&i_chroma_tmp );
2062 msg_Warn( p_vout, "XVideo adaptor %i does not have a free "
2063 "XVideo port for format 0x%.8x (%4.4s)",
2064 i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
2068 return i_selected_port;
2072 /*****************************************************************************
2073 * InitDisplay: open and initialize X11 device
2074 *****************************************************************************
2075 * Create a window according to video output given size, and set other
2076 * properties according to the display properties.
2077 *****************************************************************************/
2078 static int InitDisplay( vout_thread_t *p_vout )
2080 #ifdef HAVE_SYS_SHM_H
2081 p_vout->p_sys->i_shm_opcode = 0;
2083 if( config_GetInt( p_vout, MODULE_STRING "-shm" ) > 0 )
2085 int major, evt, err;
2087 if( XQueryExtension( p_vout->p_sys->p_display, "MIT-SHM", &major,
2089 && XShmQueryExtension( p_vout->p_sys->p_display ) )
2090 p_vout->p_sys->i_shm_opcode = major;
2092 if( p_vout->p_sys->i_shm_opcode )
2097 XShmQueryVersion( p_vout->p_sys->p_display, &major, &minor,
2099 msg_Dbg( p_vout, "XShm video extension v%d.%d "
2100 "(with%s pixmaps, opcode: %d)",
2101 major, minor, pixmaps ? "" : "out",
2102 p_vout->p_sys->i_shm_opcode );
2105 msg_Warn( p_vout, "XShm video extension not available" );
2108 msg_Dbg( p_vout, "XShm video extension disabled" );
2114 #ifndef MODULE_NAME_IS_glx
2116 #ifdef HAVE_SYS_SHM_H
2117 /*****************************************************************************
2118 * CreateShmImage: create an XImage or XvImage using shared memory extension
2119 *****************************************************************************
2120 * Prepare an XImage or XvImage for display function.
2121 * The order of the operations respects the recommandations of the mit-shm
2122 * document by J.Corbet and K.Packard. Most of the parameters were copied from
2123 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
2124 *****************************************************************************/
2125 IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
2126 Display* p_display, EXTRA_ARGS_SHM,
2127 int i_width, int i_height )
2129 IMAGE_TYPE *p_image;
2132 /* Create XImage / XvImage */
2133 #if defined(MODULE_NAME_IS_xvmc)
2134 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
2135 i_width, i_height, p_shm );
2137 if( p_image == NULL )
2139 msg_Err( p_vout, "image creation failed" );
2143 /* For too big image, the buffer returned is sometimes too small, prevent
2144 * VLC to segfault because of it
2145 * FIXME is it normal ? Is there a way to detect it
2146 * before (XvQueryBestSize did not) ? */
2147 if( p_image->width < i_width || p_image->height < i_height )
2149 msg_Err( p_vout, "cannot allocate shared image data with the right size "
2150 "(%dx%d instead of %dx%d)",
2151 p_image->width, p_image->height,
2152 i_width, i_height );
2153 IMAGE_FREE( p_image );
2157 /* Allocate shared memory segment. */
2158 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0600 );
2159 if( p_shm->shmid < 0 )
2161 msg_Err( p_vout, "cannot allocate shared image data (%m)" );
2162 IMAGE_FREE( p_image );
2166 /* Attach shared memory segment to process (read/write) */
2167 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
2168 if(! p_shm->shmaddr )
2170 msg_Err( p_vout, "cannot attach shared memory (%m)" );
2171 IMAGE_FREE( p_image );
2172 shmctl( p_shm->shmid, IPC_RMID, 0 );
2176 /* Read-only data. We won't be using XShmGetImage */
2177 p_shm->readOnly = True;
2179 /* Attach shared memory segment to X server */
2180 XSynchronize( p_display, True );
2181 i_shm_major = p_vout->p_sys->i_shm_opcode;
2182 result = XShmAttach( p_display, p_shm );
2183 if( result == False || !i_shm_major )
2185 msg_Err( p_vout, "cannot attach shared memory to X server" );
2186 IMAGE_FREE( p_image );
2187 shmctl( p_shm->shmid, IPC_RMID, 0 );
2188 shmdt( p_shm->shmaddr );
2191 XSynchronize( p_display, False );
2193 /* Send image to X server. This instruction is required, since having
2194 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2195 * and remember NOT to use XFlush ! */
2196 XSync( p_display, False );
2199 /* Mark the shm segment to be removed when there are no more
2200 * attachements, so it is automatic on process exit or after shmdt */
2201 shmctl( p_shm->shmid, IPC_RMID, 0 );
2209 /*****************************************************************************
2210 * X11ErrorHandler: replace error handler so we can intercept some of them
2211 *****************************************************************************/
2212 static int X11ErrorHandler( Display * display, XErrorEvent * event )
2216 XGetErrorText( display, event->error_code, txt, sizeof( txt ) );
2218 "[????????] x11 video output error: X11 request %u.%u failed "
2219 "with error code %u:\n %s\n",
2220 event->request_code, event->minor_code, event->error_code, txt );
2222 switch( event->request_code )
2224 case X_SetInputFocus:
2225 /* Ignore errors on XSetInputFocus()
2226 * (they happen when a window is not yet mapped) */
2230 #ifdef HAVE_SYS_SHM_H
2231 if( event->request_code == i_shm_major ) /* MIT-SHM */
2234 "[????????] x11 video output notice:"
2235 " buggy X11 server claims shared memory\n"
2236 "[????????] x11 video output notice:"
2237 " support though it does not work (OpenSSH?)\n" );
2238 return i_shm_major = 0;
2243 XSetErrorHandler(NULL);
2244 return (XSetErrorHandler(X11ErrorHandler))( display, event );
2246 /* Work-around Maemo Xvideo bug */
2251 /*****************************************************************************
2252 * Control: control facility for the vout
2253 *****************************************************************************/
2254 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
2256 unsigned int i_width, i_height;
2261 i_width = va_arg( args, unsigned int );
2262 i_height = va_arg( args, unsigned int );
2263 if( !i_width ) i_width = p_vout->i_window_width;
2264 if( !i_height ) i_height = p_vout->i_window_height;
2266 return vout_window_SetSize( p_vout->p_sys->window.owner_window,
2269 case VOUT_SET_STAY_ON_TOP:
2270 return vout_window_SetOnTop( p_vout->p_sys->window.owner_window,
2271 va_arg( args, int ) );
2274 return VLC_EGENERIC;