From 961e60a89bc60e760707892539ccd7c6d283ef01 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Thu, 13 Feb 2014 14:54:34 +0100 Subject: 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. --- src/uca-ring-buffer.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/uca-ring-buffer.c') 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) { -- cgit v1.2.3