test_vevent.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * test_vevent.c - Test VIDEO_GET_EVENT and poll(9 for video events
  3. *
  4. * Copyright (C) 2003 convergence GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version 2.1
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <sys/ioctl.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/poll.h>
  27. #include <fcntl.h>
  28. #include <time.h>
  29. #include <unistd.h>
  30. #include <linux/types.h>
  31. #include <linux/dvb/video.h>
  32. int videoGetSize(int fd, char *arg)
  33. {
  34. video_size_t size;
  35. if (arg)
  36. return -1;
  37. if (ioctl(fd, VIDEO_GET_SIZE, &size) == -1){
  38. perror("VIDEO_GET_SIZE");
  39. return 0;
  40. }
  41. printf("Video Size: %ux%u ", size.w, size.h);
  42. switch (size.aspect_ratio) {
  43. case VIDEO_FORMAT_4_3:
  44. printf("4:3 (%d)\n", size.aspect_ratio);
  45. break;
  46. case VIDEO_FORMAT_16_9:
  47. printf("16:9 (%d)\n", size.aspect_ratio);
  48. break;
  49. case VIDEO_FORMAT_221_1:
  50. printf("2.21:1 (%d)\n", size.aspect_ratio);
  51. break;
  52. default:
  53. printf("unknown aspect ratio (%d)\n", size.aspect_ratio);
  54. break;
  55. }
  56. return 0;
  57. }
  58. int main(void)
  59. {
  60. int vfd, rc;
  61. char *videodev = "/dev/dvb/adapter0/video0";
  62. struct pollfd pfd[1];
  63. struct video_event event;
  64. if (getenv("VIDEO"))
  65. videodev = getenv("VIDEO");
  66. printf("using video device '%s'\n", videodev);
  67. if ((vfd = open(videodev, O_RDONLY | O_NONBLOCK)) < 0) {
  68. perror("open video device");
  69. return 1;
  70. }
  71. videoGetSize(vfd, NULL);
  72. pfd[0].fd = vfd;
  73. pfd[0].events = POLLPRI;
  74. for (;;) {
  75. rc = poll(pfd, 1, -1);
  76. if (rc == -1) {
  77. perror("poll");
  78. return -1;
  79. }
  80. printf("poll events: %#x\n", pfd[0].revents);
  81. if (pfd[0].revents & POLLPRI) {
  82. rc = ioctl(vfd, VIDEO_GET_EVENT, &event);
  83. if (rc == -1) {
  84. perror("VIDEO_GET_EVENT");
  85. return -1;
  86. }
  87. printf("video event %d\n", event.type);
  88. if (event.type == VIDEO_EVENT_SIZE_CHANGED) {
  89. printf(" VIDEO_EVENT_SIZE_CHANGED %ux%u ",
  90. event.u.size.w, event.u.size.h);
  91. switch (event.u.size.aspect_ratio) {
  92. case VIDEO_FORMAT_4_3:
  93. printf("4:3 (%d)\n", event.u.size.aspect_ratio);
  94. break;
  95. case VIDEO_FORMAT_16_9:
  96. printf("16:9 (%d)\n", event.u.size.aspect_ratio);
  97. break;
  98. case VIDEO_FORMAT_221_1:
  99. printf("2.21:1 (%d)\n", event.u.size.aspect_ratio);
  100. break;
  101. default:
  102. printf("unknown aspect ratio (%d)\n",
  103. event.u.size.aspect_ratio);
  104. break;
  105. }
  106. }
  107. }
  108. }
  109. close(vfd);
  110. return 0;
  111. }