Can not read frames from the camera of TX1 with ioctl fuction

We use ioctl to open the camera of TX1, but buffers is null which is set to save raw data of video. We want to use the owned camera of TX1, and it is “/dev/video0” in out ubuntu OS. The following is the code to read frames from the camera.

    /* Read raw data from camera buffer. */
ret = ioctl (*fd, VIDIOC_DQBUF, &buf);
if(ret < 0)
	printf("failure read v4l2_buffers\n");
	(*v4l2_data) = (unsigned char *)v4l2_buffers[buf.index].start;
    printf("read v4l2_frame success\n");

Here, we find the valuable “v4l2_data” can not obtain raw data from buffer. Would you please tell us if the camera of TX1 need be some special setting?
build-v4l2-Release.tar.gz (88.1 KB)

Hi blueseaky,

Because v4l2-ctl works well, please refer to its source for this.


You mean v4l2-ctl can replace ioctl to open the camera of TX1 itself?

Hi buleseaky

You need to set the vi as bypass mode before capture.
Please reference to the channel.c, the vi driver only working on bypass mode.

static int tegra_channel_s_ctrl(struct v4l2_ctrl *ctrl)
	struct tegra_channel *chan = container_of(ctrl->handler,
				struct tegra_channel, ctrl_handler);

	switch (ctrl->id) {
		if (switch_ctrl_qmenu[ctrl->val] == SWITCH_ON)
			chan->bypass = true;
		else if (chan->vi->vi->bypass) {
				"can't disable bypass mode\n");
				"because the VI/CSI is in bypass mode\n");
			chan->bypass = true;
		} else
			chan->bypass = false;
		dev_err(&chan->, "%s:Not valid ctrl\n", __func__);
		return -EINVAL;

	return 0;

Is the file “channel.c” is in kernal layer of Linux OS? Actually, we want to use the camera in Qt programming environment. Therefore, how should we set the “vi as bypass mode” in Qt environment?

The code I show you is the kernel driver code. You can set IOCTL to set the bypass mode.

Thank you for your quick reply, but we can not find the MACRO to set the bypass mode of the camera. Could you send us the concrete command for ioctl function?

Have you verify your code by capturing a frame from an usb camera? Or you have try if on others platform.

We have tested a usb camera which is YUV format, and this usb camera can be opened and captured all frames successfully. But, the owned camera of TX1 can not be captured any frames, and the buffer is null always. We are very puzzled.

Could you attached your source and bin file here for debug.

Hi, we have attached the bin release file and the file which opens camera device and reads frame from camera, in #1.

Just confirm from internal designer We did support DQBUF ioctl for MMAP and USERPTR mode buffers. Based on the application choice, it has to follow steps based on the buffer mode selected. Could you trace the source of v4l2-ctl to find the setting sequence before capture a frame.

The attached compressed file contains the source file “v4l2-readframe.cpp” for setting process. In the file, there are two functions about the initialization process of camera, and the frames reading process. You can refer to them to confirm the setting sequence before capturing a frame.

My apologize I don’t familiar with QT you have to review the code by yourself.

Actually, qt is programmed with C program. Do you understand C programming language? Now, that confuse us is whether the CSI camera can be opened with ioctl and read frames. Do you give us a determined answer? We’ll be very appreciated!

We did verify the v4l2-ctl to get the raw data by the command. "v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=ov1080.raw
You can reference to the v4l2-ctl source by below like.