typedef struct MCBackendV4l2 {
MaruCamBackend base;
- char *dev_name;
+ char dev_name[16];
int fd;
int convert_trial;
int ready_count;
}
}
-static uint32_t stop_capturing(MCBackendV4l2 *backend)
+static int32_t stop_capturing(MCBackendV4l2 *backend)
{
enum v4l2_buf_type type;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(backend->fd, VIDIOC_STREAMOFF, &type) < 0) {
ERR("Failed to ioctl() with VIDIOC_STREAMOFF: %s\n", strerror(errno));
- return errno;
+ return -errno;
}
return 0;
}
-static uint32_t start_capturing(MCBackendV4l2 *backend)
+static int32_t start_capturing(MCBackendV4l2 *backend)
{
enum v4l2_buf_type type;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl(backend->fd, VIDIOC_STREAMON, &type) < 0) {
ERR("Failed to ioctl() with VIDIOC_STREAMON: %s\n", strerror(errno));
- return errno;
+ return -errno;
}
return 0;
}
backend->fb_num = 0;
}
-static uint32_t
+static int32_t
mmap_framebuffers(MCBackendV4l2 *backend)
{
struct v4l2_requestbuffers req;
} else {
ERR("Failed to request bufs: %s\n", strerror(errno));
}
- return errno;
+ return -errno;
}
if (req.count == 0) {
ERR("Insufficient buffer memory on %s\n", backend->dev_name);
- return EINVAL;
+ return -EINVAL;
}
*fb = g_new0(MCBuffer, req.count);
if (*fb == NULL) {
ERR("Not enough memory to allocate framebuffers\n");
- return ENOMEM;
+ return -ENOMEM;
}
for (*buf_num = 0; *buf_num < req.count; ++*buf_num) {
if (xioctl(backend->fd, VIDIOC_QUERYBUF, &buf) < 0) {
ERR("Failed to ioctl() with VIDIOC_QUERYBUF: %s\n",
strerror(errno));
- return errno;
+ return -errno;
}
(*fb)[*buf_num].size = buf.length;
backend->fd, buf.m.offset);
if (MAP_FAILED == (*fb)[*buf_num].data) {
ERR("Failed to mmap: %s\n", strerror(errno));
- return errno;
+ return -errno;
}
/* Queue the mapped buffer. */
buf.index = *buf_num;
if (xioctl(backend->fd, VIDIOC_QBUF, &buf) < 0) {
ERR("Failed to ioctl() with VIDIOC_QBUF: %s\n", strerror(errno));
- return errno;
+ return -errno;
}
}
return 0;
{
MCBackendV4l2 *backend = (MCBackendV4l2 *)(state->backend);
+ if (backend->dev_name[0] == '\0') {
+ const char *dev_name = "/dev/video0";
+ pstrcpy(backend->dev_name, sizeof(backend->dev_name), dev_name);
+ }
+
backend->fd = v4l2_open(backend->dev_name, O_RDWR | O_NONBLOCK, 0);
if (backend->fd < 0) {
ERR("The v4l2 device open failed: %s\n", backend->dev_name);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
INFO("Opened\n");
backend->dst_fmt.fmt.pix.height,
backend->dst_fmt.fmt.pix.sizeimage);
- state->io_ptr->err_code = mmap_framebuffers(backend);
- if (state->io_ptr->err_code) {
+ state->io_ptr->ret_val = mmap_framebuffers(backend);
+ if (state->io_ptr->ret_val) {
ERR("Failed to mmap framebuffers\n");
if (backend->fbs != NULL) {
free_framebuffers(backend);
}
- state->io_ptr->ret_val = -1;
return;
}
- state->io_ptr->err_code = start_capturing(backend);
- if (state->io_ptr->err_code) {
+ state->io_ptr->ret_val = start_capturing(backend);
+ if (state->io_ptr->ret_val) {
if (backend->fbs != NULL) {
free_framebuffers(backend);
}
- state->io_ptr->ret_val = -1;
return;
}
backend_v4l2_storedframe_set(backend);
}
- state->io_ptr->err_code = stop_capturing(backend);
- if (state->io_ptr->err_code) {
+ state->io_ptr->ret_val = stop_capturing(backend);
+ if (state->io_ptr->ret_val) {
ERR("Try again to turn off streaming\n");
- state->io_ptr->err_code = stop_capturing(backend);
+ state->io_ptr->ret_val = stop_capturing(backend);
}
if (backend->fbs != NULL) {
free_framebuffers(backend);
strerror(errno));
}
- if (state->io_ptr->err_code) {
- state->io_ptr->ret_val = -1;
- }
-
INFO("Stopping preview\n");
}
ERR("Failed to set video format: format(0x%x), w:h(%d:%d), "
"errstr(%s)\n", f->fmt.pix.pixelformat, f->fmt.pix.width,
f->fmt.pix.height, strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
if (xioctl(backend->fd, VIDIOC_G_FMT, f) < 0) {
ERR("Failed to get video format: %s\n", strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
TRACE("Get the format: w:h(%dx%d), fmt(0x%x), "
ERR("Failed to check video format: format(0x%x), w:h(%d:%d),"
" errstr(%s)\n", f->fmt.pix.pixelformat, f->fmt.pix.width,
f->fmt.pix.height, strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
TRACE("Check the format: w:h(%dx%d), pix_fmt(0x%x), "
struct v4l2_fmtdesc *f = (struct v4l2_fmtdesc *)state->io_ptr->data;
if (f->index >= ARRAY_SIZE(support_fmts)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
break;
default:
ERR("Invalid fixel format\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
break;
}
}
break;
default:
ERR("Invalid control ID\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
if (errno != EINVAL) {
ERR("Failed to query video controls: %s\n", strerror(errno));
}
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
} else {
struct v4l2_control sctrl, gctrl;
ERR("[%s] Failed to get video control value: id(0x%x), "
"errstr(%s)\n",
__func__, gctrl.id, strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
ERR("[%s] Failed to set control value: id(0x%x), value(%d), "
"errstr(%s)\n",
__func__, sctrl.id, sctrl.value, strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
- INFO("Query Control: id(0x%x), name(%s), min(%d), max(%d), "
- "step(%d), def_value(%d)\n"
- "flags(0x%x), get_value(%d), set_value(%d)\n",
+ INFO("Query Control: id(0x%x), name(%s), min(%d), max(%d), step(%d), "
+ "def_value(%d), flags(0x%x), get_value(%d), set_value(%d)\n",
qc->id, qc->name, qc->minimum, qc->maximum,
qc->step, qc->default_value, qc->flags,
gctrl.value, sctrl.value);
break;
default:
ERR("Our emulator does not support this control: 0x%x\n", ctrl->id);
- state->io_ptr->err_code= EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val= EINVAL;
return;
}
if (xioctl(backend->fd, VIDIOC_S_CTRL, ctrl) < 0) {
ERR("Failed to set control value: id(0x%x), value(%d), errstr(%s)\n",
ctrl->id, ctrl->value, strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
}
break;
default:
ERR("Our emulator does not support this control: 0x%x\n", ctrl->id);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
if (xioctl(backend->fd, VIDIOC_G_CTRL, ctrl) < 0) {
ERR("Failed to get video control value: %s\n", strerror(errno));
- state->io_ptr->err_code = errno;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -errno;
return;
}
ctrl->value = value_convert_to_guest(ctrl_tbl[i].min,
uint32_t i;
if (fsize->index >= ARRAY_SIZE(support_frames)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
for (i = 0; i < ARRAY_SIZE(support_fmts); i++) {
}
if (i == ARRAY_SIZE(support_fmts)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
fival->discrete.denominator = 30;
break;
default:
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
}
if (FAILED(hr)) {
ERR("CoInitailizeEx failure\n");
ERR("Device open failed: HRESULT(0x%x)\n", hr);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
RemoveFilters(backend);
CloseInterfaces(backend);
CoUninitialize();
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
RemoveFilters(backend);
CloseInterfaces(backend);
CoUninitialize();
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
RemoveFilters(backend);
CloseInterfaces(backend);
CoUninitialize();
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
RemoveFilters(backend);
CloseInterfaces(backend);
CoUninitialize();
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
RemoveFilters(backend);
CloseInterfaces(backend);
CoUninitialize();
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
hr = HWCPin_SetCallback(backend->pInPin, backend->pCallback);
if (FAILED(hr)) {
ERR("Failed to set IGrabCallback interface.\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
}
backend->buf = (void *)g_malloc0(state->buf_size);
if (backend->buf == NULL) {
- state->io_ptr->err_code = ENOMEM;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -ENOMEM;
return;
}
hr = IMediaControl_Run(backend->pMC);
if (FAILED(hr)) {
ERR("Failed to run media control. hr=0x%x\n", hr);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
hr = HWCPin_SetCallback(backend->pInPin, NULL);
if (FAILED(hr)) {
ERR("Failed to set IGrabCallback interface.\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
hr = backend->pMC->lpVtbl->Stop(backend->pMC);
if (FAILED(hr)) {
ERR("Failed to stop media control.\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
}
}
if (fidx == ARRAY_SIZE(support_frames)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
for (pidx = 0; pidx < ARRAY_SIZE(support_fmts); pidx++) {
}
}
if (pidx == ARRAY_SIZE(support_fmts)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
HRESULT hr = SetFormat(backend, f->fmt.pix.width, f->fmt.pix.height,
f->fmt.pix.pixelformat);
if (FAILED(hr)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
}
}
}
if (i == ARRAY_SIZE(support_frames)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
for (i = 0; i < ARRAY_SIZE(support_fmts); i++) {
}
}
if (i == ARRAY_SIZE(support_fmts)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
struct v4l2_fmtdesc *f = (struct v4l2_fmtdesc *)state->io_ptr->data;
if (f->index >= ARRAY_SIZE(support_fmts)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
break;
default:
ERR("Invalid fixel format\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
break;
}
}
break;
default:
ERR("Invalid control ID\n");
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
hr = QueryVideoProcAmp(backend, property, &min, &max, &step, &def_val);
if (FAILED(hr)) {
ERR("Failed to query video controls: HRESULT(0x%x)\n", hr);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
} else {
ctrl_tbl[i].hit = 1;
if (FAILED(hr)) {
ERR("Failed to set video control value when query controls: "
"HRESULT(0x%x)\n", hr);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;
return;
}
INFO("Query Control: id(0x%x), name(%s), "
break;
default:
ERR("Our emulator does not support this control: 0x%x\n", ctrl->id);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
set_val = value_convert_from_guest(ctrl_tbl[i].min,
hr = SetVideoProcAmp(backend, property, set_val);
if (FAILED(hr)) {
ERR("Failed to set video control value: HRESULT(0x%x)\n", hr);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
}
break;
default:
ERR("Our emulator does not support this control: 0x%x\n", ctrl->id);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
hr = GetVideoProcAmp(backend, property, &get_val);
if (FAILED(hr)) {
ERR("Failed to get video control value: HRESULT(0x%x)\n", hr);
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
uint32_t i;
if (fsize->index >= ARRAY_SIZE(support_frames)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
for (i = 0; i < ARRAY_SIZE(support_fmts); i++) {
}
if (i == ARRAY_SIZE(support_fmts)) {
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
fival->discrete.denominator = 30;
break;
default:
- state->io_ptr->err_code = EINVAL;
- state->io_ptr->ret_val = -1;
+ state->io_ptr->ret_val = -EINVAL;;
return;
}
}