1 /* Quicktime muxer plugin for GStreamer
2 * Copyright (C) 2008 Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
24 * Permission is hereby granted, free of charge, to any person obtaining a copy of
25 * this software and associated documentation files (the "Software"), to deal in
26 * the Software without restriction, including without limitation the rights to
27 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28 * of the Software, and to permit persons to whom the Software is furnished to do
29 * so, subject to the following conditions:
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 #include "properties.h"
45 /* if needed, re-allocate buffer to ensure size bytes can be written into it
48 prop_copy_ensure_buffer (guint8 ** buffer, guint64 * bsize, guint64 * offset,
51 if (buffer && *bsize - *offset < size) {
52 *bsize += size + 10 * 1024;
53 *buffer = g_realloc (*buffer, *bsize);
58 copy_func (void *prop, guint size, guint8 ** buffer, guint64 * bsize,
62 prop_copy_ensure_buffer (buffer, bsize, offset, size);
63 memcpy (*buffer + *offset, prop, size);
69 #define INT_ARRAY_COPY_FUNC_FAST(name, datatype) \
70 guint64 prop_copy_ ## name ## _array (datatype *prop, guint size, \
71 guint8 ** buffer, guint64 * bsize, guint64 * offset) { \
72 return copy_func (prop, sizeof (datatype) * size, buffer, bsize, offset);\
75 #define INT_ARRAY_COPY_FUNC(name, datatype) \
76 guint64 prop_copy_ ## name ## _array (datatype *prop, guint size, \
77 guint8 ** buffer, guint64 * bsize, guint64 * offset) { \
80 for (i = 0; i < size; i++) { \
81 prop_copy_ ## name (prop[i], buffer, bsize, offset); \
83 return sizeof (datatype) * size; \
88 prop_copy_uint8 (guint8 prop, guint8 ** buffer, guint64 * size,
91 return copy_func (&prop, sizeof (guint8), buffer, size, offset);
95 prop_copy_uint16 (guint16 prop, guint8 ** buffer, guint64 * size,
98 prop = GUINT16_TO_BE (prop);
99 return copy_func (&prop, sizeof (guint16), buffer, size, offset);
103 prop_copy_uint32 (guint32 prop, guint8 ** buffer, guint64 * size,
106 prop = GUINT32_TO_BE (prop);
107 return copy_func (&prop, sizeof (guint32), buffer, size, offset);
111 prop_copy_uint64 (guint64 prop, guint8 ** buffer, guint64 * size,
114 prop = GUINT64_TO_BE (prop);
115 return copy_func (&prop, sizeof (guint64), buffer, size, offset);
119 prop_copy_int32 (gint32 prop, guint8 ** buffer, guint64 * size,
122 prop = GINT32_TO_BE (prop);
123 return copy_func (&prop, sizeof (guint32), buffer, size, offset);
126 /* uint8 can use direct copy in any case, and may be used for large quantity */
127 INT_ARRAY_COPY_FUNC_FAST (uint8, guint8);
128 /* not used in large quantity anyway */
129 INT_ARRAY_COPY_FUNC (uint16, guint16);
130 INT_ARRAY_COPY_FUNC (uint32, guint32);
131 INT_ARRAY_COPY_FUNC (uint64, guint64);
135 prop_copy_fourcc (guint32 prop, guint8 ** buffer, guint64 * size,
138 prop = GINT32_TO_LE (prop);
139 return copy_func (&prop, sizeof (guint32), buffer, size, offset);
142 INT_ARRAY_COPY_FUNC (fourcc, guint32);
145 * prop_copy_fixed_size_string:
146 * @string: the string to be copied
147 * @str_size: size of the string
148 * @buffer: the array to copy the string to
149 * @offset: the position in the buffer array.
150 * This value is updated to the point right after the copied string.
152 * Copies a string of bytes without placing its size at the beginning.
154 * Returns: the number of bytes copied
157 prop_copy_fixed_size_string (guint8 * string, guint str_size, guint8 ** buffer,
158 guint64 * size, guint64 * offset)
160 return copy_func (string, str_size * sizeof (guint8), buffer, size, offset);
164 * prop_copy_size_string:
166 * @string: the string to be copied
167 * @str_size: size of the string
168 * @buffer: the array to copy the string to
169 * @offset: the position in the buffer array.
170 * This value is updated to the point right after the copied string.
172 * Copies a string and its size to an array. Example:
174 * result in the array: [3][a][b][c] (each [x] represents a position)
176 * Returns: the number of bytes copied
179 prop_copy_size_string (guint8 * string, guint str_size, guint8 ** buffer,
180 guint64 * size, guint64 * offset)
182 guint64 original_offset = *offset;
184 prop_copy_uint8 (str_size, buffer, size, offset);
185 prop_copy_fixed_size_string (string, str_size, buffer, size, offset);
186 return *offset - original_offset;
190 * prop_copy_null_terminated_string:
191 * @string: the string to be copied
192 * @buffer: the array to copy the string to
193 * @offset: the position in the buffer array.
194 * This value is updated to the point right after the copied string.
196 * Copies a string including its null terminating char to an array.
198 * Returns: the number of bytes copied
201 prop_copy_null_terminated_string (gchar * string, guint8 ** buffer,
202 guint64 * size, guint64 * offset)
204 guint64 original_offset = *offset;
205 guint len = strlen (string);
207 prop_copy_fixed_size_string ((guint8 *) string, len, buffer, size, offset);
208 prop_copy_uint8 ('\0', buffer, size, offset);
209 return *offset - original_offset;