コード例 #1
0
ファイル: pciv_test_slave.c プロジェクト: mglz/Drv
HI_S32 PCIV_Slave_StartVenc(PCIV_MSGHEAD_S *pMsg)
{
    HI_S32   s32Ret;
    VENC_CHN vencChn;
    VENC_CHN_ATTR_S     *pAttr    = NULL;
    PCIV_VENCCMD_CREATE_S *pCmd     = (PCIV_VENCCMD_CREATE_S *)pMsg->cMsgBody;
    PCIV_VENCCMD_ECHO_S   *pCmdEcho = (PCIV_VENCCMD_ECHO_S   *)pMsg->cMsgBody;

    /* If start the local vi then just do it */
    pAttr         = &(pCmd->stAttr);
    pAttr->pValue = pCmd + 1;

    vencChn = pCmd->vencChn;
    s32Ret  = HI_MPI_VENC_CreateChn(vencChn, pAttr, NULL);
    HI_ASSERT(HI_SUCCESS == s32Ret);

    /* register to group */
    s32Ret = HI_MPI_VENC_RegisterChn(pCmd->vencGrp,vencChn);
    HI_ASSERT(HI_SUCCESS == s32Ret);

    s32Ret = HI_MPI_VENC_StartRecvPic(vencChn);/*main chn start rev */
    HI_ASSERT(HI_SUCCESS == s32Ret);

    /* Echo the cmd */
    pMsg->enMsgType   = PCIV_MSGTYPE_CMDECHO;
    pMsg->enDevType   = PCIV_DEVTYPE_VENCCHN;
    pMsg->u32Target   = 0;
    pMsg->u32MsgLen   = sizeof(PCIV_VENCCMD_ECHO_S);
    pCmdEcho->vencChn = vencChn;
    pCmdEcho->s32Echo = HI_SUCCESS;
    s32Ret = PCIV_SendMsg(0, PCIV_MSGPORT_USERCMD, pMsg);
    HI_ASSERT((HI_FAILURE != s32Ret));

    return HI_SUCCESS;
}
コード例 #2
0
ファイル: v_producer.c プロジェクト: AxelLin/Drv
HI_S32 SampleStartSnap(VENC_GRP VeGroup,VENC_CHN SnapChn,
										VI_DEV ViDev,VI_CHN ViChn,FILE *pFile)
{
	HI_S32 s32Ret;

	s32Ret = HI_MPI_VENC_BindInput(VeGroup, ViDev, ViChn);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_BindInput err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_RegisterChn(VeGroup, SnapChn);
	if(s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_RegisterChn err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_StartRecvPic(SnapChn);
	if(s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_StartRecvPic err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	/*save jpeg picture*/
	s32Ret = SampleSaveSnapPic(SnapChn,pFile);
	if(s32Ret != HI_SUCCESS)
	{
		printf("SampleSaveSnapPic err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_StopRecvPic(SnapChn);
	if(s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_StopRecvPic err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_UnRegisterChn(SnapChn);
	if(s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_UnRegisterChn err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_UnbindInput(VeGroup);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_UnbindInput err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	return HI_SUCCESS;
}
コード例 #3
0
ファイル: sample_codec.c プロジェクト: AxelLin/Drv
static HI_S32 SampleEnableEncodeH264(VENC_GRP VeGroup, VENC_CHN VeChn,
                        VI_DEV ViDev, VI_CHN ViChn, VENC_CHN_ATTR_S *pstAttr)
{
    HI_S32 s32Ret;

    s32Ret = HI_MPI_VENC_CreateGroup(VeGroup);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_CreateGroup err 0x%x\n",s32Ret);
        return HI_FAILURE;
    }

    s32Ret = HI_MPI_VENC_BindInput(VeGroup, ViDev, ViChn);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_BindInput err 0x%x\n",s32Ret);
        return HI_FAILURE;
    }

    s32Ret = HI_MPI_VENC_CreateChn(VeChn, pstAttr, HI_NULL);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_CreateChn err 0x%x\n",s32Ret);
        return HI_FAILURE;
    }

    s32Ret = HI_MPI_VENC_RegisterChn(VeGroup, VeChn);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_RegisterChn err 0x%x\n",s32Ret);
        return HI_FAILURE;
    }

    s32Ret = HI_MPI_VENC_StartRecvPic(VeChn);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_StartRecvPic err 0x%x\n",s32Ret);
        return HI_FAILURE;
    }

    return HI_SUCCESS;
}
コード例 #4
0
bool HimppVencChan::enableObject()
{
    HI_S32 s32Ret;
    GROUP_CROP_CFG_S dis_crop = { .bEnable = HI_FALSE };

    if ((s32Ret = HI_MPI_VENC_CreateGroup(_grpid)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_VENC_CreateGroup %d failed [%#x]\n",
                    _grpid, s32Ret);
        return false;
    }

    VENC_CHN_ATTR_S attr;
    prepareVencChnAttr(attr);
    if ((s32Ret = HI_MPI_VENC_CreateChn(_chnid, &attr)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_VENC_CreateChn %d faild [%#x]\n",
                    _chnid, s32Ret);
        goto err_destroy_grp;
    }

    if ((s32Ret = HI_MPI_VENC_SetMaxStreamCnt(_chnid, 4)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_VENC_SetMaxStreamCnt %d failed [%#x]\n",
                    _chnid, s32Ret);
    }

    if ((s32Ret = HI_MPI_VENC_RegisterChn(_grpid, _chnid)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_VENC_RegisterChn %d-%d failed [%#x]\n",
                    _grpid, _chnid, s32Ret);
        goto err_destroy_chn;
    }

    if ((s32Ret = HI_MPI_VENC_SetGrpCrop(_grpid, &_crop_cfg)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_VENC_SetGrpCrop [%d] faild [%#x]!\n",
                    _grpid, s32Ret);
        goto err_unregister_chn;
    }

    if ((s32Ret = HI_MPI_VENC_StartRecvPic(_chnid)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_VENC_StartRecvPic %d failed [%#x]\n",
                    _chnid, s32Ret);
        goto err_disable_crop;
    }

    MPP_CHN_S dst_chn;
    dst_chn.enModId = HI_ID_GROUP;
    dst_chn.s32DevId = _grpid;
    dst_chn.s32ChnId = 0;
    if ((s32Ret = HI_MPI_SYS_Bind(*source(), &dst_chn)) != HI_SUCCESS) {
        HIMPP_PRINT("HI_MPI_SYS_Bind %d failed [%#x]\n",
                    _chnid, s32Ret);
        goto err_stop_recv_pic;
    }

    return true;

err_stop_recv_pic:
    HI_MPI_VENC_StopRecvPic(_chnid);
err_disable_crop:
    HI_MPI_VENC_SetGrpCrop(_grpid, &dis_crop);
err_unregister_chn:
    HI_MPI_VENC_UnRegisterChn(_chnid);
err_destroy_chn:
    HI_MPI_VENC_DestroyChn(_chnid);
err_destroy_grp:
    HI_MPI_VENC_DestroyGroup(_grpid);

    return false;
}
コード例 #5
0
ファイル: hi3520a_enc.c プロジェクト: Hi-Spy/hidvr-git
static int enc_create_h264_stream(const char* name, int vin, int stream, SDK_ENC_H264_STREAM_ATTR_t* stream_attr)
{
	if(stream_attr && vin < HI_VENC_CH_BACKLOG_REF && stream < HI_VENC_STREAM_BACKLOG_REF){
		SDK_ENC_H264_STREAM_ATTR_t* this_stream_attr = &_sdk_enc.attr.video_stream_attr[vin][stream];
		if(0 == this_stream_attr->magic){
			int const venc_group = vin * HI_VENC_STREAM_BACKLOG_REF + stream;
			int const venc_ch = venc_group;
			int const vpss_group = vin;
			int const vpss_ch = (0 == stream) ? VPSS_BSTR_CHN : VPSS_LSTR_CHN;
			int bps_regular = 0;

			// hisilicon structure
			//VPSS_CHN_MODE_S vpss_chn_mode;
			//VPSS_CHN_ATTR_S vpss_chn_attr;
			MPP_CHN_S mpp_chn_vpss;
			MPP_CHN_S mpp_chn_venc;
			VENC_CHN_ATTR_S venc_chn_attr;
			VENC_ATTR_H264_REF_MODE_E venc_attr_h264_ref_mode;
			VENC_ATTR_S* const p_venc_attr = &venc_chn_attr.stVeAttr; // the attribute of video encoder
			VENC_RC_ATTR_S* const p_venc_rc_attr = &venc_chn_attr.stRcAttr; // the attribute of rate  ctrl
			VENC_ATTR_H264_S* const p_venc_attr_h264 = &p_venc_attr->stAttrH264e;
			VENC_ATTR_H264_CBR_S* const p_h264_cbr = &p_venc_rc_attr->stAttrH264Cbr;
			VENC_ATTR_H264_VBR_S* const p_h264_vbr = &p_venc_rc_attr->stAttrH264Vbr;
			VENC_ATTR_H264_FIXQP_S* const p_h264_fixqp = &p_venc_rc_attr->stAttrH264FixQp;
			VENC_ATTR_H264_ABR_S* const p_h264_abr = &p_venc_rc_attr->stAttrH264Abr;
			
			// only magic is null could be init
			// init this stream attribute;
			memcpy(this_stream_attr, stream_attr, sizeof(SDK_ENC_H264_STREAM_ATTR_t));
			strncpy(this_stream_attr->name, name, sizeof(this_stream_attr->name));
			this_stream_attr->magic = ENC_H264_STREAM_ATTR_MAGIC;
			this_stream_attr->vin = vin;
			this_stream_attr->stream = stream;
			this_stream_attr->start = false; // very important, declare the encode status

			// Greate Venc Group
			SOC_CHECK(HI_MPI_VENC_CreateGroup(venc_group));

			// Create Venc Channel
			memset(&venc_chn_attr, 0, sizeof(venc_chn_attr));
			p_venc_attr->enType = PT_H264; // must be h264 for this interface
			p_venc_attr_h264->u32MaxPicWidth = stream_attr->width;
			p_venc_attr_h264->u32MaxPicHeight = stream_attr->height;
			p_venc_attr_h264->u32PicWidth = stream_attr->width; // the picture width
			p_venc_attr_h264->u32PicHeight = stream_attr->height;// the picture height
			//p_venc_attr_h264->u32BufSize  = p_venc_attr_h264->u32MaxPicWidth * p_venc_attr_h264->u32MaxPicHeight * 3 / 2; // stream buffer size
			p_venc_attr_h264->u32BufSize  = p_venc_attr_h264->u32MaxPicWidth * p_venc_attr_h264->u32MaxPicHeight*3/4; // stream buffer size
			if(0 < (p_venc_attr_h264->u32BufSize%64)) {
				p_venc_attr_h264->u32BufSize += 64 - (p_venc_attr_h264->u32BufSize%64);
			}
			switch(stream_attr->profile){
				default:
				case SDK_ENC_H264_PROFILE_BASELINE:
					p_venc_attr_h264->u32Profile = 0;
					break;
				
				case SDK_ENC_H264_PROFILE_DEFAULT:
				case SDK_ENC_H264_PROFILE_MAIN:
					p_venc_attr_h264->u32Profile = 1;
					break;
			}
			p_venc_attr_h264->bByFrame = HI_TRUE;// get stream mode is slice mode or frame mode
			p_venc_attr_h264->bField = HI_FALSE;  // surpport frame code only for hi3516, bfield = HI_FALSE
			p_venc_attr_h264->bMainStream = HI_TRUE; // surpport main stream only for hi3516, bMainStream = HI_TRUE
			p_venc_attr_h264->u32Priority = 0; // channels precedence level. invalidate for hi3516
			p_venc_attr_h264->bVIField = HI_FALSE; // the sign of the VI picture is field or frame. Invalidate for hi3516

			switch(stream_attr->profile){
				case SDK_ENC_H264_PROFILE_BASELINE:
				{
					p_venc_attr_h264->u32Profile = 0;
					break;
				}
				case SDK_ENC_H264_PROFILE_DEFAULT:
				case SDK_ENC_H264_PROFILE_MAIN:
				{
					p_venc_attr_h264->u32Profile = 1;
					break;
				}
			}

			bps_regular = bitrate_regulate(this_stream_attr->width, this_stream_attr->height, this_stream_attr->bps);
			switch(stream_attr->mode){
				case SDK_ENC_H264_MODE_VBR:
				case SDK_ENC_H264_MODE_AUTO:
				{
					venc_chn_attr.stRcAttr.enRcMode = VENC_RC_MODE_H264VBRv2;
					p_h264_vbr->u32Gop = stream_attr->gop;
					p_h264_vbr->u32StatTime = (stream_attr->gop + stream_attr->fps - 1) / stream_attr->fps;
					p_h264_vbr->u32ViFrmRate = stream_attr->vin_fps;
					p_h264_vbr->fr32TargetFrmRate = (typeof(p_h264_vbr->fr32TargetFrmRate))stream_attr->fps;
					p_h264_vbr->u32MaxBitRate = bps_regular * 4 /3;
					p_h264_vbr->u32MinQp = 24;
					p_h264_vbr->u32MaxQp = 32;
					break;
				}

				case SDK_ENC_H264_MODE_CBR:
				case SDK_ENC_H264_MODE_ABR:
				{
					p_venc_rc_attr->enRcMode = VENC_RC_MODE_H264CBRv2;
					p_h264_cbr->u32Gop = stream_attr->gop;
					p_h264_cbr->u32StatTime = (stream_attr->gop + stream_attr->fps - 1) / stream_attr->fps;
					p_h264_cbr->u32ViFrmRate = stream_attr->vin_fps;
					p_h264_cbr->fr32TargetFrmRate = (typeof(p_h264_vbr->fr32TargetFrmRate))stream_attr->fps;
					p_h264_cbr->u32BitRate = bps_regular;
					p_h264_cbr->u32FluctuateLevel = 0;
					break;
				}
				case SDK_ENC_H264_MODE_FIXQP:
				{
					p_venc_rc_attr->enRcMode = VENC_RC_MODE_H264FIXQP;
					p_h264_fixqp->u32Gop = stream_attr->gop;
					p_h264_fixqp->u32ViFrmRate = stream_attr->vin_fps;
					p_h264_fixqp->fr32TargetFrmRate = (typeof(p_h264_vbr->fr32TargetFrmRate))stream_attr->fps;
					p_h264_fixqp->u32IQp = 20;
					p_h264_fixqp->u32PQp = 23;
					break;
				}
				default:
				{
					SOC_TRACE("H264 encode mode %d not supported!", stream_attr->mode);
					break;
				}
			}

			SOC_CHECK(HI_MPI_VENC_CreateChn(venc_ch, &venc_chn_attr));
			SOC_CHECK(HI_MPI_VENC_RegisterChn(venc_ch, venc_group));

			memset(&mpp_chn_vpss, 0, sizeof(mpp_chn_vpss));
			memset(&mpp_chn_venc, 0, sizeof(mpp_chn_venc));
			// binding venc to vpss
			mpp_chn_vpss.enModId = HI_ID_VPSS;
			mpp_chn_vpss.s32DevId = vpss_group;
			mpp_chn_vpss.s32ChnId = vpss_ch;
			mpp_chn_venc.enModId = HI_ID_GROUP;
			mpp_chn_venc.s32DevId = venc_group;
			mpp_chn_venc.s32ChnId = venc_ch;
			SOC_CHECK(HI_MPI_SYS_Bind(&mpp_chn_vpss, &mpp_chn_venc));

			// set h264 reference mode
			SOC_CHECK(HI_MPI_VENC_GetH264eRefMode(venc_ch, &venc_attr_h264_ref_mode));
			switch(stream_attr->ref_mode) {
			case SDK_ENC_H264_REF_MODE_1X:
				venc_attr_h264_ref_mode = H264E_REF_MODE_1X;
				break;
			case SDK_ENC_H264_REF_MODE_2X:
				venc_attr_h264_ref_mode = H264E_REF_MODE_2X;
				break;
			case SDK_ENC_H264_REF_MODE_4X:
				venc_attr_h264_ref_mode = H264E_REF_MODE_4X;
				break;
			}
			SOC_CHECK(HI_MPI_VENC_SetH264eRefMode(venc_ch, venc_attr_h264_ref_mode));

			// create a new video encode engine
			return SDK_SUCCESS;
		}
	}
	return SDK_FAILURE;
}
コード例 #6
0
ファイル: hi3515_enc.c プロジェクト: Hi-Spy/hidvr-git
static int enc_create_h264_stream(const char* name, int vin, int stream, SDK_ENC_H264_STREAM_ATTR_t* stream_attr)
{
	if(vin < HI_VENC_CH_BACKLOG_REF){
		if(stream < HI_VENC_STREAM_BACKLOG_REF){
			SDK_ENC_H264_STREAM_ATTR_t* const main_stream_attr = &_sdk_enc.attr.video_stream_attr[vin][0];
			SDK_ENC_H264_STREAM_ATTR_t* const this_stream_attr = &_sdk_enc.attr.video_stream_attr[vin][stream];
			if(0 == this_stream_attr->magic){
				VENC_ATTR_H264_REF_MODE_E venc_attr_h264_ref_mode;
				VENC_CHN_ATTR_S venc_chn_attr;
				VENC_ATTR_H264_S venc_attr_h264;
				VENC_ATTR_H264_RC_S venc_attr_h264_rc = {0};
				int const venc_group = vin;
				int const venc_ch = vin * HI_VENC_STREAM_BACKLOG_REF + stream;
				bool is_main = (0 == stream) ? true : false;
				
				// only magic is null could be init
				// init this stream attribute;
				memcpy(this_stream_attr, stream_attr, sizeof(SDK_ENC_H264_STREAM_ATTR_t));
				strncpy(this_stream_attr->name, name, sizeof(this_stream_attr->name));
				this_stream_attr->magic = ENC_H264_STREAM_ATTR_MAGIC; // mark it
				this_stream_attr->vin = vin;
				this_stream_attr->stream = stream;
				if(stream > 0){
					// the size of stream depands on the main stream size
					if((this_stream_attr->width != main_stream_attr->width && this_stream_attr->width * 2 != main_stream_attr->width)
						|| (this_stream_attr->height != main_stream_attr->height && this_stream_attr->height * 2 != main_stream_attr->height)){

						this_stream_attr->width = main_stream_attr->width / 2;
						this_stream_attr->height = main_stream_attr->height / 2;
					}
				}
				this_stream_attr->start = false; // very important, declare the encode status
				

				SDK_ZERO_VAL(venc_chn_attr);
				venc_chn_attr.enType = PT_H264;	// both h264
				venc_chn_attr.pValue = &venc_attr_h264;

				SDK_ZERO_VAL(venc_attr_h264);
				venc_attr_h264.bMainStream = is_main ? HI_TRUE : HI_FALSE;
				venc_attr_h264.bField = HI_FALSE;
				venc_attr_h264.bVIField = HI_FALSE;
				venc_attr_h264.u32PicWidth = this_stream_attr->width;
				venc_attr_h264.u32PicHeight = this_stream_attr->height;
				venc_attr_h264.u32ViFramerate = this_stream_attr->vin_fps;
				venc_attr_h264.u32TargetFramerate = this_stream_attr->fps;
				venc_attr_h264.u32Gop = this_stream_attr->gop;
				venc_attr_h264.u32MaxDelay = 100;
				venc_attr_h264.u32Priority = 0;
				venc_attr_h264.bByFrame = HI_TRUE;
				venc_attr_h264.u32BufSize = venc_attr_h264.u32PicWidth * venc_attr_h264.u32PicHeight * 3 / 2;
				venc_attr_h264.enRcMode = RC_MODE_CBR;
				venc_attr_h264.u32PicLevel = 0;
				//venc_attr_h264.u32Bitrate = this_stream_attr->bps;
				venc_attr_h264.u32Bitrate = bitrate_regulate(this_stream_attr->width, this_stream_attr->height, this_stream_attr->bps);

				SOC_TRACE("Creating h264 %d,%d", vin, stream);

				// create video encode group
				if(is_main){
					int vi_dev = 0;
					int vi_chn = 0;
					vimap_hi3515(vin, &vi_dev, &vi_chn);
					SOC_TRACE("Binding to (%d,%d)", vi_dev, vi_chn);
					SOC_CHECK(HI_MPI_VENC_CreateGroup(venc_group));
					SOC_CHECK(HI_MPI_VENC_BindInput(venc_group, vi_dev, vi_chn));
				}

				// create video encode channel and register it
				SOC_CHECK(HI_MPI_VENC_CreateChn(venc_ch, &venc_chn_attr, HI_NULL));
				SOC_CHECK(HI_MPI_VENC_RegisterChn(venc_group, venc_ch));

				// set h264 rc parameter
				SOC_CHECK(HI_MPI_VENC_GetH264eRcPara(venc_ch, &venc_attr_h264_rc));
				venc_attr_h264_rc.s32IdrQpMax = 42; // 050 version description point 9
				venc_attr_h264_rc.bFrameLostAllow = HI_TRUE;
				venc_attr_h264_rc.s32OsdProtectEn = HI_FALSE;
				venc_attr_h264_rc.bSceneChangeClip = HI_FALSE; // 050 version description point 13
				venc_attr_h264_rc.bVbrQpDownAllowed = HI_TRUE;
				SOC_CHECK(HI_MPI_VENC_SetH264eRcPara(venc_ch, &venc_attr_h264_rc));

				// set h264 reference mode
				SOC_CHECK(HI_MPI_VENC_GetH264eRefMode(venc_ch, &venc_attr_h264_ref_mode));
				switch(stream_attr->ref_mode) {
				case SDK_ENC_H264_REF_MODE_1X:
					venc_attr_h264_ref_mode = H264E_REF_MODE_1X;
					break;
				case SDK_ENC_H264_REF_MODE_2X:
					venc_attr_h264_ref_mode = H264E_REF_MODE_2X;
					break;
				case SDK_ENC_H264_REF_MODE_4X:
					venc_attr_h264_ref_mode = H264E_REF_MODE_4X;
					break;
				}
				SOC_CHECK(HI_MPI_VENC_SetH264eRefMode(venc_ch, venc_attr_h264_ref_mode));

				return SDK_SUCCESS;
			}
			
		}
	}
	return SDK_FAILURE;
}
コード例 #7
0
ファイル: v_producer.c プロジェクト: AxelLin/Drv
HI_S32 SampleEnable1D1H2641CifH264(HI_VOID)
{
    HI_S32 s32Ret;
    VENC_GRP VeGroup = 0;
    VENC_CHN VeChn = 0, VeChn2 = 1;

	VI_DEV ViDev = VIDEVID;
	VI_CHN ViChn = VICHNID;
	VENC_CHN_ATTR_S stAttr[2];
	VENC_ATTR_H264_S stH264Attr;
	VENC_ATTR_H264_S stH264Attr2;

	stH264Attr.u32PicWidth = 704;
	stH264Attr.u32PicHeight = 576;
	stH264Attr.bMainStream = HI_TRUE;
	stH264Attr.bByFrame = HI_TRUE;
	stH264Attr.bCBR = HI_TRUE;
	stH264Attr.bField = HI_FALSE;
	stH264Attr.bVIField = HI_FALSE;
	stH264Attr.u32Bitrate = 1024;
	stH264Attr.u32ViFramerate = 25;
	stH264Attr.u32TargetFramerate = 25;
	stH264Attr.u32BufSize = 704*576*2;
	stH264Attr.u32Gop = 100;
	stH264Attr.u32MaxDelay = 100;
	stH264Attr.u32PicLevel = 0;

	stH264Attr2.u32PicWidth = 352;
	stH264Attr2.u32PicHeight = 288;
	stH264Attr2.bMainStream = HI_FALSE;
	stH264Attr2.bByFrame = HI_TRUE;
	stH264Attr2.bCBR = HI_TRUE;
	stH264Attr2.bField = HI_FALSE;
	stH264Attr2.bVIField = HI_FALSE;
	stH264Attr2.u32Bitrate = 512;
	stH264Attr2.u32ViFramerate = 25;
	stH264Attr2.u32TargetFramerate = 25;
	stH264Attr2.u32BufSize = 352*288*2;
	stH264Attr2.u32Gop = 100;
	stH264Attr2.u32MaxDelay = 100;
	stH264Attr2.u32PicLevel = 0;


	memset(&stAttr[0], 0 ,sizeof(VENC_CHN_ATTR_S));
	stAttr[0].enType = PT_H264;
	stAttr[0].pValue = (HI_VOID *)&stH264Attr;

	memset(&stAttr[1], 0 ,sizeof(VENC_CHN_ATTR_S));
	stAttr[1].enType = PT_H264;
	stAttr[1].pValue = (HI_VOID *)&stH264Attr2;

	s32Ret = HI_MPI_VENC_CreateGroup(VeGroup);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_CreateGroup err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_BindInput(VeGroup, ViDev, ViChn);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_BindInput err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_CreateChn(VeChn, &stAttr[0], HI_NULL);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_CreateChn err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_CreateChn(VeChn2, &stAttr[1], HI_NULL);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_CreateChn err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_RegisterChn(VeGroup, VeChn);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_RegisterChn err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_RegisterChn(VeGroup, VeChn2);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_RegisterChn err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_StartRecvPic(VeChn);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_StartRecvPic err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	s32Ret = HI_MPI_VENC_StartRecvPic(VeChn2);
	if (s32Ret != HI_SUCCESS)
	{
		printf("HI_MPI_VENC_StartRecvPic err 0x%x\n",s32Ret);
		return HI_FAILURE;
	}

	return HI_SUCCESS;
}
コード例 #8
0
ファイル: sample_venc.c プロジェクト: 119/myimpsrc2
/*****************************************************************************
                    snap by mode 2
 how to snap:
 1)create snap group for each vichn,and bind them (not unbind until program end),
   that is muti snap group exit, instead of only one
 2)create one snap channel for each snap group
 3)register snap chn to its corresponding group, snapping, and then unregister
 4)repeat 3) to snap muti pictures of the channel

 features:
 1)need more memory than mode 1, because muti snap group and snap channel exit
 2)higher efficiency, because all snap chn run simultaneity.
*****************************************************************************/
HI_VOID* thread_StartSnapByMode2(HI_VOID *p)
{
    HI_S32 s32Ret;
    VENC_GRP VeGroup;
    VENC_CHN SnapChn;
    VI_DEV ViDev;
    VI_CHN ViChn;
    FILE *pFile = NULL;
    HI_S32 s32SnapCnt;
    HI_S32 s32SnapTotal;
    SNAP_SINGLE_CHN_S *pstSnapSingleChn = NULL;

    pstSnapSingleChn = (SNAP_SINGLE_CHN_S*)p;
    VeGroup = pstSnapSingleChn->VeGroup;
    SnapChn = pstSnapSingleChn->SnapChn;
    ViDev = pstSnapSingleChn->ViDev;
    ViChn = pstSnapSingleChn->ViChn;
    s32SnapTotal = pstSnapSingleChn->s32SnapTotal;

    /*note: bind snap group to vichn, not unbind while snapping*/
    s32Ret = HI_MPI_VENC_BindInput(VeGroup, ViDev, ViChn);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_BindInput err 0x%x\n", s32Ret);
        return NULL;
    }

    s32SnapCnt = 0;
    while (HI_TRUE == pstSnapSingleChn->bThreadStart)
    {
        s32Ret = HI_MPI_VENC_RegisterChn(VeGroup, SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_RegisterChn err 0x%x\n", s32Ret);
            return NULL;
        }

        s32Ret = HI_MPI_VENC_StartRecvPic(SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_StartRecvPic err 0x%x\n", s32Ret);
            return NULL;
        }

        {
            /*save jpeg picture*/
            char acFile[128]  = {0};
            //struct timeval timenow;
            sprintf(acFile, "Vichn%d_num%d.jpg", ViChn, s32SnapCnt);
            pFile = fopen(acFile, "wb");
            if (pFile == NULL)
            {
                printf("open file err\n");
                return NULL;
            }

            s32Ret = SAMPLE_GetSnapPic(SnapChn, pFile);
            if (s32Ret != HI_SUCCESS)
            {
                printf("SAMPLE_GetSnapPic err 0x%x\n", s32Ret);
                fclose(pFile);
                return NULL;
            }
            fclose(pFile);
        }

        s32Ret = HI_MPI_VENC_StopRecvPic(SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_StopRecvPic err 0x%x\n", s32Ret);
            return NULL;
        }

        s32Ret = HI_MPI_VENC_UnRegisterChn(SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_UnRegisterChn err 0x%x\n", s32Ret);
            return NULL;
        }

        s32SnapCnt++;
    }

    s32Ret = HI_MPI_VENC_UnbindInput(VeGroup);
    if (s32Ret != HI_SUCCESS)
    {
        printf("HI_MPI_VENC_UnbindInput err 0x%x\n", s32Ret);
        return NULL;
    }

    return NULL;
}
コード例 #9
0
ファイル: sample_venc.c プロジェクト: 119/myimpsrc2
/*****************************************************************************
                    snap by mode 1
 how to snap:
 1)only creat one snap group
 2)bind to a vichn to snap and then unbind
 3)repeat 2) to snap all vichn in turn

 features:
 1)save memory, because only one snap group and snap channel
 2)efficiency lower than mode 2, pictures snapped will not more than 8.
*****************************************************************************/
HI_VOID* thread_StartSnapByMode1(HI_VOID *p)
{
    HI_S32 s32Ret;
    VENC_GRP VeGroup = 0;
    VENC_CHN SnapChn = 0;
    VI_DEV ViDev = 0;
    VI_CHN ViChn = 0;
    FILE *pFile = NULL;
    HI_S32 s32SnapCnt = 0;
    HI_S32 s32SnapTotal;
    SNAP_MULTI_CHN_S *pstSnapMultiChn = NULL;
    HI_S32 s32ViChnTotal;

    pstSnapMultiChn = (SNAP_MULTI_CHN_S*)p;
    VeGroup = pstSnapMultiChn->SnapGroup;
    SnapChn = pstSnapMultiChn->SnapChn;
    ViDev = pstSnapMultiChn->ViDev;
    s32ViChnTotal = pstSnapMultiChn->s32ViChnCnt;
    s32SnapTotal = pstSnapMultiChn->s32SnapTotal;

    /* snap all vi channels in sequence.
      * step 1: bind vi
      * step 2: register snap channel to group.
      * step 3: start snap channel to receiver picture.
      * step 4: get one-picture stream and save as jpeg file.
      * step 5: undo step 3, step 2, step 1.
      * step 6: chose next vi to snap, then go to step 1
      */
    ViChn = 0;
    while (HI_TRUE == pstSnapMultiChn->bThreadStart)
    {
        s32Ret = HI_MPI_VENC_BindInput(VeGroup, ViDev, ViChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_BindInput err 0x%x\n", s32Ret);
            return NULL;
        }

        s32Ret = HI_MPI_VENC_RegisterChn(VeGroup, SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_RegisterChn err 0x%x\n", s32Ret);
            return NULL;
        }

        s32Ret = HI_MPI_VENC_StartRecvPic(SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_StartRecvPic err 0x%x\n", s32Ret);
            return NULL;
        }

        {
            /*save jpeg picture*/
            char acFile[128]  = {0};
            //struct timeval timenow;
            //gettimeofday(&timenow, NULL);
            sprintf(acFile, "Vichn%d_num%d.jpg", ViChn, s32SnapCnt);
            pFile = fopen(acFile, "wb");
            if (pFile == NULL)
            {
                printf("open file err\n");
                return NULL;
            }

            s32Ret = SAMPLE_GetSnapPic(SnapChn, pFile);
            if (s32Ret != HI_SUCCESS)
            {
                printf("SAMPLE_GetSnapPic err 0x%x\n", s32Ret);
                fclose(pFile);
                return NULL;
            }

            fclose(pFile);
        }

        s32Ret = HI_MPI_VENC_StopRecvPic(SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_StopRecvPic err 0x%x\n", s32Ret);
            return NULL;
        }

        s32Ret = HI_MPI_VENC_UnRegisterChn(SnapChn);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_UnRegisterChn err 0x%x\n", s32Ret);
            return NULL;
        }

        s32Ret = HI_MPI_VENC_UnbindInput(VeGroup);
        if (s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_VENC_UnbindInput err 0x%x\n", s32Ret);
            return NULL;
        }

        /* continue to snap next vi channel */
        ViChn++;
        if(ViChn >= s32ViChnTotal)
        {
            ViChn = 0;
            s32SnapCnt++;
        }
    }

    return NULL;
}