📄 ra_depack_internal.c
字号:
memset(pHdr->pIPresentFlags, 0, ulTmp); /* Allocate the de-interleaved flags */ pHdr->pDPresentFlags = (UINT32*) ra_depacki_malloc(pInt, ulTmp); if (pHdr->pDPresentFlags) { /* Null out the memory */ memset(pHdr->pDPresentFlags, 0, ulTmp); /* Clear the return value */ retVal = HXR_OK; /* If this is GENR interleaving, then init the tables */ if (pHdr->ulInterleaverID == RA_INTERLEAVER_GENR) { retVal = ra_depacki_init_genr(pInt, i); } } } } } } /* Update the buffer cursors */ pBuf += ulSize; ulLen -= ulSize; } } else { retVal = HXR_FAIL; } } } } return retVal;}void ra_depacki_cleanup_substream_hdr(ra_depack_internal* pInt, ra_substream_hdr* hdr){ if (pInt && hdr) { if (hdr->pulInterleavePattern) { ra_depacki_free(pInt, hdr->pulInterleavePattern); hdr->pulInterleavePattern = HXNULL; } if (hdr->pOpaqueData) { ra_depacki_free(pInt, hdr->pOpaqueData); hdr->pOpaqueData = HXNULL; } if (hdr->pFragBuffer) { ra_depacki_free(pInt, hdr->pFragBuffer); hdr->pFragBuffer = HXNULL; } if (hdr->pIBuffer) { ra_depacki_free(pInt, hdr->pIBuffer); hdr->pIBuffer = HXNULL; } if (hdr->pDBuffer) { ra_depacki_free(pInt, hdr->pDBuffer); hdr->pDBuffer = HXNULL; } if (hdr->pIPresentFlags) { ra_depacki_free(pInt, hdr->pIPresentFlags); hdr->pIPresentFlags = HXNULL; } if (hdr->pDPresentFlags) { ra_depacki_free(pInt, hdr->pDPresentFlags); hdr->pDPresentFlags = HXNULL; } if (hdr->pulGENRPattern) { ra_depacki_free(pInt, hdr->pulGENRPattern); hdr->pulGENRPattern = HXNULL; } if (hdr->pulGENRBlockNum) { ra_depacki_free(pInt, hdr->pulGENRBlockNum); hdr->pulGENRBlockNum = HXNULL; } if (hdr->pulGENRBlockOffset) { ra_depacki_free(pInt, hdr->pulGENRBlockOffset); hdr->pulGENRBlockOffset = HXNULL; } }}void ra_depacki_cleanup_substream_hdr_array(ra_depack_internal* pInt){ if (pInt && pInt->pSubStreamHdr) { UINT32 i = 0; for (i = 0; i < pInt->multiStreamHdr.ulNumSubStreams; i++) { ra_depacki_cleanup_substream_hdr(pInt, &pInt->pSubStreamHdr[i]); } /* Free the header array */ ra_depacki_free(pInt, pInt->pSubStreamHdr); /* NULL out the pointer */ pInt->pSubStreamHdr = HXNULL; }}HX_RESULT ra_depacki_unpack_substream_hdr(ra_depack_internal* pInt, BYTE* pBuf, UINT32 ulLen, ra_substream_hdr* pHdr){ HX_RESULT retVal = HXR_FAIL; if (pInt && pBuf && ulLen >= 6 && pHdr) { UINT32 ulID = 0; UINT16 usVersion = 0; /* Clean up any existing header info */ ra_depacki_cleanup_substream_hdr(pInt, pHdr); /* Read the ID and the RAFormat version */ ulID = rm_unpack32(&pBuf, &ulLen); usVersion = rm_unpack16(&pBuf, &ulLen); /* Sanity check on ID */ if (ulID == RA_FORMAT_ID) { /* Switch based on RAFormat version */ switch (usVersion) { case 3: retVal = ra_depacki_unpack_raformat3(pInt, pBuf, ulLen, pHdr); break; case 4: retVal = ra_depacki_unpack_raformat4(pInt, pBuf, ulLen, pHdr); break; case 5: retVal = ra_depacki_unpack_raformat5(pInt, pBuf, ulLen, pHdr); break; } } } return retVal;}HX_RESULT ra_depacki_unpack_raformat3(ra_depack_internal* pInt, BYTE* pBuf, UINT32 ulLen, ra_substream_hdr* pHdr){ return HXR_NOTIMPL;}HX_RESULT ra_depacki_unpack_raformat4(ra_depack_internal* pInt, BYTE* pBuf, UINT32 ulLen, ra_substream_hdr* pHdr){ HX_RESULT retVal = HXR_FAIL; if (pInt && pBuf && ulLen >= 63 && pHdr) { /* Init local variables */ UINT32 ulSize = 0; UINT32 i = 0; /* Skip first 10 bytes */ pBuf += 10; ulLen -= 10; /* Read the version and revision */ pHdr->usRAFormatVersion = rm_unpack16(&pBuf, &ulLen); pHdr->usRAFormatRevision = rm_unpack16(&pBuf, &ulLen); /* Sanity check */ if (pHdr->usRAFormatVersion == 4 && pHdr->usRAFormatRevision == 0) { pHdr->usHeaderBytes = rm_unpack16(&pBuf, &ulLen); pHdr->usFlavorIndex = rm_unpack16(&pBuf, &ulLen); pHdr->ulGranularity = rm_unpack32(&pBuf, &ulLen); pHdr->ulTotalBytes = rm_unpack32(&pBuf, &ulLen); pHdr->ulBytesPerMin = rm_unpack32(&pBuf, &ulLen); pHdr->ulBytesPerMin2 = rm_unpack32(&pBuf, &ulLen); pHdr->ulInterleaveFactor = rm_unpack16(&pBuf, &ulLen); pHdr->ulInterleaveBlockSize = rm_unpack16(&pBuf, &ulLen); pHdr->ulUserData = rm_unpack32(&pBuf, &ulLen); pHdr->ulSampleRate = rm_unpack32(&pBuf, &ulLen); pHdr->ulSampleRate >>= 16; pHdr->ulSampleSize = rm_unpack16(&pBuf, &ulLen); pHdr->ulChannels = rm_unpack16(&pBuf, &ulLen); pHdr->ulInterleaverID = rm_unpack32_from_byte_string(&pBuf, &ulLen); pHdr->ulCodecID = rm_unpack32_from_byte_string(&pBuf, &ulLen); pHdr->bIsInterleaved = rm_unpack8(&pBuf, &ulLen); pHdr->bCopyByte = rm_unpack8(&pBuf, &ulLen); pHdr->ucStreamType = rm_unpack8(&pBuf, &ulLen); /* * If the bIsInterleaved flag says we are * not interleaved, then make sure the * interleaverID is set to no interleaver. */ if (!pHdr->bIsInterleaved) { pHdr->ulInterleaverID = RA_NO_INTERLEAVER; } /* If the interleave factor is 0, make it 1. */ if (!pHdr->ulInterleaveFactor) { pHdr->ulInterleaveFactor = 1; } /* Clear the return value */ retVal = HXR_OK; } } return retVal;}HX_RESULT ra_depacki_unpack_raformat5(ra_depack_internal* pInt, BYTE* pBuf, UINT32 ulLen, ra_substream_hdr* pHdr){ HX_RESULT retVal = HXR_FAIL; if (pInt && pBuf && ulLen >= 68 && pHdr) { /* Init local variables */ UINT32 ulSize = 0; UINT32 i = 0; /* Skip first 10 bytes */ pBuf += 10; ulLen -= 10; /* Read the version and revision */ pHdr->usRAFormatVersion = rm_unpack16(&pBuf, &ulLen); pHdr->usRAFormatRevision = rm_unpack16(&pBuf, &ulLen); /* Sanity check */ if (pHdr->usRAFormatVersion == 5 && pHdr->usRAFormatRevision == 0) { pHdr->usHeaderBytes = rm_unpack16(&pBuf, &ulLen); pHdr->usFlavorIndex = rm_unpack16(&pBuf, &ulLen); pHdr->ulGranularity = rm_unpack32(&pBuf, &ulLen); pHdr->ulTotalBytes = rm_unpack32(&pBuf, &ulLen); pHdr->ulBytesPerMin = rm_unpack32(&pBuf, &ulLen); pHdr->ulBytesPerMin2 = rm_unpack32(&pBuf, &ulLen); pHdr->ulInterleaveFactor = rm_unpack16(&pBuf, &ulLen); pHdr->ulInterleaveBlockSize = rm_unpack16(&pBuf, &ulLen); pHdr->ulCodecFrameSize = rm_unpack16(&pBuf, &ulLen); pHdr->ulUserData = rm_unpack32(&pBuf, &ulLen); pHdr->ulSampleRate = rm_unpack32(&pBuf, &ulLen); pHdr->ulSampleRate >>= 16; pHdr->ulActualSampleRate = rm_unpack32(&pBuf, &ulLen); pHdr->ulActualSampleRate >>= 16; pHdr->ulSampleSize = rm_unpack16(&pBuf, &ulLen); pHdr->ulChannels = rm_unpack16(&pBuf, &ulLen); pHdr->ulInterleaverID = rm_unpack32(&pBuf, &ulLen); pHdr->ulCodecID = rm_unpack32(&pBuf, &ulLen); pHdr->bIsInterleaved = rm_unpack8(&pBuf, &ulLen); pHdr->bCopyByte = rm_unpack8(&pBuf, &ulLen); pHdr->ucStreamType = rm_unpack8(&pBuf, &ulLen); pHdr->ucScatterType = rm_unpack8(&pBuf, &ulLen); pHdr->ulNumCodecFrames = pHdr->ulInterleaveFactor * pHdr->ulInterleaveBlockSize / pHdr->ulCodecFrameSize; /* Clear the return value */ retVal = HXR_OK; /* * If ucScatterType is non-zero, then we have * to read in an interleave pattern. */ if (pHdr->ucScatterType) { /* Set the return value */ retVal = HXR_FAIL; /* Allocate space for the interleave pattern */ ulSize = pHdr->ulNumCodecFrames * sizeof(UINT32); pHdr->pulInterleavePattern = ra_depacki_malloc(pInt, ulSize); if (pHdr->pulInterleavePattern) { /* NULL out all the memory */ memset(pHdr->pulInterleavePattern, 0, ulSize); /* Make sure we have enough parsing buffer left */ if (ulLen >= ulSize) { /* Read in the interleave pattern */ for (i = 0; i < pHdr->ulNumCodecFrames; i++) { pHdr->pulInterleavePattern[i] = rm_unpack16(&pBuf, &ulLen); } /* Clear the return value */ retVal = HXR_OK; } } } if (retVal == HXR_OK) { /* Set the return value */ retVal = HXR_FAIL; /* Make sure we have four bytes */ if (ulLen >= 4) { /* Read in the opaque data size */ pHdr->ulOpaqueDataSize = rm_unpack32(&pBuf, &ulLen); /* Make sure we have this much parsing space left */ if (ulLen >= pHdr->ulOpaqueDataSize) { /* Allocate the buffer */ pHdr->pOpaqueData = ra_depacki_malloc(pInt, pHdr->ulOpaqueDataSize); if (pHdr->pOpaqueData) { /* Copy the opaque data */ memcpy(pHdr->pOpaqueData, pBuf, pHdr->ulOpaqueDataSize); /* Clear the return value */ retVal = HXR_OK; /* * If the bIsInterleaved flag says we are * not interleaved, then make sure the * interleaverID is set to no interleaver. */ if (!pHdr->bIsInterleaved) { pHdr->ulInterleaverID = RA_NO_INTERLEAVER; } /* If the interleave factor is 0, make it 1. */ if (!pHdr->ulInterleaveFactor) { pHdr->ulInterleaveFactor = 1; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -