comparison westwood.c @ 1673:a782462e2497 libavformat

rename BE/LE_8/16/32 to AV_RL/B_8/16/32
author alex
date Fri, 19 Jan 2007 22:12:59 +0000
parents 4cb185273d4b
children 2f0154760e5f
comparison
equal deleted inserted replaced
1672:818eafa8fc95 1673:a782462e2497
99 99
100 if (p->buf_size < AUD_HEADER_SIZE) 100 if (p->buf_size < AUD_HEADER_SIZE)
101 return 0; 101 return 0;
102 102
103 /* check sample rate */ 103 /* check sample rate */
104 field = LE_16(&p->buf[0]); 104 field = AV_RL16(&p->buf[0]);
105 if ((field < 8000) || (field > 48000)) 105 if ((field < 8000) || (field > 48000))
106 return 0; 106 return 0;
107 107
108 /* note: only check for WS IMA (type 99) right now since there is no 108 /* note: only check for WS IMA (type 99) right now since there is no
109 * support for type 1 */ 109 * support for type 1 */
122 AVStream *st; 122 AVStream *st;
123 unsigned char header[AUD_HEADER_SIZE]; 123 unsigned char header[AUD_HEADER_SIZE];
124 124
125 if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE) 125 if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE)
126 return AVERROR_IO; 126 return AVERROR_IO;
127 wsaud->audio_samplerate = LE_16(&header[0]); 127 wsaud->audio_samplerate = AV_RL16(&header[0]);
128 if (header[11] == 99) 128 if (header[11] == 99)
129 wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS; 129 wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS;
130 else 130 else
131 return AVERROR_INVALIDDATA; 131 return AVERROR_INVALIDDATA;
132 132
168 if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != 168 if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
169 AUD_CHUNK_PREAMBLE_SIZE) 169 AUD_CHUNK_PREAMBLE_SIZE)
170 return AVERROR_IO; 170 return AVERROR_IO;
171 171
172 /* validate the chunk */ 172 /* validate the chunk */
173 if (LE_32(&preamble[4]) != AUD_CHUNK_SIGNATURE) 173 if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE)
174 return AVERROR_INVALIDDATA; 174 return AVERROR_INVALIDDATA;
175 175
176 chunk_size = LE_16(&preamble[0]); 176 chunk_size = AV_RL16(&preamble[0]);
177 ret= av_get_packet(pb, pkt, chunk_size); 177 ret= av_get_packet(pb, pkt, chunk_size);
178 if (ret != chunk_size) 178 if (ret != chunk_size)
179 return AVERROR_IO; 179 return AVERROR_IO;
180 pkt->stream_index = wsaud->audio_stream_index; 180 pkt->stream_index = wsaud->audio_stream_index;
181 pkt->pts = wsaud->audio_frame_counter; 181 pkt->pts = wsaud->audio_frame_counter;
200 /* need 12 bytes to qualify */ 200 /* need 12 bytes to qualify */
201 if (p->buf_size < 12) 201 if (p->buf_size < 12)
202 return 0; 202 return 0;
203 203
204 /* check for the VQA signatures */ 204 /* check for the VQA signatures */
205 if ((BE_32(&p->buf[0]) != FORM_TAG) || 205 if ((AV_RB32(&p->buf[0]) != FORM_TAG) ||
206 (BE_32(&p->buf[8]) != WVQA_TAG)) 206 (AV_RB32(&p->buf[8]) != WVQA_TAG))
207 return 0; 207 return 0;
208 208
209 return AVPROBE_SCORE_MAX; 209 return AVPROBE_SCORE_MAX;
210 } 210 }
211 211
240 if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) != 240 if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
241 VQA_HEADER_SIZE) { 241 VQA_HEADER_SIZE) {
242 av_free(st->codec->extradata); 242 av_free(st->codec->extradata);
243 return AVERROR_IO; 243 return AVERROR_IO;
244 } 244 }
245 st->codec->width = LE_16(&header[6]); 245 st->codec->width = AV_RL16(&header[6]);
246 st->codec->height = LE_16(&header[8]); 246 st->codec->height = AV_RL16(&header[8]);
247 247
248 /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */ 248 /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */
249 if (LE_16(&header[24]) || (LE_16(&header[0]) == 1 && LE_16(&header[2]) == 1)) { 249 if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) {
250 st = av_new_stream(s, 0); 250 st = av_new_stream(s, 0);
251 if (!st) 251 if (!st)
252 return AVERROR_NOMEM; 252 return AVERROR_NOMEM;
253 av_set_pts_info(st, 33, 1, VQA_FRAMERATE); 253 av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
254 st->codec->codec_type = CODEC_TYPE_AUDIO; 254 st->codec->codec_type = CODEC_TYPE_AUDIO;
255 if (LE_16(&header[0]) == 1) 255 if (AV_RL16(&header[0]) == 1)
256 st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; 256 st->codec->codec_id = CODEC_ID_WESTWOOD_SND1;
257 else 257 else
258 st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; 258 st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS;
259 st->codec->codec_tag = 0; /* no tag */ 259 st->codec->codec_tag = 0; /* no tag */
260 st->codec->sample_rate = LE_16(&header[24]); 260 st->codec->sample_rate = AV_RL16(&header[24]);
261 if (!st->codec->sample_rate) 261 if (!st->codec->sample_rate)
262 st->codec->sample_rate = 22050; 262 st->codec->sample_rate = 22050;
263 st->codec->channels = header[26]; 263 st->codec->channels = header[26];
264 if (!st->codec->channels) 264 if (!st->codec->channels)
265 st->codec->channels = 1; 265 st->codec->channels = 1;
279 do { 279 do {
280 if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) { 280 if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
281 av_free(st->codec->extradata); 281 av_free(st->codec->extradata);
282 return AVERROR_IO; 282 return AVERROR_IO;
283 } 283 }
284 chunk_tag = BE_32(&scratch[0]); 284 chunk_tag = AV_RB32(&scratch[0]);
285 chunk_size = BE_32(&scratch[4]); 285 chunk_size = AV_RB32(&scratch[4]);
286 286
287 /* catch any unknown header tags, for curiousity */ 287 /* catch any unknown header tags, for curiousity */
288 switch (chunk_tag) { 288 switch (chunk_tag) {
289 case CINF_TAG: 289 case CINF_TAG:
290 case CINH_TAG: 290 case CINH_TAG:
321 unsigned int chunk_type; 321 unsigned int chunk_type;
322 unsigned int chunk_size; 322 unsigned int chunk_size;
323 int skip_byte; 323 int skip_byte;
324 324
325 while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) { 325 while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) {
326 chunk_type = BE_32(&preamble[0]); 326 chunk_type = AV_RB32(&preamble[0]);
327 chunk_size = BE_32(&preamble[4]); 327 chunk_size = AV_RB32(&preamble[4]);
328 skip_byte = chunk_size & 0x01; 328 skip_byte = chunk_size & 0x01;
329 329
330 if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) { 330 if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) {
331 331
332 if (av_new_packet(pkt, chunk_size)) 332 if (av_new_packet(pkt, chunk_size))
342 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ 342 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
343 wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels; 343 wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels;
344 } else if(chunk_type == SND1_TAG) { 344 } else if(chunk_type == SND1_TAG) {
345 pkt->stream_index = wsvqa->audio_stream_index; 345 pkt->stream_index = wsvqa->audio_stream_index;
346 /* unpacked size is stored in header */ 346 /* unpacked size is stored in header */
347 wsvqa->audio_frame_counter += LE_16(pkt->data) / wsvqa->audio_channels; 347 wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels;
348 } else { 348 } else {
349 pkt->stream_index = wsvqa->video_stream_index; 349 pkt->stream_index = wsvqa->video_stream_index;
350 wsvqa->video_pts += VQA_VIDEO_PTS_INC; 350 wsvqa->video_pts += VQA_VIDEO_PTS_INC;
351 } 351 }
352 /* stay on 16-bit alignment */ 352 /* stay on 16-bit alignment */