diff options
Diffstat (limited to 'gst/librfb/rfbbytestream.c')
-rw-r--r-- | gst/librfb/rfbbytestream.c | 109 |
1 files changed, 68 insertions, 41 deletions
diff --git a/gst/librfb/rfbbytestream.c b/gst/librfb/rfbbytestream.c index bcdc1b08..b33a33a3 100644 --- a/gst/librfb/rfbbytestream.c +++ b/gst/librfb/rfbbytestream.c @@ -1,23 +1,40 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include <rfbbytestream.h> #include <string.h> +static gint rfb_bytestream_copy_nocheck (RfbBytestream * bs, + RfbBuffer * buffer, gint len); + RfbBytestream * rfb_bytestream_new (void) { return g_new0 (RfbBytestream, 1); } -int -rfb_bytestream_get (RfbBytestream * bs, int len) +void +rfb_bytestream_free (RfbBytestream * bs) +{ + g_return_if_fail (bs != NULL); + + g_slist_free (bs->buffer_list); + g_free (bs); +} + +gint +rfb_bytestream_get (RfbBytestream * bs, gint len) { RfbBuffer *buffer; + g_return_val_if_fail (bs != NULL, 0); + buffer = bs->get_buffer (len, bs->user_data); if (buffer) { - g_print ("got buffer (%d bytes)\n", buffer->length); - bs->buffer_list = g_list_append (bs->buffer_list, buffer); + // g_print ("got buffer (%d bytes)\n", buffer->length); + bs->buffer_list = g_slist_append (bs->buffer_list, buffer); bs->length += buffer->length; @@ -28,46 +45,24 @@ rfb_bytestream_get (RfbBytestream * bs, int len) } gboolean -rfb_bytestream_check (RfbBytestream * bs, int len) +rfb_bytestream_check (RfbBytestream * bs, gint len) { + g_return_val_if_fail (bs != NULL, FALSE); + while (bs->length < len) { rfb_bytestream_get (bs, len - bs->length); } return TRUE; } -static int -rfb_bytestream_copy_nocheck (RfbBytestream * bs, RfbBuffer * buffer, int len) -{ - GList *item; - int offset; - int first_offset; - RfbBuffer *frombuf; - int n; - - offset = 0; - first_offset = bs->offset; - for (item = bs->buffer_list; item; item = g_list_next (item)) { - frombuf = (RfbBuffer *) item->data; - n = MIN (len, frombuf->length - first_offset); - g_print ("copying %d bytes from %p\n", n, frombuf); - memcpy (buffer->data + offset, frombuf->data + first_offset, n); - first_offset = 0; - len -= n; - offset += n; - if (len == 0) - return len; - } - - g_assert_not_reached (); - return 0; -} - -int -rfb_bytestream_read (RfbBytestream * bs, RfbBuffer ** buffer, int len) +gint +rfb_bytestream_read (RfbBytestream * bs, RfbBuffer ** buffer, gint len) { RfbBuffer *buf; + g_return_val_if_fail (bs != NULL, 0); + g_return_val_if_fail (buffer != NULL, 0); + rfb_bytestream_check (bs, len); buf = rfb_buffer_new_and_alloc (len); @@ -79,11 +74,14 @@ rfb_bytestream_read (RfbBytestream * bs, RfbBuffer ** buffer, int len) return len; } -int -rfb_bytestream_peek (RfbBytestream * bs, RfbBuffer ** buffer, int len) +gint +rfb_bytestream_peek (RfbBytestream * bs, RfbBuffer ** buffer, gint len) { RfbBuffer *buf; + g_return_val_if_fail (bs != NULL, 0); + g_return_val_if_fail (buffer != NULL, 0); + rfb_bytestream_check (bs, len); buf = rfb_buffer_new_and_alloc (len); @@ -93,12 +91,14 @@ rfb_bytestream_peek (RfbBytestream * bs, RfbBuffer ** buffer, int len) return len; } -int -rfb_bytestream_flush (RfbBytestream * bs, int len) +gint +rfb_bytestream_flush (RfbBytestream * bs, gint len) { - GList *item; + GSList *item; RfbBuffer *buf; - int n; + gint n; + + g_return_val_if_fail (bs != NULL, 0); while ((item = bs->buffer_list)) { buf = (RfbBuffer *) item->data; @@ -106,7 +106,7 @@ rfb_bytestream_flush (RfbBytestream * bs, int len) n = MIN (buf->length - bs->offset, len); if (n <= len) { bs->offset = 0; - bs->buffer_list = g_list_delete_link (bs->buffer_list, item); + bs->buffer_list = g_slist_delete_link (bs->buffer_list, item); rfb_buffer_free (buf); } else { bs->offset = bs->offset + len; @@ -120,3 +120,30 @@ rfb_bytestream_flush (RfbBytestream * bs, int len) g_assert_not_reached (); return 0; } + +static gint +rfb_bytestream_copy_nocheck (RfbBytestream * bs, RfbBuffer * buffer, gint len) +{ + GSList *item; + gint offset; + gint first_offset; + RfbBuffer *frombuf; + gint n; + + offset = 0; + first_offset = bs->offset; + for (item = bs->buffer_list; item; item = item->next) { + frombuf = (RfbBuffer *) item->data; + n = MIN (len, frombuf->length - first_offset); + // g_print ("copying %d bytes from %p\n", n, frombuf); + memcpy (buffer->data + offset, frombuf->data + first_offset, n); + first_offset = 0; + len -= n; + offset += n; + if (len == 0) + return len; + } + + g_assert_not_reached (); + return 0; +} |