Other Parts Discussed in Thread: OMAPL138, TVP5146, TVP5147M1, SYSBIOS
Hi, i am a newcomer to linux, v4l2 and fb. I want to capture images by the "/dev/video0" and display them by "/dev/fb0".
because of lack of ti example for omapl138 lcdk, i use the saLoopBackFbdev for dm8148 and modify some parameters according to omapl138 lcdk hardware.
Some errors occur. The fb initial failed. The minicom display "MMap Failed". I don’t know the reason.
Can anyone help me please? thanks in advance.
./saLoop
initCapture()
Driver Name: vpif capture
Driver bus info: VPtvp514x 1-005d: tvp5146 (Version - 0x07) found at 0xba (i2c-)
IF Platform
Driver is capable of doing capture
standard.name = NTSC
standard.name = NTSC-M
standard.name = NTSC-M-JP
standard.name = NTSC-M-KR
standard.name = PAL
Found standard support in the driver
Input video standard is PAL.
initFbdev()
setupCapture()
saLoopBackFbdev: width = 720
saLoopBackFbdev: height = 576
saLoopBackFbdev: bytesperline = 720
saLoopBackFbdev: sizeimage = 831488
=============================================================
Capture Format:
=============================================================
fmt.type = 1
fmt.width = 720
fmt.height = 576
fmt.pixelformat = 1345466932
fmt.bytesperline = 720
fmt.sizeimage = 829440
========Unable to handle kernel NULL pointer dereference at virtual address 0004
================pgd = c0004000
================[00000004] *pgd=00000000================
=====
setupFbdevAndBuffers()
Internal error: Oops: 17 [#1] PREEMPT
Modules linked in:
CPU: 0 Not tainted (3.3.0 #1)
PC is at vpif_release+0x5c/0x1c4
LR is at v4l2_release+0x4c/0x6c
pc : [<c0296790>] lr : [<c02837e0>] psr: 60000013
sp : c7041e80 ip : c7041ea0 fp : c7041e9c
r10: 00000000 r9 : c780de70 r8 : c7321908
r7 : 00000008 r6 : c7321900 r5 : c7178620 r4 : c7984000
r3 : 00000000 r2 : 00000000 r1 : c0543b24 r0 : c7321900
Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 0005317f Table: c701c000 DAC: 00000015
Process saLoop (pid: 976, stack limit = 0xc7040270)
Stack: (0xc7041e80 to 0xc7042000)
1e80: c7be9800 c7321900 c74a7b00 00000008 c7041eb4 c7041ea0 c02837e0 c0296744
1ea0: c7321900 c72d9170 c7041eec c7041eb8 c008e4cc c02837a4 00000000 00000000
1ec0: 00000000 c7321900 00000000 c730d600 c7178280 0000000c c7040000 00000000
1ee0: c7041f0c c7041ef0 c008ad50 c008e3c8 c71a900c c730d600 00000000 00000003
1f00: c7041f34 c7041f10 c001b5e8 c008ace8 c730d600 0000ff00 46c27760 000000f8
1f20: c00095c4 00000000 c7041f4c c7041f38 c001b6f8 c001b574 00000000 c78a5b80
1f40: c7041f7c c7041f50 c001b8f8 c001b6ac b6f75000 00000001 00000000 0000001f
1f60: c7041fa4 c7041f70 c008d108 000000f8 c7041f94 c7041f80 c001c17c c001b70c
1f80: ffffffff 000953a0 c7041fa4 c7041f98 c001c1c0 c001c0cc 00000000 c7041fa8
1fa0: c0009440 c001c1b8 000953a0 46c27760 ffffffff 0009538c 00000008 ffffffff
1fc0: 000953a0 46c27760 46c27760 000000f8 46c29000 00000000 46afd000 00000000
1fe0: b6f75000 bed6fcb0 46b30130 46b93db4 60000010 ffffffff 00000000 00000000
Backtrace:
[<c0296734>] (vpif_release+0x0/0x1c4) from [<c02837e0>] (v4l2_release+0x4c/0x6c)
r7:00000008 r6:c74a7b00 r5:c7321900 r4:c7be9800
[<c0283794>] (v4l2_release+0x0/0x6c) from [<c008e4cc>] (fput+0x114/0x200)
r5:c72d9170 r4:c7321900
[<c008e3b8>] (fput+0x0/0x200) from [<c008ad50>] (filp_close+0x78/0x84)
[<c008acd8>] (filp_close+0x0/0x84) from [<c001b5e8>] (put_files_struct+0x84/0xe)
r6:00000003 r5:00000000 r4:c730d600 r3:c71a900c
[<c001b564>] (put_files_struct+0x0/0xe0) from [<c001b6f8>] (exit_files+0x5c/0x6)
[<c001b69c>] (exit_files+0x0/0x60) from [<c001b8f8>] (do_exit+0x1fc/0x708)
r4:c78a5b80 r3:00000000
[<c001b6fc>] (do_exit+0x0/0x708) from [<c001c17c>] (do_group_exit+0xc0/0xec)
r7:000000f8
[<c001c0bc>] (do_group_exit+0x0/0xec) from [<c001c1c0>] (sys_exit_group+0x18/0x)
r4:000953a0 r3:ffffffff
[<c001c1a8>] (sys_exit_group+0x0/0x20) from [<c0009440>] (ret_fast_syscall+0x0/)
Code: e3530000 1a00001d e59f1164 e5913000 (e5932004)
Fix Screen Info:
----------------
Line Length - 1280
Physical Address = c7a00000
Buffer Len---[ end trace be62152724069cd7 ]---
gth = 1228800
Fixing recursive fault but reboot is needed!
Var Screen Info:
----------------
Xres - 640
Yres - 480
Xres Virtual - 640
Yres Virtual - 960
nonstd - 0
Bits Per Pixel - 16
blue lenth 5 msb 0 offset 0
red lenth 5 msb 0 offset 11
green lenth 6 msb 0 offset 5
trans lenth 0 msb 0 offset 0
Var Screen Info:
----------------
Xres - 720
Yres - 576
Xres Virtual - 720
Yres Virtual - 1728
nonstd - 0
Bits Per Pixel - 16
blue lenth 5 msb 0 offset 0
red lenth 5 msb 0 offset 11
green lenth 6 msb 0 offset 5
trans lenth 0 msb 0 offset 0
Fix Screen Info:
----------------
Line Length - 1280
Physical Address = c7a00000
Buffer Length = 1228800
MMap Failed.
Error in setting up of Display
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <linux/fb.h>
#include<linux/videodev2.h>
/* Number of buffers capture driver */
#define MAX_BUFFER 3
/* Number of times queue/dequeue happens before stopping applications */
#define MAXLOOPCOUNT 500
/* Application name */
#define APP_NAME "saLoopBackFbdev"
/* device node to be used for capture */
#define CAPTURE_DEVICE "/dev/video0"
//#define CAPTURE_DEVICE "/dev/video5"
/* device node to be used for fbdev */
#define FBDEV_DEVICE "/dev/fb0"
v4l2_std_id input_std_id = V4L2_STD_PAL;
char *input_name = "Composite";
/* Define below #def for debug information enable */
#undef SALOOPBACKFBDEV_DEBUG
/* Structure for storing application data like file pointers, format etc.
* Same structure will be used for fbdev as well as V4L2 capture. Only/
* required fields will be initialized for both of them*/
struct app_obj {
int fd;
struct v4l2_capability cap;
struct v4l2_format fmt;
//struct v4l2_dv_preset dv_preset;
struct v4l2_requestbuffers reqbuf;
unsigned int numbuffers;
unsigned int buffersize;
unsigned char *buffer_addr[MAX_BUFFER];
struct v4l2_buffer buf;
//struct ti81xxvin_overflow_status over_flow;
struct fb_var_screeninfo varinfo;
struct fb_var_screeninfo org_varinfo;
struct fb_fix_screeninfo fixinfo;
};
/* Buffer descriptor for caputre queue/dequeue */
struct buf_info {
int index;
unsigned int length;
char *start;
};
/* Globals for capture and display application objects */
struct app_obj fbdev, capt;
/* Utility function to calculate FPS
*
*/
static int timeval_subtract(struct timeval *result, struct timeval *x,
struct timeval *y)
{
/* Perform the carry for the later subtraction by updating y */
if (x->tv_usec < y->tv_usec) {
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000) {
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}
/* Compute the time remaining to wait, tv_usec is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;
/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}
/* Utility function which gets the fixed screeninfo from driver and prints it
*/
static int get_fixinfo(int fbdev_fd, struct fb_fix_screeninfo *fixinfo)
{
int ret;
ret = ioctl(fbdev_fd, FBIOGET_FSCREENINFO, fixinfo);
if (ret < 0) {
perror("Error reading fixed information.\n");
return ret;
}
printf("\nFix Screen Info:\n");
printf("----------------\n");
printf("Line Length - %d\n", fixinfo->line_length);
printf("Physical Address = %lx\n", fixinfo->smem_start);
printf("Buffer Length = %d\n", fixinfo->smem_len);
return 0;
}
/* Utility function which gets the variable screen info from driver and prints\
* it on console
*/
static int get_varinfo(int fbdev_fd, struct fb_var_screeninfo *varinfo)
{
int ret;
ret = ioctl(fbdev_fd, FBIOGET_VSCREENINFO, varinfo);
if (ret < 0) {
perror("Error reading variable information.\n");
return ret;
}
printf("\nVar Screen Info:\n");
printf("----------------\n");
printf("Xres - %d\n", varinfo->xres);
printf("Yres - %d\n", varinfo->yres);
printf("Xres Virtual - %d\n", varinfo->xres_virtual);
printf("Yres Virtual - %d\n", varinfo->yres_virtual);
printf("nonstd - %d\n", varinfo->nonstd);
printf("Bits Per Pixel - %d\n", varinfo->bits_per_pixel);
printf("blue lenth %d msb %d offset %d\n",
varinfo->blue.length,
varinfo->blue.msb_right,
varinfo->blue.offset);
printf("red lenth %d msb %d offset %d\n",
varinfo->red.length,
varinfo->red.msb_right,
varinfo->red.offset);
printf("green lenth %d msb %d offset %d\n",
varinfo->green.length,
varinfo->green.msb_right,
varinfo->green.offset);
printf("trans lenth %d msb %d offset %d\n",
varinfo->transp.length,
varinfo->transp.msb_right,
varinfo->transp.offset);
return 0;
}
/* Utility function for printing format */
static void printFormat(char *string, struct v4l2_format *fmt)
{
printf("=============================================================\n");
printf("%s Format:\n", string);
printf("=============================================================\n");
printf("fmt.type\t\t = %d\n", fmt->type);
printf("fmt.width\t\t = %d\n", fmt->fmt.pix.width);
printf("fmt.height\t\t = %d\n", fmt->fmt.pix.height);
printf("fmt.pixelformat\t = %d\n", fmt->fmt.pix.pixelformat);
printf("fmt.bytesperline\t = %d\n", fmt->fmt.pix.bytesperline);
printf("fmt.sizeimage\t = %d\n", fmt->fmt.pix.sizeimage);
printf("=============================================================\n");
}
/* Open and query dv preset for capture driver*/
static int initCapture(void)
{
int mode = O_RDWR;
int ret=0;
v4l2_std_id std;
struct v4l2_input input;
struct v4l2_standard standard;
int input_idx = 0;
int found = 0;
/* Open capture driver */
capt.fd = open((const char *)CAPTURE_DEVICE, mode);
if (capt.fd == -1) {
printf("failed to open capture device\n");
return -1;
}
input.index = 0;
while(1) {
ret = ioctl(capt.fd, VIDIOC_ENUMINPUT, &input);
if (ret < 0) {
perror("VIDIOC_ENUMINPUT\n");
return -1;
}
if (!strcmp(input.name, input_name)) {
found = 1;
break;
}
}
if (!found) {
printf("Input %s not found\n", input_name);
return -1;
}
/* Query for capabilities */
if (ioctl(capt.fd, VIDIOC_QUERYCAP, &capt.cap)) {
printf("Query capability failed\n");
exit(2);
} else {
printf("Driver Name: %s\n", capt.cap.driver);
printf("Driver bus info: %s\n", capt.cap.bus_info);
if (capt.cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
printf("Driver is capable of doing capture\n");
if (capt.cap.capabilities & V4L2_CAP_VIDEO_OVERLAY)
printf("Driver is capabled of scaling and cropping\n");
}
input_idx = 0;
ret = ioctl(capt.fd, VIDIOC_S_INPUT, &input.index);
if (ret < 0) {
perror("VIDIOC_S_INPUT\n");
return -1;
}
ret = ioctl(capt.fd, VIDIOC_G_INPUT, &input_idx);
if (ret < 0) {
perror("VIDIOC_G_INPUT\n");
return -1;
}
if (input_idx != input.index) {
printf("Couldn't set input correctly\n");
return -1;
}
found = 0;
/* Enumerate standard to get the name of the standard detected */
standard.index = 0;
do {
ret = ioctl(capt.fd, VIDIOC_ENUMSTD, &standard);
if (ret < 0) {
perror("VIDIOC_ENUM_STD failed\n");
return -1;
}
printf("standard.name = %s\n", standard.name);
if (standard.id & input_std_id) {
printf("Found standard support in the driver\n");
found = 1;
break;
}
standard.index++;
} while (1);
if (!found) {
printf("Driver doesn't support the standard\n");
return -1;
}
ret == ioctl(capt.fd, VIDIOC_S_STD, &input_std_id);
if (ret < 0) {
perror("VIDIOC_S_STD failed\n");
return -1;
}
/* Detect the standard in the input detected */
ret = ioctl(capt.fd, VIDIOC_QUERYSTD, &std);
if (ret < 0) {
perror("VIDIOC_QUERYSTD\n");
return -1;
}
if (std & V4L2_STD_NTSC)
printf("Input video standard is NTSC.\n");
else if (std & V4L2_STD_PAL)
printf("Input video standard is PAL.\n");
else if (std & V4L2_STD_PAL_M)
printf("Input video standard is PAL-M.\n");
else if (std & V4L2_STD_PAL_N)
printf("Input video standard is PAL-N.\n");
else if (std & V4L2_STD_SECAM)
printf("Input video standard is SECAM.\n");
else if (std & V4L2_STD_PAL_60)
printf("Input video standard to PAL60.\n");
else
return -1;
//printf("V4L2_STD_PAL = %08x\n",V4L2_STD_PAL);
ret = ioctl(capt.fd, VIDIOC_S_STD, &std);
if (ret < 0) {
perror("VIDIOC_S_STD\n");
return -1;
}
return 0;
}
static int initFbdev(void)
{
int mode = O_RDWR;
/* Open display driver */
fbdev.fd = open((const char *)FBDEV_DEVICE, mode);
if (fbdev.fd == -1) {
printf("failed to open fbdev device\n");
return -1;
}
return 0;
}
static int setupCapture(void)
{
int ret;
/* Get current format */
capt.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ret = ioctl(capt.fd, VIDIOC_G_FMT, &capt.fmt);
if (ret < 0) {
printf("Get Format failed\n");
return -1;
}
printf("%s: width = %d\n", APP_NAME, capt.fmt.fmt.pix.width);
printf("%s: height = %d\n", APP_NAME, capt.fmt.fmt.pix.height);
printf("%s: bytesperline = %d\n", APP_NAME, capt.fmt.fmt.pix.bytesperline);
printf("%s: sizeimage = %d\n", APP_NAME, capt.fmt.fmt.pix.sizeimage);
/* Set format according to mode detected */
if(capt.fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24)
printf("%s: pixelformat = V4L2_PIX_FMT_RGB24\n", APP_NAME);
else if(capt.fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
printf("%s: pixelformat = V4L2_PIX_FMT_YUYV\n", APP_NAME);
else if(capt.fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
printf("%s: pixelformat = Others\n", APP_NAME);
capt.fmt.fmt.pix.bytesperline = capt.fmt.fmt.pix.width;
capt.fmt.fmt.pix.sizeimage = capt.fmt.fmt.pix.bytesperline *
capt.fmt.fmt.pix.height*2;
//capt.fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
capt.fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
capt.fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
//printf("V4L2_PIX_FMT_UYVY = %d\n",V4L2_PIX_FMT_UYVY);
ret = ioctl(capt.fd, VIDIOC_S_FMT, &capt.fmt);
if (ret < 0) {
printf("Set Format failed1\n");
return -1;
}
/* Get format again and print it on console */
capt.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ret = ioctl(capt.fd, VIDIOC_G_FMT, &capt.fmt);
if (ret < 0) {
printf("Set Format failed2\n");
return -1;
}
printFormat("Capture", &capt.fmt);
/* Request buffers. We are operating in userPtr mode */
capt.reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capt.reqbuf.count = MAX_BUFFER;
capt.reqbuf.memory = V4L2_MEMORY_USERPTR;
ret = ioctl(capt.fd, VIDIOC_REQBUFS, &capt.reqbuf);
if (ret < 0) {
printf("Could not allocate the buffers\n");
return -1;
}
return 0;
}
/* Setup display driver */
static int setupFbdevAndBuffers(void)
{
int ret, i;
/* Get fix screen information. Fix screen information gives
* fix information like panning step for horizontal and vertical
* direction, line length, memory mapped start address and length etc.
*/
if (get_fixinfo(fbdev.fd, &fbdev.fixinfo))
return -1;
/* Get variable screen information. Variable screen information
* gives informtion like size of the image, bites per pixel,
* virtual size of the image etc. */
if (get_varinfo(fbdev.fd, &fbdev.varinfo))
return -1;
/*store the original information*/
memcpy(&fbdev.org_varinfo, &fbdev.varinfo, sizeof(fbdev.varinfo));
/*
* Set the resolution which read before again to prove the
* FBIOPUT_VSCREENINFO ioctl, except virtual part which is required for
* panning.
*/
fbdev.varinfo.xres = capt.fmt.fmt.pix.width;
fbdev.varinfo.yres = capt.fmt.fmt.pix.height;
fbdev.varinfo.xres_virtual = fbdev.varinfo.xres;
fbdev.varinfo.yres_virtual = fbdev.varinfo.yres * MAX_BUFFER;
fbdev.varinfo.bits_per_pixel = 16;
fbdev.varinfo.transp.offset = 0;
fbdev.varinfo.transp.length = 0;
fbdev.varinfo.transp.msb_right = 0;
ret = ioctl(fbdev.fd, FBIOPUT_VSCREENINFO, &fbdev.varinfo);
if (ret < 0) {
perror("Error writing variable information.\n");
return -1;
}
/* Get variable info and print it again after setting it */
if (get_varinfo(fbdev.fd, &fbdev.varinfo))
return -1;
/* It is better to get fix screen information again. its because
* changing variable screen info may also change fix screen info.
* Get fix screen information. Fix screen information gives
* fix information like panning step for horizontal and vertical
* direction, line length, memory mapped start address and length etc.
*/
if (get_fixinfo(fbdev.fd, &fbdev.fixinfo))
return -1;
/* Mmap the driver buffers in application space so that application
* can write on to them. Driver allocates contiguous memory for
* three buffers. These buffers can be displayed one by one. */
fbdev.buffersize = fbdev.fixinfo.line_length * fbdev.varinfo.yres;
fbdev.buffer_addr[0] = (unsigned char *)mmap(0,
fbdev.buffersize * MAX_BUFFER,
(PROT_READ | PROT_WRITE),
MAP_SHARED, fbdev.fd, 0);
if ((int)fbdev.buffer_addr[0] == -1) {
printf("MMap Failed.\n");
return -1;
}
/* Store each buffer addresses in the local variable. These buffer
* addresses can be used to fill the image. */
for (i = 1; i < MAX_BUFFER; i++)
fbdev.buffer_addr[i] = fbdev.buffer_addr[i-1] + fbdev.buffersize;
memset(fbdev.buffer_addr[0], 0x00, fbdev.buffersize * MAX_BUFFER);
return 0;
}
static int queueCaptureBuffers(void)
{
int ret, i;
for (i = 0; i < MAX_BUFFER; i++) {
capt.buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capt.buf.memory = V4L2_MEMORY_USERPTR;
capt.buf.index = i;
capt.buf.m.userptr = (unsigned long)fbdev.buffer_addr[capt.buf.index];
capt.buf.length = capt.fmt.fmt.pix.sizeimage;
ret = ioctl(capt.fd, VIDIOC_QBUF, &capt.buf);
if (ret < 0) {
perror("VIDIOC_QBUF\n");
return -1;
}
}
return ret;
}
/*
Starts Streaming of capture
*/
static int startCapture(void)
{
int a = V4L2_BUF_TYPE_VIDEO_CAPTURE, ret;
ret = ioctl(capt.fd, VIDIOC_STREAMON, &a);
if (ret < 0) {
perror("VIDIOC_STREAMON\n");
return -1;
}
return 0;
}
/*
* Stop streaming on capture
*/
static int stopCapture(void)
{
int a = V4L2_BUF_TYPE_VIDEO_CAPTURE, ret;
ret = ioctl(capt.fd, VIDIOC_STREAMOFF, &a);
if (ret < 0) {
perror("VIDIOC_STREAMON\n");
return -1;
}
return 0;
}
/* Application main */
static int app_main(int argc , char *argv[])
{
int ret;
int i;
struct timeval before, after, result;
/*FILE *filePtr;
filePtr = fopen("captdump.yuv", "wb");
if (filePtr == NULL) {
printf("Cannot Open Output file:captdump.yuv \n");
return 0;
}
system ("echo 1:hdmi > /sys/devices/platform/vpss/graphics0/nodes");
*/
/* Open the capture driver. Query the resolution from the capture driver
*/
printf("initCapture()\n");
ret = initCapture();
if (ret < 0) {
printf("Error in opening capture device for channel 0\n");
return ret;
}
/* Open the Display driver. */
printf("initFbdev()\n");
ret = initFbdev();
if (ret < 0) {
printf("Error in opening display device for channel 0\n");
return ret;
}
restart:
/* Setup the capture driver Step includes
* Set the format according to the resolution queried.
* request for buffer descriptors for userpointer buffers
*/
printf("setupCapture()\n");
ret = setupCapture();
if (ret < 0) {
printf("Error in setting up of capture\n");
return ret;
}
/* Setup the display driver Step includes
* Set the format according to the resolution queried by capture.
* request for buffer descriptors for userpointer buffers
*/
printf("setupFbdevAndBuffers()\n");
ret = setupFbdevAndBuffers();
if (ret < 0) {
printf("Error in setting up of Display\n");
return ret;
}
printf("queueCaptureBuffers()\n");
ret = queueCaptureBuffers();
if (ret < 0) {
printf("Error in queuing capture buffers\n");
return ret;
}
/* Start Captureing */
printf("startCapture()\n");
ret = startCapture();
if (ret < 0) {
printf("Error in starting capture\n");
return ret;
}
/* Get time of day for calculating FPS */
gettimeofday(&before, NULL);
/* Start capture and display loop */
for (i = 0; i < MAXLOOPCOUNT; i++) {
/*
Get capture buffer using DQBUF ioctl
*/
printf("VIDIOC_DQBUF\n");
ret = ioctl(capt.fd, VIDIOC_DQBUF, &capt.buf);
if (ret < 0) {
perror("VIDIOC_DQBUF\n");
return -1;
}
if ((i % 1000) == 0)
printf("C: %d\n TS: %d index %d\n", i,
(unsigned int)capt.buf.timestamp.tv_usec,
capt.buf.index);
/* Pan the display to the next buffer captured.
* Application should provide y-offset in terms of number of
* lines to have panning effect. To entirely change to next
* buffer, yoffset needs to be changed to yres field. */
fbdev.varinfo.yoffset = (capt.buf.index * 1080) % MAX_BUFFER;
printf("FBIOPAN_DISPLAY\n");
ret = ioctl(fbdev.fd, FBIOPAN_DISPLAY, &fbdev.varinfo);
if (ret < 0) {
perror("Cannot pan display.\n");
}
/* Wait for buffer to complete display */
printf("FBIO_WAITFORVSYNC\n");
//ret = ioctl(fbdev.fd, FBIO_WAITFORVSYNC, 0);
//if (ret < 0) {
// perror("wait vsync failed.\n");
// break;
//}
/* HDVPSS VIP capture is having bug that it locks up some time
* under heavy bandwidth conditions. DQBUF will return error in
* case hardware lock up. Applicatin needs to check for the
* lockup and in case of lockup, restart the driver */
/*printf("TICAPT_CHECK_OVERFLOW\n");
if (capt.buf.flags & V4L2_BUF_FLAG_ERROR) {
ret = ioctl(capt.fd, TICAPT_CHECK_OVERFLOW, &capt.over_flow);
if (ret < 0) {
perror("TICAPT_CHECK_OVERFLOW\n");
return -1;
} else {
if (capt.over_flow.porta_overflow) {
printf("Port a overflowed\n\n\n\n\n\n\n");
stopCapture();
goto restart;
}
if (capt.over_flow.portb_overflow) {
printf("Port b overflowed\n\n\n\n\n\n\n");
stopCapture();
goto restart;
}
}
}
*/
/* Queue the buffer back to display */
capt.buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capt.buf.memory = V4L2_MEMORY_USERPTR;
capt.buf.m.userptr = (unsigned long)fbdev.buffer_addr[capt.buf.index];
capt.buf.length = fbdev.buffersize;
ret = ioctl(capt.fd, VIDIOC_QBUF, &capt.buf);
if (ret < 0) {
perror("VIDIOC_QBUF\n");
return -1;
}
}
/* Get time of day after to do FPS calculation */
//fwrite(fbdev.buffer_addr[0], 1, capt.fmt.fmt.pix.sizeimage, filePtr);
gettimeofday(&after, NULL);
timeval_subtract(&result, &after, &before);
printf("Result Time:\t%ld %ld\n", result.tv_sec, result.tv_usec);
printf("Calculated Frame Rate:\t%ld Fps\n\n", MAXLOOPCOUNT/result.tv_sec);
printf("FBIOPUT_VSCREENINFO\n");
ret = ioctl(fbdev.fd, FBIOPUT_VSCREENINFO, &fbdev.org_varinfo);
if (ret < 0) {
perror("Error reading variable information.\n");
}
close(capt.fd);
close(fbdev.fd);
return ret;
}
int main(int argc , char *argv[])
{
return app_main(argc , argv);
}