Remove hard-coded values.

This commit is contained in:
Michael Jumper 2012-10-31 17:44:23 -07:00
parent 9207d7c89e
commit c5e4dcabf2
5 changed files with 69 additions and 17 deletions

View File

@ -97,21 +97,43 @@ void guac_rdpsnd_process_message_formats(guac_rdpsndPlugin* rdpsnd,
if (format->wFormatTag == WAVE_FORMAT_PCM) {
guac_client_log_info(audio->client,
"Accepted format: %i-bit PCM with %i channels at "
"%i Hz",
format->wBitsPerSample,
format->nChannels,
format->nSamplesPerSec);
/* If can fit another format, accept it */
if (rdpsnd->format_count < GUAC_RDP_MAX_FORMATS) {
/* Add channel */
int current = rdpsnd->format_count++;
rdpsnd->formats[current].rate = format->nSamplesPerSec;
rdpsnd->formats[current].channels = format->nChannels;
rdpsnd->formats[current].bps = format->wBitsPerSample;
/* Log format */
guac_client_log_info(audio->client,
"Accepted format: %i-bit PCM with %i channels at "
"%i Hz",
format->wBitsPerSample,
format->nChannels,
format->nSamplesPerSec);
/* Store as accepted for future response */
stream_check_size(output_stream, 18 + format->cbSize);
stream_write(output_stream, format_mark, 18 + format->cbSize);
if (format->cbSize > 0) {
format->data = xmalloc(format->cbSize);
memcpy(format->data, data_mark, format->cbSize);
}
n_out_formats++;
}
/* Otherwise, log that we dropped one */
else
guac_client_log_info(audio->client,
"Dropped valid format: %i-bit PCM with %i channels at "
"%i Hz",
format->wBitsPerSample,
format->nChannels,
format->nSamplesPerSec);
stream_check_size(output_stream, 18 + format->cbSize);
stream_write(output_stream, format_mark, 18 + format->cbSize);
if (format->cbSize > 0)
{
format->data = xmalloc(format->cbSize);
memcpy(format->data, data_mark, format->cbSize);
}
n_out_formats++;
}
}
@ -181,7 +203,11 @@ 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 */
/* Init stream with requested format */
audio_stream_begin(audio,
rdpsnd->formats[wFormatNo].rate,
rdpsnd->formats[wFormatNo].channels,
rdpsnd->formats[wFormatNo].bps);
}

View File

@ -20,6 +20,21 @@
#ifndef __GUAC_RDPSND_SERVICE_H
#define __GUAC_RDPSND_SERVICE_H
#define GUAC_RDP_MAX_FORMATS 16
typedef struct guac_pcm_format {
int rate;
int channels;
int bps;
} guac_pcm_format;
typedef struct guac_rdpsndPlugin {
rdpSvcPlugin plugin;
@ -31,7 +46,11 @@ typedef struct guac_rdpsndPlugin {
uint16 waveDataSize;
uint32 wTimeStamp; /* server timestamp */
} guac_rdpsndPlugin ;
guac_pcm_format formats[GUAC_RDP_MAX_FORMATS];
int format_count;
} guac_rdpsndPlugin;
void guac_rdpsnd_process_connect(rdpSvcPlugin* plugin);

View File

@ -64,6 +64,12 @@ typedef void audio_encoder_write_handler(audio_stream* audio,
*/
typedef struct audio_encoder {
/**
* The mimetype of the audio data encoded by this audio
* encoder.
*/
const char* mimetype;
/**
* Handler which will be called when the audio stream is opened.
*/

View File

@ -103,7 +103,7 @@ void audio_stream_end(audio_stream* audio) {
/* Send audio */
guac_protocol_send_audio(audio->stream->socket,
0, "audio/ogg" /* FIXME: Hard-coded mimetype */,
0, audio->encoder->mimetype,
duration, audio->encoded_data, audio->encoded_data_used);
pthread_mutex_unlock(&(data->update_lock));

View File

@ -200,6 +200,7 @@ void ogg_encoder_write_handler(audio_stream* audio,
/* Encoder handlers */
audio_encoder _ogg_encoder = {
.mimetype = "audio/ogg",
.begin_handler = ogg_encoder_begin_handler,
.write_handler = ogg_encoder_write_handler,
.end_handler = ogg_encoder_end_handler