10034
|
1 /*
|
|
2 Realaudio demuxer for MPlayer
|
14908
|
3 (c) 2003, 2005 Roberto Togni
|
10034
|
4 */
|
|
5
|
|
6 #include <stdio.h>
|
|
7 #include <stdlib.h>
|
|
8 #include <unistd.h>
|
|
9
|
|
10 #include "config.h"
|
|
11 #include "mp_msg.h"
|
|
12 #include "help_mp.h"
|
|
13
|
|
14 #include "stream.h"
|
|
15 #include "demuxer.h"
|
|
16 #include "stheader.h"
|
|
17 #include "bswap.h"
|
|
18
|
|
19
|
|
20 #define FOURCC_DOTRA mmioFOURCC('.','r','a', 0xfd)
|
|
21 #define FOURCC_144 mmioFOURCC('1','4','_','4')
|
|
22 #define FOURCC_288 mmioFOURCC('2','8','_','8')
|
|
23 #define FOURCC_DNET mmioFOURCC('d','n','e','t')
|
|
24 #define FOURCC_LPCJ mmioFOURCC('l','p','c','J')
|
|
25
|
|
26
|
|
27 typedef struct {
|
|
28 unsigned short version;
|
|
29 unsigned int dotranum;
|
|
30 unsigned int data_size;
|
|
31 unsigned short version2;
|
|
32 unsigned int hdr_size;
|
|
33 unsigned short codec_flavor;
|
|
34 unsigned int coded_framesize;
|
|
35 unsigned short sub_packet_h;
|
|
36 unsigned short frame_size;
|
|
37 unsigned short sub_packet_size;
|
|
38 char genr[4];
|
|
39 } ra_priv_t;
|
|
40
|
|
41
|
|
42
|
16175
|
43 static int ra_check_file(demuxer_t* demuxer)
|
10034
|
44 {
|
|
45 unsigned int chunk_id;
|
|
46
|
|
47 chunk_id = stream_read_dword_le(demuxer->stream);
|
|
48 if (chunk_id == FOURCC_DOTRA)
|
16175
|
49 return DEMUXER_TYPE_REALAUDIO;
|
10034
|
50 else
|
|
51 return 0;
|
|
52 }
|
|
53
|
|
54
|
|
55
|
|
56 void hexdump(char *, unsigned long);
|
|
57
|
|
58 // return value:
|
|
59 // 0 = EOF or no stream found
|
|
60 // 1 = successfully read a packet
|
16175
|
61 static int demux_ra_fill_buffer(demuxer_t *demuxer, demux_stream_t *dsds)
|
10034
|
62 {
|
|
63 ra_priv_t *ra_priv = demuxer->priv;
|
|
64 int len;
|
|
65 int timestamp;
|
|
66 int flags;
|
|
67 demux_stream_t *ds = demuxer->audio;
|
|
68 sh_audio_t *sh = ds->sh;
|
|
69 WAVEFORMATEX *wf = sh->wf;
|
|
70 demux_packet_t *dp;
|
|
71
|
|
72 if (demuxer->stream->eof)
|
|
73 return 0;
|
|
74
|
|
75 len = wf->nBlockAlign;
|
|
76 demuxer->filepos = stream_tell(demuxer->stream);
|
|
77
|
|
78 dp = new_demux_packet(len);
|
|
79 stream_read(demuxer->stream, dp->buffer, len);
|
|
80
|
10035
|
81 dp->pts = demuxer->filepos / ra_priv->data_size;
|
10034
|
82 dp->pos = demuxer->filepos;
|
|
83 dp->flags = 0;
|
|
84 ds_add_packet(ds, dp);
|
|
85
|
|
86 return 1;
|
|
87 }
|
|
88
|
|
89
|
|
90
|
|
91 extern void print_wave_header(WAVEFORMATEX *h);
|
|
92
|
|
93
|
|
94
|
16175
|
95 static demuxer_t* demux_open_ra(demuxer_t* demuxer)
|
10034
|
96 {
|
|
97 ra_priv_t* ra_priv = demuxer->priv;
|
|
98 sh_audio_t *sh;
|
|
99 int i;
|
|
100 char *buf;
|
|
101
|
|
102 if ((ra_priv = (ra_priv_t *)malloc(sizeof(ra_priv_t))) == NULL) {
|
|
103 mp_msg(MSGT_DEMUX, MSGL_ERR, "[RealAudio] Can't allocate memory for private data.\n");
|
10232
|
104 return 0;
|
10034
|
105 }
|
|
106 memset(ra_priv, 0, sizeof(ra_priv_t));
|
|
107
|
|
108 demuxer->priv = ra_priv;
|
|
109 sh = new_sh_audio(demuxer, 0);
|
|
110 demuxer->audio->id = 0;
|
|
111 sh->ds=demuxer->audio;
|
|
112 demuxer->audio->sh = sh;
|
|
113
|
|
114 ra_priv->version = stream_read_word(demuxer->stream);
|
|
115 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] File version: %d\n", ra_priv->version);
|
|
116 if ((ra_priv->version < 3) || (ra_priv->version > 4)) {
|
|
117 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] ra version %d is not supported yet, please "
|
|
118 "contact MPlayer developers\n", ra_priv->version);
|
10232
|
119 return 0;
|
10034
|
120 }
|
|
121 if (ra_priv->version == 3) {
|
|
122 ra_priv->hdr_size = stream_read_word(demuxer->stream);
|
|
123 stream_skip(demuxer->stream, 10);
|
|
124 ra_priv->data_size = stream_read_dword(demuxer->stream);
|
|
125 } else {
|
|
126 stream_skip(demuxer->stream, 2);
|
|
127 ra_priv->dotranum = stream_read_dword(demuxer->stream);
|
|
128 ra_priv->data_size = stream_read_dword(demuxer->stream);
|
|
129 ra_priv->version2 = stream_read_word(demuxer->stream);
|
|
130 ra_priv->hdr_size = stream_read_dword(demuxer->stream);
|
|
131 ra_priv->codec_flavor = stream_read_word(demuxer->stream);
|
|
132 ra_priv->coded_framesize = stream_read_dword(demuxer->stream);
|
|
133 stream_skip(demuxer->stream, 4); // data size?
|
|
134 stream_skip(demuxer->stream, 8);
|
|
135 ra_priv->sub_packet_h = stream_read_word(demuxer->stream);
|
|
136 ra_priv->frame_size = stream_read_word(demuxer->stream);
|
|
137 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Frame size: %d\n", ra_priv->frame_size);
|
|
138 ra_priv->sub_packet_size = stream_read_word(demuxer->stream);
|
|
139 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Sub packet size: %d\n", ra_priv->sub_packet_size);
|
|
140 stream_skip(demuxer->stream, 2);
|
|
141 sh->samplerate = stream_read_word(demuxer->stream);
|
|
142 stream_skip(demuxer->stream, 2);
|
|
143 sh->samplesize = stream_read_word(demuxer->stream);
|
|
144 sh->channels = stream_read_word(demuxer->stream);
|
|
145 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] %d channel, %d bit, %dHz\n", sh->channels,
|
|
146 sh->samplesize, sh->samplerate);
|
|
147 i = stream_read_char(demuxer->stream);
|
|
148 *((unsigned int *)(ra_priv->genr)) = stream_read_dword(demuxer->stream);
|
|
149 if (i != 4) {
|
|
150 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] Genr size is not 4 (%d), please report to "
|
|
151 "MPlayer developers\n", i);
|
|
152 stream_skip(demuxer->stream, i - 4);
|
|
153 }
|
|
154 i = stream_read_char(demuxer->stream);
|
|
155 sh->format = stream_read_dword_le(demuxer->stream);
|
|
156 if (i != 4) {
|
|
157 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] FourCC size is not 4 (%d), please report to "
|
|
158 "MPlayer developers\n", i);
|
|
159 stream_skip(demuxer->stream, i - 4);
|
|
160 }
|
|
161 stream_skip(demuxer->stream, 3);
|
|
162 }
|
|
163
|
|
164 if ((i = stream_read_char(demuxer->stream)) != 0) {
|
|
165 buf = malloc(i+1);
|
|
166 stream_read(demuxer->stream, buf, i);
|
|
167 buf[i] = 0;
|
|
168 demux_info_add(demuxer, "Title", buf);
|
|
169 free(buf);
|
|
170 }
|
|
171 if ((i = stream_read_char(demuxer->stream)) != 0) {
|
|
172 buf = malloc(i+1);
|
|
173 stream_read(demuxer->stream, buf, i);
|
|
174 buf[i] = 0;
|
|
175 demux_info_add(demuxer, "Author", buf);
|
|
176 free(buf);
|
|
177 }
|
|
178 if ((i = stream_read_char(demuxer->stream)) != 0) {
|
|
179 buf = malloc(i+1);
|
|
180 stream_read(demuxer->stream, buf, i);
|
|
181 buf[i] = 0;
|
|
182 demux_info_add(demuxer, "Copyright", buf);
|
|
183 free(buf);
|
|
184 }
|
|
185
|
14908
|
186 if ((i = stream_read_char(demuxer->stream)) != 0) {
|
|
187 buf = malloc(i+1);
|
|
188 stream_read(demuxer->stream, buf, i);
|
|
189 buf[i] = 0;
|
|
190 demux_info_add(demuxer, "Comment", buf);
|
|
191 free(buf);
|
|
192 }
|
10034
|
193
|
|
194 if (ra_priv->version == 3) {
|
14909
|
195 if(ra_priv->hdr_size + 8 > stream_tell(demuxer->stream)) {
|
10034
|
196 stream_skip(demuxer->stream, 1);
|
|
197 i = stream_read_char(demuxer->stream);
|
|
198 sh->format = stream_read_dword_le(demuxer->stream);
|
|
199 if (i != 4) {
|
|
200 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] FourCC size is not 4 (%d), please report to "
|
|
201 "MPlayer developers\n", i);
|
|
202 stream_skip(demuxer->stream, i - 4);
|
|
203 }
|
|
204
|
|
205 if (sh->format != FOURCC_LPCJ) {
|
|
206 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] Version 3 with FourCC %8x, please report to "
|
|
207 "MPlayer developers\n", sh->format);
|
|
208 }
|
14909
|
209 } else
|
|
210 // If a stream does not have fourcc, let's assume it's 14.4
|
|
211 sh->format = FOURCC_LPCJ;
|
10034
|
212
|
|
213 sh->channels = 1;
|
|
214 sh->samplesize = 16;
|
|
215 sh->samplerate = 8000;
|
|
216 ra_priv->frame_size = 240;
|
|
217 sh->format = FOURCC_144;
|
|
218 }
|
|
219
|
|
220 /* Fill WAVEFORMATEX */
|
|
221 sh->wf = malloc(sizeof(WAVEFORMATEX));
|
|
222 memset(sh->wf, 0, sizeof(WAVEFORMATEX));
|
|
223 sh->wf->nChannels = sh->channels;
|
|
224 sh->wf->wBitsPerSample = sh->samplesize;
|
|
225 sh->wf->nSamplesPerSec = sh->samplerate;
|
|
226 sh->wf->nAvgBytesPerSec = sh->samplerate*sh->samplesize/8;
|
|
227 sh->wf->nBlockAlign = ra_priv->frame_size;
|
|
228 sh->wf->cbSize = 0;
|
|
229 sh->wf->wFormatTag = sh->format;
|
|
230
|
|
231 switch (sh->format) {
|
|
232 case FOURCC_144:
|
|
233 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: 14_4\n");
|
|
234 sh->wf->cbSize = 10/*+codecdata_length*/;
|
|
235 sh->wf = realloc(sh->wf, sizeof(WAVEFORMATEX)+sh->wf->cbSize);
|
|
236 ((short*)(sh->wf+1))[0]=0;
|
|
237 ((short*)(sh->wf+1))[1]=240;
|
|
238 ((short*)(sh->wf+1))[2]=0;
|
|
239 ((short*)(sh->wf+1))[3]=0x14;
|
|
240 ((short*)(sh->wf+1))[4]=0;
|
|
241 break;
|
|
242 case FOURCC_288:
|
|
243 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: 28_8\n");
|
11544
|
244 sh->wf->cbSize = 10/*+codecdata_length*/;
|
10034
|
245 sh->wf = realloc(sh->wf, sizeof(WAVEFORMATEX)+sh->wf->cbSize);
|
|
246 ((short*)(sh->wf+1))[0]=0;
|
|
247 ((short*)(sh->wf+1))[1]=ra_priv->sub_packet_h;
|
|
248 ((short*)(sh->wf+1))[2]=ra_priv->codec_flavor;
|
|
249 ((short*)(sh->wf+1))[3]=ra_priv->coded_framesize;
|
|
250 ((short*)(sh->wf+1))[4]=0;
|
|
251 break;
|
|
252 case FOURCC_DNET:
|
|
253 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: DNET -> AC3\n");
|
|
254 break;
|
|
255 default:
|
|
256 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: Unknown (%d)\n", sh->format);
|
|
257 }
|
|
258
|
|
259 print_wave_header(sh->wf);
|
|
260
|
|
261 /* disable seeking */
|
|
262 demuxer->seekable = 0;
|
|
263
|
|
264 if(!ds_fill_buffer(demuxer->audio))
|
|
265 mp_msg(MSGT_DEMUXER,MSGL_INFO,"[RealAudio] No data.\n");
|
10232
|
266
|
16175
|
267 return demuxer;
|
10034
|
268 }
|
|
269
|
|
270
|
|
271
|
16175
|
272 static void demux_close_ra(demuxer_t *demuxer)
|
10034
|
273 {
|
|
274 ra_priv_t* ra_priv = demuxer->priv;
|
|
275
|
|
276 if (ra_priv)
|
|
277 free(ra_priv);
|
|
278
|
|
279 return;
|
|
280 }
|
|
281
|
|
282
|
|
283 #if 0
|
|
284 /* please upload RV10 samples WITH INDEX CHUNK */
|
|
285 int demux_seek_ra(demuxer_t *demuxer, float rel_seek_secs, int flags)
|
|
286 {
|
|
287 real_priv_t *priv = demuxer->priv;
|
|
288 demux_stream_t *d_audio = demuxer->audio;
|
|
289 sh_audio_t *sh_audio = d_audio->sh;
|
|
290 int aid = d_audio->id;
|
|
291 int next_offset = 0;
|
|
292 int rel_seek_frames = 0;
|
|
293 int streams = 0;
|
|
294
|
|
295 return stream_seek(demuxer->stream, next_offset);
|
|
296 }
|
|
297 #endif
|
16175
|
298
|
|
299
|
|
300 demuxer_desc_t demuxer_desc_realaudio = {
|
|
301 "Realaudio demuxer",
|
|
302 "realaudio",
|
|
303 "REALAUDIO",
|
|
304 "Roberto Togni",
|
|
305 "handles old audio only .ra files",
|
|
306 DEMUXER_TYPE_REALAUDIO,
|
|
307 1, // safe autodetect
|
|
308 ra_check_file,
|
|
309 demux_ra_fill_buffer,
|
|
310 demux_open_ra,
|
|
311 demux_close_ra,
|
|
312 NULL,
|
|
313 NULL
|
|
314 };
|