1. 程式人生 > >pstStream->pstPack[i].pu8Addr詳解

pstStream->pstPack[i].pu8Addr詳解

/******************************************************************************
* funciton : save H264 stream
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SaveH264(FILE* fpH264File, VENC_STREAM_S *pstStream)
{
    HI_S32 i;

    
    for (i = 0
; i < pstStream->u32PackCount; i++) { //swann add for test 20181115 #if ORTP_ENABLE rtpSend(pRtpSession,pstStream->pstPack[i].pu8Addr, pstStream->pstPack[i].u32Len); #else fwrite(pstStream->pstPack[i].pu8Addr+pstStream->pstPack[i].u32Offset, pstStream
->pstPack[i].u32Len-pstStream->pstPack[i].u32Offset, 1, fpH264File); fflush(fpH264File); #endif } return HI_SUCCESS; }

查C語言優先順序表得知:-> [] . 處於同一優先順序,因此從左到右解析;

1)pstStream->pstPack

typedef struct hiVENC_STREAM_S
{
    VENC_PACK_S *pstPack;                           /*
stream pack attribute*/ HI_U32 u32PackCount; /*the pack number of one frame stream*/ HI_U32 u32Seq; /*the list number of stream*/ union { VENC_STREAM_INFO_H264_S stH264Info; /*the stream info of h264*/ VENC_STREAM_INFO_JPEG_S stJpegInfo; /*the stream info of jpeg*/ VENC_STREAM_INFO_MPEG4_S stMpeg4Info; /*the stream info of mpeg4*/ VENC_STREAM_INFO_H265_S stH265Info; /*the stream info of h265*/ }; }VENC_STREAM_S;
2)pstStream->pstPack[i]的意義:
注意到前面有
            /*******************************************************
                     step 2.1 : query how many packs in one-frame stream.
                    *******************************************************/
                    memset(&stStream, 0, sizeof(stStream));
                    s32Ret = HI_MPI_VENC_Query(i, &stStat);//stStat,為了獲取當前幀的編碼好的碼流包個數。

                    /*******************************************************
                     step 2.3 : malloc corresponding number of pack nodes.
                    *******************************************************/
                    stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
                    /*******************************************************
                     step 2.4 : call mpi to get one-frame stream
                    *******************************************************/
                    stStream.u32PackCount = stStat.u32CurPacks;
                    s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);
stStream.pstPack為一個指標,指向malloc申請的sizeof(VENC_PACK_S) * stStat.u32CurPacks大小的記憶體的首地址;
效果等同於建立了一個VENC_PACK_S結構體陣列,陣列有stStat.u32CurPacks個元素,每個陣列元素為結構體VENC_PACK_S型別
typedef struct hiVENC_PACK_S
{
    HI_U32   u32PhyAddr;                         /*the physics address of stream*/
    HI_U8   *pu8Addr;                            /*the virtual address of stream*/
    HI_U32   u32Len;                             /*the length of stream*/
    
    HI_U64   u64PTS;                                /*PTS*/
    HI_BOOL  bFrameEnd;                             /*frame end*/
    
    VENC_DATA_TYPE_U  DataType;                     /*the type of stream*/
    HI_U32   u32Offset;

    HI_U32 u32DataNum;
    VENC_PACK_INFO_S stPackInfo[8];
}VENC_PACK_S;
因此pstStream->pstPack[i]表示訪問VENC_PACK_S結構體陣列中的第i個元素

3)pstStream->pstPack[i].pu8Addr

訪問結構體中的    HI_U8 *pu8Addr; /*the virtual address of stream*/