From b9dd8ca0765a02a9556838ba143aec387261862a Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 19 May 2004 16:37:53 +0000 Subject: [PATCH 01/54] gdp: add dataprotocol Original commit message from CVS: clean up libs docs; add dataprotocol --- gst/gdp/dataprotocol.c | 625 +++++++++++++++++++++++++++++++++++++++++ gst/gdp/dataprotocol.h | 100 +++++++ gst/gdp/dp-private.h | 55 ++++ 3 files changed, 780 insertions(+) create mode 100644 gst/gdp/dataprotocol.c create mode 100644 gst/gdp/dataprotocol.h create mode 100644 gst/gdp/dp-private.h diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c new file mode 100644 index 0000000000..cabba42c57 --- /dev/null +++ b/gst/gdp/dataprotocol.c @@ -0,0 +1,625 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2004> Thomas Vander Stichele + * + * dataprotocol.c: Functions implementing the GStreamer Data Protocol + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include /* g_sprintf */ +#include /* strlen */ +#include "dp-private.h" + +/* debug category */ +GST_DEBUG_CATEGORY (data_protocol_debug); +#define GST_CAT_DEFAULT data_protocol_debug + +/*** private functions ***/ + +#define GST_DP_WRITE_GUINT64(buf, value) (*((guint64 *) (buf)) = GUINT64_TO_BE (value)) +#define GST_DP_WRITE_GUINT32(buf, value) (*((guint32 *) (buf)) = GUINT32_TO_BE (value)) +#define GST_DP_WRITE_GUINT16(buf, value) (*((guint16 *) (buf)) = GUINT16_TO_BE (value)) + +/* calculate a CCITT 16 bit CRC check value for a given byte array */ +/* + * this code snippet is adapted from a web page I found + * it is identical except for cleanups, and a final XOR with 0xffff + * as outlined in the uecp spec + * + * XMODEM x^16 + x^12 + x^5 + 1 + */ + +#define POLY 0x1021 +#define CRC_INIT 0xFFFF + +static guint16 +gst_dp_crc (const guint8 * buffer, register guint length) +{ + static gboolean initialized = FALSE; + static guint16 crc_register, crc_table[256]; + unsigned long i, j, k; + + if (!initialized) { + for (i = 0; i < 256; i++) { + j = i << 8; + for (k = 8; k--;) { + j = j & 0x8000 ? (j << 1) ^ POLY : j << 1; + } + + crc_table[i] = (guint16) j; + } + initialized = TRUE; + } + + crc_register = CRC_INIT; /* always init register */ + + /* calc CRC */ + for (; length--;) { + crc_register = (guint16) ((crc_register << 8) ^ + crc_table[((crc_register >> 8) & 0x00ff) ^ *buffer++]); + } + return (0xffff ^ crc_register); +} + +/* debugging function; dumps byte array values per 8 bytes */ +/* FIXME: would be nice to merge this with gst_util_dump_mem () */ +void +gst_dp_dump_byte_array (guint8 * array, guint length) +{ + int i; + int n = 8; /* number of bytes per line */ + gchar *line = g_malloc (3 * n); + + GST_LOG ("dumping byte array of length %d", length); + for (i = 0; i < length; ++i) { + g_sprintf (line + 3 * (i % n), "%02x ", array[i]); + if (i % n == (n - 1)) { + GST_LOG ("%03d: %s", i - (n - 1), line); + } + } + if (i % n != 0) { + GST_LOG ("%03d: %s", (i / n) * n, line); + } + g_free (line); +} + +/** + * gst_dp_init: + * + * Initialize GStreamer Data Protocol library. + * + * Should be called before using these functions; either from source linking + * to this source file or from plugin_init. + */ +void +gst_dp_init (void) +{ + static gboolean _gst_dp_initialized = FALSE; + + if (_gst_dp_initialized) + return; + + _gst_dp_initialized = TRUE; + + GST_DEBUG_CATEGORY_INIT (data_protocol_debug, "gdp", 0, + "GStreamer Data Protocol"); +} + +/*** PUBLIC FUNCTIONS ***/ + +/** + * gst_dp_header_payload_length: + * @header: the byte header of the packet array + * + * Returns: the length of the payload this header describes. + */ +guint32 +gst_dp_header_payload_length (const guint8 * header) +{ + return GST_DP_HEADER_PAYLOAD_LENGTH (header); +} + +/** + * gst_dp_header_payload_type: + * @header: the byte header of the packet array + * + * Returns: the #GstDPPayloadType the payload this header describes. + */ +GstDPPayloadType +gst_dp_header_payload_type (const guint8 * header) +{ + return GST_DP_HEADER_PAYLOAD_TYPE (header); +} + +/** + * gst_dp_header_from_buffer: + * @buffer: a #GstBuffer to create a header for + * @flags: the #GDPHeaderFlags to create the header with + * @length: a guint pointer to store the header length in + * @header: a guint8 * pointer to store a newly allocated header byte array in + * + * Creates a GDP header from the given buffer. + * + * Returns: %TRUE if the header was successfully created + */ + +gboolean +gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, + guint * length, guint8 ** header) +{ + guint8 *h; + guint16 crc; + + g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); + g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buffer) > 0, FALSE); + + *length = GST_DP_HEADER_LENGTH; + h = g_malloc (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] = GST_DP_PAYLOAD_BUFFER; + + /* buffer properties */ + GST_DP_WRITE_GUINT32 (h + 4, GST_BUFFER_SIZE (buffer)); + GST_DP_WRITE_GUINT64 (h + 8, GST_BUFFER_TIMESTAMP (buffer)); + GST_DP_WRITE_GUINT64 (h + 16, GST_BUFFER_DURATION (buffer)); + GST_DP_WRITE_GUINT64 (h + 24, GST_BUFFER_OFFSET (buffer)); + GST_DP_WRITE_GUINT64 (h + 32, GST_BUFFER_OFFSET_END (buffer)); + + /* ABI padding */ + GST_DP_WRITE_GUINT64 (h + 40, (guint64) 0); + GST_DP_WRITE_GUINT64 (h + 48, (guint64) 0); + + /* CRC */ + crc = 0; + if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { + /* we don't crc the last four bytes of the header since they are crc's */ + crc = gst_dp_crc (h, 56); + } + GST_DP_WRITE_GUINT16 (h + 56, crc); + + crc = 0; + if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { + crc = gst_dp_crc (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); + } + GST_DP_WRITE_GUINT16 (h + 58, crc); + + GST_LOG ("created header from buffer:"); + gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; + return TRUE; +} + + /** + * gst_dp_packet_from_caps: + * @caps: a #GstCaps to create a packet for + * @flags: the #GDPHeaderFlags to create the header with + * @length: a guint pointer to store the header length in + * @header: a guint8 pointer to store a newly allocated header byte array in + * @payload: a guint8 pointer to store a newly allocated payload byte array in + * + * Creates a GDP packet from the given caps. + * + * Returns: %TRUE if the packet was successfully created + */ +gboolean +gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload) +{ + guint8 *h; + guint16 crc; + gchar *string; + + /* FIXME: GST_IS_CAPS doesn't work + g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */ + + *length = GST_DP_HEADER_LENGTH; + h = g_malloc (GST_DP_HEADER_LENGTH); + + string = 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] = GST_DP_PAYLOAD_CAPS; + + /* buffer properties */ + GST_DP_WRITE_GUINT32 (h + 4, strlen (string) + 1); /* include trailing 0 */ + GST_DP_WRITE_GUINT64 (h + 8, (guint64) 0); + GST_DP_WRITE_GUINT64 (h + 16, (guint64) 0); + GST_DP_WRITE_GUINT64 (h + 24, (guint64) 0); + GST_DP_WRITE_GUINT64 (h + 32, (guint64) 0); + + /* ABI padding */ + GST_DP_WRITE_GUINT64 (h + 40, (guint64) 0); + GST_DP_WRITE_GUINT64 (h + 48, (guint64) 0); + + /* CRC */ + crc = 0; + if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { + crc = gst_dp_crc (h, 56); + } + GST_DP_WRITE_GUINT16 (h + 56, crc); + + crc = 0; + if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { + crc = gst_dp_crc (string, strlen (string) + 1); + } + GST_DP_WRITE_GUINT16 (h + 58, crc); + + GST_LOG ("created header from caps:"); + gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; + *payload = string; + return TRUE; +} + +/** + * gst_dp_packet_from_event: + * @event: a #GstEvent to create a packet for + * @flags: the #GDPHeaderFlags to create the header with + * @length: a guint pointer to store the header length in + * @header: a guint8 pointer to store a newly allocated header byte array in + * @payload: a guint8 pointer to store a newly allocated payload byte array in + * + * Creates a GDP packet from the given event. + * + * Returns: %TRUE if the packet was successfully created + */ +gboolean +gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload) +{ + guint8 *h; + guint16 crc; + gchar *string = NULL; + guint pl_length; /* length of payload */ + + g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + + *length = GST_DP_HEADER_LENGTH; + h = g_malloc0 (GST_DP_HEADER_LENGTH); + + /* first construct payload, since we need the length */ + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_UNKNOWN: + g_warning ("Unknown event, ignoring"); + *length = 0; + g_free (h); + return FALSE; + case GST_EVENT_EOS: + case GST_EVENT_FLUSH: + case GST_EVENT_EMPTY: + case GST_EVENT_DISCONTINUOUS: + GST_DP_WRITE_GUINT64 (h + 8, GST_EVENT_TIMESTAMP (event)); + pl_length = 0; + *payload = NULL; + break; + case GST_EVENT_SEEK: + pl_length = 4 + 8 + 4; + *payload = g_malloc0 (pl_length); + GST_DP_WRITE_GUINT32 (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); + GST_DP_WRITE_GUINT64 (*payload + 4, + (guint64) GST_EVENT_SEEK_OFFSET (event)); + GST_DP_WRITE_GUINT32 (*payload + 12, + (guint32) GST_EVENT_SEEK_ACCURACY (event)); + break; + case GST_EVENT_SEEK_SEGMENT: + pl_length = 4 + 8 + 8 + 4; + *payload = g_malloc0 (pl_length); + GST_DP_WRITE_GUINT32 (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); + GST_DP_WRITE_GUINT64 (*payload + 4, + (guint64) GST_EVENT_SEEK_OFFSET (event)); + GST_DP_WRITE_GUINT64 (*payload + 12, + (guint64) GST_EVENT_SEEK_ENDOFFSET (event)); + GST_DP_WRITE_GUINT32 (*payload + 20, + (guint32) GST_EVENT_SEEK_ACCURACY (event)); + break; + case GST_EVENT_QOS: + case GST_EVENT_SEGMENT_DONE: + case GST_EVENT_SIZE: + case GST_EVENT_RATE: + case GST_EVENT_FILLER: + case GST_EVENT_TS_OFFSET: + case GST_EVENT_INTERRUPT: + case GST_EVENT_NAVIGATION: + case GST_EVENT_TAG: + g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); + return FALSE; + default: + g_warning ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); + *length = 0; + g_free (h); + return FALSE; + } + + /* version, flags, type */ + h[0] = (guint8) GST_DP_VERSION_MAJOR; + h[1] = (guint8) GST_DP_VERSION_MINOR; + h[2] = (guint8) flags; + h[3] = GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event); + + /* length */ + GST_DP_WRITE_GUINT32 (h + 4, (guint32) pl_length); + /* timestamp */ + GST_DP_WRITE_GUINT64 (h + 8, GST_EVENT_TIMESTAMP (event)); + + /* ABI padding */ + GST_DP_WRITE_GUINT64 (h + 40, (guint64) 0); + GST_DP_WRITE_GUINT64 (h + 48, (guint64) 0); + + /* CRC */ + crc = 0; + if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { + crc = gst_dp_crc (h, 56); + } + GST_DP_WRITE_GUINT16 (h + 56, crc); + + crc = 0; + if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { + crc = gst_dp_crc (string, strlen (string) + 1); + } + GST_DP_WRITE_GUINT16 (h + 58, crc); + + GST_LOG ("created header from event:"); + gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; + return TRUE; +} + + +/** + * gst_dp_buffer_from_header: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * + * Creates a newly allocated #GstBuffer from the given header. + * The buffer data needs to be copied into it before validating. + * + * Use this function if you want to pre-allocate a buffer based on the + * packet header to read the packet payload in to. + * + * Returns: %TRUE if the buffer was successfully created + */ +GstBuffer * +gst_dp_buffer_from_header (guint header_length, const guint8 * header) +{ + GstBuffer *buffer; + + g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == + GST_DP_PAYLOAD_BUFFER, FALSE); + buffer = + gst_buffer_new_and_alloc ((guint) GST_DP_HEADER_PAYLOAD_LENGTH (header)); + GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header); + GST_BUFFER_DURATION (buffer) = GST_DP_HEADER_DURATION (header); + GST_BUFFER_OFFSET (buffer) = GST_DP_HEADER_OFFSET (header); + GST_BUFFER_OFFSET_END (buffer) = GST_DP_HEADER_OFFSET_END (header); + + return buffer; +} + +/** + * gst_dp_caps_from_packet: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * @payload: the byte array of the packet payload + * + * Creates a newly allocated #GstCaps from the given packet. + * + * Returns: %TRUE if the caps was successfully created + */ +GstCaps * +gst_dp_caps_from_packet (guint header_length, const guint8 * header, + const guint8 * payload) +{ + GstCaps *caps; + const gchar *string; + + g_return_val_if_fail (header, FALSE); + g_return_val_if_fail (payload, FALSE); + g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == + GST_DP_PAYLOAD_CAPS, FALSE); + + string = payload; + caps = gst_caps_from_string (string); + return caps; +} + +/** + * gst_dp_event_from_packet: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * @payload: the byte array of the packet payload + * + * Creates a newly allocated #GstEvent from the given packet. + * + * Returns: %TRUE if the event was successfully created + */ +GstEvent * +gst_dp_event_from_packet (guint header_length, const guint8 * header, + const guint8 * payload) +{ + GstEvent *event = NULL; + GstEventType type; + + g_return_val_if_fail (header, FALSE); + /* payload can be NULL, e.g. for an EOS event */ + + type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE; + switch (type) { + case GST_EVENT_UNKNOWN: + g_warning ("Unknown event, ignoring"); + return FALSE; + case GST_EVENT_EOS: + case GST_EVENT_FLUSH: + case GST_EVENT_EMPTY: + case GST_EVENT_DISCONTINUOUS: + event = gst_event_new (type); + GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); + break; + case GST_EVENT_SEEK: + { + GstSeekType type; + gint64 offset; + GstSeekAccuracy accuracy; + + type = (GstSeekType) GST_DP_GUINT32 (payload); + offset = (gint64) GST_DP_GUINT64 (payload + 4); + accuracy = (GstSeekAccuracy) GST_DP_GUINT32 (payload + 12); + event = gst_event_new_seek (type, offset); + GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); + GST_EVENT_SEEK_ACCURACY (event) = accuracy; + break; + } + case GST_EVENT_SEEK_SEGMENT: + { + GstSeekType type; + gint64 offset, endoffset; + GstSeekAccuracy accuracy; + + type = (GstSeekType) GST_DP_GUINT32 (payload); + offset = (gint64) GST_DP_GUINT64 (payload + 4); + endoffset = (gint64) GST_DP_GUINT64 (payload + 12); + accuracy = (GstSeekAccuracy) GST_DP_GUINT32 (payload + 20); + event = gst_event_new_segment_seek (type, offset, endoffset); + GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); + GST_EVENT_SEEK_ACCURACY (event) = accuracy; + break; + } + case GST_EVENT_QOS: + case GST_EVENT_SEGMENT_DONE: + case GST_EVENT_SIZE: + case GST_EVENT_RATE: + case GST_EVENT_FILLER: + case GST_EVENT_TS_OFFSET: + case GST_EVENT_INTERRUPT: + case GST_EVENT_NAVIGATION: + case GST_EVENT_TAG: + g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); + return FALSE; + default: + g_warning ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); + return FALSE; + } + + return event; +} + +/** + * gst_dp_validate_header: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * + * Validates the given packet header by checking the CRC checksum. + * + * Returns: %TRUE if the CRC matches, or no CRC checksum is present + */ +gboolean +gst_dp_validate_header (guint header_length, const guint8 * header) +{ + guint16 crc_read, crc_calculated; + + if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_HEADER)) + return TRUE; + crc_read = GST_DP_HEADER_CRC_HEADER (header); + /* don't included the last two crc fields for the crc check */ + crc_calculated = gst_dp_crc (header, header_length - 4); + if (crc_read != crc_calculated) { + GST_WARNING ("header crc mismatch: read %02x, calculated %02x", crc_read, + crc_calculated); + return FALSE; + } + GST_LOG ("header crc validation: %02x", crc_read); + return TRUE; +} + +/** + * gst_dp_validate_payload: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * @payload: the byte array of the packet payload + * + * Validates the given packet payload using the given packet header + * by checking the CRC checksum. + * + * Returns: %TRUE if the CRC matches, or no CRC checksum is present + */ +gboolean +gst_dp_validate_payload (guint header_length, const guint8 * header, + const guint8 * payload) +{ + guint16 crc_read, crc_calculated; + + if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_PAYLOAD)) + return TRUE; + crc_read = GST_DP_HEADER_CRC_PAYLOAD (header); + crc_calculated = gst_dp_crc (payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); + if (crc_read != crc_calculated) { + GST_WARNING ("payload crc mismatch: read %02x, calculated %02x", crc_read, + crc_calculated); + return FALSE; + } + GST_LOG ("payload crc validation: %02x", crc_read); + return TRUE; +} + +/** + * gst_dp_validate_packet: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * @payload: the byte array of the packet payload + * + * Validates the given packet by checking version information and checksums. + * + * Returns: %TRUE if the packet validates + */ +gboolean +gst_dp_validate_packet (guint header_length, const guint8 * header, + const guint8 * payload) +{ + if (!gst_dp_validate_header (header_length, header)) + return FALSE; + if (!gst_dp_validate_payload (header_length, header, payload)) + return FALSE; + + return TRUE; +} + +/*** PLUGIN STUFF ***/ +static gboolean +plugin_init (GstPlugin * plugin) +{ + gst_dp_init (); + + return TRUE; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gstdataprotocol", + "a data protocol to serialize buffers, caps and events", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h new file mode 100644 index 0000000000..76b1d62a1e --- /dev/null +++ b/gst/gdp/dataprotocol.h @@ -0,0 +1,100 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2004> Thomas Vander Stichele + * + * dataprotocol.h: Functions implementing the GStreamer Data Protocol + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_DATA_PROTOCOL_H__ +#define __GST_DATA_PROTOCOL_H__ + +#include +#include +#include +#include + +G_BEGIN_DECLS + +/* GStreamer Data Protocol Version */ +#define GST_DP_VERSION_MAJOR 0 +#define GST_DP_VERSION_MINOR 0 + +#define GST_DP_HEADER_LENGTH 60 /* header size in bytes */ + + +/* header flags */ +typedef enum { + GST_DP_HEADER_FLAG_NONE = 0, + GST_DP_HEADER_FLAG_CRC_HEADER = (1 << 0), + GST_DP_HEADER_FLAG_CRC_PAYLOAD = (1 << 1), + GST_DP_HEADER_FLAG_CRC = (1 << 1) | (1 <<0), +} GstDPHeaderFlag; + +/* payload types */ +typedef enum { + GST_DP_PAYLOAD_NONE = 0, + GST_DP_PAYLOAD_BUFFER, + GST_DP_PAYLOAD_CAPS, + GST_DP_PAYLOAD_EVENT_NONE = 64, +} GstDPPayloadType; + +/* payload information from header */ +guint32 gst_dp_header_payload_length (const guint8 * header); +GstDPPayloadType + gst_dp_header_payload_type (const guint8 * header); + +/* converting from GstBuffer/GstEvent/GstCaps */ +gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header); +gboolean gst_dp_packet_from_caps (const GstCaps * caps, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header, + guint8 ** payload); +gboolean gst_dp_packet_from_event (const GstEvent * event, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header, + guint8 ** payload); + + +/* converting to GstBuffer/GstEvent/GstCaps */ +GstBuffer * gst_dp_buffer_from_header (guint header_length, + const guint8 * header); +GstCaps * gst_dp_caps_from_packet (guint header_length, + const guint8 * header, + const guint8 * payload); +GstEvent * gst_dp_event_from_packet (guint header_length, + const guint8 * header, + const guint8 * payload); + +/* validation */ +gboolean gst_dp_validate_header (guint header_length, + const guint8 * header); +gboolean gst_dp_validate_payload (guint header_length, + const guint8 * header, + const guint8 * payload); +gboolean gst_dp_validate_packet (guint header_length, + const guint8 * header, + const guint8 * payload); + +G_END_DECLS + +#endif /* __GST_DATA_PROTOCOL_H__ */ diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h new file mode 100644 index 0000000000..be19ab5f9a --- /dev/null +++ b/gst/gdp/dp-private.h @@ -0,0 +1,55 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2004> Thomas Vander Stichele + * + * dp-private.h: private defines/macros for dataprotocol implementation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_DP_PRIVATE_H__ +#define __GST_DP_PRIVATE_H__ + +#include +#include +#include +#include + +G_BEGIN_DECLS + +/* read the given type out of the byte buffer using glib conversion macros */ +#define GST_DP_GUINT16(x) GUINT16_FROM_BE (* (guint16 *) (x)) +#define GST_DP_GUINT32(x) GUINT32_FROM_BE (* (guint32 *) (x)) +#define GST_DP_GUINT64(x) GUINT64_FROM_BE (* (guint64 *) (x)) + +/* accessor defines */ +#define GST_DP_HEADER_MAJOR_VERSION(x) ((x)[0]) +#define GST_DP_HEADER_MINOR_VERSION(x) ((x)[1]) +#define GST_DP_HEADER_FLAGS(x) ((x)[2]) +#define GST_DP_HEADER_PAYLOAD_TYPE(x) ((x)[3]) +#define GST_DP_HEADER_PAYLOAD_LENGTH(x) GST_DP_GUINT32 (x + 4) +#define GST_DP_HEADER_TIMESTAMP(x) GST_DP_GUINT64 (x + 8) +#define GST_DP_HEADER_DURATION(x) GST_DP_GUINT64 (x + 16) +#define GST_DP_HEADER_OFFSET(x) GST_DP_GUINT64 (x + 24) +#define GST_DP_HEADER_OFFSET_END(x) GST_DP_GUINT64 (x + 32) +#define GST_DP_HEADER_CRC_HEADER(x) GST_DP_GUINT16 (x + 56) +#define GST_DP_HEADER_CRC_PAYLOAD(x) GST_DP_GUINT16 (x + 58) + +void gst_dp_dump_byte_array (guint8 *array, guint length); + +G_END_DECLS + +#endif /* __GST_DP_PRIVATE_H__ */ From 889f9e1464ba61fecc8bc6c1471ee5a694ef5c81 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 19 May 2004 16:59:39 +0000 Subject: [PATCH 02/54] gdp: private prototype Original commit message from CVS: private prototype --- gst/gdp/dp-private.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h index be19ab5f9a..d253789dba 100644 --- a/gst/gdp/dp-private.h +++ b/gst/gdp/dp-private.h @@ -48,6 +48,7 @@ G_BEGIN_DECLS #define GST_DP_HEADER_CRC_HEADER(x) GST_DP_GUINT16 (x + 56) #define GST_DP_HEADER_CRC_PAYLOAD(x) GST_DP_GUINT16 (x + 58) +void gst_dp_init (void); void gst_dp_dump_byte_array (guint8 *array, guint length); G_END_DECLS From 44dc4f9608612e908fe5b415795e0787a6927f9b Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 19 May 2004 17:22:53 +0000 Subject: [PATCH 03/54] Original commit message from CVS: use GST macros; add asserts --- gst/gdp/dataprotocol.c | 97 +++++++++++++++++++++--------------------- gst/gdp/dp-private.h | 19 +++------ 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index cabba42c57..85c798e929 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -34,12 +34,6 @@ GST_DEBUG_CATEGORY (data_protocol_debug); #define GST_CAT_DEFAULT data_protocol_debug -/*** private functions ***/ - -#define GST_DP_WRITE_GUINT64(buf, value) (*((guint64 *) (buf)) = GUINT64_TO_BE (value)) -#define GST_DP_WRITE_GUINT32(buf, value) (*((guint32 *) (buf)) = GUINT32_TO_BE (value)) -#define GST_DP_WRITE_GUINT16(buf, value) (*((guint16 *) (buf)) = GUINT16_TO_BE (value)) - /* calculate a CCITT 16 bit CRC check value for a given byte array */ /* * this code snippet is adapted from a web page I found @@ -172,6 +166,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buffer) > 0, FALSE); + g_return_val_if_fail (header, FALSE); *length = GST_DP_HEADER_LENGTH; h = g_malloc (GST_DP_HEADER_LENGTH); @@ -183,15 +178,15 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, h[3] = GST_DP_PAYLOAD_BUFFER; /* buffer properties */ - GST_DP_WRITE_GUINT32 (h + 4, GST_BUFFER_SIZE (buffer)); - GST_DP_WRITE_GUINT64 (h + 8, GST_BUFFER_TIMESTAMP (buffer)); - GST_DP_WRITE_GUINT64 (h + 16, GST_BUFFER_DURATION (buffer)); - GST_DP_WRITE_GUINT64 (h + 24, GST_BUFFER_OFFSET (buffer)); - GST_DP_WRITE_GUINT64 (h + 32, GST_BUFFER_OFFSET_END (buffer)); + GST_WRITE_UINT32_BE (h + 4, GST_BUFFER_SIZE (buffer)); + GST_WRITE_UINT64_BE (h + 8, GST_BUFFER_TIMESTAMP (buffer)); + GST_WRITE_UINT64_BE (h + 16, GST_BUFFER_DURATION (buffer)); + GST_WRITE_UINT64_BE (h + 24, GST_BUFFER_OFFSET (buffer)); + GST_WRITE_UINT64_BE (h + 32, GST_BUFFER_OFFSET_END (buffer)); /* ABI padding */ - GST_DP_WRITE_GUINT64 (h + 40, (guint64) 0); - GST_DP_WRITE_GUINT64 (h + 48, (guint64) 0); + GST_WRITE_UINT64_BE (h + 40, (guint64) 0); + GST_WRITE_UINT64_BE (h + 48, (guint64) 0); /* CRC */ crc = 0; @@ -199,13 +194,13 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, /* we don't crc the last four bytes of the header since they are crc's */ crc = gst_dp_crc (h, 56); } - GST_DP_WRITE_GUINT16 (h + 56, crc); + GST_WRITE_UINT16_BE (h + 56, crc); crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { crc = gst_dp_crc (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); } - GST_DP_WRITE_GUINT16 (h + 58, crc); + GST_WRITE_UINT16_BE (h + 58, crc); GST_LOG ("created header from buffer:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -235,6 +230,9 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, /* FIXME: GST_IS_CAPS doesn't work g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */ + g_return_val_if_fail (caps, FALSE); + g_return_val_if_fail (header, FALSE); + g_return_val_if_fail (payload, FALSE); *length = GST_DP_HEADER_LENGTH; h = g_malloc (GST_DP_HEADER_LENGTH); @@ -248,28 +246,28 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, h[3] = GST_DP_PAYLOAD_CAPS; /* buffer properties */ - GST_DP_WRITE_GUINT32 (h + 4, strlen (string) + 1); /* include trailing 0 */ - GST_DP_WRITE_GUINT64 (h + 8, (guint64) 0); - GST_DP_WRITE_GUINT64 (h + 16, (guint64) 0); - GST_DP_WRITE_GUINT64 (h + 24, (guint64) 0); - GST_DP_WRITE_GUINT64 (h + 32, (guint64) 0); + GST_WRITE_UINT32_BE (h + 4, strlen (string) + 1); /* include trailing 0 */ + GST_WRITE_UINT64_BE (h + 8, (guint64) 0); + GST_WRITE_UINT64_BE (h + 16, (guint64) 0); + GST_WRITE_UINT64_BE (h + 24, (guint64) 0); + GST_WRITE_UINT64_BE (h + 32, (guint64) 0); /* ABI padding */ - GST_DP_WRITE_GUINT64 (h + 40, (guint64) 0); - GST_DP_WRITE_GUINT64 (h + 48, (guint64) 0); + GST_WRITE_UINT64_BE (h + 40, (guint64) 0); + GST_WRITE_UINT64_BE (h + 48, (guint64) 0); /* CRC */ crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { crc = gst_dp_crc (h, 56); } - GST_DP_WRITE_GUINT16 (h + 56, crc); + GST_WRITE_UINT16_BE (h + 56, crc); crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { crc = gst_dp_crc (string, strlen (string) + 1); } - GST_DP_WRITE_GUINT16 (h + 58, crc); + GST_WRITE_UINT16_BE (h + 58, crc); GST_LOG ("created header from caps:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -296,10 +294,12 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, { guint8 *h; guint16 crc; - gchar *string = NULL; guint pl_length; /* length of payload */ + g_return_val_if_fail (event, FALSE); g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + g_return_val_if_fail (header, FALSE); + g_return_val_if_fail (payload, FALSE); *length = GST_DP_HEADER_LENGTH; h = g_malloc0 (GST_DP_HEADER_LENGTH); @@ -315,28 +315,28 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, case GST_EVENT_FLUSH: case GST_EVENT_EMPTY: case GST_EVENT_DISCONTINUOUS: - GST_DP_WRITE_GUINT64 (h + 8, GST_EVENT_TIMESTAMP (event)); + GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event)); pl_length = 0; *payload = NULL; break; case GST_EVENT_SEEK: pl_length = 4 + 8 + 4; *payload = g_malloc0 (pl_length); - GST_DP_WRITE_GUINT32 (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); - GST_DP_WRITE_GUINT64 (*payload + 4, + GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); + GST_WRITE_UINT64_BE (*payload + 4, (guint64) GST_EVENT_SEEK_OFFSET (event)); - GST_DP_WRITE_GUINT32 (*payload + 12, + GST_WRITE_UINT32_BE (*payload + 12, (guint32) GST_EVENT_SEEK_ACCURACY (event)); break; case GST_EVENT_SEEK_SEGMENT: pl_length = 4 + 8 + 8 + 4; *payload = g_malloc0 (pl_length); - GST_DP_WRITE_GUINT32 (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); - GST_DP_WRITE_GUINT64 (*payload + 4, + GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); + GST_WRITE_UINT64_BE (*payload + 4, (guint64) GST_EVENT_SEEK_OFFSET (event)); - GST_DP_WRITE_GUINT64 (*payload + 12, + GST_WRITE_UINT64_BE (*payload + 12, (guint64) GST_EVENT_SEEK_ENDOFFSET (event)); - GST_DP_WRITE_GUINT32 (*payload + 20, + GST_WRITE_UINT32_BE (*payload + 20, (guint32) GST_EVENT_SEEK_ACCURACY (event)); break; case GST_EVENT_QOS: @@ -364,26 +364,27 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, h[3] = GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event); /* length */ - GST_DP_WRITE_GUINT32 (h + 4, (guint32) pl_length); + GST_WRITE_UINT32_BE (h + 4, (guint32) pl_length); /* timestamp */ - GST_DP_WRITE_GUINT64 (h + 8, GST_EVENT_TIMESTAMP (event)); + GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event)); /* ABI padding */ - GST_DP_WRITE_GUINT64 (h + 40, (guint64) 0); - GST_DP_WRITE_GUINT64 (h + 48, (guint64) 0); + GST_WRITE_UINT64_BE (h + 40, (guint64) 0); + GST_WRITE_UINT64_BE (h + 48, (guint64) 0); /* CRC */ crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { crc = gst_dp_crc (h, 56); } - GST_DP_WRITE_GUINT16 (h + 56, crc); + GST_WRITE_UINT16_BE (h + 56, crc); crc = 0; - if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { - crc = gst_dp_crc (string, strlen (string) + 1); + /* events can have a NULL payload */ + if (*payload && flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { + crc = gst_dp_crc (*payload, strlen (*payload) + 1); } - GST_DP_WRITE_GUINT16 (h + 58, crc); + GST_WRITE_UINT16_BE (h + 58, crc); GST_LOG ("created header from event:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -487,9 +488,9 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, gint64 offset; GstSeekAccuracy accuracy; - type = (GstSeekType) GST_DP_GUINT32 (payload); - offset = (gint64) GST_DP_GUINT64 (payload + 4); - accuracy = (GstSeekAccuracy) GST_DP_GUINT32 (payload + 12); + type = (GstSeekType) GST_READ_UINT32_BE (payload); + offset = (gint64) GST_READ_UINT64_BE (payload + 4); + accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 12); event = gst_event_new_seek (type, offset); GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); GST_EVENT_SEEK_ACCURACY (event) = accuracy; @@ -501,10 +502,10 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, gint64 offset, endoffset; GstSeekAccuracy accuracy; - type = (GstSeekType) GST_DP_GUINT32 (payload); - offset = (gint64) GST_DP_GUINT64 (payload + 4); - endoffset = (gint64) GST_DP_GUINT64 (payload + 12); - accuracy = (GstSeekAccuracy) GST_DP_GUINT32 (payload + 20); + type = (GstSeekType) GST_READ_UINT32_BE (payload); + offset = (gint64) GST_READ_UINT64_BE (payload + 4); + endoffset = (gint64) GST_READ_UINT64_BE (payload + 12); + accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 20); event = gst_event_new_segment_seek (type, offset, endoffset); GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); GST_EVENT_SEEK_ACCURACY (event) = accuracy; diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h index d253789dba..f522457454 100644 --- a/gst/gdp/dp-private.h +++ b/gst/gdp/dp-private.h @@ -30,23 +30,18 @@ G_BEGIN_DECLS -/* read the given type out of the byte buffer using glib conversion macros */ -#define GST_DP_GUINT16(x) GUINT16_FROM_BE (* (guint16 *) (x)) -#define GST_DP_GUINT32(x) GUINT32_FROM_BE (* (guint32 *) (x)) -#define GST_DP_GUINT64(x) GUINT64_FROM_BE (* (guint64 *) (x)) - /* accessor defines */ #define GST_DP_HEADER_MAJOR_VERSION(x) ((x)[0]) #define GST_DP_HEADER_MINOR_VERSION(x) ((x)[1]) #define GST_DP_HEADER_FLAGS(x) ((x)[2]) #define GST_DP_HEADER_PAYLOAD_TYPE(x) ((x)[3]) -#define GST_DP_HEADER_PAYLOAD_LENGTH(x) GST_DP_GUINT32 (x + 4) -#define GST_DP_HEADER_TIMESTAMP(x) GST_DP_GUINT64 (x + 8) -#define GST_DP_HEADER_DURATION(x) GST_DP_GUINT64 (x + 16) -#define GST_DP_HEADER_OFFSET(x) GST_DP_GUINT64 (x + 24) -#define GST_DP_HEADER_OFFSET_END(x) GST_DP_GUINT64 (x + 32) -#define GST_DP_HEADER_CRC_HEADER(x) GST_DP_GUINT16 (x + 56) -#define GST_DP_HEADER_CRC_PAYLOAD(x) GST_DP_GUINT16 (x + 58) +#define GST_DP_HEADER_PAYLOAD_LENGTH(x) GST_READ_UINT32_BE (x + 4) +#define GST_DP_HEADER_TIMESTAMP(x) GST_READ_UINT64_BE (x + 8) +#define GST_DP_HEADER_DURATION(x) GST_READ_UINT64_BE (x + 16) +#define GST_DP_HEADER_OFFSET(x) GST_READ_UINT64_BE (x + 24) +#define GST_DP_HEADER_OFFSET_END(x) GST_READ_UINT64_BE (x + 32) +#define GST_DP_HEADER_CRC_HEADER(x) GST_READ_UINT16_BE (x + 56) +#define GST_DP_HEADER_CRC_PAYLOAD(x) GST_READ_UINT16_BE (x + 58) void gst_dp_init (void); void gst_dp_dump_byte_array (guint8 *array, guint length); From 047718e576e6af9090f522823f43625309332b6c Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 24 May 2004 16:38:15 +0000 Subject: [PATCH 04/54] gdp: wrap header in _NEW Original commit message from CVS: wrap header in _NEW --- gst/gdp/dataprotocol.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 76b1d62a1e..41e7feeb4f 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -20,6 +20,7 @@ * Boston, MA 02111-1307, USA. */ +#ifdef GST_ENABLE_NEW #ifndef __GST_DATA_PROTOCOL_H__ #define __GST_DATA_PROTOCOL_H__ @@ -98,3 +99,5 @@ gboolean gst_dp_validate_packet (guint header_length, G_END_DECLS #endif /* __GST_DATA_PROTOCOL_H__ */ +#endif /* GST_ENABLE_NEW */ + From b07fa6fc0548c34aaced7ed73e941fe26b131e67 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 9 Jun 2004 16:24:19 +0000 Subject: [PATCH 05/54] gdp: bump GDP to 0.1, add buffer flags Original commit message from CVS: bump GDP to 0.1, add buffer flags --- gst/gdp/dataprotocol.c | 12 +++++++++++- gst/gdp/dataprotocol.h | 2 +- gst/gdp/dp-private.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 85c798e929..2fdbc5fc74 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -163,6 +163,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, { guint8 *h; guint16 crc; + guint16 flags_mask; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buffer) > 0, FALSE); @@ -184,8 +185,16 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_WRITE_UINT64_BE (h + 24, GST_BUFFER_OFFSET (buffer)); GST_WRITE_UINT64_BE (h + 32, GST_BUFFER_OFFSET_END (buffer)); + /* data flags */ + /* we only copy KEY_UNIT and IN_CAPS flags */ + flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_KEY_UNIT) | + GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS); + + GST_WRITE_UINT16_BE (h + 40, GST_BUFFER_FLAGS (buffer) & flags_mask); + /* ABI padding */ - GST_WRITE_UINT64_BE (h + 40, (guint64) 0); + GST_WRITE_UINT16_BE (h + 42, (guint64) 0); + GST_WRITE_UINT32_BE (h + 44, (guint64) 0); GST_WRITE_UINT64_BE (h + 48, (guint64) 0); /* CRC */ @@ -419,6 +428,7 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) GST_BUFFER_DURATION (buffer) = GST_DP_HEADER_DURATION (header); GST_BUFFER_OFFSET (buffer) = GST_DP_HEADER_OFFSET (header); GST_BUFFER_OFFSET_END (buffer) = GST_DP_HEADER_OFFSET_END (header); + GST_BUFFER_FLAGS (buffer) = GST_DP_HEADER_BUFFER_FLAGS (header); return buffer; } diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 41e7feeb4f..ca394ccf9a 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS /* GStreamer Data Protocol Version */ #define GST_DP_VERSION_MAJOR 0 -#define GST_DP_VERSION_MINOR 0 +#define GST_DP_VERSION_MINOR 1 #define GST_DP_HEADER_LENGTH 60 /* header size in bytes */ diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h index f522457454..77f7f8b630 100644 --- a/gst/gdp/dp-private.h +++ b/gst/gdp/dp-private.h @@ -40,6 +40,7 @@ G_BEGIN_DECLS #define GST_DP_HEADER_DURATION(x) GST_READ_UINT64_BE (x + 16) #define GST_DP_HEADER_OFFSET(x) GST_READ_UINT64_BE (x + 24) #define GST_DP_HEADER_OFFSET_END(x) GST_READ_UINT64_BE (x + 32) +#define GST_DP_HEADER_BUFFER_FLAGS(x) GST_READ_UINT16_BE (x + 40) #define GST_DP_HEADER_CRC_HEADER(x) GST_READ_UINT16_BE (x + 56) #define GST_DP_HEADER_CRC_PAYLOAD(x) GST_READ_UINT16_BE (x + 58) From 6235216793bc2b84a4cd7a6f1142e72cf0dfcd99 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 28 Jul 2004 10:22:07 +0000 Subject: [PATCH 06/54] gdp: doc style fixes Original commit message from CVS: doc style fixes --- gst/gdp/dataprotocol.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 2fdbc5fc74..a1aa067dcd 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -154,7 +154,7 @@ gst_dp_header_payload_type (const guint8 * header) * * Creates a GDP header from the given buffer. * - * Returns: %TRUE if the header was successfully created + * Returns: %TRUE if the header was successfully created. */ gboolean @@ -227,7 +227,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, * * Creates a GDP packet from the given caps. * - * Returns: %TRUE if the packet was successfully created + * Returns: %TRUE if the packet was successfully created. */ gboolean gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, @@ -295,7 +295,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, * * Creates a GDP packet from the given event. * - * Returns: %TRUE if the packet was successfully created + * Returns: %TRUE if the packet was successfully created. */ gboolean gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, @@ -413,7 +413,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, * Use this function if you want to pre-allocate a buffer based on the * packet header to read the packet payload in to. * - * Returns: %TRUE if the buffer was successfully created + * Returns: %TRUE if the buffer was successfully created. */ GstBuffer * gst_dp_buffer_from_header (guint header_length, const guint8 * header) @@ -441,7 +441,7 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) * * Creates a newly allocated #GstCaps from the given packet. * - * Returns: %TRUE if the caps was successfully created + * Returns: %TRUE if the caps was successfully created. */ GstCaps * gst_dp_caps_from_packet (guint header_length, const guint8 * header, @@ -468,7 +468,7 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, * * Creates a newly allocated #GstEvent from the given packet. * - * Returns: %TRUE if the event was successfully created + * Returns: %TRUE if the event was successfully created. */ GstEvent * gst_dp_event_from_packet (guint header_length, const guint8 * header, @@ -547,7 +547,7 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, * * Validates the given packet header by checking the CRC checksum. * - * Returns: %TRUE if the CRC matches, or no CRC checksum is present + * Returns: %TRUE if the CRC matches, or no CRC checksum is present. */ gboolean gst_dp_validate_header (guint header_length, const guint8 * header) @@ -577,7 +577,7 @@ gst_dp_validate_header (guint header_length, const guint8 * header) * Validates the given packet payload using the given packet header * by checking the CRC checksum. * - * Returns: %TRUE if the CRC matches, or no CRC checksum is present + * Returns: %TRUE if the CRC matches, or no CRC checksum is present. */ gboolean gst_dp_validate_payload (guint header_length, const guint8 * header, @@ -606,7 +606,7 @@ gst_dp_validate_payload (guint header_length, const guint8 * header, * * Validates the given packet by checking version information and checksums. * - * Returns: %TRUE if the packet validates + * Returns: %TRUE if the packet validates. */ gboolean gst_dp_validate_packet (guint header_length, const guint8 * header, From e8ef3dac6e4ae6428dcf4a590d5f536a7a66162c Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 16 Aug 2004 10:35:36 +0000 Subject: [PATCH 07/54] gdp: fix for #150242 Original commit message from CVS: fix for #150242 --- gst/gdp/dataprotocol.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index a1aa067dcd..8df6fc080d 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -186,9 +186,10 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_WRITE_UINT64_BE (h + 32, GST_BUFFER_OFFSET_END (buffer)); /* data flags */ - /* we only copy KEY_UNIT and IN_CAPS flags */ + /* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */ flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_KEY_UNIT) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS); + GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS) | + GST_DATA_FLAG_SHIFT (GST_BUFFER_DELTA_UNIT); GST_WRITE_UINT16_BE (h + 40, GST_BUFFER_FLAGS (buffer) & flags_mask); From c6ebc310671f4c1f9651374df6033756394156b8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 1 Oct 2004 16:49:01 +0000 Subject: [PATCH 08/54] gdp: Fix threadsafety of the crc checking function. Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_crc): Fix threadsafety of the crc checking function. --- gst/gdp/dataprotocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 8df6fc080d..27512987ea 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -50,7 +50,8 @@ static guint16 gst_dp_crc (const guint8 * buffer, register guint length) { static gboolean initialized = FALSE; - static guint16 crc_register, crc_table[256]; + static guint16 crc_table[256]; + guint16 crc_register; unsigned long i, j, k; if (!initialized) { From a3562d1fdabdcdfc470f422f0c1dccf9c34f2e51 Mon Sep 17 00:00:00 2001 From: Zaheer Abbas Merali Date: Fri, 18 Feb 2005 13:58:36 +0000 Subject: [PATCH 09/54] gdp: Allocate the 1 byte more memory that was forgotten!!!!! Original commit message from CVS: 2005-02-18 Zaheer Abbas Merali * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_dump_byte_array): Allocate the 1 byte more memory that was forgotten!!!!! --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 27512987ea..645d7574a7 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -83,7 +83,7 @@ gst_dp_dump_byte_array (guint8 * array, guint length) { int i; int n = 8; /* number of bytes per line */ - gchar *line = g_malloc (3 * n); + gchar *line = g_malloc (3 * n + 1); GST_LOG ("dumping byte array of length %d", length); for (i = 0; i < length; ++i) { From d29a498d864d62d5880596f0ed6399e35869e711 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 7 Mar 2005 18:27:42 +0000 Subject: [PATCH 10/54] gdp: First THREADED backport attempt, focusing on adding locks and making sure the API is threadsafe. Needs more work. Mor... Original commit message from CVS: First THREADED backport attempt, focusing on adding locks and making sure the API is threadsafe. Needs more work. More docs follow this week. --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 645d7574a7..b271883c37 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -188,7 +188,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, /* data flags */ /* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */ - flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_KEY_UNIT) | + flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_PREROLL) | GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS) | GST_DATA_FLAG_SHIFT (GST_BUFFER_DELTA_UNIT); From 1e5ba07cbb32304351cea41ac3a4e5d03c1ebc26 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 21 Mar 2005 17:34:02 +0000 Subject: [PATCH 11/54] gdp: Next big merge. Original commit message from CVS: Next big merge. Added GstBus for mainloop integration. Added GstMessage for sending notifications on the bus. Added GstTask as an abstraction for pipeline entry points. Removed GstThread. Removed Schedulers. Simplified GstQueue for multithreaded core. Made _link threadsafe, removed old capsnego. Added STREAM_LOCK and PREROLL_LOCK in GstPad. Added pad blocking functions. Reworked scheduling functions in GstPad to prepare for scheduling updates soon. Moved events out of data stream. Simplified GstEvent types. Added return values to push/pull. Removed clocking from GstElement. Added prototypes for state change function for next merge. Removed iterate from bins and state change management. Fixed some elements, disabled others for now. Fixed -inspect and -launch. Added check for GstBus. --- gst/gdp/dataprotocol.c | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index b271883c37..0ae75af0f0 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -324,22 +324,12 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, return FALSE; case GST_EVENT_EOS: case GST_EVENT_FLUSH: - case GST_EVENT_EMPTY: case GST_EVENT_DISCONTINUOUS: GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event)); pl_length = 0; *payload = NULL; break; case GST_EVENT_SEEK: - pl_length = 4 + 8 + 4; - *payload = g_malloc0 (pl_length); - GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); - GST_WRITE_UINT64_BE (*payload + 4, - (guint64) GST_EVENT_SEEK_OFFSET (event)); - GST_WRITE_UINT32_BE (*payload + 12, - (guint32) GST_EVENT_SEEK_ACCURACY (event)); - break; - case GST_EVENT_SEEK_SEGMENT: pl_length = 4 + 8 + 8 + 4; *payload = g_malloc0 (pl_length); GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); @@ -351,12 +341,8 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, (guint32) GST_EVENT_SEEK_ACCURACY (event)); break; case GST_EVENT_QOS: - case GST_EVENT_SEGMENT_DONE: case GST_EVENT_SIZE: case GST_EVENT_RATE: - case GST_EVENT_FILLER: - case GST_EVENT_TS_OFFSET: - case GST_EVENT_INTERRUPT: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); @@ -489,26 +475,11 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, return FALSE; case GST_EVENT_EOS: case GST_EVENT_FLUSH: - case GST_EVENT_EMPTY: case GST_EVENT_DISCONTINUOUS: event = gst_event_new (type); GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); break; case GST_EVENT_SEEK: - { - GstSeekType type; - gint64 offset; - GstSeekAccuracy accuracy; - - type = (GstSeekType) GST_READ_UINT32_BE (payload); - offset = (gint64) GST_READ_UINT64_BE (payload + 4); - accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 12); - event = gst_event_new_seek (type, offset); - GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); - GST_EVENT_SEEK_ACCURACY (event) = accuracy; - break; - } - case GST_EVENT_SEEK_SEGMENT: { GstSeekType type; gint64 offset, endoffset; @@ -524,12 +495,8 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, break; } case GST_EVENT_QOS: - case GST_EVENT_SEGMENT_DONE: case GST_EVENT_SIZE: case GST_EVENT_RATE: - case GST_EVENT_FILLER: - case GST_EVENT_TS_OFFSET: - case GST_EVENT_INTERRUPT: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); From 9867259b81996aedbc5270f0fb6f74f0217d1387 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 4 May 2005 21:29:44 +0000 Subject: [PATCH 12/54] gdp: GCC 4 fixen. Original commit message from CVS: 2005-05-04 Andy Wingo * check/Makefile.am: * docs/gst/tmpl/gstatomic.sgml: * docs/gst/tmpl/gstplugin.sgml: * gst/base/gstbasesink.c: (gst_basesink_activate): * gst/base/gstbasesrc.c: (gst_basesrc_class_init), (gst_basesrc_init), (gst_basesrc_set_dataflow_funcs), (gst_basesrc_query), (gst_basesrc_set_property), (gst_basesrc_get_property), (gst_basesrc_check_get_range), (gst_basesrc_activate): * gst/base/gstbasesrc.h: * gst/base/gstbasetransform.c: (gst_base_transform_sink_activate), (gst_base_transform_src_activate): * gst/elements/gstelements.c: * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init), (gst_fakesrc_set_property), (gst_fakesrc_get_property): * gst/elements/gsttee.c: (gst_tee_sink_activate): * gst/elements/gsttypefindelement.c: (find_element_get_length), (gst_type_find_element_checkgetrange), (gst_type_find_element_activate): * gst/gstbin.c: (gst_bin_save_thyself), (gst_bin_restore_thyself): * gst/gstcaps.c: (gst_caps_do_simplify), (gst_caps_save_thyself), (gst_caps_load_thyself): * gst/gstelement.c: (gst_element_pads_activate), (gst_element_save_thyself), (gst_element_restore_thyself): * gst/gstpad.c: (gst_pad_load_and_link), (gst_pad_save_thyself), (gst_ghost_pad_save_thyself), (gst_pad_check_pull_range): * gst/gstpad.h: * gst/gstxml.c: (gst_xml_write), (gst_xml_parse_doc), (gst_xml_parse_file), (gst_xml_parse_memory), (gst_xml_get_element), (gst_xml_make_element): * gst/indexers/gstfileindex.c: (gst_file_index_load), (_file_index_id_save_xml), (gst_file_index_commit): * gst/registries/gstlibxmlregistry.c: (read_string), (read_uint), (read_enum), (load_pad_template), (load_feature), (load_plugin), (load_paths): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_caps), (gst_dp_packet_from_event), (gst_dp_caps_from_packet): * tools/gst-complete.c: (main): * tools/gst-compprep.c: (main): * tools/gst-inspect.c: (print_element_properties_info): * tools/gst-launch.c: (xmllaunch_parse_cmdline): * tools/gst-xmlinspect.c: (print_element_properties): GCC 4 fixen. --- gst/gdp/dataprotocol.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 0ae75af0f0..9210f29901 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -237,7 +237,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, { guint8 *h; guint16 crc; - gchar *string; + guchar *string; /* FIXME: GST_IS_CAPS doesn't work g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */ @@ -248,7 +248,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, *length = GST_DP_HEADER_LENGTH; h = g_malloc (GST_DP_HEADER_LENGTH); - string = gst_caps_to_string (caps); + string = (guchar *) gst_caps_to_string (caps); /* version, flags, type */ h[0] = (guint8) GST_DP_VERSION_MAJOR; @@ -257,7 +257,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, h[3] = GST_DP_PAYLOAD_CAPS; /* buffer properties */ - GST_WRITE_UINT32_BE (h + 4, strlen (string) + 1); /* include trailing 0 */ + GST_WRITE_UINT32_BE (h + 4, strlen ((gchar *) string) + 1); /* include trailing 0 */ GST_WRITE_UINT64_BE (h + 8, (guint64) 0); GST_WRITE_UINT64_BE (h + 16, (guint64) 0); GST_WRITE_UINT64_BE (h + 24, (guint64) 0); @@ -276,7 +276,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { - crc = gst_dp_crc (string, strlen (string) + 1); + crc = gst_dp_crc (string, strlen ((gchar *) string) + 1); } GST_WRITE_UINT16_BE (h + 58, crc); @@ -379,7 +379,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, crc = 0; /* events can have a NULL payload */ if (*payload && flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { - crc = gst_dp_crc (*payload, strlen (*payload) + 1); + crc = gst_dp_crc (*payload, strlen ((gchar *) * payload) + 1); } GST_WRITE_UINT16_BE (h + 58, crc); @@ -443,7 +443,7 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == GST_DP_PAYLOAD_CAPS, FALSE); - string = payload; + string = (gchar *) payload; caps = gst_caps_from_string (string); return caps; } From 94855803727928546e750602bae61be32dbadb65 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Mon, 16 May 2005 20:21:55 +0000 Subject: [PATCH 13/54] gdp: remove GstData checks Original commit message from CVS: * check/Makefile.am: remove GstData checks * check/gst-libs/gdp.c: (START_TEST): fix for API changes * gst/Makefile.am: add miniobject, remove data * gst/gst.h: add miniobject, remove data * gst/gstdata.c: remove * gst/gstdata.h: remove * gst/gstdata_private.h: remove * gst/gsttypes.h: remove GstEvent and GstMessage * gst/gstelement.c: (gst_element_post_message): fix for API changes * gst/gstmarshal.list: change BOXED -> OBJECT Implement GstMiniObject. * gst/gstminiobject.c: * gst/gstminiobject.h: Modify to be subclasses of GstMiniObject. * gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type), (gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy), (gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc), (gst_subbuffer_get_type), (gst_subbuffer_init), (gst_buffer_create_sub), (gst_buffer_is_span_fast), (gst_buffer_span): * gst/gstbuffer.h: * gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type), (gst_event_class_init), (gst_event_init), (gst_event_finalize), (_gst_event_copy), (gst_event_new): * gst/gstevent.h: * gst/gstmessage.c: (_gst_message_initialize), (gst_message_get_type), (gst_message_class_init), (gst_message_init), (gst_message_finalize), (_gst_message_copy), (gst_message_new), (gst_message_new_error), (gst_message_new_warning), (gst_message_new_tag), (gst_message_new_state_changed), (gst_message_new_application): * gst/gstmessage.h: * gst/gstprobe.c: (gst_probe_perform), (gst_probe_dispatcher_dispatch): * gst/gstprobe.h: * gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type), (gst_query_class_init), (gst_query_finalize), (gst_query_init), (_gst_query_copy), (gst_query_new): Update elements for GstData -> GstMiniObject changes * gst/gstquery.h: * gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush), (gst_queue_chain), (gst_queue_loop): * gst/elements/gstbufferstore.c: (gst_buffer_store_add_buffer_func), (gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer): * gst/elements/gstfakesink.c: (gst_fakesink_class_init), (gst_fakesink_render): * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init): * gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type), (gst_mmap_buffer_class_init), (gst_mmap_buffer_init), (gst_mmap_buffer_finalize), (gst_filesrc_map_region), (gst_filesrc_create_read): * gst/elements/gstidentity.c: (gst_identity_class_init): * gst/elements/gsttypefindelement.c: (gst_type_find_element_src_event), (free_entry_buffers), (gst_type_find_element_handle_event): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_header_from_buffer): * libs/gst/dataprotocol/dataprotocol.h: * libs/gst/dataprotocol/dp-private.h: --- gst/gdp/dataprotocol.c | 6 ++---- gst/gdp/dataprotocol.h | 1 - gst/gdp/dp-private.h | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 9210f29901..dabcb202e9 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -167,7 +167,6 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint16 flags_mask; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); - g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buffer) > 0, FALSE); g_return_val_if_fail (header, FALSE); *length = GST_DP_HEADER_LENGTH; @@ -188,9 +187,8 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, /* data flags */ /* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */ - flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_PREROLL) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_DELTA_UNIT); + flags_mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS | + GST_BUFFER_FLAG_DELTA_UNIT; GST_WRITE_UINT16_BE (h + 40, GST_BUFFER_FLAGS (buffer) & flags_mask); diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index ca394ccf9a..da3c2b9337 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -24,7 +24,6 @@ #ifndef __GST_DATA_PROTOCOL_H__ #define __GST_DATA_PROTOCOL_H__ -#include #include #include #include diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h index 77f7f8b630..386916e14d 100644 --- a/gst/gdp/dp-private.h +++ b/gst/gdp/dp-private.h @@ -23,7 +23,6 @@ #ifndef __GST_DP_PRIVATE_H__ #define __GST_DP_PRIVATE_H__ -#include #include #include #include From 9e03fd9fc07b9f2adf2cc07f72a30eafb36d5702 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 5 Jul 2005 10:20:14 +0000 Subject: [PATCH 14/54] gdp: Ported dataprotol to 0.9. Original commit message from CVS: * configure.ac: * libs/gst/dataprotocol/Makefile.am: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_validate_packet): * libs/gst/dataprotocol/dataprotocol.h: * pkgconfig/Makefile.am: * pkgconfig/gstreamer-dataprotocol-uninstalled.pc.in: * pkgconfig/gstreamer-dataprotocol.pc.in: Ported dataprotol to 0.9. Added pkgconfig files. --- gst/gdp/dataprotocol.c | 19 ++----------------- gst/gdp/dataprotocol.h | 4 ++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index dabcb202e9..d83e649f8d 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -103,8 +103,8 @@ gst_dp_dump_byte_array (guint8 * array, guint length) * * Initialize GStreamer Data Protocol library. * - * Should be called before using these functions; either from source linking - * to this source file or from plugin_init. + * Should be called before using these functions from source linking + * to this source file. */ void gst_dp_init (void) @@ -586,18 +586,3 @@ gst_dp_validate_packet (guint header_length, const guint8 * header, return TRUE; } - -/*** PLUGIN STUFF ***/ -static gboolean -plugin_init (GstPlugin * plugin) -{ - gst_dp_init (); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gstdataprotocol", - "a data protocol to serialize buffers, caps and events", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index da3c2b9337..cb1c826fd0 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -20,7 +20,6 @@ * Boston, MA 02111-1307, USA. */ -#ifdef GST_ENABLE_NEW #ifndef __GST_DATA_PROTOCOL_H__ #define __GST_DATA_PROTOCOL_H__ @@ -53,6 +52,8 @@ typedef enum { GST_DP_PAYLOAD_EVENT_NONE = 64, } GstDPPayloadType; +void gst_dp_init (void); + /* payload information from header */ guint32 gst_dp_header_payload_length (const guint8 * header); GstDPPayloadType @@ -98,5 +99,4 @@ gboolean gst_dp_validate_packet (guint header_length, G_END_DECLS #endif /* __GST_DATA_PROTOCOL_H__ */ -#endif /* GST_ENABLE_NEW */ From 0d96e7ec13816c4d75c69241dd39ad202ed6badd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 27 Jul 2005 18:33:03 +0000 Subject: [PATCH 15/54] gdp: Some docs updates Original commit message from CVS: * CHANGES-0.9: * docs/design/part-TODO.txt: * docs/design/part-events.txt: Some docs updates * gst/base/gstbasesink.c: (gst_base_sink_handle_object), (gst_base_sink_event), (gst_base_sink_do_sync), (gst_base_sink_activate_push), (gst_base_sink_activate_pull): * gst/base/gstbasesrc.c: (gst_base_src_send_discont), (gst_base_src_do_seek), (gst_base_src_event_handler), (gst_base_src_loop): * gst/base/gstbasetransform.c: (gst_base_transform_transform_caps), (gst_base_transform_configure_caps), (gst_base_transform_setcaps), (gst_base_transform_get_size), (gst_base_transform_buffer_alloc), (gst_base_transform_event), (gst_base_transform_handle_buffer), (gst_base_transform_set_passthrough), (gst_base_transform_is_passthrough): * gst/elements/gstfakesink.c: (gst_fake_sink_event): * gst/elements/gstfilesink.c: (gst_file_sink_event): Event updates. * gst/gstbuffer.h: Use faster casts. * gst/gstelement.c: (gst_element_seek): * gst/gstelement.h: Update gst_element_seek. * gst/gstevent.c: (gst_event_finalize), (_gst_event_copy), (gst_event_new), (gst_event_new_custom), (gst_event_get_structure), (gst_event_new_flush_start), (gst_event_new_flush_stop), (gst_event_new_eos), (gst_event_new_newsegment), (gst_event_parse_newsegment), (gst_event_new_tag), (gst_event_parse_tag), (gst_event_new_filler), (gst_event_new_qos), (gst_event_parse_qos), (gst_event_new_seek), (gst_event_parse_seek), (gst_event_new_navigation): * gst/gstevent.h: Make GstEvent use GstStructure. Add parsing code, make sure the API is sufficiently generic. Mark possible directions of events and serialization. * gst/gstmessage.c: (gst_message_init), (gst_message_finalize), (_gst_message_copy), (gst_message_new_segment_start), (gst_message_new_segment_done), (gst_message_new_custom), (gst_message_parse_segment_start), (gst_message_parse_segment_done): Small cleanups. * gst/gstpad.c: (gst_pad_get_caps_unlocked), (gst_pad_accept_caps), (gst_pad_set_caps), (gst_pad_send_event): Update for new events. Catch events sent in wrong directions. * gst/gstqueue.c: (gst_queue_link_src), (gst_queue_handle_sink_event), (gst_queue_chain), (gst_queue_loop), (gst_queue_handle_src_query): Event updates. * gst/gsttag.c: * gst/gsttag.h: Remove event code from this file. * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_event), (gst_dp_event_from_packet): Event updates. --- gst/gdp/dataprotocol.c | 54 ++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index d83e649f8d..babefbd3c4 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -321,8 +321,9 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, g_free (h); return FALSE; case GST_EVENT_EOS: - case GST_EVENT_FLUSH: - case GST_EVENT_DISCONTINUOUS: + case GST_EVENT_FLUSH_START: + case GST_EVENT_FLUSH_STOP: + case GST_EVENT_NEWSEGMENT: GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event)); pl_length = 0; *payload = NULL; @@ -330,17 +331,17 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, case GST_EVENT_SEEK: pl_length = 4 + 8 + 8 + 4; *payload = g_malloc0 (pl_length); - GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); - GST_WRITE_UINT64_BE (*payload + 4, - (guint64) GST_EVENT_SEEK_OFFSET (event)); - GST_WRITE_UINT64_BE (*payload + 12, - (guint64) GST_EVENT_SEEK_ENDOFFSET (event)); - GST_WRITE_UINT32_BE (*payload + 20, - (guint32) GST_EVENT_SEEK_ACCURACY (event)); + /* + GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); + GST_WRITE_UINT64_BE (*payload + 4, + (guint64) GST_EVENT_SEEK_OFFSET (event)); + GST_WRITE_UINT64_BE (*payload + 12, + (guint64) GST_EVENT_SEEK_ENDOFFSET (event)); + GST_WRITE_UINT32_BE (*payload + 20, + (guint32) GST_EVENT_SEEK_ACCURACY (event)); + */ break; case GST_EVENT_QOS: - case GST_EVENT_SIZE: - case GST_EVENT_RATE: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); @@ -472,29 +473,30 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, g_warning ("Unknown event, ignoring"); return FALSE; case GST_EVENT_EOS: - case GST_EVENT_FLUSH: - case GST_EVENT_DISCONTINUOUS: - event = gst_event_new (type); + case GST_EVENT_FLUSH_START: + case GST_EVENT_FLUSH_STOP: + case GST_EVENT_NEWSEGMENT: + event = gst_event_new_custom (type, NULL); GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); break; case GST_EVENT_SEEK: { - GstSeekType type; - gint64 offset, endoffset; - GstSeekAccuracy accuracy; + /* + GstSeekType type; + gint64 offset, endoffset; + GstSeekAccuracy accuracy; - type = (GstSeekType) GST_READ_UINT32_BE (payload); - offset = (gint64) GST_READ_UINT64_BE (payload + 4); - endoffset = (gint64) GST_READ_UINT64_BE (payload + 12); - accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 20); - event = gst_event_new_segment_seek (type, offset, endoffset); - GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); - GST_EVENT_SEEK_ACCURACY (event) = accuracy; + type = (GstSeekType) GST_READ_UINT32_BE (payload); + offset = (gint64) GST_READ_UINT64_BE (payload + 4); + endoffset = (gint64) GST_READ_UINT64_BE (payload + 12); + accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 20); + event = gst_event_new_segment_seek (type, offset, endoffset); + GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); + GST_EVENT_SEEK_ACCURACY (event) = accuracy; + */ break; } case GST_EVENT_QOS: - case GST_EVENT_SIZE: - case GST_EVENT_RATE: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); From 784ffd1b4fcb53ed798c3e902865208e3da6cff9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 27 Jul 2005 19:00:36 +0000 Subject: [PATCH 16/54] gdp: Fix serialization of seek events. Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_event), (gst_dp_event_from_packet): Fix serialization of seek events. --- gst/gdp/dataprotocol.c | 58 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index babefbd3c4..c4a3f6acc6 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -329,18 +329,27 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, *payload = NULL; break; case GST_EVENT_SEEK: - pl_length = 4 + 8 + 8 + 4; + { + gdouble rate; + GstFormat format; + GstSeekFlags flags; + GstSeekType cur_type, stop_type; + gint64 cur, stop; + + gst_event_parse_seek ((GstEvent *) event, &rate, &format, &flags, + &cur_type, &cur, &stop_type, &stop); + + pl_length = 4 + 4 + 4 + 8 + 4 + 8; *payload = g_malloc0 (pl_length); - /* - GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event)); - GST_WRITE_UINT64_BE (*payload + 4, - (guint64) GST_EVENT_SEEK_OFFSET (event)); - GST_WRITE_UINT64_BE (*payload + 12, - (guint64) GST_EVENT_SEEK_ENDOFFSET (event)); - GST_WRITE_UINT32_BE (*payload + 20, - (guint32) GST_EVENT_SEEK_ACCURACY (event)); - */ + /* FIXME write rate */ + GST_WRITE_UINT32_BE (*payload, (guint32) format); + GST_WRITE_UINT32_BE (*payload + 4, (guint32) flags); + GST_WRITE_UINT32_BE (*payload + 8, (guint32) cur_type); + GST_WRITE_UINT64_BE (*payload + 12, (guint64) cur); + GST_WRITE_UINT32_BE (*payload + 20, (guint32) stop_type); + GST_WRITE_UINT64_BE (*payload + 24, (guint64) stop); break; + } case GST_EVENT_QOS: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: @@ -481,19 +490,24 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, break; case GST_EVENT_SEEK: { - /* - GstSeekType type; - gint64 offset, endoffset; - GstSeekAccuracy accuracy; + gdouble rate; + GstFormat format; + GstSeekFlags flags; + GstSeekType cur_type, stop_type; + gint64 cur, stop; - type = (GstSeekType) GST_READ_UINT32_BE (payload); - offset = (gint64) GST_READ_UINT64_BE (payload + 4); - endoffset = (gint64) GST_READ_UINT64_BE (payload + 12); - accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 20); - event = gst_event_new_segment_seek (type, offset, endoffset); - GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); - GST_EVENT_SEEK_ACCURACY (event) = accuracy; - */ + /* FIXME, read rate */ + rate = 1.0; + format = (GstFormat) GST_READ_UINT32_BE (payload); + flags = (GstSeekFlags) GST_READ_UINT32_BE (payload + 4); + cur_type = (GstSeekType) GST_READ_UINT32_BE (payload + 8); + cur = (gint64) GST_READ_UINT64_BE (payload + 12); + stop_type = (GstSeekType) GST_READ_UINT32_BE (payload + 20); + stop = (gint64) GST_READ_UINT64_BE (payload + 24); + + event = gst_event_new_seek (rate, format, flags, cur_type, cur, + stop_type, stop); + GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); break; } case GST_EVENT_QOS: From 80ccce89c1e28cecad246dada9ed28c19f07853f Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 27 Sep 2005 16:30:26 +0000 Subject: [PATCH 17/54] gdp: Fix error-checking return values. Original commit message from CVS: 2005-09-27 Andy Wingo * libs/gst/dataprotocol/dataprotocol.c: Fix error-checking return values. --- gst/gdp/dataprotocol.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index c4a3f6acc6..21bca4316e 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -417,7 +417,7 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) GstBuffer *buffer; g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == - GST_DP_PAYLOAD_BUFFER, FALSE); + GST_DP_PAYLOAD_BUFFER, NULL); buffer = gst_buffer_new_and_alloc ((guint) GST_DP_HEADER_PAYLOAD_LENGTH (header)); GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header); @@ -446,10 +446,10 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, GstCaps *caps; const gchar *string; - g_return_val_if_fail (header, FALSE); - g_return_val_if_fail (payload, FALSE); + g_return_val_if_fail (header, NULL); + g_return_val_if_fail (payload, NULL); g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == - GST_DP_PAYLOAD_CAPS, FALSE); + GST_DP_PAYLOAD_CAPS, NULL); string = (gchar *) payload; caps = gst_caps_from_string (string); @@ -473,7 +473,7 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, GstEvent *event = NULL; GstEventType type; - g_return_val_if_fail (header, FALSE); + g_return_val_if_fail (header, NULL); /* payload can be NULL, e.g. for an EOS event */ type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE; From cc0ba720a4638b52d983315a0794857b5908e1aa Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 8 Oct 2005 17:17:25 +0000 Subject: [PATCH 18/54] gdp: It's about time we bump the version number. 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): * libs/gst/dataprotocol/dataprotocol.h: * libs/gst/dataprotocol/dp-private.h: It's about time we bump the version number. Since event types don't fit in the guint8 anymore describing the payload type, make payload type 16 bits wide. --- gst/gdp/dataprotocol.c | 64 ++++++++++++++++++++++-------------------- gst/gdp/dataprotocol.h | 4 +-- gst/gdp/dp-private.h | 19 +++++++------ 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 21bca4316e..7c39492bea 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -176,24 +176,24 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, h[0] = (guint8) GST_DP_VERSION_MAJOR; h[1] = (guint8) GST_DP_VERSION_MINOR; h[2] = (guint8) flags; - h[3] = GST_DP_PAYLOAD_BUFFER; + h[3] = 0; /* padding byte */ + GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_BUFFER); /* buffer properties */ - GST_WRITE_UINT32_BE (h + 4, GST_BUFFER_SIZE (buffer)); - GST_WRITE_UINT64_BE (h + 8, GST_BUFFER_TIMESTAMP (buffer)); - GST_WRITE_UINT64_BE (h + 16, GST_BUFFER_DURATION (buffer)); - GST_WRITE_UINT64_BE (h + 24, GST_BUFFER_OFFSET (buffer)); - GST_WRITE_UINT64_BE (h + 32, GST_BUFFER_OFFSET_END (buffer)); + GST_WRITE_UINT32_BE (h + 6, GST_BUFFER_SIZE (buffer)); + GST_WRITE_UINT64_BE (h + 10, GST_BUFFER_TIMESTAMP (buffer)); + GST_WRITE_UINT64_BE (h + 18, GST_BUFFER_DURATION (buffer)); + GST_WRITE_UINT64_BE (h + 26, GST_BUFFER_OFFSET (buffer)); + GST_WRITE_UINT64_BE (h + 34, GST_BUFFER_OFFSET_END (buffer)); /* data flags */ /* 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 + 40, GST_BUFFER_FLAGS (buffer) & flags_mask); + GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask); /* ABI padding */ - GST_WRITE_UINT16_BE (h + 42, (guint64) 0); GST_WRITE_UINT32_BE (h + 44, (guint64) 0); GST_WRITE_UINT64_BE (h + 48, (guint64) 0); @@ -201,15 +201,15 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { /* we don't crc the last four bytes of the header since they are crc's */ - crc = gst_dp_crc (h, 56); + crc = gst_dp_crc (h, 58); } - GST_WRITE_UINT16_BE (h + 56, crc); + GST_WRITE_UINT16_BE (h + 58, crc); crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { crc = gst_dp_crc (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); } - GST_WRITE_UINT16_BE (h + 58, crc); + GST_WRITE_UINT16_BE (h + 60, crc); GST_LOG ("created header from buffer:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -252,31 +252,32 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, h[0] = (guint8) GST_DP_VERSION_MAJOR; h[1] = (guint8) GST_DP_VERSION_MINOR; h[2] = (guint8) flags; - h[3] = GST_DP_PAYLOAD_CAPS; + h[3] = 0; /* padding bytes */ + GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_CAPS); /* buffer properties */ - GST_WRITE_UINT32_BE (h + 4, strlen ((gchar *) string) + 1); /* include trailing 0 */ - GST_WRITE_UINT64_BE (h + 8, (guint64) 0); - GST_WRITE_UINT64_BE (h + 16, (guint64) 0); - GST_WRITE_UINT64_BE (h + 24, (guint64) 0); - GST_WRITE_UINT64_BE (h + 32, (guint64) 0); + GST_WRITE_UINT32_BE (h + 8, strlen ((gchar *) string) + 1); /* include trailing 0 */ + GST_WRITE_UINT64_BE (h + 10, (guint64) 0); + GST_WRITE_UINT64_BE (h + 18, (guint64) 0); + GST_WRITE_UINT64_BE (h + 26, (guint64) 0); + GST_WRITE_UINT64_BE (h + 34, (guint64) 0); /* ABI padding */ - GST_WRITE_UINT64_BE (h + 40, (guint64) 0); - GST_WRITE_UINT64_BE (h + 48, (guint64) 0); + 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) { - crc = gst_dp_crc (h, 56); + crc = gst_dp_crc (h, 58); } - GST_WRITE_UINT16_BE (h + 56, crc); + GST_WRITE_UINT16_BE (h + 58, crc); crc = 0; if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { crc = gst_dp_crc (string, strlen ((gchar *) string) + 1); } - GST_WRITE_UINT16_BE (h + 58, crc); + GST_WRITE_UINT16_BE (h + 60, crc); GST_LOG ("created header from caps:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -324,7 +325,6 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, case GST_EVENT_FLUSH_START: case GST_EVENT_FLUSH_STOP: case GST_EVENT_NEWSEGMENT: - GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event)); pl_length = 0; *payload = NULL; break; @@ -366,30 +366,32 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, h[0] = (guint8) GST_DP_VERSION_MAJOR; h[1] = (guint8) GST_DP_VERSION_MINOR; h[2] = (guint8) flags; - h[3] = GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event); + h[3] = 0; /* padding byte */ + GST_WRITE_UINT16_BE (h + 4, + GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event)); /* length */ - GST_WRITE_UINT32_BE (h + 4, (guint32) pl_length); + GST_WRITE_UINT32_BE (h + 6, (guint32) pl_length); /* timestamp */ - GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event)); + GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event)); /* ABI padding */ - GST_WRITE_UINT64_BE (h + 40, (guint64) 0); - GST_WRITE_UINT64_BE (h + 48, (guint64) 0); + 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) { - crc = gst_dp_crc (h, 56); + crc = gst_dp_crc (h, 58); } - GST_WRITE_UINT16_BE (h + 56, crc); + GST_WRITE_UINT16_BE (h + 58, crc); crc = 0; /* events can have a NULL payload */ if (*payload && flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { crc = gst_dp_crc (*payload, strlen ((gchar *) * payload) + 1); } - GST_WRITE_UINT16_BE (h + 58, crc); + GST_WRITE_UINT16_BE (h + 60, crc); GST_LOG ("created header from event:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index cb1c826fd0..a326a912f1 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -31,9 +31,9 @@ G_BEGIN_DECLS /* GStreamer Data Protocol Version */ #define GST_DP_VERSION_MAJOR 0 -#define GST_DP_VERSION_MINOR 1 +#define GST_DP_VERSION_MINOR 2 -#define GST_DP_HEADER_LENGTH 60 /* header size in bytes */ +#define GST_DP_HEADER_LENGTH 62 /* header size in bytes */ /* header flags */ diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h index 386916e14d..18834c2e5d 100644 --- a/gst/gdp/dp-private.h +++ b/gst/gdp/dp-private.h @@ -33,15 +33,16 @@ G_BEGIN_DECLS #define GST_DP_HEADER_MAJOR_VERSION(x) ((x)[0]) #define GST_DP_HEADER_MINOR_VERSION(x) ((x)[1]) #define GST_DP_HEADER_FLAGS(x) ((x)[2]) -#define GST_DP_HEADER_PAYLOAD_TYPE(x) ((x)[3]) -#define GST_DP_HEADER_PAYLOAD_LENGTH(x) GST_READ_UINT32_BE (x + 4) -#define GST_DP_HEADER_TIMESTAMP(x) GST_READ_UINT64_BE (x + 8) -#define GST_DP_HEADER_DURATION(x) GST_READ_UINT64_BE (x + 16) -#define GST_DP_HEADER_OFFSET(x) GST_READ_UINT64_BE (x + 24) -#define GST_DP_HEADER_OFFSET_END(x) GST_READ_UINT64_BE (x + 32) -#define GST_DP_HEADER_BUFFER_FLAGS(x) GST_READ_UINT16_BE (x + 40) -#define GST_DP_HEADER_CRC_HEADER(x) GST_READ_UINT16_BE (x + 56) -#define GST_DP_HEADER_CRC_PAYLOAD(x) GST_READ_UINT16_BE (x + 58) +/* free byte here to align */ +#define GST_DP_HEADER_PAYLOAD_TYPE(x) GST_READ_UINT16_BE (x + 4) +#define GST_DP_HEADER_PAYLOAD_LENGTH(x) GST_READ_UINT32_BE (x + 6) +#define GST_DP_HEADER_TIMESTAMP(x) GST_READ_UINT64_BE (x + 10) +#define GST_DP_HEADER_DURATION(x) GST_READ_UINT64_BE (x + 18) +#define GST_DP_HEADER_OFFSET(x) GST_READ_UINT64_BE (x + 26) +#define GST_DP_HEADER_OFFSET_END(x) GST_READ_UINT64_BE (x + 34) +#define GST_DP_HEADER_BUFFER_FLAGS(x) GST_READ_UINT16_BE (x + 42) +#define GST_DP_HEADER_CRC_HEADER(x) GST_READ_UINT16_BE (x + 58) +#define GST_DP_HEADER_CRC_PAYLOAD(x) GST_READ_UINT16_BE (x + 60) void gst_dp_init (void); void gst_dp_dump_byte_array (guint8 *array, guint length); From 68158437c5ba665780e35ad466147f69366fa934 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 10 Oct 2005 23:55:39 +0000 Subject: [PATCH 19/54] gdp: fix more valgrind warnings before turning up the heat Original commit message from CVS: fix more valgrind warnings before turning up the heat --- gst/gdp/dataprotocol.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 7c39492bea..804ee16dbd 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -51,7 +51,7 @@ gst_dp_crc (const guint8 * buffer, register guint length) { static gboolean initialized = FALSE; static guint16 crc_table[256]; - guint16 crc_register; + guint16 crc_register = CRC_INIT; unsigned long i, j, k; if (!initialized) { @@ -66,8 +66,6 @@ gst_dp_crc (const guint8 * buffer, register guint length) initialized = TRUE; } - crc_register = CRC_INIT; /* always init register */ - /* calc CRC */ for (; length--;) { crc_register = (guint16) ((crc_register << 8) ^ @@ -83,7 +81,7 @@ gst_dp_dump_byte_array (guint8 * array, guint length) { int i; int n = 8; /* number of bytes per line */ - gchar *line = g_malloc (3 * n + 1); + gchar *line = g_malloc0 (3 * n + 1); GST_LOG ("dumping byte array of length %d", length); for (i = 0; i < length; ++i) { @@ -170,7 +168,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, g_return_val_if_fail (header, FALSE); *length = GST_DP_HEADER_LENGTH; - h = g_malloc (GST_DP_HEADER_LENGTH); + h = g_malloc0 (GST_DP_HEADER_LENGTH); /* version, flags, type */ h[0] = (guint8) GST_DP_VERSION_MAJOR; @@ -244,7 +242,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, g_return_val_if_fail (payload, FALSE); *length = GST_DP_HEADER_LENGTH; - h = g_malloc (GST_DP_HEADER_LENGTH); + h = g_malloc0 (GST_DP_HEADER_LENGTH); string = (guchar *) gst_caps_to_string (caps); From 8572c5fc766ca10ad38b9a7963ad516d969705af Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Thu, 13 Oct 2005 16:26:12 +0000 Subject: [PATCH 20/54] gdp: Fix Timmeke Waymans bug. Original commit message from CVS: 2005-10-13 Andy Wingo * libs/gst/dataprotocol/dataprotocol.c (gst_dp_packet_from_caps): Fix Timmeke Waymans bug. (gst_dp_caps_from_packet): Make sure we pass a NUL-terminated string of the proper length to gst_caps_from_string. There's a potential for, before this fix, that this could cause someone connecting over the network to cause a segfault if the payload is not NUL-terminated. --- gst/gdp/dataprotocol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 804ee16dbd..aaf3d3efbb 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -254,7 +254,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_CAPS); /* buffer properties */ - GST_WRITE_UINT32_BE (h + 8, strlen ((gchar *) string) + 1); /* include trailing 0 */ + GST_WRITE_UINT32_BE (h + 6, strlen ((gchar *) string) + 1); /* include trailing 0 */ GST_WRITE_UINT64_BE (h + 10, (guint64) 0); GST_WRITE_UINT64_BE (h + 18, (guint64) 0); GST_WRITE_UINT64_BE (h + 26, (guint64) 0); @@ -444,15 +444,16 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, const guint8 * payload) { GstCaps *caps; - const gchar *string; + gchar *string; g_return_val_if_fail (header, NULL); g_return_val_if_fail (payload, NULL); g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == GST_DP_PAYLOAD_CAPS, NULL); - string = (gchar *) payload; + string = g_strndup ((gchar *) payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); caps = gst_caps_from_string (string); + g_free (string); return caps; } From 76424103fe483c6474c040b9248504feae4156e7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 18 Dec 2005 16:04:41 +0000 Subject: [PATCH 21/54] gdp: Documentation updates. Original commit message from CVS: * libs/gst/base/gstadapter.c: * libs/gst/base/gstadapter.h: * libs/gst/base/gstbasesink.c: (gst_base_sink_class_init), (gst_base_sink_get_position): * libs/gst/base/gstbasesink.h: * libs/gst/base/gstbasesrc.c: (gst_base_src_class_init), (gst_base_src_default_query), (gst_base_src_default_do_seek), (gst_base_src_do_seek), (gst_base_src_perform_seek), (gst_base_src_send_event), (gst_base_src_update_length), (gst_base_src_get_range), (gst_base_src_loop), (gst_base_src_start): * libs/gst/base/gstbasesrc.h: * libs/gst/base/gstbasetransform.h: * libs/gst/base/gstcollectpads.h: * libs/gst/base/gstpushsrc.c: * libs/gst/base/gstpushsrc.h: * libs/gst/dataprotocol/dataprotocol.c: * libs/gst/dataprotocol/dataprotocol.h: * libs/gst/net/gstnetclientclock.h: * libs/gst/net/gstnettimeprovider.h: Documentation updates. --- gst/gdp/dataprotocol.c | 4 ++++ gst/gdp/dataprotocol.h | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index aaf3d3efbb..1316682b30 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -124,6 +124,8 @@ gst_dp_init (void) * gst_dp_header_payload_length: * @header: the byte header of the packet array * + * Get the length of the payload described by @header. + * * Returns: the length of the payload this header describes. */ guint32 @@ -136,6 +138,8 @@ gst_dp_header_payload_length (const guint8 * header) * gst_dp_header_payload_type: * @header: the byte header of the packet array * + * Get the type of the payload described by @header. + * * Returns: the #GstDPPayloadType the payload this header describes. */ GstDPPayloadType diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index a326a912f1..0f6024820b 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -29,14 +29,35 @@ G_BEGIN_DECLS -/* GStreamer Data Protocol Version */ +/** + * GST_DP_VERSION_MAJOR: + * + * The major version number of the GStreamer Data Protocol. + */ #define GST_DP_VERSION_MAJOR 0 +/** + * GST_DP_VERSION_MINOR: + * + * The minor version number of the GStreamer Data Protocol. + */ #define GST_DP_VERSION_MINOR 2 -#define GST_DP_HEADER_LENGTH 62 /* header size in bytes */ +/** + * GST_DP_HEADER_LENGTH: + * + * The header size in bytes. + */ +#define GST_DP_HEADER_LENGTH 62 - -/* header flags */ +/** + * GstDPHeaderFlag: + * @GST_DP_HEADER_FLAG_NONE: No flag present. + * @GST_DP_HEADER_FLAG_CRC_HEADER: a header CRC field is present. + * @GST_DP_HEADER_FLAG_CRC_PAYLOAD: a payload CRC field is present. + * @GST_DP_HEADER_FLAG_CRC: a CRC for header and payload is present. + * + * header flags for the dataprotocol. + */ typedef enum { GST_DP_HEADER_FLAG_NONE = 0, GST_DP_HEADER_FLAG_CRC_HEADER = (1 << 0), @@ -44,7 +65,16 @@ typedef enum { GST_DP_HEADER_FLAG_CRC = (1 << 1) | (1 <<0), } GstDPHeaderFlag; -/* payload types */ +/** + * GstDPPayloadType: + * @GST_DP_PAYLOAD_NONE: Invalid payload type. + * @GST_DP_PAYLOAD_BUFFER: #GstBuffer payload packet. + * @GST_DP_PAYLOAD_CAPS: #GstCaps payload packet. + * @GST_DP_PAYLOAD_EVENT_NONE: First value of #GstEvent payload packets. + * + * The GDP payload types. a #GstEvent payload type is encoded with the + * event type number starting from @GST_DP_PAYLOAD_EVENT_NONE. + */ typedef enum { GST_DP_PAYLOAD_NONE = 0, GST_DP_PAYLOAD_BUFFER, From ed4d76a9f0cbae93e8fb5f6d95f6d9ecb1ff055e Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 10 Mar 2006 15:30:27 +0000 Subject: [PATCH 22/54] gdp: Fix docs for dataprocotol to not get the return types completely wrong for a fe... Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: Fix docs for dataprocotol to not get the return types completely wrong for a few functions. --- gst/gdp/dataprotocol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 1316682b30..9598321e4c 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -413,7 +413,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, * Use this function if you want to pre-allocate a buffer based on the * packet header to read the packet payload in to. * - * Returns: %TRUE if the buffer was successfully created. + * Returns: A #GstBuffer if the buffer was successfully created, or NULL. */ GstBuffer * gst_dp_buffer_from_header (guint header_length, const guint8 * header) @@ -441,7 +441,8 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) * * Creates a newly allocated #GstCaps from the given packet. * - * Returns: %TRUE if the caps was successfully created. + * Returns: A #GstCaps containing the caps represented in the packet, + * or NULL if the packet could not be converted. */ GstCaps * gst_dp_caps_from_packet (guint header_length, const guint8 * header, @@ -469,7 +470,8 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, * * Creates a newly allocated #GstEvent from the given packet. * - * Returns: %TRUE 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 * gst_dp_event_from_packet (guint header_length, const guint8 * header, From 039571d0134051e155fdf7532df8d5b7ff9cc066 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 28 Apr 2006 13:40:15 +0000 Subject: [PATCH 23/54] gdp: Fixes in reading/writing events over GDP (not currently used?) - dereferencing ... Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_event), (gst_dp_event_from_packet): Fixes in reading/writing events over GDP (not currently used?) - dereferencing NULL events for unknown/invalid event types, memory leak, and change g_warning to GST_WARNING. --- gst/gdp/dataprotocol.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 9598321e4c..4f909b1380 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -319,7 +319,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, /* first construct payload, since we need the length */ switch (GST_EVENT_TYPE (event)) { case GST_EVENT_UNKNOWN: - g_warning ("Unknown event, ignoring"); + GST_WARNING ("Unknown event, ignoring"); *length = 0; g_free (h); return FALSE; @@ -355,10 +355,12 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, case GST_EVENT_QOS: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: - g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); + GST_WARNING ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); + *length = 0; + g_free (h); return FALSE; default: - g_warning ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); + GST_WARNING ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); *length = 0; g_free (h); return FALSE; @@ -486,7 +488,7 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE; switch (type) { case GST_EVENT_UNKNOWN: - g_warning ("Unknown event, ignoring"); + GST_WARNING ("Unknown event, ignoring"); return FALSE; case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: @@ -520,10 +522,10 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, case GST_EVENT_QOS: case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: - g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); + GST_WARNING ("Unhandled event type %d, ignoring", type); return FALSE; default: - g_warning ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); + GST_WARNING ("Unknown event type %d, ignoring", type); return FALSE; } From 8afe1aa8e9230807126c88501f42855c4788a63a Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 8 May 2006 15:53:12 +0000 Subject: [PATCH 24/54] gdp: whitespace, comment, doc fixup Original commit message from CVS: whitespace, comment, doc fixup --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 4f909b1380..4620064c19 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -549,7 +549,7 @@ gst_dp_validate_header (guint header_length, const guint8 * header) if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_HEADER)) return TRUE; crc_read = GST_DP_HEADER_CRC_HEADER (header); - /* don't included the last two crc fields for the crc check */ + /* don't include the last two crc fields for the crc check */ crc_calculated = gst_dp_crc (header, header_length - 4); if (crc_read != crc_calculated) { GST_WARNING ("header crc mismatch: read %02x, calculated %02x", crc_read, From e0e93cd3d1ee92c899284e13520e84151c106134 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 1 Jun 2006 11:13:44 +0000 Subject: [PATCH 25/54] gdp: make sure we zero the whole ABI-compatible area Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_header_from_buffer): make sure we zero the whole ABI-compatible area --- gst/gdp/dataprotocol.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 4620064c19..ef35a13b8c 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -196,8 +196,9 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask); /* ABI padding */ - GST_WRITE_UINT32_BE (h + 44, (guint64) 0); - GST_WRITE_UINT64_BE (h + 48, (guint64) 0); + 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; From c0fc54e2b4c32714b80c88324114f90593591734 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 2 Jun 2006 10:08:31 +0000 Subject: [PATCH 26/54] gdp: make gst_dp_crc() public Original commit message from CVS: * docs/libs/gstreamer-libs-sections.txt: * docs/libs/tmpl/gstdataprotocol.sgml: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_crc): * libs/gst/dataprotocol/dataprotocol.h: API: make gst_dp_crc() public --- gst/gdp/dataprotocol.c | 13 +++++++++++-- gst/gdp/dataprotocol.h | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index ef35a13b8c..c4e06b35a8 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -46,8 +46,17 @@ GST_DEBUG_CATEGORY (data_protocol_debug); #define POLY 0x1021 #define CRC_INIT 0xFFFF -static guint16 -gst_dp_crc (const guint8 * buffer, register guint length) +/** + * gst_dp_crc: + * + * Calculate a CRC for the given buffer over the given number of bytes. + * This is only provided for verification purposes; typical GDP users + * will not need this function. + * + * Returns: a two-byte CRC checksum. + */ +guint16 +gst_dp_crc (const guint8 * buffer, guint length) { static gboolean initialized = FALSE; static guint16 crc_table[256]; diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 0f6024820b..25c09c6f0e 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -84,6 +84,10 @@ typedef enum { void gst_dp_init (void); +/* crc checksum */ +guint16 gst_dp_crc (const guint8 * buffer, + guint length); + /* payload information from header */ guint32 gst_dp_header_payload_length (const guint8 * header); GstDPPayloadType From cbb7337a938d9ea3c735f7375eef32cb85950147 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 2 Jun 2006 10:58:47 +0000 Subject: [PATCH 27/54] gdp: factor out some common header init code 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 --- gst/gdp/dataprotocol.c | 55 ++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index c4e06b35a8..fdfe277e57 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -1,6 +1,6 @@ /* GStreamer * Copyright (C) <1999> Erik Walthinsen - * Copyright (C) <2004> Thomas Vander Stichele + * Copyright (C) 2004,2006 Thomas Vander Stichele * * dataprotocol.c: Functions implementing the GStreamer Data Protocol * @@ -34,6 +34,23 @@ 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 From 207c0ce3f1cc463276d51a03fbc557e1803347a8 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Fri, 2 Jun 2006 16:46:19 +0000 Subject: [PATCH 28/54] gdp: factor out CRC code 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 CRC code --- gst/gdp/dataprotocol.c | 58 ++++++++++++------------------------------ 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index fdfe277e57..e68926f4b9 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -39,7 +39,6 @@ GST_DEBUG_CATEGORY (data_protocol_debug); /* 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; \ @@ -50,6 +49,19 @@ G_STMT_START { \ GST_WRITE_UINT64_BE (h + 50, (guint64) 0); /* ABI padding */ \ } G_STMT_END +#define GST_DP_SET_CRC(h, flags, payload, length); \ +G_STMT_START { \ + guint16 crc = 0; \ + if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) \ + /* we don't crc the last four bytes since they are crc's */ \ + crc = gst_dp_crc (h, 58); \ + GST_WRITE_UINT16_BE (h + 58, crc); \ + \ + crc = 0; \ + if (length && (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD)) \ + crc = gst_dp_crc (payload, length); \ + GST_WRITE_UINT16_BE (h + 60, crc); \ +} G_STMT_END /* calculate a CCITT 16 bit CRC check value for a given byte array */ /* @@ -191,7 +203,6 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header) { guint8 *h; - guint16 crc; guint16 flags_mask; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); @@ -218,19 +229,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask); - /* CRC */ - crc = 0; - if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { - /* we don't crc the last four bytes of the header since they are crc's */ - crc = gst_dp_crc (h, 58); - } - GST_WRITE_UINT16_BE (h + 58, crc); - - crc = 0; - if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { - crc = gst_dp_crc (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); - } - GST_WRITE_UINT16_BE (h + 60, crc); + GST_DP_SET_CRC (h, flags, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); GST_LOG ("created header from buffer:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -255,7 +254,6 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) { guint8 *h; - guint16 crc; guchar *string; /* FIXME: GST_IS_CAPS doesn't work @@ -280,18 +278,7 @@ 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); - /* CRC */ - crc = 0; - if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { - crc = gst_dp_crc (h, 58); - } - GST_WRITE_UINT16_BE (h + 58, crc); - - crc = 0; - if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { - crc = gst_dp_crc (string, strlen ((gchar *) string) + 1); - } - GST_WRITE_UINT16_BE (h + 60, crc); + GST_DP_SET_CRC (h, flags, string, strlen ((gchar *) string) + 1); GST_LOG ("created header from caps:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); @@ -317,7 +304,6 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) { guint8 *h; - guint16 crc; guint pl_length; /* length of payload */ g_return_val_if_fail (event, FALSE); @@ -387,19 +373,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, /* timestamp */ GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event)); - /* CRC */ - crc = 0; - if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) { - crc = gst_dp_crc (h, 58); - } - GST_WRITE_UINT16_BE (h + 58, crc); - - crc = 0; - /* events can have a NULL payload */ - if (*payload && flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) { - crc = gst_dp_crc (*payload, strlen ((gchar *) * payload) + 1); - } - GST_WRITE_UINT16_BE (h + 60, crc); + GST_DP_SET_CRC (h, flags, *payload, pl_length); GST_LOG ("created header from event:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); From 99e9c6d6330f3fc322b934378240f0b75a7f5b99 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 6 Jun 2006 14:24:00 +0000 Subject: [PATCH 29/54] gdp: add a GstDPPacketizer object, and create/free functions Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_header_from_buffer_any), (gst_dp_packet_from_caps_any), (gst_dp_version_get_type), (gst_dp_init), (gst_dp_header_from_buffer), (gst_dp_header_from_buffer_1_0), (gst_dp_packet_from_caps), (gst_dp_packet_from_caps_1_0), (gst_dp_packet_from_event), (gst_dp_packet_from_event_1_0), (gst_dp_event_from_packet_0_2), (gst_dp_event_from_packet_1_0), (gst_dp_event_from_packet), (gst_dp_packetizer_new), (gst_dp_packetizer_free): * libs/gst/dataprotocol/dataprotocol.h: API: add a GstDPPacketizer object, and create/free functions API: add GstDPVersion enum Add 1.0 event function that uses the string serialization Serialize more useful buffer flags Fixes #343988 --- gst/gdp/dataprotocol.c | 402 ++++++++++++++++++++++++++++++++--------- gst/gdp/dataprotocol.h | 53 +++++- 2 files changed, 367 insertions(+), 88 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index e68926f4b9..74da67f855 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -20,6 +20,42 @@ * Boston, MA 02111-1307, USA. */ +/** + * SECTION:gstdataprotocol + * @short_description: Serialization of caps, buffers and events. + * @see_also: #GstCaps, #GstEvent, #GstBuffer + * + * This helper library provides serialization of GstBuffer, GstCaps and + * GstEvent structures. + * + * This serialization is useful when GStreamer needs to interface with + * the outside world to transport data between distinct GStreamer pipelines. + * The connections with the outside world generally don't have mechanisms + * to transport properties of these structures. + * + * For example, transporting buffers across named pipes or network connections + * doesn't maintain the buffer size and separation. + * + * This data protocol assumes a reliable connection-oriented transport, such as + * TCP, a pipe, or a file. The protocol does not serialize the caps for + * each buffer; instead, it transport the caps only when they change in the + * stream. This implies that there will always be a caps packet before any + * buffer packets. + * + * Version 0.2 serializes only a small subset of all events, with a custom + * payload for each type. Also, all GDP streams start with the initial caps + * packet. + * + * Version 1.0 serializes all events by taking the string representation of + * the event as the payload. In addition, GDP streams can now start with + * events as well, as required by the new data stream model in GStreamer 0.10. + * + * Converting buffers, caps and events to GDP buffers is done using a + * #GstDPPacketizer object and invoking its packetizer functions. + * For backwards-compatibility reasons, the old 0.2 methods are still + * available but deprecated. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -37,8 +73,13 @@ GST_DEBUG_CATEGORY (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) \ +#define GST_DP_INIT_HEADER(h, version, flags, type) \ G_STMT_START { \ + gint maj = 0, min = 0; \ + switch (version) { \ + case GST_DP_VERSION_0_2: maj = 0; min = 2; break; \ + case GST_DP_VERSION_1_0: maj = 1; min = 0; break; \ + } \ h[0] = (guint8) maj; \ h[1] = (guint8) min; \ h[2] = (guint8) flags; \ @@ -75,6 +116,89 @@ G_STMT_START { \ #define POLY 0x1021 #define CRC_INIT 0xFFFF +/*** HELPER FUNCTIONS ***/ + +static gboolean +gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, + guint * length, guint8 ** header, GstDPVersion version) +{ + guint8 *h; + guint16 flags_mask; + + g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); + g_return_val_if_fail (header, FALSE); + + *length = GST_DP_HEADER_LENGTH; + h = g_malloc0 (GST_DP_HEADER_LENGTH); + + /* version, flags, type */ + GST_DP_INIT_HEADER (h, version, flags, GST_DP_PAYLOAD_BUFFER); + + /* buffer properties */ + GST_WRITE_UINT32_BE (h + 6, GST_BUFFER_SIZE (buffer)); + GST_WRITE_UINT64_BE (h + 10, GST_BUFFER_TIMESTAMP (buffer)); + GST_WRITE_UINT64_BE (h + 18, GST_BUFFER_DURATION (buffer)); + GST_WRITE_UINT64_BE (h + 26, GST_BUFFER_OFFSET (buffer)); + GST_WRITE_UINT64_BE (h + 34, GST_BUFFER_OFFSET_END (buffer)); + + /* data flags; eats two bytes from the ABI area */ + /* we copy everything but the read-only flags */ + flags_mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_DISCONT | + GST_BUFFER_FLAG_IN_CAPS | GST_BUFFER_FLAG_GAP | + GST_BUFFER_FLAG_DELTA_UNIT; + + GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask); + + GST_DP_SET_CRC (h, flags, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); + + GST_LOG ("created header from buffer:"); + gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; + return TRUE; +} + +static gboolean +gst_dp_packet_from_caps_any (const GstCaps * caps, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload, GstDPVersion version) +{ + guint8 *h; + guchar *string; + guint payload_length; + + /* FIXME: GST_IS_CAPS doesn't work + g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */ + g_return_val_if_fail (caps, FALSE); + g_return_val_if_fail (header, FALSE); + g_return_val_if_fail (payload, FALSE); + + *length = GST_DP_HEADER_LENGTH; + h = g_malloc0 (GST_DP_HEADER_LENGTH); + + string = (guchar *) gst_caps_to_string (caps); + payload_length = strlen ((gchar *) string) + 1; /* include trailing 0 */ + + /* version, flags, type */ + GST_DP_INIT_HEADER (h, version, flags, GST_DP_PAYLOAD_CAPS); + + /* buffer properties */ + GST_WRITE_UINT32_BE (h + 6, payload_length); + GST_WRITE_UINT64_BE (h + 10, (guint64) 0); + GST_WRITE_UINT64_BE (h + 18, (guint64) 0); + GST_WRITE_UINT64_BE (h + 26, (guint64) 0); + GST_WRITE_UINT64_BE (h + 34, (guint64) 0); + + GST_DP_SET_CRC (h, flags, string, payload_length); + + GST_LOG ("created header from caps:"); + gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; + *payload = string; + return TRUE; +} + + +/*** PUBLIC FUNCTIONS ***/ + /** * gst_dp_crc: * @@ -134,6 +258,23 @@ gst_dp_dump_byte_array (guint8 * array, guint length) g_free (line); } +GType +gst_dp_version_get_type (void) +{ + static GType gst_dp_version_type = 0; + static const GEnumValue gst_dp_version[] = { + {GST_DP_VERSION_0_2, "GDP Version 0.2", "0.2"}, + {GST_DP_VERSION_1_0, "GDP Version 1.0", "1.0"}, + {0, NULL, NULL}, + }; + + if (!gst_dp_version_type) { + gst_dp_version_type = + g_enum_register_static ("GstDPVersion", gst_dp_version); + } + return gst_dp_version_type; +}; + /** * gst_dp_init: * @@ -152,12 +293,12 @@ gst_dp_init (void) _gst_dp_initialized = TRUE; + gst_dp_version_get_type (); + GST_DEBUG_CATEGORY_INIT (data_protocol_debug, "gdp", 0, "GStreamer Data Protocol"); } -/*** PUBLIC FUNCTIONS ***/ - /** * gst_dp_header_payload_length: * @header: the byte header of the packet array @@ -186,6 +327,8 @@ gst_dp_header_payload_type (const guint8 * header) return GST_DP_HEADER_PAYLOAD_TYPE (header); } +/*** PACKETIZER FUNCTIONS ***/ + /** * gst_dp_header_from_buffer: * @buffer: a #GstBuffer to create a header for @@ -195,46 +338,24 @@ gst_dp_header_payload_type (const guint8 * header) * * Creates a GDP header from the given buffer. * + * Deprecated: use a #GstDPPacketizer + * * Returns: %TRUE if the header was successfully created. */ - gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header) { - guint8 *h; - guint16 flags_mask; + return gst_dp_header_from_buffer_any (buffer, flags, length, header, + GST_DP_VERSION_0_2); +} - g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); - g_return_val_if_fail (header, FALSE); - - *length = GST_DP_HEADER_LENGTH; - h = g_malloc0 (GST_DP_HEADER_LENGTH); - - /* version, flags, type */ - 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)); - GST_WRITE_UINT64_BE (h + 10, GST_BUFFER_TIMESTAMP (buffer)); - GST_WRITE_UINT64_BE (h + 18, GST_BUFFER_DURATION (buffer)); - GST_WRITE_UINT64_BE (h + 26, GST_BUFFER_OFFSET (buffer)); - GST_WRITE_UINT64_BE (h + 34, GST_BUFFER_OFFSET_END (buffer)); - - /* 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); - - GST_DP_SET_CRC (h, flags, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); - - GST_LOG ("created header from buffer:"); - gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); - *header = h; - return TRUE; +static gboolean +gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, + guint * length, guint8 ** header) +{ + return gst_dp_header_from_buffer_any (buffer, flags, length, header, + GST_DP_VERSION_1_0); } /** @@ -247,44 +368,24 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, * * Creates a GDP packet from the given caps. * + * Deprecated: use a #GstDPPacketizer + * * Returns: %TRUE if the packet was successfully created. */ gboolean gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) { - guint8 *h; - guchar *string; + return gst_dp_packet_from_caps_any (caps, flags, length, header, payload, + GST_DP_VERSION_0_2); +} - /* FIXME: GST_IS_CAPS doesn't work - g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */ - g_return_val_if_fail (caps, FALSE); - g_return_val_if_fail (header, FALSE); - g_return_val_if_fail (payload, FALSE); - - *length = GST_DP_HEADER_LENGTH; - h = g_malloc0 (GST_DP_HEADER_LENGTH); - - string = (guchar *) gst_caps_to_string (caps); - - /* version, flags, type */ - 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 */ - GST_WRITE_UINT64_BE (h + 10, (guint64) 0); - GST_WRITE_UINT64_BE (h + 18, (guint64) 0); - GST_WRITE_UINT64_BE (h + 26, (guint64) 0); - GST_WRITE_UINT64_BE (h + 34, (guint64) 0); - - GST_DP_SET_CRC (h, flags, string, strlen ((gchar *) string) + 1); - - GST_LOG ("created header from caps:"); - gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); - *header = h; - *payload = string; - return TRUE; +gboolean +gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload) +{ + return gst_dp_packet_from_caps_any (caps, flags, length, header, payload, + GST_DP_VERSION_1_0); } /** @@ -297,6 +398,8 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, * * Creates a GDP packet from the given event. * + * Deprecated: use a #GstDPPacketizer + * * Returns: %TRUE if the packet was successfully created. */ gboolean @@ -365,7 +468,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, } /* version, flags, type */ - GST_DP_INIT_HEADER (h, GST_DP_VERSION_MAJOR, GST_DP_VERSION_MINOR, flags, + GST_DP_INIT_HEADER (h, GST_DP_VERSION_0_2, flags, GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event)); /* length */ @@ -381,6 +484,51 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, return TRUE; } +static gboolean +gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload) +{ + guint8 *h; + guint32 pl_length; /* length of payload */ + guchar *string = NULL; + + g_return_val_if_fail (event, FALSE); + g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + g_return_val_if_fail (header, FALSE); + g_return_val_if_fail (payload, FALSE); + + *length = GST_DP_HEADER_LENGTH; + h = g_malloc0 (GST_DP_HEADER_LENGTH); + + if (event->structure) { + string = (guchar *) gst_structure_to_string (event->structure); + GST_LOG ("event %p has structure, string %s", event, string); + pl_length = strlen ((gchar *) string) + 1; /* include trailing 0 */ + } else { + GST_LOG ("event %p has no structure"); + pl_length = 0; + } + + /* version, flags, type */ + GST_DP_INIT_HEADER (h, GST_DP_VERSION_1_0, flags, + GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event)); + + /* length */ + GST_WRITE_UINT32_BE (h + 6, pl_length); + /* timestamp */ + GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event)); + + GST_DP_SET_CRC (h, flags, *payload, pl_length); + + GST_LOG ("created header from event:"); + gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; + *payload = string; + return TRUE; +} + +/*** DEPACKETIZING FUNCTIONS ***/ + /** * gst_dp_buffer_from_header: * @header_length: the length of the packet header @@ -441,27 +589,13 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, return caps; } -/** - * gst_dp_event_from_packet: - * @header_length: the length of the packet header - * @header: the byte array of the packet header - * @payload: the byte array of the packet payload - * - * Creates a newly allocated #GstEvent from the given packet. - * - * Returns: A #GstEvent if the event was successfully created, - * or NULL if an event could not be read from the payload. - */ -GstEvent * -gst_dp_event_from_packet (guint header_length, const guint8 * header, +static GstEvent * +gst_dp_event_from_packet_0_2 (guint header_length, const guint8 * header, const guint8 * payload) { GstEvent *event = NULL; GstEventType type; - g_return_val_if_fail (header, NULL); - /* payload can be NULL, e.g. for an EOS event */ - type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE; switch (type) { case GST_EVENT_UNKNOWN: @@ -509,6 +643,58 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, return event; } +static GstEvent * +gst_dp_event_from_packet_1_0 (guint header_length, const guint8 * header, + const guint8 * payload) +{ + GstEvent *event = NULL; + GstEventType type; + gchar *string; + GstStructure *s; + + type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE; + string = g_strndup ((gchar *) payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); + s = gst_structure_from_string (string, NULL); + g_free (string); + if (!s) + return NULL; + event = gst_event_new_custom (type, s); + return event; +} + + +/** + * gst_dp_event_from_packet: + * @header_length: the length of the packet header + * @header: the byte array of the packet header + * @payload: the byte array of the packet payload + * + * Creates a newly allocated #GstEvent from the given packet. + * + * Returns: A #GstEvent if the event was successfully created, + * or NULL if an event could not be read from the payload. + */ +GstEvent * +gst_dp_event_from_packet (guint header_length, const guint8 * header, + const guint8 * payload) +{ + guint8 major, minor; + + g_return_val_if_fail (header, NULL); + + major = GST_DP_HEADER_MAJOR_VERSION (header); + minor = GST_DP_HEADER_MINOR_VERSION (header); + + if (major == 0 && minor == 2) + return gst_dp_event_from_packet_0_2 (header_length, header, payload); + else if (major == 1 && minor == 0) + return gst_dp_event_from_packet_1_0 (header_length, header, payload); + else { + GST_ERROR ("Unknown GDP version %d.%d", major, minor); + return NULL; + } +} + /** * gst_dp_validate_header: * @header_length: the length of the packet header @@ -588,3 +774,51 @@ gst_dp_validate_packet (guint header_length, const guint8 * header, return TRUE; } + +/** + * gst_dp_packetizer_new: + * @version: the #GstDPVersion of the protocol to packetize for. + * + * Creates a new packetizer. + * + * Returns: a newly allocated #GstDPPacketizer + */ +GstDPPacketizer * +gst_dp_packetizer_new (GstDPVersion version) +{ + GstDPPacketizer *ret; + + ret = g_malloc0 (sizeof (GstDPPacketizer)); + ret->version = version; + + switch (version) { + case GST_DP_VERSION_0_2: + ret->header_from_buffer = gst_dp_header_from_buffer; + ret->packet_from_caps = gst_dp_packet_from_caps; + ret->packet_from_event = gst_dp_packet_from_event; + break; + case GST_DP_VERSION_1_0: + ret->header_from_buffer = gst_dp_header_from_buffer_1_0; + ret->packet_from_caps = gst_dp_packet_from_caps_1_0; + ret->packet_from_event = gst_dp_packet_from_event_1_0; + break; + default: + g_free (ret); + ret = NULL; + break; + } + + return ret; +} + +/** + * gst_dp_packetizer_free: + * @packetizer: the #GstDPPacketizer to free. + * + * Free the given packetizer. + */ +void +gst_dp_packetizer_free (GstDPPacketizer * packetizer) +{ + g_free (packetizer); +} diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 25c09c6f0e..5783dfd899 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -1,6 +1,6 @@ /* GStreamer - * Copyright (C) <1999> Erik Walthinsen - * Copyright (C) <2004> Thomas Vander Stichele + * Copyright (C) 1999 Erik Walthinsen + * Copyright (C) 2004,2006 Thomas Vander Stichele * * dataprotocol.h: Functions implementing the GStreamer Data Protocol * @@ -29,6 +29,21 @@ G_BEGIN_DECLS +/** + * GstDPVersion: + * @GST_DP_VERSION_0_2: protocol version 0.2 + * @GST_DP_VERSION_1_0: protocol version 1.0 + * + * The version of the GDP protocol being used. + */ +typedef enum { + GST_DP_VERSION_0_2 = 1, + GST_DP_VERSION_1_0, +} GstDPVersion; + +GType gst_dp_version_get_type (); +#define GST_TYPE_DP_VERSION (gst_dp_version_get_type ()) + /** * GST_DP_VERSION_MAJOR: * @@ -62,7 +77,7 @@ typedef enum { GST_DP_HEADER_FLAG_NONE = 0, GST_DP_HEADER_FLAG_CRC_HEADER = (1 << 0), GST_DP_HEADER_FLAG_CRC_PAYLOAD = (1 << 1), - GST_DP_HEADER_FLAG_CRC = (1 << 1) | (1 <<0), + GST_DP_HEADER_FLAG_CRC = (1 << 1) | (1 << 0), } GstDPHeaderFlag; /** @@ -82,8 +97,39 @@ typedef enum { GST_DP_PAYLOAD_EVENT_NONE = 64, } GstDPPayloadType; +typedef gboolean (*GstDPHeaderFromBufferFunction) (const GstBuffer * buffer, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header); +typedef gboolean (*GstDPPacketFromCapsFunction) (const GstCaps * caps, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header, + guint8 ** payload); +typedef gboolean (*GstDPPacketFromEventFunction) (const GstEvent * event, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header, + guint8 ** payload); +typedef struct { + GstDPVersion version; + + GstDPHeaderFromBufferFunction header_from_buffer; + GstDPPacketFromCapsFunction packet_from_caps; + GstDPPacketFromEventFunction packet_from_event; + + /*< private >*/ + gpointer _gst_reserved[GST_PADDING]; +} GstDPPacketizer; + + void gst_dp_init (void); +/* packetizer */ +GstDPPacketizer * + gst_dp_packetizer_new (GstDPVersion version); +void gst_dp_packetizer_free (GstDPPacketizer *packetizer); + /* crc checksum */ guint16 gst_dp_crc (const guint8 * buffer, guint length); @@ -109,7 +155,6 @@ gboolean gst_dp_packet_from_event (const GstEvent * event, guint8 ** header, guint8 ** payload); - /* converting to GstBuffer/GstEvent/GstCaps */ GstBuffer * gst_dp_buffer_from_header (guint header_length, const guint8 * header); From b09b5bc073f03a746a00bf7d549dcd30c06017cd Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 6 Jun 2006 14:29:54 +0000 Subject: [PATCH 30/54] gdp: add note to docs about GDP versioning; remove tmpl file Original commit message from CVS: add note to docs about GDP versioning; remove tmpl file --- gst/gdp/dataprotocol.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 74da67f855..fa07d0cab9 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -42,6 +42,12 @@ * stream. This implies that there will always be a caps packet before any * buffer packets. * + * The versioning of the protocol is independent of GStreamer's version. + * The major number gets incremented, and the minor reset, for incompatible + * changes. The minor number gets incremented for compatible changes that + * allow clients who do not completely understand the newer protocol version + * to still decode what they do understand. + * * Version 0.2 serializes only a small subset of all events, with a custom * payload for each type. Also, all GDP streams start with the initial caps * packet. From 714f14783e6ad093094388fd88dc6c97b74c4bbe Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 13 Jun 2006 19:24:34 +0000 Subject: [PATCH 31/54] gdp: add a gdp image to the docs Original commit message from CVS: * docs/README: * docs/images/gdp-header.svg: add a gdp image * docs/libs/Makefile.am: * docs/libs/gdp-header.png: * libs/gst/dataprotocol/dataprotocol.c: add it to the API docs * docs/manual/intro-motivation.xml: fix typo --- gst/gdp/dataprotocol.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index fa07d0cab9..887b2eeb72 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -60,6 +60,10 @@ * #GstDPPacketizer object and invoking its packetizer functions. * For backwards-compatibility reasons, the old 0.2 methods are still * available but deprecated. + * + * For reference, this image shows the byte layout of the GDP header: + * + * */ #ifdef HAVE_CONFIG_H From 6dc77f5db1e1ea0962ee50904ef25fda8d0ea223 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 13 Jul 2006 14:02:16 +0000 Subject: [PATCH 32/54] gdp: fix failure to deserialize event packets with empty payload (only ev... Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_event_from_packet_1_0): Fixes #347337: failure to deserialize event packets with empty payload (only event type) --- gst/gdp/dataprotocol.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 887b2eeb72..dd290cc017 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -659,15 +659,16 @@ gst_dp_event_from_packet_1_0 (guint header_length, const guint8 * header, { GstEvent *event = NULL; GstEventType type; - gchar *string; - GstStructure *s; + gchar *string = NULL; + GstStructure *s = NULL; type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE; - string = g_strndup ((gchar *) payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); - s = gst_structure_from_string (string, NULL); - g_free (string); - if (!s) - return NULL; + if (payload) { + string = + g_strndup ((gchar *) payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); + s = gst_structure_from_string (string, NULL); + g_free (string); + } event = gst_event_new_custom (type, s); return event; } From 073ad7d9c9a8fd1972443047df6c670ea4d907b1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 2 Aug 2006 15:19:30 +0000 Subject: [PATCH 33/54] gdp: Make debug category static Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_header_from_buffer_any), (gst_dp_packet_from_caps_any), (gst_dp_crc), (gst_dp_header_payload_length), (gst_dp_header_payload_type), (gst_dp_packet_from_event), (gst_dp_packet_from_event_1_0), (gst_dp_buffer_from_header), (gst_dp_caps_from_packet), (gst_dp_event_from_packet_0_2), (gst_dp_event_from_packet), (gst_dp_validate_header), (gst_dp_validate_payload): Make debug category static Constify the crc table. Do some more arg checking in public functions. Fix some docs and do some small cleanups. * tests/check/libs/gdp.c: (GST_START_TEST), (gst_dp_suite): Add some more checks to see if GDP deals with bogus input. --- gst/gdp/dataprotocol.c | 142 ++++++++++++++++++++++++++++++----------- 1 file changed, 104 insertions(+), 38 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index dd290cc017..9e71bd1071 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -77,7 +77,7 @@ #include "dp-private.h" /* debug category */ -GST_DEBUG_CATEGORY (data_protocol_debug); +GST_DEBUG_CATEGORY_STATIC (data_protocol_debug); #define GST_CAT_DEFAULT data_protocol_debug /* helper macros */ @@ -136,6 +136,7 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, guint16 flags_mask; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); + g_return_val_if_fail (length, FALSE); g_return_val_if_fail (header, FALSE); *length = GST_DP_HEADER_LENGTH; @@ -175,9 +176,8 @@ gst_dp_packet_from_caps_any (const GstCaps * caps, GstDPHeaderFlag flags, guchar *string; guint payload_length; - /* FIXME: GST_IS_CAPS doesn't work - g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */ - g_return_val_if_fail (caps, FALSE); + g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); + g_return_val_if_fail (length, FALSE); g_return_val_if_fail (header, FALSE); g_return_val_if_fail (payload, FALSE); @@ -209,8 +209,45 @@ gst_dp_packet_from_caps_any (const GstCaps * caps, GstDPHeaderFlag flags, /*** PUBLIC FUNCTIONS ***/ +static const guint16 gst_dp_crc_table[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + /** * gst_dp_crc: + * @buffer: array of bytes + * @length: the length of @buffer * * Calculate a CRC for the given buffer over the given number of bytes. * This is only provided for verification purposes; typical GDP users @@ -221,27 +258,14 @@ gst_dp_packet_from_caps_any (const GstCaps * caps, GstDPHeaderFlag flags, guint16 gst_dp_crc (const guint8 * buffer, guint length) { - static gboolean initialized = FALSE; - static guint16 crc_table[256]; guint16 crc_register = CRC_INIT; - unsigned long i, j, k; - if (!initialized) { - for (i = 0; i < 256; i++) { - j = i << 8; - for (k = 8; k--;) { - j = j & 0x8000 ? (j << 1) ^ POLY : j << 1; - } - - crc_table[i] = (guint16) j; - } - initialized = TRUE; - } + g_return_val_if_fail (buffer != NULL || length == 0, 0); /* calc CRC */ for (; length--;) { crc_register = (guint16) ((crc_register << 8) ^ - crc_table[((crc_register >> 8) & 0x00ff) ^ *buffer++]); + gst_dp_crc_table[((crc_register >> 8) & 0x00ff) ^ *buffer++]); } return (0xffff ^ crc_register); } @@ -320,6 +344,8 @@ gst_dp_init (void) guint32 gst_dp_header_payload_length (const guint8 * header) { + g_return_val_if_fail (header != NULL, 0); + return GST_DP_HEADER_PAYLOAD_LENGTH (header); } @@ -334,6 +360,8 @@ gst_dp_header_payload_length (const guint8 * header) GstDPPayloadType gst_dp_header_payload_type (const guint8 * header) { + g_return_val_if_fail (header != NULL, GST_DP_PAYLOAD_NONE); + return GST_DP_HEADER_PAYLOAD_TYPE (header); } @@ -390,7 +418,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, GST_DP_VERSION_0_2); } -gboolean +static gboolean gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) { @@ -419,20 +447,15 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, guint8 *h; guint pl_length; /* length of payload */ - g_return_val_if_fail (event, FALSE); g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + g_return_val_if_fail (length, FALSE); g_return_val_if_fail (header, FALSE); g_return_val_if_fail (payload, FALSE); - *length = GST_DP_HEADER_LENGTH; - h = g_malloc0 (GST_DP_HEADER_LENGTH); - /* first construct payload, since we need the length */ switch (GST_EVENT_TYPE (event)) { case GST_EVENT_UNKNOWN: GST_WARNING ("Unknown event, ignoring"); - *length = 0; - g_free (h); return FALSE; case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: @@ -467,16 +490,16 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: GST_WARNING ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); - *length = 0; - g_free (h); return FALSE; default: GST_WARNING ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); - *length = 0; - g_free (h); return FALSE; } + /* now we can create and fill the header */ + h = g_malloc0 (GST_DP_HEADER_LENGTH); + *length = GST_DP_HEADER_LENGTH; + /* version, flags, type */ GST_DP_INIT_HEADER (h, GST_DP_VERSION_0_2, flags, GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event)); @@ -490,6 +513,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, GST_LOG ("created header from event:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); + *header = h; return TRUE; } @@ -502,8 +526,8 @@ gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, guint32 pl_length; /* length of payload */ guchar *string = NULL; - g_return_val_if_fail (event, FALSE); g_return_val_if_fail (GST_IS_EVENT (event), FALSE); + g_return_val_if_fail (length, FALSE); g_return_val_if_fail (header, FALSE); g_return_val_if_fail (payload, FALSE); @@ -550,6 +574,9 @@ gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, * Use this function if you want to pre-allocate a buffer based on the * packet header to read the packet payload in to. * + * This function does not check the header passed to it, use + * gst_dp_validate_header() first if the header data is unchecked. + * * Returns: A #GstBuffer if the buffer was successfully created, or NULL. */ GstBuffer * @@ -557,10 +584,14 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) { GstBuffer *buffer; + g_return_val_if_fail (header != NULL, NULL); + g_return_val_if_fail (header_length >= GST_DP_HEADER_LENGTH, NULL); g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == GST_DP_PAYLOAD_BUFFER, NULL); + buffer = gst_buffer_new_and_alloc ((guint) GST_DP_HEADER_PAYLOAD_LENGTH (header)); + GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header); GST_BUFFER_DURATION (buffer) = GST_DP_HEADER_DURATION (header); GST_BUFFER_OFFSET (buffer) = GST_DP_HEADER_OFFSET (header); @@ -578,6 +609,10 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) * * Creates a newly allocated #GstCaps from the given packet. * + * This function does not check the arguments passed to it, use + * gst_dp_validate_packet() first if the header and payload data are + * unchecked. + * * Returns: A #GstCaps containing the caps represented in the packet, * or NULL if the packet could not be converted. */ @@ -589,13 +624,16 @@ gst_dp_caps_from_packet (guint header_length, const guint8 * header, gchar *string; g_return_val_if_fail (header, NULL); - g_return_val_if_fail (payload, NULL); + g_return_val_if_fail (header_length >= GST_DP_HEADER_LENGTH, NULL); g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) == GST_DP_PAYLOAD_CAPS, NULL); + g_return_val_if_fail (payload, NULL); + /* 0 sized payload length will work create NULL string */ string = g_strndup ((gchar *) payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); caps = gst_caps_from_string (string); g_free (string); + return caps; } @@ -626,6 +664,8 @@ gst_dp_event_from_packet_0_2 (guint header_length, const guint8 * header, GstSeekType cur_type, stop_type; gint64 cur, stop; + g_return_val_if_fail (payload != NULL, NULL); + /* FIXME, read rate */ rate = 1.0; format = (GstFormat) GST_READ_UINT32_BE (payload); @@ -682,6 +722,10 @@ gst_dp_event_from_packet_1_0 (guint header_length, const guint8 * header, * * Creates a newly allocated #GstEvent from the given packet. * + * This function does not check the arguments passed to it, use + * gst_dp_validate_packet() first if the header and payload data are + * unchecked. + * * Returns: A #GstEvent if the event was successfully created, * or NULL if an event could not be read from the payload. */ @@ -692,6 +736,7 @@ gst_dp_event_from_packet (guint header_length, const guint8 * header, guint8 major, minor; g_return_val_if_fail (header, NULL); + g_return_val_if_fail (header_length >= GST_DP_HEADER_LENGTH, NULL); major = GST_DP_HEADER_MAJOR_VERSION (header); minor = GST_DP_HEADER_MINOR_VERSION (header); @@ -720,18 +765,29 @@ gst_dp_validate_header (guint header_length, const guint8 * header) { guint16 crc_read, crc_calculated; + g_return_val_if_fail (header != NULL, FALSE); + g_return_val_if_fail (header_length >= GST_DP_HEADER_LENGTH, FALSE); + if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_HEADER)) return TRUE; + crc_read = GST_DP_HEADER_CRC_HEADER (header); + /* don't include the last two crc fields for the crc check */ crc_calculated = gst_dp_crc (header, header_length - 4); - if (crc_read != crc_calculated) { + if (crc_read != crc_calculated) + goto crc_error; + + GST_LOG ("header crc validation: %02x", crc_read); + return TRUE; + + /* ERRORS */ +crc_error: + { GST_WARNING ("header crc mismatch: read %02x, calculated %02x", crc_read, crc_calculated); return FALSE; } - GST_LOG ("header crc validation: %02x", crc_read); - return TRUE; } /** @@ -751,17 +807,27 @@ gst_dp_validate_payload (guint header_length, const guint8 * header, { guint16 crc_read, crc_calculated; + g_return_val_if_fail (header != NULL, FALSE); + g_return_val_if_fail (header_length >= GST_DP_HEADER_LENGTH, FALSE); + if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_PAYLOAD)) return TRUE; + crc_read = GST_DP_HEADER_CRC_PAYLOAD (header); crc_calculated = gst_dp_crc (payload, GST_DP_HEADER_PAYLOAD_LENGTH (header)); - if (crc_read != crc_calculated) { + if (crc_read != crc_calculated) + goto crc_error; + + GST_LOG ("payload crc validation: %02x", crc_read); + return TRUE; + + /* ERRORS */ +crc_error: + { GST_WARNING ("payload crc mismatch: read %02x, calculated %02x", crc_read, crc_calculated); return FALSE; } - GST_LOG ("payload crc validation: %02x", crc_read); - return TRUE; } /** From cfd6f763a77f95756b862128c5aeb9d2dcb94745 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Thu, 10 Aug 2006 19:46:14 +0000 Subject: [PATCH 34/54] gdp: add gst_object_{s,g}et_control_rate(), add private data section, fix docs Original commit message from CVS: * docs/libs/gstreamer-libs-sections.txt: * libs/gst/controller/gstcontroller.c: (_gst_controller_get_property), (_gst_controller_set_property), (_gst_controller_init), (_gst_controller_class_init): * libs/gst/controller/gstcontroller.h: * libs/gst/controller/gsthelper.c: (gst_object_get_control_rate), (gst_object_set_control_rate): API: add gst_object_{s,g}et_control_rate(), add private data section, fix docs * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packetizer_new): * libs/gst/dataprotocol/dataprotocol.h: add deprecation guards to make gtk-doc happy and allow disabling cruft --- gst/gdp/dataprotocol.c | 10 +++++++++- gst/gdp/dataprotocol.h | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 9e71bd1071..fa8063653e 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -380,6 +380,7 @@ gst_dp_header_payload_type (const guint8 * header) * * Returns: %TRUE if the header was successfully created. */ +#ifndef GST_DISABLE_DEPRECATED gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header) @@ -387,6 +388,7 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, return gst_dp_header_from_buffer_any (buffer, flags, length, header, GST_DP_VERSION_0_2); } +#endif static gboolean gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, @@ -396,7 +398,7 @@ gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_DP_VERSION_1_0); } - /** +/** * gst_dp_packet_from_caps: * @caps: a #GstCaps to create a packet for * @flags: the #GDPHeaderFlags to create the header with @@ -410,6 +412,7 @@ gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, * * Returns: %TRUE if the packet was successfully created. */ +#ifndef GST_DISABLE_DEPRECATED gboolean gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -417,6 +420,7 @@ gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, return gst_dp_packet_from_caps_any (caps, flags, length, header, payload, GST_DP_VERSION_0_2); } +#endif static gboolean gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, @@ -440,6 +444,7 @@ gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, * * Returns: %TRUE if the packet was successfully created. */ +#ifndef GST_DISABLE_DEPRECATED gboolean gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -517,6 +522,7 @@ gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, *header = h; return TRUE; } +#endif static gboolean gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, @@ -869,11 +875,13 @@ gst_dp_packetizer_new (GstDPVersion version) ret->version = version; switch (version) { +#ifndef GST_DISABLE_DEPRECATED case GST_DP_VERSION_0_2: ret->header_from_buffer = gst_dp_header_from_buffer; ret->packet_from_caps = gst_dp_packet_from_caps; ret->packet_from_event = gst_dp_packet_from_event; break; +#endif case GST_DP_VERSION_1_0: ret->header_from_buffer = gst_dp_header_from_buffer_1_0; ret->packet_from_caps = gst_dp_packet_from_caps_1_0; diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 5783dfd899..4e90e2e5d3 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -140,21 +140,26 @@ GstDPPayloadType gst_dp_header_payload_type (const guint8 * header); /* converting from GstBuffer/GstEvent/GstCaps */ +#ifndef GST_DISABLE_DEPRECATED gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header); +#endif +#ifndef GST_DISABLE_DEPRECATED gboolean gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload); +#endif +#ifndef GST_DISABLE_DEPRECATED gboolean gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload); - +#endif /* converting to GstBuffer/GstEvent/GstCaps */ GstBuffer * gst_dp_buffer_from_header (guint header_length, const guint8 * header); From e43c4dd2ff78c14ece8d21acdbff35c177b7682a Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 11 Aug 2006 15:26:33 +0000 Subject: [PATCH 35/54] gdp: GST_DISABLE_DEPRECATED is only for users of API that don't want to see deprecated functions in the headers; people th... Original commit message from CVS: 2006-08-11 Andy Wingo * configure.ac: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packetizer_new): * tests/check/libs/gdp.c: (gst_dp_suite): GST_DISABLE_DEPRECATED is only for users of API that don't want to see deprecated functions in the headers; people that want to compile out deprecated code should pass -DGST_REMOVE_DEPRECATED into the CFLAGS. Fixes the build of multifdsink, or will soon.. --- gst/gdp/dataprotocol.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index fa8063653e..7b9ec2b355 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -380,7 +380,7 @@ gst_dp_header_payload_type (const guint8 * header) * * Returns: %TRUE if the header was successfully created. */ -#ifndef GST_DISABLE_DEPRECATED +#ifndef GST_REMOVE_DEPRECATED gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header) @@ -412,7 +412,7 @@ gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, * * Returns: %TRUE if the packet was successfully created. */ -#ifndef GST_DISABLE_DEPRECATED +#ifndef GST_REMOVE_DEPRECATED gboolean gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -444,7 +444,7 @@ gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, * * Returns: %TRUE if the packet was successfully created. */ -#ifndef GST_DISABLE_DEPRECATED +#ifndef GST_REMOVE_DEPRECATED gboolean gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -875,7 +875,7 @@ gst_dp_packetizer_new (GstDPVersion version) ret->version = version; switch (version) { -#ifndef GST_DISABLE_DEPRECATED +#ifndef GST_REMOVE_DEPRECATED case GST_DP_VERSION_0_2: ret->header_from_buffer = gst_dp_header_from_buffer; ret->packet_from_caps = gst_dp_packet_from_caps; From 5cc09472a0854e43d69f35a86fad251da6badc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 5 Oct 2006 14:26:08 +0000 Subject: [PATCH 36/54] gdp: Printf fixes. Original commit message from CVS: * gst/gstpad.c: (pre_activate): * gst/gstregistry.c: (gst_registry_scan_path_level): * gst/gstregistryxml.c: (load_plugin): * libs/gst/controller/gstcontroller.c: (gst_controlled_property_set_interpolation_mode): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_event_1_0): * libs/gst/net/gstnetclientclock.c: (gst_net_client_clock_observe_times): * plugins/elements/gstfdsrc.c: (gst_fd_src_create): Printf fixes. --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 7b9ec2b355..949fd729f1 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -545,7 +545,7 @@ gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, GST_LOG ("event %p has structure, string %s", event, string); pl_length = strlen ((gchar *) string) + 1; /* include trailing 0 */ } else { - GST_LOG ("event %p has no structure"); + GST_LOG ("event %p has no structure", event); pl_length = 0; } From 16e18f3e1a186ca964fd7595e8b7c859fb27c24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 1 Nov 2007 21:50:05 +0000 Subject: [PATCH 37/54] gdp: g_type_class_ref() other types as well, see #349410 and #64764. Original commit message from CVS: * gst/gst.c: (init_post): * gst/gstevent.c: (_gst_event_initialize): * gst/gstquery.c: (_gst_query_initialize): * libs/gst/dataprotocol/dataprotocol.c (gst_dp_init): g_type_class_ref() other types as well, see #349410 and #64764. * gst/gstbuffer.c: (_gst_buffer_initialize): * gst/gstmessage.c: (_gst_message_initialize): Simplify existing g_type_class_ref(). --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 949fd729f1..b5dea2a1f9 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -327,7 +327,7 @@ gst_dp_init (void) _gst_dp_initialized = TRUE; - gst_dp_version_get_type (); + g_type_class_ref (gst_dp_version_get_type ()); GST_DEBUG_CATEGORY_INIT (data_protocol_debug, "gdp", 0, "GStreamer Data Protocol"); From ecb301819606b1ee1d44a7ded55d77d32b7372e7 Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Tue, 8 Jan 2008 02:07:38 +0000 Subject: [PATCH 38/54] gdp: Fix empty prototypes. Fixes bug #507957. Original commit message from CVS: Patch by: Damien Lespiau * libs/gst/controller/gstcontroller.h: * libs/gst/controller/gstcontrolsource.h: * libs/gst/controller/gstinterpolationcontrolsource.h: * libs/gst/controller/gstlfocontrolsource.h: * libs/gst/dataprotocol/dataprotocol.h: Fix empty prototypes. Fixes bug #507957. --- gst/gdp/dataprotocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 4e90e2e5d3..118df65a29 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -41,7 +41,7 @@ typedef enum { GST_DP_VERSION_1_0, } GstDPVersion; -GType gst_dp_version_get_type (); +GType gst_dp_version_get_type (void); #define GST_TYPE_DP_VERSION (gst_dp_version_get_type ()) /** From 1998871b391cb43d1c681456f851a193f8bee15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 29 Feb 2008 12:41:33 +0000 Subject: [PATCH 39/54] gdp: Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * gst/gstconfig.h.in: * libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer): * libs/gst/check/gstcheck.c: (gst_check_log_message_func), (gst_check_log_critical_func), (gst_check_drop_buffers), (gst_check_element_push_buffer_list): * libs/gst/controller/gstcontroller.c: (gst_controller_get), (gst_controller_get_type): * libs/gst/controller/gsthelper.c: (gst_object_control_properties), (gst_object_get_controller), (gst_object_get_control_source): * libs/gst/controller/gstinterpolationcontrolsource.c: (gst_interpolation_control_source_new): * libs/gst/controller/gstlfocontrolsource.c: (gst_lfo_control_source_new): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_event_from_packet_0_2): * plugins/elements/gstfdsrc.c: * plugins/elements/gstmultiqueue.c: * plugins/elements/gsttee.c: * plugins/elements/gsttypefindelement.c: * plugins/indexers/gstfileindex.c: (_file_index_id_save_xml), (gst_file_index_add_association): * plugins/indexers/gstmemindex.c: * tests/benchmarks/gstpollstress.c: (mess_some_more): * tests/check/elements/queue.c: (setup_queue): * tests/check/gst/gstpipeline.c: * tests/check/libs/collectpads.c: (setup), (teardown), (gst_collect_pads_suite): * tests/examples/adapter/adapter_test.c: * tests/examples/metadata/read-metadata.c: (make_pipeline): * tests/examples/xml/createxml.c: * tests/examples/xml/runxml.c: * tools/gst-inspect.c: * tools/gst-run.c: Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers, not using variable sized arrays on the stack, moving variable declarations to the beginning of a block and using "foo (void)" instead of "foo ()" for declarations. --- gst/gdp/dataprotocol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index b5dea2a1f9..8bdb9bcf8f 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -654,7 +654,7 @@ gst_dp_event_from_packet_0_2 (guint header_length, const guint8 * header, switch (type) { case GST_EVENT_UNKNOWN: GST_WARNING ("Unknown event, ignoring"); - return FALSE; + return NULL; case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: case GST_EVENT_FLUSH_STOP: @@ -690,10 +690,10 @@ gst_dp_event_from_packet_0_2 (guint header_length, const guint8 * header, case GST_EVENT_NAVIGATION: case GST_EVENT_TAG: GST_WARNING ("Unhandled event type %d, ignoring", type); - return FALSE; + return NULL; default: GST_WARNING ("Unknown event type %d, ignoring", type); - return FALSE; + return NULL; } return event; From d8942dc0db3bc7f6258a4c3bab6a129f5fcb80fa Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 27 Mar 2008 15:23:55 +0000 Subject: [PATCH 40/54] gdp: When calculating GDP body CRC, use the correct pointer. Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_event_1_0): When calculating GDP body CRC, use the correct pointer. Fixes part of #522401. --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 8bdb9bcf8f..80c02c4740 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -558,7 +558,7 @@ gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, /* timestamp */ GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event)); - GST_DP_SET_CRC (h, flags, *payload, pl_length); + GST_DP_SET_CRC (h, flags, string, pl_length); GST_LOG ("created header from event:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); From 31a9af5a2b14a91e64ff463a1bcca8e806379110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 30 Jun 2008 09:38:45 +0000 Subject: [PATCH 41/54] gdp: Don't write to the same region of memory as a uint64 and uint16 as this breaks ... Original commit message from CVS: * libs/gst/dataprotocol/dataprotocol.c: Don't write to the same region of memory as a uint64 and uint16 as this breaks strict aliasing rules and apparantly breaks on PPC and s390. Thanks to Sjoerd Simons for analysing. Fixes bug #348114. --- gst/gdp/dataprotocol.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 80c02c4740..f253b415eb 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -82,7 +82,7 @@ GST_DEBUG_CATEGORY_STATIC (data_protocol_debug); /* helper macros */ -/* write first 6 bytes of header, as well as ABI padding */ +/* write first 6 bytes of header */ #define GST_DP_INIT_HEADER(h, version, flags, type) \ G_STMT_START { \ gint maj = 0, min = 0; \ @@ -95,9 +95,6 @@ G_STMT_START { \ 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 #define GST_DP_SET_CRC(h, flags, payload, length); \ From 0dc9475fa9b2874c22747520c4e1c606746db0d9 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Fri, 27 Nov 2009 16:39:37 +0200 Subject: [PATCH 42/54] gdp: fix broken xrefs in docs --- gst/gdp/dataprotocol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index f253b415eb..61705ca93a 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -367,7 +367,7 @@ gst_dp_header_payload_type (const guint8 * header) /** * gst_dp_header_from_buffer: * @buffer: a #GstBuffer to create a header for - * @flags: the #GDPHeaderFlags to create the header with + * @flags: the #GstDPHeaderFlag to create the header with * @length: a guint pointer to store the header length in * @header: a guint8 * pointer to store a newly allocated header byte array in * @@ -398,7 +398,7 @@ gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, /** * gst_dp_packet_from_caps: * @caps: a #GstCaps to create a packet for - * @flags: the #GDPHeaderFlags to create the header with + * @flags: the #GstDPHeaderFlag to create the header with * @length: a guint pointer to store the header length in * @header: a guint8 pointer to store a newly allocated header byte array in * @payload: a guint8 pointer to store a newly allocated payload byte array in @@ -430,7 +430,7 @@ gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, /** * gst_dp_packet_from_event: * @event: a #GstEvent to create a packet for - * @flags: the #GDPHeaderFlags to create the header with + * @flags: the #GstDPHeaderFlag to create the header with * @length: a guint pointer to store the header length in * @header: a guint8 pointer to store a newly allocated header byte array in * @payload: a guint8 pointer to store a newly allocated payload byte array in From 6e44ef60fadb949990438a08c8635b11f0d7066a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 2 Mar 2010 23:51:18 +0100 Subject: [PATCH 43/54] gdp: Make code safe for -Wredundant-decls Adds that warning to configure.ac Includes a tiny change of the GST_BOILERPLATE_FULL() macro: The get_type() function is no longer declared before being defined. https://bugzilla.gnome.org/show_bug.cgi?id=611692 --- gst/gdp/dp-private.h | 1 - 1 file changed, 1 deletion(-) diff --git a/gst/gdp/dp-private.h b/gst/gdp/dp-private.h index 18834c2e5d..174a334f57 100644 --- a/gst/gdp/dp-private.h +++ b/gst/gdp/dp-private.h @@ -44,7 +44,6 @@ G_BEGIN_DECLS #define GST_DP_HEADER_CRC_HEADER(x) GST_READ_UINT16_BE (x + 58) #define GST_DP_HEADER_CRC_PAYLOAD(x) GST_READ_UINT16_BE (x + 60) -void gst_dp_init (void); void gst_dp_dump_byte_array (guint8 *array, guint length); G_END_DECLS From 779da2ef0b0dd862d074e016cdf37a2e490df86a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 2 Mar 2010 22:58:06 +0100 Subject: [PATCH 44/54] gdp: Fixes for -Wmissing-declarations -Wmissing-prototypes Also adds those flags to the configure warning flags https://bugzilla.gnome.org/show_bug.cgi?id=611692 --- gst/gdp/dataprotocol.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 61705ca93a..ac0a9ce259 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -378,6 +378,11 @@ gst_dp_header_payload_type (const guint8 * header) * Returns: %TRUE if the header was successfully created. */ #ifndef GST_REMOVE_DEPRECATED +#ifdef GST_DISABLE_DEPRECATED +gboolean +gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, + guint * length, guint8 ** header); +#endif gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header) @@ -410,6 +415,11 @@ gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, * Returns: %TRUE if the packet was successfully created. */ #ifndef GST_REMOVE_DEPRECATED +#ifdef GST_DISABLE_DEPRECATED +gboolean +gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload); +#endif gboolean gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -442,6 +452,11 @@ gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, * Returns: %TRUE if the packet was successfully created. */ #ifndef GST_REMOVE_DEPRECATED +#ifdef GST_DISABLE_DEPRECATED +gboolean +gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, + guint * length, guint8 ** header, guint8 ** payload); +#endif gboolean gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) From 700e745167dc7e5751936dee8bbfd57758013e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 8 Oct 2010 00:38:39 +0100 Subject: [PATCH 45/54] gdp: dataprotocol, lfocontrolsource: fix enum value name in enums that are public API So run-time bindings can introspect the names correctly (we abuse this field as description field only in elements, not for public API (where the description belongs into the gtk-doc chunk). https://bugzilla.gnome.org/show_bug.cgi?id=629946 --- gst/gdp/dataprotocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index ac0a9ce259..5e413b05a1 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -294,8 +294,8 @@ gst_dp_version_get_type (void) { static GType gst_dp_version_type = 0; static const GEnumValue gst_dp_version[] = { - {GST_DP_VERSION_0_2, "GDP Version 0.2", "0.2"}, - {GST_DP_VERSION_1_0, "GDP Version 1.0", "1.0"}, + {GST_DP_VERSION_0_2, "GST_DP_VERSION_0_2", "0.2"}, + {GST_DP_VERSION_1_0, "GST_DP_VERSION_1_0", "1.0"}, {0, NULL, NULL}, }; From a24e138493c7032386e80f8318d65987d67b00da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 8 Oct 2010 09:34:47 +0100 Subject: [PATCH 46/54] gdp: make public enum _get_type() functions thread-safe Not that it is likely to matter in practice, but since these are public API they should probably be thread-safe. --- gst/gdp/dataprotocol.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 5e413b05a1..b57d377d69 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -292,18 +292,19 @@ gst_dp_dump_byte_array (guint8 * array, guint length) GType gst_dp_version_get_type (void) { - static GType gst_dp_version_type = 0; + static gsize gst_dp_version_type = 0; static const GEnumValue gst_dp_version[] = { {GST_DP_VERSION_0_2, "GST_DP_VERSION_0_2", "0.2"}, {GST_DP_VERSION_1_0, "GST_DP_VERSION_1_0", "1.0"}, {0, NULL, NULL}, }; - if (!gst_dp_version_type) { - gst_dp_version_type = - g_enum_register_static ("GstDPVersion", gst_dp_version); + if (g_once_init_enter (&gst_dp_version_type)) { + GType tmp = g_enum_register_static ("GstDPVersion", gst_dp_version); + g_once_init_leave (&gst_dp_version_type, tmp); } - return gst_dp_version_type; + + return (GType) gst_dp_version_type; }; /** From a9cec31b9711654a03430742cde36b09f48b7e31 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 6 Dec 2010 19:40:03 +0100 Subject: [PATCH 47/54] gdp: remove deprecated code --- gst/gdp/dataprotocol.c | 163 ----------------------------------------- gst/gdp/dataprotocol.h | 21 ------ 2 files changed, 184 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index b57d377d69..2cecd6bf3e 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -365,34 +365,6 @@ gst_dp_header_payload_type (const guint8 * header) /*** PACKETIZER FUNCTIONS ***/ -/** - * gst_dp_header_from_buffer: - * @buffer: a #GstBuffer to create a header for - * @flags: the #GstDPHeaderFlag to create the header with - * @length: a guint pointer to store the header length in - * @header: a guint8 * pointer to store a newly allocated header byte array in - * - * Creates a GDP header from the given buffer. - * - * Deprecated: use a #GstDPPacketizer - * - * Returns: %TRUE if the header was successfully created. - */ -#ifndef GST_REMOVE_DEPRECATED -#ifdef GST_DISABLE_DEPRECATED -gboolean -gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, - guint * length, guint8 ** header); -#endif -gboolean -gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, - guint * length, guint8 ** header) -{ - return gst_dp_header_from_buffer_any (buffer, flags, length, header, - GST_DP_VERSION_0_2); -} -#endif - static gboolean gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, guint * length, guint8 ** header) @@ -401,35 +373,6 @@ gst_dp_header_from_buffer_1_0 (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_DP_VERSION_1_0); } -/** - * gst_dp_packet_from_caps: - * @caps: a #GstCaps to create a packet for - * @flags: the #GstDPHeaderFlag to create the header with - * @length: a guint pointer to store the header length in - * @header: a guint8 pointer to store a newly allocated header byte array in - * @payload: a guint8 pointer to store a newly allocated payload byte array in - * - * Creates a GDP packet from the given caps. - * - * Deprecated: use a #GstDPPacketizer - * - * Returns: %TRUE if the packet was successfully created. - */ -#ifndef GST_REMOVE_DEPRECATED -#ifdef GST_DISABLE_DEPRECATED -gboolean -gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, - guint * length, guint8 ** header, guint8 ** payload); -#endif -gboolean -gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags, - guint * length, guint8 ** header, guint8 ** payload) -{ - return gst_dp_packet_from_caps_any (caps, flags, length, header, payload, - GST_DP_VERSION_0_2); -} -#endif - static gboolean gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -438,105 +381,6 @@ gst_dp_packet_from_caps_1_0 (const GstCaps * caps, GstDPHeaderFlag flags, GST_DP_VERSION_1_0); } -/** - * gst_dp_packet_from_event: - * @event: a #GstEvent to create a packet for - * @flags: the #GstDPHeaderFlag to create the header with - * @length: a guint pointer to store the header length in - * @header: a guint8 pointer to store a newly allocated header byte array in - * @payload: a guint8 pointer to store a newly allocated payload byte array in - * - * Creates a GDP packet from the given event. - * - * Deprecated: use a #GstDPPacketizer - * - * Returns: %TRUE if the packet was successfully created. - */ -#ifndef GST_REMOVE_DEPRECATED -#ifdef GST_DISABLE_DEPRECATED -gboolean -gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, - guint * length, guint8 ** header, guint8 ** payload); -#endif -gboolean -gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags, - guint * length, guint8 ** header, guint8 ** payload) -{ - guint8 *h; - guint pl_length; /* length of payload */ - - g_return_val_if_fail (GST_IS_EVENT (event), FALSE); - g_return_val_if_fail (length, FALSE); - g_return_val_if_fail (header, FALSE); - g_return_val_if_fail (payload, FALSE); - - /* first construct payload, since we need the length */ - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_UNKNOWN: - GST_WARNING ("Unknown event, ignoring"); - return FALSE; - case GST_EVENT_EOS: - case GST_EVENT_FLUSH_START: - case GST_EVENT_FLUSH_STOP: - case GST_EVENT_NEWSEGMENT: - pl_length = 0; - *payload = NULL; - break; - case GST_EVENT_SEEK: - { - gdouble rate; - GstFormat format; - GstSeekFlags flags; - GstSeekType cur_type, stop_type; - gint64 cur, stop; - - gst_event_parse_seek ((GstEvent *) event, &rate, &format, &flags, - &cur_type, &cur, &stop_type, &stop); - - pl_length = 4 + 4 + 4 + 8 + 4 + 8; - *payload = g_malloc0 (pl_length); - /* FIXME write rate */ - GST_WRITE_UINT32_BE (*payload, (guint32) format); - GST_WRITE_UINT32_BE (*payload + 4, (guint32) flags); - GST_WRITE_UINT32_BE (*payload + 8, (guint32) cur_type); - GST_WRITE_UINT64_BE (*payload + 12, (guint64) cur); - GST_WRITE_UINT32_BE (*payload + 20, (guint32) stop_type); - GST_WRITE_UINT64_BE (*payload + 24, (guint64) stop); - break; - } - case GST_EVENT_QOS: - case GST_EVENT_NAVIGATION: - case GST_EVENT_TAG: - GST_WARNING ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event)); - return FALSE; - default: - GST_WARNING ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event)); - return FALSE; - } - - /* now we can create and fill the header */ - h = g_malloc0 (GST_DP_HEADER_LENGTH); - *length = GST_DP_HEADER_LENGTH; - - /* version, flags, type */ - GST_DP_INIT_HEADER (h, GST_DP_VERSION_0_2, flags, - GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event)); - - /* length */ - GST_WRITE_UINT32_BE (h + 6, (guint32) pl_length); - /* timestamp */ - GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event)); - - GST_DP_SET_CRC (h, flags, *payload, pl_length); - - GST_LOG ("created header from event:"); - gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); - - *header = h; - return TRUE; -} -#endif - static gboolean gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, guint * length, guint8 ** header, guint8 ** payload) @@ -888,13 +732,6 @@ gst_dp_packetizer_new (GstDPVersion version) ret->version = version; switch (version) { -#ifndef GST_REMOVE_DEPRECATED - case GST_DP_VERSION_0_2: - ret->header_from_buffer = gst_dp_header_from_buffer; - ret->packet_from_caps = gst_dp_packet_from_caps; - ret->packet_from_event = gst_dp_packet_from_event; - break; -#endif case GST_DP_VERSION_1_0: ret->header_from_buffer = gst_dp_header_from_buffer_1_0; ret->packet_from_caps = gst_dp_packet_from_caps_1_0; diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 118df65a29..62c30bdfe0 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -139,27 +139,6 @@ guint32 gst_dp_header_payload_length (const guint8 * header); GstDPPayloadType gst_dp_header_payload_type (const guint8 * header); -/* converting from GstBuffer/GstEvent/GstCaps */ -#ifndef GST_DISABLE_DEPRECATED -gboolean gst_dp_header_from_buffer (const GstBuffer * buffer, - GstDPHeaderFlag flags, - guint * length, - guint8 ** header); -#endif -#ifndef GST_DISABLE_DEPRECATED -gboolean gst_dp_packet_from_caps (const GstCaps * caps, - GstDPHeaderFlag flags, - guint * length, - guint8 ** header, - guint8 ** payload); -#endif -#ifndef GST_DISABLE_DEPRECATED -gboolean gst_dp_packet_from_event (const GstEvent * event, - GstDPHeaderFlag flags, - guint * length, - guint8 ** header, - guint8 ** payload); -#endif /* converting to GstBuffer/GstEvent/GstCaps */ GstBuffer * gst_dp_buffer_from_header (guint header_length, const guint8 * header); From d7b3ff841388934c377730c7b557311ff679cf0b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 21 Mar 2011 18:13:55 +0100 Subject: [PATCH 48/54] gdp: port code to new buffer data API --- gst/gdp/dataprotocol.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 2cecd6bf3e..728b3f5480 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -131,6 +131,8 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, { guint8 *h; guint16 flags_mask; + guint8 *data; + gsize size; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (length, FALSE); @@ -142,8 +144,10 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, /* version, flags, type */ GST_DP_INIT_HEADER (h, version, flags, GST_DP_PAYLOAD_BUFFER); + data = gst_buffer_map ((GstBuffer *) buffer, &size, NULL, GST_MAP_READ); + /* buffer properties */ - GST_WRITE_UINT32_BE (h + 6, GST_BUFFER_SIZE (buffer)); + GST_WRITE_UINT32_BE (h + 6, size); GST_WRITE_UINT64_BE (h + 10, GST_BUFFER_TIMESTAMP (buffer)); GST_WRITE_UINT64_BE (h + 18, GST_BUFFER_DURATION (buffer)); GST_WRITE_UINT64_BE (h + 26, GST_BUFFER_OFFSET (buffer)); @@ -157,7 +161,9 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask); - GST_DP_SET_CRC (h, flags, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); + GST_DP_SET_CRC (h, flags, data, size); + + gst_buffer_unmap ((GstBuffer *) buffer, data, size); GST_LOG ("created header from buffer:"); gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH); From f8cdb67fa5e86915b43c065f3158d79ce2030ca0 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Mon, 2 May 2011 16:00:52 +0300 Subject: [PATCH 49/54] gdp: add docs for GstDPPacketizer --- gst/gdp/dataprotocol.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index 62c30bdfe0..efd524af7b 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -111,6 +111,16 @@ typedef gboolean (*GstDPPacketFromEventFunction) (const GstEvent * event, guint * length, guint8 ** header, guint8 ** payload); + +/** + * GstDPPacketizer: + * @version: the #GstDPVersion of the protocol to be used + * @header_from_buffer: buffer serializer function + * @packet_from_caps: caps serializer function + * @packet_from_event: event serializer function + * + * Data protocol packetizer handle. + */ typedef struct { GstDPVersion version; From 1d9482190dd60b4be705b351a2ae98c8f888a4a0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 10 May 2011 11:50:16 +0200 Subject: [PATCH 50/54] gdp: Hide the GstStructure in GstEvent Hide the GstStructure of the event in the implementation specific part so that we can change it. Add methods to check and make the event writable. Add a new method to get a writable GstStructure of the element. Avoid directly accising the event structure. --- gst/gdp/dataprotocol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 728b3f5480..b1cda553d9 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -394,6 +394,7 @@ gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, guint8 *h; guint32 pl_length; /* length of payload */ guchar *string = NULL; + const GstStructure *structure; g_return_val_if_fail (GST_IS_EVENT (event), FALSE); g_return_val_if_fail (length, FALSE); @@ -403,8 +404,9 @@ gst_dp_packet_from_event_1_0 (const GstEvent * event, GstDPHeaderFlag flags, *length = GST_DP_HEADER_LENGTH; h = g_malloc0 (GST_DP_HEADER_LENGTH); - if (event->structure) { - string = (guchar *) gst_structure_to_string (event->structure); + structure = gst_event_get_structure ((GstEvent *) event); + if (structure) { + string = (guchar *) gst_structure_to_string (structure); GST_LOG ("event %p has structure, string %s", event, string); pl_length = strlen ((gchar *) string) + 1; /* include trailing 0 */ } else { From 7c7920e0e22c16d6683a9bcef113eb377bb2ee14 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 13 May 2011 18:07:24 +0200 Subject: [PATCH 51/54] gdp: Rework GstSegment handling Improve GstSegment, rename some fields. The idea is to have the GstSegment structure represent the timing structure of the buffers as they are generated by the source or demuxer element. gst_segment_set_seek() -> gst_segment_do_seek() Rename the NEWSEGMENT event to SEGMENT. Make parsing of the SEGMENT event into a GstSegment structure. Pass a GstSegment structure when making a new SEGMENT event. This allows us to pass the timing info directly to the next element. No accumulation is needed in the receiving element, all the info is inside the element. Remove gst_segment_set_newsegment(): This function as used to accumulate segments received from upstream, which is now not needed anymore because the segment event contains the complete timing information. --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index b1cda553d9..8b32bb8061 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -523,7 +523,7 @@ gst_dp_event_from_packet_0_2 (guint header_length, const guint8 * header, case GST_EVENT_EOS: case GST_EVENT_FLUSH_START: case GST_EVENT_FLUSH_STOP: - case GST_EVENT_NEWSEGMENT: + case GST_EVENT_SEGMENT: event = gst_event_new_custom (type, NULL); GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header); break; From bc11a6fd17fd55a0542cbe7d92c9d3d9c24f3760 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 10 Jun 2011 13:40:57 +0200 Subject: [PATCH 52/54] gdp: make new _buffer_allocate method Make a new method to allocate a buffer + memory that takes the allocator and the alignment as parameters. Provide a macro for the old method but prefer to use the new method to encourage plugins to negotiate the allocator properly. --- gst/gdp/dataprotocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index 8b32bb8061..e924ea5ed9 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -461,7 +461,8 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) GST_DP_PAYLOAD_BUFFER, NULL); buffer = - gst_buffer_new_and_alloc ((guint) GST_DP_HEADER_PAYLOAD_LENGTH (header)); + gst_buffer_new_allocate (NULL, + (guint) GST_DP_HEADER_PAYLOAD_LENGTH (header), 0); GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header); GST_BUFFER_DURATION (buffer) = GST_DP_HEADER_DURATION (header); From 9cd50cad386f576592c40a564d1949077c6d9306 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 16 Aug 2011 17:32:20 +0200 Subject: [PATCH 53/54] gdp: rename buffer PREROLL -> LIVE flag Rename the GST_BUFFER_FLAG_PREROLL to GST_BUFFER_FLAG_LIVE and give the new flag a meaning. The old PREROLL flag never had a clear meaning. --- gst/gdp/dataprotocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gdp/dataprotocol.c b/gst/gdp/dataprotocol.c index e924ea5ed9..3b2e182202 100644 --- a/gst/gdp/dataprotocol.c +++ b/gst/gdp/dataprotocol.c @@ -155,7 +155,7 @@ gst_dp_header_from_buffer_any (const GstBuffer * buffer, GstDPHeaderFlag flags, /* data flags; eats two bytes from the ABI area */ /* we copy everything but the read-only flags */ - flags_mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_DISCONT | + flags_mask = GST_BUFFER_FLAG_LIVE | GST_BUFFER_FLAG_DISCONT | GST_BUFFER_FLAG_IN_CAPS | GST_BUFFER_FLAG_GAP | GST_BUFFER_FLAG_DELTA_UNIT; From 3be7c22bd4109137bae90b86801c1aa710407fc1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 11 Nov 2011 17:17:43 +0100 Subject: [PATCH 54/54] gdp: fix header files Ensure correct indentation and retab Make sure all structure have padding --- gst/gdp/dataprotocol.h | 64 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/gst/gdp/dataprotocol.h b/gst/gdp/dataprotocol.h index efd524af7b..d2b2114661 100644 --- a/gst/gdp/dataprotocol.h +++ b/gst/gdp/dataprotocol.h @@ -98,19 +98,19 @@ typedef enum { } GstDPPayloadType; typedef gboolean (*GstDPHeaderFromBufferFunction) (const GstBuffer * buffer, - GstDPHeaderFlag flags, - guint * length, - guint8 ** header); -typedef gboolean (*GstDPPacketFromCapsFunction) (const GstCaps * caps, - GstDPHeaderFlag flags, - guint * length, - guint8 ** header, - guint8 ** payload); -typedef gboolean (*GstDPPacketFromEventFunction) (const GstEvent * event, - GstDPHeaderFlag flags, - guint * length, - guint8 ** header, - guint8 ** payload); + GstDPHeaderFlag flags, + guint * length, + guint8 ** header); +typedef gboolean (*GstDPPacketFromCapsFunction) (const GstCaps * caps, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header, + guint8 ** payload); +typedef gboolean (*GstDPPacketFromEventFunction) (const GstEvent * event, + GstDPHeaderFlag flags, + guint * length, + guint8 ** header, + guint8 ** payload); /** * GstDPPacketizer: @@ -133,7 +133,7 @@ typedef struct { } GstDPPacketizer; -void gst_dp_init (void); +void gst_dp_init (void); /* packetizer */ GstDPPacketizer * @@ -145,29 +145,29 @@ guint16 gst_dp_crc (const guint8 * buffer, guint length); /* payload information from header */ -guint32 gst_dp_header_payload_length (const guint8 * header); +guint32 gst_dp_header_payload_length (const guint8 * header); GstDPPayloadType - gst_dp_header_payload_type (const guint8 * header); + gst_dp_header_payload_type (const guint8 * header); /* converting to GstBuffer/GstEvent/GstCaps */ -GstBuffer * gst_dp_buffer_from_header (guint header_length, - const guint8 * header); -GstCaps * gst_dp_caps_from_packet (guint header_length, - const guint8 * header, - const guint8 * payload); -GstEvent * gst_dp_event_from_packet (guint header_length, - const guint8 * header, - const guint8 * payload); +GstBuffer * gst_dp_buffer_from_header (guint header_length, + const guint8 * header); +GstCaps * gst_dp_caps_from_packet (guint header_length, + const guint8 * header, + const guint8 * payload); +GstEvent * gst_dp_event_from_packet (guint header_length, + const guint8 * header, + const guint8 * payload); /* validation */ -gboolean gst_dp_validate_header (guint header_length, - const guint8 * header); -gboolean gst_dp_validate_payload (guint header_length, - const guint8 * header, - const guint8 * payload); -gboolean gst_dp_validate_packet (guint header_length, - const guint8 * header, - const guint8 * payload); +gboolean gst_dp_validate_header (guint header_length, + const guint8 * header); +gboolean gst_dp_validate_payload (guint header_length, + const guint8 * header, + const guint8 * payload); +gboolean gst_dp_validate_packet (guint header_length, + const guint8 * header, + const guint8 * payload); G_END_DECLS