GUACAMOLE-934: Handle potential lack of available audio streams.

This commit is contained in:
Michael Jumper 2020-01-20 21:16:36 -08:00
parent ddc09b161a
commit b8148b0daf
5 changed files with 28 additions and 4 deletions

View File

@ -117,6 +117,12 @@ guac_audio_stream* guac_audio_stream_alloc(guac_client* client,
audio->client = client;
audio->stream = guac_client_alloc_stream(client);
/* Abort allocation if underlying stream cannot be allocated */
if (audio->stream == NULL) {
free(audio);
return NULL;
}
/* Load PCM properties */
audio->rate = rate;
audio->channels = channels;
@ -188,6 +194,9 @@ void guac_audio_stream_free(guac_audio_stream* audio) {
if (audio->encoder != NULL && audio->encoder->end_handler)
audio->encoder->end_handler(audio);
/* Release stream back to client pool */
guac_client_free_stream(audio->client, audio->stream);
/* Free associated data */
free(audio);

View File

@ -148,7 +148,8 @@ struct guac_audio_stream {
* @return
* The newly allocated guac_audio_stream, or NULL if no audio stream could
* be allocated due to lack of support on the part of the connecting
* Guacamole client.
* Guacamole client or due to reaching the maximum number of active
* streams.
*/
guac_audio_stream* guac_audio_stream_alloc(guac_client* client,
guac_audio_encoder* encoder, int rate, int channels, int bps);

View File

@ -383,7 +383,8 @@ void guac_client_free_layer(guac_client* client, guac_layer* layer);
* The client to allocate the stream for.
*
* @return
* The next available stream, or a newly allocated stream.
* The next available stream, or a newly allocated stream, or NULL if the
* maximum number of active streams has been reached.
*/
guac_stream* guac_client_alloc_stream(guac_client* client);

View File

@ -574,8 +574,12 @@ int guac_user_handle_instruction(guac_user* user, const char* opcode,
* Allocates a new stream. An arbitrary index is automatically assigned
* if no previously-allocated stream is available for use.
*
* @param user The user to allocate the stream for.
* @return The next available stream, or a newly allocated stream.
* @param user
* The user to allocate the stream for.
*
* @return
* The next available stream, or a newly allocated stream, or NULL if the
* maximum number of active streams has been reached.
*/
guac_stream* guac_user_alloc_stream(guac_user* user);

View File

@ -123,6 +123,15 @@ BOOL guac_rdp_beep_play_sound(rdpContext* context,
guac_audio_stream* beep = guac_audio_stream_alloc(client, NULL,
GUAC_RDP_BEEP_SAMPLE_RATE, 1, 8);
/* Stream availability is not guaranteed */
if (beep == NULL) {
guac_client_log(client, GUAC_LOG_DEBUG, "Ignoring request to beep "
"for %" PRIu32 " millseconds at %" PRIu32 " Hz as no audio "
"stream could be allocated.", play_sound->duration,
play_sound->frequency);
return TRUE;
}
/* Limit maximum duration of each beep */
int duration = play_sound->duration;
if (duration > GUAC_RDP_BEEP_MAX_DURATION)