2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
4 * gstmessage.c: GstMessage subsystem
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * @short_description: Lightweight objects to signal the application of
26 * @see_also: #GstBus, #GstMiniObject, #GstElement
28 * Messages are implemented as a subclass of #GstMiniObject with a generic
29 * #GstStructure as the content. This allows for writing custom messages without
30 * requiring an API change while allowing a wide range of different types
33 * Messages are posted by objects in the pipeline and are passed to the
34 * application using the #GstBus.
36 * The basic use pattern of posting a message on a #GstBus is as follows:
39 * <title>Posting a #GstMessage</title>
41 * gst_bus_post (bus, gst_message_new_eos());
45 * A #GstElement usually posts messages on the bus provided by the parent
46 * container using gst_element_post_message().
48 * Last reviewed on 2005-11-09 (0.9.4)
52 #include "gst_private.h"
53 #include <string.h> /* memcpy */
55 #include "gstenumtypes.h"
57 #include "gstmessage.h"
58 #include "gsttaglist.h"
63 #define GST_MESSAGE_SEQNUM(e) ((GstMessage*)e)->abidata.ABI.seqnum
65 static void gst_message_finalize (GstMessage * message);
66 static GstMessage *_gst_message_copy (GstMessage * message);
68 static GstMiniObjectClass *parent_class = NULL;
71 _gst_message_initialize (void)
73 GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
75 /* the GstMiniObject types need to be class_ref'd once before it can be
76 * done from multiple threads;
77 * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
78 g_type_class_ref (gst_message_get_type ());
88 static GstMessageQuarks message_quarks[] = {
89 {GST_MESSAGE_UNKNOWN, "unknown", 0},
90 {GST_MESSAGE_EOS, "eos", 0},
91 {GST_MESSAGE_ERROR, "error", 0},
92 {GST_MESSAGE_WARNING, "warning", 0},
93 {GST_MESSAGE_INFO, "info", 0},
94 {GST_MESSAGE_TAG, "tag", 0},
95 {GST_MESSAGE_BUFFERING, "buffering", 0},
96 {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
97 {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
98 {GST_MESSAGE_STEP_DONE, "step-done", 0},
99 {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
100 {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
101 {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
102 {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
103 {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
104 {GST_MESSAGE_APPLICATION, "application", 0},
105 {GST_MESSAGE_ELEMENT, "element", 0},
106 {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
107 {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
108 {GST_MESSAGE_DURATION, "duration", 0},
109 {GST_MESSAGE_LATENCY, "latency", 0},
110 {GST_MESSAGE_ASYNC_START, "async-start", 0},
111 {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
112 {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
117 * gst_message_type_get_name:
118 * @type: the message type
120 * Get a printable name for the given message type. Do not modify or free.
122 * Returns: a reference to the static name of the message.
125 gst_message_type_get_name (GstMessageType type)
129 for (i = 0; message_quarks[i].name; i++) {
130 if (type == message_quarks[i].type)
131 return message_quarks[i].name;
137 * gst_message_type_to_quark:
138 * @type: the message type
140 * Get the unique quark for the given message type.
142 * Returns: the quark associated with the message type
145 gst_message_type_to_quark (GstMessageType type)
149 for (i = 0; message_quarks[i].name; i++) {
150 if (type == message_quarks[i].type)
151 return message_quarks[i].quark;
160 for (i = 0; message_quarks[i].name; i++) { \
161 message_quarks[i].quark = \
162 g_quark_from_static_string (message_quarks[i].name); \
166 G_DEFINE_TYPE_WITH_CODE (GstMessage, gst_message, GST_TYPE_MINI_OBJECT,
170 gst_message_class_init (GstMessageClass * klass)
172 parent_class = g_type_class_peek_parent (klass);
174 klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_message_copy;
175 klass->mini_object_class.finalize =
176 (GstMiniObjectFinalizeFunction) gst_message_finalize;
180 gst_message_init (GstMessage * message)
182 GST_CAT_LOG (GST_CAT_MESSAGE, "new message %p", message);
183 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
187 gst_message_finalize (GstMessage * message)
189 g_return_if_fail (message != NULL);
191 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p", message);
193 if (GST_MESSAGE_SRC (message)) {
194 gst_object_unref (GST_MESSAGE_SRC (message));
195 GST_MESSAGE_SRC (message) = NULL;
199 GST_MESSAGE_LOCK (message);
200 GST_MESSAGE_SIGNAL (message);
201 GST_MESSAGE_UNLOCK (message);
204 if (message->structure) {
205 gst_structure_set_parent_refcount (message->structure, NULL);
206 gst_structure_free (message->structure);
209 GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (message));
213 _gst_message_copy (GstMessage * message)
217 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p", message);
219 copy = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
221 /* FIXME, need to copy relevant data from the miniobject. */
222 //memcpy (copy, message, sizeof (GstMessage));
224 GST_MESSAGE_GET_LOCK (copy) = GST_MESSAGE_GET_LOCK (message);
225 GST_MESSAGE_COND (copy) = GST_MESSAGE_COND (message);
226 GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
227 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
228 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
230 if (GST_MESSAGE_SRC (message)) {
231 GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
234 if (message->structure) {
235 copy->structure = gst_structure_copy (message->structure);
236 gst_structure_set_parent_refcount (copy->structure,
237 ©->mini_object.refcount);
244 * gst_message_new_custom:
245 * @type: The #GstMessageType to distinguish messages
246 * @src: The object originating the message.
247 * @structure: The structure for the message. The message will take ownership of
250 * Create a new custom-typed message. This can be used for anything not
251 * handled by other message-specific functions to pass a message to the
252 * app. The structure field can be NULL.
254 * Returns: The new message.
259 gst_message_new_custom (GstMessageType type, GstObject * src,
260 GstStructure * structure)
264 message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
266 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
267 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
268 gst_message_type_get_name (type));
270 message->type = type;
273 gst_object_ref (src);
277 gst_structure_set_parent_refcount (structure,
278 &message->mini_object.refcount);
280 message->structure = structure;
282 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
288 * gst_message_get_seqnum:
289 * @message: A #GstMessage.
291 * Retrieve the sequence number of a message.
293 * Messages have ever-incrementing sequence numbers, which may also be set
294 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
295 * to indicate that a message corresponds to some other set of messages or
296 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
297 * is considered good practice to make this correspondence when possible, though
298 * it is not required.
300 * Note that events and messages share the same sequence number incrementor;
301 * two events or messages will never not have the same sequence number unless
302 * that correspondence was made explicitly.
304 * Returns: The message's sequence number.
311 gst_message_get_seqnum (GstMessage * message)
313 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
315 return GST_MESSAGE_SEQNUM (message);
319 * gst_message_set_seqnum:
320 * @message: A #GstMessage.
321 * @seqnum: A sequence number.
323 * Set the sequence number of a message.
325 * This function might be called by the creator of a message to indicate that
326 * the message relates to other messages or events. See gst_message_get_seqnum()
327 * for more information.
334 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
336 g_return_if_fail (GST_IS_MESSAGE (message));
338 GST_MESSAGE_SEQNUM (message) = seqnum;
342 * gst_message_new_eos:
343 * @src: The object originating the message.
345 * Create a new eos message. This message is generated and posted in
346 * the sink elements of a GstBin. The bin will only forward the EOS
347 * message to the application if all sinks have posted an EOS message.
349 * Returns: The new eos message.
354 gst_message_new_eos (GstObject * src)
358 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
364 * gst_message_new_error:
365 * @src: The object originating the message.
366 * @error: The GError for this message.
367 * @debug: A debugging string.
369 * Create a new error message. The message will copy @error and
370 * @debug. This message is posted by element when a fatal event
371 * occured. The pipeline will probably (partially) stop. The application
372 * receiving this message should stop the pipeline.
374 * Returns: The new error message.
379 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
382 GstStructure *structure;
384 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_ERROR));
385 gst_structure_id_set (structure,
386 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
387 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
388 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
394 * gst_message_new_warning:
395 * @src: The object originating the message.
396 * @error: The GError for this message.
397 * @debug: A debugging string.
399 * Create a new warning message. The message will make copies of @error and
402 * Returns: The new warning message.
407 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
410 GstStructure *structure;
412 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_WARNING));
413 gst_structure_id_set (structure,
414 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
415 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
416 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
422 * gst_message_new_info:
423 * @src: The object originating the message.
424 * @error: The GError for this message.
425 * @debug: A debugging string.
427 * Create a new info message. The message will make copies of @error and
432 * Returns: The new info message.
437 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
440 GstStructure *structure;
442 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_INFO));
443 gst_structure_id_set (structure, GST_QUARK (GERROR), GST_TYPE_G_ERROR,
444 error, GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
445 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
451 * gst_message_new_tag:
452 * @src: The object originating the message.
453 * @tag_list: The tag list for the message.
455 * Create a new tag message. The message will take ownership of the tag list.
456 * The message is posted by elements that discovered a new taglist.
458 * Returns: The new tag message.
463 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
467 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
470 gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
476 * gst_message_new_tag_full:
477 * @src: The object originating the message.
478 * @pad: The originating pad for the tag.
479 * @tag_list: The tag list for the message.
481 * Create a new tag message. The message will take ownership of the tag list.
482 * The message is posted by elements that discovered a new taglist.
484 * Returns: The new tag message.
491 gst_message_new_tag_full (GstObject * src, GstPad * pad, GstTagList * tag_list)
496 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
497 g_return_val_if_fail (pad == NULL || GST_IS_PAD (pad), NULL);
499 s = (GstStructure *) tag_list;
501 gst_structure_set (s, "source-pad", GST_TYPE_PAD, pad, NULL);
503 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
509 * gst_message_new_buffering:
510 * @src: The object originating the message.
511 * @percent: The buffering percent
513 * Create a new buffering message. This message can be posted by an element that
514 * needs to buffer data before it can continue processing. @percent should be a
515 * value between 0 and 100. A value of 100 means that the buffering completed.
517 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
518 * @percent is 100, the application can set the pipeline (back) to PLAYING.
519 * The application must be prepared to receive BUFFERING messages in the
520 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
521 * message with @percent set to 100, which can happen after the pipeline
522 * completed prerolling.
526 * Returns: The new buffering message.
531 gst_message_new_buffering (GstObject * src, gint percent)
534 GstStructure *structure;
536 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
538 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_BUFFERING));
539 gst_structure_id_set (structure,
540 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
541 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
542 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
543 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
544 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
545 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
546 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
552 * gst_message_new_state_changed:
553 * @src: the object originating the message
554 * @oldstate: the previous state
555 * @newstate: the new (current) state
556 * @pending: the pending (target) state
558 * Create a state change message. This message is posted whenever an element
561 * Returns: The new state change message.
566 gst_message_new_state_changed (GstObject * src,
567 GstState oldstate, GstState newstate, GstState pending)
570 GstStructure *structure;
572 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_STATE));
573 gst_structure_id_set (structure,
574 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
575 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
576 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
577 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
583 * gst_message_new_state_dirty:
584 * @src: the object originating the message
586 * Create a state dirty message. This message is posted whenever an element
587 * changed its state asynchronously and is used internally to update the
588 * states of container objects.
590 * Returns: The new state dirty message.
595 gst_message_new_state_dirty (GstObject * src)
599 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
605 * gst_message_new_clock_provide:
606 * @src: The object originating the message.
607 * @clock: The clock it provides
608 * @ready: TRUE if the sender can provide a clock
610 * Create a clock provide message. This message is posted whenever an
611 * element is ready to provide a clock or lost its ability to provide
612 * a clock (maybe because it paused or became EOS).
614 * This message is mainly used internally to manage the clock
617 * Returns: The new provide clock message.
622 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
626 GstStructure *structure;
628 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_CLOCK_PROVIDE));
629 gst_structure_id_set (structure,
630 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
631 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
632 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
638 * gst_message_new_clock_lost:
639 * @src: The object originating the message.
640 * @clock: the clock that was lost
642 * Create a clock lost message. This message is posted whenever the
643 * clock is not valid anymore.
645 * If this message is posted by the pipeline, the pipeline will
646 * select a new clock again when it goes to PLAYING. It might therefore
647 * be needed to set the pipeline to PAUSED and PLAYING again.
649 * Returns: The new clock lost message.
654 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
657 GstStructure *structure;
659 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_CLOCK_LOST));
660 gst_structure_id_set (structure,
661 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
662 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
668 * gst_message_new_new_clock:
669 * @src: The object originating the message.
670 * @clock: the new selected clock
672 * Create a new clock message. This message is posted whenever the
673 * pipeline selectes a new clock for the pipeline.
675 * Returns: The new new clock message.
680 gst_message_new_new_clock (GstObject * src, GstClock * clock)
683 GstStructure *structure;
685 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_NEW_CLOCK));
686 gst_structure_id_set (structure,
687 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
688 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
694 * gst_message_new_structure_change:
695 * @src: The object originating the message.
696 * @type: The change type.
697 * @owner: The owner element of @src.
698 * @busy: Whether the structure change is busy.
700 * Create a new structure change message. This message is posted when the
701 * structure of a pipeline is in the process of being changed, for example
702 * when pads are linked or unlinked.
704 * @src should be the srcpad that unlinked or linked.
706 * Returns: The new structure change message.
713 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
714 GstElement * owner, gboolean busy)
717 GstStructure *structure;
719 g_return_val_if_fail (GST_IS_PAD (src), NULL);
720 g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SRC, NULL);
721 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
723 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_STRUCTURE_CHANGE));
724 gst_structure_id_set (structure,
725 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
726 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
727 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
729 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
736 * gst_message_new_segment_start:
737 * @src: The object originating the message.
738 * @format: The format of the position being played
739 * @position: The position of the segment being played
741 * Create a new segment message. This message is posted by elements that
742 * start playback of a segment as a result of a segment seek. This message
743 * is not received by the application but is used for maintenance reasons in
744 * container elements.
746 * Returns: The new segment start message.
751 gst_message_new_segment_start (GstObject * src, GstFormat format,
755 GstStructure *structure;
757 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_SEGMENT_START));
758 gst_structure_id_set (structure,
759 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
760 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
761 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
767 * gst_message_new_segment_done:
768 * @src: The object originating the message.
769 * @format: The format of the position being done
770 * @position: The position of the segment being done
772 * Create a new segment done message. This message is posted by elements that
773 * finish playback of a segment as a result of a segment seek. This message
774 * is received by the application after all elements that posted a segment_start
775 * have posted the segment_done.
777 * Returns: The new segment done message.
782 gst_message_new_segment_done (GstObject * src, GstFormat format,
786 GstStructure *structure;
788 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_SEGMENT_DONE));
789 gst_structure_id_set (structure,
790 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
791 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
792 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
798 * gst_message_new_application:
799 * @src: The object originating the message.
800 * @structure: The structure for the message. The message will take ownership of
803 * Create a new application-typed message. GStreamer will never create these
804 * messages; they are a gift from us to you. Enjoy.
806 * Returns: The new application message.
811 gst_message_new_application (GstObject * src, GstStructure * structure)
813 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
817 * gst_message_new_element:
818 * @src: The object originating the message.
819 * @structure: The structure for the message. The message will take ownership of
822 * Create a new element-specific message. This is meant as a generic way of
823 * allowing one-way communication from an element to an application, for example
824 * "the firewire cable was unplugged". The format of the message should be
825 * documented in the element's documentation. The structure field can be NULL.
827 * Returns: The new element message.
832 gst_message_new_element (GstObject * src, GstStructure * structure)
834 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
838 * gst_message_new_duration:
839 * @src: The object originating the message.
840 * @format: The format of the duration
841 * @duration: The new duration
843 * Create a new duration message. This message is posted by elements that
844 * know the duration of a stream in a specific format. This message
845 * is received by bins and is used to calculate the total duration of a
846 * pipeline. Elements may post a duration message with a duration of
847 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
848 * cached duration should be discarded. The new duration can then be
849 * retrieved via a query.
851 * Returns: The new duration message.
856 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
859 GstStructure *structure;
861 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_DURATION));
862 gst_structure_id_set (structure,
863 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
864 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
865 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
871 * gst_message_new_async_start:
872 * @src: The object originating the message.
873 * @new_base_time: if a new base_time should be set on the element
875 * This message is posted by elements when they start an ASYNC state change.
876 * @new_base_time is set to TRUE when the element lost its state when it was
879 * Returns: The new async_start message.
886 gst_message_new_async_start (GstObject * src, gboolean new_base_time)
889 GstStructure *structure;
891 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_ASYNC_START));
892 gst_structure_id_set (structure,
893 GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
894 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
900 * gst_message_new_async_done:
901 * @src: The object originating the message.
903 * The message is posted when elements completed an ASYNC state change.
905 * Returns: The new async_done message.
912 gst_message_new_async_done (GstObject * src)
916 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
922 * gst_message_new_latency:
923 * @src: The object originating the message.
925 * This message can be posted by elements when their latency requirements have
928 * Returns: The new latency message.
935 gst_message_new_latency (GstObject * src)
939 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
945 * gst_message_new_request_state:
946 * @src: The object originating the message.
947 * @state: The new requested state
949 * This message can be posted by elements when they want to have their state
950 * changed. A typical use case would be an audio server that wants to pause the
951 * pipeline because a higher priority stream is being played.
953 * Returns: The new requst state message.
960 gst_message_new_request_state (GstObject * src, GstState state)
963 GstStructure *structure;
965 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_REQUEST_STATE));
966 gst_structure_id_set (structure,
967 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
968 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
974 * gst_message_get_structure:
975 * @message: The #GstMessage.
977 * Access the structure of the message.
979 * Returns: The structure of the message. The structure is still
980 * owned by the message, which means that you should not free it and
981 * that the pointer becomes invalid when you free the message.
986 gst_message_get_structure (GstMessage * message)
988 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
990 return message->structure;
994 * gst_message_parse_tag:
995 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
996 * @tag_list: Return location for the tag-list.
998 * Extracts the tag list from the GstMessage. The tag list returned in the
999 * output argument is a copy; the caller must free it when done.
1004 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1008 g_return_if_fail (GST_IS_MESSAGE (message));
1009 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1010 g_return_if_fail (tag_list != NULL);
1012 ret = gst_structure_copy (message->structure);
1013 gst_structure_remove_field (ret, "source-pad");
1015 *tag_list = (GstTagList *) ret;
1019 * gst_message_parse_tag_full:
1020 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1021 * @pad: Location where the originating pad is stored, unref after usage
1022 * @tag_list: Return location for the tag-list.
1024 * Extracts the tag list from the GstMessage. The tag list returned in the
1025 * output argument is a copy; the caller must free it when done.
1032 gst_message_parse_tag_full (GstMessage * message, GstPad ** pad,
1033 GstTagList ** tag_list)
1037 g_return_if_fail (GST_IS_MESSAGE (message));
1038 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1039 g_return_if_fail (tag_list != NULL);
1041 ret = gst_structure_copy (message->structure);
1043 if (gst_structure_has_field (ret, "source-pad") && pad) {
1046 v = gst_structure_get_value (ret, "source-pad");
1047 if (v && G_VALUE_HOLDS (v, GST_TYPE_PAD))
1048 *pad = g_value_dup_object (v);
1054 gst_structure_remove_field (ret, "source-pad");
1056 *tag_list = (GstTagList *) ret;
1060 * gst_message_parse_buffering:
1061 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1062 * @percent: Return location for the percent.
1064 * Extracts the buffering percent from the GstMessage. see also
1065 * gst_message_new_buffering().
1072 gst_message_parse_buffering (GstMessage * message, gint * percent)
1074 g_return_if_fail (GST_IS_MESSAGE (message));
1075 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1078 *percent = g_value_get_int (gst_structure_id_get_value (message->structure,
1079 GST_QUARK (BUFFER_PERCENT)));
1083 * gst_message_set_buffering_stats:
1084 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1085 * @mode: a buffering mode
1086 * @avg_in: the average input rate
1087 * @avg_out: the average output rate
1088 * @buffering_left: amount of buffering time left in milliseconds
1090 * Configures the buffering stats values in @message.
1095 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1096 gint avg_in, gint avg_out, gint64 buffering_left)
1098 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1100 gst_structure_id_set (message->structure,
1101 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1102 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1103 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1104 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1108 * gst_message_parse_buffering_stats:
1109 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1110 * @mode: a buffering mode
1111 * @avg_in: the average input rate
1112 * @avg_out: the average output rate
1113 * @buffering_left: amount of buffering time left in milliseconds.
1115 * Extracts the buffering stats values from @message.
1120 gst_message_parse_buffering_stats (GstMessage * message,
1121 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1122 gint64 * buffering_left)
1124 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1127 *mode = g_value_get_enum (gst_structure_id_get_value (message->structure,
1128 GST_QUARK (BUFFERING_MODE)));
1130 *avg_in = g_value_get_int (gst_structure_id_get_value (message->structure,
1131 GST_QUARK (AVG_IN_RATE)));
1133 *avg_out = g_value_get_int (gst_structure_id_get_value (message->structure,
1134 GST_QUARK (AVG_OUT_RATE)));
1137 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1138 GST_QUARK (BUFFERING_LEFT)));
1142 * gst_message_parse_state_changed:
1143 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1144 * @oldstate: the previous state, or NULL
1145 * @newstate: the new (current) state, or NULL
1146 * @pending: the pending (target) state, or NULL
1148 * Extracts the old and new states from the GstMessage.
1153 gst_message_parse_state_changed (GstMessage * message,
1154 GstState * oldstate, GstState * newstate, GstState * pending)
1156 g_return_if_fail (GST_IS_MESSAGE (message));
1157 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1161 g_value_get_enum (gst_structure_id_get_value (message->structure,
1162 GST_QUARK (OLD_STATE)));
1165 g_value_get_enum (gst_structure_id_get_value (message->structure,
1166 GST_QUARK (NEW_STATE)));
1168 *pending = g_value_get_enum (gst_structure_id_get_value (message->structure,
1169 GST_QUARK (PENDING_STATE)));
1173 * gst_message_parse_clock_provide:
1174 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1175 * @clock: A pointer to hold a clock object.
1176 * @ready: A pointer to hold the ready flag.
1178 * Extracts the clock and ready flag from the GstMessage.
1179 * The clock object returned remains valid until the message is freed.
1184 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1187 const GValue *clock_gvalue;
1189 g_return_if_fail (GST_IS_MESSAGE (message));
1190 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1193 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1194 g_return_if_fail (clock_gvalue != NULL);
1195 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1199 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1200 GST_QUARK (READY)));
1202 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1206 * gst_message_parse_clock_lost:
1207 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1208 * @clock: A pointer to hold the lost clock
1210 * Extracts the lost clock from the GstMessage.
1211 * The clock object returned remains valid until the message is freed.
1216 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1218 const GValue *clock_gvalue;
1220 g_return_if_fail (GST_IS_MESSAGE (message));
1221 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1224 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1225 g_return_if_fail (clock_gvalue != NULL);
1226 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1229 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1233 * gst_message_parse_new_clock:
1234 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1235 * @clock: A pointer to hold the selected new clock
1237 * Extracts the new clock from the GstMessage.
1238 * The clock object returned remains valid until the message is freed.
1243 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1245 const GValue *clock_gvalue;
1247 g_return_if_fail (GST_IS_MESSAGE (message));
1248 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1251 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1252 g_return_if_fail (clock_gvalue != NULL);
1253 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1256 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1260 * gst_message_parse_structure_change:
1261 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1262 * @type: A pointer to hold the change type
1263 * @owner: The owner element of the message source
1264 * @busy: A pointer to hold whether the change is in progress or has been
1267 * Extracts the change type and completion status from the GstMessage.
1274 gst_message_parse_structure_change (GstMessage * message,
1275 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1277 const GValue *owner_gvalue;
1279 g_return_if_fail (GST_IS_MESSAGE (message));
1280 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1283 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1284 g_return_if_fail (owner_gvalue != NULL);
1285 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1288 *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1291 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1294 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1299 * gst_message_parse_error:
1300 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1301 * @gerror: Location for the GError
1302 * @debug: Location for the debug message, or NULL
1304 * Extracts the GError and debug string from the GstMessage. The values returned
1305 * in the output arguments are copies; the caller must free them when done.
1310 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1312 const GValue *error_gvalue;
1315 g_return_if_fail (GST_IS_MESSAGE (message));
1316 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1319 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1320 g_return_if_fail (error_gvalue != NULL);
1321 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1323 error_val = (GError *) g_value_get_boxed (error_gvalue);
1325 *gerror = g_error_copy (error_val);
1331 g_value_dup_string (gst_structure_id_get_value (message->structure,
1332 GST_QUARK (DEBUG)));
1336 * gst_message_parse_warning:
1337 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1338 * @gerror: Location for the GError
1339 * @debug: Location for the debug message, or NULL
1341 * Extracts the GError and debug string from the GstMessage. The values returned
1342 * in the output arguments are copies; the caller must free them when done.
1347 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1350 const GValue *error_gvalue;
1353 g_return_if_fail (GST_IS_MESSAGE (message));
1354 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1357 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1358 g_return_if_fail (error_gvalue != NULL);
1359 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1361 error_val = (GError *) g_value_get_boxed (error_gvalue);
1363 *gerror = g_error_copy (error_val);
1369 g_value_dup_string (gst_structure_id_get_value (message->structure,
1370 GST_QUARK (DEBUG)));
1374 * gst_message_parse_info:
1375 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1376 * @gerror: Location for the GError
1377 * @debug: Location for the debug message, or NULL
1379 * Extracts the GError and debug string from the GstMessage. The values returned
1380 * in the output arguments are copies; the caller must free them when done.
1387 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1389 const GValue *error_gvalue;
1392 g_return_if_fail (GST_IS_MESSAGE (message));
1393 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1396 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1397 g_return_if_fail (error_gvalue != NULL);
1398 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1400 error_val = (GError *) g_value_get_boxed (error_gvalue);
1402 *gerror = g_error_copy (error_val);
1408 g_value_dup_string (gst_structure_id_get_value (message->structure,
1409 GST_QUARK (DEBUG)));
1413 * gst_message_parse_segment_start:
1414 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1415 * @format: Result location for the format, or NULL
1416 * @position: Result location for the position, or NULL
1418 * Extracts the position and format from the segment start message.
1423 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1426 g_return_if_fail (GST_IS_MESSAGE (message));
1427 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1431 g_value_get_enum (gst_structure_id_get_value (message->structure,
1432 GST_QUARK (FORMAT)));
1435 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1436 GST_QUARK (POSITION)));
1440 * gst_message_parse_segment_done:
1441 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1442 * @format: Result location for the format, or NULL
1443 * @position: Result location for the position, or NULL
1445 * Extracts the position and format from the segment start message.
1450 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1453 g_return_if_fail (GST_IS_MESSAGE (message));
1454 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1458 g_value_get_enum (gst_structure_id_get_value (message->structure,
1459 GST_QUARK (FORMAT)));
1462 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1463 GST_QUARK (POSITION)));
1467 * gst_message_parse_duration:
1468 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1469 * @format: Result location for the format, or NULL
1470 * @duration: Result location for the duration, or NULL
1472 * Extracts the duration and format from the duration message. The duration
1473 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1474 * changed. Applications should always use a query to retrieve the duration
1480 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1483 g_return_if_fail (GST_IS_MESSAGE (message));
1484 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1488 g_value_get_enum (gst_structure_id_get_value (message->structure,
1489 GST_QUARK (FORMAT)));
1492 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1493 GST_QUARK (DURATION)));
1497 * gst_message_parse_async_start:
1498 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1499 * @new_base_time: Result location for the new_base_time or NULL
1501 * Extract the new_base_time from the async_start message.
1508 gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
1510 g_return_if_fail (GST_IS_MESSAGE (message));
1511 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_START);
1515 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1516 GST_QUARK (NEW_BASE_TIME)));
1520 * gst_message_parse_request_state:
1521 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1522 * @state: Result location for the requested state or NULL
1524 * Extract the requested state from the request_state message.
1531 gst_message_parse_request_state (GstMessage * message, GstState * state)
1533 g_return_if_fail (GST_IS_MESSAGE (message));
1534 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1537 *state = g_value_get_enum (gst_structure_id_get_value (message->structure,
1538 GST_QUARK (NEW_STATE)));
1542 * gst_message_new_stream_status:
1543 * @src: The object originating the message.
1544 * @type: The stream status type.
1545 * @owner: The owner element of @src.
1547 * Create a new stream status message. This message is posted when a streaming
1548 * thread is created/destroyed or when the state changed.
1550 * Returns: The new stream status message.
1557 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1560 GstMessage *message;
1561 GstStructure *structure;
1563 structure = gst_structure_id_empty_new (GST_QUARK (MESSAGE_STREAM_STATUS));
1564 gst_structure_id_set (structure,
1565 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1566 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1567 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1573 * gst_message_parse_stream_status:
1574 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1575 * @type: A pointer to hold the status type
1576 * @owner: The owner element of the message source
1578 * Extracts the stream status type and owner the GstMessage. The returned
1579 * owner remains valid for as long as the reference to @message is valid and
1580 * should thus not be unreffed.
1587 gst_message_parse_stream_status (GstMessage * message,
1588 GstStreamStatusType * type, GstElement ** owner)
1590 const GValue *owner_gvalue;
1592 g_return_if_fail (GST_IS_MESSAGE (message));
1593 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1596 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1597 g_return_if_fail (owner_gvalue != NULL);
1600 *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1603 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1607 * gst_message_set_stream_status_object:
1608 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1609 * @object: the object controlling the streaming
1611 * Configures the object handling the streaming thread. This is usually a
1612 * GstTask object but other objects might be added in the future.
1617 gst_message_set_stream_status_object (GstMessage * message,
1618 const GValue * object)
1620 g_return_if_fail (GST_IS_MESSAGE (message));
1621 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1623 gst_structure_id_set_value (message->structure, GST_QUARK (OBJECT), object);
1627 * gst_message_get_stream_status_object:
1628 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1630 * Extracts the object managing the streaming thread from @message.
1632 * Returns: a GValue containing the object that manages the streaming thread.
1633 * This object is usually of type GstTask but other types can be added in the
1634 * future. The object remains valid as long as @message is valid.
1639 gst_message_get_stream_status_object (GstMessage * message)
1641 const GValue *result;
1643 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1644 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1647 result = gst_structure_id_get_value (message->structure, GST_QUARK (OBJECT));