Mercurial > mplayer.hg
annotate vidix/vidixlib.c @ 4493:be41ab8c8918
code cleanup
author | nick |
---|---|
date | Sun, 03 Feb 2002 09:12:32 +0000 |
parents | 62a6135d090e |
children | 90386125ec1f |
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 { |
4191 | 87 printf("vidixlib: Incomplete driver: some 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 { | |
104 if(verbose) printf("vidixlib: %s not driver: %s\n",drv_name,strerror(errno)); | |
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 { | |
175 err: | |
176 free(stream); | |
177 return NULL; | |
178 } | |
179 ver = dlsym(t_vdl(stream)->handle,"vixGetVersion"); | |
180 if(ver) version = (*ver)(); | |
181 if(version != VIDIX_VERSION) | |
182 { | |
183 drv_err: | |
184 if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle); | |
185 goto err; | |
186 } | |
3995 | 187 probe = dlsym(t_vdl(stream)->handle,"vixProbe"); |
4191 | 188 if(probe) { if((*probe)(verbose,PROBE_FORCE)!=0) goto drv_err; } |
3995 | 189 else goto drv_err; |
3991 | 190 fill: |
191 if(!vdl_fill_driver(stream)) goto drv_err; | |
4011 | 192 goto ok; |
3991 | 193 } |
194 else | |
4011 | 195 if(vdl_find_driver(stream,path,cap,verbose)) |
196 { | |
197 if(verbose) printf("vidixlib: will use %s driver\n",drv_name); | |
198 goto fill; | |
199 } | |
200 else goto err; | |
201 ok: | |
202 if(t_vdl(stream)->init) | |
203 { | |
204 if(verbose) printf("vidixlib: Attempt to initialize driver at: %p\n",t_vdl(stream)->init); | |
205 if((errcode=t_vdl(stream)->init())!=0) | |
206 { | |
207 if(verbose) printf("vidixlib: Can't init driver: %s\n",strerror(errcode)); | |
208 goto drv_err; | |
209 } | |
210 } | |
211 if(verbose) printf("vidixlib: '%s'successfully loaded\n",drv_name); | |
3991 | 212 return stream; |
213 } | |
214 | |
215 void vdlClose(VDL_HANDLE stream) | |
216 { | |
217 if(t_vdl(stream)->destroy) t_vdl(stream)->destroy(); | |
218 dlclose(t_vdl(stream)->handle); | |
219 memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */ | |
220 free(stream); | |
221 } | |
222 | |
223 int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap) | |
224 { | |
225 return t_vdl(handle)->get_caps(cap); | |
226 } | |
227 | |
228 int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f) | |
229 { | |
230 return t_vdl(handle)->query_fourcc(f); | |
231 } | |
232 | |
3995 | 233 int vdlConfigPlayback(VDL_HANDLE handle,vidix_playback_t *p) |
3991 | 234 { |
235 return t_vdl(handle)->config_playback(p); | |
236 } | |
237 | |
238 int vdlPlaybackOn(VDL_HANDLE handle) | |
239 { | |
240 return t_vdl(handle)->playback_on(); | |
241 } | |
242 | |
243 int vdlPlaybackOff(VDL_HANDLE handle) | |
244 { | |
245 return t_vdl(handle)->playback_off(); | |
246 } | |
247 | |
248 int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx ) | |
249 { | |
250 return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS; | |
251 } | |
252 | |
253 int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e) | |
254 { | |
255 return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS; | |
256 } | |
257 | |
258 int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e) | |
259 { | |
260 return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS; | |
261 } | |
262 | |
263 int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f) | |
264 { | |
265 return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS; | |
266 } | |
4070
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
267 |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
268 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
|
269 { |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
270 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
|
271 } |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
272 |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
273 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
|
274 { |
b61ba6c256dd
Minor interface changes: color and video keys are moved out from playback configuring
nick
parents:
4011
diff
changeset
|
275 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
|
276 } |
4191 | 277 |
278 int vdlPlaybackGetDeint(VDL_HANDLE handle, vidix_deinterlace_t * d) | |
279 { | |
280 return t_vdl(handle)->get_deint ? t_vdl(handle)->get_deint(d) : ENOSYS; | |
281 } | |
282 | |
283 int vdlPlaybackSetDeint(VDL_HANDLE handle, const vidix_deinterlace_t * d) | |
284 { | |
285 return t_vdl(handle)->set_deint ? t_vdl(handle)->set_deint(d) : ENOSYS; | |
286 } | |
287 | |
288 int vdlQueryNumOemEffects(VDL_HANDLE handle, unsigned * number ) | |
289 { | |
290 return t_vdl(handle)->get_num_fx ? t_vdl(handle)->get_num_fx(number) : ENOSYS; | |
291 } | |
292 | |
293 int vdlGetOemEffect(VDL_HANDLE handle, vidix_oem_fx_t * f) | |
294 { | |
295 return t_vdl(handle)->get_fx ? t_vdl(handle)->get_fx(f) : ENOSYS; | |
296 } | |
297 | |
298 int vdlSetOemEffect(VDL_HANDLE handle, const vidix_oem_fx_t * f) | |
299 { | |
300 return t_vdl(handle)->set_fx ? t_vdl(handle)->set_fx(f) : ENOSYS; | |
301 } |