Actually send audio messages.

This commit is contained in:
Michael Jumper 2012-10-29 11:12:49 -07:00
parent 4daa2123ba
commit 65752f689c
4 changed files with 29 additions and 3 deletions

View File

@ -206,8 +206,6 @@ void rdpsnd_process_message_wave(guac_rdpsndPlugin* rdpsnd,
buffer = stream_get_head(input_stream); buffer = stream_get_head(input_stream);
size = stream_get_size(input_stream); size = stream_get_size(input_stream);
guac_client_log_info(audio->client, "Got sound: %i bytes.", size);
/* Write rest of audio packet */ /* Write rest of audio packet */
audio_stream_write_pcm(audio, buffer, size); audio_stream_write_pcm(audio, buffer, size);
audio_stream_end(audio); audio_stream_end(audio);

View File

@ -151,6 +151,11 @@ struct audio_stream {
*/ */
int bps; int bps;
/**
* The number of PCM bytes written since the audio chunk began.
*/
int pcm_bytes_written;
/** /**
* Encoder-specific state data. * Encoder-specific state data.
*/ */

View File

@ -56,7 +56,7 @@ audio_stream* audio_stream_alloc(guac_client* client, audio_encoder* encoder) {
audio->encoded_data_used = 0; audio->encoded_data_used = 0;
audio->encoded_data_length = 0x40000; audio->encoded_data_length = 0x40000;
/* Allocate bufferis */ /* Allocate buffers */
audio->pcm_data = malloc(audio->length); audio->pcm_data = malloc(audio->length);
audio->encoded_data = malloc(audio->encoded_data_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->channels = channels;
audio->bps = bps; audio->bps = bps;
/* Reset write counter */
audio->pcm_bytes_written = 0;
/* Call handler */ /* Call handler */
audio->encoder->begin_handler(audio); audio->encoder->begin_handler(audio);
} }
void audio_stream_end(audio_stream* 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_stream_flush(audio);
audio->encoder->end_handler(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) { 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, void audio_stream_write_pcm(audio_stream* audio,
unsigned char* data, int length) { unsigned char* data, int length) {
/* Update counter */
audio->pcm_bytes_written += length;
/* Resize audio buffer if necessary */ /* Resize audio buffer if necessary */
if (length > audio->length) { if (length > audio->length) {

View File

@ -200,6 +200,10 @@ int rdp_guac_client_handle_messages(guac_client* client) {
return 1; return 1;
} }
/* Flush any audio */
if (guac_client_data->audio != NULL)
guac_socket_flush(guac_client_data->audio->stream->socket);
/* Success */ /* Success */
return 0; return 0;