comparison mp3lib/sr1.c @ 22140:0cd17afe1d4b

Make sure buffer is aligned so no unaligned access happens.
author reimar
date Mon, 05 Feb 2007 19:24:03 +0000
parents fa99b3d31d13
children 84eaacdc380d
comparison
equal deleted inserted replaced
22139:3a3effa718fd 22140:0cd17afe1d4b
313 /***************************************************************** 313 /*****************************************************************
314 * read next frame return number of frames read. 314 * read next frame return number of frames read.
315 */ 315 */
316 LOCAL int read_frame(struct frame *fr){ 316 LOCAL int read_frame(struct frame *fr){
317 unsigned long newhead; 317 unsigned long newhead;
318 unsigned char hbuf[8]; 318 union {
319 unsigned char buf[8];
320 unsigned long dummy; // for alignment
321 } hbuf;
319 int skipped,resyncpos; 322 int skipped,resyncpos;
320 int frames=0; 323 int frames=0;
321 324
322 resync: 325 resync:
323 skipped=MP3_fpos; 326 skipped=MP3_fpos;
324 resyncpos=MP3_fpos; 327 resyncpos=MP3_fpos;
325 328
326 set_pointer(512); 329 set_pointer(512);
327 fsizeold=fr->framesize; /* for Layer3 */ 330 fsizeold=fr->framesize; /* for Layer3 */
328 if(!stream_head_read(hbuf,&newhead)) return 0; 331 if(!stream_head_read(hbuf.buf,&newhead)) return 0;
329 if(!decode_header(fr,newhead)){ 332 if(!decode_header(fr,newhead)){
330 // invalid header! try to resync stream! 333 // invalid header! try to resync stream!
331 #ifdef DEBUG_RESYNC 334 #ifdef DEBUG_RESYNC
332 printf("ReSync: searching for a valid header... (pos=%X)\n",MP3_fpos); 335 printf("ReSync: searching for a valid header... (pos=%X)\n",MP3_fpos);
333 #endif 336 #endif
334 retry1: 337 retry1:
335 while(!decode_header(fr,newhead)){ 338 while(!decode_header(fr,newhead)){
336 if(!stream_head_shift(hbuf,&newhead)) return 0; 339 if(!stream_head_shift(hbuf.buf,&newhead)) return 0;
337 } 340 }
338 resyncpos=MP3_fpos-4; 341 resyncpos=MP3_fpos-4;
339 // found valid header 342 // found valid header
340 #ifdef DEBUG_RESYNC 343 #ifdef DEBUG_RESYNC
341 printf("ReSync: found valid hdr at %X fsize=%ld ",resyncpos,fr->framesize); 344 printf("ReSync: found valid hdr at %X fsize=%ld ",resyncpos,fr->framesize);
342 #endif 345 #endif
343 if(!stream_read_frame_body(fr->framesize)) return 0; // read body 346 if(!stream_read_frame_body(fr->framesize)) return 0; // read body
344 set_pointer(512); 347 set_pointer(512);
345 fsizeold=fr->framesize; /* for Layer3 */ 348 fsizeold=fr->framesize; /* for Layer3 */
346 if(!stream_head_read(hbuf,&newhead)) return 0; 349 if(!stream_head_read(hbuf.buf,&newhead)) return 0;
347 if(!decode_header(fr,newhead)){ 350 if(!decode_header(fr,newhead)){
348 // invalid hdr! go back... 351 // invalid hdr! go back...
349 #ifdef DEBUG_RESYNC 352 #ifdef DEBUG_RESYNC
350 printf("INVALID\n"); 353 printf("INVALID\n");
351 #endif 354 #endif
352 // mp3_seek(resyncpos+1); 355 // mp3_seek(resyncpos+1);
353 if(!stream_head_read(hbuf,&newhead)) return 0; 356 if(!stream_head_read(hbuf.buf,&newhead)) return 0;
354 goto retry1; 357 goto retry1;
355 } 358 }
356 #ifdef DEBUG_RESYNC 359 #ifdef DEBUG_RESYNC
357 printf("OK!\n"); 360 printf("OK!\n");
358 ++frames; 361 ++frames;