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},
113 {GST_MESSAGE_STEP_START, "step-start", 0},
114 {GST_MESSAGE_QOS, "qos", 0},
115 {GST_MESSAGE_PROGRESS, "progress", 0},
116 {GST_MESSAGE_TOC, "toc", 0},
121 * gst_message_type_get_name:
122 * @type: the message type
124 * Get a printable name for the given message type. Do not modify or free.
126 * Returns: a reference to the static name of the message.
129 gst_message_type_get_name (GstMessageType type)
133 for (i = 0; message_quarks[i].name; i++) {
134 if (type == message_quarks[i].type)
135 return message_quarks[i].name;
141 * gst_message_type_to_quark:
142 * @type: the message type
144 * Get the unique quark for the given message type.
146 * Returns: the quark associated with the message type
149 gst_message_type_to_quark (GstMessageType type)
153 for (i = 0; message_quarks[i].name; i++) {
154 if (type == message_quarks[i].type)
155 return message_quarks[i].quark;
164 for (i = 0; message_quarks[i].name; i++) { \
165 message_quarks[i].quark = \
166 g_quark_from_static_string (message_quarks[i].name); \
170 G_DEFINE_TYPE_WITH_CODE (GstMessage, gst_message, GST_TYPE_MINI_OBJECT,
174 gst_message_class_init (GstMessageClass * klass)
176 parent_class = g_type_class_peek_parent (klass);
178 klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_message_copy;
179 klass->mini_object_class.finalize =
180 (GstMiniObjectFinalizeFunction) gst_message_finalize;
184 gst_message_init (GstMessage * message)
186 GST_CAT_LOG (GST_CAT_MESSAGE, "new message %p", message);
187 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
191 gst_message_finalize (GstMessage * message)
193 g_return_if_fail (message != NULL);
195 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
196 GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
198 if (GST_MESSAGE_SRC (message)) {
199 gst_object_unref (GST_MESSAGE_SRC (message));
200 GST_MESSAGE_SRC (message) = NULL;
204 GST_MESSAGE_LOCK (message);
205 GST_MESSAGE_SIGNAL (message);
206 GST_MESSAGE_UNLOCK (message);
209 if (message->structure) {
210 gst_structure_set_parent_refcount (message->structure, NULL);
211 gst_structure_free (message->structure);
214 /* GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (message)); */
218 _gst_message_copy (GstMessage * message)
222 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
223 GST_MESSAGE_TYPE_NAME (message),
224 GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
226 copy = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
228 /* FIXME, need to copy relevant data from the miniobject. */
229 //memcpy (copy, message, sizeof (GstMessage));
231 GST_MESSAGE_GET_LOCK (copy) = GST_MESSAGE_GET_LOCK (message);
232 GST_MESSAGE_COND (copy) = GST_MESSAGE_COND (message);
233 GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
234 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
235 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
237 if (GST_MESSAGE_SRC (message)) {
238 GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
241 if (message->structure) {
242 copy->structure = gst_structure_copy (message->structure);
243 gst_structure_set_parent_refcount (copy->structure,
244 ©->mini_object.refcount);
251 * gst_message_new_custom:
252 * @type: The #GstMessageType to distinguish messages
253 * @src: The object originating the message.
254 * @structure: (transfer full): the structure for the message. The message
255 * will take ownership of the structure.
257 * Create a new custom-typed message. This can be used for anything not
258 * handled by other message-specific functions to pass a message to the
259 * app. The structure field can be NULL.
261 * Returns: (transfer full): The new message.
266 gst_message_new_custom (GstMessageType type, GstObject * src,
267 GstStructure * structure)
271 message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
273 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
274 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
275 gst_message_type_get_name (type));
277 message->type = type;
280 gst_object_ref (src);
284 gst_structure_set_parent_refcount (structure,
285 &message->mini_object.refcount);
287 message->structure = structure;
289 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
295 * gst_message_get_seqnum:
296 * @message: A #GstMessage.
298 * Retrieve the sequence number of a message.
300 * Messages have ever-incrementing sequence numbers, which may also be set
301 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
302 * to indicate that a message corresponds to some other set of messages or
303 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
304 * is considered good practice to make this correspondence when possible, though
305 * it is not required.
307 * Note that events and messages share the same sequence number incrementor;
308 * two events or messages will never have the same sequence number unless
309 * that correspondence was made explicitly.
311 * Returns: The message's sequence number.
318 gst_message_get_seqnum (GstMessage * message)
320 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
322 return GST_MESSAGE_SEQNUM (message);
326 * gst_message_set_seqnum:
327 * @message: A #GstMessage.
328 * @seqnum: A sequence number.
330 * Set the sequence number of a message.
332 * This function might be called by the creator of a message to indicate that
333 * the message relates to other messages or events. See gst_message_get_seqnum()
334 * for more information.
341 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
343 g_return_if_fail (GST_IS_MESSAGE (message));
345 GST_MESSAGE_SEQNUM (message) = seqnum;
349 * gst_message_new_eos:
350 * @src: (transfer none): The object originating the message.
352 * Create a new eos message. This message is generated and posted in
353 * the sink elements of a GstBin. The bin will only forward the EOS
354 * message to the application if all sinks have posted an EOS message.
356 * Returns: (transfer full): The new eos message.
361 gst_message_new_eos (GstObject * src)
365 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
371 * gst_message_new_error:
372 * @src: (transfer none): The object originating the message.
373 * @error: (transfer none): The GError for this message.
374 * @debug: A debugging string.
376 * Create a new error message. The message will copy @error and
377 * @debug. This message is posted by element when a fatal event
378 * occured. The pipeline will probably (partially) stop. The application
379 * receiving this message should stop the pipeline.
381 * Returns: (transfer full): the new error message.
386 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
389 GstStructure *structure;
391 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ERROR),
392 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
393 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
394 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
400 * gst_message_new_warning:
401 * @src: (transfer none): The object originating the message.
402 * @error: (transfer none): The GError for this message.
403 * @debug: A debugging string.
405 * Create a new warning message. The message will make copies of @error and
408 * Returns: (transfer full): The new warning message.
413 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
416 GstStructure *structure;
418 structure = gst_structure_id_new (GST_QUARK (MESSAGE_WARNING),
419 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
420 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
421 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
427 * gst_message_new_info:
428 * @src: (transfer none): The object originating the message.
429 * @error: (transfer none): The GError for this message.
430 * @debug: A debugging string.
432 * Create a new info message. The message will make copies of @error and
437 * Returns: (transfer full): the new info message.
442 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
445 GstStructure *structure;
447 structure = gst_structure_id_new (GST_QUARK (MESSAGE_INFO),
448 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
449 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
450 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
456 * gst_message_new_tag:
457 * @src: (transfer none): The object originating the message.
458 * @tag_list: (transfer full): the tag list for the message.
460 * Create a new tag message. The message will take ownership of the tag list.
461 * The message is posted by elements that discovered a new taglist.
463 * Returns: (transfer full): the new tag message.
468 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
472 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
475 gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
481 * gst_message_new_tag_full:
482 * @src: (transfer none): the object originating the message.
483 * @pad: (transfer none): the originating pad for the tag.
484 * @tag_list: (transfer full): the tag list for the message.
486 * Create a new tag message. The message will take ownership of the tag list.
487 * The message is posted by elements that discovered a new taglist.
491 * Returns: (transfer full): the new tag message.
496 gst_message_new_tag_full (GstObject * src, GstPad * pad, GstTagList * tag_list)
501 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
502 g_return_val_if_fail (pad == NULL || GST_IS_PAD (pad), NULL);
504 s = (GstStructure *) tag_list;
506 gst_structure_set (s, "source-pad", GST_TYPE_PAD, pad, NULL);
508 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
514 * gst_message_new_buffering:
515 * @src: (transfer none): The object originating the message.
516 * @percent: The buffering percent
518 * Create a new buffering message. This message can be posted by an element that
519 * needs to buffer data before it can continue processing. @percent should be a
520 * value between 0 and 100. A value of 100 means that the buffering completed.
522 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
523 * @percent is 100, the application can set the pipeline (back) to PLAYING.
524 * The application must be prepared to receive BUFFERING messages in the
525 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
526 * message with @percent set to 100, which can happen after the pipeline
527 * completed prerolling.
531 * Returns: (transfer full): The new buffering message.
536 gst_message_new_buffering (GstObject * src, gint percent)
539 GstStructure *structure;
541 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
543 structure = gst_structure_id_new (GST_QUARK (MESSAGE_BUFFERING),
544 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
545 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
546 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
547 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
548 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
549 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
550 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
556 * gst_message_new_state_changed:
557 * @src: (transfer none): the object originating the message
558 * @oldstate: the previous state
559 * @newstate: the new (current) state
560 * @pending: the pending (target) state
562 * Create a state change message. This message is posted whenever an element
565 * Returns: (transfer full): the new state change message.
570 gst_message_new_state_changed (GstObject * src,
571 GstState oldstate, GstState newstate, GstState pending)
574 GstStructure *structure;
576 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STATE),
577 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
578 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
579 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
580 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
586 * gst_message_new_state_dirty:
587 * @src: (transfer none): the object originating the message
589 * Create a state dirty message. This message is posted whenever an element
590 * changed its state asynchronously and is used internally to update the
591 * states of container objects.
593 * Returns: (transfer full): the new state dirty message.
598 gst_message_new_state_dirty (GstObject * src)
602 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
608 * gst_message_new_clock_provide:
609 * @src: (transfer none): the object originating the message.
610 * @clock: (transfer none): the clock it provides
611 * @ready: TRUE if the sender can provide a clock
613 * Create a clock provide message. This message is posted whenever an
614 * element is ready to provide a clock or lost its ability to provide
615 * a clock (maybe because it paused or became EOS).
617 * This message is mainly used internally to manage the clock
620 * Returns: (transfer full): the new provide clock message.
625 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
629 GstStructure *structure;
631 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
632 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
633 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
634 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
640 * gst_message_new_clock_lost:
641 * @src: (transfer none): the object originating the message.
642 * @clock: (transfer none): the clock that was lost
644 * Create a clock lost message. This message is posted whenever the
645 * clock is not valid anymore.
647 * If this message is posted by the pipeline, the pipeline will
648 * select a new clock again when it goes to PLAYING. It might therefore
649 * be needed to set the pipeline to PAUSED and PLAYING again.
651 * Returns: (transfer full): The new clock lost message.
656 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
659 GstStructure *structure;
661 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_LOST),
662 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
663 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
669 * gst_message_new_new_clock:
670 * @src: (transfer none): The object originating the message.
671 * @clock: (transfer none): the new selected clock
673 * Create a new clock message. This message is posted whenever the
674 * pipeline selectes a new clock for the pipeline.
676 * Returns: (transfer full): The new new clock message.
681 gst_message_new_new_clock (GstObject * src, GstClock * clock)
684 GstStructure *structure;
686 structure = gst_structure_id_new (GST_QUARK (MESSAGE_NEW_CLOCK),
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: (transfer none): The object originating the message.
696 * @type: The change type.
697 * @owner: (transfer none): 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 sinkpad that unlinked or linked.
706 * Returns: (transfer full): 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_SINK, NULL); */
721 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
723 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
724 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
725 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
726 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
728 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
735 * gst_message_new_segment_start:
736 * @src: (transfer none): The object originating the message.
737 * @format: The format of the position being played
738 * @position: The position of the segment being played
740 * Create a new segment message. This message is posted by elements that
741 * start playback of a segment as a result of a segment seek. This message
742 * is not received by the application but is used for maintenance reasons in
743 * container elements.
745 * Returns: (transfer full): the new segment start message.
750 gst_message_new_segment_start (GstObject * src, GstFormat format,
754 GstStructure *structure;
756 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_START),
757 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
758 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
759 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
765 * gst_message_new_segment_done:
766 * @src: (transfer none): the object originating the message.
767 * @format: The format of the position being done
768 * @position: The position of the segment being done
770 * Create a new segment done message. This message is posted by elements that
771 * finish playback of a segment as a result of a segment seek. This message
772 * is received by the application after all elements that posted a segment_start
773 * have posted the segment_done.
775 * Returns: (transfer full): the new segment done message.
780 gst_message_new_segment_done (GstObject * src, GstFormat format,
784 GstStructure *structure;
786 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_DONE),
787 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
788 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
789 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
795 * gst_message_new_application:
796 * @src: (transfer none): the object originating the message.
797 * @structure: (transfer full): the structure for the message. The message
798 * will take ownership of the structure.
800 * Create a new application-typed message. GStreamer will never create these
801 * messages; they are a gift from us to you. Enjoy.
803 * Returns: (transfer full): The new application message.
808 gst_message_new_application (GstObject * src, GstStructure * structure)
810 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
814 * gst_message_new_element:
815 * @src: (transfer none): The object originating the message.
816 * @structure: (transfer full): The structure for the message. The message
817 * will take ownership of the structure.
819 * Create a new element-specific message. This is meant as a generic way of
820 * allowing one-way communication from an element to an application, for example
821 * "the firewire cable was unplugged". The format of the message should be
822 * documented in the element's documentation. The structure field can be NULL.
824 * Returns: (transfer full): The new element message.
829 gst_message_new_element (GstObject * src, GstStructure * structure)
831 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
835 * gst_message_new_duration:
836 * @src: (transfer none): The object originating the message.
837 * @format: The format of the duration
838 * @duration: The new duration
840 * Create a new duration message. This message is posted by elements that
841 * know the duration of a stream in a specific format. This message
842 * is received by bins and is used to calculate the total duration of a
843 * pipeline. Elements may post a duration message with a duration of
844 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
845 * cached duration should be discarded. The new duration can then be
846 * retrieved via a query.
848 * Returns: (transfer full): The new duration message.
853 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
856 GstStructure *structure;
858 structure = gst_structure_id_new (GST_QUARK (MESSAGE_DURATION),
859 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
860 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
861 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
867 * gst_message_new_async_start:
868 * @src: (transfer none): The object originating the message.
869 * @new_base_time: if a new base_time should be set on the element
871 * This message is posted by elements when they start an ASYNC state change.
872 * @new_base_time is set to TRUE when the element lost its state when it was
875 * Returns: (transfer full): The new async_start message.
882 gst_message_new_async_start (GstObject * src, gboolean new_base_time)
885 GstStructure *structure;
887 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ASYNC_START),
888 GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
889 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
895 * gst_message_new_async_done:
896 * @src: (transfer none): The object originating the message.
898 * The message is posted when elements completed an ASYNC state change.
900 * Returns: (transfer full): The new async_done message.
907 gst_message_new_async_done (GstObject * src)
911 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
917 * gst_message_new_latency:
918 * @src: (transfer none): The object originating the message.
920 * This message can be posted by elements when their latency requirements have
923 * Returns: (transfer full): The new latency message.
930 gst_message_new_latency (GstObject * src)
934 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
940 * gst_message_new_request_state:
941 * @src: (transfer none): the object originating the message.
942 * @state: The new requested state
944 * This message can be posted by elements when they want to have their state
945 * changed. A typical use case would be an audio server that wants to pause the
946 * pipeline because a higher priority stream is being played.
948 * Returns: (transfer full): the new requst state message.
955 gst_message_new_request_state (GstObject * src, GstState state)
958 GstStructure *structure;
960 structure = gst_structure_id_new (GST_QUARK (MESSAGE_REQUEST_STATE),
961 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
962 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
968 * gst_message_get_structure:
969 * @message: The #GstMessage.
971 * Access the structure of the message.
973 * Returns: (transfer none): The structure of the message. The structure is
974 * still owned by the message, which means that you should not free it and
975 * that the pointer becomes invalid when you free the message.
980 gst_message_get_structure (GstMessage * message)
982 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
984 return message->structure;
988 * gst_message_parse_tag:
989 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
990 * @tag_list: (out callee-allocates): return location for the tag-list.
992 * Extracts the tag list from the GstMessage. The tag list returned in the
993 * output argument is a copy; the caller must free it when done.
995 * Typical usage of this function might be:
998 * switch (GST_MESSAGE_TYPE (msg)) {
999 * case GST_MESSAGE_TAG: {
1000 * GstTagList *tags = NULL;
1002 * gst_message_parse_tag (msg, &tags);
1003 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1004 * handle_tags (tags);
1005 * gst_tag_list_free (tags);
1016 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1020 g_return_if_fail (GST_IS_MESSAGE (message));
1021 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1022 g_return_if_fail (tag_list != NULL);
1024 ret = gst_structure_copy (message->structure);
1025 gst_structure_remove_field (ret, "source-pad");
1027 *tag_list = (GstTagList *) ret;
1031 * gst_message_parse_tag_full:
1032 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1033 * @pad: (out callee-allocates): location where the originating pad is stored,
1035 * @tag_list: (out callee-allocates): return location for the tag-list.
1037 * Extracts the tag list from the GstMessage. The tag list returned in the
1038 * output argument is a copy; the caller must free it when done.
1045 gst_message_parse_tag_full (GstMessage * message, GstPad ** pad,
1046 GstTagList ** tag_list)
1050 g_return_if_fail (GST_IS_MESSAGE (message));
1051 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1052 g_return_if_fail (tag_list != NULL);
1054 ret = gst_structure_copy (message->structure);
1056 if (gst_structure_has_field (ret, "source-pad") && pad) {
1059 v = gst_structure_get_value (ret, "source-pad");
1060 if (v && G_VALUE_HOLDS (v, GST_TYPE_PAD))
1061 *pad = g_value_dup_object (v);
1067 gst_structure_remove_field (ret, "source-pad");
1069 *tag_list = (GstTagList *) ret;
1073 * gst_message_parse_buffering:
1074 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1075 * @percent: (out) (allow-none): Return location for the percent.
1077 * Extracts the buffering percent from the GstMessage. see also
1078 * gst_message_new_buffering().
1085 gst_message_parse_buffering (GstMessage * message, gint * percent)
1087 g_return_if_fail (GST_IS_MESSAGE (message));
1088 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1091 *percent = g_value_get_int (gst_structure_id_get_value (message->structure,
1092 GST_QUARK (BUFFER_PERCENT)));
1096 * gst_message_set_buffering_stats:
1097 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1098 * @mode: a buffering mode
1099 * @avg_in: the average input rate
1100 * @avg_out: the average output rate
1101 * @buffering_left: amount of buffering time left in milliseconds
1103 * Configures the buffering stats values in @message.
1108 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1109 gint avg_in, gint avg_out, gint64 buffering_left)
1111 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1113 gst_structure_id_set (message->structure,
1114 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1115 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1116 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1117 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1121 * gst_message_parse_buffering_stats:
1122 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1123 * @mode: (out) (allow-none): a buffering mode, or NULL
1124 * @avg_in: (out) (allow-none): the average input rate, or NULL
1125 * @avg_out: (out) (allow-none): the average output rate, or NULL
1126 * @buffering_left: (out) (allow-none): amount of buffering time left in
1127 * milliseconds, or NULL
1129 * Extracts the buffering stats values from @message.
1134 gst_message_parse_buffering_stats (GstMessage * message,
1135 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1136 gint64 * buffering_left)
1138 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1141 *mode = (GstBufferingMode)
1142 g_value_get_enum (gst_structure_id_get_value (message->structure,
1143 GST_QUARK (BUFFERING_MODE)));
1145 *avg_in = g_value_get_int (gst_structure_id_get_value (message->structure,
1146 GST_QUARK (AVG_IN_RATE)));
1148 *avg_out = g_value_get_int (gst_structure_id_get_value (message->structure,
1149 GST_QUARK (AVG_OUT_RATE)));
1152 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1153 GST_QUARK (BUFFERING_LEFT)));
1157 * gst_message_parse_state_changed:
1158 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1159 * @oldstate: (out) (allow-none): the previous state, or NULL
1160 * @newstate: (out) (allow-none): the new (current) state, or NULL
1161 * @pending: (out) (allow-none): the pending (target) state, or NULL
1163 * Extracts the old and new states from the GstMessage.
1165 * Typical usage of this function might be:
1168 * switch (GST_MESSAGE_TYPE (msg)) {
1169 * case GST_MESSAGE_STATE_CHANGED: {
1170 * GstState old_state, new_state;
1172 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1173 * g_print ("Element %s changed state from %s to %s.\n",
1174 * GST_OBJECT_NAME (msg->src),
1175 * gst_element_state_get_name (old_state),
1176 * gst_element_state_get_name (new_state));
1187 gst_message_parse_state_changed (GstMessage * message,
1188 GstState * oldstate, GstState * newstate, GstState * pending)
1190 g_return_if_fail (GST_IS_MESSAGE (message));
1191 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1194 *oldstate = (GstState)
1195 g_value_get_enum (gst_structure_id_get_value (message->structure,
1196 GST_QUARK (OLD_STATE)));
1198 *newstate = (GstState)
1199 g_value_get_enum (gst_structure_id_get_value (message->structure,
1200 GST_QUARK (NEW_STATE)));
1202 *pending = (GstState)
1203 g_value_get_enum (gst_structure_id_get_value (message->structure,
1204 GST_QUARK (PENDING_STATE)));
1208 * gst_message_parse_clock_provide:
1209 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1210 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1212 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1214 * Extracts the clock and ready flag from the GstMessage.
1215 * The clock object returned remains valid until the message is freed.
1220 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1223 const GValue *clock_gvalue;
1225 g_return_if_fail (GST_IS_MESSAGE (message));
1226 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1229 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1230 g_return_if_fail (clock_gvalue != NULL);
1231 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1235 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1236 GST_QUARK (READY)));
1238 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1242 * gst_message_parse_clock_lost:
1243 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1244 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1246 * Extracts the lost clock from the GstMessage.
1247 * The clock object returned remains valid until the message is freed.
1252 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1254 const GValue *clock_gvalue;
1256 g_return_if_fail (GST_IS_MESSAGE (message));
1257 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1260 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1261 g_return_if_fail (clock_gvalue != NULL);
1262 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1265 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1269 * gst_message_parse_new_clock:
1270 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1271 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1274 * Extracts the new clock from the GstMessage.
1275 * The clock object returned remains valid until the message is freed.
1280 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1282 const GValue *clock_gvalue;
1284 g_return_if_fail (GST_IS_MESSAGE (message));
1285 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1288 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1289 g_return_if_fail (clock_gvalue != NULL);
1290 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1293 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1297 * gst_message_parse_structure_change:
1298 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1299 * @type: (out): A pointer to hold the change type
1300 * @owner: (out) (allow-none) (transfer none): The owner element of the
1302 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1303 * progress or has been completed
1305 * Extracts the change type and completion status from the GstMessage.
1312 gst_message_parse_structure_change (GstMessage * message,
1313 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1315 const GValue *owner_gvalue;
1317 g_return_if_fail (GST_IS_MESSAGE (message));
1318 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1321 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1322 g_return_if_fail (owner_gvalue != NULL);
1323 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1326 *type = (GstStructureChangeType)
1327 g_value_get_enum (gst_structure_id_get_value (message->structure,
1330 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1333 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1338 * gst_message_parse_error:
1339 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1340 * @gerror: (out) (allow-none) (transfer full): location for the GError
1341 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1344 * Extracts the GError and debug string from the GstMessage. The values returned
1345 * in the output arguments are copies; the caller must free them when done.
1347 * Typical usage of this function might be:
1350 * switch (GST_MESSAGE_TYPE (msg)) {
1351 * case GST_MESSAGE_ERROR: {
1352 * GError *err = NULL;
1353 * gchar *dbg_info = NULL;
1355 * gst_message_parse_error (msg, &err, &dbg_info);
1356 * g_printerr ("ERROR from element %s: %s\n",
1357 * GST_OBJECT_NAME (msg->src), err->message);
1358 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1359 * g_error_free (err);
1360 * g_free (dbg_info);
1371 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1373 const GValue *error_gvalue;
1376 g_return_if_fail (GST_IS_MESSAGE (message));
1377 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1380 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1381 g_return_if_fail (error_gvalue != NULL);
1382 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1384 error_val = (GError *) g_value_get_boxed (error_gvalue);
1386 *gerror = g_error_copy (error_val);
1392 g_value_dup_string (gst_structure_id_get_value (message->structure,
1393 GST_QUARK (DEBUG)));
1397 * gst_message_parse_warning:
1398 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1399 * @gerror: (out) (allow-none) (transfer full): location for the GError
1400 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1403 * Extracts the GError and debug string from the GstMessage. The values returned
1404 * in the output arguments are copies; the caller must free them when done.
1409 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1412 const GValue *error_gvalue;
1415 g_return_if_fail (GST_IS_MESSAGE (message));
1416 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1419 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1420 g_return_if_fail (error_gvalue != NULL);
1421 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1423 error_val = (GError *) g_value_get_boxed (error_gvalue);
1425 *gerror = g_error_copy (error_val);
1431 g_value_dup_string (gst_structure_id_get_value (message->structure,
1432 GST_QUARK (DEBUG)));
1436 * gst_message_parse_info:
1437 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1438 * @gerror: (out) (allow-none) (transfer full): location for the GError
1439 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1442 * Extracts the GError and debug string from the GstMessage. The values returned
1443 * in the output arguments are copies; the caller must free them when done.
1450 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1452 const GValue *error_gvalue;
1455 g_return_if_fail (GST_IS_MESSAGE (message));
1456 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1459 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1460 g_return_if_fail (error_gvalue != NULL);
1461 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1463 error_val = (GError *) g_value_get_boxed (error_gvalue);
1465 *gerror = g_error_copy (error_val);
1471 g_value_dup_string (gst_structure_id_get_value (message->structure,
1472 GST_QUARK (DEBUG)));
1476 * gst_message_parse_segment_start:
1477 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1478 * @format: (out): Result location for the format, or NULL
1479 * @position: (out): Result location for the position, or NULL
1481 * Extracts the position and format from the segment start message.
1486 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1489 g_return_if_fail (GST_IS_MESSAGE (message));
1490 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1493 *format = (GstFormat)
1494 g_value_get_enum (gst_structure_id_get_value (message->structure,
1495 GST_QUARK (FORMAT)));
1498 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1499 GST_QUARK (POSITION)));
1503 * gst_message_parse_segment_done:
1504 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1505 * @format: (out): Result location for the format, or NULL
1506 * @position: (out): Result location for the position, or NULL
1508 * Extracts the position and format from the segment start message.
1513 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1516 g_return_if_fail (GST_IS_MESSAGE (message));
1517 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1520 *format = (GstFormat)
1521 g_value_get_enum (gst_structure_id_get_value (message->structure,
1522 GST_QUARK (FORMAT)));
1525 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1526 GST_QUARK (POSITION)));
1530 * gst_message_parse_duration:
1531 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1532 * @format: (out): Result location for the format, or NULL
1533 * @duration: (out): Result location for the duration, or NULL
1535 * Extracts the duration and format from the duration message. The duration
1536 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1537 * changed. Applications should always use a query to retrieve the duration
1543 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1546 g_return_if_fail (GST_IS_MESSAGE (message));
1547 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1550 *format = (GstFormat)
1551 g_value_get_enum (gst_structure_id_get_value (message->structure,
1552 GST_QUARK (FORMAT)));
1555 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1556 GST_QUARK (DURATION)));
1560 * gst_message_parse_async_start:
1561 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1562 * @new_base_time: (out): Result location for the new_base_time or NULL
1564 * Extract the new_base_time from the async_start message.
1571 gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
1573 g_return_if_fail (GST_IS_MESSAGE (message));
1574 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_START);
1578 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1579 GST_QUARK (NEW_BASE_TIME)));
1583 * gst_message_parse_request_state:
1584 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1585 * @state: (out): Result location for the requested state or NULL
1587 * Extract the requested state from the request_state message.
1594 gst_message_parse_request_state (GstMessage * message, GstState * state)
1596 g_return_if_fail (GST_IS_MESSAGE (message));
1597 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1601 g_value_get_enum (gst_structure_id_get_value (message->structure,
1602 GST_QUARK (NEW_STATE)));
1606 * gst_message_new_stream_status:
1607 * @src: The object originating the message.
1608 * @type: The stream status type.
1609 * @owner: (transfer none): the owner element of @src.
1611 * Create a new stream status message. This message is posted when a streaming
1612 * thread is created/destroyed or when the state changed.
1614 * Returns: (transfer full): the new stream status message.
1621 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1624 GstMessage *message;
1625 GstStructure *structure;
1627 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STREAM_STATUS),
1628 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1629 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1630 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1636 * gst_message_parse_stream_status:
1637 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1638 * @type: (out): A pointer to hold the status type
1639 * @owner: (out) (transfer none): The owner element of the message source
1641 * Extracts the stream status type and owner the GstMessage. The returned
1642 * owner remains valid for as long as the reference to @message is valid and
1643 * should thus not be unreffed.
1650 gst_message_parse_stream_status (GstMessage * message,
1651 GstStreamStatusType * type, GstElement ** owner)
1653 const GValue *owner_gvalue;
1655 g_return_if_fail (GST_IS_MESSAGE (message));
1656 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1659 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1660 g_return_if_fail (owner_gvalue != NULL);
1663 *type = (GstStreamStatusType)
1664 g_value_get_enum (gst_structure_id_get_value (message->structure,
1667 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1671 * gst_message_set_stream_status_object:
1672 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1673 * @object: the object controlling the streaming
1675 * Configures the object handling the streaming thread. This is usually a
1676 * GstTask object but other objects might be added in the future.
1681 gst_message_set_stream_status_object (GstMessage * message,
1682 const GValue * object)
1684 g_return_if_fail (GST_IS_MESSAGE (message));
1685 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1687 gst_structure_id_set_value (message->structure, GST_QUARK (OBJECT), object);
1691 * gst_message_get_stream_status_object:
1692 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1694 * Extracts the object managing the streaming thread from @message.
1696 * Returns: a GValue containing the object that manages the streaming thread.
1697 * This object is usually of type GstTask but other types can be added in the
1698 * future. The object remains valid as long as @message is valid.
1703 gst_message_get_stream_status_object (GstMessage * message)
1705 const GValue *result;
1707 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1708 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1711 result = gst_structure_id_get_value (message->structure, GST_QUARK (OBJECT));
1717 * gst_message_new_step_done:
1718 * @src: The object originating the message.
1719 * @format: the format of @amount
1720 * @amount: the amount of stepped data
1721 * @rate: the rate of the stepped amount
1722 * @flush: is this an flushing step
1723 * @intermediate: is this an intermediate step
1724 * @duration: the duration of the data
1725 * @eos: the step caused EOS
1727 * This message is posted by elements when they complete a part, when @intermediate set
1728 * to TRUE, or a complete step operation.
1730 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1731 * @amount of media in format @format.
1733 * Returns: (transfer full): the new step_done message.
1740 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1741 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1744 GstMessage *message;
1745 GstStructure *structure;
1747 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_DONE),
1748 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1749 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1750 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1751 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1752 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1753 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1754 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1755 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1761 * gst_message_parse_step_done:
1762 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1763 * @format: (out) (allow-none): result location for the format
1764 * @amount: (out) (allow-none): result location for the amount
1765 * @rate: (out) (allow-none): result location for the rate
1766 * @flush: (out) (allow-none): result location for the flush flag
1767 * @intermediate: (out) (allow-none): result location for the intermediate flag
1768 * @duration: (out) (allow-none): result location for the duration
1769 * @eos: (out) (allow-none): result location for the EOS flag
1771 * Extract the values the step_done message.
1778 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1779 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1780 guint64 * duration, gboolean * eos)
1782 g_return_if_fail (GST_IS_MESSAGE (message));
1783 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1785 gst_structure_id_get (message->structure,
1786 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1787 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1788 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1789 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1790 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1791 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1792 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1796 * gst_message_new_step_start:
1797 * @src: The object originating the message.
1798 * @active: if the step is active or queued
1799 * @format: the format of @amount
1800 * @amount: the amount of stepped data
1801 * @rate: the rate of the stepped amount
1802 * @flush: is this an flushing step
1803 * @intermediate: is this an intermediate step
1805 * This message is posted by elements when they accept or activate a new step
1806 * event for @amount in @format.
1808 * @active is set to FALSE when the element accepted the new step event and has
1809 * queued it for execution in the streaming threads.
1811 * @active is set to TRUE when the element has activated the step operation and
1812 * is now ready to start executing the step in the streaming thread. After this
1813 * message is emited, the application can queue a new step operation in the
1816 * Returns: (transfer full): The new step_start message.
1823 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1824 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1826 GstMessage *message;
1827 GstStructure *structure;
1829 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_START),
1830 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1831 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1832 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1833 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1834 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1835 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1836 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1842 * gst_message_parse_step_start:
1843 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1844 * @active: (out) (allow-none): result location for the active flag
1845 * @format: (out) (allow-none): result location for the format
1846 * @amount: (out) (allow-none): result location for the amount
1847 * @rate: (out) (allow-none): result location for the rate
1848 * @flush: (out) (allow-none): result location for the flush flag
1849 * @intermediate: (out) (allow-none): result location for the intermediate flag
1851 * Extract the values from step_start message.
1858 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1859 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1860 gboolean * intermediate)
1862 g_return_if_fail (GST_IS_MESSAGE (message));
1863 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1865 gst_structure_id_get (message->structure,
1866 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1867 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1868 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1869 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1870 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1871 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1875 * gst_message_new_qos:
1876 * @src: The object originating the message.
1877 * @live: if the message was generated by a live element
1878 * @running_time: the running time of the buffer that generated the message
1879 * @stream_time: the stream time of the buffer that generated the message
1880 * @timestamp: the timestamps of the buffer that generated the message
1881 * @duration: the duration of the buffer that generated the message
1883 * A QOS message is posted on the bus whenever an element decides to drop a
1884 * buffer because of QoS reasons or whenever it changes its processing strategy
1885 * because of QoS reasons (quality adjustments such as processing at lower
1888 * This message can be posted by an element that performs synchronisation against the
1889 * clock (live) or it could be dropped by an element that performs QoS because of QOS
1890 * events received from a downstream element (!live).
1892 * @running_time, @stream_time, @timestamp, @duration should be set to the
1893 * respective running-time, stream-time, timestamp and duration of the (dropped)
1894 * buffer that generated the QoS event. Values can be left to
1895 * GST_CLOCK_TIME_NONE when unknown.
1897 * Returns: (transfer full): The new qos message.
1904 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1905 guint64 stream_time, guint64 timestamp, guint64 duration)
1907 GstMessage *message;
1908 GstStructure *structure;
1910 structure = gst_structure_id_new (GST_QUARK (MESSAGE_QOS),
1911 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1912 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1913 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1914 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1915 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1916 GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1917 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1918 GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1919 GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1920 GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1921 GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1922 message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1928 * gst_message_set_qos_values:
1929 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1930 * @jitter: The difference of the running-time against the deadline.
1931 * @proportion: Long term prediction of the ideal rate relative to normal rate
1932 * to get optimal quality.
1933 * @quality: An element dependent integer value that specifies the current
1934 * quality level of the element. The default maximum quality is 1000000.
1936 * Set the QoS values that have been calculated/analysed from the QoS data
1943 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
1944 gdouble proportion, gint quality)
1946 g_return_if_fail (GST_IS_MESSAGE (message));
1947 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1949 gst_structure_id_set (message->structure,
1950 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1951 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1952 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1956 * gst_message_set_qos_stats:
1957 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1958 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1959 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1960 * will likely use GST_FORMAT_DEFAULT (samples).
1961 * @processed: Total number of units correctly processed since the last state
1962 * change to READY or a flushing operation.
1963 * @dropped: Total number of units dropped since the last state change to READY
1964 * or a flushing operation.
1966 * Set the QoS stats representing the history of the current continuous pipeline
1969 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1970 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1977 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1978 guint64 processed, guint64 dropped)
1980 g_return_if_fail (GST_IS_MESSAGE (message));
1981 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1983 gst_structure_id_set (message->structure,
1984 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1985 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1986 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1990 * gst_message_parse_qos:
1991 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1992 * @live: (out) (allow-none): if the message was generated by a live element
1993 * @running_time: (out) (allow-none): the running time of the buffer that
1994 * generated the message
1995 * @stream_time: (out) (allow-none): the stream time of the buffer that
1996 * generated the message
1997 * @timestamp: (out) (allow-none): the timestamps of the buffer that
1998 * generated the message
1999 * @duration: (out) (allow-none): the duration of the buffer that
2000 * generated the message
2002 * Extract the timestamps and live status from the QoS message.
2004 * The returned values give the running_time, stream_time, timestamp and
2005 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2013 gst_message_parse_qos (GstMessage * message, gboolean * live,
2014 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2017 g_return_if_fail (GST_IS_MESSAGE (message));
2018 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2020 gst_structure_id_get (message->structure,
2021 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2022 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2023 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2024 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2025 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2029 * gst_message_parse_qos_values:
2030 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2031 * @jitter: (out) (allow-none): The difference of the running-time against
2033 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2034 * relative to normal rate to get optimal quality.
2035 * @quality: (out) (allow-none): An element dependent integer value that
2036 * specifies the current quality level of the element. The default
2037 * maximum quality is 1000000.
2039 * Extract the QoS values that have been calculated/analysed from the QoS data
2046 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2047 gdouble * proportion, gint * quality)
2049 g_return_if_fail (GST_IS_MESSAGE (message));
2050 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2052 gst_structure_id_get (message->structure,
2053 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2054 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2055 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2059 * gst_message_parse_qos_stats:
2060 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2061 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2062 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2063 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2065 * @processed: (out) (allow-none): Total number of units correctly processed
2066 * since the last state change to READY or a flushing operation.
2067 * @dropped: (out) (allow-none): Total number of units dropped since the last
2068 * state change to READY or a flushing operation.
2070 * Extract the QoS stats representing the history of the current continuous
2071 * pipeline playback period.
2073 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2074 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2081 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2082 guint64 * processed, guint64 * dropped)
2084 g_return_if_fail (GST_IS_MESSAGE (message));
2085 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2087 gst_structure_id_get (message->structure,
2088 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2089 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2090 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2094 * gst_message_new_progress:
2095 * @src: The object originating the message.
2096 * @type: a #GstProgressType
2097 * @code: a progress code
2098 * @text: free, user visible text describing the progress
2100 * Progress messages are posted by elements when they use an asynchronous task
2101 * to perform actions triggered by a state change.
2103 * @code contains a well defined string describing the action.
2104 * @test should contain a user visible string detailing the current action.
2106 * Returns: (transfer full): The new qos message.
2111 gst_message_new_progress (GstObject * src, GstProgressType type,
2112 const gchar * code, const gchar * text)
2114 GstMessage *message;
2115 GstStructure *structure;
2116 gint percent = 100, timeout = -1;
2118 g_return_val_if_fail (code != NULL, NULL);
2119 g_return_val_if_fail (text != NULL, NULL);
2121 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2124 structure = gst_structure_id_new (GST_QUARK (MESSAGE_PROGRESS),
2125 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2126 GST_QUARK (CODE), G_TYPE_STRING, code,
2127 GST_QUARK (TEXT), G_TYPE_STRING, text,
2128 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2129 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2130 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2136 * gst_message_parse_progress:
2137 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2138 * @type: (out) (allow-none): location for the type
2139 * @code: (out) (allow-none) (transfer full): location for the code
2140 * @text: (out) (allow-none) (transfer full): location for the text
2142 * Parses the progress @type, @code and @text.
2147 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2148 gchar ** code, gchar ** text)
2150 g_return_if_fail (GST_IS_MESSAGE (message));
2151 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2153 gst_structure_id_get (message->structure,
2154 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2155 GST_QUARK (CODE), G_TYPE_STRING, code,
2156 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2160 * gst_message_new_toc:
2161 * @src: the object originating the message.
2162 * @toc: #GstToc structure for the message.
2163 * @updated: whether TOC was updated or not.
2165 * Create a new TOC message. The message is posted by elements
2166 * that discovered or updated a TOC.
2168 * Returns: a new TOC message.
2175 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2177 GstStructure *toc_struct;
2179 g_return_val_if_fail (toc != NULL, NULL);
2181 toc_struct = priv_gst_toc_to_structure (toc);
2183 if (G_LIKELY (toc_struct != NULL)) {
2184 priv_gst_toc_structure_set_updated (toc_struct, updated);
2185 return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2191 * gst_message_parse_toc:
2192 * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2193 * @toc: (out): return location for the TOC.
2194 * @updated: (out): return location for the updated flag.
2196 * Extract the TOC from the #GstMessage. The TOC returned in the
2197 * output argument is a copy; the caller must free it with
2198 * gst_toc_free() when done.
2205 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2207 g_return_if_fail (GST_IS_MESSAGE (message));
2208 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2209 g_return_if_fail (toc != NULL);
2211 *toc = priv_gst_toc_from_structure (message->structure);
2213 if (updated != NULL)
2214 *updated = priv_gst_toc_structure_get_updated (message->structure);