⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aac_utils.c

📁 the mpeg2/4 aac decoder
💻 C
字号:
/* * * utils for AAC informations*/#include <glib.h>#include <stdio.h>#include <stdlib.h>#define ADTS_HEADER_SIZE        8#define SEEK_TABLE_CHUNK        60#define MPEG4_TYPE              0#define MPEG2_TYPE              1// Read ADTS header, the file descriptor must be at// the begining of the aac frame not at the id3tagint	getAacInfo(FILE *fd){  unsigned char	header[ADTS_HEADER_SIZE];  unsigned int	id;  unsigned long	originPosition;    originPosition = ftell(fd);  if(fread(header, 1, ADTS_HEADER_SIZE, fd) != ADTS_HEADER_SIZE){    fseek(fd, originPosition, SEEK_SET);    return(-1);  }  if(!((header[0]==0xFF)&&((header[1]& 0xF6)==0xF0))){    printf("Bad header\n");    return(-1);  }  id = header[1]&0x08;  if(id==0){//MPEG-4 AAC    fseek(fd, originPosition, SEEK_SET);    return(MPEG4_TYPE);  }else{    fseek(fd, originPosition, SEEK_SET);    return(MPEG2_TYPE);  }  fseek(fd, originPosition, SEEK_SET);  return(-1);}// as AAC is VBR we need to check all ADTS header// to enable seeking...// there is no other solutionvoid	checkADTSForSeeking(FILE *fd,			    unsigned long **seekTable,			    unsigned long *seekTableLength){  unsigned long	originPosition;  unsigned long	position;  unsigned char	header[ADTS_HEADER_SIZE];  unsigned int	frameCount, frameLength, frameInsec;  unsigned int	id=0, seconds=0;  originPosition = ftell(fd);  for(frameCount=0,frameInsec=0;; frameCount++,frameInsec++){    position = ftell(fd);    if(fread(header, 1, ADTS_HEADER_SIZE, fd)!=ADTS_HEADER_SIZE){      break;    }    if(!strncmp(header, "ID3", 3)){      break;    }    if(!((header[0]==0xFF)&&((header[1]& 0xF6)==0xF0))){      printf("error : Bad 1st header, file may be corrupt !\n");      break;    }    if(!frameCount){      id=header[1]&0x08;      if(((*seekTable) = malloc(SEEK_TABLE_CHUNK * sizeof(unsigned long)))==0){	printf("malloc error\n");	return;      }      (*seekTableLength) = SEEK_TABLE_CHUNK;    }    //if(id==0){//MPEG-4    //frameLength = ((unsigned int)header[4]<<5)|((unsigned int)header[5]>>3);    //}else{//MPEG-2      frameLength = (((unsigned int)header[3]&0x3)<<11)|((unsigned int)header[4]<<3)|(header[5]>>5);      //}    if(frameInsec==43){//???      frameInsec=0;    }    if(frameInsec==0){      if(seconds == (*seekTableLength)){	(*seekTable) = realloc((*seekTable), (seconds+SEEK_TABLE_CHUNK)*sizeof(unsigned long));	(*seekTableLength) = seconds+SEEK_TABLE_CHUNK;      }      (*seekTable)[seconds] = position;      seconds++;    }    if(fseek(fd, frameLength-ADTS_HEADER_SIZE, SEEK_CUR)==-1){      break;    }   }  (*seekTableLength) = seconds;  fseek(fd, originPosition, SEEK_SET);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -