void *VC_FaceThreadFnc(void* param)
{
	ImageThread_S *pFaceThread;
	PF_Rect_S viRect;
	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)
           {
            HNY_Rect_S curFaceRect = pAiFaceRectInfo->faceRect[id].faceRect;
           if(stRect.x == 0 && stRect.width == 0 && stRect.y == 0 && stRect.height == 0)
           {
           stRect.x = curFaceRect.left,stRect.y = curFaceRect.bottom,stRect.width =curFaceRect.right-curFaceRect.left,height =curFaceRect.bottom-curFaceRect.top;
            }
            else
            {
            int curWidth = curFaceRect.right - curFaceRect.left;;
            int curHeight =  curFaceRect.bottom - curFaceRect.top;
            int maxWidth = 1920;
            int maxHeight = 1080;
            if(curWidth < maxWidth * 0.03|| curHeight < maxHeight * 0.03) //新检测到人脸大小太小
            {
            if(cnt == 0)
            {
            cnt = 2; //直接使用上一次稳定的人脸框
            }
            continue;
            }
            else
            {
            
            stRect.x = (stRect.x + curFaceRect.left) / 2;
            stRect.width = (stRect.width + curFaceRect.right-curFaceRect.left)/ 2;
            stRect.y = (stRect.y + curFaceRect.bottom) / 2;
            stRect.height = (stRect.height + curFaceRect.bottom-curFaceRect.top) / 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;
            }
            }



				   
					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);


             

		}
		
		printf("id[%d] set face[%d,%d--%d,%d]\n", id, expWin.h_offs, expWin.v_offs, expWin.h_size, expWin.v_size);
//		ret = SAMPLE_COMM_ISP_SET_ExpWinAttr(0, expWin);
		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;
}
int VC_SetFaceExp(PF_Rect_S rect)
{
	Uapi_ExpSwAttr_t stExpSwAttr = {0};
	unsigned char aeWeight[RAWAEBIG_WIN_NUM]= {0};
	unsigned int  delta_w, delta_h, x_start, y_start, x_end, y_end;
	int i, j, ret;	
	ret = SAMPLE_COMM_ISP_GET_ExpSwAttr(0, &stExpSwAttr);
	if(ret != 0)
	{
		DEBUG_ERROR(MODULE_CODEC, "Failed to get ae attr!");
		return ret;
	}
	delta_w = 1920 / 15;
	delta_h = 1080 / 15;
	
	    x_start = rect.x/delta_w + rect.width/(delta_w*4);
		y_start = rect.y/delta_h + rect.height/(delta_h*4);
		x_end = x_start + 3*rect.width/(delta_w*4); 
		y_end = y_start + 3*rect.height/(delta_h*4);




	for(i=0; i<RAWAEBIG_WIN_NUM; i++)
	{
		aeWeight[i] = 1;
	}

	for(i=x_start; i<x_end; i++)
	{
		for(j=y_start; j<y_end; j++)
		{
			aeWeight[i + j*15] = 254;
		}
	}

	memset(&stExpSwAttr, 0x0, sizeof(Uapi_ExpSwAttr_t));
	ret = SAMPLE_COMM_ISP_GET_ExpSwAttr(0, &stExpSwAttr);
	if(ret != 0)
	{
		DEBUG_ERROR(MODULE_CODEC, "Failed to get ae attr!");
		return ret;
	}

	stExpSwAttr.enable = 1;
	stExpSwAttr.AecOpType = RK_AIQ_OP_MODE_AUTO;

	stExpSwAttr.stAuto.SetAeRangeEn = 1;
	stExpSwAttr.stAuto.stLinAeRange.stExpTimeRange.Min = 0.000100f;
	stExpSwAttr.stAuto.stLinAeRange.stExpTimeRange.Max = 0.039900f;
	stExpSwAttr.stAuto.stLinAeRange.stGainRange.Max = 32.0f; 	/*gain_max = 32x*/
	stExpSwAttr.stAuto.stLinAeRange.stGainRange.Min = 1.0f;  	/*gain_min = 1x*/
	stExpSwAttr.stAuto.stHdrAeRange.stGainRange[0].Max = 32.0f; /*sframe gain_max = 32x*/
	stExpSwAttr.stAuto.stHdrAeRange.stGainRange[0].Min = 1.0f;  /*sframe gain_min =  1x*/


	stExpSwAttr.stAuto.stAeSpeed.DampOver = 0.2f; 
	stExpSwAttr.stAuto.stAeSpeed.DampUnder = 0.5f;

	stExpSwAttr.stAuto.stFrmRate.isFpsFix = true; 
	stExpSwAttr.stAuto.stFrmRate.FpsValue = 25; /*fps = 25*/

	stExpSwAttr.stAuto.BlackDelayFrame = 0; //2
	stExpSwAttr.stAuto.WhiteDelayFrame = 0; //4

	stExpSwAttr.stAntiFlicker.enable = false; 
	stExpSwAttr.stAntiFlicker.Frequency = AEC_FLICKER_FREQUENCY_50HZ;
	stExpSwAttr.stAntiFlicker.Mode = AEC_ANTIFLICKER_AUTO_MODE;

	stExpSwAttr.stAdvanced.enable = true;
	memcpy(stExpSwAttr.stAdvanced.DayGridWeights, aeWeight, RAWAEBIG_WIN_NUM * sizeof(uint8_t));
	memcpy(stExpSwAttr.stAdvanced.NightGridWeights, aeWeight, RAWAEBIG_WIN_NUM * sizeof(uint8_t));

	stExpSwAttr.stIris.enable = 0;

	ret = SAMPLE_COMM_ISP_SET_ExpSwAttr(0, &stExpSwAttr);
	if(ret != 0)
	{
		DEBUG_ERROR(MODULE_CODEC, "Failed to set ae attr!");
		return ret;
	}

	return ret;
}
为什么这份代码中心区域人脸亮度较高，四角区域人脸亮度低，如何优化