Example #1
0
bool HimppAencChan::enableObject()
{
    HI_S32 s32Ret;
    AENC_CHN_ATTR_S attr;
    union {
        AENC_ATTR_ADPCM_S   adpcm;
        AENC_ATTR_G711_S    g711;
        AENC_ATTR_G726_S    g726;
        AENC_ATTR_LPCM_S    lpcm;
    } enc_attr;

    attr.u32BufSize = 30;
    attr.pValue = &enc_attr;

    switch (_encoding) {
    case IAudioEncoder::ADPCM:
        attr.enType = PT_ADPCMA;
        enc_attr.adpcm.enADPCMType = AUDIO_ADPCM_TYPE;
        break;
    case IAudioEncoder::G711A:
        attr.enType = PT_G711A;
        enc_attr.g711.resv = 0;
        break;
    case IAudioEncoder::G711U:
        attr.enType = PT_G711U;
        enc_attr.g711.resv = 0;
        break;
    case IAudioEncoder::G726:
        attr.enType = PT_G726;
        enc_attr.g726.enG726bps = G726_BPS;
        break;
    case IAudioEncoder::LPCM:
        attr.enType = PT_LPCM;
        enc_attr.lpcm.resv = 0;
        break;
    }
    s32Ret = HI_MPI_AENC_CreateChn(_chnid, &attr);
    if (s32Ret != HI_SUCCESS) {
        fprintf(stderr, "failed to create VENC chn%d\n", _chnid);
        return false;
    }

    MPP_CHN_S dst_chn;
    dst_chn.enModId = HI_ID_AENC;
    dst_chn.s32DevId = 0;
    dst_chn.s32ChnId = _chnid;
    s32Ret = HI_MPI_SYS_Bind(*source(), &dst_chn);
    if (s32Ret != HI_SUCCESS) {
        fprintf(stderr, "HI_MPI_SYS_Bind AENC chn%d failed [%#x]\n",
                _chnid, s32Ret);
        goto err_destroy_chn;
    }

    return true;

err_destroy_chn:
    HI_MPI_AENC_DestroyChn(_chnid);

    return false;
}
/******************************************************************************
* function : Start Aenc
******************************************************************************/
HI_S32 SAMPLE_COMM_AUDIO_StartAenc(HI_S32 s32AencChnCnt, PAYLOAD_TYPE_E enType)
{
    AENC_CHN AeChn;
    HI_S32 s32Ret, i;
    AENC_CHN_ATTR_S stAencAttr;
    
    /* set AENC chn attr */
    
    stAencAttr.enType = enType;
    stAencAttr.u32BufSize = 30;
    
    if (PT_ADPCMA == stAencAttr.enType)
    {
        AENC_ATTR_ADPCM_S stAdpcmAenc;
        stAencAttr.pValue       = &stAdpcmAenc;
        stAdpcmAenc.enADPCMType = AUDIO_ADPCM_TYPE;
    }
    else if (PT_G711A == stAencAttr.enType || PT_G711U == stAencAttr.enType)
    {
        AENC_ATTR_G711_S stAencG711;
        stAencAttr.pValue       = &stAencG711;
    }
    else if (PT_G726 == stAencAttr.enType)
    {
        AENC_ATTR_G726_S stAencG726;
        stAencAttr.pValue       = &stAencG726;
        stAencG726.enG726bps    = G726_BPS;
    }
    else if (PT_LPCM == stAencAttr.enType)
    {
        AENC_ATTR_LPCM_S stAencLpcm;
        stAencAttr.pValue = &stAencLpcm;
    }
    else
    {
        printf("%s: invalid aenc payload type:%d\n", __FUNCTION__, stAencAttr.enType);
        return HI_FAILURE;
    }    

    for (i=0; i<s32AencChnCnt; i++)
    {            
        AeChn = i;
        
        /* create aenc chn*/
        s32Ret = HI_MPI_AENC_CreateChn(AeChn, &stAencAttr);
        if (s32Ret != HI_SUCCESS)
        {
            printf("%s: HI_MPI_AENC_CreateChn(%d) failed with %#x!\n", __FUNCTION__,
                   AeChn, s32Ret);
            return HI_FAILURE;
        }        
    }
    
    return HI_SUCCESS;
}
Example #3
0
static int aenc_start(HI_S32 s32AencChnCnt, PAYLOAD_TYPE_E enType)
{
    AENC_CHN AeChn = 0;
    HI_S32 i = 0;
    HI_S32 s32Ret = HI_FAILURE;
    AENC_CHN_ATTR_S stAencAttr;
    memset(&stAencAttr, 0, sizeof(stAencAttr));
    AENC_ATTR_ADPCM_S stAdpcmAenc;
    memset(&stAdpcmAenc, 0, sizeof(stAdpcmAenc));
    AENC_ATTR_G711_S stAencG711;
    memset(&stAencG711, 0, sizeof(stAencG711));
    AENC_ATTR_G726_S stAencG726;
    memset(&stAencG726, 0, sizeof(stAencG726));
    AENC_ATTR_LPCM_S stAencLpcm;
    memset(&stAencLpcm, 0, sizeof(stAencLpcm));

    /* set AENC chn attr */
    stAencAttr.enType = enType;
    stAencAttr.u32PtNumPerFrm = g_audio_args->audio.ptNumPerFrm;
    stAencAttr.u32BufSize = 30;

    if (PT_ADPCMA == stAencAttr.enType)
    {
        stAencAttr.pValue       = &stAdpcmAenc;
        stAdpcmAenc.enADPCMType = ADPCM_TYPE_DVI4;
    }
    else if (PT_G711A == stAencAttr.enType || PT_G711U == stAencAttr.enType)
    {
        stAencAttr.pValue       = &stAencG711;
    }
    else if (PT_G726 == stAencAttr.enType)
    {
        stAencAttr.pValue       = &stAencG726;
        stAencG726.enG726bps    = G726_16K;
    }
    else if (PT_LPCM == stAencAttr.enType)
    {
        stAencAttr.pValue = &stAencLpcm;
    }
    else
    {
        DBG("invalid aenc payload type:%d\n", stAencAttr.enType);
        return HI_FAILURE;
    }

    for (i=0; i<s32AencChnCnt; i++)
    {
        AeChn = i;
        /* create aenc chn*/
        s32Ret = HI_MPI_AENC_CreateChn(AeChn, &stAencAttr);
        CHECK(s32Ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", s32Ret);
    }

    return HI_SUCCESS;
}
Example #4
0
static int enc_create_g711a_stream(int ain, int vin_ref, SDK_ENC_G711A_STREAM_ATTR_t* stream_attr)
{
	if(ain < HI_AENC_CH_BACKLOG_REF){
		if(vin_ref < HI_VENC_CH_BACKLOG_REF){
			int const aenc_ch = ain;
			SDK_ENC_G711A_STREAM_ATTR_t* const this_stream_attr = &_sdk_enc.attr.audio_stream_attr[ain];
		
			if(0 == this_stream_attr->magic){
				AENC_ATTR_G711_S aenc_attr_g711 = {0};
				AENC_CHN_ATTR_S aenc_ch_attr = {.enType = PT_G711A, .pValue = &aenc_attr_g711,};
				MPP_CHN_S mpp_ch_ai, mpp_ch_aenc;

				aenc_ch_attr.enType = PT_G711A;
				aenc_ch_attr.pValue = &aenc_attr_g711;
				//aenc_ch_attr.u32BufSize = 8;
				//aenc_ch_attr.u32BufSize = MAX_AUDIO_FRAME_NUM; // ver 050 faq 1.6.3
				aenc_ch_attr.u32BufSize = MAX_AUDIO_FRAME_NUM;

				memcpy(this_stream_attr, stream_attr, sizeof(SDK_ENC_G711A_STREAM_ATTR_t));
				this_stream_attr->magic = ENC_H264_STREAM_ATTR_MAGIC; // mark the magic
				this_stream_attr->ain = ain;
				this_stream_attr->vin_ref = vin_ref;
				// FIXME: remember to check the sample rate and bitwidth
				this_stream_attr->sample_rate = SDK_ENC_AUDIO_SAMPLE_RATE_8KBPS;
				this_stream_attr->bit_width = SDK_ENC_AUDIO_BITWIDTH_8BITS;
				this_stream_attr->packet_size = 320;

				// sdk operate
				// enable vin
				SOC_CHECK(HI_MPI_AI_EnableChn(__HI_AIN_CH, ain));
				// create aenc chn
				SOC_CHECK(HI_MPI_AENC_CreateChn(aenc_ch, &aenc_ch_attr));

#if 0 //enable resample
				// bind AENC to AI channel
				mpp_ch_ai.enModId  = HI_ID_AI;
				mpp_ch_ai.s32DevId = __HI_AIN_CH;
				mpp_ch_ai.s32ChnId = ain;

				mpp_ch_aenc.enModId  = HI_ID_AENC;
				mpp_ch_aenc.s32DevId = 0;
				mpp_ch_aenc.s32ChnId = aenc_ch;

				SOC_CHECK(HI_MPI_SYS_Bind(&mpp_ch_ai, &mpp_ch_aenc));
#endif

				_sdk_enc.attr.audio_msk |= 1<<ain;
				return SDK_SUCCESS;	
			}
		}
Example #5
0
static void avenc_AEncInit()
{
#define AENC_G711A_USE
//#define AENC_ADPCM_USE
//#define AENC_LPCM_USE
	int i = 0;
#if defined(AENC_G711A_USE)
	AENC_ATTR_G711_S stAencG711A = {0};
	AENC_CHN_ATTR_S stAencAttr = {.enType = PT_G711A, .pValue = &stAencG711A,};
#elif defined(AENC_ADPCM_USE)
	AENC_ATTR_ADPCM_S stAencADPCM = {.enADPCMType = ADPCM_TYPE_DVI4, };
	AENC_CHN_ATTR_S stAencAttr = {.enType = PT_ADPCMA, .pValue = &stAencADPCM,};
#elif defined(AENC_LPCM_USE)
	AENC_ATTR_LPCM_S stAencLPCM = {0};
	AENC_CHN_ATTR_S stAencAttr = {.enType = PT_LPCM, .pValue = &stAencLPCM,};
#else
#error "Audio Encode Format Not Supported"
#endif

//	stAencAttr.u32BufSize = 8;
//	stAencAttr.u32BufSize = MAX_AUDIO_FRAME_NUM; // ver 050 faq 1.6.3
	stAencAttr.u32BufSize = 5;

	// hisilicon SDK
	for(i = 0; i < AVENC_AUDIO_MAX_CH; ++i){
		if(g_pstSysEnv->GetEncMode(g_pstSysEnv, i) == MODE_AUDIO_VIDEO){
			if(AUDIO_IsCapLiveLoop()){
				// if with audio live loop
				// audio live init here
				DVR_ASSERT(HI_MPI_AI_EnableChn(AIN_DEV, i));
			}
			// create aenc chn
			DVR_ASSERT(HI_MPI_AENC_CreateChn(i, &stAencAttr));
			// bind AENC to AI channel
			DVR_ASSERT(HI_MPI_AENC_BindAi(i, AIN_DEV, i));
		}
	}
}
/******************************************************************************
* function : Start Aenc
******************************************************************************/
HI_S32 SAMPLE_COMM_AUDIO_StartAenc(HI_S32 s32AencChnCnt, PAYLOAD_TYPE_E enType)
{
    AENC_CHN AeChn;
    HI_S32 s32Ret, i;
    AENC_CHN_ATTR_S stAencAttr;
    
    /* set AENC chn attr */
    
    stAencAttr.enType = enType;
    stAencAttr.u32BufSize = 30;
    
    if (PT_ADPCMA == stAencAttr.enType)
    {
        AENC_ATTR_ADPCM_S stAdpcmAenc;
        stAencAttr.pValue       = &stAdpcmAenc;
        stAdpcmAenc.enADPCMType = AUDIO_ADPCM_TYPE;
    }
    else if (PT_G711A == stAencAttr.enType || PT_G711U == stAencAttr.enType)
    {
        AENC_ATTR_G711_S stAencG711;
        stAencAttr.pValue       = &stAencG711;
    }
    else if (PT_G726 == stAencAttr.enType)
    {
        AENC_ATTR_G726_S stAencG726;
        stAencAttr.pValue       = &stAencG726;
        stAencG726.enG726bps    = G726_BPS;
    }
    else if (PT_LPCM == stAencAttr.enType)
    {
        AENC_ATTR_LPCM_S stAencLpcm;
        stAencAttr.pValue = &stAencLpcm;
    }
    else if (PT_AAC == stAencAttr.enType)
    {
        //s32AiChnCnt = 1;      /* 之前aac只能一个通道有效 */
        AENC_ATTR_AAC_S stAencAac;
        stAencAttr.pValue = &stAencAac;
        stAencAac.enAACType = AAC_TYPE_AACLC;
        stAencAac.enBitRate = AAC_BPS_32K;
        stAencAac.enBitWidth = AUDIO_BIT_WIDTH_16;
        stAencAac.enSmpRate = AUDIO_SAMPLE_RATE_16000;
        stAencAac.enSoundMode = AUDIO_SOUND_MODE_MONO;
    }
    else
    {
        printf("%s: invalid aenc payload type:%d\n", __FUNCTION__, stAencAttr.enType);
        return HI_FAILURE;
    }    

    for (i=0; i<s32AencChnCnt; i++)
    {            
        AeChn = i;
        
        /* create aenc chn*/
        s32Ret = HI_MPI_AENC_CreateChn(AeChn, &stAencAttr);
        if (s32Ret != HI_SUCCESS)
        {
            printf("%s: HI_MPI_AENC_CreateChn(%d) failed with %#x!\n", __FUNCTION__,
                   AeChn, s32Ret);
            return HI_FAILURE;
        }        
    }
    
    return HI_SUCCESS;
}