Project

General

Profile

Bug #238 ยป shflip.c

v4l2 flip program based on Jon Corbet's v4l1 version - http://lists.laptop.org/pipermail/devel/2006-December/003305.html - Hammel, 11 Nov 2013 15:59

 
1
/* shflip.c */
2
#include <stdio.h>
3
#include <string.h>
4
#include <sys/types.h>
5
#include <linux/types.h>
6
#include <sys/ioctl.h>
7
#include <linux/videodev2.h>
8
#include <fcntl.h>
9
#include <errno.h>
10

    
11

    
12
main(int argc, char *argv[])
13
{
14
    int fd = open("/dev/video0", O_RDWR);
15
    int ret;
16
    struct v4l2_queryctrl queryctrl;
17
    struct v4l2_control ctrl;
18

    
19
    memset(&queryctrl, 0, sizeof(queryctrl));
20
    for (queryctrl.id = V4L2_CID_BASE;
21
         queryctrl.id < V4L2_CID_LASTP1;
22
         queryctrl.id++) {
23
        if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {
24
            if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
25
                continue;
26

    
27
            printf ("Control %s\n", queryctrl.name);
28

    
29
        } else {
30
            if (errno == EINVAL)
31
                continue;
32

    
33
            perror ("VIDIOC_QUERYCTRL");
34
            return (1);
35
        }
36
    }
37

    
38
    memset(&ctrl, 0, sizeof(ctrl));
39
    ctrl.id = V4L2_CID_HFLIP;
40
    ret = ioctl(fd, VIDIOC_G_CTRL, &ctrl);
41
    printf("Get H flip, ret %d value %d\n", ret, ctrl.value);
42
    if (argc > 1) {
43
        ctrl.value = atoi(argv[1]);
44
        ret = ioctl(fd, VIDIOC_S_CTRL, &ctrl);
45
        printf("Set to %d, ret %d\n", ctrl.value, ret);
46
    }
47
}
48

    
    (1-1/1)