Skip to content

Commit

Permalink
More debugging stuff for why VNC gets stuck.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlner committed Nov 8, 2023
1 parent 5ba11a9 commit 8b00944
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 14 deletions.
59 changes: 53 additions & 6 deletions src/common/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

/**
* The width of an update which should be considered negible and thus
Expand Down Expand Up @@ -1805,24 +1806,34 @@ static void __guac_common_surface_flush_to_webp(guac_common_surface* surface,
cairo_surface_t* rect;

/* Use RGB24 if the image is fully opaque */
if (opaque)
if (opaque) {
fprintf(stderr, "About to cairo_image_surface_create_for_data(CAIRO_FORMAT_RGB24)\n");
rect = cairo_image_surface_create_for_data(buffer,
CAIRO_FORMAT_RGB24, surface->dirty_rect.width,
surface->dirty_rect.height, surface->stride);
fprintf(stderr, "Did cairo_image_surface_create_for_data(CAIRO_FORMAT_RGB24)\n");
}

/* Otherwise ARGB32 is needed */
else
else {
fprintf(stderr, "About to cairo_image_surface_create_for_data(CAIRO_FORMAT_ARGB32)\n");
rect = cairo_image_surface_create_for_data(buffer,
CAIRO_FORMAT_ARGB32, surface->dirty_rect.width,
surface->dirty_rect.height, surface->stride);
fprintf(stderr, "Did cairo_image_surface_create_for_data(CAIRO_FORMAT_ARGB32)\n");
}

/* Send WebP for rect */
fprintf(stderr, "About to guac_client_stream_webp()\n");
guac_client_stream_webp(surface->client, socket, GUAC_COMP_OVER, layer,
surface->dirty_rect.x, surface->dirty_rect.y, rect,
guac_common_surface_suggest_quality(surface->client),
surface->lossless ? 1 : 0);
fprintf(stderr, "Did guac_client_stream_webp()\n");

fprintf(stderr, "About to cairo_surface_destroy()\n");
cairo_surface_destroy(rect);
fprintf(stderr, "Did cairo_surface_destroy()\n");
surface->realized = 1;

/* Surface is no longer dirty */
Expand Down Expand Up @@ -1892,6 +1903,8 @@ static void __guac_common_surface_flush(guac_common_surface* surface) {
/* Flush final dirty rectangle to queue. */
__guac_common_surface_flush_to_queue(surface);

fprintf(stderr, "__guac_common_surface_flush did __guac_common_surface_flush_to_queue(surface)\n");

guac_common_surface_bitmap_rect* current = surface->bitmap_queue;
int i, j;
int original_queue_length;
Expand All @@ -1903,6 +1916,8 @@ static void __guac_common_surface_flush(guac_common_surface* surface) {
qsort(surface->bitmap_queue, surface->bitmap_queue_length, sizeof(guac_common_surface_bitmap_rect),
__guac_common_surface_bitmap_rect_compare);

fprintf(stderr, "__guac_common_surface_flush did qsort()\n");

/* Flush all rects in queue */
for (i=0; i < surface->bitmap_queue_length; i++) {

Expand All @@ -1929,6 +1944,8 @@ static void __guac_common_surface_flush(guac_common_surface* surface) {
combined++;
}

fprintf(stderr, "__guac_common_surface_flush did __guac_common_bound_rect()\n");

}

candidate++;
Expand All @@ -1937,9 +1954,13 @@ static void __guac_common_surface_flush(guac_common_surface* surface) {

/* Re-add to queue if there's room and this update was modified or we expect others might be */
if ((combined > 1 || i < original_queue_length)
&& surface->bitmap_queue_length < GUAC_COMMON_SURFACE_QUEUE_SIZE)
&& surface->bitmap_queue_length < GUAC_COMMON_SURFACE_QUEUE_SIZE) {

__guac_common_surface_flush_to_queue(surface);

fprintf(stderr, "__guac_common_surface_flush did __guac_common_surface_flush_to_queue()\n");
}

/* Flush as bitmap otherwise */
else if (surface->dirty) {

Expand All @@ -1948,45 +1969,71 @@ static void __guac_common_surface_flush(guac_common_surface* surface) {
int opaque = __guac_common_surface_is_opaque(surface,
&surface->dirty_rect);

fprintf(stderr, "__guac_common_surface_flush did __guac_common_surface_is_opaque()\n");

/* Prefer WebP when reasonable */
if (__guac_common_surface_should_use_webp(surface,
&surface->dirty_rect))
&surface->dirty_rect)) {

fprintf(stderr, "__guac_common_surface_flush about to __guac_common_surface_flush_to_webp()\n");
__guac_common_surface_flush_to_webp(surface, opaque);

fprintf(stderr, "__guac_common_surface_flush did __guac_common_surface_flush_to_webp()\n");
}

/* If not WebP, JPEG is the next best (lossy) choice */
else if (opaque && __guac_common_surface_should_use_jpeg(
surface, &surface->dirty_rect))
surface, &surface->dirty_rect)) {
fprintf(stderr, "__guac_common_surface_flush about to __guac_common_surface_flush_to_jpeg()\n");
__guac_common_surface_flush_to_jpeg(surface);

fprintf(stderr, "__guac_common_surface_flush did __guac_common_surface_flush_to_jpeg()\n");
}

