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 * );
|
|
45 int (*copy_frame)( const vidix_dma_t * );
|
|
46 }vdl_stream_t;
|
|
47
|
|
48 #define t_vdl(p) (((vdl_stream_t *)p))
|
|
49
|
|
50 extern unsigned vdlGetVersion( void )
|
|
51 {
|
|
52 return VIDIX_VERSION;
|
|
53 }
|
|
54
|
|
55 static int vdl_fill_driver(VDL_HANDLE stream)
|
|
56 {
|
|
57 t_vdl(stream)->init = dlsym(t_vdl(stream)->handle,"vixInit");
|
|
58 t_vdl(stream)->destroy = dlsym(t_vdl(stream)->handle,"vixDestroy");
|
|
59 t_vdl(stream)->get_caps = dlsym(t_vdl(stream)->handle,"vixGetCapability");
|
|
60 t_vdl(stream)->query_fourcc = dlsym(t_vdl(stream)->handle,"vixQueryFourcc");
|
|
61 t_vdl(stream)->config_playback= dlsym(t_vdl(stream)->handle,"vixConfigPlayback");
|
|
62 t_vdl(stream)->playback_on = dlsym(t_vdl(stream)->handle,"vixPlaybackOn");
|
|
63 t_vdl(stream)->playback_off = dlsym(t_vdl(stream)->handle,"vixPlaybackOff");
|
|
64 t_vdl(stream)->frame_sel = dlsym(t_vdl(stream)->handle,"vixPlaybackFrameSelect");
|
|
65 t_vdl(stream)->get_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackGetEq");
|
|
66 t_vdl(stream)->set_eq = dlsym(t_vdl(stream)->handle,"vixPlaybackSetEq");
|
|
67 t_vdl(stream)->copy_frame = dlsym(t_vdl(stream)->handle,"vixPlaybackCopyFrame");
|
|
68 /* check driver viability */
|
3995
|
69 if(!( t_vdl(stream)->get_caps && t_vdl(stream)->query_fourcc &&
|
|
70 t_vdl(stream)->config_playback && t_vdl(stream)->playback_on &&
|
|
71 t_vdl(stream)->playback_off))
|
4011
|
72 {
|
|
73 printf("vidixlib: some features are missed in driver\n");
|
|
74 return 0;
|
|
75 }
|
3991
|
76 return 1;
|
|
77 }
|
|
78
|
3995
|
79 static int vdl_probe_driver(VDL_HANDLE stream,const char *path,const char *name,unsigned cap,int verbose)
|
3991
|
80 {
|
|
81 vidix_capability_t vid_cap;
|
|
82 unsigned (*_ver)(void);
|
3995
|
83 int (*_probe)(int);
|
3991
|
84 int (*_cap)(vidix_capability_t*);
|
|
85 strcpy(drv_name,path);
|
|
86 strcat(drv_name,name);
|
4008
|
87 if(verbose) printf("vidixlib: PROBING: %s\n",drv_name);
|
4011
|
88 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_LAZY|RTLD_GLOBAL)))
|
|
89 {
|
|
90 if(verbose) printf("vidixlib: %s not driver: %s\n",drv_name,strerror(errno));
|
|
91 return 0;
|
|
92 }
|
3991
|
93 _ver = dlsym(t_vdl(stream)->handle,"vixGetVersion");
|
|
94 _probe = dlsym(t_vdl(stream)->handle,"vixProbe");
|
|
95 _cap = dlsym(t_vdl(stream)->handle,"vixGetCapability");
|
4008
|
96 if(_ver)
|
|
97 {
|
|
98 if((*_ver)() != VIDIX_VERSION)
|
|
99 {
|
|
100 if(verbose) printf("vidixlib: %s has wrong version\n",drv_name);
|
|
101 err:
|
|
102 dlclose(t_vdl(stream)->handle);
|
|
103 t_vdl(stream)->handle = 0;
|
|
104 return 0;
|
|
105 }
|
|
106 }
|
|
107 else
|
|
108 {
|
|
109 fatal_err:
|
|
110 if(verbose) printf("vidixlib: %s has no function definition\n",drv_name);
|
|
111 goto err;
|
|
112 }
|
3995
|
113 if(_probe) { if((*_probe)(verbose) != 0) goto err; }
|
4008
|
114 else goto fatal_err;
|
3991
|
115 if(_cap) { if((*_cap)(&vid_cap) != 0) goto err; }
|
4008
|
116 else goto fatal_err;
|
4011
|
117 if((vid_cap.type & cap) != cap)
|
|
118 {
|
|
119 if(verbose) printf("vidixlib: Found %s but has no required capability\n",drv_name);
|
|
120 goto err;
|
|
121 }
|
4008
|
122 if(verbose) printf("vidixlib: %s probed o'k\n",drv_name);
|
3991
|
123 return 1;
|
|
124 }
|
|
125
|
3995
|
126 static int vdl_find_driver(VDL_HANDLE stream,const char *path,unsigned cap,int verbose)
|
3991
|
127 {
|
|
128 DIR *dstream;
|
|
129 struct dirent *name;
|
|
130 int done = 0;
|
|
131 if(!(dstream = opendir(path))) return 0;
|
|
132 while(!done)
|
|
133 {
|
|
134 name = readdir(dstream);
|
4008
|
135 if(name)
|
|
136 {
|
|
137 if(name->d_name[0] != '.')
|
|
138 if(vdl_probe_driver(stream,path,name->d_name,cap,verbose)) break;
|
|
139 }
|
3991
|
140 else done = 1;
|
|
141 }
|
|
142 closedir(dstream);
|
|
143 return done?0:1;
|
|
144 }
|
|
145
|
3995
|
146 VDL_HANDLE vdlOpen(const char *path,const char *name,unsigned cap,int verbose)
|
3991
|
147 {
|
|
148 vdl_stream_t *stream;
|
4011
|
149 int errcode;
|
3991
|
150 if(!(stream = malloc(sizeof(vdl_stream_t)))) return NULL;
|
|
151 memset(stream,0,sizeof(vdl_stream_t));
|
|
152 if(name)
|
|
153 {
|
|
154 unsigned (*ver)(void);
|
3995
|
155 int (*probe)(int);
|
3991
|
156 unsigned version = 0;
|
|
157 strcpy(drv_name,path);
|
|
158 strcat(drv_name,name);
|
|
159 if(!(t_vdl(stream)->handle = dlopen(drv_name,RTLD_NOW|RTLD_GLOBAL)))
|
|
160 {
|
|
161 err:
|
|
162 free(stream);
|
|
163 return NULL;
|
|
164 }
|
|
165 ver = dlsym(t_vdl(stream)->handle,"vixGetVersion");
|
|
166 if(ver) version = (*ver)();
|
|
167 if(version != VIDIX_VERSION)
|
|
168 {
|
|
169 drv_err:
|
|
170 if(t_vdl(stream)->handle) dlclose(t_vdl(stream)->handle);
|
|
171 goto err;
|
|
172 }
|
3995
|
173 probe = dlsym(t_vdl(stream)->handle,"vixProbe");
|
|
174 if(probe) { if((*probe)(verbose)!=0) goto drv_err; }
|
|
175 else goto drv_err;
|
3991
|
176 fill:
|
|
177 if(!vdl_fill_driver(stream)) goto drv_err;
|
4011
|
178 goto ok;
|
3991
|
179 }
|
|
180 else
|
4011
|
181 if(vdl_find_driver(stream,path,cap,verbose))
|
|
182 {
|
|
183 if(verbose) printf("vidixlib: will use %s driver\n",drv_name);
|
|
184 goto fill;
|
|
185 }
|
|
186 else goto err;
|
|
187 ok:
|
|
188 if(t_vdl(stream)->init)
|
|
189 {
|
|
190 if(verbose) printf("vidixlib: Attempt to initialize driver at: %p\n",t_vdl(stream)->init);
|
|
191 if((errcode=t_vdl(stream)->init())!=0)
|
|
192 {
|
|
193 if(verbose) printf("vidixlib: Can't init driver: %s\n",strerror(errcode));
|
|
194 goto drv_err;
|
|
195 }
|
|
196 }
|
|
197 if(verbose) printf("vidixlib: '%s'successfully loaded\n",drv_name);
|
3991
|
198 return stream;
|
|
199 }
|
|
200
|
|
201 void vdlClose(VDL_HANDLE stream)
|
|
202 {
|
|
203 if(t_vdl(stream)->destroy) t_vdl(stream)->destroy();
|
|
204 dlclose(t_vdl(stream)->handle);
|
|
205 memset(stream,0,sizeof(vdl_stream_t)); /* <- it's not stupid */
|
|
206 free(stream);
|
|
207 }
|
|
208
|
|
209 int vdlGetCapability(VDL_HANDLE handle, vidix_capability_t *cap)
|
|
210 {
|
|
211 return t_vdl(handle)->get_caps(cap);
|
|
212 }
|
|
213
|
|
214 int vdlQueryFourcc(VDL_HANDLE handle,vidix_fourcc_t *f)
|
|
215 {
|
|
216 return t_vdl(handle)->query_fourcc(f);
|
|
217 }
|
|
218
|
3995
|
219 int vdlConfigPlayback(VDL_HANDLE handle,vidix_playback_t *p)
|
3991
|
220 {
|
|
221 return t_vdl(handle)->config_playback(p);
|
|
222 }
|
|
223
|
|
224 int vdlPlaybackOn(VDL_HANDLE handle)
|
|
225 {
|
|
226 return t_vdl(handle)->playback_on();
|
|
227 }
|
|
228
|
|
229 int vdlPlaybackOff(VDL_HANDLE handle)
|
|
230 {
|
|
231 return t_vdl(handle)->playback_off();
|
|
232 }
|
|
233
|
|
234 int vdlPlaybackFrameSelect(VDL_HANDLE handle, unsigned frame_idx )
|
|
235 {
|
|
236 return t_vdl(handle)->frame_sel ? t_vdl(handle)->frame_sel(frame_idx) : ENOSYS;
|
|
237 }
|
|
238
|
|
239 int vdlPlaybackGetEq(VDL_HANDLE handle, vidix_video_eq_t * e)
|
|
240 {
|
|
241 return t_vdl(handle)->get_eq ? t_vdl(handle)->get_eq(e) : ENOSYS;
|
|
242 }
|
|
243
|
|
244 int vdlPlaybackSetEq(VDL_HANDLE handle, const vidix_video_eq_t * e)
|
|
245 {
|
|
246 return t_vdl(handle)->set_eq ? t_vdl(handle)->set_eq(e) : ENOSYS;
|
|
247 }
|
|
248
|
|
249 int vdlPlaybackCopyFrame(VDL_HANDLE handle, const vidix_dma_t * f)
|
|
250 {
|
|
251 return t_vdl(handle)->copy_frame ? t_vdl(handle)->copy_frame(f) : ENOSYS;
|
|
252 }
|