Mercurial > mplayer.hg
annotate libao2/ao_sun.c @ 4853:2853640cea58
colorkey enabled ... until colorkey is correctly supported in vidix
author | michael |
---|---|
date | Mon, 25 Feb 2002 02:05:30 +0000 |
parents | d678ce495a75 |
children | 08f739d36ae0 |
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" | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
18 #include "../mixer.h" |
1041 | 19 |
20 #include "audio_out.h" | |
21 #include "audio_out_internal.h" | |
1058 | 22 #include "afmt.h" |
1041 | 23 |
24 static ao_info_t info = | |
25 { | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
26 "Sun audio output", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
27 "sun", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
28 "jk@tools.de", |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
29 "" |
1041 | 30 }; |
31 | |
32 LIBAO_EXTERN(sun) | |
33 | |
34 | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
35 /* These defines are missing on NetBSD */ |
1041 | 36 #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
|
37 #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
|
38 #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
|
39 #endif |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
40 #ifndef AUDIO_CHANNELS_MONO |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
41 #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
|
42 #define AUDIO_CHANNELS_STEREO 2 |
1041 | 43 #endif |
44 | |
45 | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
46 static char *sun_mixer_device="/dev/audioctl"; |
3492
24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
jkeil
parents:
3137
diff
changeset
|
47 static char *audio_dev = NULL; |
1041 | 48 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
|
49 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
|
50 static int bytes_per_sample = 0; |
3095 | 51 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
|
52 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
|
53 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
|
54 static enum { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
55 RTSC_UNKNOWN = 0, |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
56 RTSC_ENABLED, |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
57 RTSC_DISABLED |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
58 } enable_sample_timing; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
59 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
60 extern int verbose; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
61 |
1041 | 62 |
1058 | 63 // convert an OSS audio format specification into a sun audio encoding |
64 static int oss2sunfmt(int oss_format) | |
65 { | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
66 switch (oss_format){ |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
67 case AFMT_MU_LAW: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
68 return AUDIO_ENCODING_ULAW; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
69 case AFMT_A_LAW: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
70 return AUDIO_ENCODING_ALAW; |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
71 case AFMT_S16_BE: |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
72 case AFMT_S16_LE: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
73 return AUDIO_ENCODING_LINEAR; |
1346
d6e6132bff35
AUDIO_ENCODING_LINEAR8 format is not available on sunos 5.5. Format is
jkeil
parents:
1320
diff
changeset
|
74 #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
|
75 case AFMT_U8: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
76 return AUDIO_ENCODING_LINEAR8; |
1346
d6e6132bff35
AUDIO_ENCODING_LINEAR8 format is not available on sunos 5.5. Format is
jkeil
parents:
1320
diff
changeset
|
77 #endif |
1058 | 78 #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
|
79 case AFMT_IMA_ADPCM: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
80 return AUDIO_ENCODING_DVI; |
1058 | 81 #endif |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
82 default: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
83 return AUDIO_ENCODING_NONE; |
1058 | 84 } |
85 } | |
86 | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
87 // 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
|
88 // sample counter information |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
89 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
|
90 { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
91 int fd = -1; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
92 audio_info_t info; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
93 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
|
94 int len; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
95 void *silence = NULL; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
96 struct timeval start, end; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
97 struct timespec delay; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
98 int usec_delay; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
99 unsigned last_samplecnt; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
100 unsigned increment; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
101 unsigned min_increment; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
102 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
103 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
|
104 * 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
|
105 * 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
|
106 * "write" below. |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
107 */ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
108 silence = calloc(1, len); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
109 if (silence == NULL) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
110 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
111 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
112 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
|
113 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
114 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
115 AUDIO_INITINFO(&info); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
120 info.play.samples = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
121 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
|
122 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
123 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
|
124 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
125 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
126 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
127 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
|
128 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
129 printf("rtsc: write failed"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
130 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
131 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
132 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
133 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
|
134 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
135 perror("rtsc: GETINFO1"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
136 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
137 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
138 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
139 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
|
140 min_increment = ~0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
141 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
142 gettimeofday(&start, NULL); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
143 for (;;) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
144 delay.tv_sec = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
145 delay.tv_nsec = 10000000; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
146 nanosleep(&delay, NULL); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
147 gettimeofday(&end, NULL); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
148 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
|
149 + 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
|
150 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
151 // 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
|
152 if (usec_delay > 200000) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
153 break; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
154 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
155 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
|
156 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
157 perror("rtsc: GETINFO2 failed"); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
158 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
159 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
160 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
|
161 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
162 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
|
163 goto error; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
164 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
165 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
166 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
|
167 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
168 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
|
169 if (increment < min_increment) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
170 min_increment = increment; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
171 if (min_increment < 2000) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
172 break; // looks good |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
173 } |
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 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
|
176 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
177 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
178 /* |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
179 * 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
|
180 * 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
|
181 * 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
|
182 * 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
|
183 * 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
|
184 * 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
|
185 * 16kbyte chunks. |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
186 */ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
187 if (min_increment < 2000) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
188 rtsc_ok = RTSC_ENABLED; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
189 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
190 if (verbose) |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
191 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
|
192 "\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
|
193 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
|
194 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
195 |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
196 error: |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
197 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
|
198 if (fd >= 0) { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
199 #ifdef __svr4__ |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
200 // 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
|
201 // 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
|
202 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
|
203 #endif |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
204 //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
|
205 close(fd); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
206 } |
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 return rtsc_ok; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
209 } |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
210 |
1041 | 211 // to set/get/query special features/parameters |
212 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
|
213 switch(cmd){ |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
214 case AOCONTROL_SET_DEVICE: |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
215 audio_dev=(char*)arg; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
216 return CONTROL_OK; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
217 case AOCONTROL_QUERY_FORMAT: |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
218 return CONTROL_TRUE; |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
219 case AOCONTROL_GET_VOLUME: |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
220 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
221 int fd,v,cmd,devs; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
222 |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
223 fd=open( sun_mixer_device,O_RDONLY ); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
224 if ( fd != -1 ) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
225 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
226 struct audio_info info; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
227 ioctl( fd,AUDIO_GETINFO,&info); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
228 ((ao_control_vol_t*)(arg))->left=info.play.gain * 100. / AUDIO_MAX_GAIN; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
229 ((ao_control_vol_t*)(arg))->=info.play.gain * 100. / AUDIO_MAX_GAIN; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
230 close( fd ); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
231 return CONTROL_OK; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
232 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
233 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
234 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
235 case AOCONTROL_SET_VOLUME: |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
236 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
237 int fd,v,cmd,devs; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
238 |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
239 fd=open( sun_mixer_device,O_RDONLY ); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
240 if ( fd != -1 ) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
241 { |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
242 struct audio_info info; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
243 AUDIO_INITINFO(&info); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
244 info.play.gain = (r+l) * AUDIO_MAX_GAIN / 100 / 2; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
245 ioctl( fd,AUDIO_SETINFO,&info ); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
246 close( fd ); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
247 return CONTROL_OK; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
248 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
249 return CONTROL_ERROR; |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
250 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
251 return CONTROL_UNKNOWN; |
1041 | 252 } |
253 | |
254 // open & setup audio device | |
255 // return: 1=success 0=fail | |
256 static int init(int rate,int channels,int format,int flags){ | |
257 | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
258 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
|
259 int ok; |
1041 | 260 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
261 if(mixer_device) |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
262 sun_mixer_device=mixer_device; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
3492
diff
changeset
|
263 |
3492
24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
jkeil
parents:
3137
diff
changeset
|
264 if (audio_dev == NULL) { |
24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
jkeil
parents:
3137
diff
changeset
|
265 if ((audio_dev = getenv("AUDIODEV")) == NULL) |
24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
jkeil
parents:
3137
diff
changeset
|
266 audio_dev = "/dev/audio"; |
24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
jkeil
parents:
3137
diff
changeset
|
267 } |
24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
jkeil
parents:
3137
diff
changeset
|
268 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
269 if (ao_subdevice) audio_dev = ao_subdevice; |
1209 | 270 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
271 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
|
272 && !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
|
273 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
|
274 } |
1041 | 275 |
1456
8c57a5a3c645
printfs cleanup - moved to higher -v level or moved to stderr
arpi
parents:
1346
diff
changeset
|
276 // 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
|
277 // 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
|
278 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
279 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
|
280 if(audio_fd<0){ |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
281 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
|
282 return 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
283 } |
1041 | 284 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
285 ioctl(audio_fd, AUDIO_DRAIN, 0); |
1041 | 286 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
287 AUDIO_INITINFO(&info); |
3095 | 288 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
|
289 info.play.precision = |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
290 (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
|
291 ? AUDIO_PRECISION_16 |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
292 : AUDIO_PRECISION_8); |
3095 | 293 info.play.channels = ao_data.channels = channels; |
294 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
|
295 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
|
296 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
|
297 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
|
298 /* 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
|
299 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
|
300 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
|
301 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
|
302 /* 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
|
303 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
|
304 } |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
305 } |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
306 if (!ok) { |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 } |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
311 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
312 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
|
313 byte_per_sec = bytes_per_sample * rate; |
3095 | 314 ao_data.outburst = byte_per_sec > 100000 ? 16384 : 8192; |
1041 | 315 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
316 #ifdef __not_used__ |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
317 /* |
3095 | 318 * 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
|
319 * no need to measure it |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
320 */ |
3095 | 321 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
|
322 // Measuring buffer size: |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
323 void* data; |
3095 | 324 ao_data.buffersize=0; |
1041 | 325 #ifdef HAVE_AUDIO_SELECT |
3095 | 326 data = malloc(ao_data.outburst); |
327 memset(data, format==AFMT_U8 ? 0x80 : 0, ao_data.outburst); | |
328 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
|
329 fd_set rfds; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
330 struct timeval tv; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
331 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
|
332 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
|
333 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; |
3095 | 334 write(audio_fd,data,ao_data.outburst); |
335 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
|
336 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
337 free(data); |
3095 | 338 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
|
339 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
|
340 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
|
341 return 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
342 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
343 #ifdef __svr4__ |
3095 | 344 // 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
|
345 // audio driver's STREAMS queue |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
346 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
|
347 #endif |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
348 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
|
349 #endif |
1041 | 350 } |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
351 #endif /* __not_used__ */ |
1041 | 352 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
353 AUDIO_INITINFO(&info); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
354 info.play.samples = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
355 info.play.eof = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
356 info.play.error = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
357 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
|
358 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
359 queued_bursts = 0; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
360 queued_samples = 0; |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
361 |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
362 return 1; |
1041 | 363 } |
364 | |
365 // close audio device | |
366 static void uninit(){ | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
367 #ifdef __svr4__ |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
368 // 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
|
369 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
|
370 #endif |
1041 | 371 close(audio_fd); |
372 } | |
373 | |
374 // stop playing and empty buffers (for seeking/pause) | |
375 static void reset(){ | |
376 audio_info_t info; | |
377 | |
378 uninit(); | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
379 audio_fd=open(audio_dev, O_WRONLY); |
1041 | 380 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
|
381 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE (%s) ***\n", strerror(errno)); |
1041 | 382 return; |
383 } | |
384 | |
385 ioctl(audio_fd, AUDIO_DRAIN, 0); | |
386 | |
387 AUDIO_INITINFO(&info); | |
3095 | 388 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
|
389 info.play.precision = |
3095 | 390 (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
|
391 ? AUDIO_PRECISION_16 |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
392 : AUDIO_PRECISION_8); |
3095 | 393 info.play.channels = ao_data.channels; |
394 info.play.sample_rate = ao_data.samplerate; | |
1041 | 395 info.play.samples = 0; |
396 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
|
397 info.play.error = 0; |
1041 | 398 ioctl (audio_fd, AUDIO_SETINFO, &info); |
399 queued_bursts = 0; | |
1196
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
400 queued_samples = 0; |
1041 | 401 } |
402 | |
403 // stop playing, keep buffers (for pause) | |
404 static void audio_pause() | |
405 { | |
406 struct audio_info info; | |
407 AUDIO_INITINFO(&info); | |
408 info.play.pause = 1; | |
409 ioctl(audio_fd, AUDIO_SETINFO, &info); | |
410 } | |
411 | |
412 // resume playing, after audio_pause() | |
413 static void audio_resume() | |
414 { | |
415 struct audio_info info; | |
416 AUDIO_INITINFO(&info); | |
417 info.play.pause = 0; | |
418 ioctl(audio_fd, AUDIO_SETINFO, &info); | |
419 } | |
420 | |
421 | |
422 // return: how many bytes can be played without blocking | |
423 static int get_space(){ | |
3095 | 424 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
|
425 audio_info_t info; |
1041 | 426 |
427 // check buffer | |
428 #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
|
429 { |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
430 fd_set rfds; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
431 struct timeval tv; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
432 FD_ZERO(&rfds); |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
433 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
|
434 tv.tv_sec = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
435 tv.tv_usec = 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
436 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) return 0; // not block! |
1041 | 437 } |
438 #endif | |
439 | |
440 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
|
441 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
|
442 return 0; |
fc51929ec8ea
Applied patch by J¸«ärgen Keil (jk@tools.de), improves smoothness of video playback.
atmosfear
parents:
1058
diff
changeset
|
443 |
3095 | 444 return ao_data.outburst; |
1041 | 445 } |
446 | |
447 // plays 'len' bytes of 'data' | |
448 // it should round it down to outburst*n | |
449 // return: number of bytes played | |
450 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
|
451 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
452 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
|
453 #else |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
454 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
|
455 #endif |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
456 |
3095 | 457 if (len < ao_data.outburst) return 0; |
458 len /= ao_data.outburst; | |
459 len *= ao_data.outburst; | |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
460 |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
461 /* 16-bit format using the 'wrong' byteorder? swap words */ |
3095 | 462 if ((ao_data.format == AFMT_S16_LE || ao_data.format == AFMT_S16_BE) |
463 && 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
|
464 static void *swab_buf; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
465 static int swab_len; |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1308
diff
changeset
|
466 if (len > swab_len) { |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
467 if (swab_buf) |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
468 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
|
469 else |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
470 swab_buf = malloc(len); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
471 swab_len = len; |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
472 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
|
473 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
474 swab(data, swab_buf, len); |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
475 data = swab_buf; |
3095 | 476 } 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
|
477 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
|
478 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
|
479 |
6da3b9428ff0
Sun audiocs HW does not support AFMT_U8, try to use AFMT_S8 instead. If AFMT_S8
jkeil
parents:
1456
diff
changeset
|
480 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
|
481 *p ^= 0x80; |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
482 } |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
483 |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
484 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
|
485 if(len > 0) { |
1308
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
486 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
|
487 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
|
488 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
|
489 else |
ffd63a75700c
Support playback of AFMT_S16_LE audio data on a big endian machine
jkeil
parents:
1209
diff
changeset
|
490 queued_bursts ++; |
1041 | 491 } |
492 return len; | |
493 } | |
494 | |
495 | |
3095 | 496 // return: delay in seconds between first and last sample in buffer |
497 static float get_delay(){ | |
1041 | 498 audio_info_t info; |
499 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
|
500 if (info.play.samples && enable_sample_timing == RTSC_ENABLED) |
3095 | 501 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
|
502 else |
3137 | 503 return (float)((queued_bursts - info.play.eof) * ao_data.outburst) / (float)byte_per_sec; |
1041 | 504 } |
505 |