海思hi3531d实现h264视频解码adpcm音频解码和HDMI输出音视频

把例子化简了,功能目前都正常

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#include "hi_comm_sys.h"
#include "hi_comm_vb.h"
#include "hi_comm_vdec.h"
#include "hi_comm_vpss.h"
#include "hi_comm_vo.h"
#include "hi_comm_hdmi.h"
#include "hi_comm_aio.h"
#include "hi_comm_adec.h"



#include "mpi_sys.h"
#include "mpi_vb.h"
#include "mpi_vdec.h"
#include "mpi_vpss.h"
#include "mpi_vo.h"
#include "mpi_hdmi.h"
#include "mpi_ai.h"
#include "mpi_ao.h"
#include "mpi_adec.h"




#define VO_BKGRD_RED      0xFF0000    /* red back groud color */
#define VO_BKGRD_GREEN    0x00FF00    /* green back groud color */
#define VO_BKGRD_BLUE     0x0000FF    /* blue back groud color */
#define VO_BKGRD_BLACK    0x000000    /* black back groud color */
#define VO_BKGRD_YELLOW   0xFFFF00    /* yellow back groud color */

typedef struct tagSAMPLE_ADEC_S
{
    HI_BOOL bStart;
    HI_S32 AdChn; 
    FILE *pfd;
    pthread_t stAdPid;
} SAMPLE_ADEC_S;


struct Para_Type{
	HI_CHAR srcVideoFileName[32];	//要解码的文件名
	HI_CHAR srcAudioFileName[32];
	HI_U32 u32BufSize;			//文件每次读取的大小
	HI_U32 u32Width;			//视频的宽
    HI_U32 u32Height;			//视频的高
	HI_U32 u32Frmt;				//视频的帧率
	HI_U32 u32DecChnId;			//解码通道号
	HI_U32 u32VpssChnId;		//视频处理通道号
	PAYLOAD_TYPE_E encType;		//编码格式H264
	VIDEO_MODE_E encMode;		//
	pthread_t decThread;		//解码并发送给VPSS的线程
	HI_BOOL bStopThread;		//是否停止线程

	AUDIO_DEV   AoDev;			//音频设备
	pthread_t audioThread;		//音频解码线程

}g_Para;
//SAMPLE_ADEC_S stSampleAdec;

HI_VOID * hi_video_send_to_vdec_thread(HI_VOID *args)
{
	FILE *fp=NULL;
	HI_U8 *pBuf = NULL;
	HI_S32 s32UsedBytes = 0, s32ReadLen, s32Ret;
	VDEC_STREAM_S stStream = {0};

	//二进制方式打开h264视频文件
	fp = fopen(g_Para.srcVideoFileName, "rb");
	pBuf = malloc(g_Para.u32BufSize);

	while (1)
	{
		if(g_Para.bStopThread)
			break;
		fseek(fp, s32UsedBytes, SEEK_SET);
		s32ReadLen = fread(pBuf, 1, g_Para.u32BufSize, fp);
		if (s32ReadLen == 0)				//文件已经读完,又重头开始读取,实现循环播放的效果
		{
			s32UsedBytes = 0;
			fseek(fp, 0, SEEK_SET); 		//文件指针的位置归零
			s32ReadLen = fread(pBuf, 1, g_Para.u32BufSize, fp);  
		}		
		stStream.u64PTS  = 0;
		stStream.pu8Addr = pBuf;
		stStream.u32Len  = s32ReadLen;
		stStream.bEndOfFrame = HI_FALSE;
		stStream.bEndOfStream = HI_FALSE;
		
		s32Ret = HI_MPI_VDEC_SendStream(g_Para.u32DecChnId, &stStream, 0);
		if (HI_SUCCESS != s32Ret)
        {
			sleep(1);
        }
        else
        {
            s32UsedBytes += s32ReadLen;
        }
		usleep(20000);
	};
	free(pBuf);
	fclose(fp);
	printf("video thread exit 0\n");
	return NULL;
}

