diff --git a/src/protocols/rdp/audio.c b/src/protocols/rdp/audio.c index c6c5e0db..39e27256 100644 --- a/src/protocols/rdp/audio.c +++ b/src/protocols/rdp/audio.c @@ -88,8 +88,6 @@ void audio_stream_end(audio_stream* audio) { double duration; - rdp_guac_client_data* data = (rdp_guac_client_data*) audio->client->data; - /* Flush stream and finish encoding */ audio_stream_flush(audio); audio->encoder->end_handler(audio); @@ -98,15 +96,11 @@ void audio_stream_end(audio_stream* audio) { duration = ((double) (audio->pcm_bytes_written * 1000 * 8)) / audio->rate / audio->channels / audio->bps; - pthread_mutex_lock(&(data->update_lock)); - /* Send audio */ guac_protocol_send_audio(audio->stream->socket, 0, audio->encoder->mimetype, duration, audio->encoded_data, audio->encoded_data_used); - pthread_mutex_unlock(&(data->update_lock)); - /* Clear data */ audio->encoded_data_used = 0; diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index c1ebe51f..a438cd7d 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -522,15 +522,14 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->clipboard = NULL; guac_client_data->audio = NULL; + /* Main socket needs to be threadsafe */ + guac_socket_require_threadsafe(client->socket); + /* Recursive attribute for locks */ pthread_mutexattr_init(&(guac_client_data->attributes)); pthread_mutexattr_settype(&(guac_client_data->attributes), PTHREAD_MUTEX_RECURSIVE); - /* Init update lock */ - pthread_mutex_init(&(guac_client_data->update_lock), - &(guac_client_data->attributes)); - /* Init RDP lock */ pthread_mutex_init(&(guac_client_data->rdp_lock), &(guac_client_data->attributes)); diff --git a/src/protocols/rdp/client.h b/src/protocols/rdp/client.h index d820c948..f03e0eaa 100644 --- a/src/protocols/rdp/client.h +++ b/src/protocols/rdp/client.h @@ -186,11 +186,6 @@ typedef struct rdp_guac_client_data { */ audio_stream* audio; - /** - * Lock which is locked and unlocked for each update. - */ - pthread_mutex_t update_lock; - /** * Lock which is locked and unlocked for each RDP message. */ diff --git a/src/protocols/rdp/guac_handlers.c b/src/protocols/rdp/guac_handlers.c index 507c8fe5..006332a2 100644 --- a/src/protocols/rdp/guac_handlers.c +++ b/src/protocols/rdp/guac_handlers.c @@ -206,11 +206,8 @@ int rdp_guac_client_handle_messages(guac_client* client) { pthread_mutex_unlock(&(guac_client_data->rdp_lock)); /* Flush any audio */ - if (guac_client_data->audio != NULL) { - pthread_mutex_lock(&(guac_client_data->update_lock)); + if (guac_client_data->audio != NULL) guac_socket_flush(guac_client_data->audio->stream->socket); - pthread_mutex_unlock(&(guac_client_data->update_lock)); - } /* Success */ return 0; diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c index acb95c38..d6c69512 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c @@ -31,18 +31,14 @@ char* const guac_rdpdr_pdf_filter_command[] = { static void* guac_rdpdr_print_filter_output_thread(void* data) { guac_rdpdrPlugin* rdpdr = (guac_rdpdrPlugin*) data; - rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data; int length; char buffer[8192]; /* Write all output as blobs */ - while ((length = read(rdpdr->printer_output, buffer, sizeof(buffer))) > 0) { - pthread_mutex_lock(&(client_data->update_lock)); + while ((length = read(rdpdr->printer_output, buffer, sizeof(buffer))) > 0) guac_protocol_send_blob(rdpdr->client->socket, GUAC_RDPDR_PRINTER_BLOB, buffer, length); - pthread_mutex_unlock(&(client_data->update_lock)); - } /* Log any error */ if (length < 0) @@ -158,7 +154,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s int status=0, length; unsigned char* buffer; - rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data; STREAM* output_stream = stream_new(24); stream_read_uint32(input_stream, length); @@ -166,9 +161,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s stream_seek(input_stream, 20); /* Padding */ buffer = stream_get_tail(input_stream); - /* Send data */ - pthread_mutex_lock(&(client_data->update_lock)); - /* Create print job, if not yet created */ if (rdpdr->bytes_received == 0) { @@ -224,8 +216,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s rdpdr->bytes_received += length; - pthread_mutex_unlock(&(client_data->update_lock)); - /* If not yet failed, write received data */ if (status == 0) { @@ -256,7 +246,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s void guac_rdpdr_process_print_job_close(guac_rdpdrPlugin* rdpdr, STREAM* input_stream, int completion_id) { - rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data; STREAM* output_stream = stream_new(24); /* Close input and wait for output thread to finish */ @@ -268,9 +257,7 @@ void guac_rdpdr_process_print_job_close(guac_rdpdrPlugin* rdpdr, STREAM* input_s /* Close file */ guac_client_log_info(rdpdr->client, "Print job closed"); - pthread_mutex_lock(&(client_data->update_lock)); guac_protocol_send_end(rdpdr->client->socket, GUAC_RDPDR_PRINTER_BLOB); - pthread_mutex_unlock(&(client_data->update_lock)); /* Write header */ stream_write_uint16(output_stream, RDPDR_CTYP_CORE); diff --git a/src/protocols/rdp/rdp_bitmap.c b/src/protocols/rdp/rdp_bitmap.c index b5123100..2363f75c 100644 --- a/src/protocols/rdp/rdp_bitmap.c +++ b/src/protocols/rdp/rdp_bitmap.c @@ -65,9 +65,6 @@ void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) { /* Cache image data if present */ if (bitmap->data != NULL) { - rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(data->update_lock)); - /* Create surface from image data */ cairo_surface_t* surface = cairo_image_surface_create_for_data( bitmap->data, CAIRO_FORMAT_RGB24, @@ -80,7 +77,6 @@ void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) { /* Free surface */ cairo_surface_destroy(surface); - pthread_mutex_unlock(&(data->update_lock)); } /* Store buffer reference in bitmap */ @@ -125,9 +121,6 @@ void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) { int width = bitmap->right - bitmap->left + 1; int height = bitmap->bottom - bitmap->top + 1; - rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(data->update_lock)); - /* If not cached, cache if necessary */ if (((guac_rdp_bitmap*) bitmap)->layer == NULL && ((guac_rdp_bitmap*) bitmap)->used >= 1) @@ -162,7 +155,6 @@ void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) { /* Increment usage counter */ ((guac_rdp_bitmap*) bitmap)->used++; - pthread_mutex_unlock(&(data->update_lock)); } void guac_rdp_bitmap_free(rdpContext* context, rdpBitmap* bitmap) { diff --git a/src/protocols/rdp/rdp_gdi.c b/src/protocols/rdp/rdp_gdi.c index 46f25695..cf07827c 100644 --- a/src/protocols/rdp/rdp_gdi.c +++ b/src/protocols/rdp/rdp_gdi.c @@ -113,10 +113,8 @@ void guac_rdp_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) { int w = dstblt->nWidth; int h = dstblt->nHeight; - rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(data->update_lock)); - /* Clip operation to bounds */ + rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; guac_rdp_clip_rect(data, &x, &y, &w, &h); switch (dstblt->bRop) { @@ -164,8 +162,6 @@ void guac_rdp_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) { } - pthread_mutex_unlock(&(data->update_lock)); - } @@ -291,10 +287,8 @@ void guac_rdp_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) { int x_src = scrblt->nXSrc; int y_src = scrblt->nYSrc; - rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(data->update_lock)); - /* Clip operation to bounds */ + rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; guac_rdp_clip_rect(data, &x, &y, &w, &h); /* Update source coordinates */ @@ -306,8 +300,6 @@ void guac_rdp_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) { GUAC_DEFAULT_LAYER, x_src, y_src, w, h, GUAC_COMP_OVER, current_layer, x, y); - pthread_mutex_unlock(&(data->update_lock)); - } void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { @@ -333,8 +325,6 @@ void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { return; } - pthread_mutex_lock(&(data->update_lock)); - /* Clip operation to bounds */ guac_rdp_clip_rect(data, &x, &y, &w, &h); @@ -422,8 +412,6 @@ void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { } - pthread_mutex_unlock(&(data->update_lock)); - } void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) { @@ -436,7 +424,6 @@ void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface; rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(data->update_lock)); int x = opaque_rect->nLeftRect; int y = opaque_rect->nTopRect; @@ -455,8 +442,6 @@ void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect (color ) & 0xFF, 255); - pthread_mutex_unlock(&(data->update_lock)); - } void guac_rdp_gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette) { diff --git a/src/protocols/rdp/rdp_glyph.c b/src/protocols/rdp/rdp_glyph.c index fa86692f..913d8a6b 100644 --- a/src/protocols/rdp/rdp_glyph.c +++ b/src/protocols/rdp/rdp_glyph.c @@ -204,8 +204,6 @@ void guac_rdp_glyph_enddraw(rdpContext* context, rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface; - pthread_mutex_lock(&(guac_client_data->update_lock)); - /* Use glyph surface to provide image data for glyph rectangle */ cairo_surface_t* glyph_surface = guac_client_data->glyph_surface; int stride = cairo_image_surface_get_stride(glyph_surface); @@ -241,6 +239,5 @@ void guac_rdp_glyph_enddraw(rdpContext* context, /* Destroy cairo instance */ cairo_destroy(guac_client_data->glyph_cairo); - pthread_mutex_unlock(&(guac_client_data->update_lock)); } diff --git a/src/protocols/rdp/rdp_pointer.c b/src/protocols/rdp/rdp_pointer.c index a52e5863..09ee22ad 100644 --- a/src/protocols/rdp/rdp_pointer.c +++ b/src/protocols/rdp/rdp_pointer.c @@ -59,9 +59,6 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) { cairo_surface_t* surface; - rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(client_data->update_lock)); - /* Convert to alpha cursor if mask data present */ if (pointer->andMaskData && pointer->xorMaskData) freerdp_alpha_cursor_convert(data, @@ -84,7 +81,6 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) { /* Remember buffer */ ((guac_rdp_pointer*) pointer)->layer = buffer; - pthread_mutex_unlock(&(client_data->update_lock)); } void guac_rdp_pointer_set(rdpContext* context, rdpPointer* pointer) { @@ -92,15 +88,11 @@ void guac_rdp_pointer_set(rdpContext* context, rdpPointer* pointer) { guac_client* client = ((rdp_freerdp_context*) context)->client; guac_socket* socket = client->socket; - rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; - pthread_mutex_lock(&(data->update_lock)); - /* Set cursor */ guac_protocol_send_cursor(socket, pointer->xPos, pointer->yPos, ((guac_rdp_pointer*) pointer)->layer, 0, 0, pointer->width, pointer->height); - pthread_mutex_unlock(&(data->update_lock)); } void guac_rdp_pointer_free(rdpContext* context, rdpPointer* pointer) {