1 /*****************************************************************************
2 * xvmc.c : XVMC plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
7 * Authors: Shane Harper <shanegh@optusnet.com.au>
8 * Vincent Seguin <seguin@via.ecp.fr>
9 * Samuel Hocevar <sam@zoy.org>
10 * David Kennedy <dkennedy@tinytoad.com>
11 * Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
37 #include <vlc_interface.h>
41 #ifdef HAVE_MACHINE_PARAM_H
43 # include <machine/param.h>
44 # include <sys/types.h> /* typedef ushort */
49 # include <netinet/in.h> /* BSD: struct in_addr */
53 # include <sys/shm.h> /* shmget(), shmctl() */
58 #include <X11/Xutil.h>
59 #include <X11/keysym.h>
61 # include <X11/extensions/XShm.h>
63 #ifdef DPMSINFO_IN_DPMS_H
64 # include <X11/extensions/dpms.h>
67 #include <X11/extensions/Xv.h>
68 #include <X11/extensions/Xvlib.h>
69 #include <X11/extensions/vldXvMC.h>
71 #include "../../codec/xvmc/accel_xvmc.h"
73 #include "../../codec/spudec/spudec.h"
76 /* picture structure */
78 #define BOTTOM_FIELD 2
79 #define FRAME_PICTURE 3
81 /* picture coding type */
87 /*****************************************************************************
89 *****************************************************************************/
90 extern int E_(Activate) ( vlc_object_t * );
91 extern void E_(Deactivate) ( vlc_object_t * );
93 /*****************************************************************************
95 *****************************************************************************/
96 #define ADAPTOR_TEXT N_("XVMC adaptor number")
97 #define ADAPTOR_LONGTEXT N_( \
98 "If you graphics card provides several adaptors, this option allows you " \
99 "to choose which one will be used (you shouldn't have to change this).")
101 #define ALT_FS_TEXT N_("Alternate fullscreen method")
102 #define ALT_FS_LONGTEXT N_( \
103 "There are two ways to make a fullscreen window, unfortunately each one " \
104 "has its drawbacks.\n" \
105 "1) Let the window manager handle your fullscreen window (default), but " \
106 "things like taskbars will likely show on top of the video.\n" \
107 "2) Completely bypass the window manager, but then nothing will be able " \
108 "to show on top of the video.")
110 #define DISPLAY_TEXT N_("X11 display name")
111 #define DISPLAY_LONGTEXT N_( \
112 "Specify the X11 hardware display you want to use. By default VLC will " \
113 "use the value of the DISPLAY environment variable.")
115 #define CHROMA_TEXT N_("XVimage chroma format")
116 #define CHROMA_LONGTEXT N_( \
117 "Force the XVideo renderer to use a specific chroma format instead of " \
118 "trying to improve performances by using the most efficient one.")
120 #define SHM_TEXT N_("Use shared memory")
121 #define SHM_LONGTEXT N_( \
122 "Use shared memory to communicate between VLC and the X server.")
124 #define SCREEN_TEXT N_("Screen to be used for fullscreen mode.")
125 #define SCREEN_LONGTEXT N_( \
126 "Choose the screen you want to use in fullscreen mode. For instance " \
127 "set it to 0 for first screen, 1 for the second.")
129 #define MODE_TEXT N_("Deinterlace mode")
130 #define MODE_LONGTEXT N_("You can choose the default deinterlace mode")
132 #define CROP_TEXT N_("Crop")
133 #define CROP_LONGTEXT N_("You can choose the crop style to apply.")
136 set_shortname( "XVMC" );
137 add_string( "xvmc-display", NULL, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT, VLC_TRUE );
138 add_integer( "xvmc-adaptor", -1, NULL, ADAPTOR_TEXT, ADAPTOR_LONGTEXT, VLC_TRUE );
139 add_bool( "xvmc-altfullscreen", 0, NULL, ALT_FS_TEXT, ALT_FS_LONGTEXT, VLC_TRUE );
140 add_string( "xvmc-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, VLC_TRUE );
141 #ifdef HAVE_SYS_SHM_H
142 add_bool( "xvmc-shm", 1, NULL, SHM_TEXT, SHM_LONGTEXT, VLC_TRUE );
145 add_integer ( "xvmc-xineramascreen", 0, NULL, SCREEN_TEXT, SCREEN_LONGTEXT, VLC_TRUE );
147 add_string( "xvmc-deinterlace-mode", "bob", NULL, MODE_TEXT, MODE_LONGTEXT, VLC_FALSE );
148 add_string( "xvmc-crop-style", "eq", NULL, CROP_TEXT, CROP_LONGTEXT, VLC_FALSE );
150 set_description( _("XVMC extension video output") );
151 set_capability( "video output", 160 );
152 set_callbacks( E_(Activate), E_(Deactivate) );
155 /* following functions are local */
157 static unsigned accel_priority[] = {
161 #define NUM_ACCEL_PRIORITY (sizeof(accel_priority)/sizeof(accel_priority[0]))
164 * Additional thread safety, since the plugin may decide to destroy a context
165 * while it's surfaces are still active in the video-out loop.
166 * When / If XvMC libs are reasonably thread-safe, the locks can be made
167 * more efficient by allowing multiple threads in that do not destroy
168 * the context or surfaces that may be active in other threads.
171 static void init_context_lock( context_lock_t *c )
173 pthread_cond_init(&c->cond,NULL);
174 pthread_mutex_init(&c->mutex,NULL);
178 void free_context_lock( context_lock_t *c )
180 pthread_mutex_destroy(&c->mutex);
181 pthread_cond_destroy(&c->cond);
184 void xvmc_context_reader_lock( context_lock_t *c )
186 pthread_mutex_lock(&c->mutex);
188 pthread_mutex_unlock(&c->mutex);
191 void xvmc_context_reader_unlock( context_lock_t *c )
193 pthread_mutex_lock(&c->mutex);
194 if (c->num_readers > 0) {
195 if (--(c->num_readers) == 0) {
196 pthread_cond_broadcast(&c->cond);
199 pthread_mutex_unlock(&c->mutex);
202 void xvmc_context_writer_lock( context_lock_t *c )
204 pthread_mutex_lock(&c->mutex);
205 while(c->num_readers) {
206 pthread_cond_wait( &c->cond, &c->mutex );
210 void xvmc_context_writer_unlock( context_lock_t *c )
212 pthread_mutex_unlock( &c->mutex );
215 void clear_xx44_palette( xx44_palette_t *p )
218 uint32_t *cluts = p->cluts;
219 int *ids = p->lookup_cache;
224 i = 2*OVL_PALETTE_SIZE;
230 static void init_xx44_palette( xx44_palette_t *p, unsigned num_entries )
232 p->size = (num_entries > XX44_PALETTE_SIZE) ?
233 XX44_PALETTE_SIZE : num_entries;
236 static void dispose_xx44_palette(xx44_palette_t *p)
241 static void colorToPalette( const uint32_t *icolor, unsigned char *palette_p,
242 unsigned num_xvmc_components, char *xvmc_components )
244 const clut_t *color = (const clut_t *) icolor;
247 for (i=0; i<num_xvmc_components; ++i)
249 switch(xvmc_components[i])
251 case 'V': *palette_p = color->cr; break;
252 case 'U': *palette_p = color->cb; break;
254 default: *palette_p = color->y; break;
261 void xx44_to_xvmc_palette( const xx44_palette_t *p,unsigned char *xvmc_palette,
262 unsigned first_xx44_entry, unsigned num_xx44_entries,
263 unsigned num_xvmc_components, char *xvmc_components )
266 const uint32_t *cluts = p->cluts + first_xx44_entry;
268 for( i=0; i<num_xx44_entries; ++i )
270 if( (cluts - p->cluts) < p->size )
272 colorToPalette( cluts++, xvmc_palette,
273 num_xvmc_components, xvmc_components );
274 xvmc_palette += num_xvmc_components;
279 static int xx44_paletteIndex( xx44_palette_t *p, int color, uint32_t clut )
282 uint32_t *cluts = p->cluts;
285 if( (tmp = p->lookup_cache[color]) >= 0 )
287 if (cluts[tmp] == clut)
290 for (i=0; i<p->max_used; ++i)
292 if (*cluts++ == clut) {
293 p->lookup_cache[color] = i;
294 return p->lookup_cache[color];
298 if( p->max_used == (p->size -1) )
300 //printf("video_out: Warning! Out of xx44 palette colors!\n");
303 p->cluts[p->max_used] = clut;
304 p->lookup_cache[color] = p->max_used++;
305 return p->lookup_cache[color];
308 static void memblend_xx44( uint8_t *mem, uint8_t val,
309 size_t size, uint8_t mask )
311 uint8_t masked_val = val & mask;
318 if( (*mem & mask) <= masked_val )
324 void blend_xx44( uint8_t *dst_img, subpicture_t *sub_img,
325 int dst_width, int dst_height, int dst_pitch,
326 xx44_palette_t *palette, int ia44 )
334 uint8_t norm_pixel,clip_pixel;
340 uint16_t *p_source = NULL;
341 uint16_t i_colprecomp, i_destalpha;
346 src_width = sub_img->i_width;
347 src_height = sub_img->i_height;
348 x_off = sub_img->i_x;
349 y_off = sub_img->i_y;
350 alphamask = (ia44) ? 0x0F : 0xF0;
351 p_source = (uint16_t *)sub_img->p_sys->p_data;
352 i_colprecomp, i_destalpha;
354 dst_y = dst_img + dst_pitch*y_off + x_off;
356 if( (x_off + sub_img->i_width) <= dst_width )
357 clip_right = sub_img->i_width;
359 clip_right = dst_width - x_off;
361 if ((src_height + y_off) > dst_height)
362 src_height = dst_height - y_off;
364 for (y = 0; y < src_height; y++)
366 mask = !( (y < sub_img->p_sys->i_y_start) ||
367 (y >= sub_img->p_sys->i_y_end) );
370 for (x = 0; x < src_width;)
372 i_color = *p_source & 0x3;
373 i_len = *p_source++ >> 2;
375 if( (i_len > 0) && ((x+i_len) <= src_width) )
377 /* Get the RLE part, then draw the line */
378 uint32_t color = (sub_img->p_sys->pi_yuv[i_color][0] << 16) |
379 (sub_img->p_sys->pi_yuv[i_color][1] << 0) |
380 (sub_img->p_sys->pi_yuv[i_color][2] << 8);
382 norm_pixel = (uint8_t)(
383 (xx44_paletteIndex( palette,i_color, color ) << 4) |
384 (sub_img->p_sys->pi_alpha[i_color] & 0x0F) );
385 clip_pixel = (uint8_t)(
386 (xx44_paletteIndex( palette,i_color + OVL_PALETTE_SIZE,
387 sub_img->p_sys->pi_yuv[i_color][0] ) << 4) |
388 (sub_img->p_sys->pi_alpha[i_color] & 0x0F));
392 norm_pixel = ((norm_pixel & 0x0F) << 4) | ((norm_pixel & 0xF0) >> 4);
393 clip_pixel = ((clip_pixel & 0x0F) << 4) | ((clip_pixel & 0xF0) >> 4);
397 if( x < sub_img->p_sys->i_x_start )
399 if( (x + i_len) <= sub_img->p_sys->i_x_start )
401 memblend_xx44( dst, norm_pixel, i_len, alphamask );
406 memblend_xx44( dst, norm_pixel,
407 sub_img->p_sys->i_x_start - x,
409 dst += sub_img->p_sys->i_x_start - x;
410 i_len -= sub_img->p_sys->i_x_start - x;
411 if( i_len <= (sub_img->p_sys->i_x_end -
412 sub_img->p_sys->i_x_start) )
414 memblend_xx44( dst, clip_pixel,
420 memblend_xx44( dst, clip_pixel,
421 sub_img->p_sys->i_x_end -
422 sub_img->p_sys->i_x_start,
424 dst += (sub_img->p_sys->i_x_end -
425 sub_img->p_sys->i_x_start);
426 i_len -= (sub_img->p_sys->i_x_end -
427 sub_img->p_sys->i_x_start);
428 memblend_xx44( dst, norm_pixel,
434 else if( x < sub_img->p_sys->i_x_end )
436 if( i_len <= (sub_img->p_sys->i_x_end - x) )
438 memblend_xx44( dst, clip_pixel, i_len, alphamask);
443 memblend_xx44( dst, clip_pixel,
444 sub_img->p_sys->i_x_end - x,
446 dst += (sub_img->p_sys->i_x_end - x);
447 i_len -= (sub_img->p_sys->i_x_end - x);
448 memblend_xx44( dst, norm_pixel, i_len, alphamask);
454 memblend_xx44( dst, norm_pixel, i_len, alphamask );
460 memblend_xx44( dst, norm_pixel, i_len, alphamask );
474 int xxmc_xvmc_surface_valid( vout_thread_t *p_vout, XvMCSurface *surf )
476 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
477 unsigned int index = surf - handler->surfaces;
480 if (index >= XVMC_MAX_SURFACES)
482 pthread_mutex_lock(&handler->mutex);
483 ret = handler->surfValid[index];
484 pthread_mutex_unlock(&handler->mutex);
488 static void xxmc_xvmc_dump_subpictures( vout_thread_t *p_vout )
491 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
493 for( i=0; i < XVMC_MAX_SUBPICTURES; ++i )
495 msg_Dbg( p_vout, "handler in use %d, valid %d",
496 handler->subInUse[i],
497 handler->subValid[i]);
501 XvMCSubpicture *xxmc_xvmc_alloc_subpicture( vout_thread_t *p_vout,
502 XvMCContext *context, unsigned short width,
503 unsigned short height, int xvimage_id )
506 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
509 pthread_mutex_lock(&handler->mutex);
510 /* xxmc_xvmc_dump_subpictures(p_vout); */
511 for( i=0; i<XVMC_MAX_SUBPICTURES; ++i )
513 if( handler->subValid[i] && !handler->subInUse[i] )
515 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
516 if( XvMCGetSubpictureStatus( p_vout->p_sys->p_display,
517 handler->subpictures + i,
520 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
523 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
524 if( status & XVMC_DISPLAYING )
526 handler->subInUse[i] = 1;
527 /* xxmc_xvmc_dump_subpictures(p_vout); */
528 pthread_mutex_unlock(&handler->mutex);
529 return (handler->subpictures + i);
532 for (i=0; i<XVMC_MAX_SUBPICTURES; ++i)
534 if( !handler->subInUse[i] )
536 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
537 if( Success != XvMCCreateSubpicture( p_vout->p_sys->p_display,
539 handler->subpictures + i,
540 width, height, xvimage_id ) )
542 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
543 pthread_mutex_unlock( &handler->mutex );
546 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
547 msg_Dbg( p_vout, "video_out_xxmc: created subpicture %d\n", i );
548 handler->subInUse[i] = 1;
549 handler->subValid[i] = 1;
550 pthread_mutex_unlock( &handler->mutex );
551 return (handler->subpictures + i);
554 pthread_mutex_unlock( &handler->mutex );
558 void xxmc_xvmc_free_subpicture( vout_thread_t *p_vout, XvMCSubpicture *sub )
560 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
561 unsigned int index = sub - handler->subpictures;
563 if( index >= XVMC_MAX_SUBPICTURES )
566 pthread_mutex_lock( &handler->mutex );
567 handler->subInUse[index] = 0;
568 /* xxmc_xvmc_dump_subpictures(p_vout); */
569 pthread_mutex_unlock( &handler->mutex );
572 static void xxmc_xvmc_surface_handler_construct( vout_thread_t *p_vout )
575 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
577 pthread_mutex_init( &handler->mutex, NULL );
578 for( i=0; i<XVMC_MAX_SURFACES; ++i )
580 handler->surfInUse[i] = 0;
581 handler->surfValid[i] = 0;
583 for( i=0; i<XVMC_MAX_SUBPICTURES; ++i )
585 handler->subInUse[i] = 0;
586 handler->subValid[i] = 0;
590 static void xxmc_xvmc_dump_surfaces( vout_thread_t *p_vout )
593 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
595 for (i=0; i<XVMC_MAX_SURFACES; ++i)
597 msg_Dbg(p_vout, "surfaces in use %d, valid %d;",
598 handler->surfInUse[i],
599 handler->surfValid[i]);
603 void xxmc_xvmc_free_surface( vout_thread_t *p_vout, XvMCSurface *surf )
605 xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
606 unsigned int index = 0;
608 index = (surf - handler->surfaces);
610 if (index < XVMC_MAX_SURFACES)
612 pthread_mutex_lock(&handler->mutex);
613 msg_Dbg( p_vout,"free surface %d",index );
614 handler->surfInUse[index]--;
615 xxmc_xvmc_dump_surfaces(p_vout);
616 pthread_mutex_unlock(&handler->mutex);
620 int checkXvMCCap( vout_thread_t *p_vout )
626 XvMCSurfaceInfo *surfaceInfo =NULL;
627 XvMCSurfaceInfo *curInfo = NULL;
629 xvmc_capabilities_t *curCap = NULL;
630 XvImageFormatValues *formatValues = NULL;
632 i_xvport = p_vout->p_sys->i_xvport;
633 p_vout->p_sys->xvmc_cap = 0;
635 init_context_lock( &p_vout->p_sys->xvmc_lock );
636 xvmc_context_writer_lock( &p_vout->p_sys->xvmc_lock );
638 p_vout->p_sys->old_subpic = NULL;
639 p_vout->p_sys->new_subpic = NULL;
640 p_vout->p_sys->contextActive = 0;
641 p_vout->p_sys->subImage = NULL;
642 p_vout->p_sys->hwSubpictures = 0;
643 p_vout->p_sys->xvmc_palette = NULL;
645 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
647 if( !XvMCQueryExtension( p_vout->p_sys->p_display,
648 &p_vout->p_sys->xvmc_eventbase,
649 &p_vout->p_sys->xvmc_errbase ) )
651 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
652 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
655 msg_Dbg( p_vout,"XvMC extension found" );
657 surfaceInfo = XvMCListSurfaceTypes(p_vout->p_sys->p_display, i_xvport, &numSurf);
660 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
661 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
665 p_vout->p_sys->xvmc_cap =
666 (xvmc_capabilities_t *) malloc( numSurf *
667 sizeof(xvmc_capabilities_t) );
668 if( !p_vout->p_sys->xvmc_cap )
670 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
671 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
675 p_vout->p_sys->xvmc_num_cap = numSurf;
676 curInfo = surfaceInfo;
677 curCap = p_vout->p_sys->xvmc_cap;
679 msg_Dbg( p_vout,"found %d XvMC surface types", numSurf );
681 for( i=0; i< numSurf; ++i )
683 curCap->mpeg_flags = 0;
684 curCap->accel_flags = 0;
685 if( curInfo->chroma_format == XVMC_CHROMA_FORMAT_420 )
687 curCap->mpeg_flags |= ((curInfo->mc_type & XVMC_MPEG_1) ?
688 VLC_XVMC_MPEG_1 : 0);
689 curCap->mpeg_flags |= ((curInfo->mc_type & XVMC_MPEG_2) ?
690 VLC_XVMC_MPEG_2 : 0);
691 curCap->mpeg_flags |= ((curInfo->mc_type & XVMC_MPEG_4) ?
692 VLC_XVMC_MPEG_4 : 0);
693 curCap->accel_flags |= ((curInfo->mc_type & XVMC_VLD) ?
694 VLC_XVMC_ACCEL_VLD : 0);
695 curCap->accel_flags |= ((curInfo->mc_type & XVMC_IDCT) ?
696 VLC_XVMC_ACCEL_IDCT : 0);
697 curCap->accel_flags |= ((curInfo->mc_type & (XVMC_VLD | XVMC_IDCT)) ?
698 0 : VLC_XVMC_ACCEL_MOCOMP);
699 curCap->max_width = curInfo->max_width;
700 curCap->max_height = curInfo->max_height;
701 curCap->sub_max_width = curInfo->subpicture_max_width;
702 curCap->sub_max_height = curInfo->subpicture_max_height;
703 curCap->flags = curInfo->flags;
705 msg_Dbg (p_vout, "surface type %d: Max size: %d %d.",
706 i, curCap->max_width, curCap->max_height);
707 msg_Dbg (p_vout, "surface subtype %d: Max subpic size: %d %d.",
708 i, curCap->sub_max_width, curCap->sub_max_height);
710 curCap->type_id = curInfo->surface_type_id;
711 formatValues = XvMCListSubpictureTypes( p_vout->p_sys->p_display,
715 curCap->subPicType.id = 0;
718 msg_Dbg( p_vout, "surface type %d: found %d XvMC subpicture types",
720 for( j = 0; j<numSub; ++j )
722 if( formatValues[j].id == FOURCC_IA44 )
724 curCap->subPicType = formatValues[j];
726 "surface type %d: detected and using "
727 "IA44 subpicture type.", i );
731 else if( formatValues[j].id == FOURCC_AI44 )
733 curCap->subPicType = formatValues[j];
735 "surface type %d: detected AI44 "
736 "subpicture type.", i );
748 * Try to create a direct rendering context. This will fail if we are not
749 * on the displaying computer or an indirect context is not available.
751 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
752 curCap = p_vout->p_sys->xvmc_cap;
753 if( Success == XvMCCreateContext( p_vout->p_sys->p_display, i_xvport,
759 p_vout->p_sys->context_flags = XVMC_DIRECT;
761 else if( Success == XvMCCreateContext( p_vout->p_sys->p_display, i_xvport,
767 p_vout->p_sys->context_flags = 0;
771 if( p_vout->p_sys->xvmc_cap )
772 free( p_vout->p_sys->xvmc_cap );
773 p_vout->p_sys->xvmc_cap = NULL;
774 msg_Err( p_vout, "use of direct XvMC context on a remote display failed"
775 " falling back to XV." );
776 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
779 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
780 XvMCDestroyContext( p_vout->p_sys->p_display, &c );
781 xxmc_xvmc_surface_handler_construct(p_vout );
782 /* p_vout->p_sys->capabilities |= VO_CAP_XXMC; */
783 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
784 init_xx44_palette( &p_vout->p_sys->palette , 0 );
785 p_vout->p_sys->last_accel_request = 0xFFFFFFFF;
786 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
790 static int xxmc_setup_subpictures( vout_thread_t *p_vout,
791 unsigned int width, unsigned int height )
793 xvmc_capabilities_t *curCap = NULL;
794 XvMCSubpicture *sp = NULL;
796 if( p_vout->p_sys->contextActive )
798 curCap = p_vout->p_sys->xvmc_cap + p_vout->p_sys->xvmc_cur_cap;
800 if( (width > curCap->sub_max_width) ||
801 (height > curCap->sub_max_height) )
804 if( (p_vout->p_sys->xvmc_backend_subpic =
805 (curCap->flags & XVMC_BACKEND_SUBPICTURE)) )
806 msg_Dbg( p_vout, "using backend subpictures." );
808 if (!p_vout->p_sys->subImage)
810 XLockDisplay( p_vout->p_sys->p_display );
811 msg_Dbg(p_vout, "xxmc_setup_subpictures");
812 #ifdef HAVE_SYS_SHM_H
813 if( p_vout->p_sys->i_shm_opcode )
815 /* Create image using XShm extension */
816 p_vout->p_sys->subImage = CreateShmImage( p_vout,
817 p_vout->p_sys->p_display,
818 p_vout->p_sys->i_xvport,
819 curCap->subPicType.id,
820 /* VLC2X11_FOURCC( p_vout->output. i_chroma ), */
821 &p_vout->p_sys->subShmInfo,
822 p_vout->output.i_width,
823 p_vout->output.i_height );
825 #endif /* HAVE_SYS_SHM_H */
826 XUnlockDisplay( p_vout->p_sys->p_display );
827 if( !p_vout->p_sys->subImage )
829 msg_Dbg(p_vout, "failed allocating XvImage for supbictures" );
834 sp = xxmc_xvmc_alloc_subpicture( p_vout, &p_vout->p_sys->context,
836 curCap->subPicType.id );
840 init_xx44_palette( &p_vout->p_sys->palette, sp->num_palette_entries );
841 p_vout->p_sys->xvmc_palette = (char *) malloc( sp->num_palette_entries
843 xxmc_xvmc_free_subpicture( p_vout, sp);
844 if( !p_vout->p_sys->xvmc_palette )
846 p_vout->p_sys->hwSubpictures = 1;
851 static void xvmc_check_colorkey_properties( vout_thread_t *p_vout )
854 XvAttribute *xvmc_attributes = NULL;
858 * Determine if the context is of "Overlay" type. If so,
859 * check whether we can autopaint.
861 p_vout->p_sys->have_xvmc_autopaint = 0;
862 if( p_vout->p_sys->context_flags & XVMC_OVERLAID_SURFACE )
864 msg_Dbg( p_vout, "check colorkey properties" );
865 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
866 xvmc_attributes = XvMCQueryAttributes( p_vout->p_sys->p_display,
867 &p_vout->p_sys->context,
869 if( xvmc_attributes )
871 for( i = 0; i < num; ++i )
873 if( strncmp( "XV_AUTOPAINT_COLORKEY",
874 xvmc_attributes[i].name,
877 ap = XInternAtom( p_vout->p_sys->p_display,
878 "XV_AUTOPAINT_COLORKEY",
880 XvMCSetAttribute( p_vout->p_sys->p_display,
881 &p_vout->p_sys->context,
883 1 ); /* p_vout->p_sys->props[VO_PROP_AUTOPAINT_COLORKEY].value */
884 p_vout->p_sys->have_xvmc_autopaint = 1;
885 msg_Dbg( p_vout, "has xvmc autopaint" );
889 XFree( xvmc_attributes );
890 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
891 /* p_vout->p_sys->xvmc_xoverlay_type = X11OSD_COLORKEY; */
896 p_vout->p_sys->xvmc_xoverlay_type = X11OSD_SHAPED;
901 static void xxmc_xvmc_destroy_surfaces( vout_thread_t *p_vout )
904 xvmc_surface_handler_t *handler = NULL;
906 handler = &p_vout->p_sys->xvmc_surf_handler;
908 pthread_mutex_lock( &handler->mutex );
909 for( i = 0; i < XVMC_MAX_SURFACES; ++i )
911 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
912 if( handler->surfValid[i] )
914 XvMCFlushSurface( p_vout->p_sys->p_display , handler->surfaces+i);
915 XvMCSyncSurface( p_vout->p_sys->p_display, handler->surfaces+i );
916 XvMCHideSurface( p_vout->p_sys->p_display, handler->surfaces+i );
917 XvMCDestroySurface( p_vout->p_sys->p_display, handler->surfaces+i );
919 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
920 handler->surfValid[i] = 0;
922 pthread_mutex_unlock( &handler->mutex );
925 static void xxmc_xvmc_destroy_subpictures( vout_thread_t *p_vout )
928 xvmc_surface_handler_t *handler = NULL;
930 handler = &p_vout->p_sys->xvmc_surf_handler;
932 pthread_mutex_lock( &handler->mutex );
933 for( i = 0; i < XVMC_MAX_SUBPICTURES; ++i )
935 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
936 if( handler->subValid[i] )
938 XvMCFlushSubpicture( p_vout->p_sys->p_display , handler->subpictures+i);
939 XvMCSyncSubpicture( p_vout->p_sys->p_display, handler->subpictures+i );
940 XvMCDestroySubpicture( p_vout->p_sys->p_display, handler->subpictures+i );
942 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
943 handler->subValid[i] = 0;
945 pthread_mutex_unlock( &handler->mutex );
948 static XvMCSurface *xxmc_xvmc_alloc_surface( vout_thread_t *p_vout,
949 XvMCContext *context )
951 xvmc_surface_handler_t *handler = NULL;
954 handler = &p_vout->p_sys->xvmc_surf_handler;
956 pthread_mutex_lock( &handler->mutex );
957 xxmc_xvmc_dump_surfaces( p_vout );
958 for( i = 0; i < XVMC_MAX_SURFACES; ++i )
960 if( handler->surfValid[i] && !handler->surfInUse[i] )
962 handler->surfInUse[i] = 1;
963 xxmc_xvmc_dump_surfaces( p_vout );
964 pthread_mutex_unlock( &handler->mutex );
965 return (handler->surfaces + i);
968 for( i = 0; i < XVMC_MAX_SURFACES; ++i )
970 if( !handler->surfInUse[i] )
972 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
973 if( Success != XvMCCreateSurface( p_vout->p_sys->p_display,
975 handler->surfaces + i) )
977 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
978 pthread_mutex_unlock( &handler->mutex );
981 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
983 msg_Dbg( p_vout, "created surface %d", i );
984 handler->surfInUse[i] = 1;
985 handler->surfValid[i] = 1;
986 pthread_mutex_unlock( &handler->mutex );
987 return (handler->surfaces + i);
990 pthread_mutex_unlock( &handler->mutex );
994 void xxmc_dispose_context( vout_thread_t *p_vout )
996 if( p_vout->p_sys->contextActive )
998 if( p_vout->p_sys->xvmc_accel &
999 (VLC_XVMC_ACCEL_MOCOMP | VLC_XVMC_ACCEL_IDCT) )
1001 xvmc_macroblocks_t *macroblocks = NULL;
1003 macroblocks = &p_vout->p_sys->macroblocks;
1004 XvMCDestroyMacroBlocks( p_vout->p_sys->p_display,
1005 ¯oblocks->macro_blocks );
1006 XvMCDestroyBlocks( p_vout->p_sys->p_display,
1007 ¯oblocks->blocks );
1010 msg_Dbg( p_vout, "freeing up XvMC surfaces and subpictures" );
1011 if( p_vout->p_sys->xvmc_palette )
1012 free( p_vout->p_sys->xvmc_palette );
1013 dispose_xx44_palette( &p_vout->p_sys->palette );
1014 xxmc_xvmc_destroy_subpictures( p_vout );
1015 xxmc_xvmc_destroy_surfaces( p_vout );
1017 msg_Dbg(p_vout, "freeing up XvMC Context.");
1018 XLockDisplay( p_vout->p_sys->p_display );
1019 if( p_vout->p_sys->subImage )
1021 XFree( p_vout->p_sys->subImage );
1022 p_vout->p_sys->subImage = NULL;
1024 p_vout->p_sys->subImage = NULL;
1025 XUnlockDisplay( p_vout->p_sys->p_display );
1026 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
1027 XvMCDestroyContext( p_vout->p_sys->p_display,
1028 &p_vout->p_sys->context );
1029 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
1030 p_vout->p_sys->contextActive = 0;
1031 p_vout->p_sys->hwSubpictures = 0;
1032 p_vout->p_sys->xvmc_accel = 0;
1036 static int xxmc_find_context( vout_thread_t *p_vout, vlc_xxmc_t *xxmc,
1037 unsigned int width, unsigned int height )
1040 vlc_bool_t found = VLC_FALSE;
1041 xvmc_capabilities_t *curCap = NULL;
1042 unsigned int request_mpeg_flags, request_accel_flags;
1044 request_mpeg_flags = xxmc->mpeg;
1045 for( k = 0; k < NUM_ACCEL_PRIORITY; ++k )
1047 request_accel_flags = xxmc->acceleration & accel_priority[k];
1048 if( !request_accel_flags )
1051 curCap = p_vout->p_sys->xvmc_cap;
1052 for( i =0; i < p_vout->p_sys->xvmc_num_cap; ++i )
1054 msg_Dbg( p_vout, "surface type %d, capabilities 0x%8x 0x%8x",
1057 curCap->accel_flags );
1058 msg_Dbg( p_vout, "fequests: 0x%8x 0x%8x",
1060 request_accel_flags );
1061 if( ( (curCap->mpeg_flags & request_mpeg_flags) == request_mpeg_flags) &&
1062 (curCap->accel_flags & request_accel_flags) &&
1063 (width <= curCap->max_width) &&
1064 (height <= curCap->max_height) )
1073 p_vout->p_sys->xvmc_cur_cap = i;
1079 p_vout->p_sys->xvmc_accel = request_accel_flags;
1080 p_vout->p_sys->unsigned_intra = (curCap->flags & XVMC_INTRA_UNSIGNED);
1083 p_vout->p_sys->xvmc_accel = 0;
1087 static int xxmc_create_context( vout_thread_t *p_vout,
1088 unsigned int width, unsigned int height )
1090 xvmc_capabilities_t *curCap = NULL;
1092 curCap = p_vout->p_sys->xvmc_cap + p_vout->p_sys->xvmc_cur_cap;
1094 msg_Dbg( p_vout, "creating new XvMC context %d", curCap->type_id );
1096 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
1097 if( Success == XvMCCreateContext( p_vout->p_sys->p_display,
1098 p_vout->p_sys->i_xvport,
1102 p_vout->p_sys->context_flags,
1103 &p_vout->p_sys->context ) )
1105 p_vout->p_sys->xvmc_mpeg = curCap->mpeg_flags;
1106 p_vout->p_sys->xvmc_width = width;
1107 p_vout->p_sys->xvmc_height = height;
1108 p_vout->p_sys->contextActive = 1;
1110 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
1111 return p_vout->p_sys->contextActive;
1114 static void xvmc_flushsync(picture_t *picture)
1116 vout_thread_t *p_vout = picture->p_sys->p_vout;
1118 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
1120 if( ! xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf)) {
1121 msg_Dbg(p_vout, "xvmc_flushsync 1 : %d", picture->p_sys->xxmc_data.result );
1122 picture->p_sys->xxmc_data.result = 128;
1123 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1127 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
1128 picture->p_sys->xxmc_data.result =
1129 XvMCFlushSurface( p_vout->p_sys->p_display,
1130 picture->p_sys->xvmc_surf );
1131 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
1132 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1135 static void xvmc_flush(picture_t *picture)
1137 vout_thread_t *p_vout = picture->p_sys->p_vout;
1139 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
1141 if ( !xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf ) )
1143 msg_Dbg(p_vout, "xvmc flush 1 : %d", picture->p_sys->xxmc_data.result );
1144 picture->p_sys->xxmc_data.result = 128;
1145 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1149 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
1150 picture->p_sys->xxmc_data.result =
1151 XvMCFlushSurface( p_vout->p_sys->p_display,
1152 picture->p_sys->xvmc_surf );
1153 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
1154 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1157 static int xxmc_frame_updates( vout_thread_t *p_vout, picture_t *picture )
1159 vlc_xxmc_t *xxmc = &picture->p_sys->xxmc_data;
1162 * If we have changed context since the surface was updated, xvmc_surf
1163 * is either NULL or invalid. If it is invalid. Set it to NULL.
1164 * Also if there are other users of this surface, deregister our use of
1165 * it and later try to allocate a new, fresh one.
1168 if( picture->p_sys->xvmc_surf )
1170 if( !xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf ) )
1172 xxmc_xvmc_free_surface( p_vout , picture->p_sys->xvmc_surf );
1173 picture->p_sys->xvmc_surf = NULL;
1177 if( picture->p_sys->p_image )
1179 memset( picture->p_sys->p_image->data, 0,
1180 picture->p_sys->p_image->width
1181 * picture->p_sys->p_image->height );
1185 * If it is NULL create a new surface.
1187 if( !picture->p_sys->xvmc_surf )
1189 picture->p_sys->xvmc_surf = xxmc_xvmc_alloc_surface( p_vout,
1190 &p_vout->p_sys->context );
1191 if( !picture->p_sys->xvmc_surf )
1193 msg_Err( p_vout, "accelerated surface allocation failed.\n"
1194 " You are probably out of framebuffer memory.\n"
1195 " Falling back to software decoding." );
1196 p_vout->p_sys->xvmc_accel = 0;
1197 xxmc_dispose_context( p_vout );
1198 return VLC_EGENERIC;
1201 xxmc->acceleration = p_vout->p_sys->xvmc_accel;
1203 xxmc->proc_xxmc_flush = xvmc_flush;
1204 xxmc->proc_xxmc_flushsync = xvmc_flushsync;
1205 xxmc->xvmc.proc_macro_block = NULL;
1207 frame->vo_frame.proc_duplicate_frame_data = xxmc_duplicate_frame_data;
1209 xxmc->proc_xxmc_begin = xvmc_vld_frame;
1210 xxmc->proc_xxmc_slice = xvmc_vld_slice;
1214 static int xxmc_xvmc_update_context( vout_thread_t *p_vout,
1215 picture_t *picture, uint32_t width, uint32_t height )
1217 vlc_xxmc_t *xxmc = &picture->p_sys->xxmc_data;
1220 * Are we at all capable of doing XvMC ?
1222 if( p_vout->p_sys->xvmc_cap == 0 )
1223 return VLC_EGENERIC;
1225 msg_Dbg( p_vout, "new format: need to change XvMC context. "
1226 "width: %d height: %d mpeg: %d acceleration: %d",
1228 xxmc->mpeg, xxmc->acceleration );
1230 if( picture->p_sys->xvmc_surf )
1231 xxmc_xvmc_free_surface( p_vout , picture->p_sys->xvmc_surf );
1232 picture->p_sys->xvmc_surf = NULL;
1234 xxmc_dispose_context( p_vout );
1236 if( xxmc_find_context( p_vout, xxmc, width, height ) )
1238 xxmc_create_context( p_vout, width, height);
1239 xvmc_check_colorkey_properties( p_vout );
1240 xxmc_setup_subpictures(p_vout, width, height);
1243 if( !p_vout->p_sys->contextActive )
1245 msg_Dbg( p_vout, "using software decoding for this stream" );
1246 p_vout->p_sys->xvmc_accel = 0;
1250 msg_Dbg(p_vout, "using hardware decoding for this stream." );
1253 p_vout->p_sys->xvmc_mpeg = xxmc->mpeg;
1254 p_vout->p_sys->xvmc_width = width;
1255 p_vout->p_sys->xvmc_height = height;
1256 return p_vout->p_sys->contextActive;
1260 void xxmc_do_update_frame( picture_t *picture, uint32_t width, uint32_t height,
1261 double ratio, int format, int flags)
1263 vout_thread_t *p_vout = picture->p_sys->p_vout;
1267 picture->p_sys->xxmc_data.decoded = 0;
1268 picture->p_sys->nb_display = 0;
1269 picture->b_force = 0;
1270 vlc_xxmc_t *xxmc = &picture->p_sys->xxmc_data;
1272 xvmc_context_writer_lock( &p_vout->p_sys->xvmc_lock);
1273 if( (p_vout->p_sys->last_accel_request != xxmc->acceleration) ||
1274 (p_vout->p_sys->xvmc_mpeg != xxmc->mpeg) ||
1275 (p_vout->p_sys->xvmc_width != width) ||
1276 (p_vout->p_sys->xvmc_height != height))
1278 p_vout->p_sys->last_accel_request = xxmc->acceleration;
1279 xxmc_xvmc_update_context( p_vout, picture, width, height );
1282 if( p_vout->p_sys->contextActive )
1283 xxmc_frame_updates( p_vout, picture );
1285 if( !p_vout->p_sys->contextActive )
1287 xxmc->acceleration = 0;
1288 xxmc->xvmc.macroblocks = 0;
1292 picture->format.i_chroma = format;
1294 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock);
1296 XvMCGetSurfaceStatus( p_vout->p_sys->p_display,
1297 picture->p_sys->xvmc_surf,
1299 /* Wait a little till frame is being displayed */
1300 while( status & XVMC_DISPLAYING )
1304 XvMCGetSurfaceStatus( p_vout->p_sys->p_display,
1305 picture->p_sys->xvmc_surf,
1315 /* called xlocked */
1316 static void dispose_ximage( vout_thread_t *p_vout, XShmSegmentInfo *shminfo,
1319 # ifdef HAVE_SYS_SHM_H
1320 if( p_vout->p_sys->i_shm_opcode )
1322 XShmDetach( p_vout->p_sys->p_display, shminfo );
1324 shmdt( shminfo->shmaddr );
1325 if( shminfo->shmid >= 0 )
1327 shmctl( shminfo->shmid, IPC_RMID, 0 );
1328 shminfo->shmid = -1;
1335 free(myimage->data);
1341 void xvmc_vld_frame( picture_t *picture )
1343 picture_sys_t *p_sys = picture->p_sys;
1344 vout_thread_t *p_vout = p_sys->p_vout;
1345 vlc_vld_frame_t *vft = &(p_sys->xxmc_data.vld_frame);
1346 picture_t *ff = (picture_t *) vft->forward_reference_picture;
1347 picture_t *bf = (picture_t *) vft->backward_reference_picture;
1348 XvMCMpegControl ctl;
1349 XvMCSurface *fs=0, *bs=0;
1352 ctl.BHMV_range = vft->mv_ranges[0][0];
1353 ctl.BVMV_range = vft->mv_ranges[0][1];
1354 ctl.FHMV_range = vft->mv_ranges[1][0];
1355 ctl.FVMV_range = vft->mv_ranges[1][1];
1356 ctl.picture_structure = vft->picture_structure;
1357 ctl.intra_dc_precision = vft->intra_dc_precision;
1358 ctl.picture_coding_type = vft->picture_coding_type;
1359 ctl.mpeg_coding = (vft->mpeg_coding == 0) ? XVMC_MPEG_1 : XVMC_MPEG_2;
1361 ctl.flags |= (vft->progressive_sequence) ? XVMC_PROGRESSIVE_SEQUENCE : 0;
1362 ctl.flags |= (vft->scan) ? XVMC_ALTERNATE_SCAN : XVMC_ZIG_ZAG_SCAN;
1363 ctl.flags |= (vft->pred_dct_frame) ?
1364 XVMC_PRED_DCT_FRAME : XVMC_PRED_DCT_FIELD;
1365 ctl.flags |= (picture->b_top_field_first) ?
1366 XVMC_TOP_FIELD_FIRST : XVMC_BOTTOM_FIELD_FIRST;
1367 ctl.flags |= (vft->concealment_motion_vectors) ?
1368 XVMC_CONCEALMENT_MOTION_VECTORS : 0;
1369 ctl.flags |= (vft->q_scale_type) ? XVMC_Q_SCALE_TYPE : 0;
1370 ctl.flags |= (vft->intra_vlc_format) ? XVMC_INTRA_VLC_FORMAT : 0;
1371 ctl.flags |= (vft->second_field) ? XVMC_SECOND_FIELD : 0;
1374 fs = ff->p_sys->xvmc_surf;
1376 bs = bf->p_sys->xvmc_surf;
1379 * Below is for interlaced streams and second_field.
1381 if( ctl.picture_coding_type == P_TYPE ) /* XVMC_P_PICTURE) */
1382 bs = picture->p_sys->xvmc_surf;
1384 if( (qmx.load_intra_quantiser_matrix = vft->load_intra_quantizer_matrix) )
1386 memcpy( qmx.intra_quantiser_matrix, vft->intra_quantizer_matrix,
1387 sizeof(qmx.intra_quantiser_matrix) );
1389 if( (qmx.load_non_intra_quantiser_matrix =
1390 vft->load_non_intra_quantizer_matrix) )
1392 memcpy( qmx.non_intra_quantiser_matrix, vft->non_intra_quantizer_matrix,
1393 sizeof(qmx.non_intra_quantiser_matrix) );
1395 qmx.load_chroma_intra_quantiser_matrix = 0;
1396 qmx.load_chroma_non_intra_quantiser_matrix = 0;
1397 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
1399 if( ! xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf) )
1401 picture->p_sys->xxmc_data.result = 128;
1402 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1406 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
1407 XvMCLoadQMatrix( p_vout->p_sys->p_display, &p_vout->p_sys->context, &qmx );
1409 picture->p_sys->xxmc_data.result =
1410 XvMCBeginSurface( p_vout->p_sys->p_display,
1411 &p_vout->p_sys->context,
1412 picture->p_sys->xvmc_surf,
1414 } while( !picture->p_sys->xxmc_data.result );
1415 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
1416 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1419 void xvmc_vld_slice( picture_t *picture )
1421 picture_sys_t *p_sys = picture->p_sys;
1422 vout_thread_t *p_vout = p_sys->p_vout;
1424 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
1425 if( !xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf ) )
1427 picture->p_sys->xxmc_data.result = 128;
1428 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1429 msg_Err(p_vout, "vld slice error" );
1433 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
1434 picture->p_sys->xxmc_data.result =
1435 XvMCPutSlice2( p_vout->p_sys->p_display,
1436 &p_vout->p_sys->context,
1437 picture->p_sys->xxmc_data.slice_data,
1438 picture->p_sys->xxmc_data.slice_data_size,
1439 picture->p_sys->xxmc_data.slice_code );
1441 if( picture->p_sys->xxmc_data.result != 0 )
1442 msg_Err( p_vout, "vlc slice error %d",
1443 picture->p_sys->xxmc_data.result );
1445 * If CPU-saving mode is enabled, sleep after every xxmc->sleep slice. This will free
1446 * up the cpu while the decoder is working on the slice. The value of xxmc->sleep is calculated
1447 * so that the decoder thread sleeps at most 50% of the frame delay,
1448 * assuming a 2.6 kernel clock of 1000 Hz.
1450 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
1451 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1453 if( p_vout->p_sys->cpu_save_enabled )
1455 p_vout->p_sys->cpu_saver += 1.;
1456 if( p_vout->p_sys->cpu_saver >= picture->p_sys->xxmc_data.sleep )
1459 p_vout->p_sys->cpu_saver -= picture->p_sys->xxmc_data.sleep;