gstreamer/gst/gstmessage.c
Andy Wingo 1a5201826c gst/gstmessage.h (GstMessageType): Turned into flags. Added
Original commit message from CVS:
2005-02-21  Andy Wingo  <wingo@pobox.com>

* gst/gstmessage.h (GstMessageType): Turned into flags. Added
GST_MESSAGE_ANY as an OR of all flags.
(GST_MESSAGE_PARSE_STATE_CHANGED): New terrible macro. Will be
made into a function soon.
(GstMessage): Add a state_changed structure to the union. The
union will die soon in favor of a single GstStructure tho.
(gst_message_new_state_changed): New API.

* gst/gstmessage.c (gst_message_new_state_changed): New API.

* tools/gst-launch.c (check_intr): Set the state of the pipeline
to PAUSED here; the poll will catch the state change.
(event_loop): New function, polls the pipeline bus for events. Can
block until eos/error/state change, or just handle the pending
events.
(main): Changed to use event_loop instead of running a main loop.

* gst/gstbus.h (gst_bus_poll): Added.
(gst_bus_peek): Return non-const; the message is refcounted
anyway.

* gst/gstbus.c (gst_bus_init): Replace the GAsyncQueue with a
GQueue+mutex to allow for _peek. (The wake-up functionality
provided by GAsyncQueue is already done by our socketpair.) All
queue users changed to lock, operate, and unlock.
(gst_bus_post): Check the retval of write(2) and handle errno.
(gst_bus_peek): Implemented.
(gst_bus_pop, gst_bus_peek, bus_callback): Because the socketpair
is used to wake up the GSource, read off the character in the
GSource handler and not in pop/peek. This is because a peek will
require a pop in the future, and you can't read off the char
twice. Deal with errno in the read.
(bus_callback): Interpret the handler return value as whether or
not to pop the message from the bus.
(poll_handler, poll_timeout, gst_bus_poll): New API. gst_bus_poll
is meant to replace the while(gst_bin_iterate()) idiom.
2005-02-21 11:54:55 +00:00

271 lines
6.1 KiB
C

