LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   XAWTV works, videodog works, motion works but how to code my own? (https://www.linuxquestions.org/questions/linux-hardware-18/xawtv-works-videodog-works-motion-works-but-how-to-code-my-own-400182/)

rylan76 01-06-2006 06:30 AM

XAWTV works, videodog works, motion works but how to code my own?
 
Hi all

All the above apps work in displaying output from my camera in color, everything ok.

I need to write a program that can display frames from the device myself though. I have tried to use the code of sdlcap-v4l.c to write my own framegrabber, but no matter what I do (even when cutting and pasting line by line from sdlcap-v4l) I keep getting

ioctl VIDIOCMCAPTURE: Invalid argument

with the following code when I try to run it:

int device_idx = 0, video_buf_size = 0;
struct video_capability video_capabilities;
struct video_picture video_pic;
struct video_mmap video_buf_mmap;
struct video_channel video_dev_channel;
struct video_mbuf video_mbuf_info;

unsigned char *video_buf_data;

void grab_frame(int x, int y)
/*
Currently grabs one frame from the video device on channel 0 direct to disk in .PNM format.
Prints video device capabilities to stderr.
*/
{
device_idx = open("/dev/video0",O_RDWR);

if (device_idx == -1)
{
printf("Cannot open video device.\n");

perror("open videodev");
}//if (device_idx == -1)

else

{
if (ioctl(device_idx,VIDIOCGCAP,&video_capabilities) == -1)
{
printf("Cannot get video device capabilites.\n");
}//if (ioctl(device_idx,VIDIOCGCAP,&video_capabilities) == -1)

else

{
printf("Device Identity: %s\n",video_capabilities.name);
printf("Device Type: %d\n",video_capabilities.type);
printf("Channels: %d\n",video_capabilities.channels);
printf("Audio Channels: %d\n",video_capabilities.audios);
printf("Max Capture Width: %d\n",video_capabilities.maxwidth);
printf("Max Capture Height: %d\n",video_capabilities.maxheight);
printf("Min Capture Width: %d\n",video_capabilities.minwidth);
printf("Min Capture Height: %d\n",video_capabilities.minheight);

memset(&video_pic,0,sizeof(struct video_picture));

if (ioctl(device_idx,VIDIOCGPICT,&video_pic) == -1)
{
printf("Cannot get picture information.\n");
}//if (ioctl(device_idx,VIDIOCGPICT,&video_pic) == -1)

else

{
printf("Brightness: %d\n",video_pic.brightness);
printf("Hue: %d\n",video_pic.hue);
printf("Colour: %d\n",video_pic.colour);
printf("Contrast: %d\n",video_pic.contrast);
printf("Whiteness: %d\n",video_pic.whiteness);
printf("Depth: %d\n",video_pic.depth);
printf("Palette: %d\n",video_pic.palette);

video_buf_mmap.format = VIDEO_PALETTE_RGB24;
video_buf_mmap.frame = 0;
video_buf_mmap.width = x;
video_buf_mmap.height = y;
video_buf_size = x * y * VIDEO_PALETTE_RGB24_BYTE_DEPTH;

video_buf_data = mmap(0,video_buf_size,PROT_READ|PROT_WRITE,MAP_SHARED,device_idx,0);

if (ioctl(device_idx,VIDIOCSPICT,&video_pic) == -1)
{
printf("Cannot set picture information.\n");
}//if (ioctl(device_idx,VIDIOCSPICT,&video_pic) == -1)

else

{
if (ioctl(device_idx,VIDIOCGCHAN,&video_dev_channel) == -1)
{
printf("Cannot get video channel information.\n");
}//if (ioctl(device_idx,VIDIOCGCHAN,&video_dev_channel) == -1)

else

{
printf("Channel: %d\n",video_dev_channel.channel);
printf("Name: %s\n",video_dev_channel.name);
printf("Flags: %d\n",video_dev_channel.flags);
printf("Type: %d\n",video_dev_channel.type);
printf("Norm: %d\n",video_dev_channel.norm);

if (ioctl(device_idx,VIDIOCGMBUF,&video_mbuf_info) == -1)
{
printf("Cannot get number of video buffers available.\n");
}//if (ioctl(device_idx,VIDIOCGMBUF,&video_mbuf_info) == -1)

else

{
printf("Buffers Size: %d\n",video_mbuf_info.size);
printf("Frames: %d\n",video_mbuf_info.frames);

if (ioctl(device_idx,VIDIOCMCAPTURE,&video_buf_mmap) == -1)
{
printf("Cannot capture frame.\n");
//HERE'S WHERE IT FALLS APART:
perror("ioctl VIDIOCMCAPTURE");
}

else

{
printf("Continue.\n");
}
}//if (ioctl(device_idx,VIDIOCGMBUF,&video_mbuf_info) == -1)
}//if (ioctl(device_idx,VIDIOCGCHAN,&video_dev_channel) == -1)
}//if (ioctl(device_idx,VIDIOCSPICT,&video_pic) == -1)
}//if (ioctl(device_idx,VIDIOCGPICT,&video_pic) == -1)
}//if (ioctl(device_idx,VIDIOCGCAP,&video_capabilities) == -1)
}//if (device_idx == -1)
}

Everything works fine, right up to the point where I try to execute ioctl VIDIOCMCAPTURE - it keeps on returning the invalud argument error message.

Any ideas...? I've tried to isolate the relevant code in KDETV and XAWTV as well, but they all seem to do much the same and they all give the same error... besides any obvious errors above (please tell me where!) why do the other apps work but mine does not? Anybody see anything especially wrong with my code above?

I also worked throught the "programming-v4l" pdf that comes with videodog, but using one of the two example programs just keep giving the same error in the same place as all my other attempts based on XAWTV, KDETV, motion and videodog itself.
What am I doing wrong?

Any help desperately appreciated!

Thanks.


All times are GMT -5. The time now is 07:30 AM.