test_audio.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * test_audio.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 <stdint.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #include <time.h>
  30. #include <unistd.h>
  31. #include <ost/dmx.h>
  32. #include <ost/frontend_old.h>
  33. #include <ost/sec.h>
  34. #include <ost/audio.h>
  35. #include <sys/poll.h>
  36. int audioStop(int fd)
  37. {
  38. int ans;
  39. if ((ans = ioctl(fd,AUDIO_STOP,0)) < 0) {
  40. perror("AUDIO STOP: ");
  41. return -1;
  42. }
  43. return 0;
  44. }
  45. int audioPlay(int fd)
  46. {
  47. int ans;
  48. if ((ans = ioctl(fd,AUDIO_PLAY)) < 0) {
  49. perror("AUDIO PLAY: ");
  50. return -1;
  51. }
  52. return 0;
  53. }
  54. int audioPause(int fd)
  55. {
  56. int ans;
  57. if ((ans = ioctl(fd,AUDIO_PAUSE)) < 0) {
  58. perror("AUDIO PAUSE: ");
  59. return -1;
  60. }
  61. return 0;
  62. }
  63. int audioContinue(int fd)
  64. {
  65. int ans;
  66. if ((ans = ioctl(fd,AUDIO_CONTINUE)) < 0) {
  67. perror("AUDIO CONTINUE: ");
  68. return -1;
  69. }
  70. return 0;
  71. }
  72. int audioSelectSource(int fd, audio_stream_source_t source)
  73. {
  74. int ans;
  75. if ((ans = ioctl(fd,AUDIO_SELECT_SOURCE, source)) < 0) {
  76. perror("AUDIO SELECT SOURCE: ");
  77. return -1;
  78. }
  79. return 0;
  80. }
  81. int audioSetMute(int fd, boolean state)
  82. {
  83. int ans;
  84. if ((ans = ioctl(fd,AUDIO_SET_MUTE, state)) < 0) {
  85. perror("AUDIO SET MUTE: ");
  86. return -1;
  87. }
  88. return 0;
  89. }
  90. int audioSetAVSync(int fd,boolean state)
  91. {
  92. int ans;
  93. if ((ans = ioctl(fd,AUDIO_SET_AV_SYNC, state)) < 0) {
  94. perror("AUDIO SET AV SYNC: ");
  95. return -1;
  96. }
  97. return 0;
  98. }
  99. int audioSetBypassMode(int fd,boolean mode)
  100. {
  101. int ans;
  102. if ((ans = ioctl(fd,AUDIO_SET_BYPASS_MODE, mode)) < 0) {
  103. printf("AUDIO SET BYPASS MODE not implemented?\n");
  104. return -1;
  105. }
  106. return 0;
  107. }
  108. int audioChannelSelect(int fd, audio_channel_select_t select)
  109. {
  110. int ans;
  111. if ((ans = ioctl(fd,AUDIO_CHANNEL_SELECT, select)) < 0) {
  112. perror("AUDIO CHANNEL SELECT: ");
  113. return -1;
  114. }
  115. return 0;
  116. }
  117. int audioGetStatus(int fd)
  118. {
  119. struct audio_status stat;
  120. int ans;
  121. if ((ans = ioctl(fd,AUDIO_GET_STATUS, &stat)) < 0) {
  122. perror("AUDIO GET STATUS: ");
  123. return -1;
  124. }
  125. printf("Audio Status:\n");
  126. printf(" Sync State : %s\n",
  127. (stat.AV_sync_state ? "SYNC" : "NO SYNC"));
  128. printf(" Mute State : %s\n",
  129. (stat.mute_state ? "muted" : "not muted"));
  130. printf(" Play State : ");
  131. switch ((int)stat.play_state){
  132. case AUDIO_STOPPED:
  133. printf("STOPPED (%d)\n",stat.play_state);
  134. break;
  135. case AUDIO_PLAYING:
  136. printf("PLAYING (%d)\n",stat.play_state);
  137. break;
  138. case AUDIO_PAUSED:
  139. printf("PAUSED (%d)\n",stat.play_state);
  140. break;
  141. default:
  142. printf("unknown (%d)\n",stat.play_state);
  143. break;
  144. }
  145. printf(" Stream Source : ");
  146. switch((int)stat.stream_source){
  147. case AUDIO_SOURCE_DEMUX:
  148. printf("DEMUX (%d)\n",stat.stream_source);
  149. break;
  150. case AUDIO_SOURCE_MEMORY:
  151. printf("MEMORY (%d)\n",stat.stream_source);
  152. break;
  153. default:
  154. printf("unknown (%d)\n",stat.stream_source);
  155. break;
  156. }
  157. printf(" Channel Select : ");
  158. switch((int)stat.channel_select){
  159. case AUDIO_STEREO:
  160. printf("Stereo (%d)\n",stat.channel_select);
  161. break;
  162. case AUDIO_MONO_LEFT:
  163. printf("Mono left(%d)\n",stat.channel_select);
  164. break;
  165. case AUDIO_MONO_RIGHT:
  166. printf("Mono right (%d)\n",stat.channel_select);
  167. break;
  168. default:
  169. printf("unknown (%d)\n",stat.channel_select);
  170. break;
  171. }
  172. printf(" Bypass Mode : %s\n",
  173. (stat.bypass_mode ? "ON" : "OFF"));
  174. return 0;
  175. }
  176. #define BUFFY 100000
  177. #define NFD 2
  178. play_file_audio(int filefd, int fd)
  179. {
  180. char buf[BUFFY];
  181. int count;
  182. int written;
  183. int ch;
  184. struct pollfd pfd[NFD];
  185. int stopped = 0;
  186. boolean mute = false;
  187. boolean sync = false;
  188. pfd[0].fd = STDIN_FILENO;
  189. pfd[0].events = POLLIN;
  190. pfd[1].fd = fd;
  191. pfd[1].events = POLLOUT;
  192. while ( (count = read(filefd,buf,BUFFY)) >= 0 ){
  193. written = 0;
  194. while(written < count){
  195. if (poll(pfd,NFD,1)){
  196. if (pfd[1].revents & POLLOUT){
  197. written += write(fd,buf+written,
  198. count-written);
  199. }
  200. if (pfd[0].revents & POLLIN){
  201. int c = getchar();
  202. switch(c){
  203. case 'z':
  204. audioPause(fd);
  205. printf("playback paused\n");
  206. stopped = 1;
  207. break;
  208. case 's':
  209. audioStop(fd);
  210. printf("playback stopped\n");
  211. stopped = 1;
  212. break;
  213. case 'c':
  214. audioContinue(fd);
  215. printf("playback continued\n");
  216. stopped = 0;
  217. break;
  218. case 'p':
  219. audioPlay(fd);
  220. printf("playback started\n");
  221. stopped = 0;
  222. break;
  223. case 'm':
  224. if (mute==false)mute=true;
  225. else mute=false;
  226. audioSetMute(fd,mute);
  227. printf("mute %d\n",mute);
  228. break;
  229. case 'a':
  230. if (sync==false)sync=true;
  231. else sync=false;
  232. audioSetAVSync(fd,sync);
  233. printf("AV sync %d\n",sync);
  234. stopped = 0;
  235. break;
  236. case 'q':
  237. audioContinue(fd);
  238. exit(0);
  239. break;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. main(int argc, char **argv)
  247. {
  248. int fd;
  249. int filefd;
  250. boolean mute = false;
  251. boolean sync = false;
  252. if (argc < 2) return -1;
  253. if ( (filefd = open(argv[1],O_RDONLY)) < 0){
  254. perror("File open:");
  255. return -1;
  256. }
  257. if ((fd = open("/dev/ost/audio",O_RDWR|O_NONBLOCK)) < 0){
  258. perror("AUDIO DEVICE: ");
  259. return -1;
  260. }
  261. audioSetMute(fd,mute);
  262. audioSetBypassMode(fd,false);
  263. //audioContinue(fd);
  264. audioSelectSource(fd,AUDIO_SOURCE_MEMORY);
  265. audioPlay(fd);
  266. //sleep(4);
  267. //audioPause(fd);
  268. //sleep(3);
  269. //audioContinue(fd);
  270. //sleep(3);
  271. //audioStop(fd);
  272. //audioChannelSelect(fd,AUDIO_STEREO);
  273. //audioSetAVSync(fd,sync);
  274. audioGetStatus(fd);
  275. play_file_audio(filefd,fd);
  276. close(fd);
  277. return 0;
  278. }