Remove trailing whitespace from most files
[mplayer/glamo.git] / TOOLS / realcodecs / drv2.c
blob278188afeaa03d64d036b5f6e8e5ba2e59619e64
1 /*
2 * This is a small DLL that works as a wrapper for the actual realdrv2.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 (*rvyuvCustomMessage)(ulong,ulong);
36 ulong (*rvyuvFree)(ulong);
37 ulong (*rvyuvHiveMessage)(ulong,ulong);
38 ulong (*rvyuvInit)(ulong,ulong);
39 ulong (*rvyuvTransform)(ulong,ulong,ulong,ulong,ulong);
40 ulong (*rvyuvRNFRUFree)(ulong);
41 ulong (*rvyuvRNFRUGetFrame)(ulong,ulong,ulong);
42 ulong (*rvyuvRNFRUInit)(ulong,ulong,ulong);
43 ulong (*rvyuvRNFRUSetup)(ulong,ulong,ulong,ulong,ulong,ulong,ulong,ulong);
45 //void (*setDLLAccessPath)(ulong);
47 int b_dlOpened=0;
48 void *handle=NULL;
50 /* exits program when failure */
51 void loadSyms(void) {
52 fputs("loadSyms()\n", stderr);
53 if (!b_dlOpened) {
54 char *error;
56 fputs("opening dll...\n",stderr);
57 handle = dlopen ("/usr/local/RealPlayer8/Codecs/realdrv2.so.6.0", RTLD_LAZY);
58 if (!handle) {
59 fputs (dlerror(), stderr);
60 exit(1);
63 rvyuvCustomMessage = dlsym(handle, "RV20toYUV420CustomMessage");
64 if ((error = dlerror()) != NULL) {
65 fprintf (stderr, "dlsym(rvyuvCustomMessage): %s\n", error);
66 exit(1);
68 fprintf(stderr, "RV20toYUV420CustomMessage()=0x%0x\n", rvyuvCustomMessage);
69 rvyuvFree = dlsym(handle, "RV20toYUV420Free");
70 if ((error = dlerror()) != NULL) {
71 fprintf (stderr, "dlsym(rvyuvFree): %s\n", error);
72 exit(1);
74 fprintf(stderr, "RV20toYUV420Free()=0x%0x\n", rvyuvFree);
75 rvyuvHiveMessage = dlsym(handle, "RV20toYUV420HiveMessage");
76 if ((error = dlerror()) != NULL) {
77 fprintf (stderr, "dlsym(rvyuvHiveMessage): %s\n", error);
78 exit(1);
80 fprintf(stderr, "RV20toYUV420HiveMessage()=0x%0x\n", rvyuvHiveMessage);
81 rvyuvInit = dlsym(handle, "RV20toYUV420Init");
82 if ((error = dlerror()) != NULL) {
83 fprintf (stderr, "dlsym(rvyuvInit): %s\n", error);
84 exit(1);
86 fprintf(stderr, "RV20toYUV420Init()=0x%0x\n", rvyuvInit);
87 rvyuvTransform = dlsym(handle, "RV20toYUV420Transform");
88 if ((error = dlerror()) != NULL) {
89 fprintf (stderr, "dlsym(rvyuvTransform): %s\n", error);
90 exit(1);
92 fprintf(stderr, "RV20toYUV420Transform()=0x%0x\n", rvyuvTransform);
93 rvyuvRNFRUFree = dlsym(handle, "RV20toYUV420_RN_FRU_Free");
94 if ((error = dlerror()) != NULL) {
95 fprintf (stderr, "dlsym(rvyuvRNFRUFree): %s\n", error);
96 exit(1);
98 fprintf(stderr, "RV20toYUV420_RN_FRU_Free()=0x%0x\n", rvyuvRNFRUFree);
99 rvyuvRNFRUGetFrame = dlsym(handle, "RV20toYUV420_RN_FRU_GetFrame");
100 if ((error = dlerror()) != NULL) {
101 fprintf (stderr, "dlsym(rvyuvRNFRUGetFrame): %s\n", error);
102 exit(1);
104 fprintf(stderr, "RV20toYUV420_RN_FRU_GetFrame()=0x%0x\n", rvyuvRNFRUGetFrame);
105 rvyuvRNFRUInit = dlsym(handle, "RV20toYUV420_RN_FRU_Init");
106 if ((error = dlerror()) != NULL) {
107 fprintf (stderr, "dlsym(rvyuvRNFRUInit): %s\n", error);
108 exit(1);
110 fprintf(stderr, "RV20toYUV420_RN_FRU_Init()=0x%0x\n", rvyuvRNFRUInit);
111 rvyuvRNFRUSetup = dlsym(handle, "RV20toYUV420_RN_FRU_Setup");
112 if ((error = dlerror()) != NULL) {
113 fprintf (stderr, "dlsym(rvyuvRNFRUSetup): %s\n", error);
114 exit(1);
116 fprintf(stderr, "RV20toYUV420_RN_FRU_Setup()=0x%0x\n", rvyuvRNFRUSetup);
118 /* setDLLAccessPath = dlsym(handle, "SetDLLAccessPath");
119 if ((error = dlerror()) != NULL) {
120 fprintf (stderr, "dlsym(SetDLLAccessPath): %s\n", error);
121 exit(1);
123 */ b_dlOpened=1;
127 void closeDll(void) {
128 if (handle) {
129 b_dlOpened=0;
130 dlclose(handle);
131 handle=NULL;
135 void _init(void) {
136 loadSyms();
139 struct timezone tz;
140 struct timeval tv1, tv2;
142 void tic(void) {
143 gettimeofday(&tv1, &tz);
146 void toc(void) {
147 long secs, usecs;
148 gettimeofday(&tv2, &tz);
149 secs=tv2.tv_sec-tv1.tv_sec;
150 usecs=tv2.tv_usec-tv1.tv_usec;
151 if (usecs<0) {
152 usecs+=1000000;
153 --secs;
155 // fprintf(stderr, "Duration: %ld.%.6lds\n", secs, usecs);
159 static void hexdump(void *pos, int len) {
160 unsigned char *cpos=pos, *cpos1;
161 int lines=(len+15)>>4;
162 while(lines--) {
163 int len1=len, i;
164 fprintf(stderr, "#R# %0x ", (int)cpos-(int)pos);
165 cpos1=cpos;
166 for (i=0;i<16;i++) {
167 if (len1>0) {
168 fprintf(stderr, "%02x ", *(cpos++));
169 } else {
170 fprintf(stderr, " ");
172 len1--;
174 fputs(" ", stderr);
175 cpos=cpos1;
176 for (i=0;i<16;i++) {
177 if (len>0) {
178 unsigned char ch=(*(cpos++));
179 if ((ch<32)||(ch>127)) ch='.';
180 fputc(ch, stderr);
182 len--;
184 fputs("\n", stderr);
186 fputc('\n', stderr);
190 ulong RV20toYUV420CustomMessage(ulong* p1,ulong p2) {
191 ulong result;
192 // ulong *pp1=p1;
193 ulong temp[16];
194 fprintf(stderr, "#R# => RV20toYUV420CustomMessage(%p,%p) [%ld,%ld,%ld] \n", p1, p2, p1[0],p1[1],p1[2]);
197 if(p1[0]!=17) return 0;
199 if(p1[1]!=1) return 0;
201 if(p1[0]==105) return 0;
202 if(p1[0]==3) return 0;
203 if(p1[0]==18) return 0;
204 if(p1[0]==30) return 0;
207 if(p1[0]==0x24){
208 #if 1
209 hexdump(p1[2],64);
210 memset(temp,0x77,16*4);
211 memcpy(temp,p1[2],16);
212 p1[2]=temp;
213 #endif
214 } else {
215 switch(p1[0]){
216 case 17:
217 if(p1[1]==1)
218 break;
219 case 18:
220 case 30:
221 case 3:
222 default:
223 return 0;
226 // fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
227 // hexdump((void*)p1, 12);
228 // if (pp1[0]==0x24) {
229 // hexdump((void*)(pp1[2]),128);
230 // }
231 // tic();
232 result=(*rvyuvCustomMessage)(p1,p2);
233 // toc();
234 fprintf(stderr, "#R# <= RV20toYUV420CustomMessage --> 0x%0lx(%ld)\n", result, result);
235 return result;
238 ulong RV20toYUV420Free(ulong p1) {
239 ulong result;
240 fprintf(stderr, "RV20toYUV420Free(ulong p1=0x%0lx(%ld))\n", p1, p1);
241 // hexdump((void*)p1, 44);
242 tic();
243 result=(*rvyuvFree)(p1);
244 toc();
245 // hexdump((void*)p1, 44);
246 fprintf(stderr, "RV20toYUV420Free --> 0x%0lx(%ld)\n\n\n", result, result);
247 return result;
250 char h_temp[32768];
252 ulong RV20toYUV420HiveMessage(ulong *p1,ulong p2) {
253 ulong result;
254 fprintf(stderr, "#R# RV20toYUV420HiveMessage(%p,%p)\n", p1, p2);
255 // p1->constant,p1->width,p1->height,p1->format1,p1->format2);
256 // fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
257 // hexdump((void*)p1, sizeof(struct init_data));
259 fprintf(stderr,">HIVE %ld %p\n",p1[0],p1[1]);
261 if(p1[0]!=0) return 0;
263 p1[1]=0x10000000;
264 return 0;
266 // fprintf(stderr,"COPY INIT DATA!\n");
267 memset(h_temp,0x77,1000);
268 memcpy(h_temp,p1,4);
269 // fprintf(stderr,"COPY OK!\n");
271 // tic();
272 // result=(*rvyuvHiveMessage)(p1,p2);
273 result=(*rvyuvHiveMessage)(h_temp,p2);
274 // toc();
276 fprintf(stderr,"COPY INIT DATA!\n");
277 memcpy(p1,h_temp,8);
278 fprintf(stderr,"COPY OK!\n");
280 memset(h_temp,0x77,1000);
282 // p1[0]=0;
283 // p1[1]=0x20000000;
285 fprintf(stderr,"<HIVE %ld %p\n",p1[0],p1[1]);
287 // hexdump((void*)p1, sizeof(struct init_data));
288 // hexdump((void*)p1, 8);
289 fprintf(stderr, "#R# RV20toYUV420HiveMessage --> 0x%0lx(%ld)\n\n", result, result);
290 return result;
293 struct init_data {
294 short constant; //=0xb;
295 short width, height;
296 short x1,x2,x3;
297 // 12
298 ulong format1;
299 long x4;
300 ulong format2;
301 // long unknown[32];
304 static char i_temp[32768];
306 ulong RV20toYUV420Init(ulong p1,ulong p2) {
307 ulong result;
308 fprintf(stderr, "#R# RV20toYUV420Init(ulong p1=0x%0lx(%ld), ", p1, p1);
309 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
311 fprintf(stderr,"COPY INIT DATA!\n");
312 memcpy(i_temp,p1,24);
313 p1=i_temp;
314 fprintf(stderr,"COPY OK!\n");
316 hexdump((void*)p1, 24);
317 tic();
318 result=(*rvyuvInit)(p1,p2);
319 toc();
320 hexdump((void*)p1, 24);
322 memset(i_temp,0x77,1000);
324 // hexdump(*((void**)p2), 512);
325 fprintf(stderr, "#R# RV20toYUV420Init --> 0x%0lx(%ld)\n\n\n", result, result);
326 return result;
329 unsigned long build_crc(unsigned char *pch, unsigned long len) {
330 unsigned long crc=0, a;
331 // unsigned long b;
332 // it's not the real crc function, but so what...
333 while (len--) {
334 a=*(pch++);
335 // a=a+(a<<6);
336 // a^=0x555;
337 // b=(crc>>29)&7;
338 // crc=((crc<<3)+b)^a;
339 crc^=a;
341 return crc;
344 #define MIN(a,b) ((a)<(b)?(a):(b))
346 // p1=input data (stream)
347 // p2=output buffer
348 // p3=input struct
349 // p4=output struct
350 // p5=rvyuv_main
351 ulong RV20toYUV420Transform(ulong p1,ulong p2,ulong p3,ulong p4,ulong p5) {
353 //result=RV20toYUV420Transform(char *input_stream, char *output_data,
354 // struct transin *, struct transout *, struct rvyuvMain *);
356 ulong result;
357 ulong *pp3=p3;
358 ulong *pp4=p4;
359 void *v;
360 ulong temp[128];
361 int i;
363 unsigned long crc_src, crc0;
364 // unsigned long len, crc1, crc2;
365 unsigned char *pch=(char *)p1;
366 fprintf(stderr, "#R# RV20toYUV420Transform(in=%p,out=%p,tin=%p,tout=%p,yuv=%p)\n",p1,p2,p3,p4,p5);
367 // input data, length=*p3
368 // hexdump((void*)p1, /*MIN(64,*/ *((ulong*)p3) /*)*/ );
369 // v=p5;
370 // v+=0x3c;
371 // v=*((void **)v);
372 // pp3=v;
373 // len=pp3[3]*pp3[4]*3/2;
374 // pch=p2;
375 // while(--len) *(pch++)=0;
376 // hexdump((char*)p2, 64);
377 // hexdump((void*)p3, 32);
378 // hexdump((void*)p5, 64);
379 // pp3=p3;
380 // if (pp3[3]>1024) {
381 // hexdump((void*)(pp3[3]),32);
382 // pp3=pp3[3];
383 // }
385 pp3=p3;
386 // it's not the real crc function, but so what...
387 pch=p1;
388 crc_src=build_crc(pch, pp3[0]);
390 pp4=pp3[3];
391 fprintf(stderr,"transin1[%p]: {%ld/%ld} ",pp4,pp3[2],pp3[0]);
392 // pp4[0],pp4[1],pp4[2],pp4[3],
393 // pp4[4],pp4[5],pp4[6],pp4[7]);
395 memset(temp,0x77,128*4);
397 memcpy(temp,pp4,8*(pp3[2]+1));
398 for(i=0;i<=pp3[2];i++){
399 fprintf(stderr," %p(%ld)",temp[i*2],temp[i*2+1]);
401 fprintf(stderr,"\n");
404 pp3[3]=pp4=temp;
406 // pp4[2]=
407 // pp4[3]=
408 // pp4[4]=NULL;
410 //pp4[6]=pp4[5];
412 v=p5;
413 /* fprintf(stderr, "rvyuvMain=0x%0x\n", v);
414 v+=0x3c;
415 v=*((void **)v);
416 fprintf(stderr, "[$+3ch]=0x%0x\n", v);
417 hexdump(v, 512);
418 v+=0x60;
419 v=*((void **)v);
420 fprintf(stderr, "[$+60h]=0x%0x\n", v);
421 hexdump(v, 512);
422 v+=0x28;
423 v=*((void **)v);
424 fprintf(stderr, "[$+28h]=0x%0x\n", v);
425 hexdump(v, 512);
427 /* v+=0x178;
428 hexdump(v, 16);
429 v=*((void **)v);
430 if (v>0x8000000) {
431 fprintf(stderr, "[$+178h]=0x%0x\n", v);
432 hexdump(v, 128);
435 // tic();
436 result=(*rvyuvTransform)(p1,p2,p3,p4,p5);
437 // toc();
439 crc0=build_crc(p2, 176*144);
440 // crc1=build_crc(p2+pp4[3]*pp4[4]/2, pp4[3]*pp4[4]/2);
441 // crc2=build_crc(p2+pp4[3]*pp4[4], pp4[3]*pp4[4]/2);
443 // pp3=p3;
444 // TRANSFORM: <timestamp> <numblocks> <len> <crc_src> <crc_dest> <p4[4]>
445 // fprintf(stderr, "TRAFO:\t%ld\t%ld\t%ld\t%.8lX\t%.8lX\t%ld\n",
446 // pp3[5], pp3[2], pp3[0], crc_src, crc0, pp3[4]);
447 fprintf(stderr, "#R# Decode: %ld(%ld) [%08lX] pts=%ld -> %ld [%08lX]\n",
448 pp3[0],pp3[2],crc_src,pp3[5],
449 result,crc0);
451 // output
452 // hexdump((char*)p2, /*64*/ pp4[3]*pp4[4]/2);
453 // hexdump((void*)p4, 20);
454 // hexdump((void*)p5, 512);
455 // fprintf(stderr, "RV20toYUV420Transform --> 0x%0lx(%ld)\n\n\n", result, result);
456 return result;
459 ulong RV20toYUV420_RN_FRU_Free(ulong p1) {
460 ulong result;
461 fprintf(stderr, "RV20toYUV420_RN_FRU_Free(ulong p1=0x%0lx(%ld))\n", p1, p1);
462 tic();
463 result=(*rvyuvRNFRUFree)(p1);
464 toc();
465 fprintf(stderr, "RV20toYUV420_RN_FRU_Free --> 0x%0lx(%ld)\n\n\n", result, result);
466 return result;
469 ulong RV20toYUV420_RN_FRU_GetFrame(ulong p1,ulong p2,ulong p3) {
470 ulong result;
471 // fprintf(stderr, "RV20toYUV420_RN_FRU_GetFrame(ulong p1=0x%0lx(%ld), ", p1, p1);
472 // fprintf(stderr, "ulong p2=0x%0lx(%ld),\n\t", p2, p2);
473 // fprintf(stderr, "ulong p3=0x%0lx(%ld))\n", p3, p3);
474 // hexdump((void*)p1, 44);
475 tic();
476 result=(*rvyuvRNFRUGetFrame)(p1,p2,p3);
477 toc();
478 // hexdump((void*)p1, 44);
479 // fprintf(stderr, "RV20toYUV420_RN_FRU_GetFrame --> 0x%0lx(%ld)\n\n\n", result, result);
480 return result;
483 ulong RV20toYUV420_RN_FRU_Init(ulong p1,ulong p2,ulong p3) {
484 ulong result;
485 // fprintf(stderr, "RV20toYUV420_RN_FRU_Init(ulong p1=0x%0lx(%ld), ", p1, p1);
486 // fprintf(stderr, "ulong p2=0x%0lx(%ld),\n\t", p2, p2);
487 // fprintf(stderr, "ulong p3=0x%0lx(%ld))\n", p3, p3);
488 // hexdump((void*)p1, 44);
489 tic();
490 result=(*rvyuvRNFRUInit)(p1,p2,p3);
491 toc();
492 // hexdump((void*)p1, 44);
493 // fprintf(stderr, "RV20toYUV420_RN_FRU_Init --> 0x%0lx(%ld)\n\n\n", result, result);
494 return result;
497 ulong RV20toYUV420_RN_FRU_Setup(ulong p1,ulong p2,ulong p3,ulong p4,
498 ulong p5,ulong p6,ulong p7,ulong p8) {
499 ulong result;
500 // fprintf(stderr, "RV20toYUV420_RN_FRU_Setup(ulong p1=0x%0lx(%ld), ", p1, p1);
501 // fprintf(stderr, "ulong p2=0x%0lx(%ld),\n\t", p2, p2);
502 // fprintf(stderr, "ulong p3=0x%0lx(%ld), ", p3, p3);
503 // fprintf(stderr, "ulong p4=0x%0lx(%ld),\n\t", p4, p4);
504 // fprintf(stderr, "ulong p5=0x%0lx(%ld), ", p5, p5);
505 // fprintf(stderr, "ulong p6=0x%0lx(%ld),\n\t", p6, p6);
506 // fprintf(stderr, "ulong p7=0x%0lx(%ld), ", p7, p7);
507 // fprintf(stderr, "ulong p8=0x%0lx(%ld))\n", p8, p8);
508 // hexdump((void*)p1, 44);
509 tic();
510 result=(*rvyuvRNFRUSetup)(p1,p2,p3,p4,p5,p6,p7,p8);
511 toc();
512 // hexdump((void*)p1, 44);
513 // fprintf(stderr, "RV20toYUV420_RN_FRU_Setup --> 0x%0lx(%ld)\n\n\n", result, result);
514 return result;
517 /*void SetDLLAccessPath(ulong p1) {
518 fprintf(stderr, "SetDLLAccessPath(ulong p1=0x%0lx(%ld))\n", p1, p1);
519 hexdump((void*)p1, 44);
520 (*setDLLAccessPath)(p1);
521 hexdump((void*)p1, 44);
522 fprintf(stderr, "--> void\n\n\n");