void *hi_audio_send_to_adec_thread(void *parg)
{
    AUDIO_STREAM_S stAudioStream;
    HI_U32 u32Len = 1024;
    HI_U32 u32ReadLen;
    HI_S32 s32AdecChn = 0;
    HI_U8 *pAudioBuf = NULL;
    FILE *pfd = fopen(g_Para.srcAudioFileName, "rb");
    pAudioBuf = (HI_U8*)malloc(sizeof(HI_U8)*MAX_AUDIO_STREAM_LEN);

    while (1)
    {
        // read from file 
        if(g_Para.bStopThread)
			break;
        stAudioStream.pStream = pAudioBuf;
        u32ReadLen = fread(stAudioStream.pStream, 1, u32Len, pfd);
        if (u32ReadLen <= 0)
        {
            fseek(pfd, 0, SEEK_SET);//read file again
            continue;
        }
        // here only demo adec streaming sending mode, but pack sending mode is commended 
        stAudioStream.u32Len = u32ReadLen;
        HI_MPI_ADEC_SendStream(s32AdecChn, &stAudioStream, HI_TRUE);
    }

    free(pAudioBuf);
    fclose(pfd);
	printf("audio thread exit 0\n");
    return NULL;
    
}


HI_VOID hi_mpp_para_init(HI_VOID)
{
	strcpy(g_Para.srcVideoFileName, "1080P.h264");
	strcpy(g_Para.srcAudioFileName, "mysecret.adpcm");
	g_Para.u32Width = 1920;
	g_Para.u32Height = 1080;
	g_Para.u32Frmt = 60;
	g_Para.u32DecChnId = 0;
	g_Para.u32VpssChnId = 0;
	g_Para.u32BufSize = g_Para.u32Width * g_Para.u32Height;
	g_Para.encType = PT_H264;
	g_Para.encMode = VIDEO_MODE_STREAM;
	g_Para.bStopThread = HI_FALSE;
	g_Para.AoDev = 2;
}




HI_VOID hi_mpp_sys_init(HI_VOID)
{
	VB_CONF_S stVbConf = {0};
	MPP_SYS_CONF_S stSysConf = {0};

	stVbConf.u32MaxPoolCnt = VB_MAX_POOLS;
    stVbConf.astCommPool[0].u32BlkSize = 1920*1080*2;	// 1080p yuv422格式
    stVbConf.astCommPool[0].u32BlkCnt  = 20;
		
	//设置 MPP 视频缓存池属性
	HI_MPI_VB_SetConf(&stVbConf);
	//初始化 MPP 视频缓存池
	HI_MPI_VB_Init();
	//配置系统控制参数
	stSysConf.u32AlignWidth = 64;
	HI_MPI_SYS_SetConf(&stSysConf);
	//初始化 MPP 系统
	HI_MPI_SYS_Init();
}

HI_VOID hi_mpp_sys_deinit(HI_VOID)
{
	HI_S32 i=0;
	//为了防止上一次异常退出而没有进行去初始化,测试前一律先去初始化
	//去初始化 MPP 系统
	HI_MPI_SYS_Exit();
	//退出模块公共视频缓冲池
	for(i=0; i<VB_MAX_USER; i++)
	{
		HI_MPI_VB_ExitModCommPool(i);
	}
	//销毁视频缓存池
	for (i=0; i<VB_MAX_POOLS; i++)
    {
         HI_MPI_VB_DestroyPool(i);
    }
	//去初始化 MPP 视频缓存池
	HI_MPI_VB_Exit();
}

