diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 49915dcf..71f2ea11 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -291,17 +291,8 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { GUAC_RDP_AUDIO_CHANNELS, GUAC_RDP_AUDIO_BPS); - /* If an encoding is available, load the sound plugin */ - if (guac_client_data->audio != NULL) { - - /* Load sound plugin */ - if (freerdp_channels_load_plugin(channels, instance->settings, - "guacsnd", client)) - guac_client_log(client, GUAC_LOG_WARNING, - "Failed to load guacsnd plugin. Audio will not work."); - - } - else + /* Warn if no audio encoding is available */ + if (guac_client_data->audio == NULL) guac_client_log(client, GUAC_LOG_INFO, "No available audio encoding. Sound disabled."); @@ -321,7 +312,7 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { } - /* If RDPDR required, load it */ + /* If RDPSND/RDPDR required, load them */ if (guac_client_data->settings.printing_enabled || guac_client_data->settings.drive_enabled || guac_client_data->settings.audio_enabled) { @@ -330,7 +321,16 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) { if (freerdp_channels_load_plugin(channels, instance->settings, "guacdr", client)) guac_client_log(client, GUAC_LOG_WARNING, - "Failed to load guacdr plugin. Drive redirection and printing will not work."); + "Failed to load guacdr plugin. Drive redirection and " + "printing will not work. Sound MAY not work."); + + /* Load RDPSND plugin */ + if (freerdp_channels_load_plugin(channels, instance->settings, + "guacsnd", client)) + guac_client_log(client, GUAC_LOG_WARNING, + "Failed to load guacsnd alongside guacdr plugin. Sound " + "will not work. Drive redirection and printing MAY not " + "work."); } diff --git a/src/protocols/rdp/guac_rdpsnd/rdpsnd_messages.c b/src/protocols/rdp/guac_rdpsnd/rdpsnd_messages.c index 7bb2e541..09817c39 100644 --- a/src/protocols/rdp/guac_rdpsnd/rdpsnd_messages.c +++ b/src/protocols/rdp/guac_rdpsnd/rdpsnd_messages.c @@ -92,75 +92,86 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd, Stream_Write_UINT16(output_stream, 6); Stream_Write_UINT8(output_stream, 0); - /* Check each server format, respond if supported */ - for (i=0; i < server_format_count; i++) { + /* Check each server format, respond if supported and audio is enabled */ + if (audio != NULL) { + for (i=0; i < server_format_count; i++) { - unsigned char* format_start; + unsigned char* format_start; - int format_tag; - int channels; - int rate; - int bps; - int body_size; + int format_tag; + int channels; + int rate; + int bps; + int body_size; - /* Remember position in stream */ - Stream_GetPointer(input_stream, format_start); + /* Remember position in stream */ + Stream_GetPointer(input_stream, format_start); - /* Read format */ - Stream_Read_UINT16(input_stream, format_tag); - Stream_Read_UINT16(input_stream, channels); - Stream_Read_UINT32(input_stream, rate); - Stream_Seek_UINT32(input_stream); - Stream_Seek_UINT16(input_stream); - Stream_Read_UINT16(input_stream, bps); + /* Read format */ + Stream_Read_UINT16(input_stream, format_tag); + Stream_Read_UINT16(input_stream, channels); + Stream_Read_UINT32(input_stream, rate); + Stream_Seek_UINT32(input_stream); + Stream_Seek_UINT16(input_stream); + Stream_Read_UINT16(input_stream, bps); - /* Skip past extra data */ - Stream_Read_UINT16(input_stream, body_size); - Stream_Seek(input_stream, body_size); + /* Skip past extra data */ + Stream_Read_UINT16(input_stream, body_size); + Stream_Seek(input_stream, body_size); - /* If PCM, accept */ - if (format_tag == WAVE_FORMAT_PCM) { + /* If PCM, accept */ + if (format_tag == WAVE_FORMAT_PCM) { - /* If can fit another format, accept it */ - if (rdpsnd->format_count < GUAC_RDP_MAX_FORMATS) { + /* If can fit another format, accept it */ + if (rdpsnd->format_count < GUAC_RDP_MAX_FORMATS) { - /* Add channel */ - int current = rdpsnd->format_count++; - rdpsnd->formats[current].rate = rate; - rdpsnd->formats[current].channels = channels; - rdpsnd->formats[current].bps = bps; + /* Add channel */ + int current = rdpsnd->format_count++; + rdpsnd->formats[current].rate = rate; + rdpsnd->formats[current].channels = channels; + rdpsnd->formats[current].bps = bps; - /* Log format */ - guac_client_log(client, GUAC_LOG_INFO, - "Accepted format: %i-bit PCM with %i channels at " - "%i Hz", - bps, channels, rate); + /* Log format */ + guac_client_log(client, GUAC_LOG_INFO, + "Accepted format: %i-bit PCM with %i channels at " + "%i Hz", + bps, channels, rate); - /* Ensure audio stream is configured to use accepted format */ - guac_audio_stream_reset(audio, NULL, rate, channels, bps); + /* Ensure audio stream is configured to use accepted + * format */ + guac_audio_stream_reset(audio, NULL, rate, channels, bps); - /* Queue format for sending as accepted */ - Stream_EnsureRemainingCapacity(output_stream, 18 + body_size); - Stream_Write(output_stream, format_start, 18 + body_size); + /* Queue format for sending as accepted */ + Stream_EnsureRemainingCapacity(output_stream, + 18 + body_size); + Stream_Write(output_stream, format_start, 18 + body_size); - /* - * BEWARE that using Stream_EnsureRemainingCapacity means that any - * pointers returned via Stream_GetPointer on output_stream are invalid. - */ + /* + * BEWARE that using Stream_EnsureRemainingCapacity means + * that any pointers returned via Stream_GetPointer on + * output_stream are invalid. + */ + + } + + /* Otherwise, log that we dropped one */ + else + guac_client_log(client, GUAC_LOG_INFO, + "Dropped valid format: %i-bit PCM with %i " + "channels at %i Hz", + bps, channels, rate); } - /* Otherwise, log that we dropped one */ - else - guac_client_log(client, GUAC_LOG_INFO, - "Dropped valid format: %i-bit PCM with %i channels at " - "%i Hz", - bps, channels, rate); - } - } + /* Otherwise, ignore all supported formats as we do not intend to actually + * receive audio */ + else + guac_client_log(client, GUAC_LOG_DEBUG, + "Audio explicitly disabled. Ignoring supported formats."); + /* Calculate size of PDU */ output_body_size = Stream_GetPosition(output_stream) - 4; Stream_GetPointer(output_stream, output_stream_end); @@ -257,10 +268,11 @@ void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd, rdpsnd->next_pdu_is_wave = TRUE; /* Reset audio stream if format has changed */ - guac_audio_stream_reset(audio, NULL, - rdpsnd->formats[format].rate, - rdpsnd->formats[format].channels, - rdpsnd->formats[format].bps); + if (audio != NULL) + guac_audio_stream_reset(audio, NULL, + rdpsnd->formats[format].rate, + rdpsnd->formats[format].channels, + rdpsnd->formats[format].bps); } @@ -286,8 +298,11 @@ void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd, memcpy(buffer, rdpsnd->initial_wave_data, 4); /* Write rest of audio packet */ - guac_audio_stream_write_pcm(audio, buffer, rdpsnd->incoming_wave_size + 4); - guac_audio_stream_flush(audio); + if (audio != NULL) { + guac_audio_stream_write_pcm(audio, buffer, + rdpsnd->incoming_wave_size + 4); + guac_audio_stream_flush(audio); + } /* Write Wave Confirmation PDU */ Stream_Write_UINT8(output_stream, SNDC_WAVECONFIRM);