[aravis] stream: add try_pop_buffer and modify pop_buffer to be blocking.



commit 514e2f7d6b5c73b3a2710b8dec08bf231329051f
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Thu Feb 16 19:09:37 2012 +0100

    stream: add try_pop_buffer and modify pop_buffer to be blocking.
    
    This makes the push/pop API consistent with the underlying GAsyncQueue
    object used by ArvStream.

 docs/reference/aravis/aravis-sections.txt |    1 +
 src/arvstream.c                           |   25 ++++++++++++++++++++++++-
 src/arvstream.h                           |    1 +
 tests/arvcameratest.c                     |    2 +-
 tests/arvtest.c                           |    2 +-
 5 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 302598d..42b5a6d 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -295,6 +295,7 @@ ArvStreamCallback
 ArvStream
 arv_stream_push_buffer
 arv_stream_pop_buffer
+arv_stream_try_pop_buffer
 arv_stream_timed_pop_buffer
 arv_stream_get_n_buffers
 arv_stream_get_statistics
diff --git a/src/arvstream.c b/src/arvstream.c
index 77bb44b..39a68e2 100644
--- a/src/arvstream.c
+++ b/src/arvstream.c
@@ -81,6 +81,9 @@ arv_stream_push_buffer (ArvStream *stream, ArvBuffer *buffer)
  *
  * Pops a buffer from the output queue of @stream. The retrieved buffer
  * may contain an invalid image. Caller should check the buffer status before using it.
+ * This function blocks until a buffer is available.
+ *
+ * since: 0.1.12
  */
 
 ArvBuffer *
@@ -88,6 +91,26 @@ arv_stream_pop_buffer (ArvStream *stream)
 {
 	g_return_val_if_fail (ARV_IS_STREAM (stream), NULL);
 
+	return g_async_queue_pop (stream->priv->output_queue);
+}
+
+/**
+ * arv_stream_try_pop_buffer:
+ * @stream: a #ArvStream
+ * Returns: (transfer full): a #ArvBuffer, NULL if no buffer is available.
+ *
+ * Pops a buffer from the output queue of @stream. The retrieved buffer
+ * may contain an invalid image. Caller should check the buffer status before using it.
+ * This is the non blocking version of pop_buffer.
+ *
+ * since: 0.1.12
+ */
+
+ArvBuffer *
+arv_stream_try_pop_buffer (ArvStream *stream)
+{
+	g_return_val_if_fail (ARV_IS_STREAM (stream), NULL);
+
 	return g_async_queue_try_pop (stream->priv->output_queue);
 }
 
@@ -95,7 +118,7 @@ arv_stream_pop_buffer (ArvStream *stream)
  * arv_stream_timed_pop_buffer:
  * @stream: a #ArvStream
  * @timeout: timeout, in Âs
- * Returns: (transfer full): a #ArvBuffer
+ * Returns: (transfer full): a #ArvBuffer, NULL if no buffer is available until the timeout occurs.
  *
  * Pops a buffer from the output queue of @stream, waiting no more than @timeout. The retrieved buffer
  * may contain an invalid image. Caller should check the buffer status before using it.
diff --git a/src/arvstream.h b/src/arvstream.h
index d1f539f..002be32 100644
--- a/src/arvstream.h
+++ b/src/arvstream.h
@@ -76,6 +76,7 @@ GType arv_stream_get_type (void);
 
 void		arv_stream_push_buffer 			(ArvStream *stream, ArvBuffer *buffer);
 ArvBuffer *	arv_stream_pop_buffer			(ArvStream *stream);
+ArvBuffer *	arv_stream_try_pop_buffer		(ArvStream *stream);
 ArvBuffer * 	arv_stream_timed_pop_buffer 		(ArvStream *stream, guint64 timeout);
 void 		arv_stream_get_n_buffers 		(ArvStream *stream,
 							 gint *n_input_buffers,
diff --git a/tests/arvcameratest.c b/tests/arvcameratest.c
index d03b0e5..bb6cca0 100644
--- a/tests/arvcameratest.c
+++ b/tests/arvcameratest.c
@@ -106,7 +106,7 @@ new_buffer_cb (ArvStream *stream, ApplicationData *data)
 {
 	ArvBuffer *buffer;
 
-	buffer = arv_stream_pop_buffer (stream);
+	buffer = arv_stream_try_pop_buffer (stream);
 	if (buffer != NULL) {
 		if (buffer->status == ARV_BUFFER_STATUS_SUCCESS)
 			data->buffer_count++;
diff --git a/tests/arvtest.c b/tests/arvtest.c
index c84e62e..7d22bde 100644
--- a/tests/arvtest.c
+++ b/tests/arvtest.c
@@ -199,7 +199,7 @@ main (int argc, char **argv)
 			g_usleep (100000);
 
 			do  {
-				buffer = arv_stream_pop_buffer (stream);
+				buffer = arv_stream_try_pop_buffer (stream);
 				if (buffer != NULL)
 					arv_stream_push_buffer (stream, buffer);
 			} while (buffer != NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]