2004-05-19 16:37:53 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
|
|
|
|
*
|
|
|
|
* 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 <gst/gst.h>
|
|
|
|
#include <gst/dataprotocol/dataprotocol.h>
|
|
|
|
#include <glib/gprintf.h> /* g_sprintf */
|
|
|
|
#include <string.h> /* strlen */
|
|
|
|
#include "dp-private.h"
|
|
|
|
|
|
|
|
/* debug category */
|
|
|
|
GST_DEBUG_CATEGORY (data_protocol_debug);
|
|
|
|
#define GST_CAT_DEFAULT data_protocol_debug
|
|
|
|
|
|
|
|
/* 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;
|
2004-10-01 16:49:01 +00:00
|
|
|
static guint16 crc_table[256];
|
2005-10-10 23:55:39 +00:00
|
|
|
guint16 crc_register = CRC_INIT;
|
2004-05-19 16:37:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
2005-10-10 23:55:39 +00:00
|
|
|
gchar *line = g_malloc0 (3 * n + 1);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2005-07-05 10:20:14 +00:00
|
|
|
* Should be called before using these functions from source linking
|
|
|
|
* to this source file.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
libs/gst/: 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.
2005-12-18 16:04:41 +00:00
|
|
|
* Get the length of the payload described by @header.
|
|
|
|
*
|
2004-05-19 16:37:53 +00:00
|
|
|
* 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
|
|
|
|
*
|
libs/gst/: 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.
2005-12-18 16:04:41 +00:00
|
|
|
* Get the type of the payload described by @header.
|
|
|
|
*
|
2004-05-19 16:37:53 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2004-07-28 10:22:07 +00:00
|
|
|
* Returns: %TRUE if the header was successfully created.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags,
|
|
|
|
guint * length, guint8 ** header)
|
|
|
|
{
|
|
|
|
guint8 *h;
|
|
|
|
guint16 crc;
|
2004-06-09 16:24:19 +00:00
|
|
|
guint16 flags_mask;
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
2004-05-19 17:22:53 +00:00
|
|
|
g_return_val_if_fail (header, FALSE);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
*length = GST_DP_HEADER_LENGTH;
|
2005-10-10 23:55:39 +00:00
|
|
|
h = g_malloc0 (GST_DP_HEADER_LENGTH);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* version, flags, type */
|
|
|
|
h[0] = (guint8) GST_DP_VERSION_MAJOR;
|
|
|
|
h[1] = (guint8) GST_DP_VERSION_MINOR;
|
|
|
|
h[2] = (guint8) flags;
|
2005-10-08 17:17:25 +00:00
|
|
|
h[3] = 0; /* padding byte */
|
|
|
|
GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_BUFFER);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* buffer properties */
|
2005-10-08 17:17:25 +00:00
|
|
|
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));
|
2004-05-19 16:37:53 +00:00
|
|
|
|
2004-06-09 16:24:19 +00:00
|
|
|
/* data flags */
|
2004-08-16 10:35:36 +00:00
|
|
|
/* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */
|
check/Makefile.am: 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:
2005-05-16 20:21:55 +00:00
|
|
|
flags_mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
|
|
|
|
GST_BUFFER_FLAG_DELTA_UNIT;
|
2004-06-09 16:24:19 +00:00
|
|
|
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 42, GST_BUFFER_FLAGS (buffer) & flags_mask);
|
2004-06-09 16:24:19 +00:00
|
|
|
|
2004-05-19 16:37:53 +00:00
|
|
|
/* ABI padding */
|
2004-06-09 16:24:19 +00:00
|
|
|
GST_WRITE_UINT32_BE (h + 44, (guint64) 0);
|
2004-05-19 17:22:53 +00:00
|
|
|
GST_WRITE_UINT64_BE (h + 48, (guint64) 0);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* 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 */
|
2005-10-08 17:17:25 +00:00
|
|
|
crc = gst_dp_crc (h, 58);
|
2004-05-19 16:37:53 +00:00
|
|
|
}
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 58, crc);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
crc = 0;
|
|
|
|
if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) {
|
|
|
|
crc = gst_dp_crc (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
|
|
|
}
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 60, crc);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2004-07-28 10:22:07 +00:00
|
|
|
* Returns: %TRUE if the packet was successfully created.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags,
|
|
|
|
guint * length, guint8 ** header, guint8 ** payload)
|
|
|
|
{
|
|
|
|
guint8 *h;
|
|
|
|
guint16 crc;
|
GCC 4 fixen.
Original commit message from CVS:
2005-05-04 Andy Wingo <wingo@pobox.com>
* 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.
2005-05-04 21:29:44 +00:00
|
|
|
guchar *string;
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* FIXME: GST_IS_CAPS doesn't work
|
|
|
|
g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */
|
2004-05-19 17:22:53 +00:00
|
|
|
g_return_val_if_fail (caps, FALSE);
|
|
|
|
g_return_val_if_fail (header, FALSE);
|
|
|
|
g_return_val_if_fail (payload, FALSE);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
*length = GST_DP_HEADER_LENGTH;
|
2005-10-10 23:55:39 +00:00
|
|
|
h = g_malloc0 (GST_DP_HEADER_LENGTH);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
GCC 4 fixen.
Original commit message from CVS:
2005-05-04 Andy Wingo <wingo@pobox.com>
* 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.
2005-05-04 21:29:44 +00:00
|
|
|
string = (guchar *) gst_caps_to_string (caps);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* version, flags, type */
|
|
|
|
h[0] = (guint8) GST_DP_VERSION_MAJOR;
|
|
|
|
h[1] = (guint8) GST_DP_VERSION_MINOR;
|
|
|
|
h[2] = (guint8) flags;
|
2005-10-08 17:17:25 +00:00
|
|
|
h[3] = 0; /* padding bytes */
|
|
|
|
GST_WRITE_UINT16_BE (h + 4, GST_DP_PAYLOAD_CAPS);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* buffer properties */
|
2005-10-13 16:26:12 +00:00
|
|
|
GST_WRITE_UINT32_BE (h + 6, strlen ((gchar *) string) + 1); /* include trailing 0 */
|
2005-10-08 17:17:25 +00:00
|
|
|
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);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* ABI padding */
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT64_BE (h + 42, (guint64) 0);
|
|
|
|
GST_WRITE_UINT64_BE (h + 50, (guint64) 0);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* CRC */
|
|
|
|
crc = 0;
|
|
|
|
if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
|
2005-10-08 17:17:25 +00:00
|
|
|
crc = gst_dp_crc (h, 58);
|
2004-05-19 16:37:53 +00:00
|
|
|
}
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 58, crc);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
crc = 0;
|
|
|
|
if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) {
|
GCC 4 fixen.
Original commit message from CVS:
2005-05-04 Andy Wingo <wingo@pobox.com>
* 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.
2005-05-04 21:29:44 +00:00
|
|
|
crc = gst_dp_crc (string, strlen ((gchar *) string) + 1);
|
2004-05-19 16:37:53 +00:00
|
|
|
}
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 60, crc);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2004-07-28 10:22:07 +00:00
|
|
|
* Returns: %TRUE if the packet was successfully created.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
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 */
|
|
|
|
|
2004-05-19 17:22:53 +00:00
|
|
|
g_return_val_if_fail (event, FALSE);
|
2004-05-19 16:37:53 +00:00
|
|
|
g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
|
2004-05-19 17:22:53 +00:00
|
|
|
g_return_val_if_fail (header, FALSE);
|
|
|
|
g_return_val_if_fail (payload, FALSE);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
*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:
|
2006-04-28 13:40:15 +00:00
|
|
|
GST_WARNING ("Unknown event, ignoring");
|
2004-05-19 16:37:53 +00:00
|
|
|
*length = 0;
|
|
|
|
g_free (h);
|
|
|
|
return FALSE;
|
|
|
|
case GST_EVENT_EOS:
|
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.
2005-07-27 18:33:03 +00:00
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
case GST_EVENT_NEWSEGMENT:
|
2004-05-19 16:37:53 +00:00
|
|
|
pl_length = 0;
|
|
|
|
*payload = NULL;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_SEEK:
|
2005-07-27 19:00:36 +00:00
|
|
|
{
|
|
|
|
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;
|
2004-05-19 16:37:53 +00:00
|
|
|
*payload = g_malloc0 (pl_length);
|
2005-07-27 19:00:36 +00:00
|
|
|
/* 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);
|
2004-05-19 16:37:53 +00:00
|
|
|
break;
|
2005-07-27 19:00:36 +00:00
|
|
|
}
|
2004-05-19 16:37:53 +00:00
|
|
|
case GST_EVENT_QOS:
|
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
case GST_EVENT_TAG:
|
2006-04-28 13:40:15 +00:00
|
|
|
GST_WARNING ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event));
|
|
|
|
*length = 0;
|
|
|
|
g_free (h);
|
2004-05-19 16:37:53 +00:00
|
|
|
return FALSE;
|
|
|
|
default:
|
2006-04-28 13:40:15 +00:00
|
|
|
GST_WARNING ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event));
|
2004-05-19 16:37:53 +00:00
|
|
|
*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;
|
2005-10-08 17:17:25 +00:00
|
|
|
h[3] = 0; /* padding byte */
|
|
|
|
GST_WRITE_UINT16_BE (h + 4,
|
|
|
|
GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event));
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* length */
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT32_BE (h + 6, (guint32) pl_length);
|
2004-05-19 16:37:53 +00:00
|
|
|
/* timestamp */
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT64_BE (h + 10, GST_EVENT_TIMESTAMP (event));
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* ABI padding */
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT64_BE (h + 42, (guint64) 0);
|
|
|
|
GST_WRITE_UINT64_BE (h + 50, (guint64) 0);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
/* CRC */
|
|
|
|
crc = 0;
|
|
|
|
if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
|
2005-10-08 17:17:25 +00:00
|
|
|
crc = gst_dp_crc (h, 58);
|
2004-05-19 16:37:53 +00:00
|
|
|
}
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 58, crc);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
crc = 0;
|
2004-05-19 17:22:53 +00:00
|
|
|
/* events can have a NULL payload */
|
|
|
|
if (*payload && flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) {
|
GCC 4 fixen.
Original commit message from CVS:
2005-05-04 Andy Wingo <wingo@pobox.com>
* 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.
2005-05-04 21:29:44 +00:00
|
|
|
crc = gst_dp_crc (*payload, strlen ((gchar *) * payload) + 1);
|
2004-05-19 16:37:53 +00:00
|
|
|
}
|
2005-10-08 17:17:25 +00:00
|
|
|
GST_WRITE_UINT16_BE (h + 60, crc);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2006-03-10 15:30:27 +00:00
|
|
|
* Returns: A #GstBuffer if the buffer was successfully created, or NULL.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
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) ==
|
2005-09-27 16:30:26 +00:00
|
|
|
GST_DP_PAYLOAD_BUFFER, NULL);
|
2004-05-19 16:37:53 +00:00
|
|
|
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);
|
2004-06-09 16:24:19 +00:00
|
|
|
GST_BUFFER_FLAGS (buffer) = GST_DP_HEADER_BUFFER_FLAGS (header);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2006-03-10 15:30:27 +00:00
|
|
|
* Returns: A #GstCaps containing the caps represented in the packet,
|
|
|
|
* or NULL if the packet could not be converted.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
GstCaps *
|
|
|
|
gst_dp_caps_from_packet (guint header_length, const guint8 * header,
|
|
|
|
const guint8 * payload)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2005-10-13 16:26:12 +00:00
|
|
|
gchar *string;
|
2004-05-19 16:37:53 +00:00
|
|
|
|
2005-09-27 16:30:26 +00:00
|
|
|
g_return_val_if_fail (header, NULL);
|
|
|
|
g_return_val_if_fail (payload, NULL);
|
2004-05-19 16:37:53 +00:00
|
|
|
g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) ==
|
2005-09-27 16:30:26 +00:00
|
|
|
GST_DP_PAYLOAD_CAPS, NULL);
|
2004-05-19 16:37:53 +00:00
|
|
|
|
2005-10-13 16:26:12 +00:00
|
|
|
string = g_strndup ((gchar *) payload, GST_DP_HEADER_PAYLOAD_LENGTH (header));
|
2004-05-19 16:37:53 +00:00
|
|
|
caps = gst_caps_from_string (string);
|
2005-10-13 16:26:12 +00:00
|
|
|
g_free (string);
|
2004-05-19 16:37:53 +00:00
|
|
|
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.
|
|
|
|
*
|
2006-03-10 15:30:27 +00:00
|
|
|
* Returns: A #GstEvent if the event was successfully created,
|
|
|
|
* or NULL if an event could not be read from the payload.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
GstEvent *
|
|
|
|
gst_dp_event_from_packet (guint header_length, const guint8 * header,
|
|
|
|
const guint8 * payload)
|
|
|
|
{
|
|
|
|
GstEvent *event = NULL;
|
|
|
|
GstEventType type;
|
|
|
|
|
2005-09-27 16:30:26 +00:00
|
|
|
g_return_val_if_fail (header, NULL);
|
2004-05-19 16:37:53 +00:00
|
|
|
/* 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:
|
2006-04-28 13:40:15 +00:00
|
|
|
GST_WARNING ("Unknown event, ignoring");
|
2004-05-19 16:37:53 +00:00
|
|
|
return FALSE;
|
|
|
|
case GST_EVENT_EOS:
|
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.
2005-07-27 18:33:03 +00:00
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
case GST_EVENT_NEWSEGMENT:
|
|
|
|
event = gst_event_new_custom (type, NULL);
|
2004-05-19 16:37:53 +00:00
|
|
|
GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header);
|
|
|
|
break;
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2005-07-27 19:00:36 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
|
|
|
|
|
|
|
/* 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);
|
2004-05-19 16:37:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_QOS:
|
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
case GST_EVENT_TAG:
|
2006-04-28 13:40:15 +00:00
|
|
|
GST_WARNING ("Unhandled event type %d, ignoring", type);
|
2004-05-19 16:37:53 +00:00
|
|
|
return FALSE;
|
|
|
|
default:
|
2006-04-28 13:40:15 +00:00
|
|
|
GST_WARNING ("Unknown event type %d, ignoring", type);
|
2004-05-19 16:37:53 +00:00
|
|
|
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.
|
|
|
|
*
|
2004-07-28 10:22:07 +00:00
|
|
|
* Returns: %TRUE if the CRC matches, or no CRC checksum is present.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2004-07-28 10:22:07 +00:00
|
|
|
* Returns: %TRUE if the CRC matches, or no CRC checksum is present.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2004-07-28 10:22:07 +00:00
|
|
|
* Returns: %TRUE if the packet validates.
|
2004-05-19 16:37:53 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|