gpt4 book ai didi

c++ - Video4Linux 在开始捕获时崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:34 25 4
gpt4 key购买 nike

我尝试使用 video4linux 和 mmap 方法从网络摄像头捕获图像。我的设备是 Gentoo Linux(内核版本 2.6.33.20)上的 Aptina MT9M114 相机。代码基于此示例程序:http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html

当我想开始捕获时,我运行以下代码来准备缓冲区:

enum v4l2_buf_type type;

for (uint8_t i = 0; i < n_buffers; i++) {
struct v4l2_buffer buf;
CLEAR (buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;

if (-1 == ioctl(fd, VIDIOC_QBUF, &buf)) {
return false;
}
}

当在这里调用 ioctl() 时,我遇到了深层崩溃。这是我的系统日志,我没有更多信息:

Mar  2 20:06:30 nao33 klogd: kernel BUG at drivers/media/video/videobuf-core.c:227!
Mar 2 20:06:30 nao33 klogd: invalid opcode: 0000 [#2] PREEMPT
...
Mar 2 20:06:30 nao33 klogd: EIP: 0060:[<f804dad3>] EFLAGS: 00010246 CPU: 0
Mar 2 20:06:30 nao33 klogd: EIP is at videobuf_qbuf+0x23f/0x32d [videobuf_core]
Mar 2 20:06:30 nao33 klogd: EAX: 00000001 EBX: f5bf7e6c ECX: 00000000 EDX: f5bf7e6c
Mar 2 20:06:30 nao33 klogd: ESI: f6bcf61c EDI: f657f140 EBP: f5bf7dc4 ESP: f5bf7db4
Mar 2 20:06:30 nao33 klogd: DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 0068 preempt:00000000
Mar 2 20:06:30 nao33 klogd: Process videoexample (pid: 2979, ti=f5bf6000 task=f5bf00b0 task.ti=f5bf6000)
Mar 2 20:06:30 nao33 klogd: Stack:
Mar 2 20:06:30 nao33 klogd: f5bf7e6c f5bf7e6c 00000000 f8255ca3 f5bf7dcc f8255cb0 f5bf7e48 f8148980
Mar 2 20:06:30 nao33 klogd: <0> 0000ee34 00000001 c14a6e94 c044560f f6bcf600 f5bfb540 f825777c f6b18000
Mar 2 20:06:30 nao33 klogd: <0> c14a6e94 f5bf7e10 c101ee52 00000000 f5bf00b0 f5bf7e20 c100160a f5bf0d80
Mar 2 20:06:30 nao33 klogd: Call Trace:
Mar 2 20:06:30 nao33 klogd: [<f8255ca3>] ? vidioc_qbuf+0x0/0xf [unicorn]
Mar 2 20:06:30 nao33 klogd: [<f8255cb0>] ? vidioc_qbuf+0xd/0xf [unicorn]
Mar 2 20:06:30 nao33 klogd: [<f8148980>] ? __video_do_ioctl+0xe00/0x2d31 [videodev]
Mar 2 20:06:30 nao33 klogd: [<c101ee52>] ? set_next_entity+0xab/0x117
Mar 2 20:06:30 nao33 klogd: [<c100160a>] ? __switch_to+0x12/0x14d
Mar 2 20:06:30 nao33 klogd: [<c112dd83>] ? might_fault+0x14/0x16
Mar 2 20:06:30 nao33 klogd: [<c112dedc>] ? _copy_from_user+0x31/0x115
Mar 2 20:06:30 nao33 klogd: [<f814ab79>] ? video_ioctl2+0x2c8/0x368 [videodev]
Mar 2 20:06:30 nao33 klogd: [<c104635f>] ? T.366+0x27/0x33
Mar 2 20:06:30 nao33 klogd: [<f814a8b1>] ? video_ioctl2+0x0/0x368 [videodev]
Mar 2 20:06:30 nao33 klogd: [<f814711c>] ? v4l2_ioctl+0x33/0x37 [videodev]
Mar 2 20:06:30 nao33 klogd: [<c1085daf>] ? vfs_ioctl+0x69/0x91
Mar 2 20:06:30 nao33 klogd: [<c10862ad>] ? do_vfs_ioctl+0x448/0x486
Mar 2 20:06:30 nao33 klogd: [<c107c9dd>] ? fget_light+0x87/0x91
Mar 2 20:06:30 nao33 klogd: [<c108632c>] ? sys_ioctl+0x41/0x61
Mar 2 20:06:30 nao33 klogd: [<c1002790>] ? sysenter_do_call+0x12/0x26
Mar 2 20:06:30 nao33 klogd: Code: 0f 8e e1 00 00 00 68 ba ec 04 f8 e9 77 fe ff ff 83 3d cc f4 04 f8 00 7e 0b 68 dc ec 04 f8 e8 13 e3 29 c9 5a 8b 4e 48 85 c9 75 04 <0f> 0b eb fe 83 f9 07 75 1d 83 7e 4c 02 75 0b c7 46 4c 03 00 00
Mar 2 20:06:30 nao33 klogd: EIP: [<f804dad3>] videobuf_qbuf+0x23f/0x32d [videobuf_core] SS:ESP 0068:f5bf7db4

有人提示一下,这里有什么问题吗?实际上这段代码应该可以工作,因为它在我的本地电脑上工作并且主要是从这个示例中复制的。所以我不知道如何找到问题。

最佳答案

该错误似乎与设置图像尺寸的过程有关。设置 V4L2_FIELD_NONE 而不是 V4L2_FIELD_ANY 解决了崩溃问题。

struct v4l2_format fmt;
...
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = ...
fmt.fmt.pix.height = ...
fmt.fmt.pix.pixelformat = ...
fmt.fmt.pix.field = V4L2_FIELD_NONE;

关于c++ - Video4Linux 在开始捕获时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13922022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com