Mercurial > mplayer.hg
annotate vidix/vidixlib.c @ 5315:75092614a37d
UV vs VU fix
author | arpi |
---|---|
date | Sun, 24 Mar 2002 19:01:01 +0000 |
parents | b07e453a34d7 |
children | 02576893af2a |
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 | |
27 #include "vidixlib.h" | |
4539 | 28 #include "../bswap.h" |
3991 | 29 |
4011 | 30 static char drv_name[FILENAME_MAX]; |
3991 | 31 |
32 typedef struct vdl_stream_s | |
33 { | |
34 void * handle; | |
35 int (*get_caps)(vidix_capability_t *); | |
36 int (*query_fourcc)(vidix_fourcc_t *); | |
3995 | 37 int (*config_playback)(vidix_playback_t *); |
3991 | 38 int (*playback_on)( void ); |
39 int (*playback_off)( void ); | |
40 /* Functions below can be missed in driver ;) */ | |
41 int (*init)(void); | |
42 void (*destroy)(void); | |
43 int (*frame_sel)( unsigned frame_idx ); | |
44 int (*get_eq)( vidix_video_eq_t * ); | |
45 int (*set_eq)( const vidix_video_eq_t * ); | |
4191 | 46 int (*get_deint)( vidix_deinterlace_t * ); |
47 int (*set_deint)( const vidix_deinterlace_t * ); | |
3991 | 48 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
|
49 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
|
50 int (*set_gkey)( const vidix_grkey_t * ); |
4191 | 51 int (*get_num_fx)( unsigned * ); |
52 int (*get_fx)( vidix_oem_fx_t * ); | |
53 int (*set_fx)( const vidix_oem_fx_t * ); | |
3991 | 54 }vdl_stream_t; |
55 | |
56 #define t_vdl(p) (((vdl_stream_t *)p)) | |
57 | |
58 extern unsigned vdlGetVersion( void ) | |
59 { | |
60 return VIDIX_VERSION; | |
61 } | |
62 | |
63 static int vdl_fill_driver(VDL_HANDLE stream) | |
64 { | |
65 t_vdl(stream)->init = dlsym(t_vdl(stream)->handle,"vixInit"); | |
66 t_vdl(stream)->destroy = dlsym(t_vdl(stream)->handle,"vixDestroy"); | |
67 t_vdl(stream)->get_caps = dlsym(t_vdl(stream)->handle,"vixGetCapability"); | |
68 t_vdl(stream)->query_fourcc = dlsym(t_vdl(stream)->handle,"vixQueryFourcc"); | |
69 t_vdl(stream)->config_playback= dlsym(t_vdl(stream)->handle,"vixConfigPlayback"); | |
70 t_vdl(stream)->playback_on = dlsym(t_vdl(stream)->handle,"vixPlaybackOn"); | |
71 t_vdl(stream)->playback_off = dlsym(t_vdl(stream)->handle,"vixPlaybackOff"); | |
72 t_vdl(stream)->frame_sel = dlsym(t_vdl(stream)->handle,"vixPlaybackFrameSelect"); | |
73 t_vdl(stream)->get_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackGetEq"); | |
74 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
|
75 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
|
76 t_vdl(stream)->set_gkey = dlsym(t_vdl(stream)->handle,"vixSetGrKeys"); |
4191 | 77 t_vdl(stream)->get_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackGetDeint"); |
78 t_vdl(stream)->set_deint = dlsym(t_vdl(stream)->handle,"vixPlaybackSetDeint"); | |
3991 | 79 t_vdl(stream)->copy_frame = dlsym(t_vdl(stream)->handle,"vixPlaybackCopyFrame"); |
4191 | 80 t_vdl(stream)->get_num_fx = dlsym(t_vdl(stream)->handle,"vixQueryNumOemEffects"); |
81 t_vdl(stream)->get_fx = dlsym(t_vdl(stream)->handle,"vixGetOemEffect"); | |
82 t_vdl(stream)->set_fx = dlsym(t_vdl(stream)->handle,"vixSetOemEffect"); | |
3991 | 83 /* check driver viability */ |
3995 | 84 if(!( t_vdl(stream)->get_caps && t_vdl(stream)->query_fourcc && |
85 t_vdl(stream)->config_playback && t_vdl(stream)->playback_on && | |
86 t_vdl(stream)->playback_off)) | |
4011 | 87 { |
4509
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
88 printf("vidixlib: Incomplete driver: some of essential features are missed in it.\n"); |
4011 | 89 return 0; |
90 } | |
3991 | 91 return 1; |
92 } | |
93 | |
3995 | 94 static int vdl_probe_driver(VDL_HANDLE stream,const char *path,const char *name,unsigned cap,int verbose) |
3991 | 95 { |
96 vidix_capability_t vid_cap; | |
97 unsigned (*_ver)(void); | |
4191 | 98 int (*_probe)(int,int); |
3991 | 99 int (*_cap)(vidix_capability_t*); |
100 strcpy(drv_name,path); | |
101 strcat(drv_name,name); | |
4008 | 102 if(verbose) printf("vidixlib: PROBING: %s\n",drv_name); |
4011 | 103 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_LAZY|RTLD_GLOBAL))) |
104 { | |
4509
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
105 if(verbose) printf("vidixlib: %s not driver: %s\n",drv_name,dlerror()); |
4011 | 106 return 0; |
107 } | |
3991 | 108 _ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); |
109 _probe = dlsym(t_vdl(stream)->handle,"vixProbe"); | |
110 _cap = dlsym(t_vdl(stream)->handle,"vixGetCapability"); | |
4008 | 111 if(_ver) |
112 { | |
113 if((*_ver)() != VIDIX_VERSION) | |
114 { | |
115 if(verbose) printf("vidixlib: %s has wrong version\n",drv_name); | |
116 err: | |
117 dlclose(t_vdl(stream)->handle); | |
118 t_vdl(stream)->handle = 0; | |
119 return 0; | |
120 } | |
121 } | |
122 else | |
123 { | |
124 fatal_err: | |
125 if(verbose) printf("vidixlib: %s has no function definition\n",drv_name); | |
126 goto err; | |
127 } | |
4191 | 128 if(_probe) { if((*_probe)(verbose,PROBE_NORMAL) != 0) goto err; } |
4008 | 129 else goto fatal_err; |
3991 | 130 if(_cap) { if((*_cap)(&vid_cap) != 0) goto err; } |
4008 | 131 else goto fatal_err; |
4011 | 132 if((vid_cap.type & cap) != cap) |
133 { | |
134 if(verbose) printf("vidixlib: Found %s but has no required capability\n",drv_name); | |
135 goto err; | |
136 } | |
4008 | 137 if(verbose) printf("vidixlib: %s probed o'k\n",drv_name); |
3991 | 138 return 1; |
139 } | |
140 | |
3995 | 141 static int vdl_find_driver(VDL_HANDLE stream,const char *path,unsigned cap,int verbose) |
3991 | 142 { |
143 DIR *dstream; | |
144 struct dirent *name; | |
145 int done = 0; | |
146 if(!(dstream = opendir(path))) return 0; | |
147 while(!done) | |
148 { | |
149 name = readdir(dstream); | |
4008 | 150 if(name) |
151 { | |
152 if(name->d_name[0] != '.') | |
153 if(vdl_probe_driver(stream,path,name->d_name,cap,verbose)) break; | |
154 } | |
3991 | 155 else done = 1; |
156 } | |
157 closedir(dstream); | |
158 return done?0:1; | |
159 } | |
160 | |
3995 | 161 VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap,int verbose) |
3991 | 162 { |
163 vdl_stream_t *stream; | |
4011 | 164 int errcode; |
3991 | 165 if(!(stream = malloc(sizeof(vdl_stream_t)))) return NULL; |
166 memset(stream,0,sizeof(vdl_stream_t)); | |
167 if(name) | |
168 { | |
169 unsigned (*ver)(void); | |
4191 | 170 int (*probe)(int,int); |
3991 | 171 unsigned version = 0; |
172 strcpy(drv_name,path); | |
173 strcat(drv_name,name); | |
174 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL))) | |
175 { | |
4509
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
176 if (verbose) |
90386125ec1f
using dlerror() instead strerror(), displays unresolved symbol messages
alex
parents:
4191
diff
changeset
|
177 printf("vidixlib: dlopen error: %s\n", dlerror()); |
3991 | 178 err: |
179 free(stream); | |
180 return NULL; | |
181 } | |
182 ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); | |
183 if(ver) version = (*ver)(); | |
184 if(version != VIDIX_VERSION) | |
185 { | |
186 drv_err: | |
187 if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle); | |
188 goto err; | |
189 } | |
3995 | 190 probe = dlsym(t_vdl(stream)->handle,"vixProbe"); |
4191 | 191 if(probe) { if((*probe)(verbose,PROBE_FORCE)!=0) goto drv_err; } |
3995 | 192 else goto drv_err; |
3991 | 193 fill: |
194 if(!vdl_fill_driver(stream)) goto drv_err; | |
4011 | 195 goto ok; |
3991 | 196 } |
197 else | |
4011 | 198 if(vdl_find_driver(stream,path,cap,verbose)) |
199 { | |
200 if(verbose) printf("vidixlib: will use %s driver\n",drv_name); | |
201 goto fill; | |
202 } | |
203 else goto err; | |
204 ok: | |
205 if(t_vdl(stream)->init) | |
206 { | |
207 if(verbose) printf("vidixlib: Attempt to initialize driver at: %p\n",t_vdl(stream)->init); | |
208 if((errcode=t_vdl(stream)->init())!=0) | |
209 { | |
210 if(verbose) printf("vidixlib: Can't init driver: %s\n",strerror(errcode)); | |
211 goto drv_err; | |
212 } | |
213 } | |
214 if(verbose) printf("vidixlib: '%s'successfully loaded\n",drv_name); | |
3991 | 215 return stream; |
216 } | |
217 | |
218 void vdlClose(VDL_HANDLE stream) | |
219 { | |
220 if(t_vdl(stream)->destroy) t_vdl(stream)->destroy(); | |
221 dlclose(t_vdl(stream)->handle); | |
222 memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */ | |
223 free(stream); | |
224 } | |
225 | |
226 int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap) | |
227 { | |
228 return t_vdl(handle)->get_caps(cap); | |
229 } | |
230 | |
4539 | 231 #define MPLAYER_IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8)) |
232 #define MPLAYER_IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8)) | |
233 #define MPLAYER_IMGFMT_RGB_MASK 0xFFFFFF00 | |
234 | |
4547 | 235 static uint32_t normalize_fourcc(uint32_t fourcc) |
4539 | 236 { |
237 if((fourcc & MPLAYER_IMGFMT_RGB_MASK) == (MPLAYER_IMGFMT_RGB|0) || | |
238 (fourcc & MPLAYER_IMGFMT_RGB_MASK) == (MPLAYER_IMGFMT_BGR|0)) | |
239 return bswap_32(fourcc); | |
240 else return fourcc; | |
241 } | |
242 | |
3991 | 243 int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f) |
244 { | |
4547 | 245 f->fourcc = normalize_fourcc(f->fourcc); |
3991 | 246 return t_vdl(handle)->query_fourcc(f); |
247 } | |
248 | |
3995 | 249 int vdlConfigPlayback(VDL_HANDLE handle,vidix_playback_t *p) |
3991 | 250 { |
4547 | 251 p->fourcc = normalize_fourcc(p->fourcc); |
3991 | 252 return t_vdl(handle)->config_playback(p); |
253 } | |
254 | |
255 int vdlPlaybackOn(VDL_HANDLE handle) | |
256 { | |
257 return t_vdl(handle)->playback_on(); | |
258 } | |
259 | |
260 int vdlPlaybackOff(VDL_HANDLE handle) | |
261 { | |
262 return t_vdl(handle)->playback_off(); | |
263 } | |
264 | |
265 int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx ) | |
266 { | |
267 return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS; | |
268 } | |
269 | |
270 int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e) | |
271 { | |
272 return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS; | |
273 } | |
274 | |
275 int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e) | |
276 { | |
277 return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS; | |
278 } | |
279 | |
280 int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f) | |
281 { | |
282 return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS; | |
283 } | |
4070
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
284 |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
285 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
|
286 { |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
287 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
|
288 } |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
289 |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
290 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
|
291 { |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
292 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
|
293 } |
4191 | 294 |
295 int vdlPlaybackGetDeint(VDL_HANDLE handle, vidix_deinterlace_t * d) | |
296 { | |
297 return t_vdl(handle)->get_deint ? t_vdl(handle)->get_deint(d) : ENOSYS; | |
298 } | |
299 | |
300 int vdlPlaybackSetDeint(VDL_HANDLE handle, const vidix_deinterlace_t * d) | |
301 { | |
302 return t_vdl(handle)->set_deint ? t_vdl(handle)->set_deint(d) : ENOSYS; | |
303 } | |
304 | |
305 int vdlQueryNumOemEffects(VDL_HANDLE handle, unsigned * number ) | |
306 { | |
307 return t_vdl(handle)->get_num_fx ? t_vdl(handle)->get_num_fx(number) : ENOSYS; | |
308 } | |
309 | |
310 int vdlGetOemEffect(VDL_HANDLE handle, vidix_oem_fx_t * f) | |
311 { | |
312 return t_vdl(handle)->get_fx ? t_vdl(handle)->get_fx(f) : ENOSYS; | |
313 } | |
314 | |
315 int vdlSetOemEffect(VDL_HANDLE handle, const vidix_oem_fx_t * f) | |
316 { | |
317 return t_vdl(handle)->set_fx ? t_vdl(handle)->set_fx(f) : ENOSYS; | |
318 } |