Problem with Streaming mode for frame grabbing: Linux crashing!

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



I am trying to grab images from the SenSorray 611 video grabber card
under Linux.  I installed bttv-0.8.40, V4L2, and the latest patches for
the kernel (2.4.19-pre8),.  I first tested with xawtv, and the PREVIEW
and read mode are working fine.  I then wrote a program using the read()
capture mode to grab the images and I was able to grab 640x480 at 10
frame per second.  I then modified my program to use the streaming mode
(I verified that the card had V4L2_FLAG_STREAMING on).  I am able to
initialize and map the memory, but whenever I turn the streaming on
(ioctl(vfd, VIDIOC_STREAMON,&VidBuffer.type)) linux just freeze and does
not answer to anything even a ping from the outside.  

I copied parts of my simple program below.  Does anybody have
experienced this?  Is it a bug due to the video card, bttv, V4L2, or my
program?  Any help would be GREATLY appreciated.

Lionel Bouchet


/**/
/* Opening the video device */
/**/
  vfd = open(devname,O_RDWR);
  if (vfd <= 0) {
    fprintf(stderr,"sorry, no such device %s\n",devname);
    exit(1);
  }

/**/
/* Verifying the capture and Streaming capabilities */
/**/
if (ioctl(vfd, VIDIOC_QUERYCAP, &VidCapability) < 0) {
        perror("Cannot query Video capabilities");
        close(vfd);
        exit(1);
}        
if (VidCapability.type != V4L2_TYPE_CAPTURE) {
        fprintf(stderr, "Device %s is not a video capture
device.\n",devname);
        close(vfd);
        exit(1);
}
if (!(VidCapability.flags & V4L2_FLAG_STREAMING)) {
        fprintf(stderr, "Device %s doesn't support Streaming.\n",
devname);
        close(vfd); 
        exit(1);
}

/**/
/* Setting format for capture */
/**/
/* set input */
i = 1;          /* Composite 1 */
if ( ioctl(vfd, VIDIOC_S_INPUT, &i) == -1 ) {
perror("VIDIOC_S_INPUT");
         close(vfd);
         exit(1);
}       
/* set up capture image format */
/* query settings to init struct */
if (ioctl(vfd,VIDIOC_G_FMT,&fmt) < 0) {;
        perror("error with VIDIOC_G_FMT");
        close(vfd);
        exit(1);
}

fmt.type = V4L2_BUF_TYPE_CAPTURE; /* THis is the capture device format
*/
fmt.fmt.pix.flags = V4L2_FMT_FLAG_INTERLACED ;
fmt.fmt.pix.width = 640;
fmt.fmt.pix.height = 480;
fmt.fmt.pix.depth = 8;
fmt.fmt.pix.pixelformat =  V4L2_PIX_FMT_GREY;

if ( ioctl(vfd,VIDIOC_S_FMT,&fmt) < 0) {
        perror("error with VIDIOC_S_FMT");
        close(vfd);
        exit(1);
}

/*Verifying settings*/
if ( ioctl(vfd, VIDIOC_G_FMT, &fmt1) == -1 ) {
         perror("VIDIOC_G_FMT");
         close(vfd);
         exit(1);
}
printf("after get\n");
print_fmtpix(&fmt1);

/**/
/* allocate capture buffers */
/**/
BufferCount=1;
ReqBuff.count=BufferCount;
ReqBuff.type=V4L2_BUF_TYPE_CAPTURE;
if (ioctl(vfd,VIDIOC_REQBUFS,&ReqBuff) ) {
        perror("error withVIDIOC_REQBUFS ");
        close(vfd);
        exit(1);
}
if ( (ReqBuff.count != BufferCount) || (ReqBuff.type !=
V4L2_BUF_TYPE_CAPTURE) ) {
        fprintf(stderr, "VIDIOC_REQBUFS: got not what wanted!\n");
        close(vfd);
        exit(1);
}

VidBuffer.index=0;
VidBuffer.type=ReqBuff.type;
if (ioctl(vfd,VIDIOC_QUERYBUF,&VidBuffer) < 0) {
        perror("error with VIDIOC_QUERYBUF");
        close(vfd);
        exit(1);
}

/**memory map buffers **/

VideoImage = mmap(NULL,VidBuffer.length,PROT_READ | PROT_WRITE
,MAP_SHARED,vfd,VidBuffer.offset);
if (VideoImage == MAP_FAILED) {
        perror("Error mapping memory\n");
        fprintf(stderr,"ERRNO %d\n",errno);
        fprintf(stderr,"MMAP error %d %d %d %d %d %d \n",EBADF, EACCES,
EINVAL, ETXTBSY, EAGAIN, ENOMEM);
        close(vfd);
        exit(1);
}

sleep(6);

fprintf(stderr,"Trying VIDIOC_STREAMON\n");
fflush(stderr);

/** Starting streaming video **/
if (ioctl(vfd, VIDIOC_STREAMON,&VidBuffer.type) < 0 ) {
        perror("error with VIDIOC_STREAMON");
        close(vfd);
        exit(1);
}
fprintf(stderr,"succeeded VIDIOC_STREAMON\n");
fflush(stderr);
sleep(6);  
fprintf(stderr,"doing VIDIOC_STREAMOFF\n");
fflush(stderr);
close(vfd);
exit(1);






[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