HI_VOID hi_mpp_vdec_init(HI_VOID)
{
	HI_S32 s32PicSize, s32PmvSize;
	VB_CONF_S stVbConf = {0};
	VDEC_CHN_ATTR_S stVdecAttr = {0};
	VDEC_PRTCL_PARAM_S stPrtclParam = {0};
	VDEC_CHN_PARAM_S stChnParam = {0};
	
	PAYLOAD_TYPE_E type = g_Para.encType;
	VIDEO_MODE_E encMode = g_Para.encMode;
	HI_U32 u32Width = g_Para.u32Width;
    HI_U32 u32Height = g_Para.u32Height;
	HI_U32 u32ChnId = g_Para.u32DecChnId;

	stVbConf.u32MaxPoolCnt = 2;
	VB_PIC_BLK_SIZE(u32Width, u32Height, type, s32PicSize);
	stVbConf.astCommPool[0].u32BlkSize   = s32PicSize;
	stVbConf.astCommPool[0].u32BlkCnt    = 5;
	VB_PMV_BLK_SIZE(u32Width, u32Height, type, s32PmvSize);
	stVbConf.astCommPool[1].u32BlkSize   = s32PmvSize;
	stVbConf.astCommPool[1].u32BlkCnt    = 5;

	//设置模块公共视频缓冲池属性
	HI_MPI_VB_SetModPoolConf(VB_UID_VDEC, &stVbConf);
	//初始化模块公共视频缓冲池
	HI_MPI_VB_InitModCommPool(VB_UID_VDEC);

	//创建视频解码通道
	stVdecAttr.enType=type;
	stVdecAttr.u32BufSize=2*u32Width*u32Height;
	stVdecAttr.u32Priority=5;
	stVdecAttr.u32PicWidth=u32Width;
	stVdecAttr.u32PicHeight=u32Height;
	stVdecAttr.stVdecVideoAttr.enMode=encMode;
    stVdecAttr.stVdecVideoAttr.u32RefFrameNum=1;
    stVdecAttr.stVdecVideoAttr.bTemporalMvpEnable = 1;
    HI_MPI_VDEC_CreateChn(u32ChnId, &stVdecAttr);
	
    //设置显示模式
    HI_MPI_VDEC_SetDisplayMode(0, VIDEO_DISPLAY_MODE_PLAYBACK);
	
	//获取协议相关的内存分配通道参数
    HI_MPI_VDEC_GetProtocolParam(u32ChnId, &stPrtclParam);
	
	//设置协议相关的内存分配通道参数
    stPrtclParam.enType = type;
    stPrtclParam.stH264PrtclParam.s32MaxSpsNum   = 32;
    stPrtclParam.stH264PrtclParam.s32MaxPpsNum   = 256;
    stPrtclParam.stH264PrtclParam.s32MaxSliceNum = 136;
    HI_MPI_VDEC_SetProtocolParam(u32ChnId, &stPrtclParam);

    //获取解码通道参数
    HI_MPI_VDEC_GetChnParam(u32ChnId, &stChnParam);
	//设置解码通道参数
    stChnParam.s32DecOrderOutput = 0;
    stChnParam.s32DecMode = 0;
    stChnParam.enCompressMode = COMPRESS_MODE_NONE;
    HI_MPI_VDEC_SetChnParam(u32ChnId,&stChnParam);

	//解码器开始接收用户发送的码流
    HI_MPI_VDEC_StartRecvStream(u32ChnId);

	//线程发送用户码流到解码器
	pthread_create(&g_Para.decThread, 0, hi_video_send_to_vdec_thread, NULL);
   
}

HI_VOID hi_mpp_vdec_deinit(HI_VOID)
{
    HI_MPI_VDEC_StopRecvStream(0);
    pthread_join(g_Para.decThread, NULL);
    HI_MPI_VDEC_DestroyChn(0);
    HI_MPI_VB_ExitModCommPool(VB_UID_VDEC);
}

HI_VOID hi_mpp_vpss_init(HI_VOID)
{
    VPSS_GRP VpssGrp = 0;
    VPSS_CHN VpssChn = 0;
    VPSS_GRP_ATTR_S stGrpVpssAttr;
    VPSS_CHN_ATTR_S stVpssChnAttr;

    // Create group
    stGrpVpssAttr.bHistEn   = 0;
    stGrpVpssAttr.bIeEn     = 0;
    stGrpVpssAttr.bNrEn     = 0;
    stGrpVpssAttr.bDciEn    = 0;
    stGrpVpssAttr.bEsEn     = 0;
    stGrpVpssAttr.enDieMode = VPSS_DIE_MODE_NODIE;
    stGrpVpssAttr.enPixFmt  = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stGrpVpssAttr.u32MaxW   = 3840;
    stGrpVpssAttr.u32MaxH   = 2160;

    // set channal attribute
    memset(&stVpssChnAttr, 0, sizeof(VPSS_CHN_ATTR_S));
    stVpssChnAttr.bBorderEn = HI_TRUE;
    stVpssChnAttr.stBorder.u32Color = VO_BKGRD_RED;
    stVpssChnAttr.stBorder.u32BottomWidth= 2;
    stVpssChnAttr.stBorder.u32LeftWidth = 2;
    stVpssChnAttr.stBorder.u32RightWidth = 2;
    stVpssChnAttr.stBorder.u32TopWidth = 2;
    stVpssChnAttr.bSpEn = 0;

    HI_MPI_VPSS_CreateGrp(VpssGrp, &stGrpVpssAttr);

    for (VpssChn = 0; VpssChn < VPSS_MAX_PHY_CHN_NUM; VpssChn++)
    {
        if (3 == VpssChn)
        {
            continue;
        }
        HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn,&stVpssChnAttr);

        HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);
    }
    HI_MPI_VPSS_StartGrp(VpssGrp);
}

