static int get_adif_header(BitData* bf, ADIFHeader *p) { int i, n; // adif header for (i = 0; i < 4; i++) p->adif_id[i] = (char)GetBits(bf, 8); p->adif_id[i] = 0; // null terminated string // test for id if (strncmp(p->adif_id, "ADIF", 4) != 0) return 0; // bad id // copyright string if ((p->copy_id_present = GetBits(bf, 1)) == 1) { for (i = 0; i < 9; i++) p->copy_id[i] = (char)GetBits(bf, 8); p->copy_id[i] = 0; // null terminated string } p->original_copy = GetBits(bf, 1); p->home = GetBits(bf, 1); p->bitstream_type = GetBits(bf, 1); p->bitrate = GetBits(bf, 23); // program config elements n = GetBits(bf, 4) + 1; for ( i = 0 ; i < n ; i++ ) { if( p->bitstream_type == 0 ) p->prog_config.buffer_fullness = GetBits(bf, 20); if( !get_prog_config(bf, &(p->prog_config)) ) { return 0; } } return 1; }
/* * adif_header */ int get_adif_header(faacDecHandle hDecoder) { int i, n, tag, select_status; ProgConfig tmp_config; ADIF_Header *p = &hDecoder->adif_header; /* adif header */ for (i=0; i<LEN_ADIF_ID; i++) p->adif_id[i] = (char)faad_getbits(&hDecoder->ld, LEN_BYTE); p->adif_id[i] = 0; /* null terminated string */ /* copyright string */ if ((p->copy_id_present = faad_getbits(&hDecoder->ld, LEN_COPYRT_PRES)) == 1) { for (i=0; i<LEN_COPYRT_ID; i++) p->copy_id[i] = (char)faad_getbits(&hDecoder->ld, LEN_BYTE); p->copy_id[i] = 0; /* null terminated string */ } p->original_copy = faad_getbits(&hDecoder->ld, LEN_ORIG); p->home = faad_getbits(&hDecoder->ld, LEN_HOME); p->bitstream_type = faad_getbits(&hDecoder->ld, LEN_BS_TYPE); p->bitrate = faad_getbits(&hDecoder->ld, LEN_BIT_RATE); /* program config elements */ select_status = -1; n = faad_getbits(&hDecoder->ld, LEN_NUM_PCE) + 1; for (i=0; i<n; i++) { tmp_config.buffer_fullness = (p->bitstream_type == 0) ? faad_getbits(&hDecoder->ld, LEN_ADIF_BF) : 0; tag = get_prog_config(hDecoder, &tmp_config); if (hDecoder->current_program < 0) hDecoder->current_program = tag; /* default is first prog */ if (hDecoder->current_program == tag) { CopyMemory(&hDecoder->prog_config, &tmp_config, sizeof(hDecoder->prog_config)); select_status = 1; } } return select_status; }
/*---------------------------------------------------------------------------- ; FUNCTION CODE ----------------------------------------------------------------------------*/ Int get_GA_specific_config( tDec_Int_File * const pVars, BITS *pInputStream, UInt channel_config, const tMP4AudioObjectType audioObjectType ) { Int status = SUCCESS; UInt dependsOnCoreCoder; /* Int coreCoderDelay; */ UInt extFlag; /* These variables are left for future implementation */ /* UInt layer_num; */ /* UInt numOfSubFrame; */ /* UInt layer_len; */ /* UInt aacSectionDataResilienceFlag; */ /* UInt aacScalefactorDataResilienceFlag; */ /* UInt aacSpectralDataResilienceFlag; */ Int extFlag3; /* * frame length flag == 0, 1024 samples/frame * frame length flag == 1, 960 samples/frame */ get1bits(/* LEN_FRAME_LEN_FLAG,*/ pInputStream); /* * dependsOnCoreCoder == 1, core coder has different sampling rate * in a scalable bitstream */ dependsOnCoreCoder = get1bits(/* LEN_DEPEND_ON_CORE,*/ pInputStream); if (dependsOnCoreCoder != FALSE) { /*coreCoderDelay = * getbits( * LEN_CORE_DELAY, * pInputStream); */ status = 1; /* do not support scalable coding in this release */ } /* * extension flag indicates if Amendment 1 objects are used or not * extension flag == 0 objects = 1, 2, 3, 4, 6, 7 * extension flag == 1 objects = 17, 19, 20, 21, 22, 23 */ extFlag = get1bits(pInputStream); /* LEN_EXT_FLAG,*/ /* Force checks for implicit channel configuration */ pVars->mc_info.implicit_channeling = 1; if (status == SUCCESS) { if (channel_config == 0) { status = get_prog_config(pVars, &pVars->scratch.scratch_prog_config); if (status != SUCCESS) { pVars->prog_config.front.ele_is_cpe[0] = 0; /* default to mono */ pVars->mc_info.nch = 1; pVars->prog_config.front.ele_tag[0] = 0; status = SUCCESS; } } else { /* * dummy tag = 0 and * set up decoding configurations */ channel_config--; pVars->prog_config.front.ele_is_cpe[0] = channel_config; pVars->prog_config.front.ele_tag[0] = 0; status = set_mc_info( &(pVars->mc_info), audioObjectType, /* previously profile */ pVars->prog_config.sampling_rate_idx, pVars->prog_config.front.ele_tag[0], pVars->prog_config.front.ele_is_cpe[0], pVars->winmap, /*pVars->pWinSeqInfo,*/ pVars->SFBWidth128); } /* if (channel_config) */ } /* if(status) */ /* * This layer_num is not found in ISO/IEC specs, * but it is defined in San Diego spec for scalable bitstream */ if ((audioObjectType == MP4AUDIO_AAC_SCALABLE) || (audioObjectType == MP4AUDIO_ER_AAC_SCALABLE)) { /*layer_num = * getbits( * LEN_LAYER_NUM, * pInputStream); */ status = 1; /* for this release only */ } if (extFlag) { /* * currently do not implement these functionalities * defined in Amendment 1 * keep it here for future release */ if (audioObjectType == MP4AUDIO_ER_BSAC) { status = 1; /* NOT SUPPORTED */ /* numOfSubFrame = getbits( LEN_SUB_FRAME, pInputStream); layer_len = getbits( LEN_LAYER_LEN, pInputStream); */ } /* * The following code is equivalent to * if ((audioObjectType == 17) || (audioObjectType == 18) || * (audioObjectType == 19) || (audioObjectType == 20) || * (audioObjectType == 21) || (audioObjectType == 23)) */ if (((audioObjectType > 16) && (audioObjectType < 22)) || (audioObjectType == 23)) { status = 1; /* NOT SUPPORTED */ /* aacSectionDataResilienceFlag = getbits( LEN_SECT_RES_FLAG, pInputStream); aacScalefactorDataResilienceFlag = getbits( LEN_SCF_RES_FLAG, pInputStream); aacSpectralDataResilienceFlag = getbits( LEN_SPEC_RES_FLAG, pInputStream); */ } /* * this flag is tbd in version 3 of ISO/IEC spec * if the encoder generates this bit, then it has to be read * current adif2mp4ff does not write this bit. If this bit is to * be read, it can be done by the following code: */ extFlag3 = get1bits(pInputStream); /* LEN_EXT_FLAG3 */ if (extFlag3) { status = 1; /* NOT SUPPORTED */ } } return status; }
Int get_adif_header( tDec_Int_File *pVars, ProgConfig *pScratchPCE) { Int i; UInt32 temp; Int numConfigElementsMinus1; Int bitStreamType; UInt32 theIDFromFile; BITS *pInputStream = &pVars->inputStream; ADIF_Header *pHeader = &pVars->scratch.adif_header; Int status = SUCCESS; /* * The ADIF_ID field is 32 bits long, one more than what getbits() can * do, so read the field in two parts. There is no point in saving the * string - it either matches or it does not. If it matches, it must * have been 'ADIF' */ theIDFromFile = get17_n_lessbits((2 * LEN_BYTE), pInputStream); temp = get17_n_lessbits((2 * LEN_BYTE), pInputStream); theIDFromFile = (theIDFromFile << (2 * LEN_BYTE)) | temp; if (theIDFromFile != ADIF_ID) { /* * Rewind the bit stream pointer so a search for ADTS header * can start at the beginning. */ pInputStream->usedBits -= (4 * LEN_BYTE); /* * The constant in the next line needs to be updated when * error handling method is determined. */ status = -1; } else { /* * To save space, the unused fields are read in, but not saved. */ /* copyright string */ temp = get1bits(/* LEN_COPYRT_PRES,*/ pInputStream); if (temp != FALSE) { /* * Read in and ignore the copyright string. If restoring * watch out for count down loop. */ for (i = LEN_COPYRT_ID; i > 0; i--) { get9_n_lessbits(LEN_BYTE, pInputStream); } /* end for */ /* * Make sure to terminate the string with '\0' if restoring * the the copyright string. */ } /* end if */ /* Combine the original/copy and fields into one call */ get9_n_lessbits( LEN_ORIG + LEN_HOME, pInputStream); bitStreamType = get1bits(/* LEN_BS_TYPE,*/ pInputStream); pHeader->bitrate = getbits( LEN_BIT_RATE, pInputStream); /* * Read in all the Program Configuration Elements. * For this library, only one of the up to 16 possible PCE's will be * saved. Since each PCE must be read, a temporary PCE structure is * used, and if that PCE is the one to use, it is copied into the * single PCE. This is done inside of get_prog_config() */ numConfigElementsMinus1 = get9_n_lessbits(LEN_NUM_PCE, pInputStream); for (i = numConfigElementsMinus1; (i >= 0) && (status == SUCCESS); i--) { /* * For ADIF contant bit rate streams, the _encoder_ buffer * fullness is transmitted. This version of an AAC decoder has * no use for this variable; yet it must be read in to move * the bitstream pointers. */ if (bitStreamType == CONSTANT_RATE_BITSTREAM) { getbits( LEN_ADIF_BF, pInputStream); } /* end if */ pVars->adif_test = 1; /* Get one program configuration element */ status = get_prog_config( pVars, pScratchPCE); #ifdef AAC_PLUS /* * For implicit signalling, no hint that sbr or ps is used, so we need to * check the sampling frequency of the aac content, if lesser or equal to * 24 KHz, by defualt upsample, otherwise, do nothing */ if ((pVars->prog_config.sampling_rate_idx >= 6) && (pVars->aacPlusEnabled == true) && pVars->mc_info.audioObjectType == MP4AUDIO_AAC_LC) { pVars->mc_info.upsamplingFactor = 2; pVars->prog_config.sampling_rate_idx -= 3; pVars->mc_info.sbrPresentFlag = 1; pVars->sbrDecoderData.SbrChannel[0].syncState = UPSAMPLING; pVars->sbrDecoderData.SbrChannel[1].syncState = UPSAMPLING; } #endif } /* end for */ } /* end 'else' of --> if (theIDFromFile != ADIF_ID) */ return status; } /* end get_adif_header */