xine-lib  1.2.9
xxmc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2010 the xine project
3  * Copyright (C) 2004 the unichrome project
4  *
5  * This file is part of xine, a free video player.
6  *
7  * xine is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * xine is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20  *
21  * video_out_xxmc.c, X11 decoding accelerated video extension interface for xine
22  *
23  * based on mpeg2dec code from
24  * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
25  *
26  * Xv image support by Gerd Knorr <kraxel@goldbach.in-berlin.de>
27  *
28  * xine-specific code by Guenter Bartsch <bartscgr@studbox.uni-stuttgart.de>
29  *
30  * overlay support by James Courtier-Dutton <James@superbug.demon.co.uk> - July 2001
31  * X11 unscaled overlay support by Miguel Freitas - Nov 2003
32  * XxMC implementation by Thomas Hellström - August 2004
33  */
34 
35 #ifndef _XXMC_H
36 #define _XXMC_H
37 
38 #define XVMC_THREAD_SAFE
39 
40 /*
41  * some implementations are not aware of the display having been locked
42  * already before calling the xvmc function and may therefore deadlock.
43  */
44 /*
45 #define XVMC_LOCKDISPLAY_SAFE
46 */
47 
48 #ifdef HAVE_CONFIG_H
49 #include "config.h"
50 #endif
51 
52 #ifdef HAVE_XV
53 
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <errno.h>
58 #include <math.h>
59 
60 #if defined (__SVR4) && defined (__sun)
61 # include <sys/int_types.h>
62 #else
63 # include <stdint.h>
64 #endif
65 
66 #include <sys/types.h>
67 #if defined(__FreeBSD__)
68 #include <machine/param.h>
69 #endif
70 #include <sys/ipc.h>
71 #include <sys/shm.h>
72 #include <sys/time.h>
73 
74 #include <X11/Xlib.h>
75 #include <X11/Xutil.h>
76 #include <X11/cursorfont.h>
77 #include <X11/extensions/XShm.h>
78 #include <X11/extensions/Xv.h>
79 #include <X11/extensions/Xvlib.h>
80 #include <X11/extensions/XvMClib.h>
81 #ifdef HAVE_VLDXVMC
82  #include <X11/extensions/vldXvMC.h>
83 #endif
84 
85 #define LOG_MODULE "video_out_xxmc"
86 #define LOG_VERBOSE
87 /*
88 #define LOG
89 */
90 
91 #include "xine.h"
92 #include <xine/video_out.h>
93 #include <xine/xine_internal.h>
94 #include <xine/xineutils.h>
95 #include <xine/vo_scale.h>
96 #include "x11osd.h"
97 #include "accel_xvmc.h"
98 
99 #define FOURCC_IA44 0x34344149
100 #define FOURCC_AI44 0x34344941
101 #define XVMC_MAX_SURFACES 16
102 #define XVMC_MAX_SUBPICTURES 4
103 
104 typedef struct xxmc_driver_s xxmc_driver_t;
105 
106 typedef struct {
107  xine_macroblocks_t xine_mc;
108  XvMCBlockArray blocks; /* pointer to memory for dct block array */
109  int num_blocks;
110  XvMCMacroBlock *macroblockptr; /* pointer to current macro block */
111  XvMCMacroBlock *macroblockbaseptr; /* pointer to base MacroBlock in MB array */
112  XvMCMacroBlockArray macro_blocks; /* pointer to memory for macroblock array */
113  int slices;
114 } xvmc_macroblocks_t;
115 
116 
117 typedef struct {
118  int value;
119  int min;
120  int max;
121  Atom atom;
122 
123  cfg_entry_t *entry;
124 
125  xxmc_driver_t *this;
126 } xxmc_property_t;
127 
128 typedef struct {
129  vo_frame_t vo_frame;
130 
131  int width, height, format;
132  double ratio;
133 
134  XvImage *image;
135  XShmSegmentInfo shminfo;
136 
137  /* XvMC specific stuff */
138 
139  XvMCSurface *xvmc_surf;
140  xine_xxmc_t xxmc_data;
141  int last_sw_format;
142 } xxmc_frame_t;
143 
144 typedef struct{
145  unsigned int mpeg_flags;
146  unsigned int accel_flags;
147  unsigned int max_width;
148  unsigned int max_height;
149  unsigned int sub_max_width;
150  unsigned int sub_max_height;
151  int type_id;
152  XvImageFormatValues subPicType;
153  int flags;
154 } xvmc_capabilities_t;
155 
156 typedef struct xvmc_surface_handler_s {
157  XvMCSurface surfaces[XVMC_MAX_SURFACES];
158  int surfInUse[XVMC_MAX_SURFACES];
159  int surfValid[XVMC_MAX_SURFACES];
160  XvMCSubpicture subpictures[XVMC_MAX_SUBPICTURES];
161  int subInUse[XVMC_MAX_SUBPICTURES];
162  int subValid[XVMC_MAX_SUBPICTURES];
163  pthread_mutex_t mutex;
164 } xvmc_surface_handler_t;
165 
166 typedef struct context_lock_s {
167  pthread_mutex_t mutex;
168  pthread_cond_t cond;
169  int num_readers;
170 } context_lock_t;
171 
172 #define LOCK_AND_SURFACE_VALID(driver, surface) \
173  xvmc_context_reader_lock( &(driver)->xvmc_lock ); \
174  if (!xxmc_xvmc_surface_valid((driver),(surface))) { \
175  xvmc_context_reader_unlock( &(driver)->xvmc_lock ); \
176  return; \
177  }
178 
179 #if defined(XVMC_THREAD_SAFE) && defined(XVMC_LOCKDISPLAY_SAFE)
180 #define XVMCLOCKDISPLAY(display)
181 #define XVMCUNLOCKDISPLAY(display)
182 #else
183 #define XVMCLOCKDISPLAY(display) XLockDisplay(display)
184 #define XVMCUNLOCKDISPLAY(display) XUnlockDisplay(display)
185 #endif
186 
187 struct xxmc_driver_s {
188  vo_driver_t vo_driver;
189 
190  config_values_t *config;
191 
192  /* X11 / Xv related stuff */
193  Display *display;
194  int screen;
195  Drawable drawable;
196  unsigned int xv_format_yv12;
197  unsigned int xv_format_yuy2;
198  XVisualInfo vinfo;
199  GC gc;
200  XvPortID xv_port;
201  XColor black;
202 
203  int use_shm;
204  int use_pitch_alignment;
205  xxmc_property_t props[VO_NUM_PROPERTIES];
206  uint32_t capabilities;
207  xxmc_frame_t *recent_frames[VO_NUM_RECENT_FRAMES];
208  xxmc_frame_t *cur_frame;
209  int cur_field;
210  int bob;
211  int disable_bob_for_progressive_frames;
212  int disable_bob_for_scaled_osd;
213  int scaled_osd_active;
214  x11osd *xoverlay;
215  int xv_xoverlay_type;
216  int xoverlay_type;
217  int ovl_changed;
218 
219  /* all scaling information goes here */
220  vo_scale_t sc;
221  int deinterlace_enabled;
222  int use_colorkey;
223  uint32_t colorkey;
224  int (*x11_old_error_handler) (Display *, XErrorEvent *);
225  xine_t *xine;
226 
227  /* XvMC related stuff here */
228  xvmc_macroblocks_t macroblocks;
229  xvmc_capabilities_t *xvmc_cap;
230  unsigned xvmc_num_cap;
231  unsigned int xvmc_max_subpic_x;
232  unsigned int xvmc_max_subpic_y;
233  int xvmc_eventbase;
234  int xvmc_errbase;
235  int hwSubpictures;
236  XvMCSubpicture *old_subpic,*new_subpic;
237  xx44_palette_t palette;
238  int first_overlay;
239  float cpu_saver;
240  int cpu_save_enabled;
241  int reverse_nvidia_palette;
242  int context_flags;
243 
244  /*
245  * These variables are protected by the context lock:
246  */
247 
248  unsigned xvmc_cur_cap;
249  int xvmc_backend_subpic;
250  XvMCContext context;
251  int contextActive;
252  xvmc_surface_handler_t xvmc_surf_handler;
253  unsigned xvmc_mpeg;
254  unsigned xvmc_accel;
255  unsigned last_accel_request;
256  unsigned xvmc_width;
257  unsigned xvmc_height;
258  int have_xvmc_autopaint;
259  int xvmc_xoverlay_type;
260  int unsigned_intra;
261 
262  /*
263  * Only creation and destruction of the below.
264  */
265 
266  char *xvmc_palette;
267  XvImage *subImage;
268  XShmSegmentInfo subShmInfo;
269 
270  /*
271  * The mutex below is needed since XlockDisplay wasn't really enough
272  * to protect the XvMC Calls.
273  */
274  context_lock_t xvmc_lock;
275 
276  alphablend_t alphablend_extra_data;
277 };
278 
279 typedef struct {
280  video_driver_class_t driver_class;
281 
282  config_values_t *config;
283  xine_t *xine;
284 } xxmc_class_t;
285 
286 extern void xvmc_context_reader_unlock(context_lock_t *c);
287 extern void xvmc_context_reader_lock(context_lock_t *c);
288 extern int xxmc_xvmc_surface_valid(xxmc_driver_t *this, XvMCSurface *surf);
289 
290 extern void xvmc_vld_slice(vo_frame_t *this_gen);
291 extern void xvmc_vld_frame(struct vo_frame_s *this_gen);
292 
293 extern void xxmc_xvmc_proc_macro_block(int x, int y, int mb_type, int motion_type,
294  int (*mv_field_sel)[2], int *dmvector,
295  int cbp,
296  int dct_type, vo_frame_t *current_frame,
297  vo_frame_t *forward_ref_frame,
298  vo_frame_t *backward_ref_frame,
299  int picture_structure,
300  int second_field, int (*f_mot_pmv)[2],
301  int (*b_mot_pmv)[2]);
302 
303 #endif
304 #endif
unsigned int height
Definition: gfontrle.c:5
Definition: alphablend.h:30
Definition: accel_xvmc.h:81
Definition: configfile.h:83
#define VO_NUM_PROPERTIES
Definition: video_out.h:276
Definition: video_out.h:50
void xvmc_context_reader_unlock(context_lock_t *c)
Definition: video_out_xxmc.c:99
Definition: video_out.h:60
#define VO_NUM_RECENT_FRAMES
Definition: video_out.h:289
unsigned int width
Definition: gfontrle.c:4
void xvmc_context_reader_lock(context_lock_t *c)
Definition: video_out_xxmc.c:90
Definition: alphablend.h:53
Definition: x11osd.c:57
Definition: xine_internal.h:81
void xxmc_xvmc_proc_macro_block(int x, int y, int mb_type, int motion_type, int(*mv_field_sel)[2], int *dmvector, int cbp, int dct_type, vo_frame_t *current_frame, vo_frame_t *forward_ref_frame, vo_frame_t *backward_ref_frame, int picture_structure, int second_field, int(*f_mot_pmv)[2], int(*b_mot_pmv)[2])
Definition: xvmc_mocomp.c:99
Definition: accel_xvmc.h:38
Definition: configfile.h:46
int xxmc_xvmc_surface_valid(xxmc_driver_t *this, XvMCSurface *surf)
Definition: video_out_xxmc.c:266
Definition: video_out.h:430
Definition: vo_scale.h:39