I'm currently combining the functionality of uvc-gadget (https://github.com/jdonald/uvc-gadget) and 6by9's yavta to allow a TC358743 output to be converted from UYVY/RGB24 to YUYV using a pi's internal ISP. The aim of this is to stream an HDMI source as a UVC webcam.
The issue I'm having is in my isp callback function, when I try to queue the converted data back to the uvc v4l2 device VIDIOC_QBUF gives me a bad address error (error 14). I presume I'm incorrectly parsing the MMAL_BUFFER_HEADER_T * buffer into the v4l2_buffer.
Here's my callback function code
Code: Select all
static void
isp_output_callback (MMAL_PORT_T * port, MMAL_BUFFER_HEADER_T * buffer)
{
static int i = 0;
struct v4l2_buffer ubuf;
int ret =0;
MMAL_STATUS_T status;
print ("isp_output_callback Buffer %p from isp, filled %d, timestamp %llu, flags %04X\n",
buffer, buffer->length, buffer->pts, buffer->flags);
struct v4l2_device *dev = (struct v4l2_device *) port->userdata;
print("setup ubuf details %p, %d %d %d %d\n",buffer->data,buffer->data[0],buffer->alloc_size, dev->vbuf.index, buffer->length);
{
CLEAR(ubuf);
ubuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
ubuf.memory = V4L2_MEMORY_USERPTR;
ubuf.m.userptr = (unsigned long )(buffer->data) ;
ubuf.length = buffer->alloc_size;
ubuf.index = dev->vbuf.index;;//vbuf.index;
ubuf.bytesused = buffer->length;
}
ret = ioctl (dev->udev->uvc_fd, VIDIOC_QBUF, &ubuf);
if (ret < 0) {
printf ("UVC: Unable to queue buffer %d: %s (%d) %d.\n",
ubuf.index, strerror (errno), errno, dev->udev->uvc_fd);
// Check for a USB disconnect/shutdown event.
if (errno == ENODEV) {
dev->udev->uvc_shutdown_requested = 1;
printf ("UVC: Possible USB shutdown requested from "
"Host, seen during VIDIOC_QBUF\n");
}
status = mmal_port_send_buffer (dev->isp->output[0], buffer);
i++
}
background
- UVC gadget requires YUYV pixelformat, and TC358743 only outputs RGB24 or UYVY. If it's not converted the colours are incorrect.
- I've tried gstreamer to do the conversion to a v4l2loopback but the framerates are low about 5fps on my pizero with the cpu at 100%.
- I've modified yavta to do the format conversion and then simply write to the v4l2loopback device. This works and the framerates are about x2 faster than gstreamer but I think removing the loopback device will help enormously. So this leads me to this dive into MMAL/V4L2 programming.
