[aravis] stream: pass callback at stream creation, instead of passing it in every buffers.



commit e78b8da4e912752eefcb3a950db754df1e12b9fc
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Apr 12 11:10:37 2010 +0200

    stream: pass callback at stream creation, instead of passing it in every buffers.

 src/arvbuffer.c   |   20 +-------------------
 src/arvbuffer.h   |    7 -------
 src/arvdevice.c   |   10 ++++++++--
 src/arvdevice.h   |    5 ++++-
 src/arvgvdevice.c |    4 ++--
 src/arvgvstream.c |   19 +++++++++++++++++--
 src/arvgvstream.h |    3 ++-
 src/arvstream.h   |    9 +++++++++
 src/arvtypes.h    |    2 +-
 9 files changed, 44 insertions(+), 35 deletions(-)
---
diff --git a/src/arvbuffer.c b/src/arvbuffer.c
index c85485e..9bd9239 100644
--- a/src/arvbuffer.c
+++ b/src/arvbuffer.c
@@ -24,17 +24,8 @@
 
 static GObjectClass *parent_class = NULL;
 
-
-void
-arv_buffer_run_callback (ArvBuffer *buffer)
-{
-	if (buffer != NULL && buffer->frame_callback != NULL)
-		buffer->frame_callback (buffer);
-}
-
 ArvBuffer *
-arv_buffer_new_with_callback (size_t size, void *preallocated,
-			      ArvFrameCallback frame_callback, void *user_data)
+arv_buffer_new (size_t size, void *preallocated)
 {
 	ArvBuffer *buffer;
 
@@ -49,18 +40,9 @@ arv_buffer_new_with_callback (size_t size, void *preallocated,
 		buffer->data = g_malloc (size);
 	}
 
-	buffer->frame_callback = frame_callback;
-	buffer->user_data = user_data;
-
 	return buffer;
 }
 