HI_VOID hi_mpp_vpss_deinit(HI_VOID)
{
	VPSS_GRP VpssGrp = 0;
    VPSS_CHN VpssChn = 0;
    HI_MPI_VPSS_StopGrp(VpssGrp);

     for (VpssChn = 0; VpssChn < VPSS_MAX_PHY_CHN_NUM; VpssChn++)
     {
         HI_MPI_VPSS_DisableChn(VpssGrp,VpssChn);
     }
     HI_MPI_VPSS_DestroyGrp(VpssGrp); 
}

HI_VOID hi_mpp_hdmi_init(VO_INTF_SYNC_E enIntfSync)
{
    HI_HDMI_ATTR_S      stAttr;
    HI_HDMI_VIDEO_FMT_E enVideoFmt = HI_HDMI_VIDEO_FMT_1080P_60;
	
    HI_MPI_HDMI_Init();
    HI_MPI_HDMI_Open(HI_HDMI_ID_0);
    HI_MPI_HDMI_GetAttr(0, &stAttr);
	
    stAttr.bEnableHdmi = HI_TRUE;
    stAttr.bEnableVideo = HI_TRUE;
    stAttr.enVideoFmt = enVideoFmt;
    stAttr.enVidOutMode = HI_HDMI_VIDEO_MODE_YCBCR444;
    stAttr.enDeepColorMode = HI_HDMI_DEEP_COLOR_OFF;
    stAttr.bxvYCCMode = HI_FALSE;
    stAttr.bEnableAudio = HI_FALSE;
    stAttr.enSoundIntf = HI_HDMI_SND_INTERFACE_I2S;
    stAttr.bIsMultiChannel = HI_FALSE;
    stAttr.enBitDepth = HI_HDMI_BIT_DEPTH_16;
    stAttr.bEnableSpdInfoFrame = HI_FALSE;
    stAttr.bEnableMpegInfoFrame = HI_FALSE;
    stAttr.bDebugFlag = HI_FALSE;
    stAttr.bHDCPEnable = HI_FALSE;
    stAttr.b3DEnable = HI_FALSE;

    if (enIntfSync > 12)
    {
        stAttr.bEnableHdmi = HI_FALSE;
        stAttr.enVidOutMode = HI_HDMI_VIDEO_MODE_RGB444;
    }
	
    stAttr.bEnableAudio = HI_TRUE;                  /**< if enable audio */
    stAttr.enSoundIntf = HI_HDMI_SND_INTERFACE_I2S; /**< source of HDMI audio, HI_HDMI_SND_INTERFACE_I2S suggested.the parameter must be consistent with the input of AO*/

    stAttr.u8DownSampleParm = HI_FALSE;             /**< parameter of downsampling  rate of PCM audio, default: 0 */
    stAttr.u8I2SCtlVbit = 0;                        /**< reserved, should be 0, I2S control (0x7A:0x1D) */

    stAttr.bEnableAviInfoFrame = HI_TRUE;           /**< if enable AVI InfoFrame*/
    stAttr.bEnableAudInfoFrame = HI_TRUE;           /**< if enable AUDIO InfoFrame*/

    HI_MPI_HDMI_SetAttr(0, &stAttr);
    return ;
}

