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_new (GST_QUARK (MESSAGE_ERROR),
385 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
386 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
387 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
393 * gst_message_new_warning:
394 * @src: The object originating the message.
395 * @error: The GError for this message.
396 * @debug: A debugging string.
398 * Create a new warning message. The message will make copies of @error and
401 * Returns: The new warning message.
406 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
409 GstStructure *structure;
411 structure = gst_structure_id_new (GST_QUARK (MESSAGE_WARNING),
412 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
413 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
414 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
420 * gst_message_new_info:
421 * @src: The object originating the message.
422 * @error: The GError for this message.
423 * @debug: A debugging string.
425 * Create a new info message. The message will make copies of @error and
430 * Returns: The new info message.
435 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
438 GstStructure *structure;
440 structure = gst_structure_id_new (GST_QUARK (MESSAGE_INFO),
441 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
442 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
443 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
449 * gst_message_new_tag:
450 * @src: The object originating the message.
451 * @tag_list: The tag list for the message.
453 * Create a new tag message. The message will take ownership of the tag list.
454 * The message is posted by elements that discovered a new taglist.
456 * Returns: The new tag message.
461 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
465 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
468 gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
474 * gst_message_new_tag_full:
475 * @src: The object originating the message.
476 * @pad: The originating pad for the tag.
477 * @tag_list: The tag list for the message.
479 * Create a new tag message. The message will take ownership of the tag list.
480 * The message is posted by elements that discovered a new taglist.
482 * Returns: The new tag message.
489 gst_message_new_tag_full (GstObject * src, GstPad * pad, GstTagList * tag_list)
494 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
495 g_return_val_if_fail (pad == NULL || GST_IS_PAD (pad), NULL);
497 s = (GstStructure *) tag_list;
499 gst_structure_set (s, "source-pad", GST_TYPE_PAD, pad, NULL);
501 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
507 * gst_message_new_buffering:
508 * @src: The object originating the message.
509 * @percent: The buffering percent
511 * Create a new buffering message. This message can be posted by an element that
512 * needs to buffer data before it can continue processing. @percent should be a
513 * value between 0 and 100. A value of 100 means that the buffering completed.
515 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
516 * @percent is 100, the application can set the pipeline (back) to PLAYING.
517 * The application must be prepared to receive BUFFERING messages in the
518 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
519 * message with @percent set to 100, which can happen after the pipeline
520 * completed prerolling.
524 * Returns: The new buffering message.
529 gst_message_new_buffering (GstObject * src, gint percent)
532 GstStructure *structure;
534 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
536 structure = gst_structure_id_new (GST_QUARK (MESSAGE_BUFFERING),
537 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
538 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
539 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
540 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
541 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
542 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
543 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
549 * gst_message_new_state_changed:
550 * @src: the object originating the message
551 * @oldstate: the previous state
552 * @newstate: the new (current) state
553 * @pending: the pending (target) state
555 * Create a state change message. This message is posted whenever an element
558 * Returns: The new state change message.
563 gst_message_new_state_changed (GstObject * src,
564 GstState oldstate, GstState newstate, GstState pending)
567 GstStructure *structure;
569 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STATE),
570 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
571 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
572 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
573 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
579 * gst_message_new_state_dirty:
580 * @src: the object originating the message
582 * Create a state dirty message. This message is posted whenever an element
583 * changed its state asynchronously and is used internally to update the
584 * states of container objects.
586 * Returns: The new state dirty message.
591 gst_message_new_state_dirty (GstObject * src)
595 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
601 * gst_message_new_clock_provide:
602 * @src: The object originating the message.
603 * @clock: The clock it provides
604 * @ready: TRUE if the sender can provide a clock
606 * Create a clock provide message. This message is posted whenever an
607 * element is ready to provide a clock or lost its ability to provide
608 * a clock (maybe because it paused or became EOS).
610 * This message is mainly used internally to manage the clock
613 * Returns: The new provide clock message.
618 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
622 GstStructure *structure;
624 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
625 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
626 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
627 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
633 * gst_message_new_clock_lost:
634 * @src: The object originating the message.
635 * @clock: the clock that was lost
637 * Create a clock lost message. This message is posted whenever the
638 * clock is not valid anymore.
640 * If this message is posted by the pipeline, the pipeline will
641 * select a new clock again when it goes to PLAYING. It might therefore
642 * be needed to set the pipeline to PAUSED and PLAYING again.
644 * Returns: The new clock lost message.
649 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
652 GstStructure *structure;
654 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_LOST),
655 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
656 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
662 * gst_message_new_new_clock:
663 * @src: The object originating the message.
664 * @clock: the new selected clock
666 * Create a new clock message. This message is posted whenever the
667 * pipeline selectes a new clock for the pipeline.
669 * Returns: The new new clock message.
674 gst_message_new_new_clock (GstObject * src, GstClock * clock)
677 GstStructure *structure;
679 structure = gst_structure_id_new (GST_QUARK (MESSAGE_NEW_CLOCK),
680 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
681 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
687 * gst_message_new_structure_change:
688 * @src: The object originating the message.
689 * @type: The change type.
690 * @owner: The owner element of @src.
691 * @busy: Whether the structure change is busy.
693 * Create a new structure change message. This message is posted when the
694 * structure of a pipeline is in the process of being changed, for example
695 * when pads are linked or unlinked.
697 * @src should be the srcpad that unlinked or linked.
699 * Returns: The new structure change message.
706 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
707 GstElement * owner, gboolean busy)
710 GstStructure *structure;
712 g_return_val_if_fail (GST_IS_PAD (src), NULL);
713 g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SRC, NULL);
714 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
716 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
717 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
718 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
719 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
721 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
728 * gst_message_new_segment_start:
729 * @src: The object originating the message.
730 * @format: The format of the position being played
731 * @position: The position of the segment being played
733 * Create a new segment message. This message is posted by elements that
734 * start playback of a segment as a result of a segment seek. This message
735 * is not received by the application but is used for maintenance reasons in
736 * container elements.
738 * Returns: The new segment start message.
743 gst_message_new_segment_start (GstObject * src, GstFormat format,
747 GstStructure *structure;
749 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_START),
750 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
751 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
752 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
758 * gst_message_new_segment_done:
759 * @src: The object originating the message.
760 * @format: The format of the position being done
761 * @position: The position of the segment being done
763 * Create a new segment done message. This message is posted by elements that
764 * finish playback of a segment as a result of a segment seek. This message
765 * is received by the application after all elements that posted a segment_start
766 * have posted the segment_done.
768 * Returns: The new segment done message.
773 gst_message_new_segment_done (GstObject * src, GstFormat format,
777 GstStructure *structure;
779 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_DONE),
780 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
781 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
782 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
788 * gst_message_new_application:
789 * @src: The object originating the message.
790 * @structure: The structure for the message. The message will take ownership of
793 * Create a new application-typed message. GStreamer will never create these
794 * messages; they are a gift from us to you. Enjoy.
796 * Returns: The new application message.
801 gst_message_new_application (GstObject * src, GstStructure * structure)
803 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
807 * gst_message_new_element:
808 * @src: The object originating the message.
809 * @structure: The structure for the message. The message will take ownership of
812 * Create a new element-specific message. This is meant as a generic way of
813 * allowing one-way communication from an element to an application, for example
814 * "the firewire cable was unplugged". The format of the message should be
815 * documented in the element's documentation. The structure field can be NULL.
817 * Returns: The new element message.
822 gst_message_new_element (GstObject * src, GstStructure * structure)
824 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
828 * gst_message_new_duration:
829 * @src: The object originating the message.
830 * @format: The format of the duration
831 * @duration: The new duration
833 * Create a new duration message. This message is posted by elements that
834 * know the duration of a stream in a specific format. This message
835 * is received by bins and is used to calculate the total duration of a
836 * pipeline. Elements may post a duration message with a duration of
837 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
838 * cached duration should be discarded. The new duration can then be
839 * retrieved via a query.
841 * Returns: The new duration message.
846 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
849 GstStructure *structure;
851 structure = gst_structure_id_new (GST_QUARK (MESSAGE_DURATION),
852 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
853 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
854 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
860 * gst_message_new_async_start:
861 * @src: The object originating the message.
862 * @new_base_time: if a new base_time should be set on the element
864 * This message is posted by elements when they start an ASYNC state change.
865 * @new_base_time is set to TRUE when the element lost its state when it was
868 * Returns: The new async_start message.
875 gst_message_new_async_start (GstObject * src, gboolean new_base_time)
878 GstStructure *structure;
880 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ASYNC_START),
881 GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
882 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
888 * gst_message_new_async_done:
889 * @src: The object originating the message.
891 * The message is posted when elements completed an ASYNC state change.
893 * Returns: The new async_done message.
900 gst_message_new_async_done (GstObject * src)
904 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
910 * gst_message_new_latency:
911 * @src: The object originating the message.
913 * This message can be posted by elements when their latency requirements have
916 * Returns: The new latency message.
923 gst_message_new_latency (GstObject * src)
927 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
933 * gst_message_new_request_state:
934 * @src: The object originating the message.
935 * @state: The new requested state
937 * This message can be posted by elements when they want to have their state
938 * changed. A typical use case would be an audio server that wants to pause the
939 * pipeline because a higher priority stream is being played.
941 * Returns: The new requst state message.
948 gst_message_new_request_state (GstObject * src, GstState state)
951 GstStructure *structure;
953 structure = gst_structure_id_new (GST_QUARK (MESSAGE_REQUEST_STATE),
954 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
955 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
961 * gst_message_get_structure:
962 * @message: The #GstMessage.
964 * Access the structure of the message.
966 * Returns: The structure of the message. The structure is still
967 * owned by the message, which means that you should not free it and
968 * that the pointer becomes invalid when you free the message.
973 gst_message_get_structure (GstMessage * message)
975 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
977 return message->structure;
981 * gst_message_parse_tag:
982 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
983 * @tag_list: Return location for the tag-list.
985 * Extracts the tag list from the GstMessage. The tag list returned in the
986 * output argument is a copy; the caller must free it when done.
991 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
995 g_return_if_fail (GST_IS_MESSAGE (message));
996 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
997 g_return_if_fail (tag_list != NULL);
999 ret = gst_structure_copy (message->structure);
1000 gst_structure_remove_field (ret, "source-pad");
1002 *tag_list = (GstTagList *) ret;
1006 * gst_message_parse_tag_full:
1007 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1008 * @pad: Location where the originating pad is stored, unref after usage
1009 * @tag_list: Return location for the tag-list.
1011 * Extracts the tag list from the GstMessage. The tag list returned in the
1012 * output argument is a copy; the caller must free it when done.
1019 gst_message_parse_tag_full (GstMessage * message, GstPad ** pad,
1020 GstTagList ** tag_list)
1024 g_return_if_fail (GST_IS_MESSAGE (message));
1025 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1026 g_return_if_fail (tag_list != NULL);
1028 ret = gst_structure_copy (message->structure);
1030 if (gst_structure_has_field (ret, "source-pad") && pad) {
1033 v = gst_structure_get_value (ret, "source-pad");
1034 if (v && G_VALUE_HOLDS (v, GST_TYPE_PAD))
1035 *pad = g_value_dup_object (v);
1041 gst_structure_remove_field (ret, "source-pad");
1043 *tag_list = (GstTagList *) ret;
1047 * gst_message_parse_buffering:
1048 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1049 * @percent: Return location for the percent.
1051 * Extracts the buffering percent from the GstMessage. see also
1052 * gst_message_new_buffering().
1059 gst_message_parse_buffering (GstMessage * message, gint * percent)
1061 g_return_if_fail (GST_IS_MESSAGE (message));
1062 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1065 *percent = g_value_get_int (gst_structure_id_get_value (message->structure,
1066 GST_QUARK (BUFFER_PERCENT)));
1070 * gst_message_set_buffering_stats:
1071 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1072 * @mode: a buffering mode
1073 * @avg_in: the average input rate
1074 * @avg_out: the average output rate
1075 * @buffering_left: amount of buffering time left in milliseconds
1077 * Configures the buffering stats values in @message.
1082 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1083 gint avg_in, gint avg_out, gint64 buffering_left)
1085 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1087 gst_structure_id_set (message->structure,
1088 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1089 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1090 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1091 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1095 * gst_message_parse_buffering_stats:
1096 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1097 * @mode: a buffering mode
1098 * @avg_in: the average input rate
1099 * @avg_out: the average output rate
1100 * @buffering_left: amount of buffering time left in milliseconds.
1102 * Extracts the buffering stats values from @message.
1107 gst_message_parse_buffering_stats (GstMessage * message,
1108 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1109 gint64 * buffering_left)
1111 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1114 *mode = g_value_get_enum (gst_structure_id_get_value (message->structure,
1115 GST_QUARK (BUFFERING_MODE)));
1117 *avg_in = g_value_get_int (gst_structure_id_get_value (message->structure,
1118 GST_QUARK (AVG_IN_RATE)));
1120 *avg_out = g_value_get_int (gst_structure_id_get_value (message->structure,
1121 GST_QUARK (AVG_OUT_RATE)));
1124 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1125 GST_QUARK (BUFFERING_LEFT)));
1129 * gst_message_parse_state_changed:
1130 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1131 * @oldstate: the previous state, or NULL
1132 * @newstate: the new (current) state, or NULL
1133 * @pending: the pending (target) state, or NULL
1135 * Extracts the old and new states from the GstMessage.
1140 gst_message_parse_state_changed (GstMessage * message,
1141 GstState * oldstate, GstState * newstate, GstState * pending)
1143 g_return_if_fail (GST_IS_MESSAGE (message));
1144 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1148 g_value_get_enum (gst_structure_id_get_value (message->structure,
1149 GST_QUARK (OLD_STATE)));
1152 g_value_get_enum (gst_structure_id_get_value (message->structure,
1153 GST_QUARK (NEW_STATE)));
1155 *pending = g_value_get_enum (gst_structure_id_get_value (message->structure,
1156 GST_QUARK (PENDING_STATE)));
1160 * gst_message_parse_clock_provide:
1161 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1162 * @clock: A pointer to hold a clock object.
1163 * @ready: A pointer to hold the ready flag.
1165 * Extracts the clock and ready flag from the GstMessage.
1166 * The clock object returned remains valid until the message is freed.
1171 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1174 const GValue *clock_gvalue;
1176 g_return_if_fail (GST_IS_MESSAGE (message));
1177 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1180 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1181 g_return_if_fail (clock_gvalue != NULL);
1182 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1186 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1187 GST_QUARK (READY)));
1189 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1193 * gst_message_parse_clock_lost:
1194 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1195 * @clock: A pointer to hold the lost clock
1197 * Extracts the lost clock from the GstMessage.
1198 * The clock object returned remains valid until the message is freed.
1203 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1205 const GValue *clock_gvalue;
1207 g_return_if_fail (GST_IS_MESSAGE (message));
1208 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1211 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1212 g_return_if_fail (clock_gvalue != NULL);
1213 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1216 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1220 * gst_message_parse_new_clock:
1221 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1222 * @clock: A pointer to hold the selected new clock
1224 * Extracts the new clock from the GstMessage.
1225 * The clock object returned remains valid until the message is freed.
1230 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1232 const GValue *clock_gvalue;
1234 g_return_if_fail (GST_IS_MESSAGE (message));
1235 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1238 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1239 g_return_if_fail (clock_gvalue != NULL);
1240 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1243 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1247 * gst_message_parse_structure_change:
1248 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1249 * @type: A pointer to hold the change type
1250 * @owner: The owner element of the message source
1251 * @busy: A pointer to hold whether the change is in progress or has been
1254 * Extracts the change type and completion status from the GstMessage.
1261 gst_message_parse_structure_change (GstMessage * message,
1262 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1264 const GValue *owner_gvalue;
1266 g_return_if_fail (GST_IS_MESSAGE (message));
1267 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1270 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1271 g_return_if_fail (owner_gvalue != NULL);
1272 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1275 *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1278 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1281 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1286 * gst_message_parse_error:
1287 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1288 * @gerror: Location for the GError
1289 * @debug: Location for the debug message, or NULL
1291 * Extracts the GError and debug string from the GstMessage. The values returned
1292 * in the output arguments are copies; the caller must free them when done.
1297 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1299 const GValue *error_gvalue;
1302 g_return_if_fail (GST_IS_MESSAGE (message));
1303 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1306 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1307 g_return_if_fail (error_gvalue != NULL);
1308 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1310 error_val = (GError *) g_value_get_boxed (error_gvalue);
1312 *gerror = g_error_copy (error_val);
1318 g_value_dup_string (gst_structure_id_get_value (message->structure,
1319 GST_QUARK (DEBUG)));
1323 * gst_message_parse_warning:
1324 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1325 * @gerror: Location for the GError
1326 * @debug: Location for the debug message, or NULL
1328 * Extracts the GError and debug string from the GstMessage. The values returned
1329 * in the output arguments are copies; the caller must free them when done.
1334 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1337 const GValue *error_gvalue;
1340 g_return_if_fail (GST_IS_MESSAGE (message));
1341 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1344 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1345 g_return_if_fail (error_gvalue != NULL);
1346 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1348 error_val = (GError *) g_value_get_boxed (error_gvalue);
1350 *gerror = g_error_copy (error_val);
1356 g_value_dup_string (gst_structure_id_get_value (message->structure,
1357 GST_QUARK (DEBUG)));
1361 * gst_message_parse_info:
1362 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1363 * @gerror: Location for the GError
1364 * @debug: Location for the debug message, or NULL
1366 * Extracts the GError and debug string from the GstMessage. The values returned
1367 * in the output arguments are copies; the caller must free them when done.
1374 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1376 const GValue *error_gvalue;
1379 g_return_if_fail (GST_IS_MESSAGE (message));
1380 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1383 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1384 g_return_if_fail (error_gvalue != NULL);
1385 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1387 error_val = (GError *) g_value_get_boxed (error_gvalue);
1389 *gerror = g_error_copy (error_val);
1395 g_value_dup_string (gst_structure_id_get_value (message->structure,
1396 GST_QUARK (DEBUG)));
1400 * gst_message_parse_segment_start:
1401 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1402 * @format: Result location for the format, or NULL
1403 * @position: Result location for the position, or NULL
1405 * Extracts the position and format from the segment start message.
1410 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1413 g_return_if_fail (GST_IS_MESSAGE (message));
1414 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1418 g_value_get_enum (gst_structure_id_get_value (message->structure,
1419 GST_QUARK (FORMAT)));
1422 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1423 GST_QUARK (POSITION)));
1427 * gst_message_parse_segment_done:
1428 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1429 * @format: Result location for the format, or NULL
1430 * @position: Result location for the position, or NULL
1432 * Extracts the position and format from the segment start message.
1437 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1440 g_return_if_fail (GST_IS_MESSAGE (message));
1441 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1445 g_value_get_enum (gst_structure_id_get_value (message->structure,
1446 GST_QUARK (FORMAT)));
1449 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1450 GST_QUARK (POSITION)));
1454 * gst_message_parse_duration:
1455 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1456 * @format: Result location for the format, or NULL
1457 * @duration: Result location for the duration, or NULL
1459 * Extracts the duration and format from the duration message. The duration
1460 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1461 * changed. Applications should always use a query to retrieve the duration
1467 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1470 g_return_if_fail (GST_IS_MESSAGE (message));
1471 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1475 g_value_get_enum (gst_structure_id_get_value (message->structure,
1476 GST_QUARK (FORMAT)));
1479 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1480 GST_QUARK (DURATION)));
1484 * gst_message_parse_async_start:
1485 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1486 * @new_base_time: Result location for the new_base_time or NULL
1488 * Extract the new_base_time from the async_start message.
1495 gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
1497 g_return_if_fail (GST_IS_MESSAGE (message));
1498 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_START);
1502 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1503 GST_QUARK (NEW_BASE_TIME)));
1507 * gst_message_parse_request_state:
1508 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1509 * @state: Result location for the requested state or NULL
1511 * Extract the requested state from the request_state message.
1518 gst_message_parse_request_state (GstMessage * message, GstState * state)
1520 g_return_if_fail (GST_IS_MESSAGE (message));
1521 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1524 *state = g_value_get_enum (gst_structure_id_get_value (message->structure,
1525 GST_QUARK (NEW_STATE)));
1529 * gst_message_new_stream_status:
1530 * @src: The object originating the message.
1531 * @type: The stream status type.
1532 * @owner: The owner element of @src.
1534 * Create a new stream status message. This message is posted when a streaming
1535 * thread is created/destroyed or when the state changed.
1537 * Returns: The new stream status message.
1544 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1547 GstMessage *message;
1548 GstStructure *structure;
1550 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STREAM_STATUS),
1551 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1552 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1553 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1559 * gst_message_parse_stream_status:
1560 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1561 * @type: A pointer to hold the status type
1562 * @owner: The owner element of the message source
1564 * Extracts the stream status type and owner the GstMessage. The returned
1565 * owner remains valid for as long as the reference to @message is valid and
1566 * should thus not be unreffed.
1573 gst_message_parse_stream_status (GstMessage * message,
1574 GstStreamStatusType * type, GstElement ** owner)
1576 const GValue *owner_gvalue;
1578 g_return_if_fail (GST_IS_MESSAGE (message));
1579 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1582 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1583 g_return_if_fail (owner_gvalue != NULL);
1586 *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1589 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1593 * gst_message_set_stream_status_object:
1594 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1595 * @object: the object controlling the streaming
1597 * Configures the object handling the streaming thread. This is usually a
1598 * GstTask object but other objects might be added in the future.
1603 gst_message_set_stream_status_object (GstMessage * message,
1604 const GValue * object)
1606 g_return_if_fail (GST_IS_MESSAGE (message));
1607 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1609 gst_structure_id_set_value (message->structure, GST_QUARK (OBJECT), object);
1613 * gst_message_get_stream_status_object:
1614 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1616 * Extracts the object managing the streaming thread from @message.
1618 * Returns: a GValue containing the object that manages the streaming thread.
1619 * This object is usually of type GstTask but other types can be added in the
1620 * future. The object remains valid as long as @message is valid.
1625 gst_message_get_stream_status_object (GstMessage * message)
1627 const GValue *result;
1629 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1630 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1633 result = gst_structure_id_get_value (message->structure, GST_QUARK (OBJECT));