From f286bd92c73a352c740649270e517bff830fe5f4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 26 Feb 2016 23:26:00 -0800 Subject: [PATCH] GUAC-236: Add display, buffer, image, and stream abstractions. --- src/guacenc/Makefile.am | 5 ++ src/guacenc/buffer.h | 47 +++++++++++++++++ src/guacenc/display.c | 32 +++++++++++ src/guacenc/display.h | 105 +++++++++++++++++++++++++++++++++++++ src/guacenc/image-stream.h | 42 +++++++++++++++ src/guacenc/layer.h | 80 ++++++++++++++++++++++++++++ 6 files changed, 311 insertions(+) create mode 100644 src/guacenc/buffer.h create mode 100644 src/guacenc/display.c create mode 100644 src/guacenc/display.h create mode 100644 src/guacenc/image-stream.h create mode 100644 src/guacenc/layer.h diff --git a/src/guacenc/Makefile.am b/src/guacenc/Makefile.am index 7824cf14..39b31e0e 100644 --- a/src/guacenc/Makefile.am +++ b/src/guacenc/Makefile.am @@ -25,11 +25,16 @@ AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = guacenc noinst_HEADERS = \ + buffer.h \ + display.h \ encode.h \ + image-stream.h \ instructions.h \ + layer.h \ log.h guacenc_SOURCES = \ + display.c \ encode.c \ guacenc.c \ instructions.c \ diff --git a/src/guacenc/buffer.h b/src/guacenc/buffer.h new file mode 100644 index 00000000..6bd3ce3c --- /dev/null +++ b/src/guacenc/buffer.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUACENC_BUFFER_H +#define GUACENC_BUFFER_H + +#include "config.h" + +/** + * The image and size storage for either a buffer (a Guacamole layer with a + * negative index) or a layer (a Guacamole layer with a non-negative index). + */ +typedef struct guacenc_buffer { + + /** + * The width of this buffer or layer, in pixels. + */ + int width; + + /** + * The height of this buffer or layer, in pixels. + */ + int height; + +} guacenc_buffer; + +#endif + diff --git a/src/guacenc/display.c b/src/guacenc/display.c new file mode 100644 index 00000000..fa800804 --- /dev/null +++ b/src/guacenc/display.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" +#include "display.h" + +#include + +int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp) { + /* STUB */ + return 0; +} + diff --git a/src/guacenc/display.h b/src/guacenc/display.h new file mode 100644 index 00000000..3f438a4b --- /dev/null +++ b/src/guacenc/display.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUACENC_DISPLAY_H +#define GUACENC_DISPLAY_H + +#include "config.h" +#include "buffer.h" +#include "image-stream.h" +#include "layer.h" + +#include + +/** + * The maximum number of buffers that the Guacamole video encoder will handle + * within a single Guacamole protocol dump. + */ +#define GUACENC_DISPLAY_MAX_BUFFERS 4096 + +/** + * The maximum number of layers that the Guacamole video encoder will handle + * within a single Guacamole protocol dump. + */ +#define GUACENC_DISPLAY_MAX_LAYERS 64 + +/** + * The maximum number of streams that the Guacamole video encoder will handle + * within a single Guacamole protocol dump. + */ +#define GUACENC_DISPLAY_MAX_STREAMS 64 + +/** + * The current state of the Guacamole video encoder's internal display. + */ +typedef struct guacenc_display { + + /** + * All currently-allocated buffers. The index of the buffer corresponds to + * its position within this array, where -1 is the 0th entry. If a buffer + * has not yet been allocated, or a buffer has been freed (due to a + * "dispose" instruction), its entry here will be NULL. + */ + guacenc_buffer* buffers[GUACENC_DISPLAY_MAX_BUFFERS]; + + /** + * All currently-allocated layers. The index of the layer corresponds to + * its position within this array. If a layer has not yet been allocated, + * or a layer has been freed (due to a "dispose" instruction), its entry + * here will be NULL. + */ + guacenc_layer* layers[GUACENC_DISPLAY_MAX_LAYERS]; + + /** + * All currently-allocated image streams. The index of the stream + * corresponds to its position within this array. If a stream has not yet + * been allocated, or a stream has been freed (due to an "end" + * instruction), its entry here will be NULL. + */ + guacenc_image_stream* image_streams[GUACENC_DISPLAY_MAX_STREAMS]; + + /** + * The timestamp of the last sync instruction handled, or 0 if no sync has + * yet been read. + */ + guac_timestamp last_sync; + +} guacenc_display; + +/** + * Handles a received "sync" instruction having the given timestamp, flushing + * the current display to the in-progress video encoding. + * + * @param display + * The display to flush to the video encoding as a new frame. + * + * @param timestamp + * The timestamp of the new frame, as dictated by the "sync" instruction + * sent at the end of the frame. + * + * @return + * Zero if the frame was successfully written, non-zero if an error occurs. + */ +int guacenc_display_sync(guacenc_display* display, guac_timestamp timestamp); + +#endif + diff --git a/src/guacenc/image-stream.h b/src/guacenc/image-stream.h new file mode 100644 index 00000000..d88897d4 --- /dev/null +++ b/src/guacenc/image-stream.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUACENC_IMAGE_STREAM_H +#define GUACENC_IMAGE_STREAM_H + +#include "config.h" + +/** + * The current state of an allocated Guacamole image stream. + */ +typedef struct guacenc_image_stream { + + /** + * STUB: Placeholder property. This property exists only so that the + * guacenc_image_stream struct can be defined prior to implementation. + */ + int __PLACEHOLDER; + +} guacenc_image_stream; + +#endif + diff --git a/src/guacenc/layer.h b/src/guacenc/layer.h new file mode 100644 index 00000000..739d2aa1 --- /dev/null +++ b/src/guacenc/layer.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUACENC_LAYER_H +#define GUACENC_LAYER_H + +#include "config.h" +#include "buffer.h" + +/** + * The value assigned to the parent_index property of a guacenc_layer if it has + * no parent. + */ +#define GUACENC_LAYER_NO_PARENT -1 + +/** + * A visible Guacamole layer. + */ +typedef struct guacenc_layer { + + /** + * The actual image contents of this layer, as well as this layer's size + * (width and height). + */ + guacenc_buffer buffer; + + /** + * The index of the layer that contains this layer. If this layer is the + * default layer (and thus has no parent), this will be + * GUACENC_LAYER_NO_PARENT. + */ + int parent_index; + + /** + * The X coordinate of the upper-left corner of this layer within the + * Guacamole display. + */ + int x; + + /** + * The Y coordinate of the upper-left corner of this layer within the + * Guacamole display. + */ + int y; + + /** + * The relative stacking order of this layer with respect to other sibling + * layers. + */ + int z; + + /** + * The opacity of this layer, where 0 is completely transparent and 255 is + * completely opaque. + */ + int opacity; + +} guacenc_layer; + +#endif +