10034
|
1 /*
|
|
2 Realaudio demuxer for MPlayer
|
|
3 (c) 2003 Roberto Togni
|
|
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
|
|
43 int ra_check_file(demuxer_t* demuxer)
|
|
44 {
|
|
45 unsigned int chunk_id;
|
|
46
|
|
47 chunk_id = stream_read_dword_le(demuxer->stream);
|
|
48 if (chunk_id == FOURCC_DOTRA)
|
|
49 return 1;
|
|
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
|
|
61 int demux_ra_fill_buffer(demuxer_t *demuxer)
|
|
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
|
10232
|
95 int 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
|
|
186 if ((i = stream_read_char(demuxer->stream)) != 0)
|
|
187 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] Last header byte is not zero!\n");
|
|
188
|
|
189 if (ra_priv->version == 3) {
|
|
190 stream_skip(demuxer->stream, 1);
|
|
191 i = stream_read_char(demuxer->stream);
|
|
192 sh->format = stream_read_dword_le(demuxer->stream);
|
|
193 if (i != 4) {
|
|
194 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] FourCC size is not 4 (%d), please report to "
|
|
195 "MPlayer developers\n", i);
|
|
196 stream_skip(demuxer->stream, i - 4);
|
|
197 }
|
|
198 // stream_skip(demuxer->stream, 3);
|
|
199
|
|
200 if (sh->format != FOURCC_LPCJ) {
|
|
201 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] Version 3 with FourCC %8x, please report to "
|
|
202 "MPlayer developers\n", sh->format);
|
|
203 }
|
|
204
|
|
205 sh->channels = 1;
|
|
206 sh->samplesize = 16;
|
|
207 sh->samplerate = 8000;
|
|
208 ra_priv->frame_size = 240;
|
|
209 sh->format = FOURCC_144;
|
|
210 }
|
|
211
|
|
212 /* Fill WAVEFORMATEX */
|
|
213 sh->wf = malloc(sizeof(WAVEFORMATEX));
|
|
214 memset(sh->wf, 0, sizeof(WAVEFORMATEX));
|
|
215 sh->wf->nChannels = sh->channels;
|
|
216 sh->wf->wBitsPerSample = sh->samplesize;
|
|
217 sh->wf->nSamplesPerSec = sh->samplerate;
|
|
218 sh->wf->nAvgBytesPerSec = sh->samplerate*sh->samplesize/8;
|
|
219 sh->wf->nBlockAlign = ra_priv->frame_size;
|
|
220 sh->wf->cbSize = 0;
|
|
221 sh->wf->wFormatTag = sh->format;
|
|
222
|
|
223 switch (sh->format) {
|
|
224 case FOURCC_144:
|
|
225 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: 14_4\n");
|
|
226 sh->wf->cbSize = 10/*+codecdata_length*/;
|
|
227 sh->wf = realloc(sh->wf, sizeof(WAVEFORMATEX)+sh->wf->cbSize);
|
|
228 ((short*)(sh->wf+1))[0]=0;
|
|
229 ((short*)(sh->wf+1))[1]=240;
|
|
230 ((short*)(sh->wf+1))[2]=0;
|
|
231 ((short*)(sh->wf+1))[3]=0x14;
|
|
232 ((short*)(sh->wf+1))[4]=0;
|
|
233 break;
|
|
234 case FOURCC_288:
|
|
235 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: 28_8\n");
|
11544
|
236 sh->wf->cbSize = 10/*+codecdata_length*/;
|
10034
|
237 sh->wf = realloc(sh->wf, sizeof(WAVEFORMATEX)+sh->wf->cbSize);
|
|
238 ((short*)(sh->wf+1))[0]=0;
|
|
239 ((short*)(sh->wf+1))[1]=ra_priv->sub_packet_h;
|
|
240 ((short*)(sh->wf+1))[2]=ra_priv->codec_flavor;
|
|
241 ((short*)(sh->wf+1))[3]=ra_priv->coded_framesize;
|
|
242 ((short*)(sh->wf+1))[4]=0;
|
|
243 break;
|
|
244 case FOURCC_DNET:
|
|
245 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: DNET -> AC3\n");
|
|
246 break;
|
|
247 default:
|
|
248 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: Unknown (%d)\n", sh->format);
|
|
249 }
|
|
250
|
|
251 print_wave_header(sh->wf);
|
|
252
|
|
253 /* disable seeking */
|
|
254 demuxer->seekable = 0;
|
|
255
|
|
256 if(!ds_fill_buffer(demuxer->audio))
|
|
257 mp_msg(MSGT_DEMUXER,MSGL_INFO,"[RealAudio] No data.\n");
|
10232
|
258
|
|
259 return 1;
|
10034
|
260 }
|
|
261
|
|
262
|
|
263
|
|
264 void demux_close_ra(demuxer_t *demuxer)
|
|
265 {
|
|
266 ra_priv_t* ra_priv = demuxer->priv;
|
|
267
|
|
268 if (ra_priv)
|
|
269 free(ra_priv);
|
|
270
|
|
271 return;
|
|
272 }
|
|
273
|
|
274
|
|
275 #if 0
|
|
276 /* please upload RV10 samples WITH INDEX CHUNK */
|
|
277 int demux_seek_ra(demuxer_t *demuxer, float rel_seek_secs, int flags)
|
|
278 {
|
|
279 real_priv_t *priv = demuxer->priv;
|
|
280 demux_stream_t *d_audio = demuxer->audio;
|
|
281 sh_audio_t *sh_audio = d_audio->sh;
|
|
282 int aid = d_audio->id;
|
|
283 int next_offset = 0;
|
|
284 int rel_seek_frames = 0;
|
|
285 int streams = 0;
|
|
286
|
|
287 return stream_seek(demuxer->stream, next_offset);
|
|
288 }
|
|
289 #endif
|