GUACAMOLE-1784: Migrate usage of guac_rdp_audio_buffer_ack() to guac_client_for_user().

This commit is contained in:
Mike Jumper 2023-05-08 12:33:25 -07:00
parent 211ddb2253
commit 9611dc22d2

View File

@ -274,6 +274,34 @@ guac_rdp_audio_buffer* guac_rdp_audio_buffer_alloc(guac_client* client) {
return buffer;
}
/**
* Parameters describing an "ack" instruction to be sent to the current user of
* an inbound audio stream (guac_rdp_audio_buffer).
*/
typedef struct guac_rdp_audio_buffer_ack_params {
/**
* The audio buffer associated with the guac_stream for which the "ack"
* instruction should be sent, if any. If there is no associated
* guac_stream, no "ack" will be sent.
*/
guac_rdp_audio_buffer* audio_buffer;
/**
* An arbitrary human-readable message to send along with the "ack".
*/
const char* message;
/**
* The Guacamole protocol status code to send with the "ack". This should
* be GUAC_PROTOCOL_STATUS_SUCCESS if the audio stream has been set up
* successfully or GUAC_PROTOCOL_STATUS_RESOURCE_CLOSED if the audio stream
* has been closed (but may usable again if reopened).
*/
guac_protocol_status status;
} guac_rdp_audio_buffer_ack_params;
/**
* Sends an "ack" instruction over the socket associated with the Guacamole
* stream over which audio data is being received. The "ack" instruction will
@ -285,34 +313,32 @@ guac_rdp_audio_buffer* guac_rdp_audio_buffer_alloc(guac_client* client) {
* IMPORTANT: The guac_rdp_audio_buffer's lock MUST already be held when
* invoking this function.
*
* @param audio_buffer
* The audio buffer associated with the guac_stream for which the "ack"
* instruction should be sent, if any. If there is no associated
* guac_stream, this function has no effect.
* @param user
* The user that should receive the "ack".
*
* @param message
* An arbitrary human-readable message to send along with the "ack".
* @param data
* An instance of guac_rdp_audio_buffer_ack_params describing the "ack"
* instruction to be sent.
*
* @param status
* The Guacamole protocol status code to send with the "ack". This should
* be GUAC_PROTOCOL_STATUS_SUCCESS if the audio stream has been set up
* successfully or GUAC_PROTOCOL_STATUS_RESOURCE_CLOSED if the audio stream
* has been closed (but may usable again if reopened).
* @returns
* Always NULL.
*/
static void guac_rdp_audio_buffer_ack(guac_rdp_audio_buffer* audio_buffer,
const char* message, guac_protocol_status status) {
static void* guac_rdp_audio_buffer_ack(guac_user* user, void* data) {
guac_user* user = audio_buffer->user;
guac_rdp_audio_buffer_ack_params* params = (guac_rdp_audio_buffer_ack_params*) data;
guac_rdp_audio_buffer* audio_buffer = params->audio_buffer;
guac_stream* stream = audio_buffer->stream;
/* Do not send ack unless both sides of the audio stream are ready */
if (user == NULL || stream == NULL || audio_buffer->packet == NULL)
return;
return NULL;
/* Send ack instruction */
guac_protocol_send_ack(user->socket, stream, message, status);
guac_protocol_send_ack(user->socket, stream, params->message, params->status);
guac_socket_flush(user->socket);
return NULL;
}
void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
@ -328,8 +354,8 @@ void guac_rdp_audio_buffer_set_stream(guac_rdp_audio_buffer* audio_buffer,
audio_buffer->in_format.bps = bps;
/* Acknowledge stream creation (if buffer is ready to receive) */
guac_rdp_audio_buffer_ack(audio_buffer,
"OK", GUAC_PROTOCOL_STATUS_SUCCESS);
guac_rdp_audio_buffer_ack_params ack_params = { audio_buffer, "OK", GUAC_PROTOCOL_STATUS_SUCCESS };
guac_client_for_user(audio_buffer->client, user, guac_rdp_audio_buffer_ack, &ack_params);
guac_user_log(user, GUAC_LOG_DEBUG, "User is requesting to provide audio "
"input as %i-channel, %i Hz PCM audio at %i bytes/sample.",
@ -393,8 +419,10 @@ void guac_rdp_audio_buffer_begin(guac_rdp_audio_buffer* audio_buffer,
clock_gettime(CLOCK_REALTIME, &audio_buffer->next_flush);
/* Acknowledge stream creation (if stream is ready to receive) */
guac_rdp_audio_buffer_ack(audio_buffer,
"OK", GUAC_PROTOCOL_STATUS_SUCCESS);
if (audio_buffer->user != NULL) {
guac_rdp_audio_buffer_ack_params ack_params = { audio_buffer, "OK", GUAC_PROTOCOL_STATUS_SUCCESS };
guac_client_for_user(audio_buffer->client, audio_buffer->user, guac_rdp_audio_buffer_ack, &ack_params);
}
pthread_cond_broadcast(&(audio_buffer->modified));
pthread_mutex_unlock(&(audio_buffer->lock));
@ -561,8 +589,10 @@ void guac_rdp_audio_buffer_end(guac_rdp_audio_buffer* audio_buffer) {
}
/* The stream is now closed */
guac_rdp_audio_buffer_ack(audio_buffer,
"CLOSED", GUAC_PROTOCOL_STATUS_RESOURCE_CLOSED);
if (audio_buffer->user != NULL) {
guac_rdp_audio_buffer_ack_params ack_params = { audio_buffer, "CLOSED", GUAC_PROTOCOL_STATUS_RESOURCE_CLOSED };
guac_client_for_user(audio_buffer->client, audio_buffer->user, guac_rdp_audio_buffer_ack, &ack_params);
}
/* Unset user and stream */
audio_buffer->user = NULL;