Mercurial > mplayer.hg
annotate libmpcodecs/ad_real.c @ 6727:c60fd3562f47
FFmpeg libavcodec directory is unknown to CVS, as is mga_vid_test.
author | diego |
---|---|
date | Sat, 13 Jul 2002 15:10:33 +0000 |
parents | 88a06ebb3287 |
children | 9734bfbb200a |
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", |
17 "real", | |
18 AFM_REAL, | |
19 "A'rpi", | |
20 "Florian Schneider", | |
21 "binary real audio codecs" | |
6367 | 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 | |
6404
83b3315c679b
Implement Nilmoni's and Bernd Ernesti's patches for:
atmos4
parents:
6380
diff
changeset
|
34 #if defined(__FreeBSD__) || defined(__NetBSD__) |
83b3315c679b
Implement Nilmoni's and Bernd Ernesti's patches for:
atmos4
parents:
6380
diff
changeset
|
35 void *__ctype_b=NULL; |
6377 | 36 #endif |
6367 | 37 |
38 static ulong (*raCloseCodec)(ulong); | |
39 static ulong (*raDecode)(ulong,ulong,ulong,ulong,ulong,ulong); | |
40 static ulong (*raFlush)(ulong,ulong,ulong); | |
41 static ulong (*raFreeDecoder)(ulong); | |
42 static ulong (*raGetFlavorProperty)(ulong,ulong,ulong,ulong); | |
43 //static ulong (*raGetNumberOfFlavors2)(void); | |
44 static ulong (*raInitDecoder)(ulong,ulong); | |
45 static ulong (*raOpenCodec2)(ulong); | |
46 static ulong (*raSetFlavor)(ulong,ulong); | |
47 static void (*raSetDLLAccessPath)(ulong); | |
48 | |
49 typedef struct { | |
50 int samplerate; | |
51 short bits; | |
52 short channels; | |
53 int unk1; | |
54 int unk2; | |
55 int packetsize; | |
56 int unk3; | |
57 void* unk4; | |
58 } ra_init_t; | |
59 | |
60 static int preinit(sh_audio_t *sh){ | |
61 // let's check if the driver is available, return 0 if not. | |
62 // (you should do that if you use external lib(s) which is optional) | |
63 unsigned int result; | |
6380 | 64 int len; |
65 void* prop; | |
6376 | 66 char path[4096]; |
6404
83b3315c679b
Implement Nilmoni's and Bernd Ernesti's patches for:
atmos4
parents:
6380
diff
changeset
|
67 sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll); |
6376 | 68 handle = dlopen (path, RTLD_LAZY); |
6367 | 69 if(!handle){ |
70 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot open dll: %s\n",dlerror()); | |
71 return 0; | |
72 } | |
73 | |
74 raCloseCodec = dlsym(handle, "RACloseCodec"); | |
75 raDecode = dlsym(handle, "RADecode"); | |
76 raFlush = dlsym(handle, "RAFlush"); | |
77 raFreeDecoder = dlsym(handle, "RAFreeDecoder"); | |
78 raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); | |
79 raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); | |
80 raInitDecoder = dlsym(handle, "RAInitDecoder"); | |
81 raSetFlavor = dlsym(handle, "RASetFlavor"); | |
82 raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); | |
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, | |
6373 | 105 100, // ??? |
106 ((short*)(sh->wf+1))[0], // subpacket size | |
6367 | 107 sh->wf->nBlockAlign, |
108 16, // ?? | |
6373 | 109 ((char*)(sh->wf+1))+6+8 |
6367 | 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 | |
6373 | 118 result=raSetFlavor(sh->context,((short*)(sh->wf+1))[2]); |
6367 | 119 if(result){ |
120 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); | |
121 return 0; | |
122 } | |
123 | |
6380 | 124 prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0,&len); |
125 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio codec: [%d] %s\n",((short*)(sh->wf+1))[2],prop); | |
126 | |
127 prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],1,&len); | |
128 sh->i_bps=((*((int*)prop))+4)/8; | |
129 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio bitrate: %5.3f kbit/s (%d bps) \n",(*((int*)prop))*0.001f,sh->i_bps); | |
130 | |
131 // prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0x13,&len); | |
132 // mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Samples/block?: %d \n",(*((int*)prop))); | |
133 | |
134 sh->audio_out_minsize=128000; // no idea how to get... :( | |
6373 | 135 sh->audio_in_minsize=((short*)(sh->wf+1))[1]*sh->wf->nBlockAlign; |
6367 | 136 |
137 return 1; // return values: 1=OK 0=ERROR | |
138 } | |
139 | |
140 static int init(sh_audio_t *sh_audio){ | |
141 // initialize the decoder, set tables etc... | |
142 | |
143 // you can store HANDLE or private struct pointer at sh->context | |
144 // you can access WAVEFORMATEX header at sh->wf | |
145 | |
146 // set sample format/rate parameters if you didn't do it in preinit() yet. | |
147 | |
148 return 1; // return values: 1=OK 0=ERROR | |
149 } | |
150 | |
151 static void uninit(sh_audio_t *sh){ | |
152 // uninit the decoder etc... | |
153 // again: you don't have to free() a_in_buffer here! it's done by the core. | |
154 } | |
155 | |
156 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ | |
157 int result; | |
158 int len=-1; | |
6373 | 159 int sps=((short*)(sh->wf+1))[0]; |
160 int w=sh->wf->nBlockAlign/sps; // 5 | |
161 int h=((short*)(sh->wf+1))[1]; | |
162 | |
6376 | 163 // 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
|
164 |
6373 | 165 #if 1 |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
166 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
|
167 // fill the buffer! |
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
168 int x,y; |
6373 | 169 for(y=0;y<h;y++) |
170 for(x=0;x<w;x++){ | |
6428
88a06ebb3287
audio subpacket reordering fixed for odd matrix height
arpi
parents:
6404
diff
changeset
|
171 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
|
172 } |
6373 | 173 sh->a_in_buffer_size= |
174 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
|
175 } |
6373 | 176 |
177 #else | |
178 if(sh->a_in_buffer_len<=0){ | |
179 // fill the buffer! | |
180 demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign); | |
181 sh->a_in_buffer_size= | |
182 sh->a_in_buffer_len=sh->wf->nBlockAlign; | |
183 } | |
184 #endif | |
6367 | 185 |
6373 | 186 result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign, |
6367 | 187 buf, &len, -1); |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
188 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
|
189 |
6376 | 190 // printf("radecode: %d bytes, res=0x%X \n",len,result); |
6367 | 191 |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
192 return len; // return value: number of _bytes_ written to output buffer, |
6367 | 193 // or -1 for EOF (or uncorrectable error) |
194 } | |
195 | |
196 static int control(sh_audio_t *sh,int cmd,void* arg, ...){ | |
197 // various optional functions you MAY implement: | |
198 switch(cmd){ | |
199 case ADCTRL_RESYNC_STREAM: | |
200 // it is called once after seeking, to resync. | |
201 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! | |
202 return CONTROL_TRUE; | |
203 case ADCTRL_SKIP_FRAME: | |
204 // it is called to skip (jump over) small amount (1/10 sec or 1 frame) | |
205 // of audio data - used to sync audio to video after seeking | |
206 // if you don't return CONTROL_TRUE, it will defaults to: | |
207 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet | |
208 return CONTROL_TRUE; | |
209 } | |
210 return CONTROL_UNKNOWN; | |
211 } | |
212 | |
213 #endif |