INT FDKsbrEnc_InitSbrBitstream(HANDLE_COMMON_DATA hCmonData, UCHAR *memoryBase, /*!< Pointer to bitstream buffer */ INT memorySize, /*!< Length of bitstream buffer in bytes */ HANDLE_FDK_CRCINFO hCrcInfo, UINT sbrSyntaxFlags) /*!< SBR syntax flags */ { INT crcRegion = 0; /* reset bit buffer */ FDKresetBitbuffer(&hCmonData->sbrBitbuf, BS_WRITER); FDKinitBitStream(&hCmonData->tmpWriteBitbuf, memoryBase, memorySize, 0, BS_WRITER); if (sbrSyntaxFlags & SBR_SYNTAX_CRC) { if (sbrSyntaxFlags & SBR_SYNTAX_DRM_CRC) { /* Init and start CRC region */ FDKwriteBits (&hCmonData->sbrBitbuf, 0x0, SI_SBR_DRM_CRC_BITS); FDKcrcInit( hCrcInfo, 0x001d, 0xFFFF, SI_SBR_DRM_CRC_BITS ); crcRegion = FDKcrcStartReg( hCrcInfo, &hCmonData->sbrBitbuf, 0 ); } else { FDKwriteBits (&hCmonData->sbrBitbuf, 0x0, SI_SBR_CRC_BITS); } } return (crcRegion); }
TRANSPORTDEC_ERROR transportDec_SetParam ( const HANDLE_TRANSPORTDEC hTp, const TPDEC_PARAM param, const INT value) { TRANSPORTDEC_ERROR error = TRANSPORTDEC_OK; switch (param) { case TPDEC_PARAM_MINIMIZE_DELAY: if (value) { hTp->flags |= TPDEC_MINIMIZE_DELAY; } else { hTp->flags &= ~TPDEC_MINIMIZE_DELAY; } break; case TPDEC_PARAM_EARLY_CONFIG: if (value) { hTp->flags |= TPDEC_EARLY_CONFIG; } else { hTp->flags &= ~TPDEC_EARLY_CONFIG; } break; case TPDEC_PARAM_IGNORE_BUFFERFULLNESS: if (value) { hTp->flags |= TPDEC_IGNORE_BUFFERFULLNESS; } else { hTp->flags &= ~TPDEC_IGNORE_BUFFERFULLNESS; } break; case TPDEC_PARAM_SET_BITRATE: hTp->avgBitRate = value; break; case TPDEC_PARAM_BURST_PERIOD: hTp->burstPeriod = value; break; case TPDEC_PARAM_RESET: { int i; for (i=0; i<(1*2); i++) { FDKresetBitbuffer(&hTp->bitStream[i]); hTp->auLength[i] = 0; hTp->accessUnitAnchor[i] = 0; } hTp->flags &= ~(TPDEC_SYNCOK|TPDEC_LOST_FRAMES_PENDING); if (hTp->transportFmt != TT_MP4_ADIF) { hTp->flags &= ~TPDEC_CONFIG_FOUND; } hTp->remainder = 0; hTp->avgBitRate = 0; hTp->missingAccessUnits = 0; hTp->numberOfRawDataBlocks = 0; hTp->globalFramePos = 0; hTp->holdOffFrames = 0; } break; } return error; }
int dabWrite_EncodeHeader(HANDLE_DAB hDab, HANDLE_FDK_BITSTREAM hBitStream, int buffer_fullness, int frame_length) { INT crcIndex = 0; FDK_ASSERT(((frame_length+hDab->headerBits)/8)<0x2000); /*13 bit*/ FDK_ASSERT(buffer_fullness<0x800); /* 11 bit */ FDKcrcReset(&hDab->crcInfo); // fprintf(stderr, "dabWrite_EncodeHeader() hDab->currentBlock=%d, frame_length=%d, buffer_fullness=%d\n", // hDab->currentBlock, frame_length, buffer_fullness); // if (hDab->currentBlock == 0) { // //hDab->subFrameStartPrev=dabWrite_GetHeaderBits(hDab); // fprintf(stderr, "header bits[%d] [%d]\n", hDab->subFrameStartPrev, hDab->subFrameStartPrev >> 3); // FDKresetBitbuffer(hBitStream, BS_WRITER); // } //hDab->subFrameStartBit = FDKgetValidBits(hBitStream); // fprintf(stderr, "dabWrite_EncodeHeader() hDab->subFrameStartBit=%d [%d]\n", hDab->subFrameStartBit, hDab->subFrameStartBit >> 3); //hDab->subFrameStartBit = FDKgetValidBits(hBitStream); /* Skip new header if this is raw data block 1..n */ if (hDab->currentBlock == 0) { FDKresetBitbuffer(hBitStream, BS_WRITER); // fprintf(stderr, "dabWrite_EncodeHeader() after FDKresetBitbuffer=%d [%d]\n", FDKgetValidBits(hBitStream), FDKgetValidBits(hBitStream) >> 3); /* fixed header */ FDKwriteBits(hBitStream, 0, 16); //header_firecode FDKwriteBits(hBitStream, 0, 1); //rfa FDKwriteBits(hBitStream, hDab->dac_rate, 1); FDKwriteBits(hBitStream, hDab->sbr_flag, 1); FDKwriteBits(hBitStream, hDab->aac_channel_mode, 1); FDKwriteBits(hBitStream, hDab->ps_flag, 1); FDKwriteBits(hBitStream, hDab->mpeg_surround_config, 3); /* variable header */ int i; for(i=0; i<hDab->num_raw_blocks; i++) FDKwriteBits(hBitStream, 0, 12); /* padding */ if (hDab->dac_rate == 0 || hDab->sbr_flag == 0) { FDKwriteBits(hBitStream, 0, 4); } } /* End of DAB header */ hDab->subFrameStartBit = FDKgetValidBits(hBitStream); FDK_ASSERT(FDKgetValidBits(hBitStream) % 8 == 0); //only aligned header // fprintf(stderr, "dabWrite_EncodeHeader() FDKgetValidBits(hBitStream)=%d [%d]\n", FDKgetValidBits(hBitStream), FDKgetValidBits(hBitStream) >> 3); return 0; }
int adtsWrite_EncodeHeader(HANDLE_ADTS hAdts, HANDLE_FDK_BITSTREAM hBitStream, int buffer_fullness, int frame_length) { INT crcIndex = 0; hAdts->headerBits = adtsWrite_GetHeaderBits(hAdts); FDK_ASSERT(((frame_length+hAdts->headerBits)/8)<0x2000); /*13 bit*/ FDK_ASSERT(buffer_fullness<0x800); /* 11 bit */ if (!hAdts->protection_absent) { FDKcrcReset(&hAdts->crcInfo); } if (hAdts->currentBlock == 0) { FDKresetBitbuffer(hBitStream, BS_WRITER); } hAdts->subFrameStartBit = FDKgetValidBits(hBitStream); /* Skip new header if this is raw data block 1..n */ if (hAdts->currentBlock == 0) { FDKresetBitbuffer(hBitStream, BS_WRITER); if (hAdts->num_raw_blocks == 0) { crcIndex = adtsWrite_CrcStartReg(hAdts, hBitStream, 0); } /* fixed header */ FDKwriteBits(hBitStream, 0xFFF, 12); FDKwriteBits(hBitStream, hAdts->mpeg_id, 1); FDKwriteBits(hBitStream, hAdts->layer, 2); FDKwriteBits(hBitStream, hAdts->protection_absent, 1); FDKwriteBits(hBitStream, hAdts->profile, 2); FDKwriteBits(hBitStream, hAdts->sample_freq_index, 4); FDKwriteBits(hBitStream, hAdts->private_bit, 1); FDKwriteBits(hBitStream, getChannelConfig(hAdts->channel_mode), 3); FDKwriteBits(hBitStream, hAdts->original, 1); FDKwriteBits(hBitStream, hAdts->home, 1); /* variable header */ FDKwriteBits(hBitStream, hAdts->copyright_id, 1); FDKwriteBits(hBitStream, hAdts->copyright_start, 1); FDKwriteBits(hBitStream, (frame_length + hAdts->headerBits)>>3, 13); FDKwriteBits(hBitStream, buffer_fullness, 11); FDKwriteBits(hBitStream, hAdts->num_raw_blocks, 2); if (!hAdts->protection_absent) { int i; /* End header CRC portion for single raw data block and write dummy zero values for unknown fields. */ if (hAdts->num_raw_blocks == 0) { adtsWrite_CrcEndReg(hAdts, hBitStream, crcIndex); } else { for (i=0; i<hAdts->num_raw_blocks; i++) { FDKwriteBits(hBitStream, 0, 16); } } FDKwriteBits(hBitStream, 0, 16); } } /* End of ADTS header */
void FDKsbrEnc_AssembleSbrBitstream( HANDLE_COMMON_DATA hCmonData, HANDLE_FDK_CRCINFO hCrcInfo, INT crcRegion, UINT sbrSyntaxFlags) { USHORT crcReg = SBR_CRCINIT; INT numCrcBits,i; /* check if SBR is present */ if ( hCmonData==NULL ) return; hCmonData->sbrFillBits = 0; /* Fill bits are written only for GA streams */ if ( sbrSyntaxFlags & SBR_SYNTAX_DRM_CRC ) { /* * Calculate and write DRM CRC */ FDKcrcEndReg( hCrcInfo, &hCmonData->sbrBitbuf, crcRegion ); FDKwriteBits( &hCmonData->tmpWriteBitbuf, FDKcrcGetCRC(hCrcInfo)^0xFF, SI_SBR_DRM_CRC_BITS ); } else { if ( !(sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) ) { /* Do alignment here, because its defined as part of the sbr_extension_data */ int sbrLoad = hCmonData->sbrHdrBits + hCmonData->sbrDataBits; if ( sbrSyntaxFlags & SBR_SYNTAX_CRC ) { sbrLoad += SI_SBR_CRC_BITS; } sbrLoad += 4; /* Do byte Align with 4 bit offset. ISO/IEC 14496-3:2005(E) page 39. */ hCmonData->sbrFillBits = (8 - (sbrLoad % 8)) % 8; /* append fill bits */ FDKwriteBits(&hCmonData->sbrBitbuf, 0, hCmonData->sbrFillBits ); FDK_ASSERT(FDKgetValidBits(&hCmonData->sbrBitbuf) % 8 == 4); } /* calculate crc */ if ( sbrSyntaxFlags & SBR_SYNTAX_CRC ) { FDK_BITSTREAM tmpCRCBuf = hCmonData->sbrBitbuf; FDKresetBitbuffer( &tmpCRCBuf, BS_READER ); numCrcBits = hCmonData->sbrHdrBits + hCmonData->sbrDataBits + hCmonData->sbrFillBits; for(i=0;i<numCrcBits;i++){ INT bit; bit = FDKreadBits(&tmpCRCBuf,1); crcAdvance(SBR_CRC_POLY,SBR_CRC_MASK,&crcReg,bit,1); } crcReg &= (SBR_CRC_RANGE); /* * Write CRC data. */ FDKwriteBits (&hCmonData->tmpWriteBitbuf, crcReg, SI_SBR_CRC_BITS); } } FDKsyncCache(&hCmonData->tmpWriteBitbuf); }