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