First THREADED backport attempt, focusing on adding locks and making sure the API...
[platform/upstream/gstreamer.git] / libs / gst / dataprotocol / dataprotocol.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
4  *
5  * dataprotocol.c: Functions implementing the GStreamer Data Protocol
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gst/gst.h>
28 #include <gst/dataprotocol/dataprotocol.h>
29 #include <glib/gprintf.h>       /* g_sprintf */
30 #include <string.h>             /* strlen */
31 #include "dp-private.h"
32
33 /* debug category */
34 GST_DEBUG_CATEGORY (data_protocol_debug);
35 #define GST_CAT_DEFAULT data_protocol_debug
36
37 /* calculate a CCITT 16 bit CRC check value for a given byte array */
38 /*
39  * this code snippet is adapted from a web page I found
40  * it is identical except for cleanups, and a final XOR with 0xffff
41  * as outlined in the uecp spec
42  *
43  * XMODEM    x^16 + x^12 + x^5 + 1
44  */
45
46 #define POLY       0x1021
47 #define CRC_INIT   0xFFFF
48
49 static guint16
50 gst_dp_crc (const guint8 * buffer, register guint length)
51 {
52   static gboolean initialized = FALSE;
53   static guint16 crc_table[256];
54   guint16 crc_register;
55   unsigned long i, j, k;
56
57   if (!initialized) {
58     for (i = 0; i < 256; i++) {
59       j = i << 8;
60       for (k = 8; k--;) {
61         j = j & 0x8000 ? (j << 1) ^ POLY : j << 1;
62       }
63
64       crc_table[i] = (guint16) j;
65     }
66     initialized = TRUE;
67   }
68
69   crc_register = CRC_INIT;      /* always init register */
70
71   /* calc CRC */
72   for (; length--;) {
73     crc_register = (guint16) ((crc_register << 8) ^
74         crc_table[((crc_register >> 8) & 0x00ff) ^ *buffer++]);
75   }
76   return (0xffff ^ crc_register);
77 }
78
79 /* debugging function; dumps byte array values per 8 bytes */
80 /* FIXME: would be nice to merge this with gst_util_dump_mem () */
81 void
82 gst_dp_dump_byte_array (guint8 * array, guint length)
83 {
84   int i;
85   int n = 8;                    /* number of bytes per line */
86   gchar *line = g_malloc (3 * n + 1);
87
88   GST_LOG ("dumping byte array of length %d", length);
89   for (i = 0; i < length; ++i) {
90     g_sprintf (line + 3 * (i % n), "%02x ", array[i]);
91     if (i % n == (n - 1)) {
92       GST_LOG ("%03d: %s", i - (n - 1), line);
93     }
94   }
95   if (i % n != 0) {
96     GST_LOG ("%03d: %s", (i / n) * n, line);
97   }
98   g_free (line);
99 }
100
101 /**
102  * gst_dp_init:
103  *
104  * Initialize GStreamer Data Protocol library.
105  *
106  * Should be called before using these functions; either from source linking
107  * to this source file or from plugin_init.
108  */
109 void
110 gst_dp_init (void)
111 {
112   static gboolean _gst_dp_initialized = FALSE;
113
114   if (_gst_dp_initialized)
115     return;
116
117   _gst_dp_initialized = TRUE;
118
119   GST_DEBUG_CATEGORY_INIT (data_protocol_debug, "gdp", 0,
120       "GStreamer Data Protocol");
121 }
122
123 /*** PUBLIC FUNCTIONS ***/
124
125 /**
126  * gst_dp_header_payload_length:
127  * @header: the byte header of the packet array
128  *
129  * Returns: the length of the payload this header describes.
130  */
131 guint32
132 gst_dp_header_payload_length (const guint8 * header)
133 {
134   return GST_DP_HEADER_PAYLOAD_LENGTH (header);
135 }
136
137 /**
138  * gst_dp_header_payload_type:
139  * @header: the byte header of the packet array
140  *
141  * Returns: the #GstDPPayloadType the payload this header describes.
142  */
143 GstDPPayloadType
144 gst_dp_header_payload_type (const guint8 * header)
145 {
146   return GST_DP_HEADER_PAYLOAD_TYPE (header);
147 }
148
149 /**
150  * gst_dp_header_from_buffer:
151  * @buffer: a #GstBuffer to create a header for
152  * @flags: the #GDPHeaderFlags to create the header with
153  * @length: a guint pointer to store the header length in
154  * @header: a guint8 * pointer to store a newly allocated header byte array in
155  *
156  * Creates a GDP header from the given buffer.
157  *
158  * Returns: %TRUE if the header was successfully created.
159  */
160
161 gboolean
162 gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags,
163     guint * length, guint8 ** header)
164 {
165   guint8 *h;
166   guint16 crc;
167   guint16 flags_mask;
168
169   g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
170   g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buffer) > 0, FALSE);
171   g_return_val_if_fail (header, FALSE);
172
173   *length = GST_DP_HEADER_LENGTH;
174   h = g_malloc (GST_DP_HEADER_LENGTH);
175
176   /* version, flags, type */
177   h[0] = (guint8) GST_DP_VERSION_MAJOR;
178   h[1] = (guint8) GST_DP_VERSION_MINOR;
179   h[2] = (guint8) flags;
180   h[3] = GST_DP_PAYLOAD_BUFFER;
181
182   /* buffer properties */
183   GST_WRITE_UINT32_BE (h + 4, GST_BUFFER_SIZE (buffer));
184   GST_WRITE_UINT64_BE (h + 8, GST_BUFFER_TIMESTAMP (buffer));
185   GST_WRITE_UINT64_BE (h + 16, GST_BUFFER_DURATION (buffer));
186   GST_WRITE_UINT64_BE (h + 24, GST_BUFFER_OFFSET (buffer));
187   GST_WRITE_UINT64_BE (h + 32, GST_BUFFER_OFFSET_END (buffer));
188
189   /* data flags */
190   /* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */
191   flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_PREROLL) |
192       GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS) |
193       GST_DATA_FLAG_SHIFT (GST_BUFFER_DELTA_UNIT);
194
195   GST_WRITE_UINT16_BE (h + 40, GST_BUFFER_FLAGS (buffer) & flags_mask);
196
197   /* ABI padding */
198   GST_WRITE_UINT16_BE (h + 42, (guint64) 0);
199   GST_WRITE_UINT32_BE (h + 44, (guint64) 0);
200   GST_WRITE_UINT64_BE (h + 48, (guint64) 0);
201
202   /* CRC */
203   crc = 0;
204   if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
205     /* we don't crc the last four bytes of the header since they are crc's */
206     crc = gst_dp_crc (h, 56);
207   }
208   GST_WRITE_UINT16_BE (h + 56, crc);
209
210   crc = 0;
211   if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) {
212     crc = gst_dp_crc (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
213   }
214   GST_WRITE_UINT16_BE (h + 58, crc);
215
216   GST_LOG ("created header from buffer:");
217   gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH);
218   *header = h;
219   return TRUE;
220 }
221
222  /**
223  * gst_dp_packet_from_caps:
224  * @caps: a #GstCaps to create a packet for
225  * @flags: the #GDPHeaderFlags to create the header with
226  * @length: a guint pointer to store the header length in
227  * @header: a guint8 pointer to store a newly allocated header byte array in
228  * @payload: a guint8 pointer to store a newly allocated payload byte array in
229  *
230  * Creates a GDP packet from the given caps.
231  *
232  * Returns: %TRUE if the packet was successfully created.
233  */
234 gboolean
235 gst_dp_packet_from_caps (const GstCaps * caps, GstDPHeaderFlag flags,
236     guint * length, guint8 ** header, guint8 ** payload)
237 {
238   guint8 *h;
239   guint16 crc;
240   gchar *string;
241
242   /* FIXME: GST_IS_CAPS doesn't work
243      g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); */
244   g_return_val_if_fail (caps, FALSE);
245   g_return_val_if_fail (header, FALSE);
246   g_return_val_if_fail (payload, FALSE);
247
248   *length = GST_DP_HEADER_LENGTH;
249   h = g_malloc (GST_DP_HEADER_LENGTH);
250
251   string = gst_caps_to_string (caps);
252
253   /* version, flags, type */
254   h[0] = (guint8) GST_DP_VERSION_MAJOR;
255   h[1] = (guint8) GST_DP_VERSION_MINOR;
256   h[2] = (guint8) flags;
257   h[3] = GST_DP_PAYLOAD_CAPS;
258
259   /* buffer properties */
260   GST_WRITE_UINT32_BE (h + 4, strlen (string) + 1);     /* include trailing 0 */
261   GST_WRITE_UINT64_BE (h + 8, (guint64) 0);
262   GST_WRITE_UINT64_BE (h + 16, (guint64) 0);
263   GST_WRITE_UINT64_BE (h + 24, (guint64) 0);
264   GST_WRITE_UINT64_BE (h + 32, (guint64) 0);
265
266   /* ABI padding */
267   GST_WRITE_UINT64_BE (h + 40, (guint64) 0);
268   GST_WRITE_UINT64_BE (h + 48, (guint64) 0);
269
270   /* CRC */
271   crc = 0;
272   if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
273     crc = gst_dp_crc (h, 56);
274   }
275   GST_WRITE_UINT16_BE (h + 56, crc);
276
277   crc = 0;
278   if (flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) {
279     crc = gst_dp_crc (string, strlen (string) + 1);
280   }
281   GST_WRITE_UINT16_BE (h + 58, crc);
282
283   GST_LOG ("created header from caps:");
284   gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH);
285   *header = h;
286   *payload = string;
287   return TRUE;
288 }
289
290 /**
291  * gst_dp_packet_from_event:
292  * @event: a #GstEvent to create a packet for
293  * @flags: the #GDPHeaderFlags to create the header with
294  * @length: a guint pointer to store the header length in
295  * @header: a guint8 pointer to store a newly allocated header byte array in
296  * @payload: a guint8 pointer to store a newly allocated payload byte array in
297  *
298  * Creates a GDP packet from the given event.
299  *
300  * Returns: %TRUE if the packet was successfully created.
301  */
302 gboolean
303 gst_dp_packet_from_event (const GstEvent * event, GstDPHeaderFlag flags,
304     guint * length, guint8 ** header, guint8 ** payload)
305 {
306   guint8 *h;
307   guint16 crc;
308   guint pl_length;              /* length of payload */
309
310   g_return_val_if_fail (event, FALSE);
311   g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
312   g_return_val_if_fail (header, FALSE);
313   g_return_val_if_fail (payload, FALSE);
314
315   *length = GST_DP_HEADER_LENGTH;
316   h = g_malloc0 (GST_DP_HEADER_LENGTH);
317
318   /* first construct payload, since we need the length */
319   switch (GST_EVENT_TYPE (event)) {
320     case GST_EVENT_UNKNOWN:
321       g_warning ("Unknown event, ignoring");
322       *length = 0;
323       g_free (h);
324       return FALSE;
325     case GST_EVENT_EOS:
326     case GST_EVENT_FLUSH:
327     case GST_EVENT_EMPTY:
328     case GST_EVENT_DISCONTINUOUS:
329       GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event));
330       pl_length = 0;
331       *payload = NULL;
332       break;
333     case GST_EVENT_SEEK:
334       pl_length = 4 + 8 + 4;
335       *payload = g_malloc0 (pl_length);
336       GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event));
337       GST_WRITE_UINT64_BE (*payload + 4,
338           (guint64) GST_EVENT_SEEK_OFFSET (event));
339       GST_WRITE_UINT32_BE (*payload + 12,
340           (guint32) GST_EVENT_SEEK_ACCURACY (event));
341       break;
342     case GST_EVENT_SEEK_SEGMENT:
343       pl_length = 4 + 8 + 8 + 4;
344       *payload = g_malloc0 (pl_length);
345       GST_WRITE_UINT32_BE (*payload, (guint32) GST_EVENT_SEEK_TYPE (event));
346       GST_WRITE_UINT64_BE (*payload + 4,
347           (guint64) GST_EVENT_SEEK_OFFSET (event));
348       GST_WRITE_UINT64_BE (*payload + 12,
349           (guint64) GST_EVENT_SEEK_ENDOFFSET (event));
350       GST_WRITE_UINT32_BE (*payload + 20,
351           (guint32) GST_EVENT_SEEK_ACCURACY (event));
352       break;
353     case GST_EVENT_QOS:
354     case GST_EVENT_SEGMENT_DONE:
355     case GST_EVENT_SIZE:
356     case GST_EVENT_RATE:
357     case GST_EVENT_FILLER:
358     case GST_EVENT_TS_OFFSET:
359     case GST_EVENT_INTERRUPT:
360     case GST_EVENT_NAVIGATION:
361     case GST_EVENT_TAG:
362       g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event));
363       return FALSE;
364     default:
365       g_warning ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event));
366       *length = 0;
367       g_free (h);
368       return FALSE;
369   }
370
371   /* version, flags, type */
372   h[0] = (guint8) GST_DP_VERSION_MAJOR;
373   h[1] = (guint8) GST_DP_VERSION_MINOR;
374   h[2] = (guint8) flags;
375   h[3] = GST_DP_PAYLOAD_EVENT_NONE + GST_EVENT_TYPE (event);
376
377   /* length */
378   GST_WRITE_UINT32_BE (h + 4, (guint32) pl_length);
379   /* timestamp */
380   GST_WRITE_UINT64_BE (h + 8, GST_EVENT_TIMESTAMP (event));
381
382   /* ABI padding */
383   GST_WRITE_UINT64_BE (h + 40, (guint64) 0);
384   GST_WRITE_UINT64_BE (h + 48, (guint64) 0);
385
386   /* CRC */
387   crc = 0;
388   if (flags & GST_DP_HEADER_FLAG_CRC_HEADER) {
389     crc = gst_dp_crc (h, 56);
390   }
391   GST_WRITE_UINT16_BE (h + 56, crc);
392
393   crc = 0;
394   /* events can have a NULL payload */
395   if (*payload && flags & GST_DP_HEADER_FLAG_CRC_PAYLOAD) {
396     crc = gst_dp_crc (*payload, strlen (*payload) + 1);
397   }
398   GST_WRITE_UINT16_BE (h + 58, crc);
399
400   GST_LOG ("created header from event:");
401   gst_dp_dump_byte_array (h, GST_DP_HEADER_LENGTH);
402   *header = h;
403   return TRUE;
404 }
405
406
407 /**
408  * gst_dp_buffer_from_header:
409  * @header_length: the length of the packet header
410  * @header: the byte array of the packet header
411  *
412  * Creates a newly allocated #GstBuffer from the given header.
413  * The buffer data needs to be copied into it before validating.
414  *
415  * Use this function if you want to pre-allocate a buffer based on the
416  * packet header to read the packet payload in to.
417  *
418  * Returns: %TRUE if the buffer was successfully created.
419  */
420 GstBuffer *
421 gst_dp_buffer_from_header (guint header_length, const guint8 * header)
422 {
423   GstBuffer *buffer;
424
425   g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) ==
426       GST_DP_PAYLOAD_BUFFER, FALSE);
427   buffer =
428       gst_buffer_new_and_alloc ((guint) GST_DP_HEADER_PAYLOAD_LENGTH (header));
429   GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header);
430   GST_BUFFER_DURATION (buffer) = GST_DP_HEADER_DURATION (header);
431   GST_BUFFER_OFFSET (buffer) = GST_DP_HEADER_OFFSET (header);
432   GST_BUFFER_OFFSET_END (buffer) = GST_DP_HEADER_OFFSET_END (header);
433   GST_BUFFER_FLAGS (buffer) = GST_DP_HEADER_BUFFER_FLAGS (header);
434
435   return buffer;
436 }
437
438 /**
439  * gst_dp_caps_from_packet:
440  * @header_length: the length of the packet header
441  * @header: the byte array of the packet header
442  * @payload: the byte array of the packet payload
443  *
444  * Creates a newly allocated #GstCaps from the given packet.
445  *
446  * Returns: %TRUE if the caps was successfully created.
447  */
448 GstCaps *
449 gst_dp_caps_from_packet (guint header_length, const guint8 * header,
450     const guint8 * payload)
451 {
452   GstCaps *caps;
453   const gchar *string;
454
455   g_return_val_if_fail (header, FALSE);
456   g_return_val_if_fail (payload, FALSE);
457   g_return_val_if_fail (GST_DP_HEADER_PAYLOAD_TYPE (header) ==
458       GST_DP_PAYLOAD_CAPS, FALSE);
459
460   string = payload;
461   caps = gst_caps_from_string (string);
462   return caps;
463 }
464
465 /**
466  * gst_dp_event_from_packet:
467  * @header_length: the length of the packet header
468  * @header: the byte array of the packet header
469  * @payload: the byte array of the packet payload
470  *
471  * Creates a newly allocated #GstEvent from the given packet.
472  *
473  * Returns: %TRUE if the event was successfully created.
474  */
475 GstEvent *
476 gst_dp_event_from_packet (guint header_length, const guint8 * header,
477     const guint8 * payload)
478 {
479   GstEvent *event = NULL;
480   GstEventType type;
481
482   g_return_val_if_fail (header, FALSE);
483   /* payload can be NULL, e.g. for an EOS event */
484
485   type = GST_DP_HEADER_PAYLOAD_TYPE (header) - GST_DP_PAYLOAD_EVENT_NONE;
486   switch (type) {
487     case GST_EVENT_UNKNOWN:
488       g_warning ("Unknown event, ignoring");
489       return FALSE;
490     case GST_EVENT_EOS:
491     case GST_EVENT_FLUSH:
492     case GST_EVENT_EMPTY:
493     case GST_EVENT_DISCONTINUOUS:
494       event = gst_event_new (type);
495       GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header);
496       break;
497     case GST_EVENT_SEEK:
498     {
499       GstSeekType type;
500       gint64 offset;
501       GstSeekAccuracy accuracy;
502
503       type = (GstSeekType) GST_READ_UINT32_BE (payload);
504       offset = (gint64) GST_READ_UINT64_BE (payload + 4);
505       accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 12);
506       event = gst_event_new_seek (type, offset);
507       GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header);
508       GST_EVENT_SEEK_ACCURACY (event) = accuracy;
509       break;
510     }
511     case GST_EVENT_SEEK_SEGMENT:
512     {
513       GstSeekType type;
514       gint64 offset, endoffset;
515       GstSeekAccuracy accuracy;
516
517       type = (GstSeekType) GST_READ_UINT32_BE (payload);
518       offset = (gint64) GST_READ_UINT64_BE (payload + 4);
519       endoffset = (gint64) GST_READ_UINT64_BE (payload + 12);
520       accuracy = (GstSeekAccuracy) GST_READ_UINT32_BE (payload + 20);
521       event = gst_event_new_segment_seek (type, offset, endoffset);
522       GST_EVENT_TIMESTAMP (event) = GST_DP_HEADER_TIMESTAMP (header);
523       GST_EVENT_SEEK_ACCURACY (event) = accuracy;
524       break;
525     }
526     case GST_EVENT_QOS:
527     case GST_EVENT_SEGMENT_DONE:
528     case GST_EVENT_SIZE:
529     case GST_EVENT_RATE:
530     case GST_EVENT_FILLER:
531     case GST_EVENT_TS_OFFSET:
532     case GST_EVENT_INTERRUPT:
533     case GST_EVENT_NAVIGATION:
534     case GST_EVENT_TAG:
535       g_warning ("Unhandled event type %d, ignoring", GST_EVENT_TYPE (event));
536       return FALSE;
537     default:
538       g_warning ("Unknown event type %d, ignoring", GST_EVENT_TYPE (event));
539       return FALSE;
540   }
541
542   return event;
543 }
544
545 /**
546  * gst_dp_validate_header:
547  * @header_length: the length of the packet header
548  * @header: the byte array of the packet header
549  *
550  * Validates the given packet header by checking the CRC checksum.
551  *
552  * Returns: %TRUE if the CRC matches, or no CRC checksum is present.
553  */
554 gboolean
555 gst_dp_validate_header (guint header_length, const guint8 * header)
556 {
557   guint16 crc_read, crc_calculated;
558
559   if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_HEADER))
560     return TRUE;
561   crc_read = GST_DP_HEADER_CRC_HEADER (header);
562   /* don't included the last two crc fields for the crc check */
563   crc_calculated = gst_dp_crc (header, header_length - 4);
564   if (crc_read != crc_calculated) {
565     GST_WARNING ("header crc mismatch: read %02x, calculated %02x", crc_read,
566         crc_calculated);
567     return FALSE;
568   }
569   GST_LOG ("header crc validation: %02x", crc_read);
570   return TRUE;
571 }
572
573 /**
574  * gst_dp_validate_payload:
575  * @header_length: the length of the packet header
576  * @header: the byte array of the packet header
577  * @payload: the byte array of the packet payload
578  *
579  * Validates the given packet payload using the given packet header
580  * by checking the CRC checksum.
581  *
582  * Returns: %TRUE if the CRC matches, or no CRC checksum is present.
583  */
584 gboolean
585 gst_dp_validate_payload (guint header_length, const guint8 * header,
586     const guint8 * payload)
587 {
588   guint16 crc_read, crc_calculated;
589
590   if (!(GST_DP_HEADER_FLAGS (header) & GST_DP_HEADER_FLAG_CRC_PAYLOAD))
591     return TRUE;
592   crc_read = GST_DP_HEADER_CRC_PAYLOAD (header);
593   crc_calculated = gst_dp_crc (payload, GST_DP_HEADER_PAYLOAD_LENGTH (header));
594   if (crc_read != crc_calculated) {
595     GST_WARNING ("payload crc mismatch: read %02x, calculated %02x", crc_read,
596         crc_calculated);
597     return FALSE;
598   }
599   GST_LOG ("payload crc validation: %02x", crc_read);
600   return TRUE;
601 }
602
603 /**
604  * gst_dp_validate_packet:
605  * @header_length: the length of the packet header
606  * @header: the byte array of the packet header
607  * @payload: the byte array of the packet payload
608  *
609  * Validates the given packet by checking version information and checksums.
610  *
611  * Returns: %TRUE if the packet validates.
612  */
613 gboolean
614 gst_dp_validate_packet (guint header_length, const guint8 * header,
615     const guint8 * payload)
616 {
617   if (!gst_dp_validate_header (header_length, header))
618     return FALSE;
619   if (!gst_dp_validate_payload (header_length, header, payload))
620     return FALSE;
621
622   return TRUE;
623 }
624
625 /*** PLUGIN STUFF ***/
626 static gboolean
627 plugin_init (GstPlugin * plugin)
628 {
629   gst_dp_init ();
630
631   return TRUE;
632 }
633
634 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
635     GST_VERSION_MINOR,
636     "gstdataprotocol",
637     "a data protocol to serialize buffers, caps and events",
638     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)