From 73468176691dd0956f5e8c5bd359326ebdcabcfd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 29 Oct 2012 10:51:56 -0700 Subject: [PATCH] Refactored audio API. --- protocols/rdp/guac_rdpsnd/messages.c | 6 ++++-- protocols/rdp/include/audio.h | 27 +++++++++++++++++++-------- protocols/rdp/src/audio.c | 16 ++++++++++------ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/protocols/rdp/guac_rdpsnd/messages.c b/protocols/rdp/guac_rdpsnd/messages.c index d8d595d5..c4eb0651 100644 --- a/protocols/rdp/guac_rdpsnd/messages.c +++ b/protocols/rdp/guac_rdpsnd/messages.c @@ -181,6 +181,9 @@ void guac_rdpsnd_process_message_wave_info(guac_rdpsndPlugin* rdpsnd, audio_stre rdpsnd->waveDataSize = BodySize - 8; rdpsnd->expectingWave = true; + audio_stream_begin(audio, 22050, 2, 16); /* FIXME: Hard-coding rates */ + audio_stream_write_pcm(audio, rdpsnd->waveData, 4); + } /* header is not removed from data in this function */ @@ -205,8 +208,7 @@ void rdpsnd_process_message_wave(guac_rdpsndPlugin* rdpsnd, guac_client_log_info(audio->client, "Got sound: %i bytes.", size); - /* For now, start AND end stream right here */ - audio_stream_begin(audio); + /* 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 dfa2e47c..d5dd8eb1 100644 --- a/protocols/rdp/include/audio.h +++ b/protocols/rdp/include/audio.h @@ -134,6 +134,23 @@ struct audio_stream { */ guac_stream* stream; + /** + * The number of samples per second of PCM data sent to this stream. + */ + int rate; + + /** + * The number of audio channels per sample of PCM data. Legal values are + * 1 or 2. + */ + int channels; + + /** + * The number of bits per sample per channel for PCM data. Legal values are + * 8 or 16. + */ + int bps; + }; /** @@ -150,7 +167,7 @@ void audio_stream_free(audio_stream* stream); /** * Begins a new audio stream. */ -void audio_stream_begin(audio_stream* stream); +void audio_stream_begin(audio_stream* stream, int rate, int channels, int bps); /** * Ends the current audio stream. @@ -172,14 +189,8 @@ void audio_stream_flush(audio_stream* stream); * Appends arbitrarily-encoded data to the encoded_data buffer * within the given audio stream. */ -void audio_stream_append_data(audio_stream* stream, +void audio_stream_write_encoded(audio_stream* audio, unsigned char* data, int length); -/** - * Clears all data from the encoded_data buffer in the given - * audio stream. - */ -void audio_stream_clear_data(audio_stream* stream); - #endif diff --git a/protocols/rdp/src/audio.c b/protocols/rdp/src/audio.c index 131c1ca4..74d6f723 100644 --- a/protocols/rdp/src/audio.c +++ b/protocols/rdp/src/audio.c @@ -67,8 +67,16 @@ audio_stream* audio_stream_alloc(guac_client* client, audio_encoder* encoder) { return audio; } -void audio_stream_begin(audio_stream* audio) { +void audio_stream_begin(audio_stream* audio, int rate, int channels, int bps) { + + /* Load PCM properties */ + audio->rate = rate; + audio->channels = channels; + audio->bps = bps; + + /* Call handler */ audio->encoder->begin_handler(audio); + } void audio_stream_end(audio_stream* audio) { @@ -119,7 +127,7 @@ void audio_stream_flush(audio_stream* audio) { } -void audio_stream_append_data(audio_stream* audio, +void audio_stream_write_encoded(audio_stream* audio, unsigned char* data, int length) { /* Resize audio buffer if necessary */ @@ -138,7 +146,3 @@ void audio_stream_append_data(audio_stream* audio, } -void audio_stream_clear_data(audio_stream* audio) { - audio->encoded_data_used = 0; -} -