Mercurial > mplayer.hg
annotate libao2/ao_sun.c @ 3425:387ddda42e1e
compiling g72x
author | arpi |
---|---|
date | Mon, 10 Dec 2001 01:34:14 +0000 |
parents | b9ee2d8d7279 |
children | 24b0fad7fccc |
rev | line source |
---|---|
1041 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
3 #include <string.h> |
1041 | 4 |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
5 #include <unistd.h> |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
6 #include <fcntl.h> |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
7 #include <errno.h> |
1041 | 8 #include <sys/ioctl.h> |
9 #include <sys/time.h> | |
10 #include <sys/types.h> | |
11 #include <sys/stat.h> | |
12 #include <sys/audioio.h> | |
13 #ifdef __svr4__ | |
14 #include <stropts.h> | |
15 #endif | |
16 | |
17 #include "../config.h" | |
18 | |
19 #include "audio_out.h" | |
20 #include "audio_out_internal.h" | |
1058 | 21 #include "afmt.h" |
1041 | 22 |
23 static ao_info_t info = | |
24 { | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
25 "Sun audio output", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
26 "sun", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
27 "jk@tools.de", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
28 "" |
1041 | 29 }; |
30 | |
31 LIBAO_EXTERN(sun) | |
32 | |
33 | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
34 /* These defines are missing on NetBSD */ |
1041 | 35 #ifndef AUDIO_PRECISION_8 |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
36 #define AUDIO_PRECISION_8 8 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
37 #define AUDIO_PRECISION_16 16 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
38 #endif |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
39 #ifndef AUDIO_CHANNELS_MONO |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
40 #define AUDIO_CHANNELS_MONO 1 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
41 #define AUDIO_CHANNELS_STEREO 2 |
1041 | 42 #endif |
43 | |
44 | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
45 static char *audio_dev = "/dev/audio"; |
1041 | 46 static int queued_bursts = 0; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
47 static int queued_samples = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
48 static int bytes_per_sample = 0; |
3095 | 49 static int byte_per_sec = 0; |
1807
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
50 static int convert_u8_s8; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
51 static int audio_fd = -1; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
52 static enum { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
53 RTSC_UNKNOWN = 0, |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
54 RTSC_ENABLED, |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
55 RTSC_DISABLED |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
56 } enable_sample_timing; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
57 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
58 extern int verbose; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
59 |
1041 | 60 |
1058 | 61 // convert an OSS audio format specification into a sun audio encoding |
62 static int oss2sunfmt(int oss_format) | |
63 { | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
64 switch (oss_format){ |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
65 case AFMT_MU_LAW: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
66 return AUDIO_ENCODING_ULAW; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
67 case AFMT_A_LAW: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
68 return AUDIO_ENCODING_ALAW; |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
69 case AFMT_S16_BE: |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
70 case AFMT_S16_LE: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
71 return AUDIO_ENCODING_LINEAR; |
1346
d6e6132bff35
AUDIO_ENCODING_LINEAR8 format is not available on sunos 5.5. Format is
jkeil
parents:
1320
diff
changeset
|
72 #ifdef AUDIO_ENCODING_LINEAR8 // Missing on SunOS 5.5.1... |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
73 case AFMT_U8: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
74 return AUDIO_ENCODING_LINEAR8; |
1346
d6e6132bff35
AUDIO_ENCODING_LINEAR8 format is not available on sunos 5.5. Format is
jkeil
parents:
1320
diff
changeset
|
75 #endif |
1058 | 76 #ifdef AUDIO_ENCODING_DVI // Missing on NetBSD... |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
77 case AFMT_IMA_ADPCM: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
78 return AUDIO_ENCODING_DVI; |
1058 | 79 #endif |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
80 default: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
81 return AUDIO_ENCODING_NONE; |
1058 | 82 } |
83 } | |
84 | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
85 // try to figure out, if the soundcard driver provides usable (precise) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
86 // sample counter information |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
87 static int realtime_samplecounter_available(char *dev) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
88 { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
89 int fd = -1; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
90 audio_info_t info; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
91 int rtsc_ok = RTSC_DISABLED; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
92 int len; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
93 void *silence = NULL; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
94 struct timeval start, end; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
95 struct timespec delay; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
96 int usec_delay; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
97 unsigned last_samplecnt; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
98 unsigned increment; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
99 unsigned min_increment; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
100 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
101 len = 44100 * 4 / 4; /* amount of data for 0.25sec of 44.1khz, stereo, |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
102 * 16bit. 44kbyte can be sent to all supported |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
103 * sun audio devices without blocking in the |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
104 * "write" below. |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
105 */ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
106 silence = calloc(1, len); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
107 if (silence == NULL) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
108 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
109 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
110 if ((fd = open(dev, O_WRONLY)) < 0) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
111 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
112 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
113 AUDIO_INITINFO(&info); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
114 info.play.sample_rate = 44100; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
115 info.play.channels = AUDIO_CHANNELS_STEREO; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
116 info.play.precision = AUDIO_PRECISION_16; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
117 info.play.encoding = AUDIO_ENCODING_LINEAR; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
118 info.play.samples = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
119 if (ioctl(fd, AUDIO_SETINFO, &info)) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
120 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
121 printf("rtsc: SETINFO failed\n"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
122 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
123 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
124 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
125 if (write(fd, silence, len) != len) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
126 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
127 printf("rtsc: write failed"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
128 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
129 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
130 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
131 if (ioctl(fd, AUDIO_GETINFO, &info)) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
132 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
133 perror("rtsc: GETINFO1"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
134 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
135 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
136 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
137 last_samplecnt = info.play.samples; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
138 min_increment = ~0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
139 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
140 gettimeofday(&start, NULL); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
141 for (;;) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
142 delay.tv_sec = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
143 delay.tv_nsec = 10000000; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
144 nanosleep(&delay, NULL); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
145 gettimeofday(&end, NULL); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
146 usec_delay = (end.tv_sec - start.tv_sec) * 1000000 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
147 + end.tv_usec - start.tv_usec; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
148 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
149 // stop monitoring sample counter after 0.2 seconds |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
150 if (usec_delay > 200000) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
151 break; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
152 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
153 if (ioctl(fd, AUDIO_GETINFO, &info)) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
154 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
155 perror("rtsc: GETINFO2 failed"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
156 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
157 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
158 if (info.play.samples < last_samplecnt) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
159 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
160 printf("rtsc: %d > %d?\n", last_samplecnt, info.play.samples); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
161 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
162 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
163 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
164 if ((increment = info.play.samples - last_samplecnt) > 0) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
165 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
166 printf("ao_sun: sample counter increment: %d\n", increment); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
167 if (increment < min_increment) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
168 min_increment = increment; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
169 if (min_increment < 2000) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
170 break; // looks good |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
171 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
172 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
173 last_samplecnt = info.play.samples; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
174 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
175 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
176 /* |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
177 * For 44.1kkz, stereo, 16-bit format we would send sound data in 16kbytes |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
178 * chunks (== 4096 samples) to the audio device. If we see a minimum |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
179 * sample counter increment from the soundcard driver of less than |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
180 * 2000 samples, we assume that the driver provides a useable realtime |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
181 * sample counter in the AUDIO_INFO play.samples field. Timing based |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
182 * on sample counts should be much more accurate than counting whole |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
183 * 16kbyte chunks. |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
184 */ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
185 if (min_increment < 2000) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
186 rtsc_ok = RTSC_ENABLED; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
187 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
188 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
189 printf("ao_sun: minimum sample counter increment per 10msec interval: %d\n" |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
190 "\t%susing sample counter based timing code\n", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
191 min_increment, rtsc_ok == RTSC_ENABLED ? "" : "not "); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
192 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
193 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
194 error: |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
195 if (silence != NULL) free(silence); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
196 if (fd >= 0) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
197 #ifdef __svr4__ |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
198 // remove the 0 bytes from the above measurement from the |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
199 // audio driver's STREAMS queue |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
200 ioctl(fd, I_FLUSH, FLUSHW); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
201 #endif |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
202 //ioctl(fd, AUDIO_DRAIN, 0); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
203 close(fd); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
204 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
205 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
206 return rtsc_ok; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
207 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
208 |
1041 | 209 // to set/get/query special features/parameters |
210 static int control(int cmd,int arg){ | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
211 switch(cmd){ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
212 case AOCONTROL_SET_DEVICE: |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
213 audio_dev=(char*)arg; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
214 return CONTROL_OK; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
215 case AOCONTROL_QUERY_FORMAT: |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
216 return CONTROL_TRUE; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
217 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
218 return CONTROL_UNKNOWN; |
1041 | 219 } |
220 | |
221 // open & setup audio device | |
222 // return: 1=success 0=fail | |
223 static int init(int rate,int channels,int format,int flags){ | |
224 | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
225 audio_info_t info; |
1807
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
226 int ok; |
1041 | 227 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
228 if (ao_subdevice) audio_dev = ao_subdevice; |
1209 | 229 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
230 if (enable_sample_timing == RTSC_UNKNOWN |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
231 && !getenv("AO_SUN_DISABLE_SAMPLE_TIMING")) { |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
232 enable_sample_timing = realtime_samplecounter_available(audio_dev); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
233 } |
1041 | 234 |
1456
8c57a5a3c645
printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents:
1346
diff
changeset
|
235 // printf("ao2: %d Hz %d chans %s [0x%X]\n", |
8c57a5a3c645
printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents:
1346
diff
changeset
|
236 // rate,channels,audio_out_format_name(format),format); |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
237 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
238 audio_fd=open(audio_dev, O_WRONLY); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
239 if(audio_fd<0){ |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
240 printf("Can't open audio device %s, %s -> nosound\n", audio_dev, strerror(errno)); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
241 return 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
242 } |
1041 | 243 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
244 ioctl(audio_fd, AUDIO_DRAIN, 0); |
1041 | 245 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
246 AUDIO_INITINFO(&info); |
3095 | 247 info.play.encoding = oss2sunfmt(ao_data.format = format); |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
248 info.play.precision = |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
249 (format==AFMT_S16_LE || format==AFMT_S16_BE |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
250 ? AUDIO_PRECISION_16 |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
251 : AUDIO_PRECISION_8); |
3095 | 252 info.play.channels = ao_data.channels = channels; |
253 info.play.sample_rate = ao_data.samplerate = rate; | |
1807
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
254 convert_u8_s8 = 0; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
255 ok = ioctl(audio_fd, AUDIO_SETINFO, &info) >= 0; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
256 if (!ok && info.play.encoding == AUDIO_ENCODING_LINEAR8) { |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
257 /* sun audiocs hardware does not support U8 format, try S8... */ |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
258 info.play.encoding = AUDIO_ENCODING_LINEAR; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
259 ok = ioctl(audio_fd, AUDIO_SETINFO, &info) >= 0; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
260 if (ok) { |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
261 /* we must perform software U8 -> S8 conversion */ |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
262 convert_u8_s8 = 1; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
263 } |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
264 } |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
265 if (!ok) { |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
266 printf("audio_setup: your card doesn't support %d channel, %s, %d Hz samplerate\n", |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
267 channels, audio_out_format_name(format), rate); |
1807
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
268 return 0; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
269 } |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
270 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
271 bytes_per_sample = channels * info.play.precision / 8; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
272 byte_per_sec = bytes_per_sample * rate; |
3095 | 273 ao_data.outburst = byte_per_sec > 100000 ? 16384 : 8192; |
1041 | 274 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
275 #ifdef __not_used__ |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
276 /* |
3095 | 277 * hmm, ao_data.buffersize is currently not used in this driver, do there's |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
278 * no need to measure it |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
279 */ |
3095 | 280 if(ao_data.buffersize==-1){ |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
281 // Measuring buffer size: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
282 void* data; |
3095 | 283 ao_data.buffersize=0; |
1041 | 284 #ifdef HAVE_AUDIO_SELECT |
3095 | 285 data = malloc(ao_data.outburst); |
286 memset(data, format==AFMT_U8 ? 0x80 : 0, ao_data.outburst); | |
287 while(ao_data.buffersize<0x40000){ | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
288 fd_set rfds; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
289 struct timeval tv; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
290 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
291 tv.tv_sec=0; tv.tv_usec = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
292 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; |
3095 | 293 write(audio_fd,data,ao_data.outburst); |
294 ao_data.buffersize+=ao_data.outburst; | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
295 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
296 free(data); |
3095 | 297 if(ao_data.buffersize==0){ |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
298 printf("\n *** Your audio driver DOES NOT support select() ***\n"); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
299 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
300 return 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
301 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
302 #ifdef __svr4__ |
3095 | 303 // remove the 0 bytes from the above ao_data.buffersize measurement from the |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
304 // audio driver's STREAMS queue |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
305 ioctl(audio_fd, I_FLUSH, FLUSHW); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
306 #endif |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
307 ioctl(audio_fd, AUDIO_DRAIN, 0); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
308 #endif |
1041 | 309 } |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
310 #endif /* __not_used__ */ |
1041 | 311 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
312 AUDIO_INITINFO(&info); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
313 info.play.samples = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
314 info.play.eof = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
315 info.play.error = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
316 ioctl (audio_fd, AUDIO_SETINFO, &info); |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
317 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
318 queued_bursts = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
319 queued_samples = 0; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
320 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
321 return 1; |
1041 | 322 } |
323 | |
324 // close audio device | |
325 static void uninit(){ | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
326 #ifdef __svr4__ |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
327 // throw away buffered data in the audio driver's STREAMS queue |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
328 ioctl(audio_fd, I_FLUSH, FLUSHW); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
329 #endif |
1041 | 330 close(audio_fd); |
331 } | |
332 | |
333 // stop playing and empty buffers (for seeking/pause) | |
334 static void reset(){ | |
335 audio_info_t info; | |
336 | |
337 uninit(); | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
338 audio_fd=open(audio_dev, O_WRONLY); |
1041 | 339 if(audio_fd<0){ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
340 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE (%s) ***\n", strerror(errno)); |
1041 | 341 return; |
342 } | |
343 | |
344 ioctl(audio_fd, AUDIO_DRAIN, 0); | |
345 | |
346 AUDIO_INITINFO(&info); | |
3095 | 347 info.play.encoding = oss2sunfmt(ao_data.format); |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
348 info.play.precision = |
3095 | 349 (ao_data.format==AFMT_S16_LE || ao_data.format==AFMT_S16_BE |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
350 ? AUDIO_PRECISION_16 |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
351 : AUDIO_PRECISION_8); |
3095 | 352 info.play.channels = ao_data.channels; |
353 info.play.sample_rate = ao_data.samplerate; | |
1041 | 354 info.play.samples = 0; |
355 info.play.eof = 0; | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
356 info.play.error = 0; |
1041 | 357 ioctl (audio_fd, AUDIO_SETINFO, &info); |
358 queued_bursts = 0; | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
359 queued_samples = 0; |
1041 | 360 } |
361 | |
362 // stop playing, keep buffers (for pause) | |
363 static void audio_pause() | |
364 { | |
365 struct audio_info info; | |
366 AUDIO_INITINFO(&info); | |
367 info.play.pause = 1; | |
368 ioctl(audio_fd, AUDIO_SETINFO, &info); | |
369 } | |
370 | |
371 // resume playing, after audio_pause() | |
372 static void audio_resume() | |
373 { | |
374 struct audio_info info; | |
375 AUDIO_INITINFO(&info); | |
376 info.play.pause = 0; | |
377 ioctl(audio_fd, AUDIO_SETINFO, &info); | |
378 } | |
379 | |
380 | |
381 // return: how many bytes can be played without blocking | |
382 static int get_space(){ | |
3095 | 383 int playsize = ao_data.outburst; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
384 audio_info_t info; |
1041 | 385 |
386 // check buffer | |
387 #ifdef HAVE_AUDIO_SELECT | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
388 { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
389 fd_set rfds; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
390 struct timeval tv; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
391 FD_ZERO(&rfds); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
392 FD_SET(audio_fd, &rfds); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
393 tv.tv_sec = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
394 tv.tv_usec = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
395 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! |
1041 | 396 } |
397 #endif | |
398 | |
399 ioctl(audio_fd, AUDIO_GETINFO, &info); | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
400 if (queued_bursts - info.play.eof > 2) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
401 return 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
402 |
3095 | 403 return ao_data.outburst; |
1041 | 404 } |
405 | |
406 // plays 'len' bytes of 'data' | |
407 // it should round it down to outburst*n | |
408 // return: number of bytes played | |
409 static int play(void* data,int len,int flags){ | |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
410 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
411 int native_endian = AFMT_S16_BE; |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
412 #else |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
413 int native_endian = AFMT_S16_LE; |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
414 #endif |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
415 |
3095 | 416 if (len < ao_data.outburst) return 0; |
417 len /= ao_data.outburst; | |
418 len *= ao_data.outburst; | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
419 |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
420 /* 16-bit format using the 'wrong' byteorder? swap words */ |
3095 | 421 if ((ao_data.format == AFMT_S16_LE || ao_data.format == AFMT_S16_BE) |
422 && ao_data.format != native_endian) { | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
423 static void *swab_buf; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
424 static int swab_len; |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
425 if (len > swab_len) { |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
426 if (swab_buf) |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
427 swab_buf = realloc(swab_buf, len); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
428 else |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
429 swab_buf = malloc(len); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
430 swab_len = len; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
431 if (swab_buf == NULL) return 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
432 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
433 swab(data, swab_buf, len); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
434 data = swab_buf; |
3095 | 435 } else if (ao_data.format == AFMT_U8 && convert_u8_s8) { |
1807
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
436 int i; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
437 unsigned char *p = data; |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
438 |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
439 for (i = 0, p = data; i < len; i++, p++) |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
440 *p ^= 0x80; |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
441 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
442 |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
443 len = write(audio_fd, data, len); |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
444 if(len > 0) { |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
445 queued_samples += len / bytes_per_sample; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
446 if (write(audio_fd,data,0) < 0) |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
447 perror("ao_sun: send EOF audio record"); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
448 else |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
449 queued_bursts ++; |
1041 | 450 } |
451 return len; | |
452 } | |
453 | |
454 | |
3095 | 455 // return: delay in seconds between first and last sample in buffer |
456 static float get_delay(){ | |
1041 | 457 audio_info_t info; |
458 ioctl(audio_fd, AUDIO_GETINFO, &info); | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
459 if (info.play.samples && enable_sample_timing == RTSC_ENABLED) |
3095 | 460 return (float)(queued_samples - info.play.samples) / (float)byte_per_sec; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
461 else |
3137 | 462 return (float)((queued_bursts - info.play.eof) * ao_data.outburst) / (float)byte_per_sec; |
1041 | 463 } |
464 |