-ArvBuffer *
-arv_buffer_new (size_t size, void *preallocated)
-{
-	return arv_buffer_new_with_callback (size, preallocated, NULL, NULL);
-}
-
 void
 arv_buffer_clear (ArvBuffer *buffer)
 {
diff --git a/src/arvbuffer.h b/src/arvbuffer.h
index 0b9fec6..5ece040 100644
--- a/src/arvbuffer.h
+++ b/src/arvbuffer.h
@@ -59,9 +59,6 @@ struct _ArvBuffer {
 	guint32 frame_id;
 	guint32 width;
 	guint32 height;
-
-	ArvFrameCallback frame_callback;
-	void *user_data;
 };
 
 struct _ArvBufferClass {
@@ -71,10 +68,6 @@ struct _ArvBufferClass {
 GType arv_buffer_get_type (void);
 
 ArvBuffer * 		arv_buffer_new 			(size_t size, void *preallocated);
-ArvBuffer * 		arv_buffer_new_with_callback	(size_t size, void *preallocated,
-							 ArvFrameCallback frame_callback, void *user_data);
-
-void			arv_buffer_run_callback		(ArvBuffer *buffer);
 
 G_END_DECLS
 
diff --git a/src/arvdevice.c b/src/arvdevice.c
index c36059a..c8b31c3 100644
--- a/src/arvdevice.c
+++ b/src/arvdevice.c
@@ -33,11 +33,17 @@ struct _ArvDevicePrivate {
 };
 
 ArvStream *
-arv_device_new_stream (ArvDevice *device)
+arv_device_new_stream_with_callback (ArvDevice *device, ArvStreamCallback callback, void *user_data)
 {
 	g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
 
-	return ARV_DEVICE_GET_CLASS (device)->new_stream (device);
+	return ARV_DEVICE_GET_CLASS (device)->new_stream (device, callback, user_data);
+}
+
+ArvStream *
+arv_device_new_stream (ArvDevice *device)
+{
+	return arv_device_new_stream_with_callback (device, NULL, NULL);
 }
 
 gboolean
diff --git a/src/arvdevice.h b/src/arvdevice.h
index 49a1b8b..c88b948 100644
--- a/src/arvdevice.h
+++ b/src/arvdevice.h
@@ -24,6 +24,7 @@
 #define ARV_DEVICE_H
 
 #include <arvtypes.h>
+#include <arvstream.h>
 
 G_BEGIN_DECLS
 
@@ -46,7 +47,7 @@ struct _ArvDevice {
 struct _ArvDeviceClass {
 	GObjectClass parent_class;
 
-	ArvStream *	(*new_stream)		(ArvDevice *device);
+	ArvStream *	(*new_stream)		(ArvDevice *device, ArvStreamCallback callback, void *user_data);
 
 	gboolean	(*read_memory)		(ArvDevice *device, guint32 address, guint32 size, void *buffer);
 	gboolean	(*write_memory)		(ArvDevice *device, guint32 address, guint32 size, void *buffer);
@@ -56,6 +57,8 @@ struct _ArvDeviceClass {
 
 GType arv_device_get_type (void);
 
+ArvStream *	arv_device_new_stream_with_callback	(ArvDevice *device, ArvStreamCallback callback,
+							 void *user_data);
 ArvStream *	arv_device_new_stream			(ArvDevice *device);
 
 gboolean	arv_device_read_memory 			(ArvDevice *device, guint32 address, guint32 size,
diff --git a/src/arvgvdevice.c b/src/arvgvdevice.c
index 2edc435..04e8a98 100644
--- a/src/arvgvdevice.c
+++ b/src/arvgvdevice.c
@@ -400,7 +400,7 @@ arv_gv_device_load_genicam (ArvGvDevice *gv_device)
 /* ArvDevice implemenation */
 
 static ArvStream *
-arv_gv_device_new_stream (ArvDevice *device)
+arv_gv_device_new_stream (ArvDevice *device, ArvStreamCallback callback, void *user_data)
 {
 	ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
 	ArvGvDeviceIOData *io_data = gv_device->priv->io_data;
@@ -414,7 +414,7 @@ arv_gv_device_new_stream (ArvDevice *device)
 	device_address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (io_data->device_address));
 	address_bytes = g_inet_address_to_bytes (interface_address);
 
-	stream = arv_gv_stream_new (device_address, 0);
+	stream = arv_gv_stream_new (device_address, 0, callback, user_data);
 
 	stream_port = arv_gv_stream_get_port (ARV_GV_STREAM (stream));
 
diff --git a/src/arvgvstream.c b/src/arvgvstream.c
index e14b8da..8697546 100644
--- a/src/arvgvstream.c
+++ b/src/arvgvstream.c
@@ -34,6 +34,9 @@ static GObjectClass *parent_class = NULL;
 /* Acquisition thread */
 
 typedef struct {
+	ArvStreamCallback callback;
+	void *user_data;
+
 	GSocket *socket;
 	GSocketAddress *device_address;
 
@@ -133,6 +136,9 @@ arv_gv_stream_thread (void *data)
 	gint64 last_time_us;
 	gboolean statistic_count = 0;
 
+	if (thread_data->callback != NULL)
+		thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_INIT, NULL);
+
 	packet = (ArvGvspPacket *) packet_buffer;
 
 	poll_fd.fd = g_socket_get_fd (thread_data->socket);
@@ -210,7 +216,10 @@ arv_gv_stream_thread (void *data)
 						if (buffer->status == ARV_BUFFER_STATUS_SUCCESS)
 							thread_data->n_processed_buffers++;
 
-						arv_buffer_run_callback (buffer);
+						if (thread_data->callback != NULL)
+							thread_data->callback (thread_data->user_data,
+									       ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE,
+									       buffer);
 
 						g_get_current_time (&current_time);
 						current_time_us = current_time.tv_sec * 1000000 + current_time.tv_usec;
@@ -233,6 +242,9 @@ arv_gv_stream_thread (void *data)
 		g_async_queue_push (thread_data->output_queue, buffer);
 	}
 
+	if (thread_data->callback != NULL)
+		thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_EXIT, NULL);
+
 	return NULL;
 }
 
@@ -271,7 +283,8 @@ arv_gv_stream_set_option (ArvGvStream *gv_stream, ArvGvStreamOption option, int
 }
 
 ArvStream *
-arv_gv_stream_new_with_callback (GInetAddress *device_address, guint16 port)
+arv_gv_stream_new (GInetAddress *device_address, guint16 port,
+		   ArvStreamCallback callback, void *user_data)
 {
 	ArvGvStream *gv_stream;
 	ArvStream *stream;
@@ -295,6 +308,8 @@ arv_gv_stream_new_with_callback (GInetAddress *device_address, guint16 port)
 	g_socket_bind (gv_stream->socket, gv_stream->incoming_address, TRUE, NULL);
 
 	thread_data = g_new (ArvGvStreamThreadData, 1);
+	thread_data->callback = callback;
+	thread_data->user_data = user_data;
 	thread_data->socket = gv_stream->socket;
 	thread_data->device_address = g_inet_socket_address_new (device_address, ARV_GVCP_PORT);
 	thread_data->cancel = FALSE;
diff --git a/src/arvgvstream.h b/src/arvgvstream.h
index 70e0034..d45de01 100644
--- a/src/arvgvstream.h
+++ b/src/arvgvstream.h
@@ -59,7 +59,8 @@ struct _ArvGvStreamClass {
 
 GType arv_gv_stream_get_type (void);
 
-ArvStream * 		arv_gv_stream_new 		(GInetAddress *device_address, guint16 port);
+ArvStream * 		arv_gv_stream_new		(GInetAddress *device_address, guint16 port,
+							 ArvStreamCallback callback, void *user_data);
 guint16 		arv_gv_stream_get_port		(ArvGvStream *gv_stream);
 void			arv_gv_stream_set_option	(ArvGvStream *gv_stream, ArvGvStreamOption option,
 							 int value);
diff --git a/src/arvstream.h b/src/arvstream.h
index 7600062..2cb89ce 100644
--- a/src/arvstream.h
+++ b/src/arvstream.h
@@ -27,6 +27,15 @@
 
 G_BEGIN_DECLS
 
+typedef enum {
+	ARV_STREAM_CALLBACK_TYPE_INIT,
+	ARV_STREAM_CALLBACK_TYPE_EXIT,
+	ARV_STREAM_CALLBACK_TYPE_START_BUFFER,
+	ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE
+} ArvStreamCallbackType;
+
+typedef void (*ArvStreamCallback)	(void *user_data, ArvStreamCallbackType type, ArvBuffer *buffer);
+
 #define ARV_TYPE_STREAM             (arv_stream_get_type ())
 #define ARV_STREAM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_STREAM, ArvStream))
 #define ARV_STREAM_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_STREAM, ArvStreamClass))
diff --git a/src/arvtypes.h b/src/arvtypes.h
index f980855..97c5c0c 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -60,7 +60,7 @@ typedef struct _ArvGvDevice 		ArvGvDevice;
 typedef struct _ArvGvStream 		ArvGvStream;
 
 typedef struct _ArvZip			ArvZip;
-typedef struct _ArvZipFile ArvZipFile;
+typedef struct _ArvZipFile 		ArvZipFile;
 
 G_END_DECLS
 



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