[aravis] buffer: add a timestamp setter



commit e8911f7ecf061b032c83abc2e85773e3af48b54e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Tue May 17 17:41:29 2016 +0200

    buffer: add a timestamp setter
    
    Sometimes, timestamp set by the camera is incorrect, so it can be useful
    to let the user set the buffer timestamp.
    
    Another use is when the camera is triggered by an external clock, which
    is most probably not in synch with the internal camera clock.

 docs/reference/aravis/aravis-sections.txt |    1 +
 src/arvbuffer.c                           |   19 +++++++++++++++++++
 src/arvbuffer.h                           |    1 +
 tests/buffer.c                            |   16 ++++++++++++++++
 4 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index a7fdeff..91683fd 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -98,6 +98,7 @@ arv_buffer_get_user_data
 arv_buffer_get_data
 arv_buffer_get_chunk_data
 arv_buffer_get_timestamp
+arv_buffer_set_timestamp
 arv_buffer_get_frame_id
 arv_buffer_get_payload_type
 arv_buffer_get_status
diff --git a/src/arvbuffer.c b/src/arvbuffer.c
index 49684ae..a383d12 100644
--- a/src/arvbuffer.c
+++ b/src/arvbuffer.c
@@ -316,6 +316,25 @@ arv_buffer_get_timestamp (ArvBuffer *buffer)
 }
 
 /**
+ * arv_buffer_set_timestamp:
+ * @buffer: a #ArvBuffer
+ * @timestamp_ns: a timestamp, expressed as nanoseconds
+ *
+ * Sets the buffer timestamp, which allows to override the timpestamp set by
+ * the camera, which in some case is incorrect.
+ *
+ * Since: 0.4.0
+ */
+
+void
+arv_buffer_set_timestamp (ArvBuffer *buffer, guint64 timestamp_ns)
+{
+       g_return_if_fail (ARV_IS_BUFFER (buffer));
+
+       buffer->priv->timestamp_ns = timestamp_ns;
+}
+
+/**
  * arv_buffer_get_frame_id:
  * @buffer: a #ArvBuffer
  *
diff --git a/src/arvbuffer.h b/src/arvbuffer.h
index f36b258..3ef8088 100644
--- a/src/arvbuffer.h
+++ b/src/arvbuffer.h
@@ -114,6 +114,7 @@ const void *                arv_buffer_get_user_data        (ArvBuffer *buffer);
 
 ArvBufferPayloadType   arv_buffer_get_payload_type     (ArvBuffer *buffer);
 guint64                        arv_buffer_get_timestamp        (ArvBuffer *buffer);
+void                   arv_buffer_set_timestamp        (ArvBuffer *buffer, guint64 timestamp_ns);
 guint32                arv_buffer_get_frame_id         (ArvBuffer *buffer);
 const void *           arv_buffer_get_data             (ArvBuffer *buffer, size_t *size);
 
diff --git a/tests/buffer.c b/tests/buffer.c
index 4388499..47c9d99 100644
--- a/tests/buffer.c
+++ b/tests/buffer.c
@@ -74,6 +74,21 @@ full_buffer_test (void)
        g_assert (value == 4321);
 }
 
+static void
+timestamp (void)
+{
+       ArvBuffer *buffer;
+
+       buffer = arv_buffer_new (1024, NULL);
+       g_assert (ARV_IS_BUFFER (buffer));
+       g_assert_cmpint (arv_buffer_get_timestamp (buffer), == , 0);
+
+       arv_buffer_set_timestamp (buffer, 1234);
+       g_assert_cmpint (arv_buffer_get_timestamp (buffer), == , 1234);
+
+       g_object_unref (buffer);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -86,6 +101,7 @@ main (int argc, char *argv[])
        g_test_add_func ("/buffer/simple-buffer", simple_buffer_test);
        g_test_add_func ("/buffer/preallocated-buffer", preallocated_buffer_test);
        g_test_add_func ("/buffer/full-buffer", full_buffer_test);
+       g_test_add_func ("/buffer/timestamp", timestamp);
 
        result = g_test_run();
 


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