/* Use PNG if no lossy formats are appropriate */
else
else {
fprintf(stderr, "__guac_common_surface_flush about to __guac_common_surface_flush_to_png()\n");
__guac_common_surface_flush_to_png(surface, opaque);

fprintf(stderr, "__guac_common_surface_flush did __guac_common_surface_flush_to_png()\n");
}

}

}

current++;

fprintf(stderr, "__guac_common_surface_flush did current++ - %p\n", (void*) current);

}

fprintf(stderr, "__guac_common_surface_flush Flush complete\n");

/* Flush complete */
surface->bitmap_queue_length = 0;

}

void guac_common_surface_flush(guac_common_surface* surface) {

fprintf(stderr, "guac_common_surface_flush about to pthread_mutex_lock(&surface->_lock)\n");
pthread_mutex_lock(&surface->_lock);
fprintf(stderr, "guac_common_surface_flush got pthread_mutex_lock(&surface->_lock)\n");

/* Flush any applicable layer properties */
__guac_common_surface_flush_properties(surface);
fprintf(stderr, "guac_common_surface_flush did __guac_common_surface_flush_properties(surface)\n");

/* Flush surface contents */
__guac_common_surface_flush(surface);
fprintf(stderr, "guac_common_surface_flush did __guac_common_surface_flush(surface)\n");

pthread_mutex_unlock(&surface->_lock);

fprintf(stderr, "guac_common_surface_flush did pthread_mutex_unlock(&surface->_lock)\n");


}

