From d29d5bbc9943d9f15df5c28fe906d215b2271941 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 27 Feb 2016 19:27:47 -0800 Subject: [PATCH] GUAC-236: Add helper functions for invoking stream data/end handlers. --- src/guacenc/image-stream.c | 26 ++++++++++++++++++++++++ src/guacenc/image-stream.h | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/guacenc/image-stream.c b/src/guacenc/image-stream.c index 7475d471..371fa6ba 100644 --- a/src/guacenc/image-stream.c +++ b/src/guacenc/image-stream.c @@ -86,6 +86,32 @@ guacenc_image_stream* guacenc_image_stream_alloc(int mask, int index, } +int guacenc_image_stream_receive(guacenc_image_stream* stream, + unsigned char* data, int length) { + + /* Invoke data handler of corresponding decoder (if any) */ + guacenc_decoder* decoder = stream->decoder; + if (decoder != NULL) + return decoder->data_handler(stream, data, length); + + /* If there is no decoder, simply return success */ + return 0; + +} + +int guacenc_image_stream_end(guacenc_image_stream* stream, + guacenc_buffer* buffer) { + + /* Invoke end handler of corresponding decoder (if any) */ + guacenc_decoder* decoder = stream->decoder; + if (decoder != NULL) + return decoder->end_handler(stream, buffer); + + /* If there is no decoder, simply return success */ + return 0; + +} + int guacenc_image_stream_free(guacenc_image_stream* stream) { /* Ignore NULL streams */ diff --git a/src/guacenc/image-stream.h b/src/guacenc/image-stream.h index 6275cade..22b72f1d 100644 --- a/src/guacenc/image-stream.h +++ b/src/guacenc/image-stream.h @@ -237,6 +237,47 @@ guacenc_decoder* guacenc_get_decoder(const char* mimetype); guacenc_image_stream* guacenc_image_stream_alloc(int mask, int index, const char* mimetype, int x, int y); +/** + * Signals the decoder of the given image stream that a chunk of image data + * has been received. If no decoder is associated with the given image stream, + * this function has no effect. + * + * @param stream + * The image stream that received the data. + * + * @param data + * The chunk of data received along the image stream. + * + * @param length + * The length of the chunk of data received, in bytes. + * + * @return + * Zero if the given data was handled successfully by the decoder, or + * non-zero if an error occurs. + */ +int guacenc_image_stream_receive(guacenc_image_stream* stream, + unsigned char* data, int length); + +/** + * Signals the decoder of the given image stream that no more data will be + * received and the image should be written to the given buffer as-is. If no + * decoder is associated with the given image stream, this function has no + * effect. Meta-information describing the image draw operation itself is + * stored within the guacenc_image_stream. + * + * @param stream + * The image stream that has ended. + * + * @param buffer + * The buffer that the decoded image should be written to. + * + * @return + * Zero if the image is written successfully, or non-zero if an error + * occurs. + */ +int guacenc_image_stream_end(guacenc_image_stream* stream, + guacenc_buffer* buffer); + /** * Frees the given image stream and all associated data. If the image stream * has not yet ended (reached end-of-stream), no image will be drawn to the