[aravis] fake: fill the buffer with a test pattern.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] fake: fill the buffer with a test pattern.
- Date: Sun, 16 May 2010 19:55:08 +0000 (UTC)
commit a313145d743991c340e3b035ec31a3500a287d5e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun May 16 21:47:41 2010 +0200
fake: fill the buffer with a test pattern.
src/arv-fake-camera.xml | 57 ++++++++++++++++++++++++++++++
src/arvfakecamera.c | 87 ++++++++++++++++++++++++++++++++++++++++++++--
src/arvfakecamera.h | 6 +++-
src/arvfakestream.c | 12 ++++++
4 files changed, 157 insertions(+), 5 deletions(-)
---
diff --git a/src/arv-fake-camera.xml b/src/arv-fake-camera.xml
index caa959f..47a2b59 100644
--- a/src/arv-fake-camera.xml
+++ b/src/arv-fake-camera.xml
@@ -116,6 +116,40 @@
<Endianess>LittleEndian</Endianess>
</IntReg>
+ <Integer Name="OffsetX" NameSpace="Standard">
+ <Description>X offset of image, in pixels.</Description>
+ <pValue>OffsetXRegister</pValue>
+ <Min>0</Min>
+ <pMax>SensorWidth</pMax>
+ <Inc>1</Inc>
+ </Integer>
+
+ <IntReg Name="OffsetXRegister" NameSpace="Custom">
+ <Address>0x130</Address>
+ <Length>4</Length>
+ <AccessMode>RW</AccessMode>
+ <pPort>Device</pPort>
+ <Sign>Unsigned</Sign>
+ <Endianess>LittleEndian</Endianess>
+ </IntReg>
+
+ <Integer Name="OffsetY" NameSpace="Standard">
+ <Description>Y offset of image, in pixels.</Description>
+ <pValue>OffsetYRegister</pValue>
+ <Min>0</Min>
+ <pMax>SensorHeight</pMax>
+ <Inc>1</Inc>
+ </Integer>
+
+ <IntReg Name="OffsetYRegister" NameSpace="Custom">
+ <Address>0x134</Address>
+ <Length>4</Length>
+ <AccessMode>RW</AccessMode>
+ <pPort>Device</pPort>
+ <Sign>Unsigned</Sign>
+ <Endianess>LittleEndian</Endianess>
+ </IntReg>
+
<Integer Name="Width" NameSpace="Standard">
<Description>Width of image, in pixels.</Description>
<pValue>WidthRegister</pValue>
@@ -228,6 +262,29 @@
<Endianess>LittleEndian</Endianess>
</IntReg>
+ <Enumeration Name="AcquisitionMode" NameSpace="Standard">
+ <DisplayName>Acquisition mode</DisplayName>
+ <EnumEntry Name="Continuous" NameSpace="Standard">
+ <Value>1</Value>
+ </EnumEntry>
+ <EnumEntry Name="SingleFrame" NameSpace="Standard">
+ <Value>2</Value>
+ </EnumEntry>
+ <EnumEntry Name="MultiFrame" NameSpace="Standard">
+ <Value>3</Value>
+ </EnumEntry>
+ <pValue>AcquisitionModeRegister</pValue>
+ </Enumeration>
+
+ <IntReg Name="AcquisitionModeRegister" NameSpace="Custom">
+ <Address>0x12c</Address>
+ <Length>4</Length>
+ <AccessMode>RW</AccessMode>
+ <pPort>Device</pPort>
+ <Sign>Unsigned</Sign>
+ <Endianess>LittleEndian</Endianess>
+ </IntReg>
+
<Enumeration Name="TriggerSelector" NameSpace="Standard">
<EnumEntry Name="FrameStart" NameSpace="Standard">
<Value>0</Value>
diff --git a/src/arvfakecamera.c b/src/arvfakecamera.c
index 539ff05..4dd4479 100644
--- a/src/arvfakecamera.c
+++ b/src/arvfakecamera.c
@@ -24,6 +24,7 @@
#include <arvgc.h>
#include <arvgcregister.h>
#include <arvgvcp.h>
+#include <arvbuffer.h>
#include <arvdebug.h>
#include <string.h>
@@ -33,6 +34,9 @@ struct _ArvFakeCameraPrivate {
void *memory;
const void *genicam_data;
size_t genicam_data_size;
+
+ guint32 frame_id;
+ double trigger_frequency;
};
static const char *arv_fake_camera_genicam_filename = NULL;
@@ -92,15 +96,85 @@ arv_fake_camera_write_register (ArvFakeCamera *camera, guint32 address, guint32
return arv_fake_camera_write_memory (camera, address, sizeof (value), &value);
}
+static guint32
+_get_register (ArvFakeCamera *camera, guint32 address)
+{
+ if (address + sizeof (guint32) > ARV_FAKE_CAMERA_MEMORY_SIZE)
+ return 0;
+
+ return *((guint32 *) ((void*) (camera->priv->memory + address)));
+}
+
+void
+arv_fake_camera_wait_for_next_frame (ArvFakeCamera *camera)
+{
+ struct timespec time;
+ struct timespec sleep_time;
+ guint64 sleep_time_ns;
+ guint64 frame_period_time_ns;
+
+ if (_get_register (camera, ARV_FAKE_CAMERA_REGISTER_TRIGGER_MODE) == 1)
+ frame_period_time_ns = 1000000000L / camera->priv->trigger_frequency;
+ else
+ frame_period_time_ns = (guint64) _get_register (camera, ARV_FAKE_CAMERA_REGISTER_EXPOSURE_TIME_US) *
+ 1000L;
+
+ clock_gettime (CLOCK_MONOTONIC, &time);
+ sleep_time_ns = frame_period_time_ns - (((guint64) time.tv_sec * 1000000000L +
+ (guint64) time.tv_nsec) % frame_period_time_ns);
+
+ sleep_time.tv_sec = sleep_time_ns / 1000000000L;
+ sleep_time.tv_nsec = sleep_time_ns % 1000000000L;
+
+ nanosleep (&sleep_time, NULL);
+}
+
void
arv_fake_camera_fill_buffer (ArvFakeCamera *camera, ArvBuffer *buffer)
{
+ struct timespec time;
+ guint32 width;
+ guint32 height;
+ guint32 x_offset, y_offset;
+ size_t payload;
+ guint32 x, y;
+
+ if (camera == NULL || buffer == NULL)
+ return;
+
+ clock_gettime (CLOCK_MONOTONIC, &time);
+
+ width = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_WIDTH);
+ height = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_HEIGHT);
+ x_offset = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_X_OFFSET);
+ y_offset = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_Y_OFFSET);
+ payload = width * height;
+
+ if (buffer->size != payload) {
+ buffer->status = ARV_BUFFER_STATUS_SIZE_MISMATCH;
+ return;
+ }
+
+ buffer->width = width;
+ buffer->height = height;
+ buffer->status = ARV_BUFFER_STATUS_SUCCESS;
+ buffer->timestamp_ns = time.tv_sec * 1000000000L + time.tv_nsec;
+ buffer->frame_id = camera->priv->frame_id++;
+ buffer->pixel_format = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_PIXEL_FORMAT);
+
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++)
+ ((char *) buffer->data)[y * height + x] = (x + buffer->frame_id + y) % 255;
}
-guint32
-arv_fake_camera_get_frame_period (ArvFakeCamera *camera)
+void
+arv_fake_camera_set_trigger_frequency (ArvFakeCamera *camera, double frequency)
{
- return 0;
+ g_return_if_fail (ARV_IS_FAKE_CAMERA (camera));
+ g_return_if_fail (frequency > 0.0);
+
+ camera->priv->trigger_frequency = frequency;
+ camera->priv->frame_id = 0;
}
void
@@ -183,12 +257,15 @@ arv_fake_camera_new (const char *serial_number)
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_SENSOR_HEIGHT, 2048);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_WIDTH, 512);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_HEIGHT, 512);
+ arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_X_OFFSET, 0);
+ arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_Y_OFFSET, 0);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_BINNING_HORIZONTAL, 1);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_BINNING_VERTICAL, 1);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_PIXEL_FORMAT, ARV_PIXEL_FORMAT_MONO_8);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_ACQUISITION, 0);
- arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_EXPOSURE_TIME_US, 40000);
+ arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_ACQUISITION_MODE, 1);
+ arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_EXPOSURE_TIME_US, 20000);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_GAIN_RAW, 0);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_GAIN_MODE, 0);
@@ -200,6 +277,8 @@ static void
arv_fake_camera_init (ArvFakeCamera *fake_camera)
{
fake_camera->priv = G_TYPE_INSTANCE_GET_PRIVATE (fake_camera, ARV_TYPE_FAKE_CAMERA, ArvFakeCameraPrivate);
+
+ fake_camera->priv->trigger_frequency = 25.0;
}
static void
diff --git a/src/arvfakecamera.h b/src/arvfakecamera.h
index c49b5c5..39e0248 100644
--- a/src/arvfakecamera.h
+++ b/src/arvfakecamera.h
@@ -37,12 +37,16 @@ G_BEGIN_DECLS
#define ARV_FAKE_CAMERA_REGISTER_SENSOR_HEIGHT 0x118
#define ARV_FAKE_CAMERA_REGISTER_WIDTH 0x100
#define ARV_FAKE_CAMERA_REGISTER_HEIGHT 0x104
+#define ARV_FAKE_CAMERA_REGISTER_X_OFFSET 0x130
+#define ARV_FAKE_CAMERA_REGISTER_Y_OFFSET 0x134
#define ARV_FAKE_CAMERA_REGISTER_BINNING_HORIZONTAL 0x108
#define ARV_FAKE_CAMERA_REGISTER_BINNING_VERTICAL 0x10c
#define ARV_FAKE_CAMERA_REGISTER_PIXEL_FORMAT 0x128
/* Acquisition control */
+#define ARV_FAKE_CAMERA_REGISTER_ACQUISITION_MODE 0x12c
+
#define ARV_FAKE_CAMERA_REGISTER_TRIGGER_OFFSET 0x020
#define ARV_FAKE_CAMERA_REGISTER_TRIGGER_MODE 0x300
@@ -84,8 +88,8 @@ gboolean arv_fake_camera_write_memory (ArvFakeCamera *camera, guint32 address, g
gboolean arv_fake_camera_read_register (ArvFakeCamera *camera, guint32 address, guint32 *value);
gboolean arv_fake_camera_write_register (ArvFakeCamera *camera, guint32 address, guint32 value);
+void arv_fake_camera_wait_for_next_frame (ArvFakeCamera *camera);
void arv_fake_camera_fill_buffer (ArvFakeCamera *camera, ArvBuffer *buffer);
-guint32 arv_fake_camera_get_frame_period (ArvFakeCamera *camera);
void arv_set_fake_camera_genicam_filename (const char *filename);
const char * arv_get_fake_camera_genicam_data (size_t *size);
diff --git a/src/arvfakestream.c b/src/arvfakestream.c
index 34958e6..3814f3c 100644
--- a/src/arvfakestream.c
+++ b/src/arvfakestream.c
@@ -36,6 +36,8 @@ struct _ArvFakeStreamPrivate {
/* Acquisition thread */
typedef struct {
+ ArvFakeCamera *camera;
+
ArvStreamCallback callback;
void *user_data;
@@ -54,10 +56,19 @@ static void *
arv_fake_stream_thread (void *data)
{
ArvFakeStreamThreadData *thread_data = data;
+ ArvBuffer *buffer;
if (thread_data->callback != NULL)
thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_INIT, NULL);
+ while (!thread_data->cancel) {
+ arv_fake_camera_wait_for_next_frame (thread_data->camera);
+ buffer = g_async_queue_try_pop (thread_data->input_queue);
+ arv_fake_camera_fill_buffer (thread_data->camera, buffer);
+ if (buffer != NULL)
+ 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);
@@ -82,6 +93,7 @@ arv_fake_stream_new (ArvFakeCamera *camera, ArvStreamCallback callback, void *us
stream = ARV_STREAM (fake_stream);
thread_data = g_new (ArvFakeStreamThreadData, 1);
+ thread_data->camera = camera;
thread_data->callback = callback;
thread_data->user_data = user_data;
thread_data->cancel = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]