Mercurial > mplayer.hg
annotate libmpcodecs/ad_real.c @ 6373:8d5d339f2944
get matrix w*h from the demuxer
author | arpi |
---|---|
date | Mon, 10 Jun 2002 13:55:18 +0000 |
parents | 1ae3a153f380 |
children | e3c74c01a3a2 |
rev | line source |
---|---|
6367 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <unistd.h> | |
5 | |
6 #include "config.h" | |
7 | |
8 #ifdef USE_REALCODECS | |
9 | |
10 #include <stddef.h> | |
11 #include <dlfcn.h> | |
12 | |
13 #include "ad_internal.h" | |
14 | |
15 static ad_info_t info = { | |
16 "RealAudio decoder", // name of the driver | |
17 "real", // driver name. should be the same as filename without ad_ | |
18 AFM_REAL, // replace with registered AFM number | |
19 "A'rpi", // writer/maintainer of _this_ file | |
20 "", // writer/maintainer/site of the _codec_ | |
21 "" // comments | |
22 }; | |
23 | |
24 LIBAD_EXTERN(real) | |
25 | |
6370 | 26 typedef unsigned long ulong; |
27 | |
6367 | 28 static void *handle=NULL; |
29 | |
30 void *__builtin_new(unsigned long size) { | |
31 return malloc(size); | |
32 } | |
33 | |
34 | |
35 static ulong (*raCloseCodec)(ulong); | |
36 static ulong (*raDecode)(ulong,ulong,ulong,ulong,ulong,ulong); | |
37 static ulong (*raFlush)(ulong,ulong,ulong); | |
38 static ulong (*raFreeDecoder)(ulong); | |
39 static ulong (*raGetFlavorProperty)(ulong,ulong,ulong,ulong); | |
40 //static ulong (*raGetNumberOfFlavors2)(void); | |
41 static ulong (*raInitDecoder)(ulong,ulong); | |
42 static ulong (*raOpenCodec2)(ulong); | |
43 static ulong (*raSetFlavor)(ulong,ulong); | |
44 static void (*raSetDLLAccessPath)(ulong); | |
45 | |
46 typedef struct { | |
47 int samplerate; | |
48 short bits; | |
49 short channels; | |
50 int unk1; | |
51 int unk2; | |
52 int packetsize; | |
53 int unk3; | |
54 void* unk4; | |
55 } ra_init_t; | |
56 | |
57 static int preinit(sh_audio_t *sh){ | |
58 // let's check if the driver is available, return 0 if not. | |
59 // (you should do that if you use external lib(s) which is optional) | |
60 unsigned int result; | |
61 handle = dlopen ("/usr/local/RealPlayer8/Codecs/cook.so.6.0", RTLD_LAZY); | |
62 if(!handle){ | |
63 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot open dll: %s\n",dlerror()); | |
64 return 0; | |
65 } | |
66 | |
67 raCloseCodec = dlsym(handle, "RACloseCodec"); | |
68 raDecode = dlsym(handle, "RADecode"); | |
69 raFlush = dlsym(handle, "RAFlush"); | |
70 raFreeDecoder = dlsym(handle, "RAFreeDecoder"); | |
71 raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); | |
72 raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); | |
73 raInitDecoder = dlsym(handle, "RAInitDecoder"); | |
74 raSetFlavor = dlsym(handle, "RASetFlavor"); | |
75 raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); | |
76 | |
77 if(!raCloseCodec || !raDecode || !raFlush || !raFreeDecoder || | |
78 !raGetFlavorProperty || !raOpenCodec2 || !raSetFlavor || | |
79 !raSetDLLAccessPath || !raInitDecoder){ | |
80 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll\n"); | |
81 return 0; | |
82 } | |
83 | |
84 result=raOpenCodec2(&sh->context); | |
85 if(result){ | |
86 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result); | |
87 return 0; | |
88 } | |
89 | |
90 sh->samplerate=sh->wf->nSamplesPerSec; | |
91 sh->samplesize=sh->wf->wBitsPerSample/8; | |
92 sh->channels=sh->wf->nChannels; | |
93 | |
94 { unsigned char temp2[16]={1,0,0,3,4,0,0,0x14,0,0,0,0,0,1,0,3}; | |
95 // note: temp2[] come from audio stream extra header (last 16 of the total 24 bytes) | |
96 ra_init_t init_data={ | |
97 sh->wf->nSamplesPerSec,sh->wf->wBitsPerSample,sh->wf->nChannels, | |
6373 | 98 100, // ??? |
99 ((short*)(sh->wf+1))[0], // subpacket size | |
6367 | 100 sh->wf->nBlockAlign, |
101 16, // ?? | |
6373 | 102 ((char*)(sh->wf+1))+6+8 |
6367 | 103 }; |
104 result=raInitDecoder(sh->context,&init_data); | |
105 if(result){ | |
106 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result); | |
107 return 0; | |
108 } | |
109 } | |
110 | |
6373 | 111 result=raSetFlavor(sh->context,((short*)(sh->wf+1))[2]); |
6367 | 112 if(result){ |
113 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); | |
114 return 0; | |
115 } | |
116 | |
117 sh->audio_out_minsize=128000; //sh->samplerate*sh->samplesize*sh->channels; | |
6373 | 118 sh->audio_in_minsize=((short*)(sh->wf+1))[1]*sh->wf->nBlockAlign; |
6367 | 119 // sh->samplesize=2; |
120 // sh->channels=2; | |
121 // sh->samplerate=44100; | |
122 // sh->sample_format=AFMT_S16_LE; | |
123 sh->i_bps=64000/8; | |
124 | |
125 return 1; // return values: 1=OK 0=ERROR | |
126 } | |
127 | |
128 static int init(sh_audio_t *sh_audio){ | |
129 // initialize the decoder, set tables etc... | |
130 | |
131 // you can store HANDLE or private struct pointer at sh->context | |
132 // you can access WAVEFORMATEX header at sh->wf | |
133 | |
134 // set sample format/rate parameters if you didn't do it in preinit() yet. | |
135 | |
136 return 1; // return values: 1=OK 0=ERROR | |
137 } | |
138 | |
139 static void uninit(sh_audio_t *sh){ | |
140 // uninit the decoder etc... | |
141 // again: you don't have to free() a_in_buffer here! it's done by the core. | |
142 } | |
143 | |
144 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ | |
145 int result; | |
146 int len=-1; | |
6373 | 147 int sps=((short*)(sh->wf+1))[0]; |
148 int w=sh->wf->nBlockAlign/sps; // 5 | |
149 int h=((short*)(sh->wf+1))[1]; | |
150 | |
151 printf("bs=%d sps=%d w=%d h=%d \n",sh->wf->nBlockAlign,sps,w,h); | |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
152 |
6373 | 153 #if 1 |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
154 if(sh->a_in_buffer_len<=0){ |
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
155 // fill the buffer! |
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
156 int x,y; |
6373 | 157 for(y=0;y<h;y++) |
158 for(x=0;x<w;x++){ | |
159 demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+(h/2)*(y&1)+(y>>1)), sps); | |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
160 } |
6373 | 161 sh->a_in_buffer_size= |
162 sh->a_in_buffer_len=w*h*sps; | |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
163 } |
6373 | 164 |
165 #else | |
166 if(sh->a_in_buffer_len<=0){ | |
167 // fill the buffer! | |
168 demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign); | |
169 sh->a_in_buffer_size= | |
170 sh->a_in_buffer_len=sh->wf->nBlockAlign; | |
171 } | |
172 #endif | |
6367 | 173 |
6373 | 174 result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign, |
6367 | 175 buf, &len, -1); |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
176 sh->a_in_buffer_len-=sh->wf->nBlockAlign; |
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
177 |
6367 | 178 printf("radecode: %d bytes, res=0x%X \n",len,result); |
179 | |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
180 return len; // return value: number of _bytes_ written to output buffer, |
6367 | 181 // or -1 for EOF (or uncorrectable error) |
182 } | |
183 | |
184 static int control(sh_audio_t *sh,int cmd,void* arg, ...){ | |
185 // various optional functions you MAY implement: | |
186 switch(cmd){ | |
187 case ADCTRL_RESYNC_STREAM: | |
188 // it is called once after seeking, to resync. | |
189 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! | |
190 return CONTROL_TRUE; | |
191 case ADCTRL_SKIP_FRAME: | |
192 // it is called to skip (jump over) small amount (1/10 sec or 1 frame) | |
193 // of audio data - used to sync audio to video after seeking | |
194 // if you don't return CONTROL_TRUE, it will defaults to: | |
195 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet | |
196 return CONTROL_TRUE; | |
197 } | |
198 return CONTROL_UNKNOWN; | |
199 } | |
200 | |
201 #endif |