Mercurial > mplayer.hg
annotate libmpcodecs/ad_real.c @ 6887:66427e850216
Add the control VFCTRL_CHANGE_RECTANGLE
print the rectangle boundaries.
vf_rectangle accepts stride. Is this correct?
author | kmkaplan |
---|---|
date | Sun, 04 Aug 2002 02:21:50 +0000 |
parents | 9734bfbb200a |
children | f0886fe4be89 |
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 | |
26 static void *handle=NULL; | |
27 | |
28 void *__builtin_new(unsigned long size) { | |
29 return malloc(size); | |
30 } | |
31 | |
6404
83b3315c679b
Implement Nilmoni's and Bernd Ernesti's patches for:
atmos4
parents:
6380
diff
changeset
|
32 #if defined(__FreeBSD__) || defined(__NetBSD__) |
83b3315c679b
Implement Nilmoni's and Bernd Ernesti's patches for:
atmos4
parents:
6380
diff
changeset
|
33 void *__ctype_b=NULL; |
6377 | 34 #endif |
6367 | 35 |
6745
9734bfbb200a
Avoid ulong typedef clash and replace if by unsigned long, patch by Joey Parrish.
atmos4
parents:
6428
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 //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
|
42 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
|
43 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
|
44 static unsigned long (*raSetFlavor)(unsigned long,unsigned long); |
9734bfbb200a
Avoid ulong typedef clash and replace if by unsigned long, patch by Joey Parrish.
atmos4
parents:
6428
diff
changeset
|
45 static void (*raSetDLLAccessPath)(unsigned long); |
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"); | |
80 raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); | |
81 | |
82 if(!raCloseCodec || !raDecode || !raFlush || !raFreeDecoder || | |
83 !raGetFlavorProperty || !raOpenCodec2 || !raSetFlavor || | |
84 !raSetDLLAccessPath || !raInitDecoder){ | |
85 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll\n"); | |
86 return 0; | |
87 } | |
88 | |
89 result=raOpenCodec2(&sh->context); | |
90 if(result){ | |
91 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result); | |
92 return 0; | |
93 } | |
94 | |
95 sh->samplerate=sh->wf->nSamplesPerSec; | |
96 sh->samplesize=sh->wf->wBitsPerSample/8; | |
97 sh->channels=sh->wf->nChannels; | |
98 | |
99 { unsigned char temp2[16]={1,0,0,3,4,0,0,0x14,0,0,0,0,0,1,0,3}; | |
100 // note: temp2[] come from audio stream extra header (last 16 of the total 24 bytes) | |
101 ra_init_t init_data={ | |
102 sh->wf->nSamplesPerSec,sh->wf->wBitsPerSample,sh->wf->nChannels, | |
6373 | 103 100, // ??? |
104 ((short*)(sh->wf+1))[0], // subpacket size | |
6367 | 105 sh->wf->nBlockAlign, |
106 16, // ?? | |
6373 | 107 ((char*)(sh->wf+1))+6+8 |
6367 | 108 }; |
109 result=raInitDecoder(sh->context,&init_data); | |
110 if(result){ | |
111 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result); | |
112 return 0; | |
113 } | |
114 } | |
115 | |
6373 | 116 result=raSetFlavor(sh->context,((short*)(sh->wf+1))[2]); |
6367 | 117 if(result){ |
118 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); | |
119 return 0; | |
120 } | |
121 | |
6380 | 122 prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0,&len); |
123 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio codec: [%d] %s\n",((short*)(sh->wf+1))[2],prop); | |
124 | |
125 prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],1,&len); | |
126 sh->i_bps=((*((int*)prop))+4)/8; | |
127 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Audio bitrate: %5.3f kbit/s (%d bps) \n",(*((int*)prop))*0.001f,sh->i_bps); | |
128 | |
129 // prop=raGetFlavorProperty(sh->context,((short*)(sh->wf+1))[2],0x13,&len); | |
130 // mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Samples/block?: %d \n",(*((int*)prop))); | |
131 | |
132 sh->audio_out_minsize=128000; // no idea how to get... :( | |
6373 | 133 sh->audio_in_minsize=((short*)(sh->wf+1))[1]*sh->wf->nBlockAlign; |
6367 | 134 |
135 return 1; // return values: 1=OK 0=ERROR | |
136 } | |
137 | |
138 static int init(sh_audio_t *sh_audio){ | |
139 // initialize the decoder, set tables etc... | |
140 | |
141 // you can store HANDLE or private struct pointer at sh->context | |
142 // you can access WAVEFORMATEX header at sh->wf | |
143 | |
144 // set sample format/rate parameters if you didn't do it in preinit() yet. | |
145 | |
146 return 1; // return values: 1=OK 0=ERROR | |
147 } | |
148 | |
149 static void uninit(sh_audio_t *sh){ | |
150 // uninit the decoder etc... | |
151 // again: you don't have to free() a_in_buffer here! it's done by the core. | |
152 } | |
153 | |
154 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ | |
155 int result; | |
156 int len=-1; | |
6373 | 157 int sps=((short*)(sh->wf+1))[0]; |
158 int w=sh->wf->nBlockAlign/sps; // 5 | |
159 int h=((short*)(sh->wf+1))[1]; | |
160 | |
6376 | 161 // 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
|
162 |
6373 | 163 #if 1 |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
164 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
|
165 // fill the buffer! |
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
166 int x,y; |
6373 | 167 for(y=0;y<h;y++) |
168 for(x=0;x<w;x++){ | |
6428
88a06ebb3287
audio subpacket reordering fixed for odd matrix height
arpi
parents:
6404
diff
changeset
|
169 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
|
170 } |
6373 | 171 sh->a_in_buffer_size= |
172 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
|
173 } |
6373 | 174 |
175 #else | |
176 if(sh->a_in_buffer_len<=0){ | |
177 // fill the buffer! | |
178 demux_read_data(sh->ds, sh->a_in_buffer, sh->wf->nBlockAlign); | |
179 sh->a_in_buffer_size= | |
180 sh->a_in_buffer_len=sh->wf->nBlockAlign; | |
181 } | |
182 #endif | |
6367 | 183 |
6373 | 184 result=raDecode(sh->context, sh->a_in_buffer+sh->a_in_buffer_size-sh->a_in_buffer_len, sh->wf->nBlockAlign, |
6367 | 185 buf, &len, -1); |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
186 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
|
187 |
6376 | 188 // printf("radecode: %d bytes, res=0x%X \n",len,result); |
6367 | 189 |
6368
9511fffdb8c6
yeah, it worx! but needs a big cleanup and removal of hardcoded stuff
arpi
parents:
6367
diff
changeset
|
190 return len; // return value: number of _bytes_ written to output buffer, |
6367 | 191 // or -1 for EOF (or uncorrectable error) |
192 } | |
193 | |
194 static int control(sh_audio_t *sh,int cmd,void* arg, ...){ | |
195 // various optional functions you MAY implement: | |
196 switch(cmd){ | |
197 case ADCTRL_RESYNC_STREAM: | |
198 // it is called once after seeking, to resync. | |
199 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! | |
200 return CONTROL_TRUE; | |
201 case ADCTRL_SKIP_FRAME: | |
202 // it is called to skip (jump over) small amount (1/10 sec or 1 frame) | |
203 // of audio data - used to sync audio to video after seeking | |
204 // if you don't return CONTROL_TRUE, it will defaults to: | |
205 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet | |
206 return CONTROL_TRUE; | |
207 } | |
208 return CONTROL_UNKNOWN; | |
209 } | |
210 | |
211 #endif |