Mercurial > mplayer.hg
annotate vidix/vidixlib.c @ 7242:8bafdfe945b4
document -vop halfpack
author | rfelker |
---|---|
date | Mon, 02 Sep 2002 03:21:03 +0000 |
parents | e9a309486f18 |
children | 285e298968de |
rev | line source |
---|---|
3991 | 1 /* |
2 * vidixlib.c | |
3 * VIDIXLib - Library for VIDeo Interface for *niX | |
4 * This interface is introduced as universal one to MPEG decoder, | |
5 * BES == Back End Scaler and YUV2RGB hw accelerators. | |
6 * In the future it may be expanded up to capturing and audio things. | |
7 * Main goal of this this interface imlpementation is providing DGA | |
8 * everywhere where it's possible (unlike X11 and other). | |
9 * Copyright 2002 Nick Kurshev | |
10 * Licence: GPL | |
11 * This interface is based on v4l2, fbvid.h, mga_vid.h projects | |
12 * and personally my ideas. | |
13 * NOTE: This interface is introduces as APP interface. | |
14 * Don't use it for driver. | |
15 * It provides multistreaming. This mean that APP can handle | |
16 * several streams simultaneously. (Example: Video capturing and video | |
17 * playback or capturing, video playback, audio encoding and so on). | |
18 */ | |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
21 #include <errno.h> | |
22 #include <string.h> | |
23 | |
24 #include <dlfcn.h> /* GLIBC specific. Exists under cygwin too! */ | |
25 #include <dirent.h> | |
26 | |
6130
e9a309486f18
openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents:
5872
diff
changeset
|
27 #if defined(__OpenBSD__) && !defined(__ELF__) |
e9a309486f18
openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents:
5872
diff
changeset
|
28 #define dlsym(h,s) dlsym(h, "_" s) |
e9a309486f18
openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents:
5872
diff
changeset
|
29 #endif |
e9a309486f18
openbsd a.out needs underscore for dlsym - patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
arpi
parents:
5872
diff
changeset
|
30 |
3991 | 31 #include "vidixlib.h" |
4539 | 32 #include "../bswap.h" |
3991 | 33 |
4011 | 34 static char drv_name[FILENAME_MAX]; |
3991 | 35 |
36 typedef struct vdl_stream_s | |
37 { | |
38 void * handle; | |
39 int (*get_caps)(vidix_capability_t *); | |
40 int (*query_fourcc)(vidix_fourcc_t *); | |
3995 | 41 int (*config_playback)(vidix_playback_t *); |
3991 | 42 int (*playback_on)( void ); |
43 int (*playback_off)( void ); | |
44 /* Functions below can be missed in driver ;) */ | |
45 int (*init)(void); | |
46 void (*destroy)(void); | |
47 int (*frame_sel)( unsigned frame_idx ); | |
48 int (*get_eq)( vidix_video_eq_t * ); | |
49 int (*set_eq)( const vidix_video_eq_t * ); | |
4191 | 50 int (*get_deint)( vidix_deinterlace_t * ); |
51 int (*set_deint)( const vidix_deinterlace_t * ); | |
3991 | 52 int (*copy_frame)( const vidix_dma_t * ); |
4070
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
53 int (*get_gkey)( vidix_grkey_t * ); |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
54 int (*set_gkey)( const vidix_grkey_t * ); |
4191 | 55 int (*get_num_fx)( unsigned * ); |
56 int (*get_fx)( vidix_oem_fx_t * ); | |
57 int (*set_fx)( const vidix_oem_fx_t * ); | |
3991 | 58 }vdl_stream_t; |
59 | |
60 #define t_vdl(p) (((vdl_stream_t *)p)) | |
61 | |
62 extern unsigned vdlGetVersion( void ) | |
63 { | |
64 return VIDIX_VERSION; | |
65 } | |
66 | |
67 static int vdl_fill_driver(VDL_HANDLE stream) | |
68 { | |
69 t_vdl(stream)->init = dlsym(t_vdl(stream)->handle,"vixInit"); | |
70 t_vdl(stream)->destroy = dlsym(t_vdl(stream)->handle,"vixDestroy"); | |
71 t_vdl(stream)->get_caps = dlsym(t_vdl(stream)->handle,"vixGetCapability"); | |
72 t_vdl(stream)->query_fourcc = dlsym(t_vdl(stream)->handle,"vixQueryFourcc"); | |
73 t_vdl(stream)->config_playback= dlsym(t_vdl(stream)->handle,"vixConfigPlayback"); | |
74 t_vdl(stream)->playback_on = dlsym(t_vdl(stream)->handle,"vixPlaybackOn"); | |
75 t_vdl(stream)->playback_off = dlsym(t_vdl(stream)->handle,"vixPlaybackOff"); | |
76 t_vdl(stream)->frame_sel = dlsym(t_vdl(stream)->handle,"vixPlaybackFrameSelect"); | |
77 t_vdl(stream)->get_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackGetEq"); | |
78 t_vdl(stream)->set_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackSetEq"); | |
4070
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
79 t_vdl(stream)->get_gkey = dlsym(t_vdl(stream)->handle,"vixGetGrKeys"); |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
80 t_vdl(stream)->set_gkey = dlsym(t_vdl(stream)->handle,"vixSetGrKeys"); |
4191 | 81 t_vdl(stream)->get_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackGetDeint"); |
82 t_vdl(stream)->set_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackSetDeint"); | |
3991 | 83 t_vdl(stream)->copy_frame = dlsym(t_vdl(stream)->handle,"vixPlaybackCopyFrame"); |
4191 | 84 t_vdl(stream)->get_num_fx = dlsym(t_vdl(stream)->handle,"vixQueryNumOemEffects"); |
85 t_vdl(stream)->get_fx = dlsym(t_vdl(stream)->handle,"vixGetOemEffect"); | |
86 t_vdl(stream)->set_fx = dlsym(t_vdl(stream)->handle,"vixSetOemEffect"); | |
3991 | 87 /* check driver viability */ |
3995 | 88 if(!( t_vdl(stream)->get_caps && t_vdl(stream)->query_fourcc && |
89 t_vdl(stream)->config_playback && t_vdl(stream)->playback_on && | |
90 t_vdl(stream)->playback_off)) | |
4011 | 91 { |
4509
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
92 printf("vidixlib: Incomplete driver: some of essential features are missed in it.\n"); |
4011 | 93 return 0; |
94 } | |
3991 | 95 return 1; |
96 } | |
97 | |
5872 | 98 #ifndef RTLD_GLOBAL |
99 #define RTLD_GLOBAL RTLD_LAZY | |
100 #endif | |
101 #ifndef RTLD_NOW | |
102 #define RTLD_NOW RTLD_LAZY | |
103 #endif | |
104 | |
3995 | 105 static int vdl_probe_driver(VDL_HANDLE stream,const char *path,const char *name,unsigned cap,int verbose) |
3991 | 106 { |
107 vidix_capability_t vid_cap; | |
108 unsigned (*_ver)(void); | |
4191 | 109 int (*_probe)(int,int); |
3991 | 110 int (*_cap)(vidix_capability_t*); |
111 strcpy(drv_name,path); | |
112 strcat(drv_name,name); | |
4008 | 113 if(verbose) printf("vidixlib: PROBING: %s\n",drv_name); |
4011 | 114 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_LAZY|RTLD_GLOBAL))) |
115 { | |
4509
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
116 if(verbose) printf("vidixlib: %s not driver: %s\n",drv_name,dlerror()); |
4011 | 117 return 0; |
118 } | |
3991 | 119 _ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); |
120 _probe = dlsym(t_vdl(stream)->handle,"vixProbe"); | |
121 _cap = dlsym(t_vdl(stream)->handle,"vixGetCapability"); | |
4008 | 122 if(_ver) |
123 { | |
124 if((*_ver)() != VIDIX_VERSION) | |
125 { | |
126 if(verbose) printf("vidixlib: %s has wrong version\n",drv_name); | |
127 err: | |
128 dlclose(t_vdl(stream)->handle); | |
129 t_vdl(stream)->handle = 0; | |
130 return 0; | |
131 } | |
132 } | |
133 else | |
134 { | |
135 fatal_err: | |
136 if(verbose) printf("vidixlib: %s has no function definition\n",drv_name); | |
137 goto err; | |
138 } | |
4191 | 139 if(_probe) { if((*_probe)(verbose,PROBE_NORMAL) != 0) goto err; } |
4008 | 140 else goto fatal_err; |
3991 | 141 if(_cap) { if((*_cap)(&vid_cap) != 0) goto err; } |
4008 | 142 else goto fatal_err; |
4011 | 143 if((vid_cap.type & cap) != cap) |
144 { | |
145 if(verbose) printf("vidixlib: Found %s but has no required capability\n",drv_name); | |
146 goto err; | |
147 } | |
4008 | 148 if(verbose) printf("vidixlib: %s probed o'k\n",drv_name); |
3991 | 149 return 1; |
150 } | |
151 | |
3995 | 152 static int vdl_find_driver(VDL_HANDLE stream,const char *path,unsigned cap,int verbose) |
3991 | 153 { |
154 DIR *dstream; | |
155 struct dirent *name; | |
156 int done = 0; | |
157 if(!(dstream = opendir(path))) return 0; | |
158 while(!done) | |
159 { | |
160 name = readdir(dstream); | |
4008 | 161 if(name) |
162 { | |
163 if(name->d_name[0] != '.') | |
164 if(vdl_probe_driver(stream,path,name->d_name,cap,verbose)) break; | |
165 } | |
3991 | 166 else done = 1; |
167 } | |
168 closedir(dstream); | |
169 return done?0:1; | |
170 } | |
171 | |
3995 | 172 VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap,int verbose) |
3991 | 173 { |
174 vdl_stream_t *stream; | |
4011 | 175 int errcode; |
3991 | 176 if(!(stream = malloc(sizeof(vdl_stream_t)))) return NULL; |
177 memset(stream,0,sizeof(vdl_stream_t)); | |
178 if(name) | |
179 { | |
180 unsigned (*ver)(void); | |
4191 | 181 int (*probe)(int,int); |
3991 | 182 unsigned version = 0; |
183 strcpy(drv_name,path); | |
184 strcat(drv_name,name); | |
185 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL))) | |
186 { | |
4509
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
187 if (verbose) |
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
188 printf("vidixlib: dlopen error: %s\n", dlerror()); |
3991 | 189 err: |
190 free(stream); | |
191 return NULL; | |
192 } | |
193 ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); | |
194 if(ver) version = (*ver)(); | |
195 if(version != VIDIX_VERSION) | |
196 { | |
197 drv_err: | |
198 if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle); | |
199 goto err; | |
200 } | |
3995 | 201 probe = dlsym(t_vdl(stream)->handle,"vixProbe"); |
4191 | 202 if(probe) { if((*probe)(verbose,PROBE_FORCE)!=0) goto drv_err; } |
3995 | 203 else goto drv_err; |
3991 | 204 fill: |
205 if(!vdl_fill_driver(stream)) goto drv_err; | |
4011 | 206 goto ok; |
3991 | 207 } |
208 else | |
4011 | 209 if(vdl_find_driver(stream,path,cap,verbose)) |
210 { | |
211 if(verbose) printf("vidixlib: will use %s driver\n",drv_name); | |
212 goto fill; | |
213 } | |
214 else goto err; | |
215 ok: | |
216 if(t_vdl(stream)->init) | |
217 { | |
218 if(verbose) printf("vidixlib: Attempt to initialize driver at: %p\n",t_vdl(stream)->init); | |
219 if((errcode=t_vdl(stream)->init())!=0) | |
220 { | |
221 if(verbose) printf("vidixlib: Can't init driver: %s\n",strerror(errcode)); | |
222 goto drv_err; | |
223 } | |
224 } | |
225 if(verbose) printf("vidixlib: '%s'successfully loaded\n",drv_name); | |
3991 | 226 return stream; |
227 } | |
228 | |
229 void vdlClose(VDL_HANDLE stream) | |
230 { | |
231 if(t_vdl(stream)->destroy) t_vdl(stream)->destroy(); | |
232 dlclose(t_vdl(stream)->handle); | |
233 memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */ | |
234 free(stream); | |
235 } | |
236 | |
237 int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap) | |
238 { | |
239 return t_vdl(handle)->get_caps(cap); | |
240 } | |
241 | |
4539 | 242 #define MPLAYER_IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8)) |
243 #define MPLAYER_IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8)) | |
244 #define MPLAYER_IMGFMT_RGB_MASK 0xFFFFFF00 | |
245 | |
4547 | 246 static uint32_t normalize_fourcc(uint32_t fourcc) |
4539 | 247 { |
248 if((fourcc & MPLAYER_IMGFMT_RGB_MASK) == (MPLAYER_IMGFMT_RGB|0) || | |
249 (fourcc & MPLAYER_IMGFMT_RGB_MASK) == (MPLAYER_IMGFMT_BGR|0)) | |
250 return bswap_32(fourcc); | |
251 else return fourcc; | |
252 } | |
253 | |
3991 | 254 int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f) |
255 { | |
4547 | 256 f->fourcc = normalize_fourcc(f->fourcc); |
3991 | 257 return t_vdl(handle)->query_fourcc(f); |
258 } | |
259 | |
3995 | 260 int vdlConfigPlayback(VDL_HANDLE handle,vidix_playback_t *p) |
3991 | 261 { |
4547 | 262 p->fourcc = normalize_fourcc(p->fourcc); |
3991 | 263 return t_vdl(handle)->config_playback(p); |
264 } | |
265 | |
266 int vdlPlaybackOn(VDL_HANDLE handle) | |
267 { | |
268 return t_vdl(handle)->playback_on(); | |
269 } | |
270 | |
271 int vdlPlaybackOff(VDL_HANDLE handle) | |
272 { | |
273 return t_vdl(handle)->playback_off(); | |
274 } | |
275 | |
276 int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx ) | |
277 { | |
278 return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS; | |
279 } | |
280 | |
281 int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e) | |
282 { | |
283 return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS; | |
284 } | |
285 | |
286 int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e) | |
287 { | |
288 return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS; | |
289 } | |
290 | |
291 int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f) | |
292 { | |
293 return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS; | |
294 } | |
4070
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
295 |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
296 int vdlGetGrKeys(VDL_HANDLE handle, vidix_grkey_t * k) |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
297 { |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
298 return t_vdl(handle)->get_gkey ? t_vdl(handle)->get_gkey(k) : ENOSYS; |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
299 } |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
300 |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
301 int vdlSetGrKeys(VDL_HANDLE handle, const vidix_grkey_t * k) |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
302 { |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
303 return t_vdl(handle)->set_gkey ? t_vdl(handle)->set_gkey(k) : ENOSYS; |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
304 } |
4191 | 305 |
306 int vdlPlaybackGetDeint(VDL_HANDLE handle, vidix_deinterlace_t * d) | |
307 { | |
308 return t_vdl(handle)->get_deint ? t_vdl(handle)->get_deint(d) : ENOSYS; | |
309 } | |
310 | |
311 int vdlPlaybackSetDeint(VDL_HANDLE handle, const vidix_deinterlace_t * d) | |
312 { | |
313 return t_vdl(handle)->set_deint ? t_vdl(handle)->set_deint(d) : ENOSYS; | |
314 } | |
315 | |
316 int vdlQueryNumOemEffects(VDL_HANDLE handle, unsigned * number ) | |
317 { | |
318 return t_vdl(handle)->get_num_fx ? t_vdl(handle)->get_num_fx(number) : ENOSYS; | |
319 } | |
320 | |
321 int vdlGetOemEffect(VDL_HANDLE handle, vidix_oem_fx_t * f) | |
322 { | |
323 return t_vdl(handle)->get_fx ? t_vdl(handle)->get_fx(f) : ENOSYS; | |
324 } | |
325 | |
326 int vdlSetOemEffect(VDL_HANDLE handle, const vidix_oem_fx_t * f) | |
327 { | |
328 return t_vdl(handle)->set_fx ? t_vdl(handle)->set_fx(f) : ENOSYS; | |
329 } |