summaryrefslogtreecommitdiffstats
path: root/src/uca-ring-buffer.c
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2014-02-13 14:54:34 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2014-02-14 16:17:16 +0100
commit961e60a89bc60e760707892539ccd7c6d283ef01 (patch)
tree6e002e95258e4e736c58f5187ff93cf83579541b /src/uca-ring-buffer.c
parentf15d21389a81f8df36b00113aed5c81d27143861 (diff)
downloaduca-961e60a89bc60e760707892539ccd7c6d283ef01.tar.gz
uca-961e60a89bc60e760707892539ccd7c6d283ef01.tar.bz2
uca-961e60a89bc60e760707892539ccd7c6d283ef01.tar.xz
uca-961e60a89bc60e760707892539ccd7c6d283ef01.zip
Fix #28: Add buffered recording to base class
This change adds new properties ::buffered and ::num-buffers to the base class. If ::buffered is TRUE, uca_camera_start_recording will spawn a new thread which will call the camera-specific grab. Any call to uca_camera_grab will return the next item from the ring buffer.
Diffstat (limited to 'src/uca-ring-buffer.c')
-rw-r--r--src/uca-ring-buffer.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/uca-ring-buffer.c b/src/uca-ring-buffer.c
index 98ede8f..26558d7 100644
--- a/src/uca-ring-buffer.c
+++ b/src/uca-ring-buffer.c
@@ -30,7 +30,6 @@ struct _UcaRingBufferPrivate {
guint read_index;
guint read;
guint written;
- gboolean full;
};
enum {
@@ -62,7 +61,6 @@ uca_ring_buffer_reset (UcaRingBuffer *buffer)
buffer->priv->write_index = 0;
buffer->priv->read_index = 0;
- buffer->priv->full = FALSE;
}
gsize
@@ -97,6 +95,8 @@ uca_ring_buffer_get_read_pointer (UcaRingBuffer *buffer)
g_return_val_if_fail (UCA_IS_RING_BUFFER (buffer), NULL);
priv = buffer->priv;
+
+ g_return_val_if_fail (priv->read_index != priv->write_index, NULL);
data = priv->data + (priv->read_index % priv->n_blocks_total) * priv->block_size;
priv->read_index++;
return data;
@@ -112,14 +112,17 @@ uca_ring_buffer_get_write_pointer (UcaRingBuffer *buffer)
priv = buffer->priv;
data = priv->data + (priv->write_index % priv->n_blocks_total) * priv->block_size;
- priv->write_index++;
-
- if ((priv->write_index - priv->read_index) == priv->n_blocks_total)
- priv->full = TRUE;
return data;
}
+void
+uca_ring_buffer_write_advance (UcaRingBuffer *buffer)
+{
+ g_return_if_fail (UCA_IS_RING_BUFFER (buffer));
+ buffer->priv->write_index++;
+}
+
gpointer
uca_ring_buffer_peek_pointer (UcaRingBuffer *buffer)
{