xine-lib: xine-lib-1.2.13/src/video_out/xxmc.h Source File

xine-lib 1.2.13-20230125hg15249

xxmc.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2000-2020 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#if defined(HAVE_CONFIG_H) && !defined(__XINE_LIB_CONFIG_H__)
49# error config.h not included
50#endif
51
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55#include <errno.h>
56#include <math.h>
57
58#if defined (__SVR4) && defined (__sun)
59# include <sys/int_types.h>
60#else
61# include <stdint.h>
62#endif
63
64#include <sys/types.h>
65#if defined(__FreeBSD__)
66#include <machine/param.h>
67#endif
68#include <sys/ipc.h>
69#include <sys/shm.h>
70#include <sys/time.h>
71
72#include <X11/Xlib.h>
73#include <X11/Xutil.h>
74#include <X11/cursorfont.h>
75#include <X11/extensions/XShm.h>
76#include <X11/extensions/Xv.h>
77#include <X11/extensions/Xvlib.h>
78#include <X11/extensions/XvMClib.h>
79#ifdef HAVE_VLDXVMC
80 #include <X11/extensions/vldXvMC.h>
81#endif
82
83#define LOG_MODULE "video_out_xxmc"
84#define LOG_VERBOSE
85/*
86#define LOG
87*/
88
89#include "xine.h"
90#include <xine/video_out.h>
91#include <xine/xine_internal.h>
92#include <xine/xineutils.h>
93#include <xine/vo_scale.h>
94#include "x11osd.h"
95#include "accel_xvmc.h"
96
97#define FOURCC_IA44 0x34344149
98#define FOURCC_AI44 0x34344941
99#define XVMC_MAX_SURFACES 16
100#define XVMC_MAX_SUBPICTURES 4
101
102 typedef struct xxmc_driver_s xxmc_driver_t;
103
104 typedef struct {
105 xine_macroblocks_t xine_mc;
106 XvMCBlockArray blocks; /* pointer to memory for dct block array */
107 int num_blocks;
108 XvMCMacroBlock *macroblockptr; /* pointer to current macro block */
109 XvMCMacroBlock *macroblockbaseptr; /* pointer to base MacroBlock in MB array */
110 XvMCMacroBlockArray macro_blocks; /* pointer to memory for macroblock array */
111 int slices;
112} xvmc_macroblocks_t;
113
114
115 typedef struct {
116 int value;
117 int min;
118 int max;
119 Atom atom;
120
121 cfg_entry_t *entry;
122
123 xxmc_driver_t *this;
124} xxmc_property_t;
125
126 typedef struct {
127 vo_frame_t vo_frame;
128
129 int width, height, format;
130 double ratio;
131
132 XvImage *image;
133 XShmSegmentInfo shminfo;
134
135 /* XvMC specific stuff */
136
137 XvMCSurface *xvmc_surf;
138 xine_xxmc_t xxmc_data;
139 int last_sw_format;
140} xxmc_frame_t;
141
142 typedef struct{
143 unsigned int mpeg_flags;
144 unsigned int accel_flags;
145 unsigned int max_width;
146 unsigned int max_height;
147 unsigned int sub_max_width;
148 unsigned int sub_max_height;
149 int type_id;
150 XvImageFormatValues subPicType;
151 int flags;
152} xvmc_capabilities_t;
153
154 typedef struct xvmc_surface_handler_s {
155 XvMCSurface surfaces[XVMC_MAX_SURFACES];
156 int surfInUse[XVMC_MAX_SURFACES];
157 int surfValid[XVMC_MAX_SURFACES];
158 XvMCSubpicture subpictures[XVMC_MAX_SUBPICTURES];
159 int subInUse[XVMC_MAX_SUBPICTURES];
160 int subValid[XVMC_MAX_SUBPICTURES];
161 pthread_mutex_t mutex;
162} xvmc_surface_handler_t;
163
164 typedef struct context_lock_s {
165 pthread_mutex_t mutex;
166 pthread_cond_t cond;
167 int num_readers;
168} context_lock_t;
169
170#define LOCK_AND_SURFACE_VALID(driver, surface) \
171 xvmc_context_reader_lock( &(driver)->xvmc_lock ); \
172 if (!xxmc_xvmc_surface_valid((driver),(surface))) { \
173 xvmc_context_reader_unlock( &(driver)->xvmc_lock ); \
174 return; \
175 }
176
177#if defined(XVMC_THREAD_SAFE) && defined(XVMC_LOCKDISPLAY_SAFE)
178#define XVMCLOCKDISPLAY(display)
179#define XVMCUNLOCKDISPLAY(display)
180#else
181#define XVMCLOCKDISPLAY(display) XLockDisplay(display)
182#define XVMCUNLOCKDISPLAY(display) XUnlockDisplay(display)
183#endif
184
185 struct xxmc_driver_s {
186 vo_driver_t vo_driver;
187
188 config_values_t *config;
189
190 /* X11 / Xv related stuff */
191 Display *display;
192 int screen;
193 Drawable drawable;
194 unsigned int xv_format_yv12;
195 unsigned int xv_format_yuy2;
196 XVisualInfo vinfo;
197 GC gc;
198 XvPortID xv_port;
199 XColor black;
200
201 int use_shm;
202 int use_pitch_alignment;
203 xxmc_property_t props[VO_NUM_PROPERTIES];
204 uint32_t capabilities;
205 xxmc_frame_t *recent_frames[VO_NUM_RECENT_FRAMES];
206 xxmc_frame_t *cur_frame;
207 int cur_field;
208 int bob;
209 int disable_bob_for_progressive_frames;
210 int disable_bob_for_scaled_osd;
211 int scaled_osd_active;
212 x11osd *xoverlay;
213 int xv_xoverlay_type;
214 int xoverlay_type;
215 int ovl_changed;
216
217 /* all scaling information goes here */
218 vo_scale_t sc;
219 int deinterlace_enabled;
220 int use_colorkey;
221 uint32_t colorkey;
222 int (*x11_old_error_handler) (Display *, XErrorEvent *);
223 xine_t *xine;
224
225 /* XvMC related stuff here */
226 xvmc_macroblocks_t macroblocks;
227 xvmc_capabilities_t *xvmc_cap;
228 unsigned xvmc_num_cap;
229 unsigned int xvmc_max_subpic_x;
230 unsigned int xvmc_max_subpic_y;
231 int xvmc_eventbase;
232 int xvmc_errbase;
233 int hwSubpictures;
234 XvMCSubpicture *old_subpic,*new_subpic;
235 xx44_palette_t palette;
236 int first_overlay;
237 float cpu_saver;
238 int cpu_save_enabled;
239 int reverse_nvidia_palette;
240 int context_flags;
241
242 /*
243 * These variables are protected by the context lock:
244 */
245
246 unsigned xvmc_cur_cap;
247 int xvmc_backend_subpic;
248 XvMCContext context;
249 int contextActive;
250 xvmc_surface_handler_t xvmc_surf_handler;
251 unsigned xvmc_mpeg;
252 unsigned xvmc_accel;
253 unsigned last_accel_request;
254 unsigned xvmc_width;
255 unsigned xvmc_height;
256 int have_xvmc_autopaint;
257 int xvmc_xoverlay_type;
258 int unsigned_intra;
259
260 /*
261 * Only creation and destruction of the below.
262 */
263
264 char *xvmc_palette;
265 XvImage *subImage;
266 XShmSegmentInfo subShmInfo;
267
268 /*
269 * The mutex below is needed since XlockDisplay wasn't really enough
270 * to protect the XvMC Calls.
271 */
272 context_lock_t xvmc_lock;
273
274 alphablend_t alphablend_extra_data;
275};
276
277 typedef struct {
278 video_driver_class_t driver_class;
279
280 xine_t *xine;
281} xxmc_class_t;
282
283extern void xvmc_context_reader_unlock(context_lock_t *c);
284extern void xvmc_context_reader_lock(context_lock_t *c);
285extern int xxmc_xvmc_surface_valid(xxmc_driver_t *this, XvMCSurface *surf);
286
287 extern void xvmc_vld_slice(vo_frame_t *this_gen);
288 extern void xvmc_vld_frame(struct vo_frame_s *this_gen);
289
290extern void xxmc_xvmc_proc_macro_block(int x, int y, int mb_type, int motion_type,
291 int (*mv_field_sel)[2], int *dmvector,
292 int cbp,
293 int dct_type, vo_frame_t *current_frame,
294 vo_frame_t *forward_ref_frame,
295 vo_frame_t *backward_ref_frame,
296 int picture_structure,
297 int second_field, int (*f_mot_pmv)[2],
298 int (*b_mot_pmv)[2]);
299
300#endif
accel_xvmc.h
height
unsigned int height
Definition gfontrle.c:5
width
unsigned int width
Definition gfontrle.c:4
video_out.h
VO_NUM_RECENT_FRAMES
#define VO_NUM_RECENT_FRAMES
Definition video_out.h:302
VO_NUM_PROPERTIES
#define VO_NUM_PROPERTIES
Definition video_out.h:289
alphablend_t
Definition alphablend.h:30
cfg_entry_s
Definition configfile.h:46
config_values_s
Definition configfile.h:83
context_lock_s
Definition xxmc.h:164
context_lock_s::num_readers
int num_readers
Definition xxmc.h:167
context_lock_s::cond
pthread_cond_t cond
Definition xxmc.h:166
context_lock_s::mutex
pthread_mutex_t mutex
Definition xxmc.h:165
video_driver_class_s
Definition video_out.h:449
vo_driver_t
Definition video_out.h:50
vo_frame_s
Definition video_out.h:70
vo_scale_s
Definition vo_scale.h:39
x11osd
Definition x11osd.c:60
xine_macroblock_s
Definition accel_xvmc.h:34
xine_s
Definition xine_internal.h:80
xine_xxmc_s
Definition accel_xvmc.h:77
xvmc_capabilities_t
Definition xxmc.h:142
xvmc_capabilities_t::subPicType
XvImageFormatValues subPicType
Definition xxmc.h:150
xvmc_capabilities_t::accel_flags
unsigned int accel_flags
Definition xxmc.h:144
xvmc_capabilities_t::type_id
int type_id
Definition xxmc.h:149
xvmc_capabilities_t::sub_max_height
unsigned int sub_max_height
Definition xxmc.h:148
xvmc_capabilities_t::max_width
unsigned int max_width
Definition xxmc.h:145
xvmc_capabilities_t::flags
int flags
Definition xxmc.h:151
xvmc_capabilities_t::max_height
unsigned int max_height
Definition xxmc.h:146
xvmc_capabilities_t::sub_max_width
unsigned int sub_max_width
Definition xxmc.h:147
xvmc_capabilities_t::mpeg_flags
unsigned int mpeg_flags
Definition xxmc.h:143
xvmc_macroblocks_t
Definition xxmc.h:104
xvmc_macroblocks_t::num_blocks
int num_blocks
Definition xxmc.h:107
xvmc_macroblocks_t::slices
int slices
Definition xxmc.h:111
xvmc_macroblocks_t::macroblockbaseptr
XvMCMacroBlock * macroblockbaseptr
Definition xxmc.h:109
xvmc_macroblocks_t::blocks
XvMCBlockArray blocks
Definition xxmc.h:106
xvmc_macroblocks_t::xine_mc
xine_macroblocks_t xine_mc
Definition xxmc.h:105
xvmc_macroblocks_t::macro_blocks
XvMCMacroBlockArray macro_blocks
Definition xxmc.h:110
xvmc_macroblocks_t::macroblockptr
XvMCMacroBlock * macroblockptr
Definition xxmc.h:108
xvmc_surface_handler_s
Definition xxmc.h:154
xvmc_surface_handler_s::subpictures
XvMCSubpicture subpictures[4]
Definition xxmc.h:158
xvmc_surface_handler_s::mutex
pthread_mutex_t mutex
Definition xxmc.h:161
xvmc_surface_handler_s::subValid
int subValid[4]
Definition xxmc.h:160
xvmc_surface_handler_s::subInUse
int subInUse[4]
Definition xxmc.h:159
xvmc_surface_handler_s::surfValid
int surfValid[16]
Definition xxmc.h:157
xvmc_surface_handler_s::surfInUse
int surfInUse[16]
Definition xxmc.h:156
xvmc_surface_handler_s::surfaces
XvMCSurface surfaces[16]
Definition xxmc.h:155
xx44_palette_t
Definition alphablend.h:55
xxmc_class_t
Definition xxmc.h:277
xxmc_class_t::xine
xine_t * xine
Definition xxmc.h:280
xxmc_class_t::driver_class
video_driver_class_t driver_class
Definition xxmc.h:278
xxmc_driver_s
Definition xxmc.h:185
xxmc_driver_s::reverse_nvidia_palette
int reverse_nvidia_palette
Definition xxmc.h:239
xxmc_driver_s::use_pitch_alignment
int use_pitch_alignment
Definition xxmc.h:202
xxmc_driver_s::new_subpic
XvMCSubpicture * new_subpic
Definition xxmc.h:234
xxmc_driver_s::cpu_saver
float cpu_saver
Definition xxmc.h:237
xxmc_driver_s::last_accel_request
unsigned last_accel_request
Definition xxmc.h:253
xxmc_driver_s::bob
int bob
Definition xxmc.h:208
xxmc_driver_s::capabilities
uint32_t capabilities
Definition xxmc.h:204
xxmc_driver_s::xvmc_surf_handler
xvmc_surface_handler_t xvmc_surf_handler
Definition xxmc.h:250
xxmc_driver_s::xvmc_eventbase
int xvmc_eventbase
Definition xxmc.h:231
xxmc_driver_s::xoverlay
x11osd * xoverlay
Definition xxmc.h:212
xxmc_driver_s::xvmc_errbase
int xvmc_errbase
Definition xxmc.h:232
xxmc_driver_s::disable_bob_for_scaled_osd
int disable_bob_for_scaled_osd
Definition xxmc.h:210
xxmc_driver_s::xvmc_cap
xvmc_capabilities_t * xvmc_cap
Definition xxmc.h:227
xxmc_driver_s::props
xxmc_property_t props[VO_NUM_PROPERTIES]
Definition xxmc.h:203
xxmc_driver_s::xvmc_cur_cap
unsigned xvmc_cur_cap
Definition xxmc.h:246
xxmc_driver_s::screen
int screen
Definition xxmc.h:192
xxmc_driver_s::x11_old_error_handler
int(* x11_old_error_handler)(Display *, XErrorEvent *)
Definition xxmc.h:222
xxmc_driver_s::xvmc_mpeg
unsigned xvmc_mpeg
Definition xxmc.h:251
xxmc_driver_s::xine
xine_t * xine
Definition xxmc.h:223
xxmc_driver_s::use_shm
int use_shm
Definition xxmc.h:201
xxmc_driver_s::xoverlay_type
int xoverlay_type
Definition xxmc.h:214
xxmc_driver_s::contextActive
int contextActive
Definition xxmc.h:249
xxmc_driver_s::cur_field
int cur_field
Definition xxmc.h:207
xxmc_driver_s::disable_bob_for_progressive_frames
int disable_bob_for_progressive_frames
Definition xxmc.h:209
xxmc_driver_s::have_xvmc_autopaint
int have_xvmc_autopaint
Definition xxmc.h:256
xxmc_driver_s::xvmc_max_subpic_x
unsigned int xvmc_max_subpic_x
Definition xxmc.h:229
xxmc_driver_s::xvmc_xoverlay_type
int xvmc_xoverlay_type
Definition xxmc.h:257
xxmc_driver_s::deinterlace_enabled
int deinterlace_enabled
Definition xxmc.h:219
xxmc_driver_s::cur_frame
xxmc_frame_t * cur_frame
Definition xxmc.h:206
xxmc_driver_s::sc
vo_scale_t sc
Definition xxmc.h:218
xxmc_driver_s::use_colorkey
int use_colorkey
Definition xxmc.h:220
xxmc_driver_s::palette
xx44_palette_t palette
Definition xxmc.h:235
xxmc_driver_s::first_overlay
int first_overlay
Definition xxmc.h:236
xxmc_driver_s::xvmc_max_subpic_y
unsigned int xvmc_max_subpic_y
Definition xxmc.h:230
xxmc_driver_s::vinfo
XVisualInfo vinfo
Definition xxmc.h:196
xxmc_driver_s::cpu_save_enabled
int cpu_save_enabled
Definition xxmc.h:238
xxmc_driver_s::context_flags
int context_flags
Definition xxmc.h:240
xxmc_driver_s::scaled_osd_active
int scaled_osd_active
Definition xxmc.h:211
xxmc_driver_s::xvmc_height
unsigned xvmc_height
Definition xxmc.h:255
xxmc_driver_s::ovl_changed
int ovl_changed
Definition xxmc.h:215
xxmc_driver_s::xv_format_yv12
unsigned int xv_format_yv12
Definition xxmc.h:194
xxmc_driver_s::old_subpic
XvMCSubpicture * old_subpic
Definition xxmc.h:234
xxmc_driver_s::unsigned_intra
int unsigned_intra
Definition xxmc.h:258
xxmc_driver_s::recent_frames
xxmc_frame_t * recent_frames[VO_NUM_RECENT_FRAMES]
Definition xxmc.h:205
xxmc_driver_s::black
XColor black
Definition xxmc.h:199
xxmc_driver_s::xv_xoverlay_type
int xv_xoverlay_type
Definition xxmc.h:213
xxmc_driver_s::xvmc_width
unsigned xvmc_width
Definition xxmc.h:254
xxmc_driver_s::xvmc_palette
char * xvmc_palette
Definition xxmc.h:264
xxmc_driver_s::context
XvMCContext context
Definition xxmc.h:248
xxmc_driver_s::xv_format_yuy2
unsigned int xv_format_yuy2
Definition xxmc.h:195
xxmc_driver_s::colorkey
uint32_t colorkey
Definition xxmc.h:221
xxmc_driver_s::subShmInfo
XShmSegmentInfo subShmInfo
Definition xxmc.h:266
xxmc_driver_s::xvmc_lock
context_lock_t xvmc_lock
Definition xxmc.h:272
xxmc_driver_s::xvmc_accel
unsigned xvmc_accel
Definition xxmc.h:252
xxmc_driver_s::config
config_values_t * config
Definition xxmc.h:188
xxmc_driver_s::xvmc_num_cap
unsigned xvmc_num_cap
Definition xxmc.h:228
xxmc_driver_s::macroblocks
xvmc_macroblocks_t macroblocks
Definition xxmc.h:226
xxmc_driver_s::subImage
XvImage * subImage
Definition xxmc.h:265
xxmc_driver_s::alphablend_extra_data
alphablend_t alphablend_extra_data
Definition xxmc.h:274
xxmc_driver_s::display
Display * display
Definition xxmc.h:191
xxmc_driver_s::hwSubpictures
int hwSubpictures
Definition xxmc.h:233
xxmc_driver_s::xv_port
XvPortID xv_port
Definition xxmc.h:198
xxmc_driver_s::gc
GC gc
Definition xxmc.h:197
xxmc_driver_s::vo_driver
vo_driver_t vo_driver
Definition xxmc.h:186
xxmc_driver_s::drawable
Drawable drawable
Definition xxmc.h:193
xxmc_driver_s::xvmc_backend_subpic
int xvmc_backend_subpic
Definition xxmc.h:247
xxmc_frame_t
Definition xxmc.h:126
xxmc_frame_t::format
int format
Definition xxmc.h:129
xxmc_frame_t::xvmc_surf
XvMCSurface * xvmc_surf
Definition xxmc.h:137
xxmc_frame_t::image
XvImage * image
Definition xxmc.h:132
xxmc_frame_t::shminfo
XShmSegmentInfo shminfo
Definition xxmc.h:133
xxmc_frame_t::ratio
double ratio
Definition xxmc.h:130
xxmc_frame_t::xxmc_data
xine_xxmc_t xxmc_data
Definition xxmc.h:138
xxmc_frame_t::vo_frame
vo_frame_t vo_frame
Definition xxmc.h:127
xxmc_frame_t::last_sw_format
int last_sw_format
Definition xxmc.h:139
xxmc_property_t
Definition xxmc.h:115
xxmc_property_t::max
int max
Definition xxmc.h:118
xxmc_property_t::atom
Atom atom
Definition xxmc.h:119
xxmc_property_t::entry
cfg_entry_t * entry
Definition xxmc.h:121
xxmc_property_t::value
int value
Definition xxmc.h:116
xxmc_property_t::min
int min
Definition xxmc.h:117
vo_scale.h
x11osd.h
xine.h
xine_internal.h
xineutils.h
XVMC_MAX_SUBPICTURES
#define XVMC_MAX_SUBPICTURES
Definition xxmc.h:100
xxmc_xvmc_surface_valid
int xxmc_xvmc_surface_valid(xxmc_driver_t *this, XvMCSurface *surf)
Definition video_out_xxmc.c:269
xvmc_vld_slice
void xvmc_vld_slice(vo_frame_t *this_gen)
xvmc_context_reader_unlock
void xvmc_context_reader_unlock(context_lock_t *c)
Definition video_out_xxmc.c:102
xvmc_surface_handler_t
struct xvmc_surface_handler_s xvmc_surface_handler_t
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:103
xvmc_vld_frame
void xvmc_vld_frame(struct vo_frame_s *this_gen)
xvmc_context_reader_lock
void xvmc_context_reader_lock(context_lock_t *c)
Definition video_out_xxmc.c:93
context_lock_t
struct context_lock_s context_lock_t
XVMC_MAX_SURFACES
#define XVMC_MAX_SURFACES
Definition xxmc.h:99