HI_VOID hi_mpp_hdmi_deinit(HI_VOID)
{
	HI_MPI_HDMI_Stop(0);
    HI_MPI_HDMI_Close(0);
    HI_MPI_HDMI_DeInit();
}

HI_VOID hi_mpp_vo_init(HI_VOID)
{
	VO_PUB_ATTR_S stPubAttr = {0};
	VO_CHN_ATTR_S stChnAttr = {0};
	VO_VIDEO_LAYER_ATTR_S stLayerAttr = {{0}};
	VO_PART_MODE_E enVoPartitionMode = VO_PART_MODE_MULTI;
	VO_DEV VoDev = 0;
	HI_U32 VoLayer = VoDev;
	
	HI_U32 u32Width = g_Para.u32Width;
	HI_U32 u32Height = g_Para.u32Height;
	HI_U32 u32Frmt = g_Para.u32Frmt;
	
	//获取视频输出设备的公共属性
	HI_MPI_VO_GetPubAttr(VoDev, &stPubAttr);
	stPubAttr.enIntfSync = VO_OUTPUT_1080P60;
    stPubAttr.u32BgColor = VO_BKGRD_RED;
    stPubAttr.enIntfType = VO_INTF_HDMI;
	
	//获取视频层属性
	HI_MPI_VO_GetVideoLayerAttr(VoLayer, &stLayerAttr);
	//获取视频层的分割模式
    HI_MPI_VO_GetVideoLayerPartitionMode(VoLayer, &enVoPartitionMode);
	stLayerAttr.stDispRect.s32X       = 0;
    stLayerAttr.stDispRect.s32Y       = 0;
    stLayerAttr.stDispRect.u32Width   = u32Width;
    stLayerAttr.stDispRect.u32Height  = u32Height;
    stLayerAttr.stImageSize.u32Width  = u32Width;
    stLayerAttr.stImageSize.u32Height = u32Height;
    stLayerAttr.u32DispFrmRt          = u32Frmt;
  	stLayerAttr.enPixFormat           = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stLayerAttr.bDoubleFrame          = HI_FALSE;
    stLayerAttr.bClusterMode          = HI_FALSE;

    stChnAttr.stRect.s32X       = 0;
    stChnAttr.stRect.s32Y       = 0;
    stChnAttr.stRect.u32Width   = u32Width;
    stChnAttr.stRect.u32Height  = u32Height;
    stChnAttr.u32Priority       = 0;
    stChnAttr.bDeflicker        = HI_TRUE;

	//设置视频输出设备的公共属性
	HI_MPI_VO_SetPubAttr(VoDev, &stPubAttr);
	//启用视频输出设备
	HI_MPI_VO_Enable(VoDev);
	//设置视频层的分割模式
	HI_MPI_VO_SetVideoLayerPartitionMode(VoLayer, enVoPartitionMode);
	//设置视频层属性
	HI_MPI_VO_SetVideoLayerAttr(VoLayer, &stLayerAttr);
	//使能视频层
	HI_MPI_VO_EnableVideoLayer(VoLayer);

	//设置指定视频输出通道的属性 
	HI_MPI_VO_SetChnAttr(VoLayer, 0, &stChnAttr);

	//启用指定的视频输出通道
    HI_MPI_VO_EnableChn(VoLayer, 0);
	
    hi_mpp_hdmi_init(stPubAttr.enIntfSync);	
}

HI_VOID hi_mpp_vo_deinit(HI_VOID)
{
    hi_mpp_hdmi_deinit();
    HI_MPI_VO_DisableChn(0, 0);
    HI_MPI_VO_DisableVideoLayer(0);
    HI_MPI_VO_Disable(0);
}

