2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstevent.h: Header for GstEvent subsystem
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.
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.
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.
23 #include <string.h> /* memcpy */
25 #include "gst_private.h"
26 #include "gstdata_private.h"
29 #include "gstmemchunk.h"
34 #ifndef GST_DISABLE_TRACE
35 /* #define GST_WITH_ALLOC_TRACE */
37 static GstAllocTrace *_event_trace;
40 static GstMemChunk *chunk;
44 GType _gst_event_type;
47 _gst_event_initialize (void)
49 /* register the type */
50 _gst_event_type = g_boxed_type_register_static ("GstEvent",
51 (GBoxedCopyFunc) gst_data_ref,
52 (GBoxedFreeFunc) gst_data_unref);
54 #ifndef GST_DISABLE_TRACE
55 _event_trace = gst_alloc_trace_register (GST_EVENT_TRACE_NAME);
58 chunk = gst_mem_chunk_new ("GstEventChunk", sizeof (GstEvent),
59 sizeof (GstEvent) * 50, 0);
63 _gst_event_copy (GstEvent *event)
67 copy = gst_mem_chunk_alloc (chunk);
68 #ifndef GST_DISABLE_TRACE
69 gst_alloc_trace_new (_event_trace, copy);
72 memcpy (copy, event, sizeof (GstEvent));
74 /* FIXME copy/ref additional fields */
75 switch (GST_EVENT_TYPE (event)) {
77 copy->event_data.structure.structure = gst_structure_copy (event->event_data.structure.structure);
86 _gst_event_free (GstEvent* event)
88 GST_CAT_INFO (GST_CAT_EVENT, "freeing event %p", event);
90 if (GST_EVENT_SRC (event)) {
91 gst_object_unref (GST_EVENT_SRC (event));
93 switch (GST_EVENT_TYPE (event)) {
95 if (GST_IS_TAG_LIST (event->event_data.structure.structure))
96 gst_tag_list_free (event->event_data.structure.structure);
98 case GST_EVENT_NAVIGATION:
99 gst_structure_free (event->event_data.structure.structure);
104 _GST_DATA_DISPOSE (GST_DATA (event));
105 #ifndef GST_DISABLE_TRACE
106 gst_alloc_trace_free (_event_trace, event);
108 gst_mem_chunk_free (chunk, event);
112 * gst_event_masks_contains:
113 * @masks: The eventmask array to search
114 * @mask: the event mask to find
116 * See if the given eventmask is inside the eventmask array.
118 * Returns: TRUE if the eventmask is found inside the array
121 gst_event_masks_contains (const GstEventMask *masks, GstEventMask *mask)
123 g_return_val_if_fail (mask != NULL, FALSE);
128 while (masks->type) {
129 if (masks->type == mask->type &&
130 (masks->flags & mask->flags) == mask->flags)
140 gst_event_get_type (void)
142 return _gst_event_type;
147 * @type: The type of the new event
149 * Allocate a new event of the given type.
151 * Returns: A new event.
154 gst_event_new (GstEventType type)
158 event = gst_mem_chunk_alloc0 (chunk);
159 #ifndef GST_DISABLE_TRACE
160 gst_alloc_trace_new (_event_trace, event);
163 GST_CAT_INFO (GST_CAT_EVENT, "creating new event %p %d", event, type);
165 _GST_DATA_INIT (GST_DATA (event),
168 (GstDataFreeFunction) _gst_event_free,
169 (GstDataCopyFunction) _gst_event_copy);
171 GST_EVENT_TYPE (event) = type;
172 GST_EVENT_TIMESTAMP (event) = G_GINT64_CONSTANT (0);
173 GST_EVENT_SRC (event) = NULL;
179 * gst_event_new_seek:
180 * @type: The type of the seek event
181 * @offset: The offset of the seek
183 * Allocate a new seek event with the given parameters.
185 * Returns: A new seek event.
188 gst_event_new_seek (GstSeekType type, gint64 offset)
192 event = gst_event_new (GST_EVENT_SEEK);
194 GST_EVENT_SEEK_TYPE (event) = type;
195 GST_EVENT_SEEK_OFFSET (event) = offset;
196 GST_EVENT_SEEK_ENDOFFSET (event) = -1;
202 * gst_event_new_discontinuous_valist:
203 * @new_media: A flag indicating a new media type starts
204 * @format1: The format of the discont value
205 * @var_args: more discont values and formats
207 * Allocate a new discontinuous event with the given format/value pairs. Note
208 * that the values are of type gint64 - you may not use simple integers such
209 * as "0" when calling this function, always cast them like "(gint64) 0".
210 * Terminate the list with #GST_FORMAT_UNDEFINED.
212 * Returns: A new discontinuous event.
215 gst_event_new_discontinuous_valist (gboolean new_media, GstFormat format1, va_list var_args)
220 event = gst_event_new (GST_EVENT_DISCONTINUOUS);
221 GST_EVENT_DISCONT_NEW_MEDIA (event) = new_media;
223 while (format1 != GST_FORMAT_UNDEFINED && count < 8) {
225 GST_EVENT_DISCONT_OFFSET (event, count).format = format1 & GST_SEEK_FORMAT_MASK;
226 GST_EVENT_DISCONT_OFFSET (event, count).value = va_arg (var_args, gint64);
228 format1 = va_arg (var_args, GstFormat);
233 GST_EVENT_DISCONT_OFFSET_LEN (event) = count;
239 * gst_event_new_discontinuous:
240 * @new_media: A flag indicating a new media type starts
241 * @format1: The format of the discont value
242 * @...: more discont values and formats
244 * Allocate a new discontinuous event with the given format/value pairs. Note
245 * that the values are of type gint64 - you may not use simple integers such
246 * as "0" when calling this function, always cast them like "(gint64) 0".
247 * Terminate the list with #GST_FORMAT_UNDEFINED.
249 * Returns: A new discontinuous event.
252 gst_event_new_discontinuous (gboolean new_media, GstFormat format1, ...)
257 va_start (var_args, format1);
259 event = gst_event_new_discontinuous_valist (new_media, format1, var_args);
267 * gst_event_discont_get_value:
268 * @event: The event to query
269 * @format: The format of the discont value
270 * @value: A pointer to the value
272 * Get the value for the given format in the dicont event.
274 * Returns: TRUE if the discont event caries the specified format/value pair.
277 gst_event_discont_get_value (GstEvent *event, GstFormat format, gint64 *value)
281 g_return_val_if_fail (event != NULL, FALSE);
282 g_return_val_if_fail (value != NULL, FALSE);
284 n = GST_EVENT_DISCONT_OFFSET_LEN (event);
286 for (i = 0; i < n; i++) {
287 if (GST_EVENT_DISCONT_OFFSET(event,i).format == format) {
288 *value = GST_EVENT_DISCONT_OFFSET(event,i).value;
298 * gst_event_new_size:
299 * @format: The format of the size value
300 * @value: The value of the size event
302 * Create a new size event with the given values.
304 * Returns: The new size event.
307 gst_event_new_size (GstFormat format, gint64 value)
311 event = gst_event_new (GST_EVENT_SIZE);
313 GST_EVENT_SIZE_FORMAT (event) = format;
314 GST_EVENT_SIZE_VALUE (event) = value;
321 * gst_event_new_segment_seek:
322 * @type: The type of the seek event
323 * @start: The start offset of the seek
324 * @stop: The stop offset of the seek
326 * Allocate a new segment seek event with the given parameters.
328 * Returns: A new segment seek event.
331 gst_event_new_segment_seek (GstSeekType type, gint64 start, gint64 stop)
335 g_return_val_if_fail (start < stop, NULL);
337 event = gst_event_new (GST_EVENT_SEEK_SEGMENT);
339 GST_EVENT_SEEK_TYPE (event) = type;
340 GST_EVENT_SEEK_OFFSET (event) = start;
341 GST_EVENT_SEEK_ENDOFFSET (event) = stop;