--- sourceforge.net/trunk/rdesktop/rdpsnd.c 2006/09/17 18:08:51 1263 +++ sourceforge.net/trunk/rdesktop/rdpsnd.c 2006/10/19 11:28:53 1299 @@ -19,6 +19,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include + #include "rdesktop.h" #include "rdpsnd.h" #include "rdpsnd_dsp.h" @@ -194,6 +196,7 @@ static uint16 tick, format; static uint8 packet_index; static BOOL awaiting_data_packet; + static unsigned char missing_bytes[4] = { 0, 0, 0, 0 }; #ifdef RDPSND_DEBUG printf("RDPSND recv:\n"); @@ -226,6 +229,9 @@ current_format = format; } + /* Insert the 4 missing bytes retrieved from last RDPSND_WRITE */ + memcpy(s->data, missing_bytes, 4); + current_driver-> wave_out_write(rdpsnd_dsp_process (s, current_driver, &formats[current_format]), tick, @@ -244,6 +250,8 @@ in_uint16_le(s, tick); in_uint16_le(s, format); in_uint8(s, packet_index); + /* Here are our lost bytes, but why? */ + memcpy(missing_bytes, s->end - 4, 4); awaiting_data_packet = True; break; case RDPSND_CLOSE: @@ -270,38 +278,37 @@ } } -BOOL -rdpsnd_init(void) -{ - rdpsnd_channel = - channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP, - rdpsnd_process); - - return (rdpsnd_channel != NULL); -} - -BOOL +static BOOL rdpsnd_auto_open(void) { - current_driver = drivers; - while (current_driver != NULL) + static BOOL failed = False; + + if (!failed) { - DEBUG(("trying %s...\n", current_driver->name)); - if (current_driver->wave_out_open()) + struct audio_driver *auto_driver = current_driver; + + current_driver = drivers; + while (current_driver != NULL) { - DEBUG(("selected %s\n", current_driver->name)); - return True; + DEBUG(("trying %s...\n", current_driver->name)); + if (current_driver->wave_out_open()) + { + DEBUG(("selected %s\n", current_driver->name)); + return True; + } + g_dsp_fd = 0; + current_driver = current_driver->next; } - g_dsp_fd = 0; - current_driver = current_driver->next; - } - warning("no working audio-driver found\n"); + warning("no working audio-driver found\n"); + failed = True; + current_driver = auto_driver; + } return False; } -void +static void rdpsnd_register_drivers(char *options) { struct audio_driver **reg; @@ -311,33 +318,67 @@ reg = &drivers; #if defined(RDPSND_ALSA) *reg = alsa_register(options); - reg = &((*reg)->next); -#endif -#if defined(RDPSND_OSS) - *reg = oss_register(options); + assert(*reg); reg = &((*reg)->next); #endif #if defined(RDPSND_SUN) *reg = sun_register(options); + assert(*reg); + reg = &((*reg)->next); +#endif +#if defined(RDPSND_OSS) + *reg = oss_register(options); + assert(*reg); reg = &((*reg)->next); #endif #if defined(RDPSND_SGI) *reg = sgi_register(options); + assert(*reg); reg = &((*reg)->next); #endif #if defined(RDPSND_LIBAO) *reg = libao_register(options); + assert(*reg); reg = &((*reg)->next); #endif } BOOL -rdpsnd_select_driver(char *driver, char *options) +rdpsnd_init(char *optarg) { static struct audio_driver auto_driver; struct audio_driver *pos; + char *driver = NULL, *options = NULL; drivers = NULL; + + rdpsnd_channel = + channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP, + rdpsnd_process); + + if (rdpsnd_channel == NULL) + { + error("channel_register\n"); + return False; + } + + if (optarg != NULL && strlen(optarg) > 0) + { + driver = options = optarg; + + while (*options != '\0' && *options != ':') + options++; + + if (*options == ':') + { + *options = '\0'; + options++; + } + + if (*options == '\0') + options = NULL; + } + rdpsnd_register_drivers(options); if (!driver) @@ -376,7 +417,7 @@ } } -inline void +void rdpsnd_play(void) { current_driver->wave_out_play(); @@ -404,32 +445,32 @@ current_driver->wave_out_play(); } -inline struct audio_packet * +struct audio_packet * rdpsnd_queue_current_packet(void) { return &packet_queue[queue_lo]; } -inline BOOL +BOOL rdpsnd_queue_empty(void) { return (queue_lo == queue_hi); } -inline void +void rdpsnd_queue_init(void) { queue_lo = queue_hi = 0; } -inline void +void rdpsnd_queue_next(void) { xfree(packet_queue[queue_lo].s.data); queue_lo = (queue_lo + 1) % MAX_QUEUE; } -inline int +int rdpsnd_queue_next_tick(void) { if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)