2001-10-17 10:21:27 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wim.taymans@chello.be>
|
|
|
|
*
|
|
|
|
* gstevent.h: Header for GstEvent subsystem
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2002-04-04 19:28:23 +00:00
|
|
|
#include <string.h> /* memcpy */
|
2001-10-17 10:21:27 +00:00
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
#include "gstinfo.h"
|
|
|
|
#include "gstdata_private.h"
|
|
|
|
#include "gstevent.h"
|
|
|
|
#include "gstlog.h"
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
/* #define MEMPROF */
|
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
GType _gst_event_type;
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
static gint _gst_event_live;
|
2001-10-17 10:21:27 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_gst_event_initialize (void)
|
|
|
|
{
|
2001-12-14 22:59:21 +00:00
|
|
|
/* register the type */
|
2002-07-08 19:22:02 +00:00
|
|
|
_gst_event_type = g_boxed_type_register_static ("GstEvent",
|
|
|
|
(GBoxedCopyFunc) gst_data_ref,
|
|
|
|
(GBoxedFreeFunc) gst_data_unref);
|
|
|
|
_gst_event_live = 0;
|
2001-10-17 10:21:27 +00:00
|
|
|
}
|
|
|
|
|
2001-10-21 18:00:31 +00:00
|
|
|
/**
|
2002-07-13 23:12:22 +00:00
|
|
|
* gst_event_print_stats:
|
2001-10-21 18:00:31 +00:00
|
|
|
*
|
2002-07-13 23:12:22 +00:00
|
|
|
* Logs statistics about live events (using g_log).
|
2001-10-21 18:00:31 +00:00
|
|
|
*/
|
2002-07-08 19:22:02 +00:00
|
|
|
void
|
|
|
|
gst_event_print_stats (void)
|
2001-10-17 10:21:27 +00:00
|
|
|
{
|
2002-07-08 19:22:02 +00:00
|
|
|
g_log (g_log_domain_gstreamer, G_LOG_LEVEL_INFO,
|
|
|
|
"%d live event(s)", _gst_event_live);
|
2001-10-17 10:21:27 +00:00
|
|
|
}
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
|
|
|
|
static GstEvent*
|
|
|
|
_gst_event_copy (GstEvent *event)
|
2002-02-23 13:57:09 +00:00
|
|
|
{
|
|
|
|
GstEvent *copy;
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
copy = g_new0(GstEvent, 1);
|
2002-07-08 19:22:02 +00:00
|
|
|
_gst_event_live++;
|
2002-02-23 13:57:09 +00:00
|
|
|
|
|
|
|
memcpy (copy, event, sizeof (GstEvent));
|
|
|
|
|
|
|
|
/* FIXME copy/ref additional fields */
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
static void
|
|
|
|
_gst_event_free (GstEvent* event)
|
2001-10-17 10:21:27 +00:00
|
|
|
{
|
2001-12-23 14:50:44 +00:00
|
|
|
GST_INFO (GST_CAT_EVENT, "freeing event %p", event);
|
|
|
|
|
2001-12-18 19:03:07 +00:00
|
|
|
if (GST_EVENT_SRC (event)) {
|
|
|
|
gst_object_unref (GST_EVENT_SRC (event));
|
|
|
|
}
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2002-07-08 19:22:02 +00:00
|
|
|
_GST_DATA_DISPOSE (GST_DATA (event));
|
|
|
|
_gst_event_live--;
|
2002-05-26 21:54:27 +00:00
|
|
|
g_free (event);
|
2002-07-08 19:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_event_new:
|
|
|
|
* @type: The type of the new event
|
|
|
|
*
|
|
|
|
* Allocate a new event of the given type.
|
|
|
|
*
|
|
|
|
* Returns: A new event.
|
|
|
|
*/
|
|
|
|
GstEvent*
|
|
|
|
gst_event_new (GstEventType type)
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
event = g_new0(GstEvent, 1);
|
|
|
|
_gst_event_live++;
|
|
|
|
GST_INFO (GST_CAT_EVENT, "creating new event %p", event);
|
|
|
|
|
|
|
|
_GST_DATA_INIT (GST_DATA (event),
|
|
|
|
_gst_event_type,
|
|
|
|
0,
|
|
|
|
(GstDataFreeFunction) _gst_event_free,
|
|
|
|
(GstDataCopyFunction) _gst_event_copy);
|
|
|
|
|
|
|
|
GST_EVENT_TYPE (event) = type;
|
|
|
|
GST_EVENT_TIMESTAMP (event) = 0LL;
|
|
|
|
GST_EVENT_SRC (event) = NULL;
|
|
|
|
|
|
|
|
return event;
|
2001-10-17 10:21:27 +00:00
|
|
|
}
|
|
|
|
|
2001-10-21 18:00:31 +00:00
|
|
|
/**
|
|
|
|
* gst_event_new_seek:
|
|
|
|
* @type: The type of the seek event
|
|
|
|
* @offset: The offset of the seek
|
|
|
|
*
|
|
|
|
* Allocate a new seek event with the given parameters.
|
|
|
|
*
|
|
|
|
* Returns: A new seek event.
|
|
|
|
*/
|
2001-10-17 10:21:27 +00:00
|
|
|
GstEvent*
|
2002-05-26 21:54:27 +00:00
|
|
|
gst_event_new_seek (GstSeekType type, gint64 offset)
|
2001-10-17 10:21:27 +00:00
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
event = gst_event_new (GST_EVENT_SEEK);
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
GST_EVENT_SEEK_TYPE (event) = type;
|
|
|
|
GST_EVENT_SEEK_OFFSET (event) = offset;
|
2002-10-31 18:41:18 +00:00
|
|
|
GST_EVENT_SEEK_ENDOFFSET (event) = -1;
|
2001-10-17 10:21:27 +00:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
2001-12-18 19:03:07 +00:00
|
|
|
|
2002-06-12 22:26:36 +00:00
|
|
|
/**
|
|
|
|
* gst_event_new_discontinuous:
|
|
|
|
* @new_media: A flag indicating a new media type starts
|
|
|
|
* @format1: The format of the discont value
|
|
|
|
* @...: more discont values and formats
|
|
|
|
*
|
|
|
|
* Allocate a new discontinuous event with the geven format/value pairs.
|
|
|
|
*
|
|
|
|
* Returns: A new discontinuous event.
|
|
|
|
*/
|
2002-05-26 21:54:27 +00:00
|
|
|
GstEvent*
|
2002-07-28 01:06:16 +00:00
|
|
|
gst_event_new_discontinuous (gboolean new_media, GstFormat format1, ...)
|
2002-05-26 21:54:27 +00:00
|
|
|
{
|
|
|
|
va_list var_args;
|
|
|
|
GstEvent *event;
|
|
|
|
gint count = 0;
|
|
|
|
|
|
|
|
event = gst_event_new (GST_EVENT_DISCONTINUOUS);
|
2002-06-12 22:26:36 +00:00
|
|
|
GST_EVENT_DISCONT_NEW_MEDIA (event) = new_media;
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
va_start (var_args, format1);
|
|
|
|
|
|
|
|
while (format1) {
|
|
|
|
|
|
|
|
GST_EVENT_DISCONT_OFFSET (event, count).format = format1 & GST_SEEK_FORMAT_MASK;
|
|
|
|
GST_EVENT_DISCONT_OFFSET (event, count).value = va_arg (var_args, gint64);
|
|
|
|
|
|
|
|
format1 = va_arg (var_args, GstSeekType);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
va_end (var_args);
|
|
|
|
|
|
|
|
GST_EVENT_DISCONT_OFFSET_LEN (event) = count;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2002-06-12 22:26:36 +00:00
|
|
|
/**
|
|
|
|
* gst_event_discont_get_value:
|
|
|
|
* @event: The event to query
|
|
|
|
* @format: The format of the discont value
|
|
|
|
* @value: A pointer to the value
|
|
|
|
*
|
|
|
|
* Get the value for the given format in the dicont event.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the discont event caries the specified format/value pair.
|
|
|
|
*/
|
2002-05-26 21:54:27 +00:00
|
|
|
gboolean
|
2002-06-12 22:26:36 +00:00
|
|
|
gst_event_discont_get_value (GstEvent *event, GstFormat format, gint64 *value)
|
2002-05-26 21:54:27 +00:00
|
|
|
{
|
|
|
|
gint i, n;
|
|
|
|
|
2002-11-22 23:15:14 +00:00
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
2002-05-26 21:54:27 +00:00
|
|
|
|
|
|
|
n = GST_EVENT_DISCONT_OFFSET_LEN (event);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2002-06-12 22:26:36 +00:00
|
|
|
if (GST_EVENT_DISCONT_OFFSET(event,i).format == format) {
|
2002-05-26 21:54:27 +00:00
|
|
|
*value = GST_EVENT_DISCONT_OFFSET(event,i).value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-08 19:22:02 +00:00
|
|
|
/**
|
|
|
|
* gst_event_new_size:
|
|
|
|
* @format: The format of the size value
|
|
|
|
* @value: The value of the size event
|
|
|
|
*
|
|
|
|
* Create a new size event with the given values.
|
|
|
|
*
|
|
|
|
* Returns: The new size event.
|
|
|
|
*/
|
2002-06-13 22:27:40 +00:00
|
|
|
GstEvent*
|
|
|
|
gst_event_new_size (GstFormat format, gint64 value)
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
event = gst_event_new (GST_EVENT_SIZE);
|
2002-07-08 19:22:02 +00:00
|
|
|
|
2002-06-13 22:27:40 +00:00
|
|
|
GST_EVENT_SIZE_FORMAT (event) = format;
|
|
|
|
GST_EVENT_SIZE_VALUE (event) = value;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:54:27 +00:00
|
|
|
|
2002-07-13 23:12:22 +00:00
|
|
|
/**
|
|
|
|
* gst_event_new_segment_seek:
|
|
|
|
* @type: The type of the seek event
|
|
|
|
* @start: The start offset of the seek
|
|
|
|
* @stop: The stop offset of the seek
|
|
|
|
*
|
|
|
|
* Allocate a new segment seek event with the given parameters.
|
|
|
|
*
|
|
|
|
* Returns: A new segment seek event.
|
|
|
|
*/
|
|
|
|
GstEvent*
|
|
|
|
gst_event_new_segment_seek (GstSeekType type, gint64 start, gint64 stop)
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
|
2002-10-31 18:41:18 +00:00
|
|
|
g_return_val_if_fail (start < stop, NULL);
|
|
|
|
|
2002-07-13 23:12:22 +00:00
|
|
|
event = gst_event_new (GST_EVENT_SEEK_SEGMENT);
|
|
|
|
|
|
|
|
GST_EVENT_SEEK_TYPE (event) = type;
|
|
|
|
GST_EVENT_SEEK_OFFSET (event) = start;
|
|
|
|
GST_EVENT_SEEK_ENDOFFSET (event) = stop;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
2001-12-18 19:03:07 +00:00
|
|
|
|