Mercurial > mplayer.hg
comparison libmpcodecs/ad_realaud.c @ 7172:33c38a0c20e8
renamed to match driver family name
author | arpi |
---|---|
date | Fri, 30 Aug 2002 19:49:37 +0000 |
parents | libmpcodecs/ad_real.c@6d784b2812b9 |
children | 7672615cc811 |
comparison
equal
deleted
inserted
replaced
7171:772f853f32a1 | 7172:33c38a0c20e8 |
---|---|
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", | |
17 "real", | |
18 AFM_REAL, | |
19 "A'rpi", | |
20 "Florian Schneider", | |
21 "binary real audio codecs" | |
22 }; | |
23 | |
24 LIBAD_EXTERN(real) | |
25 | |
26 static void *handle=NULL; | |
27 | |
28 void *__builtin_new(unsigned long size) { | |
29 return malloc(size); | |
30 } | |
31 | |
32 #if defined(__FreeBSD__) || defined(__NetBSD__) | |
33 void *__ctype_b=NULL; | |
34 #endif | |
35 | |
36 static unsigned long (*raCloseCodec)(unsigned long); | |
37 static unsigned long (*raDecode)(unsigned long,unsigned long,unsigned long,unsigned long,unsigned long,unsigned long); | |
38 static unsigned long (*raFlush)(unsigned long,unsigned long,unsigned long); | |
39 static unsigned long (*raFreeDecoder)(unsigned long); | |
40 static unsigned long (*raGetFlavorProperty)(unsigned long,unsigned long,unsigned long,unsigned long); | |
41 //static unsigned long (*raGetNumberOfFlavors2)(void); | |
42 static unsigned long (*raInitDecoder)(unsigned long,unsigned long); | |
43 static unsigned long (*raOpenCodec2)(unsigned long); | |
44 static unsigned long (*raSetFlavor)(unsigned long,unsigned long); | |
45 //static void (*raSetDLLAccessPath)(unsigned long); | |
46 static void (*raSetPwd)(char*,char*); | |
47 | |
48 typedef struct { | |
49 int samplerate; | |
50 short bits; | |
51 short channels; | |
52 int unk1; | |
53 int unk2; | |
54 int packetsize; | |
55 int unk3; | |
56 void* unk4; | |
57 } ra_init_t; | |
58 | |
59 static int preinit(sh_audio_t *sh){ | |
60 // let's check if the driver is available, return 0 if not. | |
61 // (you should do that if you use external lib(s) which is optional) | |
62 unsigned int result; | |
63 int len; | |
64 void* prop; | |
65 char path[4096]; | |
66 sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll); | |
67 handle = dlopen (path, RTLD_LAZY); | |
68 if(!handle){ | |
69 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot open dll: %s\n",dlerror()); | |
70 return 0; | |
71 } | |
72 | |
73 raCloseCodec = dlsym(handle, "RACloseCodec"); | |
74 raDecode = dlsym(handle, "RADecode"); | |
75 raFlush = dlsym(handle, "RAFlush"); | |
76 raFreeDecoder = dlsym(handle, "RAFreeDecoder"); | |
77 raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); | |
78 raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); | |
79 raInitDecoder = dlsym(handle, "RAInitDecoder"); | |
80 raSetFlavor = dlsym(handle, "RASetFlavor"); | |
81 // raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); | |
82 raSetPwd = dlsym(handle, "RASetPwd"); // optional, used by SIPR | |
83 | |
84 if(!raCloseCodec || !raDecode || !raFlush || !raFreeDecoder || | |
85 !raGetFlavorProperty || !raOpenCodec2 || !raSetFlavor || | |
86 /*!raSetDLLAccessPath ||*/ !raInitDecoder){ | |
87 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll\n"); | |
88 return 0; | |
89 } | |
90 | |
91 result=raOpenCodec2(&sh->context); | |
92 if(result){ | |
93 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result); | |
94 return 0; | |
95 } | |
96 | |
97 sh->samplerate=sh->wf->nSamplesPerSec; | |
98 sh->samplesize=sh->wf->wBitsPerSample/8; | |
99 sh->channels=sh->wf->nChannels; | |
100 | |
101 { unsigned char temp2[16]={1,0,0,3,4,0,0,0x14,0,0,0,0,0,1,0,3}; | |
102 // note: temp2[] come from audio stream extra header (last 16 of the total 24 bytes) | |
103 ra_init_t init_data={ | |
104 sh->wf->nSamplesPerSec,sh->wf->wBitsPerSample,sh->wf->nChannels, | |
105 100, // ??? | |
106 ((short*)(sh->wf+1))[0], // subpacket size | |
107 sh->wf->nBlockAlign, | |
108 16, // ?? | |
109 ((char*)(sh->wf+1))+6+8 | |
110 }; | |
111 result=raInitDecoder(sh->context,&init_data); | |
112 if(result){ | |
113 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result); | |
114 return 0; | |
115 } | |
116 } | |
117 | |
118 if(raSetPwd){ | |
119 // used by 'SIPR' | |
120 raSetPwd(sh->context,"Ardubancel Quazanga"); // set password... lol. | |
121 } | |
122 | |
123 result=raSetFlavor(sh->context,((short*)(sh->wf+1))[2]); | |
124 if(result){ | |
125 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); | |
126 return 0; | |
127 } | |
128 | |
129 prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0,&len); | |
130 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio codec: [%d] %s\n",((short*)(sh->wf+1))[2],prop); | |
131 | |
132 prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],1,&len); | |
133 sh->i_bps=((*((int*)prop))+4)/8; | |
134 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio bitrate: %5.3f kbit/s (%d bps) \n",(*((int*)prop))*0.001f,sh->i_bps); | |
135 | |
136 // prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0x13,&len); | |
137 // mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Samples/block?: %d \n",(*((int*)prop))); | |
138 | |
139 sh->audio_out_minsize=128000; // no idea how to get... :( | |
140 sh->audio_in_minsize=((short*)(sh->wf+1))[1]*sh->wf->nBlockAlign; | |
141 | |
142 return 1; // return values: 1=OK 0=ERROR | |
143 } | |
144 | |
145 static int init(sh_audio_t *sh_audio){ | |
146 // initialize the decoder, set tables etc... | |
147 | |
148 // you can store HANDLE or private struct pointer at sh->context | |
149 // you can access WAVEFORMATEX header at sh->wf | |
150 | |
151 // set sample format/rate parameters if you didn't do it in preinit() yet. | |
152 | |
153 return 1; // return values: 1=OK 0=ERROR | |
154 } | |
155 | |
156 static void uninit(sh_audio_t *sh){ | |
157 // uninit the decoder etc... | |
158 // again: you don't have to free() a_in_buffer here! it's done by the core. | |
159 } | |
160 | |
161 static unsigned char sipr_swaps[38][2]={ | |
162 {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, | |
163 {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, | |
164 {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, | |
165 {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, | |
166 {77,80} }; | |
167 | |
168 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ | |
169 int result; | |
170 int len=-1; | |
171 int sps=((short*)(sh->wf+1))[0]; | |
172 int w=sh->wf->nBlockAlign; // 5 | |
173 int h=((short*)(sh->wf+1))[1]; | |
174 | |
175 // printf("bs=%d sps=%d w=%d h=%d \n",sh->wf->nBlockAlign,sps,w,h); | |
176 | |
177 #if 1 | |
178 if(sh->a_in_buffer_len<=0){ | |
179 // fill the buffer! | |
180 if(!sps){ | |
181 // 'sipr' way | |
182 int j,n; | |
183 int bs=h*w*2/96; // nibbles per subpacket | |
184 unsigned char *p=sh->a_in_buffer; | |
185 demux_read_data(sh->ds, p, h*w); | |
186 for(n=0;n<38;n++){ | |
187 int i=bs*sipr_swaps[n][0]; | |
188 int o=bs*sipr_swaps[n][1]; | |
189 // swap nibbles of block 'i' with 'o' TODO: optimize | |
190 for(j=0;j<bs;j++){ | |
191 int x=(i&1) ? (p[(i>>1)]>>4) : (p[(i>>1)]&15); | |
192 int y=(o&1) ? (p[(o>>1)]>>4) : (p[(o>>1)]&15); | |
193 if(o&1) p[(o>>1)]=(p[(o>>1)]&0x0F)|(x<<4); | |
194 else p[(o>>1)]=(p[(o>>1)]&0xF0)|x; | |
195 if(i&1) p[(i>>1)]=(p[(i>>1)]&0x0F)|(y<<4); | |
196 else p[(i>>1)]=(p[(i>>1)]&0xF0)|y; | |
197 ++i;++o; | |
198 } | |
199 } | |
200 sh->a_in_buffer_size= | |
201 sh->a_in_buffer_len=w*h; | |
202 } else { | |
203 // 'cook' way | |
204 int x,y; | |
205 w/=sps; | |
206 for(y=0;y<h;y++) | |
207 for(x=0;x<w;x++){ | |
208 demux_read_data(sh->ds, sh->a_in_buffer+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); | |
209 } | |
210 sh->a_in_buffer_size= | |
211 sh->a_in_buffer_len=w*h*sps; | |
212 } | |
213 } | |
214 | |
215 #else | |
216 if(sh->a_in_buffer_len<=0){ | |
217 // fill the buffer! | |
218 demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign); | |
219 sh->a_in_buffer_size= | |
220 sh->a_in_buffer_len=sh->wf->nBlockAlign; | |
221 } | |
222 #endif | |
223 | |
224 result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign, | |
225 buf, &len, -1); | |
226 sh->a_in_buffer_len-=sh->wf->nBlockAlign; | |
227 | |
228 // printf("radecode: %d bytes, res=0x%X \n",len,result); | |
229 | |
230 return len; // return value: number of _bytes_ written to output buffer, | |
231 // or -1 for EOF (or uncorrectable error) | |
232 } | |
233 | |
234 static int control(sh_audio_t *sh,int cmd,void* arg, ...){ | |
235 // various optional functions you MAY implement: | |
236 switch(cmd){ | |
237 case ADCTRL_RESYNC_STREAM: | |
238 // it is called once after seeking, to resync. | |
239 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! | |
240 return CONTROL_TRUE; | |
241 case ADCTRL_SKIP_FRAME: | |
242 // it is called to skip (jump over) small amount (1/10 sec or 1 frame) | |
243 // of audio data - used to sync audio to video after seeking | |
244 // if you don't return CONTROL_TRUE, it will defaults to: | |
245 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet | |
246 return CONTROL_TRUE; | |
247 } | |
248 return CONTROL_UNKNOWN; | |
249 } | |
250 | |
251 #endif |