annotate libao2/ao_esd.c @ 37149:a9ceb566a008

configure: add CONFIG_STARTCODE to prevent build failure
author michael
date Tue, 05 Aug 2014 11:12:59 +0000
parents 6ec928ab8112
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
1 /*
27502
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
2 * EsounD audio output driver for MPlayer
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
3 *
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
4 * copyright (c) 2002 Juergen Keil <jk@tools.de>
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
5 *
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
6 * This file is part of MPlayer.
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
7 *
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
9 * it under the terms of the GNU General Public License as published by
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
11 * (at your option) any later version.
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
12 *
27502
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
16 * GNU General Public License for more details.
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
17 *
27502
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
18 * You should have received a copy of the GNU General Public License along
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
21 */
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
22
9a1da32ed7bf Replace casual GPL notice by proper license header.
diego
parents: 27387
diff changeset
23 /*
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
24 * TODO / known problems:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
25 * - does not work well when the esd daemon has autostandby disabled
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
26 * (workaround: run esd with option "-as 2" - fortunatelly this is
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
27 * the default)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
28 * - plays noise on a linux 2.4.4 kernel with a SB16PCI card, when using
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
29 * a local tcp connection to the esd daemon; there is no noise when using
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
30 * a unix domain socket connection.
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
31 * (there are EIO errors reported by the sound card driver, so this is
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
32 * most likely a linux sound card driver problem)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
33 */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
34
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
35 #include <sys/types.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
36 #include <sys/time.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
37 #include <sys/socket.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
38 #include <stdio.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
39 #include <string.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
40 #include <unistd.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
41 #include <errno.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
42 #include <fcntl.h>
8623
440301fef3fe Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents: 8572
diff changeset
43 #include <time.h>
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
44 #ifdef __svr4__
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
45 #include <stropts.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
46 #endif
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
47 #include <esd.h>
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
48
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14245
diff changeset
49 #include "config.h"
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
50 #include "audio_out.h"
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
51 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
52 #include "libaf/af_format.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
53 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
54 #include "help_mp.h"
32055
b8cc88eef14e Replace audio_delay extern declaration by proper mplayer.h #include.
diego
parents: 29263
diff changeset
55 #include "mplayer.h"
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
56
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
57
28362
f0a0d87b7c56 1) HAVE_SYS_ASOUNDLIB_H/HAVE_ALSA_ASOUNDLIB_H are defined/undefined,
diego
parents: 27502
diff changeset
58 #define ESD_RESAMPLES 0
f0a0d87b7c56 1) HAVE_SYS_ASOUNDLIB_H/HAVE_ALSA_ASOUNDLIB_H are defined/undefined,
diego
parents: 27502
diff changeset
59 #define ESD_DEBUG 0
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
60
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
61 #if ESD_DEBUG
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
62 #define dprintf(...) printf(__VA_ARGS__)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
63 #else
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
64 #define dprintf(...) /**/
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
65 #endif
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
66
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
67
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
68 #define ESD_CLIENT_NAME "MPlayer"
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
69 #define ESD_MAX_DELAY (1.0f) /* max amount of data buffered in esd (#sec) */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
70
28823
9a5b8c2ed6de Make ao_info_t structs const.
reimar
parents: 28362
diff changeset
71 static const ao_info_t info =
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
72 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
73 "EsounD audio output",
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
74 "esd",
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
75 "Juergen Keil <jk@tools.de>",
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
76 ""
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
77 };
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
78
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
79 LIBAO_EXTERN(esd)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
80
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
81 static int esd_fd = -1;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
82 static int esd_play_fd = -1;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
83 static esd_server_info_t *esd_svinfo;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
84 static int esd_latency;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
85 static int esd_bytes_per_sample;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
86 static unsigned long esd_samples_written;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
87 static struct timeval esd_play_start;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
88
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
89 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
90 * to set/get/query special features/parameters
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
91 */
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 8623
diff changeset
92 static int control(int cmd, void *arg)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
93 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
94 esd_player_info_t *esd_pi;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
95 esd_info_t *esd_i;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
96 time_t now;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
97 static time_t vol_cache_time;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
98 static ao_control_vol_t vol_cache;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
99
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
100 switch (cmd) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
101 case AOCONTROL_GET_VOLUME:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
102 time(&now);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
103 if (now == vol_cache_time) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
104 *(ao_control_vol_t *)arg = vol_cache;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
105 return CONTROL_OK;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
106 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
107
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
108 dprintf("esd: get vol\n");
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
109 if ((esd_i = esd_get_all_info(esd_fd)) == NULL)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
110 return CONTROL_ERROR;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
111
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
112 for (esd_pi = esd_i->player_list; esd_pi != NULL; esd_pi = esd_pi->next)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
113 if (strcmp(esd_pi->name, ESD_CLIENT_NAME) == 0)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
114 break;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
115
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
116 if (esd_pi != NULL) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
117 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
118 vol->left = esd_pi->left_vol_scale * 100 / ESD_VOLUME_BASE;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
119 vol->right = esd_pi->right_vol_scale * 100 / ESD_VOLUME_BASE;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
120
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
121 vol_cache = *vol;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
122 vol_cache_time = now;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
123 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
124 esd_free_all_info(esd_i);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
125
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
126 return CONTROL_OK;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
127
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
128 case AOCONTROL_SET_VOLUME:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
129 dprintf("esd: set vol\n");
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
130 if ((esd_i = esd_get_all_info(esd_fd)) == NULL)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
131 return CONTROL_ERROR;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
132
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
133 for (esd_pi = esd_i->player_list; esd_pi != NULL; esd_pi = esd_pi->next)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
134 if (strcmp(esd_pi->name, ESD_CLIENT_NAME) == 0)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
135 break;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
136
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
137 if (esd_pi != NULL) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
138 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
139 esd_set_stream_pan(esd_fd, esd_pi->source_id,
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
140 vol->left * ESD_VOLUME_BASE / 100,
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
141 vol->right * ESD_VOLUME_BASE / 100);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
142
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
143 vol_cache = *vol;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
144 time(&vol_cache_time);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
145 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
146 esd_free_all_info(esd_i);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
147 return CONTROL_OK;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
148
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
149 default:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
150 return CONTROL_UNKNOWN;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
151 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
152 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
153
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
154
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
155 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
156 * open & setup audio device
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
157 * return: 1=success 0=fail
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
158 */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
159 static int init(int rate_hz, int channels, int format, int flags)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
160 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
161 esd_format_t esd_fmt;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
162 int bytes_per_sample;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
163 int fl;
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
164 char *server = ao_subdevice; /* NULL for localhost */
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
165 float lag_seconds, lag_net, lag_serv;
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
166 struct timeval proto_start, proto_end;
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
167
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
168 esd_fd = esd_open_sound(server);
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
169 if (esd_fd < 0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
170 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ESD_CantOpenSound,
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
171 strerror(errno));
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
172 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
173 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
174
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
175 /* get server info, and measure network latency */
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
176 gettimeofday(&proto_start, NULL);
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
177 esd_svinfo = esd_get_server_info(esd_fd);
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
178 if(server) {
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
179 gettimeofday(&proto_end, NULL);
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
180 lag_net = (proto_end.tv_sec - proto_start.tv_sec) +
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
181 (proto_end.tv_usec - proto_start.tv_usec) / 1000000.0;
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
182 lag_net /= 2.0; /* round trip -> one way */
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
183 } else
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
184 lag_net = 0.0; /* no network lag */
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
185
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
186 /*
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
187 if (esd_svinfo) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
188 mp_msg(MSGT_AO, MSGL_INFO, "AO: [esd] server info:\n");
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
189 esd_print_server_info(esd_svinfo);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
190 }
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
191 */
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
192
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
193 esd_fmt = ESD_STREAM | ESD_PLAY;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
194
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
195 #if ESD_RESAMPLES
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
196 /* let the esd daemon convert sample rate */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
197 #else
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
198 /* let mplayer's audio filter convert the sample rate */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
199 if (esd_svinfo != NULL)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
200 rate_hz = esd_svinfo->rate;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
201 #endif
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
202 ao_data.samplerate = rate_hz;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
203
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
204 /* EsounD can play mono or stereo */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
205 switch (channels) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
206 case 1:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
207 esd_fmt |= ESD_MONO;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
208 ao_data.channels = bytes_per_sample = 1;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
209 break;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
210 default:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
211 esd_fmt |= ESD_STEREO;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
212 ao_data.channels = bytes_per_sample = 2;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
213 break;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
214 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
215
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
216 /* EsounD can play 8bit unsigned and 16bit signed native */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
217 switch (format) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
218 case AF_FORMAT_S8:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
219 case AF_FORMAT_U8:
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
220 esd_fmt |= ESD_BITS8;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
221 ao_data.format = AF_FORMAT_U8;
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
222 break;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
223 default:
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
224 esd_fmt |= ESD_BITS16;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14124
diff changeset
225 ao_data.format = AF_FORMAT_S16_NE;
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
226 bytes_per_sample *= 2;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
227 break;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
228 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
229
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
230 /* modify audio_delay depending on esd_latency
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
231 * latency is number of samples @ 44.1khz stereo 16 bit
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
232 * adjust according to rate_hz & bytes_per_sample
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
233 */
27387
eb7bdbd98210 Rename some audio-output-related preprocessor directives.
diego
parents: 18976
diff changeset
234 #ifdef CONFIG_ESD_LATENCY
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
235 esd_latency = esd_get_latency(esd_fd);
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
236 #else
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
237 esd_latency = ((channels == 1 ? 2 : 1) * ESD_DEFAULT_RATE *
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
238 (ESD_BUF_SIZE + 64 * (4.0f / bytes_per_sample))
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
239 ) / rate_hz;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
240 esd_latency += ESD_BUF_SIZE * 2;
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
241 #endif
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
242 if(esd_latency > 0) {
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
243 lag_serv = (esd_latency * 4.0f) / (bytes_per_sample * rate_hz);
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
244 lag_seconds = lag_net + lag_serv;
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
245 audio_delay += lag_seconds;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
246 mp_msg(MSGT_AO, MSGL_INFO,MSGTR_AO_ESD_LatencyInfo,
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
247 lag_serv, lag_net, lag_seconds);
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
248 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
249
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
250 esd_play_fd = esd_play_stream_fallback(esd_fmt, rate_hz,
10213
5e15ff3261ff esd:server and esd latency support by Andrew Williams <andrew.s.williams@adelaide.edu.au>
alex
parents: 9633
diff changeset
251 server, ESD_CLIENT_NAME);
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
252 if (esd_play_fd < 0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
253 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ESD_CantOpenPBStream, strerror(errno));
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
254 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
255 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
256
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
257 /* enable non-blocking i/o on the socket connection to the esd server */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
258 if ((fl = fcntl(esd_play_fd, F_GETFL)) >= 0)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
259 fcntl(esd_play_fd, F_SETFL, O_NDELAY|fl);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
260
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
261 #if ESD_DEBUG
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
262 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
263 int sbuf, rbuf, len;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
264 len = sizeof(sbuf);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
265 getsockopt(esd_play_fd, SOL_SOCKET, SO_SNDBUF, &sbuf, &len);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
266 len = sizeof(rbuf);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
267 getsockopt(esd_play_fd, SOL_SOCKET, SO_RCVBUF, &rbuf, &len);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
268 dprintf("esd: send/receive socket buffer space %d/%d bytes\n",
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
269 sbuf, rbuf);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
270 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
271 #endif
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
272
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
273 ao_data.bps = bytes_per_sample * rate_hz;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
274 ao_data.outburst = ao_data.bps > 100000 ? 4*ESD_BUF_SIZE : 2*ESD_BUF_SIZE;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
275
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
276 esd_play_start.tv_sec = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
277 esd_samples_written = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
278 esd_bytes_per_sample = bytes_per_sample;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
279
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
280 return 1;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
281 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
282
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
283
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
284 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
285 * close audio device
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
286 */
12145
99798c3cdb93 uninit immed flag
alex
parents: 11619
diff changeset
287 static void uninit(int immed)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
288 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
289 if (esd_play_fd >= 0) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
290 esd_close(esd_play_fd);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
291 esd_play_fd = -1;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
292 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
293
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
294 if (esd_svinfo) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
295 esd_free_server_info(esd_svinfo);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
296 esd_svinfo = NULL;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
297 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
298
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
299 if (esd_fd >= 0) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
300 esd_close(esd_fd);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
301 esd_fd = -1;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
302 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
303 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
304
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
305
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
306 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
307 * plays 'len' bytes of 'data'
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
308 * it should round it down to outburst*n
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
309 * return: number of bytes played
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
310 */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
311 static int play(void* data, int len, int flags)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
312 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
313 int offs;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
314 int nwritten;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
315 int nsamples;
18976
6a08d0dabca8 Remove unused variables, patch by Stefan Huehner, stefan ##at## huehner org.
diego
parents: 17566
diff changeset
316 int n;
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
317
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
318 /* round down buffersize to a multiple of ESD_BUF_SIZE bytes */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
319 len = len / ESD_BUF_SIZE * ESD_BUF_SIZE;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
320 if (len <= 0)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
321 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
322
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
323 #define SINGLE_WRITE 0
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
324 #if SINGLE_WRITE
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
325 nwritten = write(esd_play_fd, data, len);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
326 #else
11619
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
327 for (offs = 0, nwritten=0; offs + ESD_BUF_SIZE <= len; offs += ESD_BUF_SIZE) {
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
328 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
329 * note: we're writing to a non-blocking socket here.
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
330 * A partial write means, that the socket buffer is full.
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
331 */
11619
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
332 n = write(esd_play_fd, (char*)data + offs, ESD_BUF_SIZE);
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
333 if ( n < 0 ) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
334 if ( errno != EAGAIN )
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
335 dprintf("esd play: write failed: %s\n", strerror(errno));
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
336 break;
11619
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
337 } else if ( n != ESD_BUF_SIZE ) {
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
338 nwritten += n;
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
339 break;
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
340 } else
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
341 nwritten += n;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
342 }
11619
179138947307 This patch contains bugfixes for the esd audio output driver that I
attila
parents: 10213
diff changeset
343 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
344
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
345 if (nwritten > 0) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
346 if (!esd_play_start.tv_sec)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
347 gettimeofday(&esd_play_start, NULL);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
348 nsamples = nwritten / esd_bytes_per_sample;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
349 esd_samples_written += nsamples;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
350
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
351 dprintf("esd play: %d %lu\n", nsamples, esd_samples_written);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
352 } else {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
353 dprintf("esd play: blocked / %lu\n", esd_samples_written);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
354 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
355
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
356 return nwritten;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
357 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
358
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
359
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
360 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
361 * stop playing, keep buffers (for pause)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
362 */
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
363 static void audio_pause(void)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
364 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
365 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
366 * not possible with esd. the esd daemom will continue playing
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
367 * buffered data (not more than ESD_MAX_DELAY seconds of samples)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
368 */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
369 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
370
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
371
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
372 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
373 * resume playing, after audio_pause()
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
374 */
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
375 static void audio_resume(void)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
376 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
377 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
378 * not possible with esd.
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
379 *
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
380 * Let's hope the pause was long enough that the esd ran out of
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
381 * buffered data; we restart our time based delay computation
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
382 * for an audio resume.
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
383 */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
384 esd_play_start.tv_sec = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
385 esd_samples_written = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
386 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
387
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
388
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
389 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
390 * stop playing and empty buffers (for seeking/pause)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
391 */
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
392 static void reset(void)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
393 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
394 #ifdef __svr4__
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
395 /* throw away data buffered in the esd connection */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
396 if (ioctl(esd_play_fd, I_FLUSH, FLUSHW))
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
397 perror("I_FLUSH");
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
398 #endif
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
399 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
400
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
401
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
402 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
403 * return: how many bytes can be played without blocking
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
404 */
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
405 static int get_space(void)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
406 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
407 struct timeval tmout;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
408 fd_set wfds;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
409 float current_delay;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
410 int space;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
411
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
412 /*
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
413 * Don't buffer too much data in the esd daemon.
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
414 *
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
415 * If we send too much, esd will block in write()s to the sound
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
416 * device, and the consequence is a huge slow down for things like
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
417 * esd_get_all_info().
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
418 */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
419 if ((current_delay = get_delay()) >= ESD_MAX_DELAY) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
420 dprintf("esd get_space: too much data buffered\n");
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
421 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
422 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
423
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
424 FD_ZERO(&wfds);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
425 FD_SET(esd_play_fd, &wfds);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
426 tmout.tv_sec = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
427 tmout.tv_usec = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
428
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
429 if (select(esd_play_fd + 1, NULL, &wfds, NULL, &tmout) != 1)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
430 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
431
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
432 if (!FD_ISSET(esd_play_fd, &wfds))
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
433 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
434
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
435 /* try to fill 50% of the remaining "free" buffer space */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
436 space = (ESD_MAX_DELAY - current_delay) * ao_data.bps * 0.5f;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
437
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
438 /* round up to next multiple of ESD_BUF_SIZE */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
439 space = (space + ESD_BUF_SIZE-1) / ESD_BUF_SIZE * ESD_BUF_SIZE;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
440
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
441 dprintf("esd get_space: %d\n", space);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
442 return space;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
443 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
444
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
445
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
446 /*
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
447 * return: delay in seconds between first and last sample in buffer
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
448 */
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
449 static float get_delay(void)
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
450 {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
451 struct timeval now;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
452 double buffered_samples_time;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
453 double play_time;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
454
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
455 if (!esd_play_start.tv_sec)
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
456 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
457
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
458 buffered_samples_time = (float)esd_samples_written / ao_data.samplerate;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
459 gettimeofday(&now, NULL);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
460 play_time = now.tv_sec - esd_play_start.tv_sec;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
461 play_time += (now.tv_usec - esd_play_start.tv_usec) / 1000000.;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
462
8572
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
463 /* dprintf("esd delay: %f %f\n", play_time, buffered_samples_time); */
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
464
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
465 if (play_time > buffered_samples_time) {
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
466 dprintf("esd: underflow\n");
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
467 esd_play_start.tv_sec = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
468 esd_samples_written = 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
469 return 0;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
470 }
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
471
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
472 dprintf("esd: get_delay %f\n", buffered_samples_time - play_time);
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
473 return buffered_samples_time - play_time;
46dbfa8c1999 new EsounD audio driver (-ao esd)
jkeil
parents:
diff changeset
474 }