Mercurial > mplayer.hg
comparison libmpcodecs/ad_real.c @ 6367:489c4bcbda13
readaudio decoder - not yet working
author | arpi |
---|---|
date | Mon, 10 Jun 2002 01:32:12 +0000 |
parents | |
children | 9511fffdb8c6 |
comparison
equal
deleted
inserted
replaced
6366:287c2e661172 | 6367:489c4bcbda13 |
---|---|
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 | |
26 static void *handle=NULL; | |
27 | |
28 void *__builtin_new(unsigned long size) { | |
29 return malloc(size); | |
30 } | |
31 | |
32 | |
33 static ulong (*raCloseCodec)(ulong); | |
34 static ulong (*raDecode)(ulong,ulong,ulong,ulong,ulong,ulong); | |
35 static ulong (*raFlush)(ulong,ulong,ulong); | |
36 static ulong (*raFreeDecoder)(ulong); | |
37 static ulong (*raGetFlavorProperty)(ulong,ulong,ulong,ulong); | |
38 //static ulong (*raGetNumberOfFlavors2)(void); | |
39 static ulong (*raInitDecoder)(ulong,ulong); | |
40 static ulong (*raOpenCodec2)(ulong); | |
41 static ulong (*raSetFlavor)(ulong,ulong); | |
42 static void (*raSetDLLAccessPath)(ulong); | |
43 | |
44 typedef struct { | |
45 int samplerate; | |
46 short bits; | |
47 short channels; | |
48 int unk1; | |
49 int unk2; | |
50 int packetsize; | |
51 int unk3; | |
52 void* unk4; | |
53 } ra_init_t; | |
54 | |
55 static int preinit(sh_audio_t *sh){ | |
56 // let's check if the driver is available, return 0 if not. | |
57 // (you should do that if you use external lib(s) which is optional) | |
58 unsigned int result; | |
59 handle = dlopen ("/usr/local/RealPlayer8/Codecs/cook.so.6.0", RTLD_LAZY); | |
60 if(!handle){ | |
61 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot open dll: %s\n",dlerror()); | |
62 return 0; | |
63 } | |
64 | |
65 raCloseCodec = dlsym(handle, "RACloseCodec"); | |
66 raDecode = dlsym(handle, "RADecode"); | |
67 raFlush = dlsym(handle, "RAFlush"); | |
68 raFreeDecoder = dlsym(handle, "RAFreeDecoder"); | |
69 raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty"); | |
70 raOpenCodec2 = dlsym(handle, "RAOpenCodec2"); | |
71 raInitDecoder = dlsym(handle, "RAInitDecoder"); | |
72 raSetFlavor = dlsym(handle, "RASetFlavor"); | |
73 raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath"); | |
74 | |
75 if(!raCloseCodec || !raDecode || !raFlush || !raFreeDecoder || | |
76 !raGetFlavorProperty || !raOpenCodec2 || !raSetFlavor || | |
77 !raSetDLLAccessPath || !raInitDecoder){ | |
78 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Cannot resolve symbols - incompatible dll\n"); | |
79 return 0; | |
80 } | |
81 | |
82 result=raOpenCodec2(&sh->context); | |
83 if(result){ | |
84 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder open failed, error code: 0x%X\n",result); | |
85 return 0; | |
86 } | |
87 | |
88 sh->samplerate=sh->wf->nSamplesPerSec; | |
89 sh->samplesize=sh->wf->wBitsPerSample/8; | |
90 sh->channels=sh->wf->nChannels; | |
91 | |
92 { unsigned char temp2[16]={1,0,0,3,4,0,0,0x14,0,0,0,0,0,1,0,3}; | |
93 // note: temp2[] come from audio stream extra header (last 16 of the total 24 bytes) | |
94 ra_init_t init_data={ | |
95 sh->wf->nSamplesPerSec,sh->wf->wBitsPerSample,sh->wf->nChannels, | |
96 100, 60, // ????? | |
97 sh->wf->nBlockAlign, | |
98 16, // ?? | |
99 ((char*)(sh->wf+1))+2+8 | |
100 }; | |
101 result=raInitDecoder(sh->context,&init_data); | |
102 if(result){ | |
103 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder init failed, error code: 0x%X\n",result); | |
104 return 0; | |
105 } | |
106 } | |
107 | |
108 result=raSetFlavor(sh->context,*((short*)(sh->wf+1))); | |
109 if(result){ | |
110 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Decoder flavor setup failed, error code: 0x%X\n",result); | |
111 return 0; | |
112 } | |
113 | |
114 sh->audio_out_minsize=128000; //sh->samplerate*sh->samplesize*sh->channels; | |
115 sh->audio_in_minsize=2*sh->wf->nBlockAlign; | |
116 // sh->samplesize=2; | |
117 // sh->channels=2; | |
118 // sh->samplerate=44100; | |
119 // sh->sample_format=AFMT_S16_LE; | |
120 sh->i_bps=64000/8; | |
121 | |
122 return 1; // return values: 1=OK 0=ERROR | |
123 } | |
124 | |
125 static int init(sh_audio_t *sh_audio){ | |
126 // initialize the decoder, set tables etc... | |
127 | |
128 // you can store HANDLE or private struct pointer at sh->context | |
129 // you can access WAVEFORMATEX header at sh->wf | |
130 | |
131 // set sample format/rate parameters if you didn't do it in preinit() yet. | |
132 | |
133 return 1; // return values: 1=OK 0=ERROR | |
134 } | |
135 | |
136 static void uninit(sh_audio_t *sh){ | |
137 // uninit the decoder etc... | |
138 // again: you don't have to free() a_in_buffer here! it's done by the core. | |
139 } | |
140 | |
141 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ | |
142 int result; | |
143 int len=-1; | |
144 | |
145 demux_read_data(sh->ds, sh->a_in_buffer, 60); | |
146 | |
147 result=raDecode(sh->context, sh->a_in_buffer, sh->wf->nBlockAlign, | |
148 buf, &len, -1); | |
149 | |
150 printf("radecode: %d bytes, res=0x%X \n",len,result); | |
151 | |
152 // audio decoding. the most important thing :) | |
153 // parameters you get: | |
154 // buf = pointer to the output buffer, you have to store uncompressed | |
155 // samples there | |
156 // minlen = requested minimum size (in bytes!) of output. it's just a | |
157 // _recommendation_, you can decode more or less, it just tell you that | |
158 // the caller process needs 'minlen' bytes. if it gets less, it will | |
159 // call decode_audio() again. | |
160 // maxlen = maximum size (bytes) of output. you MUST NOT write more to the | |
161 // buffer, it's the upper-most limit! | |
162 // note: maxlen will be always greater or equal to sh->audio_out_minsize | |
163 | |
164 // now, let's decode... | |
165 | |
166 // you can read the compressed stream using the demux stream functions: | |
167 // demux_read_data(sh->ds, buffer, length) - read 'length' bytes to 'buffer' | |
168 // ds_get_packet(sh->ds, &buffer) - set ptr buffer to next data packet | |
169 // (both func return number of bytes or 0 for error) | |
170 | |
171 return len/8; // return value: number of _bytes_ written to output buffer, | |
172 // or -1 for EOF (or uncorrectable error) | |
173 } | |
174 | |
175 static int control(sh_audio_t *sh,int cmd,void* arg, ...){ | |
176 // various optional functions you MAY implement: | |
177 switch(cmd){ | |
178 case ADCTRL_RESYNC_STREAM: | |
179 // it is called once after seeking, to resync. | |
180 // Note: sh_audio->a_in_buffer_len=0; is done _before_ this call! | |
181 return CONTROL_TRUE; | |
182 case ADCTRL_SKIP_FRAME: | |
183 // it is called to skip (jump over) small amount (1/10 sec or 1 frame) | |
184 // of audio data - used to sync audio to video after seeking | |
185 // if you don't return CONTROL_TRUE, it will defaults to: | |
186 // ds_fill_buffer(sh_audio->ds); // skip 1 demux packet | |
187 return CONTROL_TRUE; | |
188 } | |
189 return CONTROL_UNKNOWN; | |
190 } | |
191 | |
192 #endif |