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