streaming capture problem at VIDIOC_QBUF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



I'm trying to write a simple application to do streaming capture from a bt878.
Specifically, this is a Hauppage WinTV 401 (identifies in kernel log as
card=10).  bttv-0.9.3 on kernel 2.4.18, patched for the v4l2 api.  Running the
bttv.o and video-buf.o from bttv-0.9.3 rather than the bttv.o supplied with the
2.4 kernel.

I can read() the frames just fine, although only at 10 frames per second.
mmaping fails when I get to the VIDIOC_QBUF step with the ever helpful EINVAL.

What am I doing wrong??  I've enclosed the relavent section of code (temporary
crap code to learn the api with).

    memset (&requestbuffers, 0, sizeof (requestbuffers));
    requestbuffers.count = 4;
    requestbuffers.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    requestbuffers.memory = V4L2_MEMORY_MMAP;

    r = ioctl (vd, VIDIOC_REQBUFS, &requestbuffers);
    if (r < 0)
    {
        perror ("VIDIOC_REQBUFS");
        return 1;
    }

    printf ("allocating %d buffers\n", requestbuffers.count);
    buffers = calloc (sizeof (*buffers), requestbuffers.count);
    map_buffers = calloc (sizeof (void *), requestbuffers.count);

    if (!buffers || !map_buffers)
    {
        fprintf (stderr, "out of memory\n");
        return 1;
    }

    for (i = 0; i < requestbuffers.count; i++)
    {
        buffers[i].index = i;
        buffers[i].type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        r = ioctl (vd, VIDIOC_QUERYBUF, &buffers[i]);
        if (r < 0)
        {
            perror ("VIDIOC_QUERYBUF");
            while (--i)
                munmap (map_buffers[i], buffers[i].length);
            return 1;
        }

        map_buffers[i] = mmap (NULL, buffers[i].length, PROT_READ | PROT_WRITE,
                0, vd, buffers[i].m.offset);
        if (!map_buffers[i])
        {
            perror ("mmap");
            while (--i)
                munmap (map_buffers[i], buffers[i].length);
            return 1;
        }

        printf ("mapped buffer %d length %d offset %d\n",
                buffers[i].index, buffers[i].length, buffers[i].m.offset);
    }

    for (i = 0; i < requestbuffers.count; i++)
    {
/*********** fails with EINVAL */
        r = ioctl (vd, VIDIOC_QBUF, &buffers[i]);
        if (r < 0)
        {
            perror ("VIDIOC_QBUF");
            goto done;
        }
    }

    buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    r = ioctl (vd, VIDIOC_STREAMON, &buf_type);
    if (r < 0)
    {
        perror ("VIDIOC_STREAMON");
        goto done;
    }






[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux