[aravis] buffer: add arv_buffer_new_full.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] buffer: add arv_buffer_new_full.
- Date: Wed, 16 Feb 2011 20:03:46 +0000 (UTC)
commit 24549a049baa5616b398cb5bbedf59b5839ceea8
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Wed Feb 16 21:02:47 2011 +0100
buffer: add arv_buffer_new_full.
And remove the user_data parameter from arv_buffer_new.
docs/reference/aravis/aravis-sections.txt | 1 +
gst/gstaravis.c | 41 ++++++++++++++++++++++------
src/arvbuffer.c | 28 ++++++++++++++++++-
src/arvbuffer.h | 5 +++-
src/arvfakegvcamera.c | 2 +-
tests/arvcameratest.c | 2 +-
tests/arvtest.c | 2 +-
viewer/arvviewer.c | 2 +-
8 files changed, 67 insertions(+), 16 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 84a1691..2b2baf2 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -63,6 +63,7 @@ ArvFrameCallback
ArvBufferStatus
ArvBuffer
arv_buffer_new
+arv_buffer_new_full
<SUBSECTION Standard>
ARV_BUFFER
ARV_IS_BUFFER
diff --git a/gst/gstaravis.c b/gst/gstaravis.c
index c735686..28de3df 100644
--- a/gst/gstaravis.c
+++ b/gst/gstaravis.c
@@ -202,7 +202,7 @@ gst_aravis_set_caps (GstBaseSrc *src, GstCaps *caps)
for (i = 0; i < GST_ARAVIS_N_BUFFERS; i++)
arv_stream_push_buffer (gst_aravis->stream,
- arv_buffer_new (gst_aravis->payload, NULL, NULL));
+ arv_buffer_new (gst_aravis->payload, NULL));
GST_LOG_OBJECT (gst_aravis, "Start acquisition");
arv_camera_start_acquisition (gst_aravis->camera);
@@ -255,6 +255,27 @@ gboolean gst_aravis_stop( GstBaseSrc * src )
return TRUE;
}
+static void
+gst_aravis_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
+ GstClockTime * start, GstClockTime * end)
+{
+ if (gst_base_src_is_live (basesrc)) {
+ GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
+
+ if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
+ GstClockTime duration = GST_BUFFER_DURATION (buffer);
+
+ if (GST_CLOCK_TIME_IS_VALID (duration)) {
+ *end = timestamp + duration;
+ }
+ *start = timestamp;
+ }
+ } else {
+ *start = -1;
+ *end = -1;
+ }
+}
+
static GstFlowReturn
gst_aravis_create (GstPushSrc * push_src, GstBuffer ** buffer)
{
@@ -263,16 +284,16 @@ gst_aravis_create (GstPushSrc * push_src, GstBuffer ** buffer)
gst_aravis = GST_ARAVIS (push_src);
- *buffer = gst_buffer_new ();
do {
- arv_buffer = arv_stream_pop_buffer (gst_aravis->stream);
- if (arv_buffer == NULL)
- g_usleep (1000);
- else if (arv_buffer->status != ARV_BUFFER_STATUS_SUCCESS) {
+ arv_buffer = arv_stream_timed_pop_buffer (gst_aravis->stream, 2000000);
+ if (arv_buffer != NULL && arv_buffer->status != ARV_BUFFER_STATUS_SUCCESS)
arv_stream_push_buffer (gst_aravis->stream, arv_buffer);
- arv_buffer = NULL;
- }
- } while (arv_buffer == NULL);
+ } while (arv_buffer != NULL && arv_buffer->status != ARV_BUFFER_STATUS_SUCCESS);
+
+ if (arv_buffer == NULL)
+ return GST_FLOW_ERROR;
+
+ *buffer = gst_buffer_new ();
GST_BUFFER_DATA (*buffer) = arv_buffer->data;
GST_BUFFER_MALLOCDATA (*buffer) = NULL;
@@ -505,6 +526,8 @@ gst_aravis_class_init (GstAravisClass * klass)
gstbasesrc_class->start = gst_aravis_start;
gstbasesrc_class->stop = gst_aravis_stop;
+ gstbasesrc_class->get_times = gst_aravis_get_times;
+
gstpushsrc_class->create = gst_aravis_create;
}
diff --git a/src/arvbuffer.c b/src/arvbuffer.c
index a485699..fb3116e 100644
--- a/src/arvbuffer.c
+++ b/src/arvbuffer.c
@@ -41,21 +41,26 @@ static GObjectClass *parent_class = NULL;
* @size: payload size
* @preallocated: (transfer none): preallocated memory buffer
* @user_data: (transfer none): a pointer to user data associated to this buffer
+ * @user_data_destroy_func: an optional user data destroy callback
*
* Creates a new buffer for the storage of the video stream images.
* The data space can be either preallocated, and the caller is responsible
* for it's deallocation, or allocated by this function. If it is the case,
* data memory will be freed when the buffer is destroyed.
+ *
+ * If @user_data_destroy_func is non NULL, it will be called in order to destroy
+ * user_data when the buffer is destroyed.
*/
ArvBuffer *
-arv_buffer_new (size_t size, void *preallocated, void *user_data)
+arv_buffer_new_full (size_t size, void *preallocated, void *user_data, GDestroyNotify user_data_destroy_func)
{
ArvBuffer *buffer;
buffer = g_object_new (ARV_TYPE_BUFFER, NULL);
buffer->size = size;
buffer->user_data = user_data;
+ buffer->user_data_destroy_func = user_data_destroy_func;
if (preallocated != NULL) {
buffer->is_preallocated = TRUE;
@@ -69,6 +74,23 @@ arv_buffer_new (size_t size, void *preallocated, void *user_data)
}
/**
+ * arv_buffer_new:
+ * @size: payload size
+ * @preallocated: (transfer none): preallocated memory buffer
+ *
+ * Creates a new buffer for the storage of the video stream images.
+ * The data space can be either preallocated, and the caller is responsible
+ * for it's deallocation, or allocated by this function. If it is the case,
+ * data memory will be freed when the buffer is destroyed.
+ */
+
+ArvBuffer *
+arv_buffer_new (size_t size, void *preallocated)
+{
+ return arv_buffer_new_full (size, preallocated, NULL, NULL);
+}
+
+/**
* arv_buffer_clear:
* @buffer: a #ArvBuffer
*
@@ -100,6 +122,9 @@ arv_buffer_finalize (GObject *object)
buffer->size = 0;
}
+ if (buffer->user_data && buffer->user_data_destroy_func)
+ buffer->user_data_destroy_func (buffer->user_data);
+
parent_class->finalize (object);
}
@@ -114,4 +139,3 @@ arv_buffer_class_init (ArvBufferClass *node_class)
}
G_DEFINE_TYPE (ArvBuffer, arv_buffer, G_TYPE_OBJECT)
-
diff --git a/src/arvbuffer.h b/src/arvbuffer.h
index a40ad73..1e616c6 100644
--- a/src/arvbuffer.h
+++ b/src/arvbuffer.h
@@ -65,6 +65,7 @@ struct _ArvBuffer {
void *data;
void *user_data;
+ GDestroyNotify user_data_destroy_func;
ArvBufferStatus status;
@@ -85,7 +86,9 @@ struct _ArvBufferClass {
GType arv_buffer_get_type (void);
-ArvBuffer * arv_buffer_new (size_t size, void *preallocated, void *user_data);
+ArvBuffer * arv_buffer_new (size_t size, void *preallocated);
+ArvBuffer * arv_buffer_new_full (size_t size, void *preallocated,
+ void *user_data, GDestroyNotify user_data_destroy_func);
G_END_DECLS
diff --git a/src/arvfakegvcamera.c b/src/arvfakegvcamera.c
index 95dac70..5bb1bd6 100644
--- a/src/arvfakegvcamera.c
+++ b/src/arvfakegvcamera.c
@@ -125,7 +125,7 @@ arv_fake_gv_camera_thread (void *user_data)
g_free (inet_address_string);
payload = arv_fake_camera_get_payload (gv_camera->camera);
- image_buffer = arv_buffer_new (payload, NULL, NULL);
+ image_buffer = arv_buffer_new (payload, NULL);
}
arv_fake_camera_wait_for_next_frame (gv_camera->camera);
diff --git a/tests/arvcameratest.c b/tests/arvcameratest.c
index 45deadb..ec71f30 100644
--- a/tests/arvcameratest.c
+++ b/tests/arvcameratest.c
@@ -163,7 +163,7 @@ main (int argc, char **argv)
NULL);
for (i = 0; i < 50; i++)
- arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL, NULL));
+ arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL));
arv_camera_set_acquisition_mode (camera, ARV_ACQUISITION_MODE_CONTINUOUS);
diff --git a/tests/arvtest.c b/tests/arvtest.c
index 5f5c60d..c881acf 100644
--- a/tests/arvtest.c
+++ b/tests/arvtest.c
@@ -192,7 +192,7 @@ main (int argc, char **argv)
g_print ("payload size = %d (0x%x)\n", value, value);
for (i = 0; i < 30; i++)
- arv_stream_push_buffer (stream, arv_buffer_new (value, NULL, NULL));
+ arv_stream_push_buffer (stream, arv_buffer_new (value, NULL));
arv_device_read_register (device, ARV_GVBS_FIRST_STREAM_CHANNEL_PORT, &value);
g_print ("stream port = %d (%d)\n", value, arv_gv_stream_get_port (ARV_GV_STREAM (stream)));
diff --git a/viewer/arvviewer.c b/viewer/arvviewer.c
index 6704abc..b1497ae 100644
--- a/viewer/arvviewer.c
+++ b/viewer/arvviewer.c
@@ -364,7 +364,7 @@ arv_viewer_select_camera_cb (GtkComboBox *combo_box, ArvViewer *viewer)
arv_stream_set_emit_signals (viewer->stream, TRUE);
payload = arv_camera_get_payload (viewer->camera);
for (i = 0; i < 5; i++)
- arv_stream_push_buffer (viewer->stream, arv_buffer_new (payload, NULL, NULL));
+ arv_stream_push_buffer (viewer->stream, arv_buffer_new (payload, NULL));
arv_camera_get_region (viewer->camera, NULL, NULL, &width, &height);
pixel_format = arv_camera_get_pixel_format (viewer->camera);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]