Refactored audio API.

This commit is contained in:
Michael Jumper 2012-10-29 10:51:56 -07:00
parent bcde14d270
commit 7346817669
3 changed files with 33 additions and 16 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;
}