comparison 4xm.c @ 145:4f3960430e54 libavformat

4xm adpcm
author michaelni
date Tue, 03 Jun 2003 13:58:44 +0000
parents 9e73bf732800
children bca5abd97e43
comparison
equal deleted inserted replaced
144:9e73bf732800 145:4f3960430e54
69 typedef struct AudioTrack { 69 typedef struct AudioTrack {
70 int sample_rate; 70 int sample_rate;
71 int bits; 71 int bits;
72 int channels; 72 int channels;
73 int stream_index; 73 int stream_index;
74 int adpcm;
74 } AudioTrack; 75 } AudioTrack;
75 76
76 typedef struct FourxmDemuxContext { 77 typedef struct FourxmDemuxContext {
77 int width; 78 int width;
78 int height; 79 int height;
170 if (!fourxm->tracks) { 171 if (!fourxm->tracks) {
171 av_free(header); 172 av_free(header);
172 return AVERROR_NOMEM; 173 return AVERROR_NOMEM;
173 } 174 }
174 } 175 }
176 fourxm->tracks[current_track].adpcm = LE_32(&header[i + 12]);
175 fourxm->tracks[current_track].channels = LE_32(&header[i + 36]); 177 fourxm->tracks[current_track].channels = LE_32(&header[i + 36]);
176 fourxm->tracks[current_track].sample_rate = LE_32(&header[i + 40]); 178 fourxm->tracks[current_track].sample_rate = LE_32(&header[i + 40]);
177 fourxm->tracks[current_track].bits = LE_32(&header[i + 44]); 179 fourxm->tracks[current_track].bits = LE_32(&header[i + 44]);
180 printf("bps:%d\n", fourxm->tracks[current_track].bits);
178 i += 8 + size; 181 i += 8 + size;
179 182
180 /* allocate a new AVStream */ 183 /* allocate a new AVStream */
181 st = av_new_stream(s, current_track); 184 st = av_new_stream(s, current_track);
182 if (!st) 185 if (!st)
190 st->codec.sample_rate = fourxm->tracks[current_track].sample_rate; 193 st->codec.sample_rate = fourxm->tracks[current_track].sample_rate;
191 st->codec.bits_per_sample = fourxm->tracks[current_track].bits; 194 st->codec.bits_per_sample = fourxm->tracks[current_track].bits;
192 st->codec.bit_rate = st->codec.channels * st->codec.sample_rate * 195 st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
193 st->codec.bits_per_sample; 196 st->codec.bits_per_sample;
194 st->codec.block_align = st->codec.channels * st->codec.bits_per_sample; 197 st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
195 if (st->codec.bits_per_sample == 8) 198 if (fourxm->tracks[current_track].adpcm)
199 st->codec.codec_id = CODEC_ID_ADPCM_4XM;
200 else if (st->codec.bits_per_sample == 8)
196 st->codec.codec_id = CODEC_ID_PCM_U8; 201 st->codec.codec_id = CODEC_ID_PCM_U8;
197 else 202 else
198 st->codec.codec_id = CODEC_ID_PCM_S16LE; 203 st->codec.codec_id = CODEC_ID_PCM_S16LE;
199 } 204 }
200 } 205 }
222 AVPacket *pkt) 227 AVPacket *pkt)
223 { 228 {
224 FourxmDemuxContext *fourxm = s->priv_data; 229 FourxmDemuxContext *fourxm = s->priv_data;
225 ByteIOContext *pb = &s->pb; 230 ByteIOContext *pb = &s->pb;
226 unsigned int fourcc_tag; 231 unsigned int fourcc_tag;
227 unsigned int size; 232 unsigned int size, out_size;
228 int ret = 0; 233 int ret = 0;
229 int track_number; 234 int track_number;
230 int packet_read = 0; 235 int packet_read = 0;
231 unsigned char header[8]; 236 unsigned char header[8];
232 int64_t pts_inc; 237 int64_t pts_inc;
235 240
236 if ((ret = get_buffer(&s->pb, header, 8)) < 0) 241 if ((ret = get_buffer(&s->pb, header, 8)) < 0)
237 return ret; 242 return ret;
238 fourcc_tag = LE_32(&header[0]); 243 fourcc_tag = LE_32(&header[0]);
239 size = LE_32(&header[4]); 244 size = LE_32(&header[4]);
240 245 //printf(" %8X %c%c%c%c %d\n", fourcc_tag, fourcc_tag, fourcc_tag>>8, fourcc_tag>>16, fourcc_tag>>24, size);
241 if (url_feof(pb)) 246 if (url_feof(pb))
242 return -EIO; 247 return -EIO;
243
244 switch (fourcc_tag) { 248 switch (fourcc_tag) {
245 249
246 case LIST_TAG: 250 case LIST_TAG:
247 /* skip the LIST-* tag and move on to the next fourcc */ 251 /* skip the LIST-* tag and move on to the next fourcc */
248 get_le32(pb); 252 get_le32(pb);
275 279
276 if (fourcc_tag == cfrm_TAG) { 280 if (fourcc_tag == cfrm_TAG) {
277 id = LE_32(&pkt->data[12]); 281 id = LE_32(&pkt->data[12]);
278 whole = LE_32(&pkt->data[16]); 282 whole = LE_32(&pkt->data[16]);
279 stats[id] += size - 12; 283 stats[id] += size - 12;
280 printf(" cfrm chunk id:%d size:%d whole:%d until now:%d\n", id, size, whole, stats[id]); 284 //printf(" cfrm chunk id:%d size:%d whole:%d until now:%d\n", id, size, whole, stats[id]);
281 } 285 }
282 286
283 if (ret < 0) 287 if (ret < 0)
284 av_free_packet(pkt); 288 av_free_packet(pkt);
285 else 289 else
288 } 292 }
289 293
290 case snd__TAG: 294 case snd__TAG:
291 printf (" snd_ chunk, "); 295 printf (" snd_ chunk, ");
292 track_number = get_le32(pb); 296 track_number = get_le32(pb);
293 size = get_le32(pb); 297 out_size= get_le32(pb);
298 size-=8;
299
294 if (track_number == fourxm->selected_track) { 300 if (track_number == fourxm->selected_track) {
295 printf ("correct track, dispatching...\n"); 301 printf ("correct track, dispatching...\n");
296 if (av_new_packet(pkt, size)) 302 if (av_new_packet(pkt, size))
297 return -EIO; 303 return -EIO;
298 pkt->stream_index = 304 pkt->stream_index =
319 default: 325 default:
320 url_fseek(pb, size, SEEK_CUR); 326 url_fseek(pb, size, SEEK_CUR);
321 break; 327 break;
322 } 328 }
323 } 329 }
324
325 return ret; 330 return ret;
326 } 331 }
327 332
328 static int fourxm_read_close(AVFormatContext *s) 333 static int fourxm_read_close(AVFormatContext *s)
329 { 334 {