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"
67 GstStructure *structure;
70 #define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure)
79 static GstMessageQuarks message_quarks[] = {
80 {GST_MESSAGE_UNKNOWN, "unknown", 0},
81 {GST_MESSAGE_EOS, "eos", 0},
82 {GST_MESSAGE_ERROR, "error", 0},
83 {GST_MESSAGE_WARNING, "warning", 0},
84 {GST_MESSAGE_INFO, "info", 0},
85 {GST_MESSAGE_TAG, "tag", 0},
86 {GST_MESSAGE_BUFFERING, "buffering", 0},
87 {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
88 {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
89 {GST_MESSAGE_STEP_DONE, "step-done", 0},
90 {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
91 {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
92 {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
93 {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
94 {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
95 {GST_MESSAGE_APPLICATION, "application", 0},
96 {GST_MESSAGE_ELEMENT, "element", 0},
97 {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
98 {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
99 {GST_MESSAGE_DURATION, "duration", 0},
100 {GST_MESSAGE_LATENCY, "latency", 0},
101 {GST_MESSAGE_ASYNC_START, "async-start", 0},
102 {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
103 {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
104 {GST_MESSAGE_STEP_START, "step-start", 0},
105 {GST_MESSAGE_QOS, "qos", 0},
106 {GST_MESSAGE_PROGRESS, "progress", 0},
107 {GST_MESSAGE_TOC, "toc", 0},
111 static GType _gst_message_type = 0;
112 GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
115 _priv_gst_message_initialize (void)
119 GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
121 /* the GstMiniObject types need to be class_ref'd once before it can be
122 * done from multiple threads;
123 * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
124 gst_message_get_type ();
126 for (i = 0; message_quarks[i].name; i++) {
127 message_quarks[i].quark =
128 g_quark_from_static_string (message_quarks[i].name);
131 _gst_message_type = gst_message_get_type ();
135 * gst_message_type_get_name:
136 * @type: the message type
138 * Get a printable name for the given message type. Do not modify or free.
140 * Returns: a reference to the static name of the message.
143 gst_message_type_get_name (GstMessageType type)
147 for (i = 0; message_quarks[i].name; i++) {
148 if (type == message_quarks[i].type)
149 return message_quarks[i].name;
155 * gst_message_type_to_quark:
156 * @type: the message type
158 * Get the unique quark for the given message type.
160 * Returns: the quark associated with the message type
163 gst_message_type_to_quark (GstMessageType type)
167 for (i = 0; message_quarks[i].name; i++) {
168 if (type == message_quarks[i].type)
169 return message_quarks[i].quark;
175 _gst_message_free (GstMessage * message)
177 GstStructure *structure;
179 g_return_if_fail (message != NULL);
181 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
182 GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
184 if (GST_MESSAGE_SRC (message)) {
185 gst_object_unref (GST_MESSAGE_SRC (message));
186 GST_MESSAGE_SRC (message) = NULL;
189 if (message->lock.p) {
190 GST_MESSAGE_LOCK (message);
191 GST_MESSAGE_SIGNAL (message);
192 GST_MESSAGE_UNLOCK (message);
195 structure = GST_MESSAGE_STRUCTURE (message);
197 gst_structure_set_parent_refcount (structure, NULL);
198 gst_structure_free (structure);
201 g_slice_free1 (sizeof (GstMessageImpl), message);
205 gst_message_init (GstMessageImpl * message, GstMessageType type,
209 _gst_message_copy (GstMessage * message)
211 GstMessageImpl *copy;
212 GstStructure *structure;
214 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
215 GST_MESSAGE_TYPE_NAME (message),
216 GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
218 copy = g_slice_new0 (GstMessageImpl);
220 gst_message_init (copy, GST_MESSAGE_TYPE (message),
221 GST_MESSAGE_SRC (message));
223 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
224 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
226 structure = GST_MESSAGE_STRUCTURE (message);
228 GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
229 gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
230 ©->message.mini_object.refcount);
232 GST_MESSAGE_STRUCTURE (copy) = NULL;
235 return GST_MESSAGE_CAST (copy);
239 gst_message_init (GstMessageImpl * message, GstMessageType type,
242 gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type);
244 message->message.mini_object.copy =
245 (GstMiniObjectCopyFunction) _gst_message_copy;
246 message->message.mini_object.free =
247 (GstMiniObjectFreeFunction) _gst_message_free;
249 GST_MESSAGE_TYPE (message) = type;
251 gst_object_ref (src);
252 GST_MESSAGE_SRC (message) = src;
253 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
254 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
259 * gst_message_new_custom:
260 * @type: The #GstMessageType to distinguish messages
261 * @src: The object originating the message.
262 * @structure: (transfer full): the structure for the message. The message
263 * will take ownership of the structure.
265 * Create a new custom-typed message. This can be used for anything not
266 * handled by other message-specific functions to pass a message to the
267 * app. The structure field can be NULL.
269 * Returns: (transfer full): The new message.
274 gst_message_new_custom (GstMessageType type, GstObject * src,
275 GstStructure * structure)
277 GstMessageImpl *message;
279 message = g_slice_new0 (GstMessageImpl);
281 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
282 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
283 gst_message_type_get_name (type));
286 /* structure must not have a parent */
287 if (!gst_structure_set_parent_refcount (structure,
288 &message->message.mini_object.refcount))
291 gst_message_init (message, type, src);
293 GST_MESSAGE_STRUCTURE (message) = structure;
295 return GST_MESSAGE_CAST (message);
300 g_slice_free1 (sizeof (GstMessageImpl), message);
301 g_warning ("structure is already owned by another object");
307 * gst_message_get_seqnum:
308 * @message: A #GstMessage.
310 * Retrieve the sequence number of a message.
312 * Messages have ever-incrementing sequence numbers, which may also be set
313 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
314 * to indicate that a message corresponds to some other set of messages or
315 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
316 * is considered good practice to make this correspondence when possible, though
317 * it is not required.
319 * Note that events and messages share the same sequence number incrementor;
320 * two events or messages will never have the same sequence number unless
321 * that correspondence was made explicitly.
323 * Returns: The message's sequence number.
330 gst_message_get_seqnum (GstMessage * message)
332 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
334 return GST_MESSAGE_SEQNUM (message);
338 * gst_message_set_seqnum:
339 * @message: A #GstMessage.
340 * @seqnum: A sequence number.
342 * Set the sequence number of a message.
344 * This function might be called by the creator of a message to indicate that
345 * the message relates to other messages or events. See gst_message_get_seqnum()
346 * for more information.
353 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
355 g_return_if_fail (GST_IS_MESSAGE (message));
357 GST_MESSAGE_SEQNUM (message) = seqnum;
361 * gst_message_new_eos:
362 * @src: (transfer none): The object originating the message.
364 * Create a new eos message. This message is generated and posted in
365 * the sink elements of a GstBin. The bin will only forward the EOS
366 * message to the application if all sinks have posted an EOS message.
368 * Returns: (transfer full): The new eos message.
373 gst_message_new_eos (GstObject * src)
377 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
383 * gst_message_new_error:
384 * @src: (transfer none): The object originating the message.
385 * @error: (transfer none): The GError for this message.
386 * @debug: A debugging string.
388 * Create a new error message. The message will copy @error and
389 * @debug. This message is posted by element when a fatal event
390 * occured. The pipeline will probably (partially) stop. The application
391 * receiving this message should stop the pipeline.
393 * Returns: (transfer full): the new error message.
398 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
401 GstStructure *structure;
403 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
404 GST_QUARK (GERROR), G_TYPE_ERROR, error,
405 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
406 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
412 * gst_message_new_warning:
413 * @src: (transfer none): The object originating the message.
414 * @error: (transfer none): The GError for this message.
415 * @debug: A debugging string.
417 * Create a new warning message. The message will make copies of @error and
420 * Returns: (transfer full): The new warning message.
425 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
428 GstStructure *structure;
430 structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
431 GST_QUARK (GERROR), G_TYPE_ERROR, error,
432 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
433 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
439 * gst_message_new_info:
440 * @src: (transfer none): The object originating the message.
441 * @error: (transfer none): The GError for this message.
442 * @debug: A debugging string.
444 * Create a new info message. The message will make copies of @error and
449 * Returns: (transfer full): the new info message.
454 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
457 GstStructure *structure;
459 structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
460 GST_QUARK (GERROR), G_TYPE_ERROR, error,
461 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
462 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
468 * gst_message_new_tag:
469 * @src: (transfer none): The object originating the message.
470 * @tag_list: (transfer full): the tag list for the message.
472 * Create a new tag message. The message will take ownership of the tag list.
473 * The message is posted by elements that discovered a new taglist.
475 * Returns: (transfer full): the new tag message.
480 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
484 GValue val = G_VALUE_INIT;
486 g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
488 s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
489 g_value_init (&val, GST_TYPE_TAG_LIST);
490 g_value_take_boxed (&val, tag_list);
491 gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
492 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
497 * gst_message_new_buffering:
498 * @src: (transfer none): The object originating the message.
499 * @percent: The buffering percent
501 * Create a new buffering message. This message can be posted by an element that
502 * needs to buffer data before it can continue processing. @percent should be a
503 * value between 0 and 100. A value of 100 means that the buffering completed.
505 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
506 * @percent is 100, the application can set the pipeline (back) to PLAYING.
507 * The application must be prepared to receive BUFFERING messages in the
508 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
509 * message with @percent set to 100, which can happen after the pipeline
510 * completed prerolling.
514 * Returns: (transfer full): The new buffering message.
519 gst_message_new_buffering (GstObject * src, gint percent)
522 GstStructure *structure;
524 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
526 structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
527 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
528 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
529 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
530 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
531 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
532 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
533 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
539 * gst_message_new_state_changed:
540 * @src: (transfer none): the object originating the message
541 * @oldstate: the previous state
542 * @newstate: the new (current) state
543 * @pending: the pending (target) state
545 * Create a state change message. This message is posted whenever an element
548 * Returns: (transfer full): the new state change message.
553 gst_message_new_state_changed (GstObject * src,
554 GstState oldstate, GstState newstate, GstState pending)
557 GstStructure *structure;
559 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
560 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
561 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
562 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
563 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
569 * gst_message_new_state_dirty:
570 * @src: (transfer none): the object originating the message
572 * Create a state dirty message. This message is posted whenever an element
573 * changed its state asynchronously and is used internally to update the
574 * states of container objects.
576 * Returns: (transfer full): the new state dirty message.
581 gst_message_new_state_dirty (GstObject * src)
585 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
591 * gst_message_new_clock_provide:
592 * @src: (transfer none): the object originating the message.
593 * @clock: (transfer none): the clock it provides
594 * @ready: TRUE if the sender can provide a clock
596 * Create a clock provide message. This message is posted whenever an
597 * element is ready to provide a clock or lost its ability to provide
598 * a clock (maybe because it paused or became EOS).
600 * This message is mainly used internally to manage the clock
603 * Returns: (transfer full): the new provide clock message.
608 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
612 GstStructure *structure;
614 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
615 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
616 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
617 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
623 * gst_message_new_clock_lost:
624 * @src: (transfer none): the object originating the message.
625 * @clock: (transfer none): the clock that was lost
627 * Create a clock lost message. This message is posted whenever the
628 * clock is not valid anymore.
630 * If this message is posted by the pipeline, the pipeline will
631 * select a new clock again when it goes to PLAYING. It might therefore
632 * be needed to set the pipeline to PAUSED and PLAYING again.
634 * Returns: (transfer full): The new clock lost message.
639 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
642 GstStructure *structure;
644 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
645 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
646 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
652 * gst_message_new_new_clock:
653 * @src: (transfer none): The object originating the message.
654 * @clock: (transfer none): the new selected clock
656 * Create a new clock message. This message is posted whenever the
657 * pipeline selectes a new clock for the pipeline.
659 * Returns: (transfer full): The new new clock message.
664 gst_message_new_new_clock (GstObject * src, GstClock * clock)
667 GstStructure *structure;
669 structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
670 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
671 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
677 * gst_message_new_structure_change:
678 * @src: (transfer none): The object originating the message.
679 * @type: The change type.
680 * @owner: (transfer none): The owner element of @src.
681 * @busy: Whether the structure change is busy.
683 * Create a new structure change message. This message is posted when the
684 * structure of a pipeline is in the process of being changed, for example
685 * when pads are linked or unlinked.
687 * @src should be the sinkpad that unlinked or linked.
689 * Returns: (transfer full): the new structure change message.
696 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
697 GstElement * owner, gboolean busy)
700 GstStructure *structure;
702 g_return_val_if_fail (GST_IS_PAD (src), NULL);
703 /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
704 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
706 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
707 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
708 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
709 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
711 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
718 * gst_message_new_segment_start:
719 * @src: (transfer none): The object originating the message.
720 * @format: The format of the position being played
721 * @position: The position of the segment being played
723 * Create a new segment message. This message is posted by elements that
724 * start playback of a segment as a result of a segment seek. This message
725 * is not received by the application but is used for maintenance reasons in
726 * container elements.
728 * Returns: (transfer full): the new segment start message.
733 gst_message_new_segment_start (GstObject * src, GstFormat format,
737 GstStructure *structure;
739 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
740 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
741 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
742 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
748 * gst_message_new_segment_done:
749 * @src: (transfer none): the object originating the message.
750 * @format: The format of the position being done
751 * @position: The position of the segment being done
753 * Create a new segment done message. This message is posted by elements that
754 * finish playback of a segment as a result of a segment seek. This message
755 * is received by the application after all elements that posted a segment_start
756 * have posted the segment_done.
758 * Returns: (transfer full): the new segment done message.
763 gst_message_new_segment_done (GstObject * src, GstFormat format,
767 GstStructure *structure;
769 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
770 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
771 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
772 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
778 * gst_message_new_application:
779 * @src: (transfer none): the object originating the message.
780 * @structure: (transfer full): the structure for the message. The message
781 * will take ownership of the structure.
783 * Create a new application-typed message. GStreamer will never create these
784 * messages; they are a gift from us to you. Enjoy.
786 * Returns: (transfer full): The new application message.
791 gst_message_new_application (GstObject * src, GstStructure * structure)
793 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
797 * gst_message_new_element:
798 * @src: (transfer none): The object originating the message.
799 * @structure: (transfer full): The structure for the message. The message
800 * will take ownership of the structure.
802 * Create a new element-specific message. This is meant as a generic way of
803 * allowing one-way communication from an element to an application, for example
804 * "the firewire cable was unplugged". The format of the message should be
805 * documented in the element's documentation. The structure field can be NULL.
807 * Returns: (transfer full): The new element message.
812 gst_message_new_element (GstObject * src, GstStructure * structure)
814 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
818 * gst_message_new_duration:
819 * @src: (transfer none): The object originating the message.
820 * @format: The format of the duration
821 * @duration: The new duration
823 * Create a new duration message. This message is posted by elements that
824 * know the duration of a stream in a specific format. This message
825 * is received by bins and is used to calculate the total duration of a
826 * pipeline. Elements may post a duration message with a duration of
827 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
828 * cached duration should be discarded. The new duration can then be
829 * retrieved via a query.
831 * Returns: (transfer full): The new duration message.
836 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
839 GstStructure *structure;
841 structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION),
842 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
843 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
844 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
850 * gst_message_new_async_start:
851 * @src: (transfer none): The object originating the message.
853 * This message is posted by elements when they start an ASYNC state change.
855 * Returns: (transfer full): The new async_start message.
860 gst_message_new_async_start (GstObject * src)
864 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
870 * gst_message_new_async_done:
871 * @src: (transfer none): The object originating the message.
872 * @running_time: the desired running_time
874 * The message is posted when elements completed an ASYNC state change.
875 * @running_time contains the time of the desired running_time when this
876 * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
877 * means that the element has no clock interaction and thus doesn't care about
878 * the running_time of the pipeline.
880 * Returns: (transfer full): The new async_done message.
885 gst_message_new_async_done (GstObject * src, GstClockTime running_time)
888 GstStructure *structure;
890 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
891 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
892 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
898 * gst_message_new_latency:
899 * @src: (transfer none): The object originating the message.
901 * This message can be posted by elements when their latency requirements have
904 * Returns: (transfer full): The new latency message.
911 gst_message_new_latency (GstObject * src)
915 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
921 * gst_message_new_request_state:
922 * @src: (transfer none): the object originating the message.
923 * @state: The new requested state
925 * This message can be posted by elements when they want to have their state
926 * changed. A typical use case would be an audio server that wants to pause the
927 * pipeline because a higher priority stream is being played.
929 * Returns: (transfer full): the new requst state message.
936 gst_message_new_request_state (GstObject * src, GstState state)
939 GstStructure *structure;
941 structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
942 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
943 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
949 * gst_message_get_structure:
950 * @message: The #GstMessage.
952 * Access the structure of the message.
954 * Returns: (transfer none): The structure of the message. The structure is
955 * still owned by the message, which means that you should not free it and
956 * that the pointer becomes invalid when you free the message.
961 gst_message_get_structure (GstMessage * message)
963 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
965 return GST_MESSAGE_STRUCTURE (message);
969 * gst_message_has_name:
970 * @message: The #GstMessage.
971 * @name: name to check
973 * Checks if @message has the given @name. This function is usually used to
974 * check the name of a custom message.
976 * Returns: %TRUE if @name matches the name of the message structure.
981 gst_message_has_name (GstMessage * message, const gchar * name)
983 GstStructure *structure;
985 g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
987 structure = GST_MESSAGE_STRUCTURE (message);
988 if (structure == NULL)
991 return gst_structure_has_name (structure, name);
995 * gst_message_parse_tag:
996 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
997 * @tag_list: (out callee-allocates): return location for the tag-list.
999 * Extracts the tag list from the GstMessage. The tag list returned in the
1000 * output argument is a copy; the caller must free it when done.
1002 * Typical usage of this function might be:
1005 * switch (GST_MESSAGE_TYPE (msg)) {
1006 * case GST_MESSAGE_TAG: {
1007 * GstTagList *tags = NULL;
1009 * gst_message_parse_tag (msg, &tags);
1010 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1011 * handle_tags (tags);
1012 * gst_tag_list_unref (tags);
1023 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1025 g_return_if_fail (GST_IS_MESSAGE (message));
1026 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1027 g_return_if_fail (tag_list != NULL);
1029 gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1030 GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
1034 * gst_message_parse_buffering:
1035 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1036 * @percent: (out) (allow-none): Return location for the percent.
1038 * Extracts the buffering percent from the GstMessage. see also
1039 * gst_message_new_buffering().
1046 gst_message_parse_buffering (GstMessage * message, gint * percent)
1048 g_return_if_fail (GST_IS_MESSAGE (message));
1049 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1053 g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1054 (message), GST_QUARK (BUFFER_PERCENT)));
1058 * gst_message_set_buffering_stats:
1059 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1060 * @mode: a buffering mode
1061 * @avg_in: the average input rate
1062 * @avg_out: the average output rate
1063 * @buffering_left: amount of buffering time left in milliseconds
1065 * Configures the buffering stats values in @message.
1070 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1071 gint avg_in, gint avg_out, gint64 buffering_left)
1073 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1075 gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1076 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1077 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1078 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1079 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1083 * gst_message_parse_buffering_stats:
1084 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1085 * @mode: (out) (allow-none): a buffering mode, or NULL
1086 * @avg_in: (out) (allow-none): the average input rate, or NULL
1087 * @avg_out: (out) (allow-none): the average output rate, or NULL
1088 * @buffering_left: (out) (allow-none): amount of buffering time left in
1089 * milliseconds, or NULL
1091 * Extracts the buffering stats values from @message.
1096 gst_message_parse_buffering_stats (GstMessage * message,
1097 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1098 gint64 * buffering_left)
1100 GstStructure *structure;
1102 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1104 structure = GST_MESSAGE_STRUCTURE (message);
1106 *mode = (GstBufferingMode)
1107 g_value_get_enum (gst_structure_id_get_value (structure,
1108 GST_QUARK (BUFFERING_MODE)));
1110 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1111 GST_QUARK (AVG_IN_RATE)));
1113 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1114 GST_QUARK (AVG_OUT_RATE)));
1117 g_value_get_int64 (gst_structure_id_get_value (structure,
1118 GST_QUARK (BUFFERING_LEFT)));
1122 * gst_message_parse_state_changed:
1123 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1124 * @oldstate: (out) (allow-none): the previous state, or NULL
1125 * @newstate: (out) (allow-none): the new (current) state, or NULL
1126 * @pending: (out) (allow-none): the pending (target) state, or NULL
1128 * Extracts the old and new states from the GstMessage.
1130 * Typical usage of this function might be:
1133 * switch (GST_MESSAGE_TYPE (msg)) {
1134 * case GST_MESSAGE_STATE_CHANGED: {
1135 * GstState old_state, new_state;
1137 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1138 * g_print ("Element %s changed state from %s to %s.\n",
1139 * GST_OBJECT_NAME (msg->src),
1140 * gst_element_state_get_name (old_state),
1141 * gst_element_state_get_name (new_state));
1152 gst_message_parse_state_changed (GstMessage * message,
1153 GstState * oldstate, GstState * newstate, GstState * pending)
1155 GstStructure *structure;
1157 g_return_if_fail (GST_IS_MESSAGE (message));
1158 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1160 structure = GST_MESSAGE_STRUCTURE (message);
1162 *oldstate = (GstState)
1163 g_value_get_enum (gst_structure_id_get_value (structure,
1164 GST_QUARK (OLD_STATE)));
1166 *newstate = (GstState)
1167 g_value_get_enum (gst_structure_id_get_value (structure,
1168 GST_QUARK (NEW_STATE)));
1170 *pending = (GstState)
1171 g_value_get_enum (gst_structure_id_get_value (structure,
1172 GST_QUARK (PENDING_STATE)));
1176 * gst_message_parse_clock_provide:
1177 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1178 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1180 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1182 * Extracts the clock and ready flag from the GstMessage.
1183 * The clock object returned remains valid until the message is freed.
1188 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1191 const GValue *clock_gvalue;
1192 GstStructure *structure;
1194 g_return_if_fail (GST_IS_MESSAGE (message));
1195 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1197 structure = GST_MESSAGE_STRUCTURE (message);
1198 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1199 g_return_if_fail (clock_gvalue != NULL);
1200 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1204 g_value_get_boolean (gst_structure_id_get_value (structure,
1205 GST_QUARK (READY)));
1207 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1211 * gst_message_parse_clock_lost:
1212 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1213 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1215 * Extracts the lost clock from the GstMessage.
1216 * The clock object returned remains valid until the message is freed.
1221 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1223 const GValue *clock_gvalue;
1224 GstStructure *structure;
1226 g_return_if_fail (GST_IS_MESSAGE (message));
1227 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1229 structure = GST_MESSAGE_STRUCTURE (message);
1230 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1231 g_return_if_fail (clock_gvalue != NULL);
1232 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1235 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1239 * gst_message_parse_new_clock:
1240 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1241 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1244 * Extracts the new clock from the GstMessage.
1245 * The clock object returned remains valid until the message is freed.
1250 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1252 const GValue *clock_gvalue;
1253 GstStructure *structure;
1255 g_return_if_fail (GST_IS_MESSAGE (message));
1256 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1258 structure = GST_MESSAGE_STRUCTURE (message);
1259 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1260 g_return_if_fail (clock_gvalue != NULL);
1261 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1264 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1268 * gst_message_parse_structure_change:
1269 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1270 * @type: (out): A pointer to hold the change type
1271 * @owner: (out) (allow-none) (transfer none): The owner element of the
1273 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1274 * progress or has been completed
1276 * Extracts the change type and completion status from the GstMessage.
1283 gst_message_parse_structure_change (GstMessage * message,
1284 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1286 const GValue *owner_gvalue;
1287 GstStructure *structure;
1289 g_return_if_fail (GST_IS_MESSAGE (message));
1290 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1292 structure = GST_MESSAGE_STRUCTURE (message);
1293 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1294 g_return_if_fail (owner_gvalue != NULL);
1295 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1298 *type = (GstStructureChangeType)
1299 g_value_get_enum (gst_structure_id_get_value (structure,
1302 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1305 g_value_get_boolean (gst_structure_id_get_value (structure,
1310 * gst_message_parse_error:
1311 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1312 * @gerror: (out) (allow-none) (transfer full): location for the GError
1313 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1316 * Extracts the GError and debug string from the GstMessage. The values returned
1317 * in the output arguments are copies; the caller must free them when done.
1319 * Typical usage of this function might be:
1322 * switch (GST_MESSAGE_TYPE (msg)) {
1323 * case GST_MESSAGE_ERROR: {
1324 * GError *err = NULL;
1325 * gchar *dbg_info = NULL;
1327 * gst_message_parse_error (msg, &err, &dbg_info);
1328 * g_printerr ("ERROR from element %s: %s\n",
1329 * GST_OBJECT_NAME (msg->src), err->message);
1330 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1331 * g_error_free (err);
1332 * g_free (dbg_info);
1343 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1345 const GValue *error_gvalue;
1347 GstStructure *structure;
1349 g_return_if_fail (GST_IS_MESSAGE (message));
1350 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1352 structure = GST_MESSAGE_STRUCTURE (message);
1353 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1354 g_return_if_fail (error_gvalue != NULL);
1355 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1357 error_val = (GError *) g_value_get_boxed (error_gvalue);
1359 *gerror = g_error_copy (error_val);
1365 g_value_dup_string (gst_structure_id_get_value (structure,
1366 GST_QUARK (DEBUG)));
1370 * gst_message_parse_warning:
1371 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1372 * @gerror: (out) (allow-none) (transfer full): location for the GError
1373 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1376 * Extracts the GError and debug string from the GstMessage. The values returned
1377 * in the output arguments are copies; the caller must free them when done.
1382 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1385 const GValue *error_gvalue;
1387 GstStructure *structure;
1389 g_return_if_fail (GST_IS_MESSAGE (message));
1390 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1392 structure = GST_MESSAGE_STRUCTURE (message);
1393 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1394 g_return_if_fail (error_gvalue != NULL);
1395 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1397 error_val = (GError *) g_value_get_boxed (error_gvalue);
1399 *gerror = g_error_copy (error_val);
1405 g_value_dup_string (gst_structure_id_get_value (structure,
1406 GST_QUARK (DEBUG)));
1410 * gst_message_parse_info:
1411 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1412 * @gerror: (out) (allow-none) (transfer full): location for the GError
1413 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1416 * Extracts the GError and debug string from the GstMessage. The values returned
1417 * in the output arguments are copies; the caller must free them when done.
1424 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1426 const GValue *error_gvalue;
1428 GstStructure *structure;
1430 g_return_if_fail (GST_IS_MESSAGE (message));
1431 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1433 structure = GST_MESSAGE_STRUCTURE (message);
1434 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1435 g_return_if_fail (error_gvalue != NULL);
1436 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1438 error_val = (GError *) g_value_get_boxed (error_gvalue);
1440 *gerror = g_error_copy (error_val);
1446 g_value_dup_string (gst_structure_id_get_value (structure,
1447 GST_QUARK (DEBUG)));
1451 * gst_message_parse_segment_start:
1452 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1453 * @format: (out): Result location for the format, or NULL
1454 * @position: (out): Result location for the position, or NULL
1456 * Extracts the position and format from the segment start message.
1461 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1464 GstStructure *structure;
1466 g_return_if_fail (GST_IS_MESSAGE (message));
1467 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1469 structure = GST_MESSAGE_STRUCTURE (message);
1471 *format = (GstFormat)
1472 g_value_get_enum (gst_structure_id_get_value (structure,
1473 GST_QUARK (FORMAT)));
1476 g_value_get_int64 (gst_structure_id_get_value (structure,
1477 GST_QUARK (POSITION)));
1481 * gst_message_parse_segment_done:
1482 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1483 * @format: (out): Result location for the format, or NULL
1484 * @position: (out): Result location for the position, or NULL
1486 * Extracts the position and format from the segment start message.
1491 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1494 GstStructure *structure;
1496 g_return_if_fail (GST_IS_MESSAGE (message));
1497 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1499 structure = GST_MESSAGE_STRUCTURE (message);
1501 *format = (GstFormat)
1502 g_value_get_enum (gst_structure_id_get_value (structure,
1503 GST_QUARK (FORMAT)));
1506 g_value_get_int64 (gst_structure_id_get_value (structure,
1507 GST_QUARK (POSITION)));
1511 * gst_message_parse_duration:
1512 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1513 * @format: (out): Result location for the format, or NULL
1514 * @duration: (out): Result location for the duration, or NULL
1516 * Extracts the duration and format from the duration message. The duration
1517 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1518 * changed. Applications should always use a query to retrieve the duration
1524 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1527 GstStructure *structure;
1529 g_return_if_fail (GST_IS_MESSAGE (message));
1530 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1532 structure = GST_MESSAGE_STRUCTURE (message);
1534 *format = (GstFormat)
1535 g_value_get_enum (gst_structure_id_get_value (structure,
1536 GST_QUARK (FORMAT)));
1539 g_value_get_int64 (gst_structure_id_get_value (structure,
1540 GST_QUARK (DURATION)));
1544 * gst_message_parse_async_done:
1545 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1546 * @running_time: (out): Result location for the running_time or NULL
1548 * Extract the running_time from the async_done message.
1553 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
1555 GstStructure *structure;
1557 g_return_if_fail (GST_IS_MESSAGE (message));
1558 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1560 structure = GST_MESSAGE_STRUCTURE (message);
1563 g_value_get_uint64 (gst_structure_id_get_value (structure,
1564 GST_QUARK (RUNNING_TIME)));
1568 * gst_message_parse_request_state:
1569 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1570 * @state: (out): Result location for the requested state or NULL
1572 * Extract the requested state from the request_state message.
1579 gst_message_parse_request_state (GstMessage * message, GstState * state)
1581 GstStructure *structure;
1583 g_return_if_fail (GST_IS_MESSAGE (message));
1584 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1586 structure = GST_MESSAGE_STRUCTURE (message);
1589 g_value_get_enum (gst_structure_id_get_value (structure,
1590 GST_QUARK (NEW_STATE)));
1594 * gst_message_new_stream_status:
1595 * @src: The object originating the message.
1596 * @type: The stream status type.
1597 * @owner: (transfer none): the owner element of @src.
1599 * Create a new stream status message. This message is posted when a streaming
1600 * thread is created/destroyed or when the state changed.
1602 * Returns: (transfer full): the new stream status message.
1609 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1612 GstMessage *message;
1613 GstStructure *structure;
1615 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1616 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1617 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1618 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1624 * gst_message_parse_stream_status:
1625 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1626 * @type: (out): A pointer to hold the status type
1627 * @owner: (out) (transfer none): The owner element of the message source
1629 * Extracts the stream status type and owner the GstMessage. The returned
1630 * owner remains valid for as long as the reference to @message is valid and
1631 * should thus not be unreffed.
1638 gst_message_parse_stream_status (GstMessage * message,
1639 GstStreamStatusType * type, GstElement ** owner)
1641 const GValue *owner_gvalue;
1642 GstStructure *structure;
1644 g_return_if_fail (GST_IS_MESSAGE (message));
1645 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1647 structure = GST_MESSAGE_STRUCTURE (message);
1648 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1649 g_return_if_fail (owner_gvalue != NULL);
1652 *type = (GstStreamStatusType)
1653 g_value_get_enum (gst_structure_id_get_value (structure,
1656 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1660 * gst_message_set_stream_status_object:
1661 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1662 * @object: the object controlling the streaming
1664 * Configures the object handling the streaming thread. This is usually a
1665 * GstTask object but other objects might be added in the future.
1670 gst_message_set_stream_status_object (GstMessage * message,
1671 const GValue * object)
1673 GstStructure *structure;
1675 g_return_if_fail (GST_IS_MESSAGE (message));
1676 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1678 structure = GST_MESSAGE_STRUCTURE (message);
1679 gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
1683 * gst_message_get_stream_status_object:
1684 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1686 * Extracts the object managing the streaming thread from @message.
1688 * Returns: a GValue containing the object that manages the streaming thread.
1689 * This object is usually of type GstTask but other types can be added in the
1690 * future. The object remains valid as long as @message is valid.
1695 gst_message_get_stream_status_object (GstMessage * message)
1697 const GValue *result;
1698 GstStructure *structure;
1700 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1701 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1704 structure = GST_MESSAGE_STRUCTURE (message);
1705 result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1711 * gst_message_new_step_done:
1712 * @src: The object originating the message.
1713 * @format: the format of @amount
1714 * @amount: the amount of stepped data
1715 * @rate: the rate of the stepped amount
1716 * @flush: is this an flushing step
1717 * @intermediate: is this an intermediate step
1718 * @duration: the duration of the data
1719 * @eos: the step caused EOS
1721 * This message is posted by elements when they complete a part, when @intermediate set
1722 * to TRUE, or a complete step operation.
1724 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1725 * @amount of media in format @format.
1727 * Returns: (transfer full): the new step_done message.
1734 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1735 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1738 GstMessage *message;
1739 GstStructure *structure;
1741 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
1742 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1743 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1744 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1745 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1746 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1747 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1748 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1749 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1755 * gst_message_parse_step_done:
1756 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1757 * @format: (out) (allow-none): result location for the format
1758 * @amount: (out) (allow-none): result location for the amount
1759 * @rate: (out) (allow-none): result location for the rate
1760 * @flush: (out) (allow-none): result location for the flush flag
1761 * @intermediate: (out) (allow-none): result location for the intermediate flag
1762 * @duration: (out) (allow-none): result location for the duration
1763 * @eos: (out) (allow-none): result location for the EOS flag
1765 * Extract the values the step_done message.
1772 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1773 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1774 guint64 * duration, gboolean * eos)
1776 GstStructure *structure;
1778 g_return_if_fail (GST_IS_MESSAGE (message));
1779 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1781 structure = GST_MESSAGE_STRUCTURE (message);
1782 gst_structure_id_get (structure,
1783 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1784 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1785 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1786 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1787 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1788 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1789 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1793 * gst_message_new_step_start:
1794 * @src: The object originating the message.
1795 * @active: if the step is active or queued
1796 * @format: the format of @amount
1797 * @amount: the amount of stepped data
1798 * @rate: the rate of the stepped amount
1799 * @flush: is this an flushing step
1800 * @intermediate: is this an intermediate step
1802 * This message is posted by elements when they accept or activate a new step
1803 * event for @amount in @format.
1805 * @active is set to FALSE when the element accepted the new step event and has
1806 * queued it for execution in the streaming threads.
1808 * @active is set to TRUE when the element has activated the step operation and
1809 * is now ready to start executing the step in the streaming thread. After this
1810 * message is emited, the application can queue a new step operation in the
1813 * Returns: (transfer full): The new step_start message.
1820 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1821 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1823 GstMessage *message;
1824 GstStructure *structure;
1826 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
1827 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1828 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1829 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1830 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1831 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1832 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1833 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1839 * gst_message_parse_step_start:
1840 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1841 * @active: (out) (allow-none): result location for the active flag
1842 * @format: (out) (allow-none): result location for the format
1843 * @amount: (out) (allow-none): result location for the amount
1844 * @rate: (out) (allow-none): result location for the rate
1845 * @flush: (out) (allow-none): result location for the flush flag
1846 * @intermediate: (out) (allow-none): result location for the intermediate flag
1848 * Extract the values from step_start message.
1855 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1856 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1857 gboolean * intermediate)
1859 GstStructure *structure;
1861 g_return_if_fail (GST_IS_MESSAGE (message));
1862 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1864 structure = GST_MESSAGE_STRUCTURE (message);
1865 gst_structure_id_get (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_new_id (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 GstStructure *structure;
1948 g_return_if_fail (GST_IS_MESSAGE (message));
1949 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1951 structure = GST_MESSAGE_STRUCTURE (message);
1952 gst_structure_id_set (structure,
1953 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1954 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1955 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1959 * gst_message_set_qos_stats:
1960 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1961 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1962 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1963 * will likely use GST_FORMAT_DEFAULT (samples).
1964 * @processed: Total number of units correctly processed since the last state
1965 * change to READY or a flushing operation.
1966 * @dropped: Total number of units dropped since the last state change to READY
1967 * or a flushing operation.
1969 * Set the QoS stats representing the history of the current continuous pipeline
1972 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1973 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1980 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1981 guint64 processed, guint64 dropped)
1983 GstStructure *structure;
1985 g_return_if_fail (GST_IS_MESSAGE (message));
1986 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1988 structure = GST_MESSAGE_STRUCTURE (message);
1989 gst_structure_id_set (structure,
1990 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1991 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1992 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1996 * gst_message_parse_qos:
1997 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1998 * @live: (out) (allow-none): if the message was generated by a live element
1999 * @running_time: (out) (allow-none): the running time of the buffer that
2000 * generated the message
2001 * @stream_time: (out) (allow-none): the stream time of the buffer that
2002 * generated the message
2003 * @timestamp: (out) (allow-none): the timestamps of the buffer that
2004 * generated the message
2005 * @duration: (out) (allow-none): the duration of the buffer that
2006 * generated the message
2008 * Extract the timestamps and live status from the QoS message.
2010 * The returned values give the running_time, stream_time, timestamp and
2011 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2019 gst_message_parse_qos (GstMessage * message, gboolean * live,
2020 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2023 GstStructure *structure;
2025 g_return_if_fail (GST_IS_MESSAGE (message));
2026 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2028 structure = GST_MESSAGE_STRUCTURE (message);
2029 gst_structure_id_get (structure,
2030 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2031 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2032 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2033 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2034 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2038 * gst_message_parse_qos_values:
2039 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2040 * @jitter: (out) (allow-none): The difference of the running-time against
2042 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2043 * relative to normal rate to get optimal quality.
2044 * @quality: (out) (allow-none): An element dependent integer value that
2045 * specifies the current quality level of the element. The default
2046 * maximum quality is 1000000.
2048 * Extract the QoS values that have been calculated/analysed from the QoS data
2055 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2056 gdouble * proportion, gint * quality)
2058 GstStructure *structure;
2060 g_return_if_fail (GST_IS_MESSAGE (message));
2061 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2063 structure = GST_MESSAGE_STRUCTURE (message);
2064 gst_structure_id_get (structure,
2065 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2066 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2067 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2071 * gst_message_parse_qos_stats:
2072 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2073 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2074 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2075 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2077 * @processed: (out) (allow-none): Total number of units correctly processed
2078 * since the last state change to READY or a flushing operation.
2079 * @dropped: (out) (allow-none): Total number of units dropped since the last
2080 * state change to READY or a flushing operation.
2082 * Extract the QoS stats representing the history of the current continuous
2083 * pipeline playback period.
2085 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2086 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2093 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2094 guint64 * processed, guint64 * dropped)
2096 GstStructure *structure;
2098 g_return_if_fail (GST_IS_MESSAGE (message));
2099 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2101 structure = GST_MESSAGE_STRUCTURE (message);
2102 gst_structure_id_get (structure,
2103 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2104 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2105 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2109 * gst_message_new_progress:
2110 * @src: The object originating the message.
2111 * @type: a #GstProgressType
2112 * @code: a progress code
2113 * @text: free, user visible text describing the progress
2115 * Progress messages are posted by elements when they use an asynchronous task
2116 * to perform actions triggered by a state change.
2118 * @code contains a well defined string describing the action.
2119 * @test should contain a user visible string detailing the current action.
2121 * Returns: (transfer full): The new qos message.
2126 gst_message_new_progress (GstObject * src, GstProgressType type,
2127 const gchar * code, const gchar * text)
2129 GstMessage *message;
2130 GstStructure *structure;
2131 gint percent = 100, timeout = -1;
2133 g_return_val_if_fail (code != NULL, NULL);
2134 g_return_val_if_fail (text != NULL, NULL);
2136 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2139 structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2140 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2141 GST_QUARK (CODE), G_TYPE_STRING, code,
2142 GST_QUARK (TEXT), G_TYPE_STRING, text,
2143 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2144 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2145 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2151 * gst_message_parse_progress:
2152 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2153 * @type: (out) (allow-none): location for the type
2154 * @code: (out) (allow-none) (transfer full): location for the code
2155 * @text: (out) (allow-none) (transfer full): location for the text
2157 * Parses the progress @type, @code and @text.
2162 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2163 gchar ** code, gchar ** text)
2165 GstStructure *structure;
2167 g_return_if_fail (GST_IS_MESSAGE (message));
2168 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2170 structure = GST_MESSAGE_STRUCTURE (message);
2171 gst_structure_id_get (structure,
2172 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2173 GST_QUARK (CODE), G_TYPE_STRING, code,
2174 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2178 * gst_message_new_toc:
2179 * @src: the object originating the message.
2180 * @toc: #GstToc structure for the message.
2181 * @updated: whether TOC was updated or not.
2183 * Create a new TOC message. The message is posted by elements
2184 * that discovered or updated a TOC.
2186 * Returns: a new TOC message.
2193 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2195 GstStructure *toc_struct;
2197 g_return_val_if_fail (toc != NULL, NULL);
2199 toc_struct = __gst_toc_to_structure (toc);
2201 if (G_LIKELY (toc_struct != NULL)) {
2202 __gst_toc_structure_set_updated (toc_struct, updated);
2203 return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2209 * gst_message_parse_toc:
2210 * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2211 * @toc: (out): return location for the TOC.
2212 * @updated: (out): return location for the updated flag.
2214 * Extract thef TOC from the #GstMessage. The TOC returned in the
2215 * output argument is a copy; the caller must free it with
2216 * gst_toc_free() when done.
2223 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2225 g_return_if_fail (GST_IS_MESSAGE (message));
2226 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2227 g_return_if_fail (toc != NULL);
2229 *toc = __gst_toc_from_structure (GST_MESSAGE_STRUCTURE (message));
2231 if (updated != NULL)
2233 __gst_toc_structure_get_updated (GST_MESSAGE_STRUCTURE (message));
2237 * gst_message_new_reset_time:
2238 * @src: (transfer none): The object originating the message.
2239 * @running_time: the requested running-time
2241 * This message is posted when the pipeline running-time should be reset to
2242 * @running_time, like after a flushing seek.
2244 * Returns: (transfer full): The new reset_time message.
2249 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2251 GstMessage *message;
2252 GstStructure *structure;
2254 structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2255 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2256 message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2262 * gst_message_parse_reset_time:
2263 * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2264 * @running_time: (out): Result location for the running_time or NULL
2266 * Extract the running-time from the RESET_TIME message.
2271 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2273 GstStructure *structure;
2275 g_return_if_fail (GST_IS_MESSAGE (message));
2276 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2278 structure = GST_MESSAGE_STRUCTURE (message);
2281 g_value_get_uint64 (gst_structure_id_get_value (structure,
2282 GST_QUARK (RUNNING_TIME)));