audio: add af_lavrresample, remove old resampling filters
[mplayer.git] / TOOLS / realcodecs / cook.c
blob2e22e7fcf752ab9b06e5ee9748ccb9eec43f22e8
1 /*
2 * This is a small DLL that works as a wrapper for the actual realcook.so.6.0
3 * DLL from RealPlayer 8.0.
5 * This file is part of MPlayer.
7 * MPlayer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * MPlayer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 Assuming that RACloseCodec is the last call.
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <dlfcn.h>
31 #include <sys/time.h>
33 typedef unsigned long ulong;
35 ulong (*raCloseCodec)(ulong);
36 ulong (*raDecode)(ulong,ulong,ulong,ulong,ulong,ulong);
37 ulong (*raEncode)(ulong,ulong,ulong);
38 ulong (*raFlush)(ulong,ulong,ulong);
39 ulong (*raFreeDecoder)(ulong);
40 ulong (*raFreeEncoder)(ulong);
41 ulong (*raGetFlavorProperty)(ulong,ulong,ulong,ulong);
42 ulong (*raGetNumberOfFlavors)(void);
43 ulong (*raGetNumberOfFlavors2)(void);
44 ulong (*raInitDecoder)(ulong,ulong);
45 ulong (*raInitEncoder)(ulong,ulong);
46 ulong (*raOpenCodec)(ulong);
47 ulong (*raOpenCodec2)(ulong);
48 ulong (*raSetFlavor)(ulong,ulong);
49 void (*raSetDLLAccessPath)(ulong);
50 /* the following symbol will be _dlsym()ed by rarender.so,
51 but at least doesn't exist in cook.so
52 ulong (raSetPwd*)(ulong);
55 int b_dlOpened=0;
56 void *handle=NULL;
58 /* exits program when failure */
59 void loadSyms(void) {
60 fputs("loadSyms()\n", stderr);
61 if (!b_dlOpened) {
62 char *error;
64 // fputs("opening dll...\n");
65 handle = dlopen ("/usr/local/RealPlayer8/Codecs/realcook.so.6.0", RTLD_LAZY);
66 if (!handle) {
67 fputs (dlerror(), stderr);
68 exit(1);
71 raCloseCodec = dlsym(handle, "RACloseCodec");
72 if ((error = dlerror()) != NULL) {
73 fprintf (stderr, "dlsym(RACloseCodec): %s\n", error);
74 exit(1);
76 raDecode = dlsym(handle, "RADecode");
77 if ((error = dlerror()) != NULL) {
78 fprintf (stderr, "dlsym(RADecode): %s\n", error);
79 exit(1);
81 raEncode = dlsym(handle, "RAEncode");
82 if ((error = dlerror()) != NULL) {
83 fprintf (stderr, "dlsym(RAEncode): %s\n", error);
84 exit(1);
86 raFlush = dlsym(handle, "RAFlush");
87 if ((error = dlerror()) != NULL) {
88 fprintf (stderr, "dlsym(RAFlush): %s\n", error);
89 exit(1);
91 raFreeDecoder = dlsym(handle, "RAFreeDecoder");
92 if ((error = dlerror()) != NULL) {
93 fprintf (stderr, "dlsym(RAFreeDecoder): %s\n", error);
94 exit(1);
96 raFreeEncoder = dlsym(handle, "RAFreeEncoder");
97 if ((error = dlerror()) != NULL) {
98 fprintf (stderr, "dlsym(RAFreeEncoder): %s\n", error);
99 exit(1);
101 raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty");
102 if ((error = dlerror()) != NULL) {
103 fprintf (stderr, "dlsym(RAGetFlavorProperty): %s\n", error);
104 exit(1);
106 raGetNumberOfFlavors = dlsym(handle, "RAGetNumberOfFlavors");
107 if ((error = dlerror()) != NULL) {
108 fprintf (stderr, "dlsym(RAGetNumberOfFlavors): %s\n", error);
109 exit(1);
111 raGetNumberOfFlavors2 = dlsym(handle, "RAGetNumberOfFlavors2");
112 if ((error = dlerror()) != NULL) {
113 fprintf (stderr, "dlsym(RAGetNumberOfFlavors2): %s\n", error);
114 exit(1);
116 raInitDecoder = dlsym(handle, "RAInitDecoder");
117 if ((error = dlerror()) != NULL) {
118 fprintf (stderr, "dlsym(RAInitDecoder): %s\n", error);
119 exit(1);
121 raInitEncoder = dlsym(handle, "RAInitEncoder");
122 if ((error = dlerror()) != NULL) {
123 fprintf (stderr, "dlsym(RAInitEncoder): %s\n", error);
124 exit(1);
126 raOpenCodec = dlsym(handle, "RAOpenCodec");
127 if ((error = dlerror()) != NULL) {
128 fprintf (stderr, "dlsym(RAOpenCodec): %s\n", error);
129 exit(1);
131 raOpenCodec2 = dlsym(handle, "RAOpenCodec2");
132 if ((error = dlerror()) != NULL) {
133 fprintf (stderr, "dlsym(RAOpenCodec2): %s\n", error);
134 exit(1);
136 raSetFlavor = dlsym(handle, "RASetFlavor");
137 if ((error = dlerror()) != NULL) {
138 fprintf (stderr, "dlsym(RASetFlavor): %s\n", error);
139 exit(1);
141 raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath");
142 if ((error = dlerror()) != NULL) {
143 fprintf (stderr, "dlsym(SetDLLAccessPath): %s\n", error);
144 exit(1);
146 b_dlOpened=1;
150 void closeDll(void) {
151 if (handle) {
152 b_dlOpened=0;
153 dlclose(handle);
154 handle=NULL;
158 void _init(void) {
159 loadSyms();
162 struct timezone tz;
163 struct timeval tv1, tv2;
165 void tic(void) {
166 gettimeofday(&tv1, &tz);
169 void toc(void) {
170 long secs, usecs;
171 gettimeofday(&tv2, &tz);
172 secs=tv2.tv_sec-tv1.tv_sec;
173 usecs=tv2.tv_usec-tv1.tv_usec;
174 if (usecs<0) {
175 usecs+=1000000;
176 --secs;
178 fprintf(stderr, "Duration: %ld.%.6lds\n", secs, usecs);
182 void hexdump(void *pos, int len) {
183 unsigned char *cpos=pos, *cpos1;
184 int lines=(len+15)>>4;
185 while(lines--) {
186 int len1=len, i;
187 fprintf(stderr, "%0x ", cpos);
188 cpos1=cpos;
189 for (i=0;i<16;i++) {
190 if (len1>0) {
191 fprintf(stderr, "%02x ", *(cpos++));
192 } else {
193 fprintf(stderr, " ");
195 len1--;
197 fputs(" ", stderr);
198 cpos=cpos1;
199 for (i=0;i<16;i++) {
200 if (len>0) {
201 unsigned char ch=(*(cpos++));
202 if ((ch<32)||(ch>127)) ch='.';
203 fputc(ch, stderr);
205 len--;
207 fputs("\n", stderr);
209 fputc('\n', stderr);
213 ulong RACloseCodec(ulong p1) {
214 ulong result;
215 fprintf(stderr, "RACloseCodec(ulong p1=0x%0lx(%ld))\n", p1, p1);
216 result=(*raCloseCodec)(p1);
217 // closeDll();
218 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
219 return result;
222 static int pkno=0;
224 ulong RADecode(ulong p1,ulong p2,ulong p3,ulong p4,ulong* p5,ulong p6) {
225 ulong result;
226 int x,y;
228 fprintf(stderr, "RADecode(ulong ctx=0x%0lx, ", p1);
229 fprintf(stderr, "ulong src=0x%0lx,\n", p2);
230 fprintf(stderr, "ulong len=0x%0lx,", p3);
231 fprintf(stderr, "ulong dst=0x%0lx,\n", p4);
232 fprintf(stderr, "ulong dstcnt=0x%0lx, ",p5);
233 fprintf(stderr, "ulong p6=%ld)\n", p6);
234 // hexdump((void*)p1, 44);
235 // hexdump((void*)p2, p3);
236 // hexdump((void*)p4, 80);
237 // hexdump((void*)p5, 16);
238 // tic();
240 fprintf(stderr,"\n#CRC[%3d]",pkno++);
241 for(y=0;y<10;y++){
242 unsigned short crc=0;
243 unsigned char* p=p2;
244 p+=60*y;
245 for(x=0;x<60;x++){
246 crc+=p[x]<<(x&7);
248 fprintf(stderr," %04X",crc);
250 fprintf(stderr,"\n");
252 result=(*raDecode)(p1,p2,p3,p4,p5,p6);
253 // toc();
254 // hexdump((void*)p1, 44);
255 // hexdump((void*)p4, 80);
256 // hexdump((void*)p5, 16);
257 fprintf(stderr, "--> 0x%0lx(%ld) decoded: %ld \n\n\n", result, result, p5[0]);
258 return result;
261 ulong RAEncode(ulong p1,ulong p2,ulong p3) {
262 ulong result;
263 fprintf(stderr, "RAEncode(ulong p1=0x%0lx(%ld), ", p1, p1);
264 fprintf(stderr, "ulong p2=0x%0lx(%ld),\n", p2, p2);
265 fprintf(stderr, "ulong p3=0x%0lx(%ld))\n", p3, p3);
266 result=(*raEncode)(p1,p2,p3);
267 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
268 return result;
271 ulong RAFlush(ulong p1,ulong p2,ulong p3) {
272 ulong result;
273 fprintf(stderr, "RAFlush(ulong p1=0x%0lx(%ld), ", p1, p1);
274 fprintf(stderr, "ulong p2=0x%0lx(%ld),\n", p2, p2);
275 fprintf(stderr, "ulong p3=0x%0lx(%ld))\n", p3, p3);
276 result=(*raFlush)(p1,p2,p3);
277 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
278 return result;
281 ulong RAFreeDecoder(ulong p1) {
282 ulong result;
283 fprintf(stderr, "RAFreeDecoder(ulong p1=0x%0lx(%ld))\n", p1, p1);
284 hexdump((void*)p1, 44);
285 result=(*raFreeDecoder)(p1);
286 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
287 return result;
290 ulong RAFreeEncoder(ulong p1) {
291 ulong result;
292 fprintf(stderr, "RAFreeEncoder(ulong p1=0x%0lx(%ld))\n", p1, p1);
293 result=(*raFreeEncoder)(p1);
294 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
295 return result;
298 ulong RAGetFlavorProperty(ulong p1,ulong p2,ulong p3, ulong p4) {
299 ulong result;
300 fprintf(stderr, "RAGetFlavorProperty(ulong p1=0x%0lx(%ld), ", p1, p1);
301 fprintf(stderr, "ulong p2=0x%0lx(%ld),\n", p2, p2);
302 fprintf(stderr, "ulong p3=0x%0lx(%ld), ", p3, p3);
303 fprintf(stderr, "ulong p4=0x%0lx(%ld))\n", p4, p4);
304 hexdump((void*)p4/*(void*)(*((void**)p4))*/,p2);
305 hexdump((void*)p1, 44);
306 tic();
307 result=(*raGetFlavorProperty)(p1,p2,p3,p4);
308 toc();
309 fprintf(stderr, "*p4=0x%0lx\n", *((ulong*)p4));
310 hexdump((void*)p4/*(void*)(*((void**)p4))*/,p2);
311 hexdump((void*)p1, 44);
312 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
313 return result;
316 ulong RAGetNumberOfFlavors(void) {
317 ulong result;
318 fprintf(stderr, "RAGetNumberOfFlavors(void)\n");
319 result=(*raGetNumberOfFlavors)();
320 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
321 return result;
324 ulong RAGetNumberOfFlavors2(void) {
325 ulong result;
326 fprintf(stderr, "RAGetNumberOfFlavors2(void)\n");
327 result=(*raGetNumberOfFlavors2)();
328 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
329 return result;
332 ulong RAInitDecoder(ulong p1,ulong p2) {
333 ulong result;
334 int temp[256];
335 unsigned char temp2[256];
336 fprintf(stderr, "RAInitDecoder(ulong p1=0x%0lx(%ld), ", p1, p1);
337 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
338 hexdump((void*)p2, 4*7);
339 // hexdump((void*)p1, 44);
340 memset(temp,0x77,256*4);
341 memcpy(temp,p2,4*7);
342 hexdump((void*)temp[6], 32);
344 memset(temp2,0x77,256);
345 memcpy(temp2,temp[6],16);
346 temp[6]=temp2;
348 result=(*raInitDecoder)(p1,temp);
349 hexdump((void*)temp[6], 32);
350 // memcpy(p2,temp,4*11);
351 // hexdump((void*)p1, 44);
352 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
353 return result;
356 ulong RAInitEncoder(ulong p1,ulong p2) {
357 ulong result;
358 fprintf(stderr, "RAInitEncoder(ulong p1=0x%0lx(%ld), ", p1, p1);
359 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
360 result=(*raInitEncoder)(p1,p2);
361 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
362 return result;
365 ulong RAOpenCodec(ulong p1) {
366 ulong result;
367 // loadSyms();
368 fprintf(stderr, "RAOpenCodec(ulong p1=0x%0lx(%ld))\n", p1, p1);
369 result=(*raOpenCodec)(p1);
370 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
371 return result;
374 ulong RAOpenCodec2(ulong p1,ulong p2) {
375 ulong result;
376 // loadSyms();
377 fprintf(stderr, "RAOpenCodec2(ulong p1=0x%0lx(%ld), p2=%p)\n", p1, p1, p2);
378 hexdump((void*)p1, 44);
379 hexdump((void*)p2, 44);
380 result=(*raOpenCodec2)(p1);
381 hexdump((void*)p2, 44);
382 hexdump((void*)p1, 44);
383 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
384 return result;
387 ulong RASetFlavor(ulong p1,ulong p2) {
388 ulong result, numprop=0, result1=0;
389 ulong numflavors, flavor;
390 unsigned short property;
391 fprintf(stderr, "RASetFlavor(ulong p1=0x%0lx(%ld), ", p1, p1);
392 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
393 hexdump((void*)p1, 44);
394 hexdump((void*)p1, 44);
395 result=(*raSetFlavor)(p1,p2);
396 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
398 fputs("######################## FLAVOR PROPERTIES ###################\n\n", stderr);
399 numflavors=raGetNumberOfFlavors2();
400 flavor=0;
401 while (flavor<numflavors) {
402 fprintf(stderr, "************ Flavor %ld *************\n\n", flavor);
403 numprop=0;
404 while (numprop<32) {
405 result1=raGetFlavorProperty(p1, flavor, numprop, (ulong)&property);
406 fprintf(stderr, "property %ld=%d, result=0x%0lx\n\n",
407 numprop, property, result1);
408 hexdump((void*)result1, property);
409 numprop++;
411 flavor++;
414 fputs("######################## FLAVOR PROPERTIES ###################\n\n", stderr);
416 return result;
419 void SetDLLAccessPath(ulong p1) {
420 // loadSyms();
421 fprintf(stderr, "SetDLLAccessPath(ulong p1=0x%0lx(%ld))\n", p1, p1);
422 hexdump((void*)p1, 44);
423 (*raSetDLLAccessPath)(p1);
424 hexdump((void*)p1, 44);
425 fprintf(stderr, "--> void\n\n\n");