]>
Commit | Line | Data |
---|---|---|
ffbf0089 AM |
1 | --- esound-0.2.22.orig/configure.in |
2 | +++ esound-0.2.22/configure.in | |
3 | @@ -50,6 +50,7 @@ | |
4 | AC_CHECK_LIB(rt,nanosleep,,[AC_CHECK_LIB(posix4,nanosleep)])]) | |
5 | AC_CHECK_FUNCS(usleep) | |
6 | AC_CHECK_FUNC(inet_aton,,[AC_CHECK_LIB(resolv,inet_aton)]) | |
7 | +AC_CHECK_FUNCS(strtok_r) | |
8 | ||
9 | case $ac_cv_func_nanosleep/$ac_cv_lib_rt_nanosleep/$ac_cv_lib_posix4_nanosleep in | |
10 | no/no/no) ;; | |
11 | --- esound-0.2.22.orig/esddsp.in | |
12 | +++ esound-0.2.22/esddsp.in | |
13 | @@ -92,8 +92,10 @@ | |
14 | exec_prefix=@exec_prefix@ | |
15 | libdir=@libdir@ | |
16 | ||
17 | -export LD_PRELOAD_PATH=${libdir} | |
18 | -export LD_PRELOAD='libesddsp.so libesd.so' | |
19 | +# Don't try to connect to esd if it isn't running | |
20 | +#if [ ! "x`pidof esd`" = "x" ]; then | |
21 | + export LD_PRELOAD="${libdir}/libesddsp.so.0:${libdir}/libesd.so.0" | |
22 | +#fi | |
23 | ||
24 | # invoke the program with the args given | |
25 | exec "$@" | |
26 | --- esound-0.2.22.orig/esddsp.c | |
27 | +++ esound-0.2.22/esddsp.c | |
28 | @@ -185,6 +185,11 @@ | |
29 | ||
30 | if (!strcmp (pathname, "/dev/dsp")) | |
31 | { | |
32 | +/* We shouldn't need this with Unix domain sockets, plus there | |
33 | + * is a better test in esdlib.c - for more info see: | |
34 | + * http://www.debian.org/Bugs/db/53/53602.html | |
35 | + * commented out by bma@debian.org 1999-12-29 */ | |
36 | +/* | |
37 | if (!getenv ("ESPEAKER")) | |
38 | { | |
39 | int ret; | |
40 | @@ -193,6 +198,7 @@ | |
41 | if ((ret = (*func) (pathname, flags, mode)) >= 0) | |
42 | return ret; | |
43 | } | |
44 | +*/ | |
45 | ||
46 | DPRINTF ("hijacking /dev/dsp open, and taking it to esd...\n"); | |
47 | settings = done = 0; | |
48 | --- esound-0.2.22.orig/esdlib.c | |
49 | +++ esound-0.2.22/esdlib.c | |
50 | @@ -637,7 +637,7 @@ | |
51 | /* ebm - I think this is an Inherently Bad Idea, but will leave it | |
52 | alone until I can get a good look at it */ | |
53 | if(! (host && *host)) { | |
54 | - int childpid, mypid; | |
55 | + pid_t childpid, mypid; | |
56 | struct sigaction sa, sa_orig; | |
57 | struct sigaction sa_alarm, sa_orig_alarm; | |
58 | ||
59 | @@ -666,9 +666,10 @@ | |
60 | char *cmd; | |
61 | ||
62 | setsid(); | |
63 | - cmd = malloc(sizeof("esd ") + esd_spawn_options?strlen(esd_spawn_options):0); | |
64 | + chdir("/tmp"); | |
65 | ||
66 | - sprintf(cmd, "esd %s -spawnpid %d", esd_spawn_options?esd_spawn_options:"", mypid); | |
67 | + cmd = malloc(sizeof("esd -spawnpid ") + esd_spawn_options?strlen(esd_spawn_options):0 + 10); | |
68 | + sprintf(cmd, "esd %s -spawnpid %u", esd_spawn_options?esd_spawn_options:"", mypid); | |
69 | ||
70 | execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); | |
71 | perror("execl"); | |
72 | --- esound-0.2.22.orig/esd_config.c | |
73 | +++ esound-0.2.22/esd_config.c | |
74 | @@ -5,6 +5,14 @@ | |
75 | #include <string.h> | |
76 | ||
77 | #define LINEBUF_SIZE 1024 | |
78 | + | |
79 | +#ifdef HAVE_STRTOK_R | |
80 | +#define DO_STRTOK(S,DELIM) strtok_r(S,DELIM,&strtok_state) | |
81 | +char strtok_state[LINEBUF_SIZE]; | |
82 | +#else | |
83 | +#define DO_STRTOK(S,DELIM) strtok(S,DELIM) | |
84 | +#endif | |
85 | + | |
86 | int esd_no_spawn=1; /* If we can't find even the system config file, | |
87 | things are screwed up - don't try to make things | |
88 | worse. */ | |
89 | @@ -90,9 +98,9 @@ | |
90 | break; | |
91 | } | |
92 | ||
93 | - key = strtok(aline, "="); | |
94 | + key = DO_STRTOK(aline, "="); | |
95 | if(!key) continue; | |
96 | - value = strtok(NULL, "="); | |
97 | + value = DO_STRTOK(NULL, "="); | |
98 | if(!value) value = ""; | |
99 | ||
100 | if(!strcasecmp(key, "auto_spawn")) | |
101 | --- esound-0.2.22.orig/audio.c | |
102 | +++ esound-0.2.22/audio.c | |
103 | @@ -7,6 +7,7 @@ | |
104 | #include <fcntl.h> | |
105 | #include <sys/ioctl.h> | |
106 | #include <math.h> | |
107 | +#include <errno.h> | |
108 | ||
109 | /*******************************************************************/ | |
110 | /* globals */ | |
111 | @@ -76,7 +77,22 @@ | |
112 | /* dump a buffer to the sound device */ | |
113 | int esd_audio_write( void *buffer, int buf_size ) | |
114 | { | |
115 | - return write( esd_audio_fd, buffer, buf_size ); | |
116 | + ssize_t nwrite=0, pos=0; | |
117 | + int counter = 0; | |
118 | + | |
119 | + while (counter < 100 && (nwrite = write( esd_audio_fd, buffer+pos, buf_size-pos )) != buf_size-pos ) { | |
120 | + if ( nwrite > 0 ) { | |
121 | + pos += nwrite; | |
122 | + } else if ( nwrite == -1 ) { | |
123 | + if ( errno == EAGAIN ) { | |
124 | + usleep(100); | |
125 | + counter++; | |
126 | + } else { | |
127 | + return -1; | |
128 | + } | |
129 | + } | |
130 | + } | |
131 | + return pos; | |
132 | } | |
133 | #endif | |
134 | ||
135 | --- esound-0.2.22.orig/audio_alsa.c | |
136 | +++ esound-0.2.22/audio_alsa.c | |
137 | @@ -22,7 +22,7 @@ | |
138 | static snd_pcm_format_t alsa_format; | |
139 | static snd_pcm_channel_info_t alsa_pinfo; | |
140 | static int alsa_direction = SND_PCM_OPEN_PLAYBACK; | |
141 | -static int alsa_mode = SND_PCM_MODE_BLOCK; | |
142 | +static int alsa_mode = SND_PCM_MODE_STREAM; | |
143 | static int alsa_channel = SND_PCM_CHANNEL_PLAYBACK; | |
144 | #endif | |
145 | ||
146 | @@ -65,13 +65,6 @@ | |
147 | int nbr_cards, ret; | |
148 | char buf[256]; | |
149 | struct snd_ctl_hw_info hw_info; | |
150 | - static int frag_size = 4*1024; | |
151 | - | |
152 | -#ifdef ALSA_5_API | |
153 | - static int frag_count = 0; | |
154 | -#else | |
155 | - static int frag_count = 2; | |
156 | -#endif | |
157 | ||
158 | #ifdef ALSA_5_API | |
159 | snd_pcm_channel_params_t params; | |
160 | @@ -84,6 +77,10 @@ | |
161 | ||
162 | snd_ctl_t *ctl_handle; | |
163 | ||
164 | + if ( esd_audio_device ) { | |
165 | + card = atoi( esd_audio_device ); | |
166 | + } | |
167 | + | |
168 | if( driver_trace ) { | |
169 | fprintf( stderr, "Using ALSA %s\n", SND_LIB_VERSION_STR ); | |
170 | } | |
171 | @@ -127,7 +124,7 @@ | |
172 | fprintf( stderr, "esd: Found %d card(s)\n", nbr_cards ); | |
173 | } | |
174 | ||
175 | - for ( card=0; ( card < nbr_cards ) && (alsa_sound_handle == NULL); card++ ) { | |
176 | + for ( ; ( card < nbr_cards ) && (alsa_sound_handle == NULL); card++ ) { | |
177 | if( driver_trace ) { | |
178 | fprintf( stderr, "esd: trying alsa card %d\n", card ); | |
179 | } | |
180 | @@ -199,9 +196,8 @@ | |
181 | } | |
182 | ||
183 | memset(¶ms, 0, sizeof(params)); | |
184 | - params.buf.block.frag_size = frag_size; | |
185 | - params.buf.block.frags_max = frag_count; | |
186 | - params.buf.block.frags_min = 1; | |
187 | + params.buf.stream.queue_size = ESD_BUF_SIZE; | |
188 | + params.buf.stream.fill = SND_PCM_FILL_NONE; | |
189 | params.channel = alsa_channel; | |
190 | params.mode = alsa_mode; | |
191 | params.start_mode = SND_PCM_START_FULL; | |
192 | @@ -343,43 +339,44 @@ | |
193 | #define ARCH_esd_audio_write | |
194 | int esd_audio_write( void *buffer, int buf_size ) | |
195 | { | |
196 | - int i=0; | |
197 | + ssize_t nwrite=0, pos=0; | |
198 | + int counter = 0; | |
199 | ||
200 | #ifdef ALSA_5_API | |
201 | snd_pcm_channel_status_t status; | |
202 | int ret; | |
203 | #endif | |
204 | ||
205 | - i = snd_pcm_write( alsa_sound_handle, buffer, buf_size); | |
206 | - if( i<0 ) { | |
207 | -#if 0 | |
208 | - fprintf( stderr, "error: %s: in snd_pcm_write\n", snd_strerror(i) ); | |
209 | -#endif | |
210 | - } | |
211 | - | |
212 | + while (counter < 100 && (nwrite = snd_pcm_write( alsa_sound_handle, buffer+pos, buf_size-pos )) != buf_size-pos ) { | |
213 | + if ( nwrite > 0 ) { | |
214 | + pos += nwrite; | |
215 | + } else if ( nwrite < 0 ) { | |
216 | + if ( errno == EAGAIN ) { | |
217 | + usleep(100); | |
218 | + counter++; | |
219 | + } else { | |
220 | #ifdef ALSA_5_API | |
221 | - status.channel = SND_PCM_CHANNEL_PLAYBACK; | |
222 | - ret = snd_pcm_channel_status( alsa_sound_handle, &status ); | |
223 | - if( ret ) { | |
224 | - if( driver_trace ) fprintf( stderr, "error: %s: in snd_pcm_channel_status\n", snd_strerror(ret) ); | |
225 | - return(-1); | |
226 | - } | |
227 | - if( status.underrun ) { | |
228 | - snd_pcm_channel_flush( alsa_sound_handle, alsa_channel ); | |
229 | - snd_pcm_playback_prepare( alsa_sound_handle ); | |
230 | - snd_pcm_write( alsa_sound_handle, buffer, buf_size ); | |
231 | - if (snd_pcm_channel_status( alsa_sound_handle, &status ) < 0 && driver_trace) { | |
232 | - fprintf(stderr, "ALSA: could not get channel status. giving up\n"); | |
233 | - return -1; | |
234 | - } | |
235 | - if (status.underrun) { | |
236 | - if( driver_trace ) fprintf(stderr, "ALSA: write error. giving up\n"); | |
237 | - return -1; | |
238 | - } | |
239 | - } | |
240 | + status.channel = alsa_channel; | |
241 | + ret = snd_pcm_channel_status( alsa_sound_handle, &status ); | |
242 | + if( ret ) { | |
243 | + if( driver_trace ) fprintf( stderr, "error: %s: in snd_pcm_channel_status\n", snd_strerror(ret) ); | |
244 | + return(-1); | |
245 | + } | |
246 | + if( status.status == SND_PCM_STATUS_UNDERRUN ) { | |
247 | + counter++; | |
248 | + snd_pcm_channel_flush( alsa_sound_handle, alsa_channel ); | |
249 | + snd_pcm_playback_prepare( alsa_sound_handle ); | |
250 | + usleep(100); | |
251 | + } else { | |
252 | + return -1; | |
253 | + } | |
254 | +#else | |
255 | + return -1; | |
256 | #endif /* ALSA_5_API */ | |
257 | - | |
258 | - return (i); | |
259 | + } | |
260 | + } | |
261 | + } | |
262 | + return pos; | |
263 | } | |
264 | ||
265 | #define ARCH_esd_audio_flush | |
266 | --- esound-0.2.22.orig/esd.c | |
267 | +++ esound-0.2.22/esd.c | |
268 | @@ -191,7 +191,7 @@ | |
269 | return -1; | |
270 | /* set the connect information */ | |
271 | socket_unix.sun_family = AF_UNIX; | |
272 | - strncpy(socket_unix.sun_path, ESD_UNIX_SOCKET_NAME, sizeof(socket_unix.sun_path)); | |
273 | + strncpy(socket_unix.sun_path, ESD_UNIX_SOCKET_NAME, sizeof(socket_unix.sun_path)-1); | |
274 | if ( connect( socket_out, | |
275 | (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix) ) < 0 ) | |
276 | return -1; | |
277 | @@ -754,11 +754,8 @@ | |
278 | while ( 1 ) | |
279 | { | |
280 | /* block while waiting for more clients and new data */ | |
281 | - wait_for_clients_and_data( listen_socket ); | |
282 | - | |
283 | - /* accept new connections */ | |
284 | - get_new_clients( listen_socket ); | |
285 | - | |
286 | + if ( wait_for_clients_and_data( listen_socket ) || | |
287 | + esd_playing_samples || esd_recorder_list ) { | |
288 | ||
289 | if ((esd_clients_list == NULL) && (!first) && (esd_terminate)) { | |
290 | /* fprintf(stderr, "No clients!\n");*/ | |
291 | @@ -777,7 +774,9 @@ | |
292 | /* awaken if on autostandby and doing anything */ | |
293 | if ( esd_on_autostandby && length && !esd_forced_standby ) { | |
294 | ESDBG_TRACE( printf( "stuff to play, waking up.\n" ); ); | |
295 | - esd_server_resume(); | |
296 | + if ( !esd_server_resume()) { | |
297 | + usleep(100); | |
298 | + } | |
299 | } | |
300 | ||
301 | /* we handle this even when length == 0 because a filter could have | |
302 | @@ -846,6 +845,7 @@ | |
303 | restrain.tv_usec *= 1000L; /* convert to microseconds */ | |
304 | select( 0, 0, 0, 0, &restrain ); | |
305 | #endif | |
306 | + } | |
307 | } | |
308 | } /* while ( 1 ) */ | |
309 | ||
310 | --- esound-0.2.22.orig/clients.c | |
311 | +++ esound-0.2.22/clients.c | |
312 | @@ -17,6 +17,7 @@ | |
313 | ||
314 | /*******************************************************************/ | |
315 | /* globals */ | |
316 | +extern int esd_use_tcpip; | |
317 | ||
318 | /* the list of the currently connected clients */ | |
319 | esd_client_t *esd_clients_list; | |
320 | @@ -129,17 +130,20 @@ | |
321 | do { | |
322 | fd = accept( listen, (struct sockaddr*) &incoming, &size_in ); | |
323 | if ( fd > 0 ) { | |
324 | - port = ntohs( incoming.sin_port ); | |
325 | - addr = ntohl( incoming.sin_addr.s_addr ); | |
326 | - | |
327 | ESDBG_TRACE( | |
328 | + if (esd_use_tcpip) { | |
329 | + port = ntohs( incoming.sin_port ); | |
330 | + addr = ntohl( incoming.sin_addr.s_addr ); | |
331 | + | |
332 | printf( "(%02d) new client from: %03u.%03u.%03u.%03u:%05d\n", | |
333 | fd, (unsigned int) addr >> 24, | |
334 | (unsigned int) (addr >> 16) % 256, | |
335 | (unsigned int) (addr >> 8) % 256, | |
336 | - (unsigned int) addr % 256, port ); ); | |
337 | + (unsigned int) addr % 256, port ); | |
338 | + } ); | |
339 | ||
340 | #ifdef USE_LIBWRAP | |
341 | + if (esd_use_tcpip) | |
342 | { | |
343 | struct request_info req; | |
344 | struct servent *serv; | |
345 | @@ -270,7 +274,7 @@ | |
346 | "paused=%d, samples=%d, auto=%d, standby=%d, record=%d, ready=%d\n", | |
347 | is_paused_here, esd_playing_samples, | |
348 | esd_autostandby_secs, esd_on_standby, | |
349 | - (esd_recorder != 0), ready ); ); | |
350 | + (esd_recorder_list != 0), ready ); ); | |
351 | ||
352 | /* TODO: return ready, and do this in esd.c */ | |
353 | if ( ready <= 0 ) { | |
354 | @@ -304,6 +308,10 @@ | |
355 | ||
356 | is_paused_here = 0; | |
357 | ||
358 | + } | |
359 | + | |
360 | + if ( FD_ISSET(listen, &rd_fds ) ) { | |
361 | + get_new_clients( listen ); | |
362 | } | |
363 | ||
364 | return ready; | |
365 | --- esound-0.2.22.orig/mix.c | |
366 | +++ esound-0.2.22/mix.c | |
367 | @@ -592,7 +592,7 @@ | |
368 | rd_dat = wr_dat * player->rate / esd_audio_rate; | |
369 | rd_dat /= 2; /* adjust for mono */ | |
370 | ||
371 | - sample = source_data_uc[ rd_dat++ ]; | |
372 | + sample = source_data_uc[ rd_dat ]; | |
373 | sample -= 127; sample *= 256; | |
374 | ||
375 | mixed_buffer[ wr_dat++ ] += sample; | |
376 | @@ -624,7 +624,7 @@ | |
377 | { | |
378 | rd_dat = wr_dat * player->rate / esd_audio_rate; | |
379 | ||
380 | - sample = source_data_uc[ rd_dat++ ]; | |
381 | + sample = source_data_uc[ rd_dat ]; | |
382 | sample -= 127; sample *= 256; | |
383 | ||
384 | mixed_buffer[ wr_dat++ ] += sample; | |
385 | @@ -650,7 +650,7 @@ | |
386 | rd_dat = wr_dat * player->rate / esd_audio_rate; | |
387 | rd_dat /= 2; /* adjust for mono */ | |
388 | ||
389 | - sample = source_data_ss[ rd_dat++ ]; | |
390 | + sample = source_data_ss[ rd_dat ]; | |
391 | ||
392 | mixed_buffer[ wr_dat++ ] += sample; | |
393 | mixed_buffer[ wr_dat++ ] += sample; | |
394 | @@ -680,7 +680,7 @@ | |
395 | while ( wr_dat < length/sizeof(signed short) ) | |
396 | { | |
397 | rd_dat = wr_dat * player->rate / esd_audio_rate; | |
398 | - sample = source_data_ss[ rd_dat++ ]; | |
399 | + sample = source_data_ss[ rd_dat ]; | |
400 | mixed_buffer[ wr_dat++ ] += sample; | |
401 | } | |
402 | } | |
403 | @@ -706,7 +706,7 @@ | |
404 | rd_dat = wr_dat * player->rate / esd_audio_rate; | |
405 | rd_dat /= 2; /* adjust for mono */ | |
406 | ||
407 | - sample = source_data_uc[ rd_dat++ ]; | |
408 | + sample = source_data_uc[ rd_dat ]; | |
409 | sample -= 127; sample *= 256; | |
410 | ||
411 | sample = sample * player->left_vol_scale / ESD_VOLUME_BASE; | |
412 | @@ -751,7 +751,7 @@ | |
413 | sample = sample * player->left_vol_scale / ESD_VOLUME_BASE; | |
414 | mixed_buffer[ wr_dat++ ] += sample; | |
415 | ||
416 | - sample = source_data_uc[ rd_dat++ ]; | |
417 | + sample = source_data_uc[ rd_dat ]; | |
418 | sample -= 127; sample *= 256; | |
419 | sample = sample * player->right_vol_scale / ESD_VOLUME_BASE; | |
420 | mixed_buffer[ wr_dat++ ] += sample; | |
421 | @@ -777,7 +777,7 @@ | |
422 | rd_dat = wr_dat * player->rate / esd_audio_rate; | |
423 | rd_dat /= 2; /* adjust for mono */ | |
424 | ||
425 | - sample = source_data_ss[ rd_dat++ ]; | |
426 | + sample = source_data_ss[ rd_dat ]; | |
427 | ||
428 | mixed_buffer[ wr_dat++ ] | |
429 | += sample * player->left_vol_scale / ESD_VOLUME_BASE; | |
430 | @@ -820,7 +820,7 @@ | |
431 | sample = sample * player->left_vol_scale / ESD_VOLUME_BASE; | |
432 | mixed_buffer[ wr_dat++ ] += sample; | |
433 | ||
434 | - sample = source_data_ss[ rd_dat++ ]; | |
435 | + sample = source_data_ss[ rd_dat ]; | |
436 | sample = sample * player->right_vol_scale / ESD_VOLUME_BASE; | |
437 | mixed_buffer[ wr_dat++ ] += sample; | |
438 | } | |
439 | @@ -875,14 +875,14 @@ | |
440 | /* takes all input players, and mixes them to the mixed_buffer */ | |
441 | int mix_players( void *output, int length ) | |
442 | { | |
443 | - int actual = 0, max = 0; | |
444 | + int actual = 0, min = 0, max = 0, translated = 0, iBps, used; | |
445 | esd_player_t *player = NULL; | |
446 | esd_player_t *erase = NULL; | |
447 | ||
448 | ESDBG_MIXER( printf( "++++++++++++++++++++++++++++++++++++++++++\n" ); ); | |
449 | ||
450 | /* zero the sum buffer */ | |
451 | - memset( mixed_buffer, 0, esd_buf_size_samples * sizeof(int) ); | |
452 | + memset( mixed_buffer, 0, ESD_BUF_SIZE * sizeof(signed int) ); | |
453 | ||
454 | /* as long as there's a player out there */ | |
455 | player = esd_players_list; | |
456 | @@ -890,21 +890,45 @@ | |
457 | { | |
458 | /* read the client sound data */ | |
459 | actual = read_player( player ); | |
460 | - | |
461 | - /* read_player(): >0 = data, ==0 = no data, <0 = erase it */ | |
462 | - if ( actual > 0 ) { | |
463 | - /* printf( "received: %d bytes from %d\n", | |
464 | - actual, player->source_id ); */ | |
465 | - /* actual = mix_to_stereo_32s( player, length ); */ | |
466 | - actual = player->mix_func( player, length ); | |
467 | - if ( actual > max ) max = actual; | |
468 | - | |
469 | - } else if ( actual == 0 ) { | |
470 | - ESDBG_TRACE( printf( "(%02d) no data available from player [%p]\n", | |
471 | + | |
472 | + if ( actual == 0 ) { | |
473 | + ESDBG_TRACE( printf( "(%02d) no new data available from player [%p]\n", | |
474 | player->source_id, player ); ); | |
475 | - } else { | |
476 | + if ( player->actual_length == 0 ) { | |
477 | + player = player->next; | |
478 | + continue; | |
479 | + } | |
480 | + } | |
481 | + | |
482 | + if ( actual < 0 ) { | |
483 | /* actual < 0 means erase the player */ | |
484 | erase = player; | |
485 | + } else { | |
486 | + /* actual >= 0 means data might be there to mix */ | |
487 | + iBps = sizeof(signed short) * 2; | |
488 | + | |
489 | + if ( (player->format & ESD_MASK_BITS) == ESD_BITS8 ) | |
490 | + iBps /= sizeof(signed short); | |
491 | + if ( (player->format & ESD_MASK_CHAN) == ESD_MONO ) | |
492 | + iBps /= 2; | |
493 | + | |
494 | + /* how much data is really there? */ | |
495 | + translated = ((player->actual_length / iBps) * esd_audio_rate + player->rate - 1) / player->rate; | |
496 | + translated *= sizeof(signed short) * 2; | |
497 | + | |
498 | + if ( translated > length ) { | |
499 | + ESDBG_TRACE( printf( "(%02d) player translated length doesn't fit [%p]\n", | |
500 | + player->source_id, player ); ); | |
501 | + translated = length; | |
502 | + } | |
503 | + | |
504 | + if ( min == 0 ) { | |
505 | + min = translated; | |
506 | + } else { | |
507 | + if ( min > translated ) { | |
508 | + min = translated; | |
509 | + } | |
510 | + } | |
511 | } | |
512 | ||
513 | /* check out the next item in the list */ | |
514 | @@ -917,13 +941,54 @@ | |
515 | } | |
516 | } | |
517 | ||
518 | + if ( min > 0 ) { | |
519 | + player = esd_players_list; | |
520 | + while( player != NULL ) | |
521 | + { | |
522 | + if ( player->actual_length > 0 ) { | |
523 | + /* read_player(): >0 = data, ==0 = no data, <0 = erase it */ | |
524 | + iBps = sizeof(signed short) * 2; | |
525 | + | |
526 | + if ( (player->format & ESD_MASK_BITS) == ESD_BITS8 ) | |
527 | + iBps /= sizeof(signed short); | |
528 | + if ( (player->format & ESD_MASK_CHAN) == ESD_MONO ) | |
529 | + iBps /= 2; | |
530 | + | |
531 | + actual = player->mix_func( player, min ); | |
532 | + | |
533 | + /* but how much data did we use? */ | |
534 | + used = (actual / (sizeof(signed short) * 2)) * player->rate / esd_audio_rate; | |
535 | + | |
536 | + if ( (player->format & ESD_MASK_BITS) != ESD_BITS8 ) | |
537 | + used *= sizeof(signed short); | |
538 | + if ( (player->format & ESD_MASK_CHAN) != ESD_MONO ) | |
539 | + used *= 2; | |
540 | + | |
541 | + if ( player->actual_length - used > 0 ) { | |
542 | + memmove( player->data_buffer, player->data_buffer + used, player->actual_length - used ); | |
543 | + player->actual_length -= used; | |
544 | + } else { | |
545 | + /* kill it, it's probably all used anyways */ | |
546 | + player->actual_length = 0; | |
547 | + } | |
548 | + | |
549 | + if ( actual > max ) { | |
550 | + max = actual; | |
551 | + } | |
552 | + } | |
553 | + | |
554 | + /* check out the next item in the list */ | |
555 | + player = player->next; | |
556 | + } | |
557 | + | |
558 | /* ESDBG_COMMS( printf( "maximum stream length = %d bytes\n", max ); ); */ | |
559 | ||
560 | - if ( (esd_audio_format & ESD_MASK_BITS) == ESD_BITS16 ) | |
561 | - clip_mix_to_output_16s( output, max ); | |
562 | - else { | |
563 | - clip_mix_to_output_8u( output, max ); | |
564 | - max /= 2; /* half as many samples as you'd think */ | |
565 | + if ( (esd_audio_format & ESD_MASK_BITS) == ESD_BITS16 ) | |
566 | + clip_mix_to_output_16s( output, max ); | |
567 | + else { | |
568 | + clip_mix_to_output_8u( output, max ); | |
569 | + max /= 2; /* half as many samples as you'd think */ | |
570 | + } | |
571 | } | |
572 | ||
573 | return max; | |
574 | --- esound-0.2.22.orig/players.c | |
575 | +++ esound-0.2.22/players.c | |
576 | @@ -287,27 +287,28 @@ | |
577 | FD_SET( player->source_id, &rd_fds ); | |
578 | ||
579 | /* if the data is ready, read a block */ | |
580 | - can_read = select( player->source_id + 1, | |
581 | - &rd_fds, NULL, NULL, &timeout ) ; | |
582 | + can_read = (( player->actual_length < player->buffer_length ) && | |
583 | + select( player->source_id + 1, &rd_fds, NULL, NULL, &timeout )); | |
584 | + | |
585 | if ( can_read > 0 ) | |
586 | { | |
587 | - ESD_READ_BIN( player->source_id, player->data_buffer, | |
588 | - player->buffer_length, actual, "str rd" ); | |
589 | + ESD_READ_BIN( player->source_id, player->data_buffer+player->actual_length, | |
590 | + player->buffer_length-player->actual_length, actual, "str rd" ); | |
591 | ||
592 | /* check for end of stream */ | |
593 | if ( actual == 0 | |
594 | || ( actual < 0 && errno != EAGAIN && errno != EINTR ) ) | |
595 | return -1; | |
596 | ||
597 | - /* more data, save how much we got */ | |
598 | - player->actual_length = actual; | |
599 | - | |
600 | /* endian swap multi-byte data if we need to */ | |
601 | client = (esd_client_t *) (player->parent); | |
602 | if ( client->swap_byte_order | |
603 | && ( (player->format & ESD_MASK_BITS) == ESD_BITS16 ) ) | |
604 | { | |
605 | - buffer = (unsigned short*) player->data_buffer; | |
606 | + /* this will break if a read doesn't get us 16bit aligned | |
607 | + * data... | |
608 | + */ | |
609 | + buffer = (unsigned short*) player->data_buffer+player->actual_length; | |
610 | for ( pos = buffer | |
611 | ; pos < buffer + actual / sizeof(short) | |
612 | ; pos ++ ) | |
613 | @@ -317,6 +318,9 @@ | |
614 | } | |
615 | } | |
616 | ||
617 | + /* more data, save how much we got */ | |
618 | + player->actual_length += actual; | |
619 | + | |
620 | } else if ( can_read < 0 ) { | |
621 | sprintf( message, "error reading client (%d)\n", | |
622 | player->source_id ); | |
623 | @@ -330,6 +334,7 @@ | |
624 | ||
625 | /* printf( "player [%p], pos = %d, format = 0x%08x\n", | |
626 | player, player->last_pos, player->format ); */ | |
627 | + player->actual_length = 0; | |
628 | ||
629 | /* only keep going if we didn't want to stop looping */ | |
630 | if ( ( player->last_pos ) == 0 && | |
631 | @@ -351,6 +356,7 @@ | |
632 | player->last_pos += actual; | |
633 | if ( ( player->format & ESD_MASK_FUNC ) != ESD_LOOP ) { | |
634 | /* we're done for this iteration */ | |
635 | + player->actual_length = actual; | |
636 | break; | |
637 | } | |
638 | } else { | |
639 | @@ -387,6 +393,7 @@ | |
640 | /* something horrible has happened to the sample */ | |
641 | return -1; | |
642 | } | |
643 | + player->actual_length = actual; | |
644 | ||
645 | /* sample data is swapped as it's cached, no swap needed here */ | |
646 | break; | |
647 | @@ -541,8 +548,8 @@ | |
648 | if ( (player->format & ESD_MASK_CHAN) == ESD_MONO ) | |
649 | player->buffer_length /= 2; | |
650 | ||
651 | - /* force to an even multiple of 4 */ | |
652 | - player->buffer_length += ( 4 - (player->buffer_length % 4) ) % 4; | |
653 | + /* force to an even multiple of 4 bytes (lower) */ | |
654 | + player->buffer_length -= (player->buffer_length % 4); | |
655 | ||
656 | player->data_buffer | |
657 | = (void *) malloc( player->buffer_length ); | |
658 | @@ -553,6 +560,7 @@ | |
659 | return NULL; | |
660 | } | |
661 | ||
662 | + player->actual_length = 0; | |
663 | /* everything's ok, set the easy stuff */ | |
664 | player->left_vol_scale = player->right_vol_scale = ESD_VOLUME_BASE; | |
665 | player->mix_func = get_mix_func( player ); | |
666 | @@ -614,7 +622,7 @@ | |
667 | player->buffer_length /= 2; | |
668 | ||
669 | /* force to an even multiple of 4 */ | |
670 | - player->buffer_length += ( 4 - (player->buffer_length % 4) ) % 4; | |
671 | + player->buffer_length -= ( player->buffer_length % 4 ); | |
672 | ||
673 | player->data_buffer | |
674 | = (void *) malloc( player->buffer_length ); | |
675 | @@ -628,6 +636,7 @@ | |
676 | /* update housekeeping values */ | |
677 | esd_playing_samples++; | |
678 | player->last_pos = 0; | |
679 | + player->actual_length = 0; | |
680 | sample->ref_count++; | |
681 | player->mix_func = get_mix_func( player ); | |
682 | player->translate_func = NULL; /* no translating, just mixing */ | |
683 | --- esound-0.2.22.orig/proto.c | |
684 | +++ esound-0.2.22/proto.c | |
685 | @@ -336,14 +336,13 @@ | |
686 | /* let the device know we want to record */ | |
687 | ESDBG_TRACE( printf( "closing audio for a sec...\n" ); ); | |
688 | esd_audio_close(); | |
689 | - sleep(1); | |
690 | esd_audio_format |= ESD_RECORD; | |
691 | ESDBG_TRACE( printf( "reopening audio to record...\n" ); ); | |
692 | if (esd_audio_open() < 0) { | |
693 | /* Failed to record */ | |
694 | free_player( recorder ); | |
695 | esd_audio_format &= ~ESD_RECORD; | |
696 | - sleep(1); | |
697 | + usleep(100); | |
698 | /* If we fail here, we have a oops */ | |
699 | esd_audio_open(); | |
700 | return 0; | |
701 | --- esound-0.2.22.orig/esdcat.c | |
702 | +++ esound-0.2.22/esdcat.c | |
703 | @@ -60,7 +60,7 @@ | |
704 | #endif | |
705 | ||
706 | format = bits | channels | mode | func; | |
707 | - printf( "opening socket, format = 0x%08x at %d Hz\n", | |
708 | + fprintf( stderr, "opening socket, format = 0x%08x at %d Hz\n", | |
709 | format, rate ); | |
710 | ||
711 | /* sock = esd_play_stream( format, rate ); */ | |
712 | --- esound-0.2.22.orig/esd-server.h | |
713 | +++ esound-0.2.22/esd-server.h | |
714 | @@ -15,6 +15,7 @@ | |
715 | #include <sys/ioctl.h> | |
716 | #include <netinet/in.h> | |
717 | #include <sys/socket.h> | |
718 | +#include <sys/un.h> | |
719 | #include <signal.h> | |
720 | #include <sys/time.h> | |
721 | #include <sys/types.h> | |
722 | --- esound-0.2.22.orig/esdmon.c | |
723 | +++ esound-0.2.22/esdmon.c | |
724 | @@ -52,7 +52,7 @@ | |
725 | } | |
726 | ||
727 | format = bits | channels | mode | func; | |
728 | - printf( "opening socket, format = 0x%08x at %d Hz\n", | |
729 | + fprintf( stderr, "opening socket, format = 0x%08x at %d Hz\n", | |
730 | format, rate ); | |
731 | ||
732 | sock = esd_monitor_stream( format, rate, host, argv[0] ); | |
733 | --- esound-0.2.22.orig/esdrec.c | |
734 | +++ esound-0.2.22/esdrec.c | |
735 | @@ -54,7 +54,7 @@ | |
736 | } | |
737 | ||
738 | format = bits | channels | mode | func; | |
739 | - printf( "opening socket, format = 0x%08x at %d Hz\n", | |
740 | + fprintf( stderr, "opening socket, format = 0x%08x at %d Hz\n", | |
741 | format, rate ); | |
742 | ||
743 | /* sock = esd_record_stream( format, rate ); */ | |
744 | --- esound-0.2.22.orig/esdsample.c | |
745 | +++ esound-0.2.22/esdsample.c | |
746 | @@ -95,7 +95,7 @@ | |
747 | if ( sock <= 0 ) | |
748 | return 1; | |
749 | format = bits | channels | mode | func; | |
750 | - printf( "opening socket, format = 0x%08x at %d Hz\n", | |
751 | + fprintf( stderr, "opening socket, format = 0x%08x at %d Hz\n", | |
752 | format, rate ); | |
753 | ||
754 | stat( name, &source_stats ); | |
755 | --- esound-0.2.22.orig/esdloop.c | |
756 | +++ esound-0.2.22/esdloop.c | |
757 | @@ -67,7 +67,7 @@ | |
758 | } | |
759 | ||
760 | format = bits | channels | mode | func; | |
761 | - printf( "opening socket, format = 0x%08x at %d Hz\n", | |
762 | + fprintf( stderr, "opening socket, format = 0x%08x at %d Hz\n", | |
763 | format, rate ); | |
764 | ||
765 | sock = esd_open_sound( host ); | |
766 | --- esound-0.2.22.orig/esd.m4 | |
767 | +++ esound-0.2.22/esd.m4 | |
768 | @@ -38,6 +38,8 @@ | |
769 | if test "$ESD_CONFIG" = "no" ; then | |
770 | no_esd=yes | |
771 | else | |
772 | + AC_LANG_SAVE | |
773 | + AC_LANG_C | |
774 | ESD_CFLAGS=`$ESD_CONFIG $esdconf_args --cflags` | |
775 | ESD_LIBS=`$ESD_CONFIG $esdconf_args --libs` | |
776 | ||
777 | @@ -114,6 +116,7 @@ | |
778 | ],, no_esd=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) | |
779 | CFLAGS="$ac_save_CFLAGS" | |
780 | LIBS="$ac_save_LIBS" | |
781 | + AC_LANG_RESTORE | |
782 | fi | |
783 | fi | |
784 | if test "x$no_esd" = x ; then | |
785 | @@ -133,6 +136,8 @@ | |
786 | echo "*** Could not run ESD test program, checking why..." | |
787 | CFLAGS="$CFLAGS $ESD_CFLAGS" | |
788 | LIBS="$LIBS $ESD_LIBS" | |
789 | + AC_LANG_SAVE | |
790 | + AC_LANG_C | |
791 | AC_TRY_LINK([ | |
792 | #include <stdio.h> | |
793 | #include <esd.h> | |
794 | @@ -152,6 +157,7 @@ | |
795 | echo "*** may want to edit the esd-config script: $ESD_CONFIG" ]) | |
796 | CFLAGS="$ac_save_CFLAGS" | |
797 | LIBS="$ac_save_LIBS" | |
798 | + AC_LANG_RESTORE | |
799 | fi | |
800 | fi | |
801 | ESD_CFLAGS="" | |
802 |