test_video.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * test_video.c - Test program for new API
  3. *
  4. * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
  5. * & Marcus Metzler <marcus@convergence.de>
  6. for convergence integrated media GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. */
  23. #include <sys/ioctl.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <stdint.h>
  27. #include <sys/types.h>
  28. #include <sys/stat.h>
  29. #include <fcntl.h>
  30. #include <time.h>
  31. #include <unistd.h>
  32. #include <linux/dvb/dmx.h>
  33. #include <linux/dvb/frontend.h>
  34. #include <linux/dvb/video.h>
  35. #include <sys/poll.h>
  36. int videoStop(int fd)
  37. {
  38. int ans;
  39. if ((ans = ioctl(fd,VIDEO_STOP,0)) < 0) {
  40. perror("VIDEO STOP: ");
  41. return -1;
  42. }
  43. return 0;
  44. }
  45. int videoPlay(int fd)
  46. {
  47. int ans;
  48. if ((ans = ioctl(fd,VIDEO_PLAY)) < 0) {
  49. perror("VIDEO PLAY: ");
  50. return -1;
  51. }
  52. return 0;
  53. }
  54. int videoFreeze(int fd)
  55. {
  56. int ans;
  57. if ((ans = ioctl(fd,VIDEO_FREEZE)) < 0) {
  58. perror("VIDEO FREEZE: ");
  59. return -1;
  60. }
  61. return 0;
  62. }
  63. int videoContinue(int fd)
  64. {
  65. int ans;
  66. if ((ans = ioctl(fd,VIDEO_CONTINUE)) < 0) {
  67. perror("VIDEO CONTINUE: ");
  68. return -1;
  69. }
  70. return 0;
  71. }
  72. int videoSelectSource(int fd, video_stream_source_t source)
  73. {
  74. int ans;
  75. if ((ans = ioctl(fd,VIDEO_SELECT_SOURCE, source)) < 0) {
  76. perror("VIDEO SELECT SOURCE: ");
  77. return -1;
  78. }
  79. return 0;
  80. }
  81. int videoSetBlank(int fd, int state)
  82. {
  83. int ans;
  84. if ((ans = ioctl(fd,VIDEO_SET_BLANK, state)) < 0) {
  85. perror("VIDEO SET BLANK: ");
  86. return -1;
  87. }
  88. return 0;
  89. }
  90. int videoFastForward(int fd,int nframes)
  91. {
  92. int ans;
  93. if ((ans = ioctl(fd,VIDEO_FAST_FORWARD, nframes)) < 0) {
  94. perror("VIDEO FAST FORWARD: ");
  95. return -1;
  96. }
  97. return 0;
  98. }
  99. int videoSlowMotion(int fd,int nframes)
  100. {
  101. int ans;
  102. if ((ans = ioctl(fd,VIDEO_SLOWMOTION, nframes)) < 0) {
  103. perror("VIDEO SLOWMOTION: ");
  104. return -1;
  105. }
  106. return 0;
  107. }
  108. int videoGetStatus(int fd)
  109. {
  110. struct video_status vstat;
  111. int ans;
  112. if ((ans = ioctl(fd,VIDEO_GET_STATUS, &vstat)) < 0) {
  113. perror("VIDEO GET STATUS: ");
  114. return -1;
  115. }
  116. printf("Video Status:\n");
  117. printf(" Blank State : %s\n",
  118. (vstat.video_blank ? "BLANK" : "STILL"));
  119. printf(" Play State : ");
  120. switch ((int)vstat.play_state){
  121. case VIDEO_STOPPED:
  122. printf("STOPPED (%d)\n",vstat.play_state);
  123. break;
  124. case VIDEO_PLAYING:
  125. printf("PLAYING (%d)\n",vstat.play_state);
  126. break;
  127. case VIDEO_FREEZED:
  128. printf("FREEZED (%d)\n",vstat.play_state);
  129. break;
  130. default:
  131. printf("unknown (%d)\n",vstat.play_state);
  132. break;
  133. }
  134. printf(" Stream Source : ");
  135. switch((int)vstat.stream_source){
  136. case VIDEO_SOURCE_DEMUX:
  137. printf("DEMUX (%d)\n",vstat.stream_source);
  138. break;
  139. case VIDEO_SOURCE_MEMORY:
  140. printf("MEMORY (%d)\n",vstat.stream_source);
  141. break;
  142. default:
  143. printf("unknown (%d)\n",vstat.stream_source);
  144. break;
  145. }
  146. printf(" Format (Aspect Ratio): ");
  147. switch((int)vstat.video_format){
  148. case VIDEO_FORMAT_4_3:
  149. printf("4:3 (%d)\n",vstat.video_format);
  150. break;
  151. case VIDEO_FORMAT_16_9:
  152. printf("16:9 (%d)\n",vstat.video_format);
  153. break;
  154. default:
  155. printf("unknown (%d)\n",vstat.video_format);
  156. break;
  157. }
  158. printf(" Display Format : ");
  159. switch((int)vstat.display_format){
  160. case VIDEO_PAN_SCAN:
  161. printf("Pan&Scan (%d)\n",vstat.display_format);
  162. break;
  163. case VIDEO_LETTER_BOX:
  164. printf("Letterbox (%d)\n",vstat.display_format);
  165. break;
  166. case VIDEO_CENTER_CUT_OUT:
  167. printf("Center cutout (%d)\n",vstat.display_format);
  168. break;
  169. default:
  170. printf("unknown (%d)\n",vstat.display_format);
  171. break;
  172. }
  173. return 0;
  174. }
  175. int videoStillPicture(int fd, struct video_still_picture *sp)
  176. {
  177. int ans;
  178. if ((ans = ioctl(fd,VIDEO_STILLPICTURE, sp)) < 0) {
  179. perror("VIDEO STILLPICTURE: ");
  180. return -1;
  181. }
  182. return 0;
  183. }
  184. #define BUFFY 32768
  185. #define NFD 2
  186. void play_file_video(int filefd, int fd)
  187. {
  188. char buf[BUFFY];
  189. int count;
  190. int written;
  191. struct pollfd pfd[NFD];
  192. // int stopped = 0;
  193. pfd[0].fd = STDIN_FILENO;
  194. pfd[0].events = POLLIN;
  195. pfd[1].fd = fd;
  196. pfd[1].events = POLLOUT;
  197. videoSelectSource(fd,VIDEO_SOURCE_MEMORY);
  198. videoPlay(fd);
  199. count = read(filefd,buf,BUFFY);
  200. write(fd,buf,count);
  201. while ( (count = read(filefd,buf,BUFFY)) >= 0 ){
  202. written = 0;
  203. while(written < count){
  204. if (poll(pfd,NFD,1)){
  205. if (pfd[1].revents & POLLOUT){
  206. written += write(fd,buf+written,
  207. count-written);
  208. }
  209. if (pfd[0].revents & POLLIN){
  210. int c = getchar();
  211. switch(c){
  212. case 'z':
  213. videoFreeze(fd);
  214. printf("playback frozen\n");
  215. // stopped = 1;
  216. break;
  217. case 's':
  218. videoStop(fd);
  219. printf("playback stopped\n");
  220. // stopped = 1;
  221. break;
  222. case 'c':
  223. videoContinue(fd);
  224. printf("playback continued\n");
  225. // stopped = 0;
  226. break;
  227. case 'p':
  228. videoPlay(fd);
  229. printf("playback started\n");
  230. // stopped = 0;
  231. break;
  232. case 'f':
  233. videoFastForward(fd,0);
  234. printf("fastforward\n");
  235. // stopped = 0;
  236. break;
  237. case 'm':
  238. videoSlowMotion(fd,2);
  239. printf("slowmotion\n");
  240. // stopped = 0;
  241. break;
  242. case 'q':
  243. videoContinue(fd);
  244. exit(0);
  245. break;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. void load_iframe(int filefd, int fd)
  253. {
  254. struct stat st;
  255. struct video_still_picture sp;
  256. fstat(filefd, &st);
  257. sp.iFrame = (char *) malloc(st.st_size);
  258. sp.size = st.st_size;
  259. printf("I-frame size: %d\n", sp.size);
  260. if (!sp.iFrame) {
  261. printf("No memory for I-Frame\n");
  262. return;
  263. }
  264. printf("read: %zd bytes\n",read(filefd,sp.iFrame,sp.size));
  265. videoStillPicture(fd,&sp);
  266. sleep(3);
  267. videoPlay(fd);
  268. }
  269. int main(int argc, char **argv)
  270. {
  271. int fd;
  272. int filefd;
  273. if (argc < 2) return -1;
  274. if ( (filefd = open(argv[1],O_RDONLY)) < 0){
  275. perror("File open:");
  276. return -1;
  277. }
  278. if ((fd = open("/dev/dvb/adapter0/video0",O_RDWR|O_NONBLOCK)) < 0){
  279. perror("VIDEO DEVICE: ");
  280. return -1;
  281. }
  282. // videoSetBlank(fd,false);
  283. //videoPlay(fd);
  284. //sleep(4);
  285. //videoFreeze(fd);
  286. //sleep(3);
  287. //videoContinue(fd);
  288. //sleep(3);
  289. //videoStop(fd);
  290. videoGetStatus(fd);
  291. //load_iframe(filefd, fd);
  292. play_file_video(filefd, fd);
  293. close(fd);
  294. close(filefd);
  295. return 0;
  296. }