/* GStreamer
* Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
*
* gstmessage.c: GstMessage 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.
*/
#include <string.h> /* memcpy */
#include "gst_private.h"
#include "gstdata_private.h"
#include "gstinfo.h"
#include "gstmemchunk.h"
#include "gstmessage.h"
#include "gsttag.h"
#ifndef GST_DISABLE_TRACE
/* #define GST_WITH_ALLOC_TRACE */
#include "gsttrace.h"
static GstAllocTrace *_message_trace;
#endif
static GstMemChunk *chunk;
/* #define MEMPROF */
GType _gst_message_type;
void
_gst_message_initialize (void)
{
/* register the type */
_gst_message_type = g_boxed_type_register_static ("GstMessage",
(GBoxedCopyFunc) gst_data_copy, (GBoxedFreeFunc) gst_data_unref);
#ifndef GST_DISABLE_TRACE
_message_trace = gst_alloc_trace_register (GST_MESSAGE_TRACE_NAME);
#endif
chunk = gst_mem_chunk_new ("GstMessageChunk", sizeof (GstMessage),
sizeof (GstMessage) * 50, 0);
}
static GstMessage *
_gst_message_copy (GstMessage * message)
{
GstMessage *copy;
GST_CAT_INFO (GST_CAT_MESSAGE, "copy message %p", message);
copy = gst_mem_chunk_alloc (chunk);
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_new (_message_trace, copy);
#endif
memcpy (copy, message, sizeof (GstMessage));
if (GST_MESSAGE_SRC (copy)) {
gst_object_ref (GST_MESSAGE_SRC (copy));
}
/* FIXME copy/ref additional fields */
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_TAG:
copy->message_data.structure.structure =
gst_tag_list_copy ((GstTagList *) message->message_data.structure.
structure);
break;
default:
break;
}
return copy;
}
static void
_gst_message_free (GstMessage * message)
{
GST_CAT_INFO (GST_CAT_MESSAGE, "freeing message %p", message);
if (GST_MESSAGE_SRC (message)) {
gst_object_unref (GST_MESSAGE_SRC (message));
}
if (message->lock) {
GST_MESSAGE_LOCK (message);
GST_MESSAGE_SIGNAL (message);
GST_MESSAGE_UNLOCK (message);
}
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:
case GST_MESSAGE_WARNING:
g_error_free (GST_MESSAGE_ERROR_GERROR (message));
g_free (GST_MESSAGE_ERROR_DEBUG (message));
break;
case GST_MESSAGE_TAG:
if (GST_IS_TAG_LIST (message->message_data.tag.list)) {
gst_tag_list_free (message->message_data.tag.list);
} else {
g_warning ("tag message %p didn't contain a valid tag list!", message);
GST_ERROR ("tag message %p didn't contain a valid tag list!", message);
}
break;
default:
break;
}
_GST_DATA_DISPOSE (GST_DATA (message));
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_free (_message_trace, message);
#endif
gst_mem_chunk_free (chunk, message);
}
GType
gst_message_get_type (void)
{
return _gst_message_type;
}
/**
* gst_message_new:
* @type: The type of the new message
*
* Allocate a new message of the given type.
*
* Returns: A new message.
*
* MT safe.
*/
GstMessage *
gst_message_new (GstMessageType type, GstObject * src)
{
GstMessage *message;
message = gst_mem_chunk_alloc0 (chunk);
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_new (_message_trace, message);
#endif
GST_CAT_INFO (GST_CAT_MESSAGE, "creating new message %p %d", message, type);
_GST_DATA_INIT (GST_DATA (message),
_gst_message_type,
0,
(GstDataFreeFunction) _gst_message_free,
(GstDataCopyFunction) _gst_message_copy);
GST_MESSAGE_TYPE (message) = type;
GST_MESSAGE_TIMESTAMP (message) = G_GINT64_CONSTANT (0);
gst_object_ref (src);
GST_MESSAGE_SRC (message) = src;
return message;
}
/**
* gst_message_new_eos:
*
* Create a new eos message.
*
* Returns: The new eos message.
*
* MT safe.
*/
GstMessage *
gst_message_new_eos (GstObject * src)
{
GstMessage *message;
message = gst_message_new (GST_MESSAGE_EOS, src);
return message;
}
/**
* gst_message_new_error:
*
* Create a new error message.
*
* Returns: The new error message.
*
* MT safe.
*/
GstMessage *
gst_message_new_error (GstObject * src, GError * error, gchar * debug)
{
GstMessage *message;
message = gst_message_new (GST_MESSAGE_ERROR, src);
GST_MESSAGE_ERROR_GERROR (message) = error;
GST_MESSAGE_ERROR_DEBUG (message) = debug;
return message;
}
/**
* gst_message_new_warning:
*
* Create a new warning message.
*
* Returns: The new warning message.
*
* MT safe.
*/
GstMessage *
gst_message_new_warning (GstObject * src, GError * error, gchar * debug)
{
GstMessage *message;
message = gst_message_new (GST_MESSAGE_WARNING, src);
GST_MESSAGE_WARNING_GERROR (message) = error;
GST_MESSAGE_WARNING_DEBUG (message) = debug;
return message;
}
/**
* gst_message_new_tag:
*
* Create a new tag message.
*
* Returns: The new tag message.
*
* MT safe.
*/
GstMessage *
gst_message_new_tag (GstObject * src, GstTagList * tag_list)
{
GstMessage *message;
message = gst_message_new (GST_MESSAGE_TAG, src);
GST_MESSAGE_TAG_LIST (message) = tag_list;
return message;
}
/**
* gst_message_new_state_change:
*
* Create a state change message.
*
* Returns: The new state change message.
*
* MT safe.
*/
GstMessage *
gst_message_new_state_changed (GstObject * src, GstElementState old,
GstElementState new)
{
GstMessage *message;
message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src);
message->message_data.state_changed.old = old;
message->message_data.state_changed.new = new;
return message;
}