2 * gstannodex.c - GStreamer annodex plugin
3 * Copyright (C) 2005 Alessandro Decina
6 * Alessandro Decina <alessandro@nnva.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <gst/tag/tag.h>
30 #include "gstannodex.h"
31 #include "gstcmmlparser.h"
32 #include "gstcmmlenc.h"
33 #include "gstcmmldec.h"
36 gst_annodex_granule_to_time (gint64 granulepos, gint64 granulerate_n,
37 gint64 granulerate_d, guint8 granuleshift)
39 gint64 keyindex, keyoffset;
43 g_return_val_if_fail (granuleshift <= 64, GST_CLOCK_TIME_NONE);
46 return GST_CLOCK_TIME_NONE;
48 if (granulepos == 0 || granulerate_n == 0 || granulerate_d == 0)
51 if (granuleshift != 0 && granuleshift != 64) {
52 keyindex = granulepos >> granuleshift;
53 keyoffset = granulepos - (keyindex << granuleshift);
54 granulepos = keyindex + keyoffset;
57 /* GST_SECOND / (granulerate_n / granulerate_d) */
58 granulerate = gst_util_uint64_scale (GST_SECOND,
59 granulerate_d, granulerate_n);
61 /* granulepos * granulerate */
62 res = gst_util_uint64_scale (granulepos, granulerate, 1);
68 gst_annodex_parse_headers (const gchar * headers)
72 gchar *header_name = NULL;
73 gchar *header_value = NULL;
74 gchar *line, *column, *space, *tmp;
78 array = g_value_array_new (0);
79 g_value_init (&val, G_TYPE_STRING);
81 lines = g_strsplit (headers, "\r\n", 0);
83 while (line != NULL && *line != '\0') {
84 if (line[0] == '\t' || line[0] == ' ') {
85 /* WSP: continuation line */
86 if (header_value == NULL)
87 /* continuation line without a previous value */
90 tmp = g_strjoin (" ", header_value, g_strstrip (line), NULL);
91 g_free (header_value);
95 g_value_take_string (&val, header_name);
96 g_value_array_append (array, &val);
97 g_value_take_string (&val, header_value);
98 g_value_array_append (array, &val);
100 /* search the column starting from line[1] as an header name can't be
102 column = g_strstr_len (line + 1, strlen (line) - 1, ":");
107 if (*(space = column + 1) != ' ')
111 header_name = g_strndup (line, column - line);
112 header_value = g_strdup (space + 1);
119 g_value_take_string (&val, header_name);
120 g_value_array_append (array, &val);
121 g_value_take_string (&val, header_value);
122 g_value_array_append (array, &val);
125 g_value_unset (&val);
131 GST_WARNING ("could not parse annodex headers");
132 g_free (header_name);
133 g_free (header_value);
135 g_value_array_free (array);
136 g_value_unset (&val);
141 plugin_init (GstPlugin * plugin)
143 gst_tag_register (GST_TAG_CMML_STREAM, GST_TAG_FLAG_META,
144 GST_TYPE_CMML_TAG_STREAM, "cmml-stream", "annodex CMML stream tag", NULL);
146 gst_tag_register (GST_TAG_CMML_HEAD, GST_TAG_FLAG_META,
147 GST_TYPE_CMML_TAG_HEAD, "cmml-head", "annodex CMML head tag", NULL);
149 gst_tag_register (GST_TAG_CMML_CLIP, GST_TAG_FLAG_META,
150 GST_TYPE_CMML_TAG_CLIP, "cmml-clip", "annodex CMML clip tag", NULL);
152 gst_cmml_parser_init ();
154 if (!gst_cmml_enc_plugin_init (plugin))
157 if (!gst_cmml_dec_plugin_init (plugin))
163 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
166 "annodex stream manipulation (info about annodex: http://www.annodex.net)",
167 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)