[aravis/chunk: 3/6] buffer: chunk data accessor



commit cfd9b14e85cb7d228c965eab5b6cffa7c4b5e6a0
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Aug 18 17:56:13 2014 +0200

    buffer: chunk data accessor

 src/arvbuffer.c     |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/arvbuffer.h     |   14 +++++++----
 src/arvfakecamera.c |    1 +
 src/arvgvsp.h       |   39 ++++++++++++++++++++++++++++++++-
 src/arvgvstream.c   |    1 +
 5 files changed, 108 insertions(+), 6 deletions(-)
---
diff --git a/src/arvbuffer.c b/src/arvbuffer.c
index 50f7aa5..e043e17 100644
--- a/src/arvbuffer.c
+++ b/src/arvbuffer.c
@@ -157,6 +157,65 @@ arv_buffer_get_data (ArvBuffer *buffer, size_t *size)
        return buffer->data;
 }
 
+typedef struct ARAVIS_PACKED_STRUCTURE {
+       guint32 id;
+       guint32 size;
+} ArvChunkInfos;
+
+/**
+ * arv_buffer_get_chunk_data:
+ * @buffer: a #ArvBuffer
+ * @chunk_id: chunk id
+ * @size: (allow-none): location to store chunk data size, or %NULL
+ *
+ * Chunk data accessor.
+ *
+ * Returns: (array length=size) (element-type guint8): a pointer to the chunk data.
+ *
+ * Since: 0.3.5
+ **/
+
+const void *
+arv_buffer_get_chunk_data (ArvBuffer *buffer, guint64 chunk_id, size_t *size)
+{
+       ArvChunkInfos *infos;
+       char *data;
+       ptrdiff_t offset;
+
+       if (size != NULL)
+               *size = 0;
+
+       g_return_val_if_fail (ARV_IS_BUFFER (buffer), NULL);
+       g_return_val_if_fail (buffer->data != NULL, NULL);
+       g_return_val_if_fail (buffer->payload_type == ARV_GVSP_PAYLOAD_TYPE_CHUNK_DATA, NULL);
+
+       if (buffer->status != ARV_BUFFER_STATUS_SUCCESS)
+               return NULL;
+
+       data = buffer->data;
+       offset = buffer->size - sizeof (ArvChunkInfos);
+       while (offset > 0) {
+               infos = (ArvChunkInfos *) &data[offset];
+               if (GUINT32_FROM_BE (infos->id) == chunk_id) {
+                       ptrdiff_t data_offset;
+
+                       data_offset = offset - GUINT32_FROM_BE (infos->size);
+                       if (data_offset >= 0) {
+                               if (size != NULL)
+                                       *size = GUINT32_FROM_BE (infos->size);
+                               return &data[data_offset];
+                       } else
+                               return NULL;
+               }
+               if (GUINT32_FROM_BE (infos->size) > 0)
+                       offset = offset - GUINT32_FROM_BE (infos->size) - sizeof (ArvChunkInfos);
+               else
+                       offset = 0;
+       };
+
+       return NULL;
+}
+
 static void
 arv_buffer_init (ArvBuffer *buffer)
 {
diff --git a/src/arvbuffer.h b/src/arvbuffer.h
index c454486..3fef727 100644
--- a/src/arvbuffer.h
+++ b/src/arvbuffer.h
@@ -24,6 +24,7 @@
 #define ARV_BUFFER_H
 
 #include <arvtypes.h>
+#include <arvgvsp.h>
 
 G_BEGIN_DECLS
 
@@ -73,6 +74,8 @@ struct _ArvBuffer {
 
        ArvBufferStatus status;
 
+       ArvGvspPayloadType payload_type;
+
        guint32 frame_id;
        guint64 timestamp_ns;
 
@@ -90,11 +93,12 @@ struct _ArvBufferClass {
 
 GType arv_buffer_get_type (void);
 
-ArvBuffer *    arv_buffer_new_allocate (size_t size);
-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);
-const void *   arv_buffer_get_data     (ArvBuffer *buffer, size_t *size);
+ArvBuffer *    arv_buffer_new_allocate         (size_t size);
+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);
+const void *   arv_buffer_get_data             (ArvBuffer *buffer, size_t *size);
+const void *   arv_buffer_get_chunk_data       (ArvBuffer *buffer, guint64 chunk_id, size_t *size);
 
 G_END_DECLS
 
diff --git a/src/arvfakecamera.c b/src/arvfakecamera.c
index beb6330..92c18ad 100644
--- a/src/arvfakecamera.c
+++ b/src/arvfakecamera.c
@@ -279,6 +279,7 @@ arv_fake_camera_fill_buffer (ArvFakeCamera *camera, ArvBuffer *buffer, guint32 *
                return;
        }
 
+       buffer->payload_type = ARV_GVSP_PAYLOAD_TYPE_IMAGE;
        buffer->width = width;
        buffer->height = height;
        buffer->status = ARV_BUFFER_STATUS_SUCCESS;
diff --git a/src/arvgvsp.h b/src/arvgvsp.h
index 2278af9..1b2061f 100644
--- a/src/arvgvsp.h
+++ b/src/arvgvsp.h
@@ -60,6 +60,33 @@ typedef enum {
        ARV_GVSP_CONTENT_TYPE_DATA_BLOCK =      0x03
 } ArvGvspContentType;
 
+/**
+ * ArvGvspPayloadType:
+ * @ARV_GVSP_PAYLOAD_TYPE_IMAGE: image data
+ * @ARV_GVSP_PAYLOAD_TYPE_RAWDATA: raw data
+ * @ARV_GVSP_PAYLOAD_TYPE_FILE: file
+ * @ARV_GVSP_PAYLOAD_TYPE_CHUNK_DATA: chunk data
+ * @ARV_GVSP_PAYLOAD_TYPE_EXTENDED_CHUNK_DATA: extended chink data
+ * @ARV_GVSP_PAYLOAD_TYPE_JPEG: JPEG data
+ * @ARV_GVSP_PAYLOAD_TYPE_JPEG2000: JPEG2000 data
+ * @ARV_GVSP_PAYLOAD_TYPE_H264: h264 data
+ * @ARV_GVSP_PAYLOAD_TYPE_MULTIZONE_IMAGE: multizone image
+ * @ARV_GVSP_PAYLOAD_TYPE_DEVICE_PSECIFIC_START: device specific
+*/
+
+typedef enum {
+       ARV_GVSP_PAYLOAD_TYPE_IMAGE =                   0x0001,
+       ARV_GVSP_PAYLOAD_TYPE_RAWDATA =                 0x0002,
+       ARV_GVSP_PAYLOAD_TYPE_FILE =                    0x0003,
+       ARV_GVSP_PAYLOAD_TYPE_CHUNK_DATA =              0x0004,
+       ARV_GVSP_PAYLOAD_TYPE_EXTENDED_CHUNK_DATA =     0x0005, /* Deprecated */
+       ARV_GVSP_PAYLOAD_TYPE_JPEG =                    0x0006,
+       ARV_GVSP_PAYLOAD_TYPE_JPEG2000 =                0x0007,
+       ARV_GVSP_PAYLOAD_TYPE_H264 =                    0x0008,
+       ARV_GVSP_PAYLOAD_TYPE_MULTIZONE_IMAGE =         0x0009,
+       ARV_GVSP_PAYLOAD_TYPE_DEVICE_PSECIFIC_START =   0x8000
+} ArvGvspPayloadType;
+
 #define ARAVIS_PACKED_STRUCTURE __attribute__((__packed__))
 
 /**
@@ -115,7 +142,6 @@ typedef struct ARAVIS_PACKED_STRUCTURE {
        guint32 data1;
 } ArvGvspDataTrailer;
 
-#undef ARAVIS_PACKED_STRUCTURE
 
 /**
  * ArvGvspPacket:
@@ -130,6 +156,8 @@ typedef struct ARAVIS_PACKED_STRUCTURE {
        guint8 data[];
 } ArvGvspPacket;
 
+#undef ARAVIS_PACKED_STRUCTURE
+
 ArvGvspPacket *                arv_gvsp_packet_new_data_leader         (guint16 frame_id, guint32 packet_id,
                                                                 guint64 timestamp, ArvPixelFormat 
pixel_format,
                                                                 guint32 width, guint32 height,
@@ -168,6 +196,15 @@ arv_gvsp_packet_get_frame_id (const ArvGvspPacket *packet)
        return g_ntohs (packet->header.frame_id);
 }
 
+static inline ArvGvspPayloadType
+arv_gvsp_packet_get_payload_type (const ArvGvspPacket *packet)
+{
+       ArvGvspDataLeader *leader;
+
+       leader = (ArvGvspDataLeader *) &packet->data;
+       return g_ntohl (leader->payload_type);
+}
+
 static inline guint32
 arv_gvsp_packet_get_x_offset (const ArvGvspPacket *packet)
 {
diff --git a/src/arvgvstream.c b/src/arvgvstream.c
index b27a5d9..5948b17 100644
--- a/src/arvgvstream.c
+++ b/src/arvgvstream.c
@@ -194,6 +194,7 @@ _process_data_leader (ArvGvStreamThreadData *thread_data,
                return;
        }
 
+       frame->buffer->payload_type = arv_gvsp_packet_get_payload_type (packet);
        frame->buffer->x_offset = arv_gvsp_packet_get_x_offset (packet);
        frame->buffer->y_offset = arv_gvsp_packet_get_y_offset (packet);
        frame->buffer->width = arv_gvsp_packet_get_width (packet);


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