GUAC-1196: Load RDPSND if RDPDR is loaded, but do not actually handle audio unless enabled.

This commit is contained in:
Michael Jumper 2015-11-02 16:54:37 -08:00
parent 0dddf47af0
commit c3e2754ec4
2 changed files with 85 additions and 70 deletions

View File

@ -291,17 +291,8 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) {
GUAC_RDP_AUDIO_CHANNELS, GUAC_RDP_AUDIO_CHANNELS,
GUAC_RDP_AUDIO_BPS); GUAC_RDP_AUDIO_BPS);
/* If an encoding is available, load the sound plugin */ /* Warn if no audio encoding is available */
if (guac_client_data->audio != NULL) { 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
guac_client_log(client, GUAC_LOG_INFO, guac_client_log(client, GUAC_LOG_INFO,
"No available audio encoding. Sound disabled."); "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 if (guac_client_data->settings.printing_enabled
|| guac_client_data->settings.drive_enabled || guac_client_data->settings.drive_enabled
|| guac_client_data->settings.audio_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, if (freerdp_channels_load_plugin(channels, instance->settings,
"guacdr", client)) "guacdr", client))
guac_client_log(client, GUAC_LOG_WARNING, 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.");
} }

View File

@ -92,7 +92,8 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
Stream_Write_UINT16(output_stream, 6); Stream_Write_UINT16(output_stream, 6);
Stream_Write_UINT8(output_stream, 0); Stream_Write_UINT8(output_stream, 0);
/* Check each server format, respond if supported */ /* Check each server format, respond if supported and audio is enabled */
if (audio != NULL) {
for (i=0; i < server_format_count; i++) { for (i=0; i < server_format_count; i++) {
unsigned char* format_start; unsigned char* format_start;
@ -136,16 +137,19 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
"%i Hz", "%i Hz",
bps, channels, rate); bps, channels, rate);
/* Ensure audio stream is configured to use accepted format */ /* Ensure audio stream is configured to use accepted
* format */
guac_audio_stream_reset(audio, NULL, rate, channels, bps); guac_audio_stream_reset(audio, NULL, rate, channels, bps);
/* Queue format for sending as accepted */ /* Queue format for sending as accepted */
Stream_EnsureRemainingCapacity(output_stream, 18 + body_size); Stream_EnsureRemainingCapacity(output_stream,
18 + body_size);
Stream_Write(output_stream, format_start, 18 + body_size); Stream_Write(output_stream, format_start, 18 + body_size);
/* /*
* BEWARE that using Stream_EnsureRemainingCapacity means that any * BEWARE that using Stream_EnsureRemainingCapacity means
* pointers returned via Stream_GetPointer on output_stream are invalid. * that any pointers returned via Stream_GetPointer on
* output_stream are invalid.
*/ */
} }
@ -153,13 +157,20 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
/* Otherwise, log that we dropped one */ /* Otherwise, log that we dropped one */
else else
guac_client_log(client, GUAC_LOG_INFO, guac_client_log(client, GUAC_LOG_INFO,
"Dropped valid format: %i-bit PCM with %i channels at " "Dropped valid format: %i-bit PCM with %i "
"%i Hz", "channels at %i Hz",
bps, channels, rate); 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 */ /* Calculate size of PDU */
output_body_size = Stream_GetPosition(output_stream) - 4; output_body_size = Stream_GetPosition(output_stream) - 4;
@ -257,6 +268,7 @@ void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd,
rdpsnd->next_pdu_is_wave = TRUE; rdpsnd->next_pdu_is_wave = TRUE;
/* Reset audio stream if format has changed */ /* Reset audio stream if format has changed */
if (audio != NULL)
guac_audio_stream_reset(audio, NULL, guac_audio_stream_reset(audio, NULL,
rdpsnd->formats[format].rate, rdpsnd->formats[format].rate,
rdpsnd->formats[format].channels, rdpsnd->formats[format].channels,
@ -286,8 +298,11 @@ void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd,
memcpy(buffer, rdpsnd->initial_wave_data, 4); memcpy(buffer, rdpsnd->initial_wave_data, 4);
/* Write rest of audio packet */ /* Write rest of audio packet */
guac_audio_stream_write_pcm(audio, buffer, rdpsnd->incoming_wave_size + 4); if (audio != NULL) {
guac_audio_stream_write_pcm(audio, buffer,
rdpsnd->incoming_wave_size + 4);
guac_audio_stream_flush(audio); guac_audio_stream_flush(audio);
}
/* Write Wave Confirmation PDU */ /* Write Wave Confirmation PDU */
Stream_Write_UINT8(output_stream, SNDC_WAVECONFIRM); Stream_Write_UINT8(output_stream, SNDC_WAVECONFIRM);