MAP_SHARED requires the file to be writeable, you've opened it as read only.

Steve

[EMAIL PROTECTED] wrote:
Hi!, I just started learning v4l and I'm trying to make a little program
in order to understand how it works.

It gives segfault, but I cannot understand why.

The error is:

[EMAIL PROTECTED]:~/video > ./ottavio
mmap: Invalid argument
Segmentation fault
[EMAIL PROTECTED]:~/video > gdb ottavio
GNU gdb 2002-04-01-cvs
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-linux"...
(gdb) run
Starting program: /home/bott/video/ottavio
mmap: Invalid argument
Program received signal SIGSEGV, Segmentation fault.
0x40093d7d in mempcpy () from /lib/libc.so.6
(gdb) where
#0 0x40093d7d in mempcpy () from /lib/libc.so.6
#1 0x40089892 in _IO_file_xsputn () from /lib/libc.so.6
#2 0x40080f7a in fwrite () from /lib/libc.so.6
#3 0x08048602 in main () at ottavio.c:40
(gdb)


I can't find the error. Can you please help me?

Thank you.

Here's the code.

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <linux/ioctl.h>
#include <linux/videodev.h>

main()
{
  int fd, siz;
  short targaheader[9]={ 0,2,0,0,0,0,444,555,8216 }; /* 444 and 555 are fake */
  void *map;
  struct video_mmap v;

  v.format=VIDEO_PALETTE_RGB24;    // ... GREY, RGB555, RGB565, RGB24, RGB32
  v.frame=0;                       // 0 or 1 (buffer 0 or buffer 1)
  v.width=768;                     // from 32 to 924 (sometimes limited to 768)
  v.height=576;                    // from 32 to 576
  siz=v.width*v.height*3;          // rgb24:3, rgb32:4, rgb565:2, rgb555:2

  targaheader[6]=v.width;
  targaheader[7]=v.height;         // update targa header for frame

  fd=open("/dev/video",O_RDONLY);  // open video device
  if(fd<0) perror("/dev/video");

  map=mmap(0, siz, PROT_READ, MAP_SHARED, fd, 0);   // select memory-map
  if(map==MAP_FAILED) perror("mmap");

  if(ioctl(fd, VIDIOCMCAPTURE, &v)<0)        // start capturing a frame
    perror("VIDIOCMCAPTURE");

  if(ioctl(fd, VIDIOCSYNC, &v.frame)<0)      // wait for end of frame
    perror("VIDIOCSYNC");

  fwrite(targaheader, sizeof(targaheader),   // save header & data to stdout
    1, stdout);
  fwrite(map, siz, 1, stdout);
}


--
Steve Miller
Software Engineer
STMicroelectronics
phone (602) 485-2014



--
video4linux-list mailing list
Unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/video4linux-list

Reply via email to