HI_VOID hi_mpp_audio_init(HI_VOID)
{
	AIO_ATTR_S stAioAttr = {0};
	HI_HDMI_ATTR_S stHdmiAttr = {0};
    HI_U32 u32StrmSmprate = 0;
    HI_U32 u32StrmPointNum = 0;

	ADEC_CHN_ATTR_S stAdecAttr;
    ADEC_ATTR_ADPCM_S stAdecAdpcm;
	MPP_CHN_S stSrcChn,stDestChn;

	/* init stAio. all of cases will use it */  
    stAioAttr.enBitwidth = AUDIO_BIT_WIDTH_16;
    stAioAttr.enWorkmode = AIO_MODE_I2S_MASTER;
    stAioAttr.enSoundmode = AUDIO_SOUND_MODE_MONO;
    stAioAttr.u32EXFlag = 0;
    stAioAttr.u32FrmNum = 30;
    stAioAttr.u32ChnCnt = 1;
    stAioAttr.u32ClkSel = 0;
    stAioAttr.enSamplerate = 48000;
   
    u32StrmSmprate = AUDIO_SAMPLE_RATE_8000;
    u32StrmPointNum = 320;
    stAioAttr.u32PtNumPerFrm = u32StrmPointNum * stAioAttr.enSamplerate / u32StrmSmprate;


    HI_MPI_HDMI_SetAVMute(HI_HDMI_ID_0, HI_TRUE);
    HI_MPI_HDMI_GetAttr(HI_HDMI_ID_0, &stHdmiAttr);

    stHdmiAttr.bEnableAudio = HI_TRUE;                  /**< if enable audio */
    stHdmiAttr.enSoundIntf = HI_HDMI_SND_INTERFACE_I2S; /**< source of HDMI audio, HI_HDMI_SND_INTERFACE_I2S suggested.the parameter must be consistent with the input of AO*/
    stHdmiAttr.enSampleRate = stAioAttr.enSamplerate; /**< sampling rate of PCM audio,the parameter must be consistent with the input of AO */
    stHdmiAttr.u8DownSampleParm = HI_FALSE;             /**< parameter of downsampling rate of PCM audio, default :0 */

    stHdmiAttr.enBitDepth = 8 * (stAioAttr.enBitwidth+1);   /**< bitwidth of audio,default :16,the parameter must be consistent with the config of AO */
    stHdmiAttr.u8I2SCtlVbit = 0;                        /**< reserved, should be 0, I2S control (0x7A:0x1D) */

    stHdmiAttr.bEnableAviInfoFrame = HI_TRUE;           /**< if enable AVI InfoFrame*/
    stHdmiAttr.bEnableAudInfoFrame = HI_TRUE;           /**< if enable AUDIO InfoFrame*/

    HI_MPI_HDMI_Stop(HI_HDMI_ID_0);
    HI_MPI_HDMI_SetAttr(HI_HDMI_ID_0, &stHdmiAttr);
    HI_MPI_HDMI_Start(HI_HDMI_ID_0);
    HI_MPI_HDMI_SetAVMute(HI_HDMI_ID_0, HI_FALSE);
	
    stAdecAttr.enType = PT_ADPCMA;
    stAdecAttr.u32BufSize = 20;
    stAdecAttr.enMode = ADEC_MODE_STREAM;/* propose use pack mode in your app */
    stAdecAttr.pValue = &stAdecAdpcm;
    stAdecAdpcm.enADPCMType = ADPCM_TYPE_DVI4;

    /* create adec chn*/
    HI_MPI_ADEC_CreateChn(0, &stAdecAttr);
   
    stAioAttr.u32ClkChnCnt = stAioAttr.u32ChnCnt;
 
    HI_MPI_AO_SetPubAttr(g_Para.AoDev, &stAioAttr);
    HI_MPI_AO_Enable(g_Para.AoDev);
    HI_MPI_AO_EnableChn(g_Para.AoDev, 0);
    HI_MPI_AO_DisableReSmp(g_Para.AoDev, 0);
    HI_MPI_AO_EnableReSmp(g_Para.AoDev, 0, AUDIO_SAMPLE_RATE_8000);

    stSrcChn.enModId = HI_ID_ADEC;
    stSrcChn.s32DevId = 0;
    stSrcChn.s32ChnId = 0;
    stDestChn.enModId = HI_ID_AO;
    stDestChn.s32DevId = g_Para.AoDev;
    stDestChn.s32ChnId = 0;

    HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
    pthread_create(&g_Para.audioThread, 0, hi_audio_send_to_adec_thread, NULL);
}

