GUACAMOLE-25: Store input and output audio format.
This commit is contained in:
parent
320f564daf
commit
533a47f06d
@ -118,7 +118,7 @@ static int guac_rdp_audio_parse_mimetype(const char* mimetype,
|
||||
} while (mimetype != NULL);
|
||||
|
||||
/* Mimetype is invalid if rate was not specified */
|
||||
if (rate == -1)
|
||||
if (parsed_rate == -1)
|
||||
return 1;
|
||||
|
||||
/* Parse success */
|
||||
@ -142,25 +142,20 @@ int guac_rdp_audio_handler(guac_user* user, guac_stream* stream,
|
||||
|
||||
/* Parse mimetype, abort on parse error */
|
||||
if (guac_rdp_audio_parse_mimetype(mimetype, &rate, &channels, &bps)) {
|
||||
guac_user_log(user, GUAC_LOG_WARN, "Denying user audio stream with "
|
||||
guac_user_log(user, GUAC_LOG_WARNING, "Denying user audio stream with "
|
||||
"unsupported mimetype: \"%s\"", mimetype);
|
||||
guac_protocol_send_ack(user->socket, stream, "Unsupported audio "
|
||||
"mimetype", GUAC_PROTOCOL_STATUS_CLIENT_BAD_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: Assuming mimetype of "audio/L16;rate=44100,channels=2" */
|
||||
else {
|
||||
guac_user_log(user, GUAC_LOG_DEBUG, "rate=%i, channels=%i, bps=%i",
|
||||
rate, channels, bps);
|
||||
}
|
||||
|
||||
/* Init stream data */
|
||||
stream->blob_handler = guac_rdp_audio_blob_handler;
|
||||
stream->end_handler = guac_rdp_audio_end_handler;
|
||||
|
||||
/* Associate stream with audio buffer */
|
||||
guac_rdp_audio_buffer_set_stream(rdp_client->audio_input, user, stream);
|
||||
guac_rdp_audio_buffer_set_stream(rdp_client->audio_input, user, stream,
|
||||
rate, channels, bps);
|
||||
|
||||
return 0;
|
||||
|
||||
@ -240,13 +235,16 @@ static void guac_rdp_audio_buffer_ack(guac_rdp_audio_buffer* audio_buffer,
|
||||
}
|
||||
|
||||
void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
|
||||
guac_user* user, guac_stream* stream) {
|
||||
guac_user* user, guac_stream* stream, int rate, int channels, int bps) {
|
||||
|
||||
pthread_mutex_lock(&(audio_buffer->lock));
|
||||
|
||||
/* Associate received stream */
|
||||
audio_buffer->user = user;
|
||||
audio_buffer->stream = stream;
|
||||
audio_buffer->in_rate = rate;
|
||||
audio_buffer->in_channels = channels;
|
||||
audio_buffer->in_bps = bps;
|
||||
|
||||
/* Acknowledge stream creation (if buffer is ready to receive) */
|
||||
guac_rdp_audio_buffer_ack(audio_buffer,
|
||||
@ -257,13 +255,16 @@ void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
|
||||
}
|
||||
|
||||
void guac_rdp_audio_buffer_begin(guac_rdp_audio_buffer* audio_buffer,
|
||||
int packet_size, guac_rdp_audio_buffer_flush_handler* flush_handler,
|
||||
void* data) {
|
||||
int rate, int channels, int bps, int packet_size,
|
||||
guac_rdp_audio_buffer_flush_handler* flush_handler, void* data) {
|
||||
|
||||
pthread_mutex_lock(&(audio_buffer->lock));
|
||||
|
||||
/* Reset buffer state to provided values */
|
||||
audio_buffer->bytes_written = 0;
|
||||
audio_buffer->out_rate = rate;
|
||||
audio_buffer->out_channels = channels;
|
||||
audio_buffer->out_bps = bps;
|
||||
audio_buffer->packet_size = packet_size;
|
||||
audio_buffer->flush_handler = flush_handler;
|
||||
audio_buffer->data = data;
|
||||
@ -285,6 +286,8 @@ void guac_rdp_audio_buffer_write(guac_rdp_audio_buffer* audio_buffer,
|
||||
|
||||
pthread_mutex_lock(&(audio_buffer->lock));
|
||||
|
||||
/* FIXME: Assuming mimetype of "audio/L16;rate=44100,channels=2" */
|
||||
|
||||
/* Ignore packet if there is no buffer */
|
||||
if (audio_buffer->packet_size == 0 || audio_buffer->packet == NULL) {
|
||||
pthread_mutex_unlock(&(audio_buffer->lock));
|
||||
|
@ -73,6 +73,45 @@ typedef struct guac_rdp_audio_buffer {
|
||||
*/
|
||||
guac_stream* stream;
|
||||
|
||||
/**
|
||||
* The rate of the audio stream being received from the user, if any, in
|
||||
* samples per second. If no stream is yet associated, this value is
|
||||
* undefined.
|
||||
*/
|
||||
int in_rate;
|
||||
|
||||
/**
|
||||
* The number of channels included in the audio stream being received from
|
||||
* the user, if any. If no stream is yet associated, this value is
|
||||
* undefined.
|
||||
*/
|
||||
int in_channels;
|
||||
|
||||
/**
|
||||
* The size of each sample within the audio stream being received from the
|
||||
* user, if any, in bytes. If no stream is yet associated, this value is
|
||||
* undefined.
|
||||
*/
|
||||
int in_bps;
|
||||
|
||||
/**
|
||||
* The rate of the audio stream expected by RDP, if any, in samples per
|
||||
* second. If no stream is yet associated, this value is undefined.
|
||||
*/
|
||||
int out_rate;
|
||||
|
||||
/**
|
||||
* The number of channels included in the audio stream expected by RDP, if
|
||||
* any. If no stream is yet associated, this value is undefined.
|
||||
*/
|
||||
int out_channels;
|
||||
|
||||
/**
|
||||
* The size of each sample within the audio stream expected by RDP, if any,
|
||||
* in bytes. If no stream is yet associated, this value is undefined.
|
||||
*/
|
||||
int out_bps;
|
||||
|
||||
/**
|
||||
* The size that each audio packet must be, in bytes. The packet buffer
|
||||
* within this structure will be at least this size.
|
||||
@ -127,9 +166,21 @@ guac_rdp_audio_buffer* guac_rdp_audio_buffer_alloc();
|
||||
*
|
||||
* @param stream
|
||||
* The guac_stream object representing the audio stream.
|
||||
*
|
||||
* @param rate
|
||||
* The rate of the audio stream being received from the user, if any, in
|
||||
* samples per second.
|
||||
*
|
||||
* @param channels
|
||||
* The number of channels included in the audio stream being received from
|
||||
* the user, if any.
|
||||
*
|
||||
* @param bps
|
||||
* The size of each sample within the audio stream being received from the
|
||||
* user, if any, in bytes.
|
||||
*/
|
||||
void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
|
||||
guac_user* user, guac_stream* stream);
|
||||
guac_user* user, guac_stream* stream, int rate, int channels, int bps);
|
||||
|
||||
/**
|
||||
* Begins handling of audio data received via guac_rdp_audio_buffer_write() and
|
||||
@ -140,6 +191,18 @@ void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
|
||||
* @param audio_buffer
|
||||
* The audio buffer to begin.
|
||||
*
|
||||
* @param rate
|
||||
* The rate of the audio stream expected by RDP, if any, in samples per
|
||||
* second.
|
||||
*
|
||||
* @param channels
|
||||
* The number of channels included in the audio stream expected by RDP, if
|
||||
* any.
|
||||
*
|
||||
* @param bps
|
||||
* The size of each sample within the audio stream expected by RDP, if any,
|
||||
* in bytes.
|
||||
*
|
||||
* @param packet_size
|
||||
* The number of bytes to include in all audio packets provided to the
|
||||
* given flush_handler.
|
||||
@ -152,8 +215,8 @@ void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
|
||||
* needs to be flushed.
|
||||
*/
|
||||
void guac_rdp_audio_buffer_begin(guac_rdp_audio_buffer* audio_buffer,
|
||||
int packet_size, guac_rdp_audio_buffer_flush_handler* flush_handler,
|
||||
void* data);
|
||||
int rate, int channels, int bps, int packet_size,
|
||||
guac_rdp_audio_buffer_flush_handler* flush_handler, void* data);
|
||||
|
||||
/**
|
||||
* Writes the given buffer of audio data to the given audio buffer. A new
|
||||
|
@ -312,7 +312,7 @@ void guac_rdp_ai_process_open(guac_client* client,
|
||||
|
||||
/* FIXME: Assuming mimetype of 16-bit 44100 Hz stereo PCM */
|
||||
guac_rdp_audio_buffer_begin(audio_buffer, packet_frames * 2 * 2,
|
||||
guac_rdp_ai_flush_packet, channel);
|
||||
44100, 2, 2, guac_rdp_ai_flush_packet, channel);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user