void *VC_FaceThreadFnc(void* param)
{
	ImageThread_S *pFaceThread;
	PF_Rect_S viRect;
	PF_Rect_S faceRect = {0};
	Uapi_ExpWin_t expWin;
	HNY_AiFaceRectInfo_S *pAiFaceRectInfo = NULL;
	char threadName[64];
	char *pBuf = NULL;
	int i, id, faceRect, width, height, ret, cnt = 0;
	PF_Rect_S stRect = {0};

	sprintf(threadName, "FaceFnc");
	prctl(PR_SET_NAME, (unsigned long)threadName, 0, 0, 0);
	pBuf = (char *)malloc(sizeof(HNY_FrameHeader_S) + sizeof(HNY_AiFaceRectInfo_S));
	if(pBuf == NULL)
	{
		DEBUG_ERROR(MODULE_CODEC, "Call malloc func err!");
		return NULL;
	}

	memset(&viRect, 0x0, sizeof(PF_Rect_S));
	VC_GetViRect(0, &viRect);

	pFaceThread = (ImageThread_S *)param;
	while(pFaceThread->threadRun)
	{
		memset(pBuf, 0x00, sizeof(HNY_FrameHeader_S) + sizeof(HNY_AiFaceRectInfo_S));
		ret = SHB_ShareBufGetOneFrame(g_imageManager.metaDataBuf, sizeof(HNY_FrameHeader_S) + sizeof(HNY_AiFaceRectInfo_S), pBuf);
		if(ret <= 0)
		{
			usleep(50*1000);
			cnt ++;
			if(cnt < 3)
				continue;
		}

		if(cnt >= 3)
		{
			cnt = 0;
			expWin.h_offs = 0;
			expWin.v_offs = 0;
			expWin.h_size = 1920;
			expWin.v_size = 1080;
		}
		else
		{
			pAiFaceRectInfo = (HNY_AiFaceRectInfo_S *)(pBuf + sizeof(HNY_FrameHeader_S));

			if(pAiFaceRectInfo->faceCnt <= 0)
			{
				usleep(50*1000);
				continue;
			}

			//查找最大人脸
			id = -1;
			faceRect = 0;
			for(i=0; i<pAiFaceRectInfo->faceCnt; i++)
			{
				width = pAiFaceRectInfo->faceRect[i].faceRect.right - pAiFaceRectInfo->faceRect[i].faceRect.left;
				height = pAiFaceRectInfo->faceRect[i].faceRect.bottom - pAiFaceRectInfo->faceRect[i].faceRect.top;
				if(faceRect < width*height)
				{
					id = i;
					faceRect = width*height;
				}
			}
			
			if(id >= 0)
           {
            PF_Rect_S curFaceRect = pAiFaceRectInfo->faceRect[id].faceRect;
           if(stRect.x == 0 && stRect.width == 0 && stRect.y == 0 && stRect.height == 0)
           {
          stRect = curFaceRect;
            }
            else
            {
            int curWidth = curFaceRect.width;
            int curHeight = curFaceRect.height;
            int maxWidth = stRect.width;
            int maxHeight = stRect.height;
            if(curWidth < maxWidth * 0.8 || curHeight < maxHeight * 0.8) //新检测到人脸大小太小
            {
            if(cnt == 0)
            {
            cnt = 3; //直接使用上一次稳定的人脸框
            }
            continue;
            }
            else
            {
            stRect.x = (stRect.x + curFaceRect.x) / 2;
            stRect.width = (stRect.width + curFaceRect.width) / 2;
            stRect.y = (stRect.y + curFaceRect.y) / 2;
            stRect.height = (stRect.height + curFaceRect.height) / 2;
            //限制人脸框的范围
            if(stRect.x < 0) 
				{stRect.x = 0;}
            if(stRect.y < 0) {stRect.y = 0;}
            if(stRect.width > viRect.width) {stRect.width = viRect.width;}
            if(stRect.height > viRect.height) {stRect.height = viRect.height;}
            }
            }
            //更新当前使用的人脸框
            id = -1;
            for(i=0; i<pAiFaceRectInfo->faceCnt; i++)
            {
            if(stRect.x >= pAiFaceRectInfo->faceRect[i].faceRect.left
            && (stRect.x + stRect.width) <= pAiFaceRectInfo->faceRect[i].faceRect.right
            && stRect.y >= pAiFaceRectInfo->faceRect[i].faceRect.top
            && (stRect.y+stRect.height) <= pAiFaceRectInfo->faceRect[i].faceRect.bottom)
            {
            id = i;
            break;
            }
            }
            if(id >= 0)
            {
            pAiFaceRectInfo->faceCnt = 1;
            pAiFaceRectInfo->faceRect[0] = pAiFaceRectInfo->faceRect[id];
            }
            else
            {
            continue;
            }
            }
            
            //获取人脸框

            if(pAiFaceRectInfo->faceCnt > 0)
            {
            faceRect = pAiFaceRectInfo->faceRect[0].faceRect;
            }
            else
            {
            usleep(50*1000);
            continue;
            }
            


				   
					expWin.h_offs      = pAiFaceRectInfo->faceRect[id].faceRect.left * viRect.width / 10000;
					expWin.v_offs     = pAiFaceRectInfo->faceRect[id].faceRect.top * viRect.height / 10000;
					expWin.h_size  = (pAiFaceRectInfo->faceRect[id].faceRect.right - pAiFaceRectInfo->faceRect[id].faceRect.left) * viRect.width / 10000;
					expWin.v_size = (pAiFaceRectInfo->faceRect[id].faceRect.bottom - pAiFaceRectInfo->faceRect[id].faceRect.top) * viRect.height / 10000;
					stRect.x	  = expWin.h_offs;
				    stRect.y	  = expWin.v_offs;
				    stRect.width  = expWin.h_size;
				    stRect.height = expWin.v_size;
					
					 ret = VC_SetFaceExp(stRect);


             

		}
		
		if(ret < 0)
		{
			DEBUG_ERROR(MODULE_CODEC, "SAMPLE_COMM_ISP_SET_ExpWinAttr failed[%d]!", ret);
		}
	}

	DEBUG_ERROR(MODULE_CODEC, "thread[%s] exit!", threadName);
	free(pBuf);

	return NULL;
}