libs/gst/dataprotocol/dataprotocol.c: factor out some common header init code
authorThomas Vander Stichele <thomas@apestaart.org>
Fri, 2 Jun 2006 10:58:47 +0000 (10:58 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Fri, 2 Jun 2006 10:58:47 +0000 (10:58 +0000)
Original commit message from CVS:
* libs/gst/dataprotocol/dataprotocol.c:
(gst_dp_header_from_buffer), (gst_dp_packet_from_caps),
(gst_dp_packet_from_event):
factor out some common header init code

ChangeLog
libs/gst/dataprotocol/dataprotocol.c

index c1901fc..721f649 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2006-06-02  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+       * libs/gst/dataprotocol/dataprotocol.c:
+       (gst_dp_header_from_buffer), (gst_dp_packet_from_caps),
+       (gst_dp_packet_from_event):
+         factor out some common header init code
+
+2006-06-02  Thomas Vander Stichele  <thomas at apestaart dot org>
+
        * docs/libs/gstreamer-libs-sections.txt:
        * docs/libs/tmpl/gstdataprotocol.sgml:
        * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_crc):
index 8453b3c..fdfe277 100644 (file)
@@ -1,6 +1,6 @@
 /* GStreamer
  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
- * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
+ * Copyright (C) 2004,2006 Thomas Vander Stichele <thomas at apestaart dot org>
  *
  * dataprotocol.c: Functions implementing the GStreamer Data Protocol
  *
 GST_DEBUG_CATEGORY (data_protocol_debug);
 #define GST_CAT_DEFAULT data_protocol_debug
 
+/* helper macros */
+
+/* write first 6 bytes of header, as well as ABI padding */
+#define GST_DP_INIT_HEADER(h, maj, min, flags, type)           \
+G_STMT_START {                                                 \
+                                                               \
+  h[0] = (guint8) maj;                                         \
+  h[1] = (guint8) min;                                         \
+  h[2] = (guint8) flags;                                       \
+  h[3] = 0; /* padding byte */                                 \
+  GST_WRITE_UINT16_BE (h + 4, type);                           \
+                                                               \
+  GST_WRITE_UINT64_BE (h + 42, (guint64) 0); /* ABI padding */ \
+  GST_WRITE_UINT64_BE (h + 50, (guint64) 0); /* ABI padding */ \
+} G_STMT_END
+
+
 /* calculate a CCITT 16 bit CRC check value for a given byte array */
 /*
  * this code snippet is adapted from a web page I found
@@ -184,11 +201,8 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags,
   h = g_malloc0 (GST_DP_HEADER_LENGTH);
 
   /* version, flags, type */
-  h[0] = (guint8) GST_DP_VERSION_MAJOR;
-  h[1] = (guint8) GST_DP_VERSION_MINOR;
-  h[2] = (guint8) flags;
-  h[3] = 0;                     /* padding byte */
-  GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_BUFFER);
+  GST_DP_INIT_HEADER (h, GST_DP_VERSION_MAJOR, GST_DP_VERSION_MINOR, flags,
+      GST_DP_PAYLOAD_BUFFER);
 
   /* buffer properties */
   GST_WRITE_UINT32_BE (h + 6, GST_BUFFER_SIZE (buffer));
@@ -197,18 +211,13 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags,
   GST_WRITE_UINT64_BE (h + 26, GST_BUFFER_OFFSET (buffer));
   GST_WRITE_UINT64_BE (h + 34, GST_BUFFER_OFFSET_END (buffer));
 
-  /* data flags */
+  /* data flags; eats two bytes from the ABI area */
   /* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */
   flags_mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
       GST_BUFFER_FLAG_DELTA_UNIT;
 
   GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask);
 
-  /* ABI padding */
-  GST_WRITE_UINT64_BE (h + 44, (guint64) 0);
-  GST_WRITE_UINT32_BE (h + 52, (guint32) 0);
-  GST_WRITE_UINT16_BE (h + 56, (guint16) 0);
-
   /* CRC */
   crc = 0;
   if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
@@ -261,11 +270,8 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags,
   string = (guchar *) gst_caps_to_string (caps);
 
   /* version, flags, type */
-  h[0] = (guint8) GST_DP_VERSION_MAJOR;
-  h[1] = (guint8) GST_DP_VERSION_MINOR;
-  h[2] = (guint8) flags;
-  h[3] = 0;                     /* padding bytes */
-  GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_CAPS);
+  GST_DP_INIT_HEADER (h, GST_DP_VERSION_MAJOR, GST_DP_VERSION_MINOR, flags,
+      GST_DP_PAYLOAD_CAPS);
 
   /* buffer properties */
   GST_WRITE_UINT32_BE (h + 6, strlen ((gchar *) string) + 1);   /* include trailing 0 */
@@ -274,10 +280,6 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags,
   GST_WRITE_UINT64_BE (h + 26, (guint64) 0);
   GST_WRITE_UINT64_BE (h + 34, (guint64) 0);
 
-  /* ABI padding */
-  GST_WRITE_UINT64_BE (h + 42, (guint64) 0);
-  GST_WRITE_UINT64_BE (h + 50, (guint64) 0);
-
   /* CRC */
   crc = 0;
   if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
@@ -377,11 +379,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags,
   }
 
   /* version, flags, type */
-  h[0] = (guint8) GST_DP_VERSION_MAJOR;
-  h[1] = (guint8) GST_DP_VERSION_MINOR;
-  h[2] = (guint8) flags;
-  h[3] = 0;                     /* padding byte */
-  GST_WRITE_UINT16_BE (h + 4,
+  GST_DP_INIT_HEADER (h, GST_DP_VERSION_MAJOR, GST_DP_VERSION_MINOR, flags,
       GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event));
 
   /* length */
@@ -389,10 +387,6 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags,
   /* timestamp */
   GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event));
 
-  /* ABI padding */
-  GST_WRITE_UINT64_BE (h + 42, (guint64) 0);
-  GST_WRITE_UINT64_BE (h + 50, (guint64) 0);
-
   /* CRC */
   crc = 0;
   if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
@@ -413,7 +407,6 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags,
   return TRUE;
 }
 
-
 /**
  * gst_dp_buffer_from_header:
  * @header_length: the length of the packet header
@@ -482,7 +475,7 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header,
  *
  * Creates a newly allocated #GstEvent from the given packet.
  *
- * Returns: A #GstEvent if the event was successfully created, 
+ * Returns: A #GstEvent if the event was successfully created,
  *          or NULL if an event could not be read from the payload.
  */
 GstEvent *