From: Francois B <mrs...@us...> - 2005-08-21 21:55:00
|
Update of /cvsroot/openneo/openneo/firmware In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4684 Modified Files: mp3.c Log Message: Changed find next frame function Index: mp3.c =================================================================== RCS file: /cvsroot/openneo/openneo/firmware/mp3.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mp3.c 20 Jul 2005 02:02:36 -0000 1.3 --- mp3.c 21 Aug 2005 21:54:50 -0000 1.4 *************** *** 96,152 **** } ! /* Finds and reads the next frame header */ ! unsigned int mpeg_find_next_frame(int fd) { ! unsigned char buffer[128]; ! unsigned char *ptr; ! unsigned int header; ! int i,count; ! ! /* Because the MAS 3507D supports mpeg 2.5 ! We only use the first 11 bits to sync ourselves */ ! ! while(1){ ! ! count = read(fd,buffer,128); ! if( count != 128 ) ! break; ! ptr = buffer; ! ! for( i=0; i< count && *ptr != 0xff; i++ ) ! ptr++; ! if( *ptr == 0xff && (i < count) ) { ! ! //is the last byte our 0xff? ! if( (ptr-buffer) == 127 ){ ! lseek(fd, -1, SEEK_CUR); ! continue; //Read another block ! } ! ! //Check the next byte ! if( (ptr[1] & 0xe0) == 0xe0) { ! //msg_error( "maybe %d", lseek(fd, 0, SEEK_CUR) - 128 - (ptr-buffer)); ! ! /* We found a possible frame ! Position file cursor at the beginning */ ! lseek(fd,(ptr-buffer) - 128, SEEK_CUR); ! if( read(fd,&header,4) != 4 ) ! return 0; ! //msg_error( "maybeh %x", header ); ! //Validate frame header ! if( is_validframeheader(header)) ! return header; ! } ! ptr++; } ! } ! ! return 0; } --- 96,159 ---- } ! /* Finds and reads the next frame header ! ! Possible return values: ! -1 : Read error ! 0 : Reached the end of the file ! 1 : A valid header was found */ ! ! int mpeg_find_next_frame(int fd, unsigned int *header) { ! unsigned char buffer[128]; ! unsigned char *ptr; ! int bytes_read, i; ! /* Because the MAS 3507D supports mpeg 2.5 ! We only use the first 11 bits to sync ourselves */ ! while(1){ ! bytes_read = read(fd,buffer,128); ! if( bytes_read < 0 ) ! return -1; ! ! if( !bytes_read ) ! break; ! ptr = buffer; ! //Analyse our buffer ! for( i=0; i< bytes_read; i++ ) { ! ! if( *ptr == 0xff ) { ! ! //is this the last byte of the buffer? ! if( i == (bytes_read-1) ){ ! lseek(fd, -1, SEEK_CUR); ! break; //Exit the for loop ! } ! //Check the next byte ! if( (ptr[1] & 0xe0) == 0xe0) { ! ! /* We found a possible frame ! Position file cursor at the beginning */ ! lseek(fd,(ptr-buffer) - bytes_read, SEEK_CUR); ! if( read(fd,header,4) == 4 ) { ! ! //Validate frame header ! if( is_validframeheader(*header)) ! return 1; ! } ! else ! return -1; ! } ! } ! ! ptr++; ! } } ! ! return 0; } *************** *** 196,202 **** static unsigned char frame[1800]; ! /* Calculates the length in bytes of the frame ! Because the MAS only support layer 2 and 3 ! we expect a layer 2 or 3 header */ unsigned int mpeg_frame_length( unsigned int header ) { --- 203,209 ---- static unsigned char frame[1800]; ! /* Calculates the length in bytes of the frame including the header ! Because the MAS only support layer 2 and 3 we expect a layer ! 2 or 3 header */ unsigned int mpeg_frame_length( unsigned int header ) { *************** *** 226,231 **** memset(mpeg, 0, sizeof(struct mpeg_info)); ! header = mpeg_find_next_frame(fd); ! if(!header) return -1; --- 233,237 ---- memset(mpeg, 0, sizeof(struct mpeg_info)); ! if( mpeg_find_next_frame(fd, &header) != 1 ) return -1; *************** *** 293,299 **** if( !is_validframeheader(header)) { ! header = mpeg_find_next_frame(fd); ! if(!header) ! return -1; } } --- 299,304 ---- if( !is_validframeheader(header)) { ! if( mpeg_find_next_frame(fd, &header) != 1 ) ! break; } } *************** *** 337,341 **** unsigned int header; ! header = mpeg_find_next_frame(fd); while( is_validframeheader(header) ) { --- 342,347 ---- unsigned int header; ! if( mpeg_find_next_frame(fd, &header) != 1 ) ! return 0; while( is_validframeheader(header) ) { |