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