From cf16398927a23339bcfe72d7b74820793933d0b7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 29 Oct 2012 23:11:33 -0700 Subject: [PATCH] Fix bytes-written calculation. --- protocols/rdp/guac_rdpsnd/messages.c | 14 +++----------- protocols/rdp/src/audio.c | 10 ++++++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/protocols/rdp/guac_rdpsnd/messages.c b/protocols/rdp/guac_rdpsnd/messages.c index decc5a54..34af38fd 100644 --- a/protocols/rdp/guac_rdpsnd/messages.c +++ b/protocols/rdp/guac_rdpsnd/messages.c @@ -182,7 +182,6 @@ void guac_rdpsnd_process_message_wave_info(guac_rdpsndPlugin* rdpsnd, audio_stre rdpsnd->expectingWave = true; audio_stream_begin(audio, 22050, 2, 16); /* FIXME: Hard-coding rates */ - audio_stream_write_pcm(audio, rdpsnd->waveData, 4); } @@ -194,20 +193,13 @@ void rdpsnd_process_message_wave(guac_rdpsndPlugin* rdpsnd, STREAM* output_stream; - int size; - unsigned char* buffer; + unsigned char* buffer = stream_get_head(input_stream); rdpsnd->expectingWave = 0; - memcpy(stream_get_head(input_stream), rdpsnd->waveData, 4); - if (stream_get_size(input_stream) != rdpsnd->waveDataSize) { - return; - } - - buffer = stream_get_head(input_stream); - size = stream_get_size(input_stream); + memcpy(buffer, rdpsnd->waveData, 4); /* Write rest of audio packet */ - audio_stream_write_pcm(audio, buffer, size); + audio_stream_write_pcm(audio, buffer, rdpsnd->waveDataSize); audio_stream_end(audio); output_stream = stream_new(8); diff --git a/protocols/rdp/src/audio.c b/protocols/rdp/src/audio.c index cc529584..a4815f37 100644 --- a/protocols/rdp/src/audio.c +++ b/protocols/rdp/src/audio.c @@ -84,15 +84,17 @@ void audio_stream_begin(audio_stream* audio, int rate, int channels, int bps) { 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; + int duration; /* Flush stream and finish encoding */ audio_stream_flush(audio); audio->encoder->end_handler(audio); + /* Calculate duration of PCM data */ + duration = + audio->pcm_bytes_written * 1000 * 8 / audio->rate + / audio->channels / audio->bps; + /* Send audio */ guac_protocol_send_audio(audio->stream->socket, 0, "audio/ogg" /* FIXME: Hard-coded mimetype */,