[RK3288][Android6.0] 调试笔记 --- Camera HAL固定fps的方法

Platform: RK3288
OS: Android 6.0
Kernel: 3.10.92

为了降低cpu使用率, 就从降低fps入手.

理论上可以通过正常的ioctl接口去操作:
CameraUSBAdapter.cpp:
CameraUSBAdapter::initDefaultParameters(int camFd)
{
......
    memset(&setfps, 0, sizeof(struct v4l2_streamparm));
    setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    setfps.parm.capture.timeperframe.numerator=1;
    setfps.parm.capture.timeperframe.denominator=fps_max;    //修改此行
    ret = ioctl(mCamFd, VIDIOC_S_PARM, &setfps);
......
}
或者修改这里面的
int CameraUSBAdapter::cameraConfig(const CameraParameters &tmpparams,bool isInit,bool &isRestartValue)
{
......
    setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    setfps.parm.capture.timeperframe.numerator=1;
    setfps.parm.capture.timeperframe.denominator=params.getPreviewFrameRate();
    err = ioctl(mCamFd, VIDIOC_S_PARM, &setfps);
......
}

但从log看到,当前使用的uvc camera帧率是固定无法修改:
D CameraHal: initDefaultParameters(540): Support Preview FPS range: (30000,30000)

只支持30fps,因此从HAL层下手,kernel帧率不变, HAL层丢弃一些帧,比如我要15fps, 改动如下:
CameraAdapter.cpp:
int CameraAdapter::getFrame(FramInfo_s** tmpFrame){
......
/*Kris, 170210, reduce fps to lower cpu usage. {*/
#if 0
    if(mPreviewFrameIndex++ < FILTER_FRAME_NUMBER)
#else
    mPreviewFrameIndex++;
     if(mPreviewFrameIndex < FILTER_FRAME_NUMBER || mPreviewFrameIndex % 2 == 0)
#endif
/*Kris, 170210, reduce fps to lower cpu usage. }*/

    {
        LOG2("%s:filter frame %d",__FUNCTION__,mPreviewFrameIndex);
        mCamDriverStreamLock.lock();
        if(mCamDriverStream)
        ioctl(mCamFd, VIDIOC_QBUF, &cfilledbuffer1);
        mCamDriverStreamLock.unlock();
        goto FILTER_FRAMES;
    }
......
}

你可能感兴趣的:(子类__Camera)