From 65752f689c7e9f02d731f6c28e0e8564622ce054 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 29 Oct 2012 11:12:49 -0700 Subject: [PATCH] Actually send audio messages. --- protocols/rdp/guac_rdpsnd/messages.c | 2 -- protocols/rdp/include/audio.h | 5 +++++ protocols/rdp/src/audio.c | 21 ++++++++++++++++++++- protocols/rdp/src/guac_handlers.c | 4 ++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/protocols/rdp/guac_rdpsnd/messages.c b/protocols/rdp/guac_rdpsnd/messages.c index c4eb0651..decc5a54 100644 --- a/protocols/rdp/guac_rdpsnd/messages.c +++ b/protocols/rdp/guac_rdpsnd/messages.c @@ -206,8 +206,6 @@ void rdpsnd_process_message_wave(guac_rdpsndPlugin* rdpsnd, buffer = stream_get_head(input_stream); size = stream_get_size(input_stream); - guac_client_log_info(audio->client, "Got sound: %i bytes.", size); - /* Write rest of audio packet */ audio_stream_write_pcm(audio, buffer, size); audio_stream_end(audio); diff --git a/protocols/rdp/include/audio.h b/protocols/rdp/include/audio.h index fb441f2a..61f537f7 100644 --- a/protocols/rdp/include/audio.h +++ b/protocols/rdp/include/audio.h @@ -151,6 +151,11 @@ struct audio_stream { */ int bps; + /** + * The number of PCM bytes written since the audio chunk began. + */ + int pcm_bytes_written; + /** * Encoder-specific state data. */ diff --git a/protocols/rdp/src/audio.c b/protocols/rdp/src/audio.c index 74d6f723..e27fe50d 100644 --- a/protocols/rdp/src/audio.c +++ b/protocols/rdp/src/audio.c @@ -56,7 +56,7 @@ audio_stream* audio_stream_alloc(guac_client* client, audio_encoder* encoder) { audio->encoded_data_used = 0; audio->encoded_data_length = 0x40000; - /* Allocate bufferis */ + /* Allocate buffers */ audio->pcm_data = malloc(audio->length); audio->encoded_data = malloc(audio->encoded_data_length); @@ -74,14 +74,30 @@ void audio_stream_begin(audio_stream* audio, int rate, int channels, int bps) { audio->channels = channels; audio->bps = bps; + /* Reset write counter */ + audio->pcm_bytes_written = 0; + /* Call handler */ audio->encoder->begin_handler(audio); } void audio_stream_end(audio_stream* audio) { + + /* Calculate duration of PCM data */ + int duration = + audio->pcm_bytes_written * 1000 * 8 / audio->rate + / audio->channels / audio->bps; + + /* Flush stream and finish encoding */ audio_stream_flush(audio); audio->encoder->end_handler(audio); + + /* Send audio */ + guac_protocol_send_audio(audio->stream->socket, + 0, "audio/ogg" /* FIXME: Hard-coded mimetype */, + duration, audio->encoded_data, audio->encoded_data_used); + } void audio_stream_free(audio_stream* audio) { @@ -92,6 +108,9 @@ void audio_stream_free(audio_stream* audio) { void audio_stream_write_pcm(audio_stream* audio, unsigned char* data, int length) { + /* Update counter */ + audio->pcm_bytes_written += length; + /* Resize audio buffer if necessary */ if (length > audio->length) { diff --git a/protocols/rdp/src/guac_handlers.c b/protocols/rdp/src/guac_handlers.c index f0b6e888..9638bb00 100644 --- a/protocols/rdp/src/guac_handlers.c +++ b/protocols/rdp/src/guac_handlers.c @@ -200,6 +200,10 @@ int rdp_guac_client_handle_messages(guac_client* client) { return 1; } + /* Flush any audio */ + if (guac_client_data->audio != NULL) + guac_socket_flush(guac_client_data->audio->stream->socket); + /* Success */ return 0;