📄 ra_depack_internal.c
字号:
} } } } return retVal;}HX_RESULT ra_depacki_get_format_info(ra_depack_internal* pInt, UINT32 ulSubStream, ra_format_info* pInfo){ HX_RESULT retVal = HXR_FAIL; if (pInt && pInfo && pInt->pSubStreamHdr && ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) { /* Init local variables */ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream]; if (pHdr) { /* Clean up any existing format info */ ra_depacki_cleanup_format_info(pInt, pInfo); /* Assign members */ pInfo->ulSampleRate = pHdr->ulSampleRate; pInfo->ulActualRate = pHdr->ulActualSampleRate; pInfo->usBitsPerSample = (UINT16) pHdr->ulSampleSize; pInfo->usNumChannels = (UINT16) pHdr->ulChannels; pInfo->usAudioQuality = 100; pInfo->usFlavorIndex = pHdr->usFlavorIndex; pInfo->ulBitsPerFrame = pHdr->ulCodecFrameSize; pInfo->ulGranularity = pHdr->ulGranularity; pInfo->ulOpaqueDataSize = pHdr->ulOpaqueDataSize; /* Copy the opaque data buffer */ pInfo->pOpaqueData = copy_buffer(pInt->pUserMem, pInt->fpMalloc, pHdr->pOpaqueData, pHdr->ulOpaqueDataSize); if (!pInfo->ulOpaqueDataSize || pInfo->pOpaqueData) { /* Clear the return value */ retVal = HXR_OK; } } } return retVal;}void ra_depacki_cleanup_format_info(ra_depack_internal* pInt, ra_format_info* pInfo){ if (pInt && pInfo && pInfo->pOpaqueData) { ra_depacki_free(pInt, pInfo->pOpaqueData); pInfo->pOpaqueData = HXNULL; }}UINT32 ra_depacki_rule_to_flags(ra_depack_internal* pInt, UINT32 ulRule){ UINT32 ulRet = 0; if (pInt && pInt->rule2Flag.pulMap && ulRule < pInt->rule2Flag.ulNumRules) { ulRet = pInt->rule2Flag.pulMap[ulRule]; } return ulRet;}HXBOOL ra_depacki_is_keyframe_rule(ra_depack_internal* pInt, UINT32 ulRule){ UINT32 ulFlag = ra_depacki_rule_to_flags(pInt, ulRule); return (ulFlag & HX_KEYFRAME_FLAG ? TRUE : FALSE);}UINT32 ra_depacki_rule_to_substream(ra_depack_internal* pInt, UINT32 ulRule){ UINT32 ulRet = 0; if (pInt && pInt->multiStreamHdr.rule2SubStream.pulMap && ulRule < pInt->multiStreamHdr.rule2SubStream.ulNumRules) { ulRet = pInt->multiStreamHdr.rule2SubStream.pulMap[ulRule]; } return ulRet;}HX_RESULT ra_depacki_add_packet(ra_depack_internal* pInt, rm_packet* pPacket){ HX_RESULT retVal = HXR_FAIL; if (pInt && pPacket) { /* Init local variables */ UINT32 i = 0; /* Was this packet lost? */ if (!pPacket->ucLost) { /* This packet was not lost, so we can look up the substream. */ UINT32 ulSubStream = ra_depacki_rule_to_substream(pInt, pPacket->ucASMRule); /* Sanity check */ if (pInt->pSubStreamHdr && ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) { /* Is this substream VBR? */ if (pInt->pSubStreamHdr[ulSubStream].bIsVBR) { /* Add the VBR packet */ retVal = ra_depacki_add_vbr_packet(pInt, ulSubStream, pPacket); } else { /* Add the non-VBR packet */ retVal = ra_depacki_add_non_vbr_packet(pInt, ulSubStream, pPacket); } } } else { /* Are we multistream or single-stream? */ if (pInt->bStreamSwitchable) { /* * We are multi-stream. Therefore, we don't know which * substream this packet came from. So we simply set the * flag saying some loss happened in each substream. */ for (i = 0; i < pInt->multiStreamHdr.ulNumSubStreams; i++) { pInt->pSubStreamHdr[i].bLossOccurred = TRUE; } /* Clear the return value */ retVal = HXR_OK; } else { /* * We are single substream, so we just pass the * lost packet on. It has to be substream 0, of course. */ if (pInt->pSubStreamHdr && pInt->multiStreamHdr.ulNumSubStreams) { /* Is the single substream VBR? */ if (pInt->pSubStreamHdr[0].bIsVBR) { retVal = ra_depacki_add_vbr_packet(pInt, 0, pPacket); } else { retVal = ra_depacki_add_non_vbr_packet(pInt, 0, pPacket); } } } } } return retVal;}HX_RESULT ra_depacki_add_vbr_packet(ra_depack_internal* pInt, UINT32 ulSubStream, rm_packet* pPacket){ HX_RESULT retVal = HXR_FAIL; if (pInt && pPacket) { /* Is the packet lost? */ if (!pPacket->ucLost) { /* Packet was not lost */ if (pInt->pSubStreamHdr && ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) { /* Get the substream header */ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream]; /* Init local variables */ UINT32 ulNumAU = 0; HXBOOL bFrag = FALSE; UINT32 ulAUSize = 0; UINT32 ulAUFragSize = 0; UINT32 i = 0; /* Parse this VBR packet */ retVal = ra_depacki_parse_vbr_packet(pInt, pPacket, &ulNumAU, &bFrag, &ulAUSize, &ulAUFragSize); if (retVal == HXR_OK) { /* * Are we within the tolerance? We expect to * be if we didn't seek. Otherwise, we had loss. */ if (pPacket->ulTime > pHdr->ulLastSentEndTime + TIMESTAMP_GAP_FUDGE_FACTOR && !pHdr->bSeeked) { /* We need to send some loss packets */ retVal = ra_depacki_generate_and_send_loss(pInt, ulSubStream, pHdr->ulLastSentEndTime, pPacket->ulTime); if (retVal == HXR_OK) { pHdr->ulLastSentEndTime = pPacket->ulTime; } } /* Have we just seeked? */ if (pHdr->bSeeked) { /* Clear any remaining fragment */ ra_depacki_clear_frag_buffer(pInt, pHdr); /* Set the last sent time to this time */ pHdr->ulLastSentEndTime = pPacket->ulTime; /* Clear the seeked flag */ pHdr->bSeeked = FALSE; } /* Does this packet hold a fragmented AU? */ if (bFrag) { /* Handle the fragmented packet */ retVal = ra_depacki_handle_frag_packet(pInt, ulSubStream, pPacket, ulAUSize, ulAUFragSize); } else { /* Handle the non-fragmented packet */ retVal = ra_depacki_handle_nonfrag_packet(pInt, ulSubStream, pPacket, ulNumAU); } } } } else { /* Packet is lost - not an error */ retVal = HXR_OK; } } return retVal;}HX_RESULT ra_depacki_add_non_vbr_packet(ra_depack_internal* pInt, UINT32 ulSubStream, rm_packet* pPacket){ HX_RESULT retVal = HXR_FAIL; if (pInt && pPacket && pInt->pSubStreamHdr && ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) { /* Init local variables */ HXBOOL bKey = FALSE; HXDOUBLE dTimeDiff = 0.0; HXDOUBLE dBlockNum = 0; UINT32 ulBlockNum = 0; HXDOUBLE dTSOffset = 0.0; UINT32 ulTSOffset = 0; UINT32 ulPacketTime = pPacket->ulTime; /* Get the substream header */ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream]; /* Is the packet lost? */ if (!pPacket->ucLost) { /* Is this a keyframe packet? */ bKey = ra_depacki_is_keyframe_rule(pInt, pPacket->ucASMRule); /* * We need to determine the index of this block * in this superblock. We will do this by knowing * the timestamp of this packet (block), the timestamp * of the key block in this superblock, and the block * duration. First we make sure we have a key block time. */ if (bKey && !pHdr->bHasKeyTime) { /* We note the timestamp of this key block */ pHdr->ulKeyTime = pPacket->ulTime; /* Set the flag saying we have a key time */ pHdr->bHasKeyTime = TRUE; } /* Now we should have a key time */ if (pHdr->bHasKeyTime && ulPacketTime >= pHdr->ulKeyTime) { /* * Have we yet determined whether or * not we need to adjust timestamps? */ if (!pHdr->bKnowIfAdjustNeeded) { /* * If the last packet was not lost and was a * keyframe and this packet is not a keyframe * and the timestamps are the same, then we need * to adjust timestamps. */ if (pHdr->bHasLastPacket && !pHdr->lastPacket.ucLost && !bKey) { /* Is this timestamp the same as the last packets? */ if (ulPacketTime == pHdr->lastPacket.ulTime) { pHdr->bAdjustTimestamps = TRUE; } else { pHdr->bAdjustTimestamps = FALSE; } /* Now we know */ pHdr->bKnowIfAdjustNeeded = TRUE; } } /* Do we need to adjust timestamps? */ if (pHdr->bKnowIfAdjustNeeded && pHdr->bAdjustTimestamps && !bKey) { dTSOffset = pHdr->ulBlockCount * pHdr->dBlockDuration; ulTSOffset = (UINT32) (dTSOffset + 0.5); ulPacketTime += ulTSOffset; } /* Compute the index of the block within the superblock */ dTimeDiff = (HXDOUBLE) (ulPacketTime - pHdr->ulKeyTime); if (pHdr->dBlockDuration) { dBlockNum = dTimeDiff / pHdr->dBlockDuration;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -