/* ** Test program for channel change priority levels: The program expects ** a numerical priority level on the command line. First it will print ** the current maximum prio level (>= 1 since it includes itself at the ** default level) then change it's own level to the one given on the ** command line and attempt a channel change and report if it succeeds ** or fails. After that the program sleeps for 20 seconds to allow to ** start it a second time in parallel at a different priority level. ** ** Author: Tom Zoerner (tomzo at nefkom net), June 14th 2003 ** http://nxtvepg.sourceforge.net/v4l2 */ #include #include #include #include #include #include #include #define DEVICE_PATH "/dev/vbi" /* videodev2.h extensions */ enum v4l2_chn_prio { V4L2_CHN_PRIO_BACKGROUND, V4L2_CHN_PRIO_INTERACTIVE, V4L2_CHN_PRIO_DEFAULT = V4L2_CHN_PRIO_INTERACTIVE, V4L2_CHN_PRIO_RADIO = V4L2_CHN_PRIO_INTERACTIVE, V4L2_CHN_PRIO_RECORD, V4L2_CHN_PRIO_EXCL, V4L2_CHN_PRIO_COUNT }; #define BASE_VIDIOCPRIVATE 192 /* 192-255 are private */ #define VIDIOC_G_CHNPRIO _IOR('V' , BASE_VIDIOCPRIVATE+10, enum v4l2_chn_prio) #define VIDIOC_S_CHNPRIO _IOW('V' , BASE_VIDIOCPRIVATE+11, enum v4l2_chn_prio) int main( int argc, char ** argv ) { char * p_num_end; enum v4l2_chn_prio prio; enum v4l2_chn_prio max_prio; int fd; if (argc == 2) { prio = strtol(argv[1], &p_num_end, 0); printf("Opening %s\n", DEVICE_PATH); fd = open(DEVICE_PATH, O_RDWR); if (fd != -1) { if (ioctl(fd, VIDIOC_G_CHNPRIO, &max_prio) == 0) printf("Current max. priority level = %d (via G_CHNPRIO)\n", (int)max_prio); else fprintf(stderr, "ioctl VIDIOC_S_CHNPRIO(%d): %d: %s\n", prio, errno, strerror(errno)); printf("Setting my priority level to %d (via S_CHNPRIO)\n", (int)prio); if (ioctl(fd, VIDIOC_S_CHNPRIO, &prio) == 0) { struct video_channel vchan; if (ioctl(fd, VIDIOC_G_CHNPRIO, &max_prio) == 0) printf("New max. priority level = %d (via G_CHNPRIO)\n", (int)max_prio); else fprintf(stderr, "ioctl VIDIOC_S_CHNPRIO(%d): %d: %s\n", prio, errno, strerror(errno)); memset(&vchan, 0, sizeof(vchan)); if (ioctl(fd, VIDIOCGCHAN, &vchan) == 0) { if (ioctl(fd, VIDIOCSCHAN, &vchan) == 0) printf("Channel change successful.\n", (int)prio); else if (errno == EBUSY) printf("Channel change failed: device busy (at higher priority)\n", (int)prio); else perror("VIDIOCSCHAN"); } printf("Sleeping 20 secs now...\n"); printf("Start the test in parallel with a different priority.\n"); sleep(20); } else fprintf(stderr, "ioctl VIDIOC_S_CHNPRIO(%d): %d: %s\n", (int)prio, errno, strerror(errno)); close(fd); } else perror("open " DEVICE_PATH); } else fprintf(stderr, "Usage: %s \n", argv[0]); return 0; }