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},
120 * gst_message_type_get_name:
121 * @type: the message type
123 * Get a printable name for the given message type. Do not modify or free.
125 * Returns: a reference to the static name of the message.
128 gst_message_type_get_name (GstMessageType type)
132 for (i = 0; message_quarks[i].name; i++) {
133 if (type == message_quarks[i].type)
134 return message_quarks[i].name;
140 * gst_message_type_to_quark:
141 * @type: the message type
143 * Get the unique quark for the given message type.
145 * Returns: the quark associated with the message type
148 gst_message_type_to_quark (GstMessageType type)
152 for (i = 0; message_quarks[i].name; i++) {
153 if (type == message_quarks[i].type)
154 return message_quarks[i].quark;
163 for (i = 0; message_quarks[i].name; i++) { \
164 message_quarks[i].quark = \
165 g_quark_from_static_string (message_quarks[i].name); \
169 G_DEFINE_TYPE_WITH_CODE (GstMessage, gst_message, GST_TYPE_MINI_OBJECT,
173 gst_message_class_init (GstMessageClass * klass)
175 parent_class = g_type_class_peek_parent (klass);
177 klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_message_copy;
178 klass->mini_object_class.finalize =
179 (GstMiniObjectFinalizeFunction) gst_message_finalize;
183 gst_message_init (GstMessage * message)
185 GST_CAT_LOG (GST_CAT_MESSAGE, "new message %p", message);
186 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
190 gst_message_finalize (GstMessage * message)
192 g_return_if_fail (message != NULL);
194 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p", message);
196 if (GST_MESSAGE_SRC (message)) {
197 gst_object_unref (GST_MESSAGE_SRC (message));
198 GST_MESSAGE_SRC (message) = NULL;
202 GST_MESSAGE_LOCK (message);
203 GST_MESSAGE_SIGNAL (message);
204 GST_MESSAGE_UNLOCK (message);
207 if (message->structure) {
208 gst_structure_set_parent_refcount (message->structure, NULL);
209 gst_structure_free (message->structure);
212 /* GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (message)); */
216 _gst_message_copy (GstMessage * message)
220 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p", message);
222 copy = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
224 /* FIXME, need to copy relevant data from the miniobject. */
225 //memcpy (copy, message, sizeof (GstMessage));
227 GST_MESSAGE_GET_LOCK (copy) = GST_MESSAGE_GET_LOCK (message);
228 GST_MESSAGE_COND (copy) = GST_MESSAGE_COND (message);
229 GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
230 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
231 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
233 if (GST_MESSAGE_SRC (message)) {
234 GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
237 if (message->structure) {
238 copy->structure = gst_structure_copy (message->structure);
239 gst_structure_set_parent_refcount (copy->structure,
240 ©->mini_object.refcount);
247 * gst_message_new_custom:
248 * @type: The #GstMessageType to distinguish messages
249 * @src: The object originating the message.
250 * @structure: (transfer full): the structure for the message. The message
251 * will take ownership of the structure.
253 * Create a new custom-typed message. This can be used for anything not
254 * handled by other message-specific functions to pass a message to the
255 * app. The structure field can be NULL.
257 * Returns: (transfer full): The new message.
262 gst_message_new_custom (GstMessageType type, GstObject * src,
263 GstStructure * structure)
267 message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
269 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
270 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
271 gst_message_type_get_name (type));
273 message->type = type;
276 gst_object_ref (src);
280 gst_structure_set_parent_refcount (structure,
281 &message->mini_object.refcount);
283 message->structure = structure;
285 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
291 * gst_message_get_seqnum:
292 * @message: A #GstMessage.
294 * Retrieve the sequence number of a message.
296 * Messages have ever-incrementing sequence numbers, which may also be set
297 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
298 * to indicate that a message corresponds to some other set of messages or
299 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
300 * is considered good practice to make this correspondence when possible, though
301 * it is not required.
303 * Note that events and messages share the same sequence number incrementor;
304 * two events or messages will never not have the same sequence number unless
305 * that correspondence was made explicitly.
307 * Returns: The message's sequence number.
314 gst_message_get_seqnum (GstMessage * message)
316 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
318 return GST_MESSAGE_SEQNUM (message);
322 * gst_message_set_seqnum:
323 * @message: A #GstMessage.
324 * @seqnum: A sequence number.
326 * Set the sequence number of a message.
328 * This function might be called by the creator of a message to indicate that
329 * the message relates to other messages or events. See gst_message_get_seqnum()
330 * for more information.
337 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
339 g_return_if_fail (GST_IS_MESSAGE (message));
341 GST_MESSAGE_SEQNUM (message) = seqnum;
345 * gst_message_new_eos:
346 * @src: (transfer none): The object originating the message.
348 * Create a new eos message. This message is generated and posted in
349 * the sink elements of a GstBin. The bin will only forward the EOS
350 * message to the application if all sinks have posted an EOS message.
352 * Returns: (transfer full): The new eos message.
357 gst_message_new_eos (GstObject * src)
361 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
367 * gst_message_new_error:
368 * @src: (transfer none): The object originating the message.
369 * @error: (transfer none): The GError for this message.
370 * @debug: A debugging string.
372 * Create a new error message. The message will copy @error and
373 * @debug. This message is posted by element when a fatal event
374 * occured. The pipeline will probably (partially) stop. The application
375 * receiving this message should stop the pipeline.
377 * Returns: (transfer full): the new error message.
382 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
385 GstStructure *structure;
387 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ERROR),
388 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
389 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
390 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
396 * gst_message_new_warning:
397 * @src: (transfer none): The object originating the message.
398 * @error: (transfer none): The GError for this message.
399 * @debug: A debugging string.
401 * Create a new warning message. The message will make copies of @error and
404 * Returns: (transfer full): The new warning message.
409 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
412 GstStructure *structure;
414 structure = gst_structure_id_new (GST_QUARK (MESSAGE_WARNING),
415 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
416 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
417 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
423 * gst_message_new_info:
424 * @src: (transfer none): The object originating the message.
425 * @error: (transfer none): The GError for this message.
426 * @debug: A debugging string.
428 * Create a new info message. The message will make copies of @error and
433 * Returns: (transfer full): the new info message.
438 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
441 GstStructure *structure;
443 structure = gst_structure_id_new (GST_QUARK (MESSAGE_INFO),
444 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
445 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
446 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
452 * gst_message_new_tag:
453 * @src: (transfer none): The object originating the message.
454 * @tag_list: (transfer full): the tag list for the message.
456 * Create a new tag message. The message will take ownership of the tag list.
457 * The message is posted by elements that discovered a new taglist.
459 * Returns: (transfer full): the new tag message.
464 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
468 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
471 gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
477 * gst_message_new_tag_full:
478 * @src: (transfer none): the object originating the message.
479 * @pad: (transfer none): the originating pad for the tag.
480 * @tag_list: (transfer full): the tag list for the message.
482 * Create a new tag message. The message will take ownership of the tag list.
483 * The message is posted by elements that discovered a new taglist.
487 * Returns: (transfer full): the new tag message.
492 gst_message_new_tag_full (GstObject * src, GstPad * pad, GstTagList * tag_list)
497 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
498 g_return_val_if_fail (pad == NULL || GST_IS_PAD (pad), NULL);
500 s = (GstStructure *) tag_list;
502 gst_structure_set (s, "source-pad", GST_TYPE_PAD, pad, NULL);
504 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
510 * gst_message_new_buffering:
511 * @src: (transfer none): The object originating the message.
512 * @percent: The buffering percent
514 * Create a new buffering message. This message can be posted by an element that
515 * needs to buffer data before it can continue processing. @percent should be a
516 * value between 0 and 100. A value of 100 means that the buffering completed.
518 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
519 * @percent is 100, the application can set the pipeline (back) to PLAYING.
520 * The application must be prepared to receive BUFFERING messages in the
521 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
522 * message with @percent set to 100, which can happen after the pipeline
523 * completed prerolling.
527 * Returns: (transfer full): The new buffering message.
532 gst_message_new_buffering (GstObject * src, gint percent)
535 GstStructure *structure;
537 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
539 structure = gst_structure_id_new (GST_QUARK (MESSAGE_BUFFERING),
540 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
541 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
542 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
543 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
544 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
545 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
546 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
552 * gst_message_new_state_changed:
553 * @src: (transfer none): the object originating the message
554 * @oldstate: the previous state
555 * @newstate: the new (current) state
556 * @pending: the pending (target) state
558 * Create a state change message. This message is posted whenever an element
561 * Returns: (transfer full): the new state change message.
566 gst_message_new_state_changed (GstObject * src,
567 GstState oldstate, GstState newstate, GstState pending)
570 GstStructure *structure;
572 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STATE),
573 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
574 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
575 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
576 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
582 * gst_message_new_state_dirty:
583 * @src: (transfer none): the object originating the message
585 * Create a state dirty message. This message is posted whenever an element
586 * changed its state asynchronously and is used internally to update the
587 * states of container objects.
589 * Returns: (transfer full): the new state dirty message.
594 gst_message_new_state_dirty (GstObject * src)
598 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
604 * gst_message_new_clock_provide:
605 * @src: (transfer none): the object originating the message.
606 * @clock: (transfer none): the clock it provides
607 * @ready: TRUE if the sender can provide a clock
609 * Create a clock provide message. This message is posted whenever an
610 * element is ready to provide a clock or lost its ability to provide
611 * a clock (maybe because it paused or became EOS).
613 * This message is mainly used internally to manage the clock
616 * Returns: (transfer full): the new provide clock message.
621 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
625 GstStructure *structure;
627 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
628 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
629 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
630 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
636 * gst_message_new_clock_lost:
637 * @src: (transfer none): the object originating the message.
638 * @clock: (transfer none): the clock that was lost
640 * Create a clock lost message. This message is posted whenever the
641 * clock is not valid anymore.
643 * If this message is posted by the pipeline, the pipeline will
644 * select a new clock again when it goes to PLAYING. It might therefore
645 * be needed to set the pipeline to PAUSED and PLAYING again.
647 * Returns: (transfer full): The new clock lost message.
652 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
655 GstStructure *structure;
657 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_LOST),
658 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
659 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
665 * gst_message_new_new_clock:
666 * @src: (transfer none): The object originating the message.
667 * @clock: (transfer none): the new selected clock
669 * Create a new clock message. This message is posted whenever the
670 * pipeline selectes a new clock for the pipeline.
672 * Returns: (transfer full): The new new clock message.
677 gst_message_new_new_clock (GstObject * src, GstClock * clock)
680 GstStructure *structure;
682 structure = gst_structure_id_new (GST_QUARK (MESSAGE_NEW_CLOCK),
683 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
684 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
690 * gst_message_new_structure_change:
691 * @src: (transfer none): The object originating the message.
692 * @type: The change type.
693 * @owner: (transfer none): The owner element of @src.
694 * @busy: Whether the structure change is busy.
696 * Create a new structure change message. This message is posted when the
697 * structure of a pipeline is in the process of being changed, for example
698 * when pads are linked or unlinked.
700 * @src should be the sinkpad that unlinked or linked.
702 * Returns: (transfer full): the new structure change message.
709 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
710 GstElement * owner, gboolean busy)
713 GstStructure *structure;
715 g_return_val_if_fail (GST_IS_PAD (src), NULL);
716 /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
717 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
719 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
720 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
721 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
722 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
724 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
731 * gst_message_new_segment_start:
732 * @src: (transfer none): The object originating the message.
733 * @format: The format of the position being played
734 * @position: The position of the segment being played
736 * Create a new segment message. This message is posted by elements that
737 * start playback of a segment as a result of a segment seek. This message
738 * is not received by the application but is used for maintenance reasons in
739 * container elements.
741 * Returns: (transfer full): the new segment start message.
746 gst_message_new_segment_start (GstObject * src, GstFormat format,
750 GstStructure *structure;
752 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_START),
753 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
754 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
755 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
761 * gst_message_new_segment_done:
762 * @src: (transfer none): the object originating the message.
763 * @format: The format of the position being done
764 * @position: The position of the segment being done
766 * Create a new segment done message. This message is posted by elements that
767 * finish playback of a segment as a result of a segment seek. This message
768 * is received by the application after all elements that posted a segment_start
769 * have posted the segment_done.
771 * Returns: (transfer full): the new segment done message.
776 gst_message_new_segment_done (GstObject * src, GstFormat format,
780 GstStructure *structure;
782 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_DONE),
783 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
784 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
785 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
791 * gst_message_new_application:
792 * @src: (transfer none): the object originating the message.
793 * @structure: (transfer full): the structure for the message. The message
794 * will take ownership of the structure.
796 * Create a new application-typed message. GStreamer will never create these
797 * messages; they are a gift from us to you. Enjoy.
799 * Returns: (transfer full): The new application message.
804 gst_message_new_application (GstObject * src, GstStructure * structure)
806 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
810 * gst_message_new_element:
811 * @src: (transfer none): The object originating the message.
812 * @structure: (transfer full): The structure for the message. The message
813 * will take ownership of the structure.
815 * Create a new element-specific message. This is meant as a generic way of
816 * allowing one-way communication from an element to an application, for example
817 * "the firewire cable was unplugged". The format of the message should be
818 * documented in the element's documentation. The structure field can be NULL.
820 * Returns: (transfer full): The new element message.
825 gst_message_new_element (GstObject * src, GstStructure * structure)
827 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
831 * gst_message_new_duration:
832 * @src: (transfer none): The object originating the message.
833 * @format: The format of the duration
834 * @duration: The new duration
836 * Create a new duration message. This message is posted by elements that
837 * know the duration of a stream in a specific format. This message
838 * is received by bins and is used to calculate the total duration of a
839 * pipeline. Elements may post a duration message with a duration of
840 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
841 * cached duration should be discarded. The new duration can then be
842 * retrieved via a query.
844 * Returns: (transfer full): The new duration message.
849 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
852 GstStructure *structure;
854 structure = gst_structure_id_new (GST_QUARK (MESSAGE_DURATION),
855 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
856 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
857 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
863 * gst_message_new_async_start:
864 * @src: (transfer none): The object originating the message.
865 * @new_base_time: if a new base_time should be set on the element
867 * This message is posted by elements when they start an ASYNC state change.
868 * @new_base_time is set to TRUE when the element lost its state when it was
871 * Returns: (transfer full): The new async_start message.
878 gst_message_new_async_start (GstObject * src, gboolean new_base_time)
881 GstStructure *structure;
883 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ASYNC_START),
884 GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
885 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
891 * gst_message_new_async_done:
892 * @src: (transfer none): The object originating the message.
894 * The message is posted when elements completed an ASYNC state change.
896 * Returns: (transfer full): The new async_done message.
903 gst_message_new_async_done (GstObject * src)
907 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
913 * gst_message_new_latency:
914 * @src: (transfer none): The object originating the message.
916 * This message can be posted by elements when their latency requirements have
919 * Returns: (transfer full): The new latency message.
926 gst_message_new_latency (GstObject * src)
930 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
936 * gst_message_new_request_state:
937 * @src: (transfer none): the object originating the message.
938 * @state: The new requested state
940 * This message can be posted by elements when they want to have their state
941 * changed. A typical use case would be an audio server that wants to pause the
942 * pipeline because a higher priority stream is being played.
944 * Returns: (transfer full): the new requst state message.
951 gst_message_new_request_state (GstObject * src, GstState state)
954 GstStructure *structure;
956 structure = gst_structure_id_new (GST_QUARK (MESSAGE_REQUEST_STATE),
957 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
958 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
964 * gst_message_get_structure:
965 * @message: The #GstMessage.
967 * Access the structure of the message.
969 * Returns: (transfer none): The structure of the message. The structure is
970 * still owned by the message, which means that you should not free it and
971 * that the pointer becomes invalid when you free the message.
976 gst_message_get_structure (GstMessage * message)
978 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
980 return message->structure;
984 * gst_message_parse_tag:
985 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
986 * @tag_list: (out callee-allocates): return location for the tag-list.
988 * Extracts the tag list from the GstMessage. The tag list returned in the
989 * output argument is a copy; the caller must free it when done.
991 * Typical usage of this function might be:
994 * switch (GST_MESSAGE_TYPE (msg)) {
995 * case GST_MESSAGE_TAG: {
996 * GstTagList *tags = NULL;
998 * gst_message_parse_tag (msg, &tags);
999 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1000 * handle_tags (tags);
1001 * gst_tag_list_free (tags);
1012 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1016 g_return_if_fail (GST_IS_MESSAGE (message));
1017 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1018 g_return_if_fail (tag_list != NULL);
1020 ret = gst_structure_copy (message->structure);
1021 gst_structure_remove_field (ret, "source-pad");
1023 *tag_list = (GstTagList *) ret;
1027 * gst_message_parse_tag_full:
1028 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1029 * @pad: (out callee-allocates): location where the originating pad is stored,
1031 * @tag_list: (out callee-allocates): return location for the tag-list.
1033 * Extracts the tag list from the GstMessage. The tag list returned in the
1034 * output argument is a copy; the caller must free it when done.
1041 gst_message_parse_tag_full (GstMessage * message, GstPad ** pad,
1042 GstTagList ** tag_list)
1046 g_return_if_fail (GST_IS_MESSAGE (message));
1047 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1048 g_return_if_fail (tag_list != NULL);
1050 ret = gst_structure_copy (message->structure);
1052 if (gst_structure_has_field (ret, "source-pad") && pad) {
1055 v = gst_structure_get_value (ret, "source-pad");
1056 if (v && G_VALUE_HOLDS (v, GST_TYPE_PAD))
1057 *pad = g_value_dup_object (v);
1063 gst_structure_remove_field (ret, "source-pad");
1065 *tag_list = (GstTagList *) ret;
1069 * gst_message_parse_buffering:
1070 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1071 * @percent: (out) (allow-none): Return location for the percent.
1073 * Extracts the buffering percent from the GstMessage. see also
1074 * gst_message_new_buffering().
1081 gst_message_parse_buffering (GstMessage * message, gint * percent)
1083 g_return_if_fail (GST_IS_MESSAGE (message));
1084 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1087 *percent = g_value_get_int (gst_structure_id_get_value (message->structure,
1088 GST_QUARK (BUFFER_PERCENT)));
1092 * gst_message_set_buffering_stats:
1093 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1094 * @mode: a buffering mode
1095 * @avg_in: the average input rate
1096 * @avg_out: the average output rate
1097 * @buffering_left: amount of buffering time left in milliseconds
1099 * Configures the buffering stats values in @message.
1104 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1105 gint avg_in, gint avg_out, gint64 buffering_left)
1107 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1109 gst_structure_id_set (message->structure,
1110 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1111 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1112 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1113 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1117 * gst_message_parse_buffering_stats:
1118 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1119 * @mode: (out) (allow-none): a buffering mode, or NULL
1120 * @avg_in: (out) (allow-none): the average input rate, or NULL
1121 * @avg_out: (out) (allow-none): the average output rate, or NULL
1122 * @buffering_left: (out) (allow-none): amount of buffering time left in
1123 * milliseconds, or NULL
1125 * Extracts the buffering stats values from @message.
1130 gst_message_parse_buffering_stats (GstMessage * message,
1131 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1132 gint64 * buffering_left)
1134 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1137 *mode = g_value_get_enum (gst_structure_id_get_value (message->structure,
1138 GST_QUARK (BUFFERING_MODE)));
1140 *avg_in = g_value_get_int (gst_structure_id_get_value (message->structure,
1141 GST_QUARK (AVG_IN_RATE)));
1143 *avg_out = g_value_get_int (gst_structure_id_get_value (message->structure,
1144 GST_QUARK (AVG_OUT_RATE)));
1147 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1148 GST_QUARK (BUFFERING_LEFT)));
1152 * gst_message_parse_state_changed:
1153 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1154 * @oldstate: (out) (allow-none): the previous state, or NULL
1155 * @newstate: (out) (allow-none): the new (current) state, or NULL
1156 * @pending: (out) (allow-none): the pending (target) state, or NULL
1158 * Extracts the old and new states from the GstMessage.
1160 * Typical usage of this function might be:
1163 * switch (GST_MESSAGE_TYPE (msg)) {
1164 * case GST_MESSAGE_STATE_CHANGED: {
1165 * GstState old_state, new_state;
1167 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1168 * g_print ("Element %s changed state from %s to %s.\n",
1169 * GST_OBJECT_NAME (msg->src),
1170 * gst_element_state_get_name (old_state),
1171 * gst_element_state_get_name (new_state));
1182 gst_message_parse_state_changed (GstMessage * message,
1183 GstState * oldstate, GstState * newstate, GstState * pending)
1185 g_return_if_fail (GST_IS_MESSAGE (message));
1186 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1190 g_value_get_enum (gst_structure_id_get_value (message->structure,
1191 GST_QUARK (OLD_STATE)));
1194 g_value_get_enum (gst_structure_id_get_value (message->structure,
1195 GST_QUARK (NEW_STATE)));
1197 *pending = g_value_get_enum (gst_structure_id_get_value (message->structure,
1198 GST_QUARK (PENDING_STATE)));
1202 * gst_message_parse_clock_provide:
1203 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1204 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1206 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1208 * Extracts the clock and ready flag from the GstMessage.
1209 * The clock object returned remains valid until the message is freed.
1214 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1217 const GValue *clock_gvalue;
1219 g_return_if_fail (GST_IS_MESSAGE (message));
1220 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1223 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1224 g_return_if_fail (clock_gvalue != NULL);
1225 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1229 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1230 GST_QUARK (READY)));
1232 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1236 * gst_message_parse_clock_lost:
1237 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1238 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1240 * Extracts the lost clock from the GstMessage.
1241 * The clock object returned remains valid until the message is freed.
1246 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1248 const GValue *clock_gvalue;
1250 g_return_if_fail (GST_IS_MESSAGE (message));
1251 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1254 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1255 g_return_if_fail (clock_gvalue != NULL);
1256 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1259 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1263 * gst_message_parse_new_clock:
1264 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1265 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1268 * Extracts the new clock from the GstMessage.
1269 * The clock object returned remains valid until the message is freed.
1274 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1276 const GValue *clock_gvalue;
1278 g_return_if_fail (GST_IS_MESSAGE (message));
1279 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1282 gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1283 g_return_if_fail (clock_gvalue != NULL);
1284 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1287 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1291 * gst_message_parse_structure_change:
1292 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1293 * @type: (out): A pointer to hold the change type
1294 * @owner: (out) (allow-none) (transfer none): The owner element of the
1296 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1297 * progress or has been completed
1299 * Extracts the change type and completion status from the GstMessage.
1306 gst_message_parse_structure_change (GstMessage * message,
1307 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1309 const GValue *owner_gvalue;
1311 g_return_if_fail (GST_IS_MESSAGE (message));
1312 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1315 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1316 g_return_if_fail (owner_gvalue != NULL);
1317 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1320 *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1323 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1326 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1331 * gst_message_parse_error:
1332 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1333 * @gerror: (out) (allow-none) (transfer full): location for the GError
1334 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1337 * Extracts the GError and debug string from the GstMessage. The values returned
1338 * in the output arguments are copies; the caller must free them when done.
1340 * Typical usage of this function might be:
1343 * switch (GST_MESSAGE_TYPE (msg)) {
1344 * case GST_MESSAGE_ERROR: {
1345 * GError *err = NULL;
1346 * gchar *dbg_info = NULL;
1348 * gst_message_parse_error (msg, &err, &dbg_info);
1349 * g_printerr ("ERROR from element %s: %s\n",
1350 * GST_OBJECT_NAME (msg->src), err->message);
1351 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1352 * g_error_free (err);
1353 * g_free (dbg_info);
1364 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1366 const GValue *error_gvalue;
1369 g_return_if_fail (GST_IS_MESSAGE (message));
1370 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1373 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1374 g_return_if_fail (error_gvalue != NULL);
1375 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1377 error_val = (GError *) g_value_get_boxed (error_gvalue);
1379 *gerror = g_error_copy (error_val);
1385 g_value_dup_string (gst_structure_id_get_value (message->structure,
1386 GST_QUARK (DEBUG)));
1390 * gst_message_parse_warning:
1391 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1392 * @gerror: (out) (allow-none) (transfer full): location for the GError
1393 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1396 * Extracts the GError and debug string from the GstMessage. The values returned
1397 * in the output arguments are copies; the caller must free them when done.
1402 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1405 const GValue *error_gvalue;
1408 g_return_if_fail (GST_IS_MESSAGE (message));
1409 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1412 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1413 g_return_if_fail (error_gvalue != NULL);
1414 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1416 error_val = (GError *) g_value_get_boxed (error_gvalue);
1418 *gerror = g_error_copy (error_val);
1424 g_value_dup_string (gst_structure_id_get_value (message->structure,
1425 GST_QUARK (DEBUG)));
1429 * gst_message_parse_info:
1430 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1431 * @gerror: (out) (allow-none) (transfer full): location for the GError
1432 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1435 * Extracts the GError and debug string from the GstMessage. The values returned
1436 * in the output arguments are copies; the caller must free them when done.
1443 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1445 const GValue *error_gvalue;
1448 g_return_if_fail (GST_IS_MESSAGE (message));
1449 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1452 gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1453 g_return_if_fail (error_gvalue != NULL);
1454 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1456 error_val = (GError *) g_value_get_boxed (error_gvalue);
1458 *gerror = g_error_copy (error_val);
1464 g_value_dup_string (gst_structure_id_get_value (message->structure,
1465 GST_QUARK (DEBUG)));
1469 * gst_message_parse_segment_start:
1470 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1471 * @format: (out): Result location for the format, or NULL
1472 * @position: (out): Result location for the position, or NULL
1474 * Extracts the position and format from the segment start message.
1479 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1482 g_return_if_fail (GST_IS_MESSAGE (message));
1483 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1487 g_value_get_enum (gst_structure_id_get_value (message->structure,
1488 GST_QUARK (FORMAT)));
1491 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1492 GST_QUARK (POSITION)));
1496 * gst_message_parse_segment_done:
1497 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1498 * @format: (out): Result location for the format, or NULL
1499 * @position: (out): Result location for the position, or NULL
1501 * Extracts the position and format from the segment start message.
1506 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1509 g_return_if_fail (GST_IS_MESSAGE (message));
1510 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1514 g_value_get_enum (gst_structure_id_get_value (message->structure,
1515 GST_QUARK (FORMAT)));
1518 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1519 GST_QUARK (POSITION)));
1523 * gst_message_parse_duration:
1524 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1525 * @format: (out): Result location for the format, or NULL
1526 * @duration: (out): Result location for the duration, or NULL
1528 * Extracts the duration and format from the duration message. The duration
1529 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1530 * changed. Applications should always use a query to retrieve the duration
1536 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1539 g_return_if_fail (GST_IS_MESSAGE (message));
1540 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1544 g_value_get_enum (gst_structure_id_get_value (message->structure,
1545 GST_QUARK (FORMAT)));
1548 g_value_get_int64 (gst_structure_id_get_value (message->structure,
1549 GST_QUARK (DURATION)));
1553 * gst_message_parse_async_start:
1554 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1555 * @new_base_time: (out): Result location for the new_base_time or NULL
1557 * Extract the new_base_time from the async_start message.
1564 gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
1566 g_return_if_fail (GST_IS_MESSAGE (message));
1567 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_START);
1571 g_value_get_boolean (gst_structure_id_get_value (message->structure,
1572 GST_QUARK (NEW_BASE_TIME)));
1576 * gst_message_parse_request_state:
1577 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1578 * @state: (out): Result location for the requested state or NULL
1580 * Extract the requested state from the request_state message.
1587 gst_message_parse_request_state (GstMessage * message, GstState * state)
1589 g_return_if_fail (GST_IS_MESSAGE (message));
1590 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1593 *state = g_value_get_enum (gst_structure_id_get_value (message->structure,
1594 GST_QUARK (NEW_STATE)));
1598 * gst_message_new_stream_status:
1599 * @src: The object originating the message.
1600 * @type: The stream status type.
1601 * @owner: (transfer none): the owner element of @src.
1603 * Create a new stream status message. This message is posted when a streaming
1604 * thread is created/destroyed or when the state changed.
1606 * Returns: (transfer full): the new stream status message.
1613 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1616 GstMessage *message;
1617 GstStructure *structure;
1619 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STREAM_STATUS),
1620 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1621 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1622 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1628 * gst_message_parse_stream_status:
1629 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1630 * @type: (out): A pointer to hold the status type
1631 * @owner: (out) (transfer none): The owner element of the message source
1633 * Extracts the stream status type and owner the GstMessage. The returned
1634 * owner remains valid for as long as the reference to @message is valid and
1635 * should thus not be unreffed.
1642 gst_message_parse_stream_status (GstMessage * message,
1643 GstStreamStatusType * type, GstElement ** owner)
1645 const GValue *owner_gvalue;
1647 g_return_if_fail (GST_IS_MESSAGE (message));
1648 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1651 gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1652 g_return_if_fail (owner_gvalue != NULL);
1655 *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1658 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1662 * gst_message_set_stream_status_object:
1663 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1664 * @object: the object controlling the streaming
1666 * Configures the object handling the streaming thread. This is usually a
1667 * GstTask object but other objects might be added in the future.
1672 gst_message_set_stream_status_object (GstMessage * message,
1673 const GValue * object)
1675 g_return_if_fail (GST_IS_MESSAGE (message));
1676 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1678 gst_structure_id_set_value (message->structure, GST_QUARK (OBJECT), object);
1682 * gst_message_get_stream_status_object:
1683 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1685 * Extracts the object managing the streaming thread from @message.
1687 * Returns: a GValue containing the object that manages the streaming thread.
1688 * This object is usually of type GstTask but other types can be added in the
1689 * future. The object remains valid as long as @message is valid.
1694 gst_message_get_stream_status_object (GstMessage * message)
1696 const GValue *result;
1698 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1699 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1702 result = gst_structure_id_get_value (message->structure, GST_QUARK (OBJECT));
1708 * gst_message_new_step_done:
1709 * @src: The object originating the message.
1710 * @format: the format of @amount
1711 * @amount: the amount of stepped data
1712 * @rate: the rate of the stepped amount
1713 * @flush: is this an flushing step
1714 * @intermediate: is this an intermediate step
1715 * @duration: the duration of the data
1716 * @eos: the step caused EOS
1718 * This message is posted by elements when they complete a part, when @intermediate set
1719 * to TRUE, or a complete step operation.
1721 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1722 * @amount of media in format @format.
1724 * Returns: (transfer full): the new step_done message.
1731 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1732 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1735 GstMessage *message;
1736 GstStructure *structure;
1738 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_DONE),
1739 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1740 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1741 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1742 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1743 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1744 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1745 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1746 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1752 * gst_message_parse_step_done:
1753 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1754 * @format: (out) (allow-none): result location for the format
1755 * @amount: (out) (allow-none): result location for the amount
1756 * @rate: (out) (allow-none): result location for the rate
1757 * @flush: (out) (allow-none): result location for the flush flag
1758 * @intermediate: (out) (allow-none): result location for the intermediate flag
1759 * @duration: (out) (allow-none): result location for the duration
1760 * @eos: (out) (allow-none): result location for the EOS flag
1762 * Extract the values the step_done message.
1769 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1770 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1771 guint64 * duration, gboolean * eos)
1773 g_return_if_fail (GST_IS_MESSAGE (message));
1774 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1776 gst_structure_id_get (message->structure,
1777 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1778 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1779 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1780 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1781 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1782 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1783 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1787 * gst_message_new_step_start:
1788 * @src: The object originating the message.
1789 * @active: if the step is active or queued
1790 * @format: the format of @amount
1791 * @amount: the amount of stepped data
1792 * @rate: the rate of the stepped amount
1793 * @flush: is this an flushing step
1794 * @intermediate: is this an intermediate step
1796 * This message is posted by elements when they accept or activate a new step
1797 * event for @amount in @format.
1799 * @active is set to FALSE when the element accepted the new step event and has
1800 * queued it for execution in the streaming threads.
1802 * @active is set to TRUE when the element has activated the step operation and
1803 * is now ready to start executing the step in the streaming thread. After this
1804 * message is emited, the application can queue a new step operation in the
1807 * Returns: (transfer full): The new step_start message.
1814 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1815 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1817 GstMessage *message;
1818 GstStructure *structure;
1820 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_START),
1821 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1822 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1823 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1824 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1825 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1826 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1827 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1833 * gst_message_parse_step_start:
1834 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1835 * @active: (out) (allow-none): result location for the active flag
1836 * @format: (out) (allow-none): result location for the format
1837 * @amount: (out) (allow-none): result location for the amount
1838 * @rate: (out) (allow-none): result location for the rate
1839 * @flush: (out) (allow-none): result location for the flush flag
1840 * @intermediate: (out) (allow-none): result location for the intermediate flag
1842 * Extract the values from step_start message.
1849 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1850 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1851 gboolean * intermediate)
1853 g_return_if_fail (GST_IS_MESSAGE (message));
1854 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1856 gst_structure_id_get (message->structure,
1857 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1858 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1859 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1860 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1861 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1862 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1866 * gst_message_new_qos:
1867 * @src: The object originating the message.
1868 * @live: if the message was generated by a live element
1869 * @running_time: the running time of the buffer that generated the message
1870 * @stream_time: the stream time of the buffer that generated the message
1871 * @timestamp: the timestamps of the buffer that generated the message
1872 * @duration: the duration of the buffer that generated the message
1874 * A QOS message is posted on the bus whenever an element decides to drop a
1875 * buffer because of QoS reasons or whenever it changes its processing strategy
1876 * because of QoS reasons (quality adjustments such as processing at lower
1879 * This message can be posted by an element that performs synchronisation against the
1880 * clock (live) or it could be dropped by an element that performs QoS because of QOS
1881 * events received from a downstream element (!live).
1883 * @running_time, @stream_time, @timestamp, @duration should be set to the
1884 * respective running-time, stream-time, timestamp and duration of the (dropped)
1885 * buffer that generated the QoS event. Values can be left to
1886 * GST_CLOCK_TIME_NONE when unknown.
1888 * Returns: (transfer full): The new qos message.
1895 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1896 guint64 stream_time, guint64 timestamp, guint64 duration)
1898 GstMessage *message;
1899 GstStructure *structure;
1901 structure = gst_structure_id_new (GST_QUARK (MESSAGE_QOS),
1902 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1903 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1904 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1905 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1906 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1907 GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1908 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1909 GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1910 GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1911 GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1912 GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1913 message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1919 * gst_message_set_qos_values:
1920 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1921 * @jitter: The difference of the running-time against the deadline.
1922 * @proportion: Long term prediction of the ideal rate relative to normal rate
1923 * to get optimal quality.
1924 * @quality: An element dependent integer value that specifies the current
1925 * quality level of the element. The default maximum quality is 1000000.
1927 * Set the QoS values that have been calculated/analysed from the QoS data
1934 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
1935 gdouble proportion, gint quality)
1937 g_return_if_fail (GST_IS_MESSAGE (message));
1938 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1940 gst_structure_id_set (message->structure,
1941 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1942 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1943 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1947 * gst_message_set_qos_stats:
1948 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1949 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1950 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1951 * will likely use GST_FORMAT_DEFAULT (samples).
1952 * @processed: Total number of units correctly processed since the last state
1953 * change to READY or a flushing operation.
1954 * @dropped: Total number of units dropped since the last state change to READY
1955 * or a flushing operation.
1957 * Set the QoS stats representing the history of the current continuous pipeline
1960 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1961 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1968 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1969 guint64 processed, guint64 dropped)
1971 g_return_if_fail (GST_IS_MESSAGE (message));
1972 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1974 gst_structure_id_set (message->structure,
1975 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1976 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1977 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1981 * gst_message_parse_qos:
1982 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1983 * @live: (out) (allow-none): if the message was generated by a live element
1984 * @running_time: (out) (allow-none): the running time of the buffer that
1985 * generated the message
1986 * @stream_time: (out) (allow-none): the stream time of the buffer that
1987 * generated the message
1988 * @timestamp: (out) (allow-none): the timestamps of the buffer that
1989 * generated the message
1990 * @duration: (out) (allow-none): the duration of the buffer that
1991 * generated the message
1993 * Extract the timestamps and live status from the QoS message.
1995 * The returned values give the running_time, stream_time, timestamp and
1996 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2004 gst_message_parse_qos (GstMessage * message, gboolean * live,
2005 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2008 g_return_if_fail (GST_IS_MESSAGE (message));
2009 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2011 gst_structure_id_get (message->structure,
2012 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2013 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2014 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2015 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2016 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2020 * gst_message_parse_qos_values:
2021 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2022 * @jitter: (out) (allow-none): The difference of the running-time against
2024 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2025 * relative to normal rate to get optimal quality.
2026 * @quality: (out) (allow-none): An element dependent integer value that
2027 * specifies the current quality level of the element. The default
2028 * maximum quality is 1000000.
2030 * Extract the QoS values that have been calculated/analysed from the QoS data
2037 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2038 gdouble * proportion, gint * quality)
2040 g_return_if_fail (GST_IS_MESSAGE (message));
2041 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2043 gst_structure_id_get (message->structure,
2044 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2045 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2046 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2050 * gst_message_parse_qos_stats:
2051 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2052 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2053 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2054 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2056 * @processed: (out) (allow-none): Total number of units correctly processed
2057 * since the last state change to READY or a flushing operation.
2058 * @dropped: (out) (allow-none): Total number of units dropped since the last
2059 * state change to READY or a flushing operation.
2061 * Extract the QoS stats representing the history of the current continuous
2062 * pipeline playback period.
2064 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2065 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2072 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2073 guint64 * processed, guint64 * dropped)
2075 g_return_if_fail (GST_IS_MESSAGE (message));
2076 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2078 gst_structure_id_get (message->structure,
2079 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2080 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2081 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2085 * gst_message_new_progress:
2086 * @src: The object originating the message.
2087 * @type: a #GstProgressType
2088 * @code: a progress code
2089 * @text: free, user visible text describing the progress
2091 * Progress messages are posted by elements when they use an asynchronous task
2092 * to perform actions triggered by a state change.
2094 * @code contains a well defined string describing the action.
2095 * @test should contain a user visible string detailing the current action.
2097 * Returns: (transfer full): The new qos message.
2102 gst_message_new_progress (GstObject * src, GstProgressType type,
2103 const gchar * code, const gchar * text)
2105 GstMessage *message;
2106 GstStructure *structure;
2107 gint percent = 100, timeout = -1;
2109 g_return_val_if_fail (code != NULL, NULL);
2110 g_return_val_if_fail (text != NULL, NULL);
2112 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2115 structure = gst_structure_id_new (GST_QUARK (MESSAGE_PROGRESS),
2116 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2117 GST_QUARK (CODE), G_TYPE_STRING, code,
2118 GST_QUARK (TEXT), G_TYPE_STRING, text,
2119 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2120 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2121 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2127 * gst_message_parse_progress:
2128 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2129 * @type: (out) (allow-none): location for the type
2130 * @code: (out) (allow-none) (transfer full): location for the code
2131 * @text: (out) (allow-none) (transfer full): location for the text
2133 * Parses the progress @type, @code and @text.
2138 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2139 gchar ** code, gchar ** text)
2141 g_return_if_fail (GST_IS_MESSAGE (message));
2142 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2144 gst_structure_id_get (message->structure,
2145 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2146 GST_QUARK (CODE), G_TYPE_STRING, code,
2147 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);