V4L2_CameraParameterSetting.c 2.8 KB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h> /* getopt_long() */
#include <fcntl.h>  /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include <linux/videodev2.h>
#include "./V4L2_CameraParameterSetting.h"
#include "JZsdkLib.h"
#include "../Camera.h"

#include "MediaProc/MediaParm.h"

T_JZsdkReturnCode V4L2_Parameter_Setting(JZsdk_CameraInfo *CameraInfo)
{
    struct v4l2_control ctrl;

    //设置亮度*
    if (CameraInfo->CameraParam.Brightness != 0)
    {
        ctrl.id= V4L2_CID_BRIGHTNESS;
        ctrl.value = CameraInfo->CameraParam.Brightness;
        if(ioctl(CameraInfo->CameraFd,VIDIOC_S_CTRL,&ctrl)==-1)
        {
            JZSDK_LOG_INFO("相机亮度设置失败");
        }
    }
    
    //设置对比度
    if (CameraInfo->CameraParam.Contrast != 0)
    {
        ctrl.id = V4L2_CID_CONTRAST;
        ctrl.value= CameraInfo->CameraParam.Contrast;
        if(ioctl(CameraInfo->CameraFd,VIDIOC_S_CTRL,&ctrl)==-1)
        {
            JZSDK_LOG_INFO("相机对比度设置失败");
        }
    }
    
    //设置饱和度
    if (CameraInfo->CameraParam.Saturation != 0)
    {
        ctrl.id = V4L2_CID_SATURATION;
        ctrl.value= CameraInfo->CameraParam.Saturation;
        if(ioctl(CameraInfo->CameraFd,VIDIOC_S_CTRL,&ctrl)==-1)
        {
            perror("相机饱和度设置失败");
        }
    }

    
/* 
    //设置色度
    ctrl.id = V4L2_CID_HUE;
    ctrl.value = 1;
    if(ioctl(cam_fd,VIDIOC_S_CTRL,&ctrl)==-1)
    {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }

      //设置手动白平衡
    ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
    ctrl.value = V4L2_WHITE_BALANCE_MANUAL ;
    if(ioctl(cam_fd,VIDIOC_G_CTRL,&ctrl)==-1)
    {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
      
 
    //设置白平衡色温
    ctrl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
    ctrl.value = 5100;
     if(ioctl(cam_fd,VIDIOC_S_CTRL,&ctrl)==-1)
    {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
 
 
    //设置锐度
    ctrl.id = V4L2_CID_SHARPNESS;
    ctrl.value = 4;
    if(ioctl(cam_fd,VIDIOC_S_CTRL,&ctrl)==-1)
    {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
 
    
    //设置背光补偿
    ctrl.id = V4L2_CID_BACKLIGHT_COMPENSATION;
    ctrl.value = 3;
    if(ioctl(cam_fd,VIDIOC_S_CTRL,&ctrl)==-1)
    {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
 
    //设置伽玛值
    ctrl.id = V4L2_CID_GAMMA;
    ctrl.value = 120;
    if(ioctl(cam_fd,VIDIOC_S_CTRL,&ctrl)==-1)
    {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
*/
    JZSDK_LOG_INFO("V4L2_Parameter_Setting success");

    return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}