xine-lib  1.2.10
xxmc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2018 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  xine_t *xine;
283 } xxmc_class_t;
284 
285 extern void xvmc_context_reader_unlock(context_lock_t *c);
286 extern void xvmc_context_reader_lock(context_lock_t *c);
287 extern int xxmc_xvmc_surface_valid(xxmc_driver_t *this, XvMCSurface *surf);
288 
289 extern void xvmc_vld_slice(vo_frame_t *this_gen);
290 extern void xvmc_vld_frame(struct vo_frame_s *this_gen);
291 
292 extern void xxmc_xvmc_proc_macro_block(int x, int y, int mb_type, int motion_type,
293  int (*mv_field_sel)[2], int *dmvector,
294  int cbp,
295  int dct_type, vo_frame_t *current_frame,
296  vo_frame_t *forward_ref_frame,
297  vo_frame_t *backward_ref_frame,
298  int picture_structure,
299  int second_field, int (*f_mot_pmv)[2],
300  int (*b_mot_pmv)[2]);
301 
302 #endif
303 #endif
xine_s
Definition: xine_internal.h:80
xine_vld_frame_s::intra_vlc_format
int intra_vlc_format
Definition: accel_xvmc.h:52
xvmc_render_macro_blocks
static void xvmc_render_macro_blocks(vo_frame_t *current_image, vo_frame_t *backward_ref_image, vo_frame_t *forward_ref_image, int picture_structure, int second_field, xvmc_macroblocks_t *macroblocks)
Definition: xvmc_mocomp.c:66
xineutils.h
x11osd.h
xine_vld_frame_s::intra_dc_precision
int intra_dc_precision
Definition: accel_xvmc.h:45
xvmc_context_reader_unlock
void xvmc_context_reader_unlock(context_lock_t *c)
Definition: video_out_xxmc.c:99
xine_vld_frame_s::backward_reference_frame
vo_frame_t * backward_reference_frame
Definition: accel_xvmc.h:58
XINE_MC_FIELD
#define XINE_MC_FIELD
Definition: accel_xvmc.h:137
xine_vld_frame_s::mpeg_coding
int mpeg_coding
Definition: accel_xvmc.h:46
xine_vld_frame_s::load_intra_quantizer_matrix
int load_intra_quantizer_matrix
Definition: accel_xvmc.h:54
alphablend_t
Definition: alphablend.h:30
xxmc.h
vo_frame_s::picture_coding_type
int picture_coding_type
Definition: video_out.h:126
XINE_PICT_I_TYPE
#define XINE_PICT_I_TYPE
Definition: accel_xvmc.h:143
XINE_MC_FRAME
#define XINE_MC_FRAME
Definition: accel_xvmc.h:138
XINE_MACROBLOCK_MOTION_FORWARD
#define XINE_MACROBLOCK_MOTION_FORWARD
Definition: accel_xvmc.h:152
xine_vld_frame_s::picture_coding_type
int picture_coding_type
Definition: accel_xvmc.h:44
xine_xxmc_s
Definition: accel_xvmc.h:77
VO_NUM_PROPERTIES
#define VO_NUM_PROPERTIES
Definition: video_out.h:275
xxmc_xvmc_surface_valid
int xxmc_xvmc_surface_valid(xxmc_driver_t *this, XvMCSurface *surf)
Definition: video_out_xxmc.c:266
vo_frame_s::driver
vo_driver_t * driver
Definition: video_out.h:151
vo_scale_s
Definition: vo_scale.h:39
vo_frame_s::top_field_first
int top_field_first
Definition: video_out.h:120
lprintf
#define lprintf(...)
Definition: xineutils.h:620
XINE_PICT_B_TYPE
#define XINE_PICT_B_TYPE
Definition: accel_xvmc.h:145
XINE_MC_16X8
#define XINE_MC_16X8
Definition: accel_xvmc.h:139
xine_macroblock_s
Definition: accel_xvmc.h:34
vo_driver_t
Definition: video_out.h:50
video_out.h
video_driver_class_s
Definition: video_out.h:426
xine_vld_frame_s::q_scale_type
int q_scale_type
Definition: accel_xvmc.h:51
NULL
NULL
Definition: xine_plugin.c:78
XXMC_FRAME
#define XXMC_FRAME(frame_gen)
Definition: accel_xvmc.h:112
XINE_PICT_D_TYPE
#define XINE_PICT_D_TYPE
Definition: accel_xvmc.h:146
xine_vld_frame_s::forward_reference_frame
vo_frame_t * forward_reference_frame
Definition: accel_xvmc.h:59
width
unsigned int width
Definition: gfontrle.c:4
calc_DMV
static void calc_DMV(int DMV[][2], int *dmvector, int mvx, int mvy, int picture_structure, int top_field_first)
Definition: xvmc_mocomp.c:26
xine_vld_frame_s::scan
int scan
Definition: accel_xvmc.h:48
xine_vld_frame_s::load_non_intra_quantizer_matrix
int load_non_intra_quantizer_matrix
Definition: accel_xvmc.h:55
config_values_s
Definition: configfile.h:83
xvmc_context_reader_lock
void xvmc_context_reader_lock(context_lock_t *c)
Definition: video_out_xxmc.c:90
xine_vld_frame_s::progressive_sequence
int progressive_sequence
Definition: accel_xvmc.h:47
xine_vld_frame_s
Definition: accel_xvmc.h:40
XINE_MC_DMV
#define XINE_MC_DMV
Definition: accel_xvmc.h:140
XINE_MACROBLOCK_INTRA
#define XINE_MACROBLOCK_INTRA
Definition: accel_xvmc.h:149
VO_BOTH_FIELDS
#define VO_BOTH_FIELDS
Definition: video_out.h:293
vo_scale.h
accel_xvmc.h
xine_vld_frame_s::second_field
int second_field
Definition: accel_xvmc.h:53
xine_vld_frame_s::mv_ranges
int mv_ranges[2][2]
Definition: accel_xvmc.h:42
height
unsigned int height
Definition: gfontrle.c:5
xine_vld_frame_s::non_intra_quantizer_matrix
uint8_t non_intra_quantizer_matrix[64]
Definition: accel_xvmc.h:57
VO_NUM_RECENT_FRAMES
#define VO_NUM_RECENT_FRAMES
Definition: video_out.h:288
XINE_MACROBLOCK_MOTION_BACKWARD
#define XINE_MACROBLOCK_MOTION_BACKWARD
Definition: accel_xvmc.h:151
x11osd
Definition: x11osd.c:61
xine_vld_frame_s::concealment_motion_vectors
int concealment_motion_vectors
Definition: accel_xvmc.h:50
xine_internal.h
xine_vld_frame_s::picture_structure
int picture_structure
Definition: accel_xvmc.h:43
VO_TOP_FIELD
#define VO_TOP_FIELD
Definition: video_out.h:291
config.h
xine_vld_frame_s::intra_quantizer_matrix
uint8_t intra_quantizer_matrix[64]
Definition: accel_xvmc.h:56
xine_vld_frame_s::pred_dct_frame
int pred_dct_frame
Definition: accel_xvmc.h:49
vo_frame_s
Definition: video_out.h:59
xx44_palette_t
Definition: alphablend.h:55
cfg_entry_s
Definition: configfile.h:46
XINE_PICT_P_TYPE
#define XINE_PICT_P_TYPE
Definition: accel_xvmc.h:144
XINE_MACROBLOCK_PATTERN
#define XINE_MACROBLOCK_PATTERN
Definition: accel_xvmc.h:150
xxmc_xvmc_proc_macro_block
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
xine.h