2 * The contents of this file are subject to the Mozilla Public License
3 * Version 1.1 (the "License"); you may not use this file except in
4 * compliance with the License. You may obtain a copy of the License at
5 * http://www.mozilla.org/MPL/.
7 * Software distributed under the License is distributed on an "AS IS"
8 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9 * License for the specific language governing rights and limitations
12 * The Original Code is Fluendo MPEG Demuxer plugin.
14 * The Initial Developer of the Original Code is Fluendo, S.L.
15 * Portions created by Fluendo, S.L. are Copyright (C) 2005
16 * Fluendo, S.L. All Rights Reserved.
18 * Contributor(s): Wim Taymans <wim@fluendo.com>
20 * Alternatively, the contents of this file may be used under the terms of
21 * the GNU Lesser General Public License Version 2 or later (the "LGPL"),
22 * in which case the provisions of the LGPL are applicable instead
23 * of those above. If you wish to allow use of your version of this file only
24 * under the terms of the LGPL, and not to allow others to
25 * use your version of this file under the terms of the MPL, indicate your
26 * decision by deleting the provisions above and replace them with the notice
27 * and other provisions required by the LGPL. If you do not delete
28 * the provisions above, a recipient may use your version of this file under
29 * the terms of the MPL or the LGPL.
36 #include "gstmpegdesc.h"
38 GST_DEBUG_CATEGORY (gstmpegtsdesc_debug);
39 #define GST_CAT_DEFAULT (gstmpegtsdesc_debug)
42 gst_mpeg_descriptor_free (GstMPEGDescriptor * desc)
44 g_return_if_fail (desc != NULL);
50 gst_mpeg_descriptor_parse_1 (guint8 * data, guint size)
55 /* need at least 2 bytes for tag and length */
63 GST_DEBUG ("tag: 0x%02x, length: %d", tag, length);
68 GST_MEMDUMP ("tag contents:", data, length);
74 gst_mpeg_descriptor_parse (guint8 * data, guint size)
77 guint consumed, total, n_desc;
78 GstMPEGDescriptor *result;
80 g_return_val_if_fail (data != NULL, NULL);
87 consumed = gst_mpeg_descriptor_parse_1 (current, size);
98 GST_DEBUG ("parsed %d descriptors", n_desc);
103 result = g_malloc (sizeof (GstMPEGDescriptor) + total);
104 result->n_desc = n_desc;
105 result->data_length = total;
106 result->data = ((guint8 *) result) + sizeof (GstMPEGDescriptor);
108 memcpy (result->data, data, total);
114 gst_mpeg_descriptor_n_desc (GstMPEGDescriptor * desc)
116 g_return_val_if_fail (desc != NULL, 0);
122 gst_mpeg_descriptor_find (GstMPEGDescriptor * desc, gint tag)
128 g_return_val_if_fail (desc != NULL, NULL);
130 current = desc->data;
131 length = desc->data_length;
134 if (DESC_TAG (current) == tag)
137 size = DESC_LENGTH (current) + 2;
145 /* array needs freeing afterwards */
147 gst_mpeg_descriptor_find_all (GstMPEGDescriptor * desc, gint tag)
155 g_return_val_if_fail (desc != NULL, NULL);
156 all = g_array_new (TRUE, TRUE, sizeof (guint8 *));
158 current = desc->data;
159 length = desc->data_length;
162 if (DESC_TAG (current) == tag)
163 g_array_append_val (all, current);
164 size = DESC_LENGTH (current) + 2;
170 GST_DEBUG ("found tag 0x%02x %d times", tag, all->len);
176 gst_mpeg_descriptor_nth (GstMPEGDescriptor * desc, guint i)
182 g_return_val_if_fail (desc != NULL, NULL);
184 if (i > desc->n_desc)
187 current = desc->data;
188 length = desc->data_length;
194 size = DESC_LENGTH (current) + 2;
205 gst_mpegtsdesc_init_debug (void)
207 GST_DEBUG_CATEGORY_INIT (gstmpegtsdesc_debug, "mpegtsdesc", 0,
208 "MPEG transport stream parser (descriptor)");