HI_VOID hi_mpp_audio_deinit(HI_VOID)
{
	MPP_CHN_S stSrcChn,stDestChn;
    pthread_join(g_Para.audioThread, 0);
    stSrcChn.enModId = HI_ID_ADEC;
    stSrcChn.s32ChnId = 0;
    stSrcChn.s32DevId = 0;
    stDestChn.enModId = HI_ID_AO;
    stDestChn.s32DevId = g_Para.AoDev;
    stDestChn.s32ChnId = 0;

    HI_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
	HI_MPI_AO_DisableReSmp(g_Para.AoDev, 0);
	HI_MPI_AO_DisableChn(g_Para.AoDev, 0);
	HI_MPI_AO_Disable(g_Para.AoDev);
 	HI_MPI_ADEC_DestroyChn(0);
}



//数据接收者绑定数据源
HI_VOID vpss_bind_vdec(HI_VOID)
{
    MPP_CHN_S stBindSrc;
    MPP_CHN_S stBindDest;

    stBindDest.enModId = HI_ID_VPSS;
    stBindDest.s32DevId = g_Para.u32VpssChnId;
    stBindDest.s32ChnId = 0;

    stBindSrc.enModId = HI_ID_VDEC;
    stBindSrc.s32ChnId = g_Para.u32DecChnId;
    HI_MPI_SYS_Bind(&stBindSrc, &stBindDest);
}

HI_VOID vpss_unbind_vdec(HI_VOID)
{
    MPP_CHN_S stDestChn;
    stDestChn.enModId = HI_ID_VPSS;
    stDestChn.s32DevId = 0;
    stDestChn.s32ChnId = 0;
    HI_MPI_SYS_UnBind(NULL, &stDestChn);
}

HI_VOID vo_bind_vpss(HI_VOID)
{
	MPP_CHN_S stSrcChn, stDestChn;

    stSrcChn.enModId    = HI_ID_VPSS;
    stSrcChn.s32DevId   = 0;
    stSrcChn.s32ChnId   = 0;

    stDestChn.enModId   = HI_ID_VOU;
    stDestChn.s32ChnId  = 0;
    stDestChn.s32DevId  = 0;
	
    HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
}

HI_VOID vo_unbind_vpss(HI_VOID)
{
	MPP_CHN_S stDestChn;
    stDestChn.enModId   = HI_ID_VOU;
    stDestChn.s32DevId  = 0;
    stDestChn.s32ChnId  = 0;
    HI_MPI_SYS_UnBind(NULL, &stDestChn);
}

void signal_handler(int signal)
{
	printf("signal = %d\n", signal);
	if(SIGSEGV == signal)
	{
		printf("recv SIGSEGV\n");
		
	}else if(SIGINT == signal)
	{
		printf("recv SIGINT\n");
	}
	g_Para.bStopThread = HI_TRUE;
	hi_mpp_vo_deinit();
    vo_unbind_vpss();
    vpss_unbind_vdec();
    hi_mpp_vpss_deinit();
    hi_mpp_vdec_deinit();
	exit(1);
}

HI_S32 main(int argc, char ** argv)
{
	char cmd[32] = {0};
	signal(SIGSEGV, signal_handler);
	signal(SIGINT, signal_handler);
	
	hi_mpp_para_init();
	hi_mpp_sys_deinit();
	hi_mpp_sys_init();
	hi_mpp_vdec_init();
	hi_mpp_vpss_init();
	vpss_bind_vdec();
	hi_mpp_vo_init();
	vo_bind_vpss();
	hi_mpp_audio_init();
	while(1)
	{
		printf("input 'q' to quit!\n");
		fgets(cmd, 31, stdin);
		if(strcmp(cmd, "q"))
			break;
		sleep(1);
	}
	g_Para.bStopThread = HI_TRUE;
	sleep(1);
	hi_mpp_audio_deinit();
	hi_mpp_vo_deinit();
    vo_unbind_vpss();
    vpss_unbind_vdec();
    hi_mpp_vpss_deinit();
    hi_mpp_vdec_deinit();
	hi_mpp_sys_deinit();
	printf("main exit 0\n");
	return 0;
}


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页