Ошибка:
Код: Выделить всё
VIDIOC_ENUM_FMT: Inappropriate ioctl for device
< /code>
Я удалил другой код, так как он был слишком длинным и неактуальным, так как он даже не доходит до этих других вызовов.#include
#include
#include
#include [*]
#include
#include
#include
#include
#include
#include // ioctl
#include
#include // size_t usage
#include // uint32_t usage
#include // std::cout
// Change this to set the image format.
static const uint32_t FORMAT_INDEX = 0;
static const char DEVICE[] = "/dev/video7";
int fd;
// Wrapper around ioctl calls.
static int xioctl(int fd, int request, void *arg) {
int r;
do {
r = ioctl(fd, request, arg);
} while (-1 == r && EINTR == errno);
return r;
}
static void init_device() {
struct v4l2_fmtdesc fmtdesc = {0};
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmtdesc.index = FORMAT_INDEX;
// Enumerate formats
// Errors out here.
if (-1 == xioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) {
perror("VIDIOC_ENUM_FMT");
exit(errno);
}
printf("\nUsing format: %s\n", fmtdesc.description);
struct v4l2_format fmt = {0};
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
// This gets changed / overwritten when we make the ioctl call.
fmt.fmt.pix.width = 640;
fmt.fmt.pix.height = 480;
fmt.fmt.pix.pixelformat = fmtdesc.pixelformat;
fmt.fmt.pix.field = V4L2_FIELD_NONE;
// Set format
if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt)) {
perror("VIDIOC_S_FMT");
exit(errno);
}
char format_code[5];
strncpy(format_code, (char*)&fmt.fmt.pix.pixelformat, 5);
printf(
"Set format:\n"
" Width: %d\n"
" Height: %d\n"
" Pixel forma: %s\n"
" Field: %d\n",
fmt.fmt.pix.width,
fmt.fmt.pix.height,
format_code,
fmt.fmt.pix.field
);
init_mmap();
}
// Main
int main() {
// Open device file.
int fd = open(DEVICE, O_RDWR);
if (fd < 0) {
perror(DEVICE);
return errno;
}
init_device();
return 0;
}
< /code>
my example-6.cpp's Makefile: < /p>
CC=g++
CCFLAGS=Wall
example-6: example-6.cpp
$(CC) $(CCFLAGS) $^ -o $@
clean:
rm -f example-6
< /code>
Пожалуйста, помогите. < /p>
Я пробовал: < /p>
Проверка этого /dev /video7 < /code> существует. Open () Проверка ручка устройства с помощью fStat () и без ошибок. Удивительно, но он работает без этих ошибок. < /P>
< /li>
< /ul>
Ресурсы: < /p>
Ioctl Man Page < /li>
< /ul>
Подробнее здесь: https://stackoverflow.com/questions/795 ... for-device