GUAC-1196: Use guac_client to access guac_audio_stream rather than storing the audio stream directly.

This commit is contained in:
Michael Jumper 2015-11-02 15:55:52 -08:00
parent f9cc90307b
commit 0dddf47af0
5 changed files with 60 additions and 63 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Glyptodon LLC * Copyright (C) 2015 Glyptodon LLC
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -296,7 +296,7 @@ BOOL rdp_freerdp_pre_connect(freerdp* instance) {
/* Load sound plugin */ /* Load sound plugin */
if (freerdp_channels_load_plugin(channels, instance->settings, if (freerdp_channels_load_plugin(channels, instance->settings,
"guacsnd", guac_client_data->audio)) "guacsnd", client))
guac_client_log(client, GUAC_LOG_WARNING, guac_client_log(client, GUAC_LOG_WARNING,
"Failed to load guacsnd plugin. Audio will not work."); "Failed to load guacsnd plugin. Audio will not work.");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Glyptodon LLC * Copyright (C) 2015 Glyptodon LLC
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -44,8 +44,7 @@
/* MESSAGE HANDLERS */ /* MESSAGE HANDLERS */
void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header) {
guac_rdpsnd_pdu_header* header) {
int server_format_count; int server_format_count;
int server_version; int server_version;
@ -55,8 +54,12 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
int output_body_size; int output_body_size;
unsigned char* output_stream_end; unsigned char* output_stream_end;
rdp_guac_client_data* guac_client_data = /* Get associated client data */
(rdp_guac_client_data*) audio->client->data; guac_client* client = rdpsnd->client;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
/* Get audio stream from client data */
guac_audio_stream* audio = client_data->audio;
/* Format header */ /* Format header */
Stream_Seek(input_stream, 14); Stream_Seek(input_stream, 14);
@ -128,7 +131,7 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
rdpsnd->formats[current].bps = bps; rdpsnd->formats[current].bps = bps;
/* Log format */ /* Log format */
guac_client_log(audio->client, GUAC_LOG_INFO, guac_client_log(client, GUAC_LOG_INFO,
"Accepted format: %i-bit PCM with %i channels at " "Accepted format: %i-bit PCM with %i channels at "
"%i Hz", "%i Hz",
bps, channels, rate); bps, channels, rate);
@ -149,7 +152,7 @@ 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(audio->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 channels at "
"%i Hz", "%i Hz",
bps, channels, rate); bps, channels, rate);
@ -174,7 +177,7 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
Stream_SetPointer(output_stream, output_stream_end); Stream_SetPointer(output_stream, output_stream_end);
/* Send accepted formats */ /* Send accepted formats */
pthread_mutex_lock(&(guac_client_data->rdp_lock)); pthread_mutex_lock(&(client_data->rdp_lock));
svc_plugin_send((rdpSvcPlugin*)rdpsnd, output_stream); svc_plugin_send((rdpSvcPlugin*)rdpsnd, output_stream);
/* If version greater than 6, must send Quality Mode PDU */ /* If version greater than 6, must send Quality Mode PDU */
@ -191,20 +194,20 @@ void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
svc_plugin_send((rdpSvcPlugin*)rdpsnd, output_stream); svc_plugin_send((rdpSvcPlugin*)rdpsnd, output_stream);
} }
pthread_mutex_unlock(&(guac_client_data->rdp_lock)); pthread_mutex_unlock(&(client_data->rdp_lock));
} }
/* server is getting a feel of the round trip time */ /* server is getting a feel of the round trip time */
void guac_rdpsnd_training_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_training_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header) {
guac_rdpsnd_pdu_header* header) {
int data_size; int data_size;
wStream* output_stream; wStream* output_stream;
rdp_guac_client_data* guac_client_data = /* Get associated client data */
(rdp_guac_client_data*) audio->client->data; guac_client* client = rdpsnd->client;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
/* Read timestamp and data size */ /* Read timestamp and data size */
Stream_Read_UINT16(input_stream, rdpsnd->server_timestamp); Stream_Read_UINT16(input_stream, rdpsnd->server_timestamp);
@ -218,18 +221,24 @@ void guac_rdpsnd_training_handler(guac_rdpsndPlugin* rdpsnd,
Stream_Write_UINT16(output_stream, rdpsnd->server_timestamp); Stream_Write_UINT16(output_stream, rdpsnd->server_timestamp);
Stream_Write_UINT16(output_stream, data_size); Stream_Write_UINT16(output_stream, data_size);
pthread_mutex_lock(&(guac_client_data->rdp_lock)); pthread_mutex_lock(&(client_data->rdp_lock));
svc_plugin_send((rdpSvcPlugin*) rdpsnd, output_stream); svc_plugin_send((rdpSvcPlugin*) rdpsnd, output_stream);
pthread_mutex_unlock(&(guac_client_data->rdp_lock)); pthread_mutex_unlock(&(client_data->rdp_lock));
} }
void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header) {
guac_rdpsnd_pdu_header* header) {
int format; int format;
/* Get associated client data */
guac_client* client = rdpsnd->client;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
/* Get audio stream from client data */
guac_audio_stream* audio = client_data->audio;
/* Read wave information */ /* Read wave information */
Stream_Read_UINT16(input_stream, rdpsnd->server_timestamp); Stream_Read_UINT16(input_stream, rdpsnd->server_timestamp);
Stream_Read_UINT16(input_stream, format); Stream_Read_UINT16(input_stream, format);
@ -256,13 +265,16 @@ void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd,
} }
void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header) {
guac_rdpsnd_pdu_header* header) {
rdpSvcPlugin* plugin = (rdpSvcPlugin*)rdpsnd; rdpSvcPlugin* plugin = (rdpSvcPlugin*)rdpsnd;
rdp_guac_client_data* guac_client_data = /* Get associated client data */
(rdp_guac_client_data*) audio->client->data; guac_client* client = rdpsnd->client;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
/* Get audio stream from client data */
guac_audio_stream* audio = client_data->audio;
/* Wave Confirmation PDU */ /* Wave Confirmation PDU */
wStream* output_stream = Stream_New(NULL, 8); wStream* output_stream = Stream_New(NULL, 8);
@ -286,9 +298,9 @@ void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd,
Stream_Write_UINT8(output_stream, 0); Stream_Write_UINT8(output_stream, 0);
/* Send Wave Confirmation PDU */ /* Send Wave Confirmation PDU */
pthread_mutex_lock(&(guac_client_data->rdp_lock)); pthread_mutex_lock(&(client_data->rdp_lock));
svc_plugin_send(plugin, output_stream); svc_plugin_send(plugin, output_stream);
pthread_mutex_unlock(&(guac_client_data->rdp_lock)); pthread_mutex_unlock(&(client_data->rdp_lock));
/* We no longer expect to receive wave data */ /* We no longer expect to receive wave data */
rdpsnd->next_pdu_is_wave = FALSE; rdpsnd->next_pdu_is_wave = FALSE;
@ -296,8 +308,7 @@ void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd,
} }
void guac_rdpsnd_close_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_close_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header) {
guac_rdpsnd_pdu_header* header) {
/* STUB: Do nothing for now */ /* STUB: Do nothing for now */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Glyptodon LLC * Copyright (C) 2015 Glyptodon LLC
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -28,8 +28,6 @@
#include "rdpsnd_service.h" #include "rdpsnd_service.h"
#include <guacamole/audio.h>
#ifdef ENABLE_WINPR #ifdef ENABLE_WINPR
#include <winpr/stream.h> #include <winpr/stream.h>
#else #else
@ -125,36 +123,31 @@ typedef struct guac_rdpsnd_pdu_header {
* Handler for the SNDC_FORMATS (Server Audio Formats and Version) PDU. * Handler for the SNDC_FORMATS (Server Audio Formats and Version) PDU.
*/ */
void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_formats_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header);
guac_rdpsnd_pdu_header* header);
/** /**
* Handler for the SNDC_TRAINING (Training) PDU. * Handler for the SNDC_TRAINING (Training) PDU.
*/ */
void guac_rdpsnd_training_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_training_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header);
guac_rdpsnd_pdu_header* header);
/** /**
* Handler for the SNDC_WAVE (WaveInfo) PDU. * Handler for the SNDC_WAVE (WaveInfo) PDU.
*/ */
void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_wave_info_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header);
guac_rdpsnd_pdu_header* header);
/** /**
* Handler for the SNDWAV (Wave) PDU which follows any WaveInfo PDU. * Handler for the SNDWAV (Wave) PDU which follows any WaveInfo PDU.
*/ */
void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_wave_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header);
guac_rdpsnd_pdu_header* header);
/** /**
* Handler for the SNDC_CLOSE (Close) PDU. * Handler for the SNDC_CLOSE (Close) PDU.
*/ */
void guac_rdpsnd_close_handler(guac_rdpsndPlugin* rdpsnd, void guac_rdpsnd_close_handler(guac_rdpsndPlugin* rdpsnd,
guac_audio_stream* audio, wStream* input_stream, wStream* input_stream, guac_rdpsnd_pdu_header* header);
guac_rdpsnd_pdu_header* header);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Glyptodon LLC * Copyright (C) 2015 Glyptodon LLC
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -30,7 +30,6 @@
#include <freerdp/constants.h> #include <freerdp/constants.h>
#include <freerdp/utils/svc_plugin.h> #include <freerdp/utils/svc_plugin.h>
#include <guacamole/audio.h>
#include <guacamole/client.h> #include <guacamole/client.h>
#ifdef ENABLE_WINPR #ifdef ENABLE_WINPR
@ -73,11 +72,11 @@ void guac_rdpsnd_process_connect(rdpSvcPlugin* plugin) {
guac_rdpsndPlugin* rdpsnd = (guac_rdpsndPlugin*) plugin; guac_rdpsndPlugin* rdpsnd = (guac_rdpsndPlugin*) plugin;
/* Get audio stream from plugin parameters */ /* Get client from plugin parameters */
guac_audio_stream* audio = rdpsnd->audio = guac_client* client = rdpsnd->client =
(guac_audio_stream*) plugin->channel_entry_points.pExtendedData; (guac_client*) plugin->channel_entry_points.pExtendedData;
/* NULL out pExtendedData so we don't lose our guac_audio_stream due to an /* NULL out pExtendedData so we don't lose our guac_client due to an
* automatic free() within libfreerdp */ * automatic free() within libfreerdp */
plugin->channel_entry_points.pExtendedData = NULL; plugin->channel_entry_points.pExtendedData = NULL;
@ -87,7 +86,7 @@ void guac_rdpsnd_process_connect(rdpSvcPlugin* plugin) {
#endif #endif
/* Log that sound has been loaded */ /* Log that sound has been loaded */
guac_client_log(audio->client, GUAC_LOG_INFO, "guacsnd connected."); guac_client_log(client, GUAC_LOG_INFO, "guacsnd connected.");
} }
@ -105,9 +104,6 @@ void guac_rdpsnd_process_receive(rdpSvcPlugin* plugin,
guac_rdpsndPlugin* rdpsnd = (guac_rdpsndPlugin*) plugin; guac_rdpsndPlugin* rdpsnd = (guac_rdpsndPlugin*) plugin;
guac_rdpsnd_pdu_header header; guac_rdpsnd_pdu_header header;
/* Get audio stream from plugin */
guac_audio_stream* audio = rdpsnd->audio;
/* Read RDPSND PDU header */ /* Read RDPSND PDU header */
Stream_Read_UINT8(input_stream, header.message_type); Stream_Read_UINT8(input_stream, header.message_type);
Stream_Seek_UINT8(input_stream); Stream_Seek_UINT8(input_stream);
@ -118,7 +114,7 @@ void guac_rdpsnd_process_receive(rdpSvcPlugin* plugin,
* ignore the header and parse as a Wave PDU. * ignore the header and parse as a Wave PDU.
*/ */
if (rdpsnd->next_pdu_is_wave) { if (rdpsnd->next_pdu_is_wave) {
guac_rdpsnd_wave_handler(rdpsnd, audio, input_stream, &header); guac_rdpsnd_wave_handler(rdpsnd, input_stream, &header);
return; return;
} }
@ -127,26 +123,22 @@ void guac_rdpsnd_process_receive(rdpSvcPlugin* plugin,
/* Server Audio Formats and Version PDU */ /* Server Audio Formats and Version PDU */
case SNDC_FORMATS: case SNDC_FORMATS:
guac_rdpsnd_formats_handler(rdpsnd, audio, guac_rdpsnd_formats_handler(rdpsnd, input_stream, &header);
input_stream, &header);
break; break;
/* Training PDU */ /* Training PDU */
case SNDC_TRAINING: case SNDC_TRAINING:
guac_rdpsnd_training_handler(rdpsnd, audio, guac_rdpsnd_training_handler(rdpsnd, input_stream, &header);
input_stream, &header);
break; break;
/* WaveInfo PDU */ /* WaveInfo PDU */
case SNDC_WAVE: case SNDC_WAVE:
guac_rdpsnd_wave_info_handler(rdpsnd, audio, guac_rdpsnd_wave_info_handler(rdpsnd, input_stream, &header);
input_stream, &header);
break; break;
/* Close PDU */ /* Close PDU */
case SNDC_CLOSE: case SNDC_CLOSE:
guac_rdpsnd_close_handler(rdpsnd, audio, guac_rdpsnd_close_handler(rdpsnd, input_stream, &header);
input_stream, &header);
break; break;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Glyptodon LLC * Copyright (C) 2015 Glyptodon LLC
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -27,7 +27,7 @@
#include "config.h" #include "config.h"
#include <freerdp/utils/svc_plugin.h> #include <freerdp/utils/svc_plugin.h>
#include <guacamole/audio.h> #include <guacamole/client.h>
#ifdef ENABLE_WINPR #ifdef ENABLE_WINPR
#include <winpr/stream.h> #include <winpr/stream.h>
@ -80,9 +80,10 @@ typedef struct guac_rdpsndPlugin {
rdpSvcPlugin plugin; rdpSvcPlugin plugin;
/** /**
* The current audio stream. * The Guacamole client associated with the guac_audio_stream that this
* plugin should use to stream received audio packets.
*/ */
guac_audio_stream* audio; guac_client* client;
/** /**
* The block number of the last SNDC_WAVE (WaveInfo) PDU received. * The block number of the last SNDC_WAVE (WaveInfo) PDU received.