/* * * Copyright (C) 2007 Texas Instruments Inc * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define VIDIOC_G_OMAP2_ROTATION _IOR ('V', 4, int) char dev_name[2][20] = { "/dev/video1", "/dev/video2" }; #define IS_VALID_CHANNEL(ch) (((ch) == 0) || ((ch) == 1)) #define NUMBUFFERS 3 #define WIDTH 320 #define HEIGHT 240 struct buf_info { unsigned int length; char *start; }; int main(int argc, char *argv[]) { char shortoptions[] = "c:n:"; int mode = O_RDWR, c, ret, l, k, j, i; int index,m = 1,del_cnt=10; int fd, ch_no = 0, numbuffers = NUMBUFFERS, a; unsigned int *ui; struct v4l2_requestbuffers req; struct v4l2_buffer buf; struct buf_info *buff_info; struct v4l2_format fmt; struct timeval before, after, result; int rotation=0; double red, green, blue; char *c_ptr; unsigned char CB; unsigned char Y0; unsigned char CR; if (!IS_VALID_CHANNEL(ch_no)) { printf("Invalid channel id"); exit(0); } if (numbuffers < 0) { printf("Invalid numbufers\n"); exit(0); } fd = open((const char *)dev_name[ch_no], mode); if (fd <= 0) { printf("Cannot open = %s device\n", dev_name[ch_no]); perror("Error:"); exit(0); } fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; fmt.fmt.pix.width = WIDTH; fmt.fmt.pix.height = HEIGHT; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; ret = ioctl(fd, VIDIOC_S_FMT, &fmt); if (ret < 0) { perror("VIDIOC_S_FMT\n"); close(fd); exit(0); } ret = ioctl(fd, VIDIOC_G_FMT, &fmt); if (ret < 0) { perror("VIDIOC_G_FMT\n"); close(fd); exit(0); } printf("Format:\n"); printf("Height: %i\n" , fmt.fmt.pix.height); printf("Width: %i\n" , fmt.fmt.pix.width); printf("Bytes per line: %i\n", fmt.fmt.pix.bytesperline); ret = ioctl(fd, VIDIOC_G_OMAP2_ROTATION, &rotation); if(ret < 0) { perror("VIDIOC_G_OMAP2_ROTATION\n"); close(fd); exit(0); } printf("getfmt\n"); req.count = numbuffers; req.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; req.memory = V4L2_MEMORY_MMAP; ret = ioctl(fd, VIDIOC_REQBUFS, &req); if (ret < 0) { perror("cannot allocate memory\n"); close(fd); exit(0); } printf("reqbufs = %d\n",req.count); buff_info = (struct buf_info *) malloc(sizeof(struct buf_info) * req.count); if (!buff_info) { printf("cannot allocate memory for buff_info\n"); close(fd); exit(0); } memset(&buf, 0, sizeof(buf)); for (i = 0; i < req.count; i++) { buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf.index = i; buf.memory = V4L2_MEMORY_MMAP; ret = ioctl(fd, VIDIOC_QUERYBUF, &buf); if (ret < 0) { perror("VIDIOC_QUERYCAP\n"); for (j = 0; j < i; j++) munmap(buff_info[j].start, buff_info[j].length); close(fd); exit(0); } buff_info[i].length = buf.length; buff_info[i].start = (char*)mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset); if ((unsigned int) buff_info[i].start == MAP_SHARED) { printf("Cannot mmap = %d buffer\n", i); for (j = 0; j < i; j++) munmap(buff_info[j].start, buff_info[j].length); close(fd); exit(0); } memset(buff_info[i].start, 0x80, buff_info[i].length); printf("mapped = %d\n",i); } memset(&buf, 0, sizeof(buf)); /* Enqueue buffers */ for (i = 0; i < req.count; i++) { buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf.index = i; buf.memory = V4L2_MEMORY_MMAP; ret = ioctl(fd, VIDIOC_QBUF, &buf); if (ret < 0) { perror("VIDIOC_QBUF\n"); for (j = 0; j < req.count; j++) munmap(buff_info[j].start, buff_info[j].length); exit(0); } for(k=0; k