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