void guac_common_surface_dup(guac_common_surface* surface,
Expand Down
5 changes: 3 additions & 2 deletions src/guacd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ static void guacd_proc_add_user(guacd_proc* proc, HANDLE handle, int owner) {

/* Start user thread */
pthread_t user_thread;
pthread_create(&user_thread, NULL, guacd_user_thread, params);
int the_return = pthread_create(&user_thread, NULL, guacd_user_thread, params);
fprintf(stderr, "guacd_proc_add_user pthread_create(): %i, errno: %i\n", the_return, errno);
pthread_detach(user_thread);

}
Expand Down Expand Up @@ -362,7 +363,7 @@ static int guacd_timed_client_free(guac_client* client, int timeout) {
/* Free the client in a separate thread, so we can time the free operation */
int the_return = pthread_create(&client_free_thread, NULL,
guacd_client_free_thread, &free_operation);
fprintf(stderr, "pthread_create(): %i, errno: %i\n", the_return, errno);
fprintf(stderr, "guacd_timed_client_free pthread_create(): %i, errno: %i\n", the_return, errno);

if (!the_return) {

Expand Down
8 changes: 8 additions & 0 deletions src/libguac/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,20 +913,28 @@ void guac_client_stream_webp(guac_client* client, guac_socket* socket,
cairo_surface_t* surface, int quality, int lossless) {

#ifdef ENABLE_WEBP

fprintf(stderr, "guac_client_stream_webp about to guac_client_alloc_stream()\n");
/* Allocate new stream for image */
guac_stream* stream = guac_client_alloc_stream(client);
fprintf(stderr, "guac_client_stream_webp about did guac_client_alloc_stream()\n");

/* Declare stream as containing image data */
guac_protocol_send_img(socket, stream, mode, layer, "image/webp", x, y);
fprintf(stderr, "guac_client_stream_webp about did guac_protocol_send_img()\n");

/* Write WebP data */
guac_webp_write(socket, stream, surface, quality, lossless);
fprintf(stderr, "guac_client_stream_webp about did guac_webp_write()\n");

/* Terminate stream */
guac_protocol_send_end(socket, stream);
fprintf(stderr, "guac_client_stream_webp about did guac_protocol_send_end()\n");


/* Free allocated stream */
guac_client_free_stream(client, stream);
fprintf(stderr, "guac_client_stream_webp about did guac_client_free_stream()\n");
#else
/* Do nothing if WebP support is not built in */
#endif
Expand Down
31 changes: 30 additions & 1 deletion src/libguac/encode-webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,19 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream,

int x, y;

fprintf(stderr, "guac_webp_write about to cairo_image_surface_get_width()\n");

int width = cairo_image_surface_get_width(surface);

fprintf(stderr, "guac_webp_write did cairo_image_surface_get_width()\n");
int height = cairo_image_surface_get_height(surface);
fprintf(stderr, "guac_webp_write did cairo_image_surface_get_height()\n");
int stride = cairo_image_surface_get_stride(surface);
fprintf(stderr, "guac_webp_write did cairo_image_surface_get_stride()\n");
cairo_format_t format = cairo_image_surface_get_format(surface);
fprintf(stderr, "guac_webp_write did cairo_image_surface_get_format()\n");
unsigned char* data = cairo_image_surface_get_data(surface);
fprintf(stderr, "guac_webp_write did cairo_image_surface_get_data()\n");

if (format != CAIRO_FORMAT_RGB24 && format != CAIRO_FORMAT_ARGB32) {
guac_error = GUAC_STATUS_INTERNAL_ERROR;
Expand All @@ -185,11 +193,18 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream,

/* Flush pending operations to surface */
cairo_surface_flush(surface);
fprintf(stderr, "guac_webp_write did cairo_surface_flush()\n");

/* Configure WebP compression bits */
WebPConfig config;
if (!WebPConfigPreset(&config, WEBP_PRESET_DEFAULT, quality))
if (!WebPConfigPreset(&config, WEBP_PRESET_DEFAULT, quality)) {

fprintf(stderr, "not WebPConfigPreset()\n");

return -1;
}

fprintf(stderr, "guac_webp_write did WebPConfigPreset()\n");

/* Add additional tuning */
config.lossless = lossless;
Expand All @@ -200,18 +215,26 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream,
/* Validate configuration */
WebPValidateConfig(&config);

fprintf(stderr, "guac_webp_write did WebPValidateConfig()\n");

/* Set up WebP picture */
WebPPictureInit(&picture);
picture.use_argb = 1;
picture.width = width;
picture.height = height;

fprintf(stderr, "guac_webp_write did WebPPictureInit()\n");

/* Allocate and init writer */
WebPPictureAlloc(&picture);

fprintf(stderr, "guac_webp_write did WebPPictureAlloc()\n");
picture.writer = guac_webp_stream_write;
picture.custom_ptr = &writer;
guac_webp_stream_writer_init(&writer, socket, stream);

fprintf(stderr, "guac_webp_write did guac_webp_stream_writer_init()\n");

/* Copy image data into WebP picture */
argb_output = picture.argb;
for (y = 0; y < height; y++) {
Expand Down Expand Up @@ -246,12 +269,18 @@ int guac_webp_write(guac_socket* socket, guac_stream* stream,
/* Encode image */
WebPEncode(&config, &picture);

fprintf(stderr, "guac_webp_write did WebPEncode()\n");

/* Free picture */
WebPPictureFree(&picture);

fprintf(stderr, "guac_webp_write did WebPPictureFree()\n");

/* Ensure all data is written */
guac_webp_flush_data(&writer);

fprintf(stderr, "guac_webp_write did guac_webp_flush_data()\n");

return 0;

}
Expand Down
Loading

0 comments on commit 8b00944

Please sign in to comment.