#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <linux/videodev2.h>
#include "rgb133v4l2.h"
Defines | |
#define | NUM_INPUTS 1 |
#define | DEVICE_OFFSET 0 |
Functions | |
int | main (int argc, char *argv[]) |
#define DEVICE_OFFSET 0 |
#define NUM_INPUTS 1 |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
00019 { 00020 int fd = 0; 00021 int i = 0; 00022 struct v4l2_format f; 00023 00024 char device_name[128]; 00025 00026 memset(device_name, 0, 128); 00027 00028 for(i=0; i<NUM_INPUTS; i++) 00029 { 00030 sprintf(device_name, "/dev/video%d", i+DEVICE_OFFSET); 00031 printf("\n\nDevice: %s\n", device_name); 00032 fd = open(device_name, O_RDWR); 00033 if(fd < 0) 00034 { 00035 printf("Failed to open device: %s\n", device_name); 00036 exit(0); 00037 } 00038 00039 memset (&f, 0, sizeof(struct v4l2_format)); 00040 f.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 00041 if(ioctl(fd, VIDIOC_G_FMT, &f) < 0) 00042 { 00043 perror("Failed to get capture buffer format: "); 00044 close(fd); 00045 exit(0); 00046 } 00047 printf("Capture buffer format: %dx%d\n", 00048 f.fmt.pix.width, f.fmt.pix.height); 00049 00050 f.fmt.pix.width = 240; 00051 f.fmt.pix.height = 480; 00052 printf("Set Capture buffer format: %dx%d\n", 00053 f.fmt.pix.width, f.fmt.pix.height); 00054 if(ioctl(fd, VIDIOC_S_FMT, &f) < 0) 00055 { 00056 perror("Failed to get capture buffer format: "); 00057 close(fd); 00058 exit(0); 00059 } 00060 00061 memset (&f, 0, sizeof(struct v4l2_format)); 00062 f.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 00063 if(ioctl(fd, VIDIOC_G_FMT, &f) < 0) 00064 { 00065 perror("Failed to get capture buffer format: "); 00066 close(fd); 00067 exit(0); 00068 } 00069 printf("New Capture buffer format: %dx%d\n", 00070 f.fmt.pix.width, f.fmt.pix.height); 00071 00072 memset (&f, 0, sizeof(struct v4l2_format)); 00073 f.type = V4L2_BUF_TYPE_CAPTURE_SOURCE; 00074 { 00075 int err = 0; 00076 if((err = ioctl(fd, RGB133_VIDIOC_G_SRC_FMT, (void*)&f)) < 0) 00077 { 00078 perror("Failed to get source input format through propietary ioctl: "); 00079 if(ioctl(fd, VIDIOC_G_FMT, &f) < 0) 00080 { 00081 perror("Failed to get source input format using private ioctl and type: "); 00082 close(fd); 00083 exit(0); 00084 } 00085 else 00086 { 00087 printf("Input format (private ioctl): %dx%d\n", 00088 f.fmt.pix.width, f.fmt.pix.height); 00089 } 00090 } 00091 else 00092 { 00093 printf("Input format (propietary ioctl): %dx%d\n", 00094 f.fmt.pix.width, f.fmt.pix.height); 00095 } 00096 } 00097 00098 close(fd); 00099 } 00100 00101 return 0; 00102 }