[aravis] gv_stream: use glib properties for packet resend and socket buffer size.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] gv_stream: use glib properties for packet resend and socket buffer size.
- Date: Thu, 10 Feb 2011 21:14:40 +0000 (UTC)
commit 79d219c10a3e47003460651e8445e330684b0ee1
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Thu Feb 10 22:13:46 2011 +0100
gv_stream: use glib properties for packet resend and socket buffer size.
docs/reference/aravis/aravis-sections.txt | 4 +-
src/arvgvstream.c | 124 +++++++++++++++++++++--------
src/arvgvstream.h | 15 ++--
src/arvstream.c | 2 -
tests/arvcameratest.c | 15 ++--
tests/arvtest.c | 7 +-
6 files changed, 108 insertions(+), 59 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index ddb4272..0a7972e 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -643,13 +643,11 @@ ArvGcStringInterface
<SECTION>
<FILE>arvgvstream</FILE>
<TITLE>ArvGvStream</TITLE>
-ArvGvStreamOption
+ArvGvStreamSocketBuffer
ArvGvStreamPacketResend
ArvGvStream
arv_gv_stream_new
arv_gv_stream_get_port
-arv_gv_stream_set_option
-arv_gv_stream_set_packet_resend
arv_gv_stream_get_statistics
<SUBSECTION Standard>
ARV_GV_STREAM
diff --git a/src/arvgvstream.c b/src/arvgvstream.c
index 779aa9d..5a805eb 100644
--- a/src/arvgvstream.c
+++ b/src/arvgvstream.c
@@ -31,11 +31,19 @@
#include <arvgvcp.h>
#include <arvdebug.h>
#include <arvtools.h>
+#include <arvenumtypes.h>
#include <string.h>
#include <sys/socket.h>
#define ARV_GV_STREAM_INCOMING_BUFFER_SIZE 65536
+enum {
+ ARV_GV_STREAM_PROPERTY_0,
+ ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER,
+ ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER_SIZE,
+ ARV_GV_STREAM_PROPERTY_PACKET_RESEND
+} ArvGvStreamProperties;
+
static GObjectClass *parent_class = NULL;
/* Acquisition thread */
@@ -71,7 +79,7 @@ typedef struct {
ArvStatistic *statistic;
- ArvGvStreamOption socket_buffer_option;
+ ArvGvStreamSocketBuffer socket_buffer_option;
int socket_buffer_size;
int current_socket_buffer_size;
} ArvGvStreamThreadData;
@@ -104,17 +112,17 @@ _update_socket (ArvGvStreamThreadData *thread_data, ArvBuffer *buffer)
{
int buffer_size, fd;
- if (thread_data->socket_buffer_option == ARV_GV_STREAM_OPTION_SOCKET_BUFFER_FIXED &&
+ if (thread_data->socket_buffer_option == ARV_GV_STREAM_SOCKET_BUFFER_FIXED &&
thread_data->socket_buffer_size <= 0)
return;
fd = g_socket_get_fd (thread_data->socket);
switch (thread_data->socket_buffer_option) {
- case ARV_GV_STREAM_OPTION_SOCKET_BUFFER_FIXED:
+ case ARV_GV_STREAM_SOCKET_BUFFER_FIXED:
buffer_size = thread_data->socket_buffer_size;
break;
- case ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO:
+ case ARV_GV_STREAM_SOCKET_BUFFER_AUTO:
if (thread_data->socket_buffer_size <= 0)
buffer_size = buffer->size;
else
@@ -402,36 +410,6 @@ arv_gv_stream_get_port (ArvGvStream *gv_stream)
return g_inet_socket_address_get_port (local_address);
}
-void
-arv_gv_stream_set_option (ArvGvStream *gv_stream, ArvGvStreamOption option, int value)
-{
- ArvGvStreamThreadData *thread_data;
-
- g_return_if_fail (ARV_IS_GV_STREAM (gv_stream));
-
- thread_data = gv_stream->thread_data;
- switch (option) {
- case ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO:
- thread_data->socket_buffer_size = value;
- thread_data->socket_buffer_option = option;
- break;
- case ARV_GV_STREAM_OPTION_SOCKET_BUFFER_FIXED:
- thread_data->socket_buffer_option = option;
- thread_data->socket_buffer_size = value;
- break;
- }
-}
-
-void arv_gv_stream_set_packet_resend (ArvGvStream *gv_stream, ArvGvStreamPacketResend resend)
-{
- ArvGvStreamThreadData *thread_data;
-
- g_return_if_fail (ARV_IS_GV_STREAM (gv_stream));
-
- thread_data = gv_stream->thread_data;
- thread_data->packet_resend = resend;
-}
-
ArvStream *
arv_gv_stream_new (GInetAddress *device_address, guint16 port,
ArvStreamCallback callback, void *user_data,
@@ -485,7 +463,7 @@ arv_gv_stream_new (GInetAddress *device_address, guint16 port,
arv_statistic_set_name (thread_data->statistic, 1, "Local time delta");
arv_statistic_set_name (thread_data->statistic, 2, "Buffer reception time");
- thread_data->socket_buffer_option = ARV_GV_STREAM_OPTION_SOCKET_BUFFER_FIXED;
+ thread_data->socket_buffer_option = ARV_GV_STREAM_SOCKET_BUFFER_FIXED;
thread_data->socket_buffer_size = 0;
thread_data->current_socket_buffer_size = 0;
@@ -536,6 +514,56 @@ _get_statistics (ArvStream *stream,
}
static void
+arv_gv_stream_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ ArvGvStream *gv_stream = ARV_GV_STREAM (object);
+ ArvGvStreamThreadData *thread_data;
+
+ thread_data = gv_stream->thread_data;
+
+ switch (prop_id) {
+ case ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER:
+ thread_data->socket_buffer_option = g_value_get_enum (value);
+ break;
+ case ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER_SIZE:
+ thread_data->socket_buffer_size = g_value_get_int (value);
+ break;
+ case ARV_GV_STREAM_PROPERTY_PACKET_RESEND:
+ thread_data->packet_resend = g_value_get_enum (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+arv_gv_stream_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ ArvGvStream *gv_stream = ARV_GV_STREAM (object);
+ ArvGvStreamThreadData *thread_data;
+
+ thread_data = gv_stream->thread_data;
+
+ switch (prop_id) {
+ case ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER:
+ g_value_set_enum (value, thread_data->socket_buffer_option);
+ break;
+ case ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER_SIZE:
+ g_value_set_int (value, thread_data->socket_buffer_size);
+ break;
+ case ARV_GV_STREAM_PROPERTY_PACKET_RESEND:
+ g_value_set_enum (value, thread_data->packet_resend);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
arv_gv_stream_init (ArvGvStream *gv_stream)
{
}
@@ -600,8 +628,34 @@ arv_gv_stream_class_init (ArvGvStreamClass *gv_stream_class)
parent_class = g_type_class_peek_parent (gv_stream_class);
object_class->finalize = arv_gv_stream_finalize;
+ object_class->set_property = arv_gv_stream_set_property;
+ object_class->get_property = arv_gv_stream_get_property;
stream_class->get_statistics = _get_statistics;
+
+ g_object_class_install_property (
+ object_class, ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER,
+ g_param_spec_enum ("socket-buffer", "Socket buffer",
+ "Socket buffer behaviour",
+ ARV_TYPE_GV_STREAM_SOCKET_BUFFER,
+ ARV_GV_STREAM_SOCKET_BUFFER_AUTO,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
+ );
+ g_object_class_install_property (
+ object_class, ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER_SIZE,
+ g_param_spec_int ("socket-buffer-size", "Socket buffer size",
+ "Socket buffer size, in bytes",
+ -1, G_MAXINT, 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
+ );
+ g_object_class_install_property (
+ object_class, ARV_GV_STREAM_PROPERTY_PACKET_RESEND,
+ g_param_spec_enum ("packet-resend", "Packet resend",
+ "Packet resend behaviour",
+ ARV_TYPE_GV_STREAM_PACKET_RESEND,
+ ARV_GV_STREAM_PACKET_RESEND_ALWAYS,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
+ );
}
G_DEFINE_TYPE (ArvGvStream, arv_gv_stream, ARV_TYPE_STREAM)
diff --git a/src/arvgvstream.h b/src/arvgvstream.h
index 945d82f..e2d7880 100644
--- a/src/arvgvstream.h
+++ b/src/arvgvstream.h
@@ -30,15 +30,15 @@
G_BEGIN_DECLS
/**
- * ArvGvStreamOption:
- * @ARV_GV_STREAM_OPTION_SOCKET_BUFFER_FIXED: socket buffer is set to a given fixed value
- * @ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO: sockect buffer is set with respect to the payload size
+ * ArvGvStreamSocketBuffer:
+ * @ARV_GV_STREAM_SOCKET_BUFFER_FIXED: socket buffer is set to a given fixed value
+ * @ARV_GV_STREAM_SOCKET_BUFFER_AUTO: sockect buffer is set with respect to the payload size
*/
typedef enum {
- ARV_GV_STREAM_OPTION_SOCKET_BUFFER_FIXED,
- ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO
-} ArvGvStreamOption;
+ ARV_GV_STREAM_SOCKET_BUFFER_FIXED,
+ ARV_GV_STREAM_SOCKET_BUFFER_AUTO
+} ArvGvStreamSocketBuffer;
/**
* ArvGvStreamPacketResend:
@@ -80,9 +80,6 @@ ArvStream * arv_gv_stream_new (GInetAddress *device_address, guint16 port,
ArvStreamCallback callback, void *user_data,
guint64 timestamp_tick_frequency);
guint16 arv_gv_stream_get_port (ArvGvStream *gv_stream);
-void arv_gv_stream_set_option (ArvGvStream *gv_stream, ArvGvStreamOption option,
- int value);
-void arv_gv_stream_set_packet_resend (ArvGvStream *gv_stream, ArvGvStreamPacketResend resend);
void arv_gv_stream_get_statistics (ArvGvStream *gv_stream,
guint64 *n_resent_blocks,
diff --git a/src/arvstream.c b/src/arvstream.c
index 73fd2ff..695764f 100644
--- a/src/arvstream.c
+++ b/src/arvstream.c
@@ -49,7 +49,6 @@ enum {
static GObjectClass *parent_class = NULL;
-
struct _ArvStreamPrivate {
GAsyncQueue *input_queue;
GAsyncQueue *output_queue;
@@ -330,7 +329,6 @@ arv_stream_class_init (ArvStreamClass *node_class)
"Emit signals", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
);
-
}
G_DEFINE_ABSTRACT_TYPE (ArvStream, arv_stream, G_TYPE_OBJECT)
diff --git a/tests/arvcameratest.c b/tests/arvcameratest.c
index 501a05d..ec71f30 100644
--- a/tests/arvcameratest.c
+++ b/tests/arvcameratest.c
@@ -5,7 +5,7 @@
static char *arv_option_camera_name = NULL;
static char *arv_option_debug_domains = NULL;
static gboolean arv_option_snaphot = FALSE;
-static gboolean arv_option_auto_buffer = FALSE;
+static int arv_option_auto_socket_buffer = -1;
static char *arv_option_trigger = NULL;
static double arv_option_frequency = -1.0;
static int arv_option_width = -1;
@@ -21,8 +21,8 @@ static const GOptionEntry arv_option_entries[] =
&arv_option_camera_name,"Camera name", NULL},
{ "snapshot", 's', 0, G_OPTION_ARG_NONE,
&arv_option_snaphot, "Snapshot", NULL},
- { "auto", 'a', 0, G_OPTION_ARG_NONE,
- &arv_option_auto_buffer, "Auto buffer size", NULL},
+ { "auto", 'a', 0, G_OPTION_ARG_INT,
+ &arv_option_auto_socket_buffer, "Auto socket buffer size", NULL},
{ "frequency", 'f', 0, G_OPTION_ARG_DOUBLE,
&arv_option_frequency, "Acquisition frequency", NULL },
{ "trigger", 't', 0, G_OPTION_ARG_STRING,
@@ -156,10 +156,11 @@ main (int argc, char **argv)
g_printf ("gain = %d dB\n", gain);
stream = arv_camera_create_stream (camera, NULL, NULL);
- if (arv_option_auto_buffer)
- arv_gv_stream_set_option (ARV_GV_STREAM (stream),
- ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO,
- 0);
+ if (arv_option_auto_socket_buffer >= 0)
+ g_object_set (stream,
+ "socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_AUTO,
+ "socket-buffer-size", arv_option_auto_socket_buffer,
+ NULL);
for (i = 0; i < 50; i++)
arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL));
diff --git a/tests/arvtest.c b/tests/arvtest.c
index 2535838..c881acf 100644
--- a/tests/arvtest.c
+++ b/tests/arvtest.c
@@ -182,9 +182,10 @@ main (int argc, char **argv)
stream = arv_device_create_stream (device, NULL, NULL);
if (arv_option_auto_buffer)
- arv_gv_stream_set_option (ARV_GV_STREAM (stream),
- ARV_GV_STREAM_OPTION_SOCKET_BUFFER_AUTO,
- 0);
+ g_object_set (stream,
+ "socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_AUTO,
+ "socket-buffer-size", 0,
+ NULL);
node = arv_gc_get_node (genicam, "PayloadSize");
value = arv_gc_integer_get_value (ARV_GC_INTEGER (node));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]