V4L2如何设置帧率?

本帖最后由 luffy 于 2019-12-6 16:54 编辑

RK3399平台
Sensor 支持120FPS, 我设置的60FPS, 但是我v4l2读取速率一直都是30FPS, 测MIPI信号也是差不多60FPS


读取代码如下:

int Camera::readFrame()
{
  struct v4l2_buffer buf;
  int i, bytesused;

  CLEAR(buf);

  buf.type = m_bufType;
  buf.memory = V4L2_MEMORY_MMAP;

  if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == m_bufType) {
    struct v4l2_plane planes[FMT_NUM_PLANES];
    buf.m.planes = planes;
    buf.length = FMT_NUM_PLANES;
  }

  if (-1 == xioctl(m_camfd, VIDIOC_DQBUF, &buf)) {
    ERR("VIDIOC_DQBUF");
    return -1;
  }

  i = buf.index;

  if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == m_bufType)
    bytesused = buf.m.planes[0].bytesused;
  else
    bytesused = buf.bytesused;

  uint8_t *pdata = (uint8_t *)(m_imgBuffers[i].start);
  for (size_t i = 0; i < m_width*m_height*2; i+=2) {
    m_rawBuffer[i] = pdata[i+1];
    m_rawBuffer[i+1] = pdata[i];
  }

  if (-1 == xioctl(m_camfd, VIDIOC_QBUF, &buf)) {
    ERR("VIDIOC_QBUF");
    return -1;
  }

  return 0;
}

bool Camera::trigger()
{
  struct reg_map regs[] = {
    {0x1100, 0x01},
    {REG_NULL, 0x00},
  };
  return ioctl(m_camconf_fd, SET_REGS_ONLINE_CMD, regs) == 0 ? true : false;
}

int Camera::nextFrame(std::vector<CameraFrame> &frames)
{
  if (m_triggerMode) {
    if (!trigger()) {
      LOG(ERROR) << "trigger error";
      return -1;
    }
  }

  std::lock_guard<std::mutex> l(m_runLock);
  if (!m_isRunning) {
    LOG(ERROR) << "not running, can not read frame";
    return -1;
  }

  TimeMeasure tm;
  tm.addRecord("all");
  tm.addRecord("read");
  if (readFrame() == -1) {
    return -1;
  }
  LOG(INFO) << "read frame cost: " << tm.stopRecord("read") << "ms";

  CameraFrame frame;
  frame.pdata = m_rawBuffer;
  frame.step = m_width * 2;
  frame.type = kTypeGray;
  frame.width = m_width;
  frame.height = m_height;
  frame.fmt = kFmt16Gray;
  frames.push_back(frame);

  return 0;
}

驱动配置如下:

        {
                .width = 640,
                .height = 480,
                .max_fps = {
                        .numerator = 1,
                        .denominator = 120,
                },
                .hts_def = 640,
                .vts_def = 480,
                .regs_size = ARRAY_SIZE(cam_640x480_regs),
                .reg_list = cam_640x480_regs,
        },
static int cam_g_frame_interval(struct v4l2_subdev *sd,
                                    struct v4l2_subdev_frame_interval *fi)
{
        struct mycam *mycam = to_mycam(sd);
        const struct mycam_mode *mode = mycam->cur_mode;

        mutex_lock(&mycam->mutex);
        fi->interval = mode->max_fps;
        mutex_unlock(&mycam->mutex);

        return 0;
}

请问解决了吗

这代码是在哪里? 可以提供下代码文件?