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 (GST_MINI_OBJECT_SIZE (message), message);
205 gst_message_init (GstMessageImpl * message, gsize size, 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, sizeof (GstMessageImpl), 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, gsize size, GstMessageType type,
242 gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type,
245 message->message.mini_object.copy =
246 (GstMiniObjectCopyFunction) _gst_message_copy;
247 message->message.mini_object.free =
248 (GstMiniObjectFreeFunction) _gst_message_free;
250 GST_MESSAGE_TYPE (message) = type;
252 gst_object_ref (src);
253 GST_MESSAGE_SRC (message) = src;
254 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
255 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
260 * gst_message_new_custom:
261 * @type: The #GstMessageType to distinguish messages
262 * @src: The object originating the message.
263 * @structure: (transfer full): the structure for the message. The message
264 * will take ownership of the structure.
266 * Create a new custom-typed message. This can be used for anything not
267 * handled by other message-specific functions to pass a message to the
268 * app. The structure field can be NULL.
270 * Returns: (transfer full): The new message.
275 gst_message_new_custom (GstMessageType type, GstObject * src,
276 GstStructure * structure)
278 GstMessageImpl *message;
280 message = g_slice_new0 (GstMessageImpl);
282 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
283 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
284 gst_message_type_get_name (type));
287 /* structure must not have a parent */
288 if (!gst_structure_set_parent_refcount (structure,
289 &message->message.mini_object.refcount))
292 gst_message_init (message, sizeof (GstMessageImpl), type, src);
294 GST_MESSAGE_STRUCTURE (message) = structure;
296 return GST_MESSAGE_CAST (message);
301 g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
302 g_warning ("structure is already owned by another object");
308 * gst_message_get_seqnum:
309 * @message: A #GstMessage.
311 * Retrieve the sequence number of a message.
313 * Messages have ever-incrementing sequence numbers, which may also be set
314 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
315 * to indicate that a message corresponds to some other set of messages or
316 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
317 * is considered good practice to make this correspondence when possible, though
318 * it is not required.
320 * Note that events and messages share the same sequence number incrementor;
321 * two events or messages will never have the same sequence number unless
322 * that correspondence was made explicitly.
324 * Returns: The message's sequence number.
331 gst_message_get_seqnum (GstMessage * message)
333 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
335 return GST_MESSAGE_SEQNUM (message);
339 * gst_message_set_seqnum:
340 * @message: A #GstMessage.
341 * @seqnum: A sequence number.
343 * Set the sequence number of a message.
345 * This function might be called by the creator of a message to indicate that
346 * the message relates to other messages or events. See gst_message_get_seqnum()
347 * for more information.
354 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
356 g_return_if_fail (GST_IS_MESSAGE (message));
358 GST_MESSAGE_SEQNUM (message) = seqnum;
362 * gst_message_new_eos:
363 * @src: (transfer none): The object originating the message.
365 * Create a new eos message. This message is generated and posted in
366 * the sink elements of a GstBin. The bin will only forward the EOS
367 * message to the application if all sinks have posted an EOS message.
369 * Returns: (transfer full): The new eos message.
374 gst_message_new_eos (GstObject * src)
378 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
384 * gst_message_new_error:
385 * @src: (transfer none): The object originating the message.
386 * @error: (transfer none): The GError for this message.
387 * @debug: A debugging string.
389 * Create a new error message. The message will copy @error and
390 * @debug. This message is posted by element when a fatal event
391 * occured. The pipeline will probably (partially) stop. The application
392 * receiving this message should stop the pipeline.
394 * Returns: (transfer full): the new error message.
399 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
402 GstStructure *structure;
404 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
405 GST_QUARK (GERROR), G_TYPE_ERROR, error,
406 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
407 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
413 * gst_message_new_warning:
414 * @src: (transfer none): The object originating the message.
415 * @error: (transfer none): The GError for this message.
416 * @debug: A debugging string.
418 * Create a new warning message. The message will make copies of @error and
421 * Returns: (transfer full): The new warning message.
426 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
429 GstStructure *structure;
431 structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
432 GST_QUARK (GERROR), G_TYPE_ERROR, error,
433 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
434 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
440 * gst_message_new_info:
441 * @src: (transfer none): The object originating the message.
442 * @error: (transfer none): The GError for this message.
443 * @debug: A debugging string.
445 * Create a new info message. The message will make copies of @error and
450 * Returns: (transfer full): the new info message.
455 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
458 GstStructure *structure;
460 structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
461 GST_QUARK (GERROR), G_TYPE_ERROR, error,
462 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
463 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
469 * gst_message_new_tag:
470 * @src: (transfer none): The object originating the message.
471 * @tag_list: (transfer full): the tag list for the message.
473 * Create a new tag message. The message will take ownership of the tag list.
474 * The message is posted by elements that discovered a new taglist.
476 * Returns: (transfer full): the new tag message.
481 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
485 GValue val = G_VALUE_INIT;
487 g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
489 s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
490 g_value_init (&val, GST_TYPE_TAG_LIST);
491 g_value_take_boxed (&val, tag_list);
492 gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
493 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
498 * gst_message_new_buffering:
499 * @src: (transfer none): The object originating the message.
500 * @percent: The buffering percent
502 * Create a new buffering message. This message can be posted by an element that
503 * needs to buffer data before it can continue processing. @percent should be a
504 * value between 0 and 100. A value of 100 means that the buffering completed.
506 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
507 * @percent is 100, the application can set the pipeline (back) to PLAYING.
508 * The application must be prepared to receive BUFFERING messages in the
509 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
510 * message with @percent set to 100, which can happen after the pipeline
511 * completed prerolling.
515 * Returns: (transfer full): The new buffering message.
520 gst_message_new_buffering (GstObject * src, gint percent)
523 GstStructure *structure;
525 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
527 structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
528 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
529 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
530 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
531 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
532 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
533 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
534 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
540 * gst_message_new_state_changed:
541 * @src: (transfer none): the object originating the message
542 * @oldstate: the previous state
543 * @newstate: the new (current) state
544 * @pending: the pending (target) state
546 * Create a state change message. This message is posted whenever an element
549 * Returns: (transfer full): the new state change message.
554 gst_message_new_state_changed (GstObject * src,
555 GstState oldstate, GstState newstate, GstState pending)
558 GstStructure *structure;
560 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
561 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
562 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
563 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
564 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
570 * gst_message_new_state_dirty:
571 * @src: (transfer none): the object originating the message
573 * Create a state dirty message. This message is posted whenever an element
574 * changed its state asynchronously and is used internally to update the
575 * states of container objects.
577 * Returns: (transfer full): the new state dirty message.
582 gst_message_new_state_dirty (GstObject * src)
586 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
592 * gst_message_new_clock_provide:
593 * @src: (transfer none): the object originating the message.
594 * @clock: (transfer none): the clock it provides
595 * @ready: TRUE if the sender can provide a clock
597 * Create a clock provide message. This message is posted whenever an
598 * element is ready to provide a clock or lost its ability to provide
599 * a clock (maybe because it paused or became EOS).
601 * This message is mainly used internally to manage the clock
604 * Returns: (transfer full): the new provide clock message.
609 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
613 GstStructure *structure;
615 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
616 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
617 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
618 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
624 * gst_message_new_clock_lost:
625 * @src: (transfer none): the object originating the message.
626 * @clock: (transfer none): the clock that was lost
628 * Create a clock lost message. This message is posted whenever the
629 * clock is not valid anymore.
631 * If this message is posted by the pipeline, the pipeline will
632 * select a new clock again when it goes to PLAYING. It might therefore
633 * be needed to set the pipeline to PAUSED and PLAYING again.
635 * Returns: (transfer full): The new clock lost message.
640 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
643 GstStructure *structure;
645 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
646 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
647 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
653 * gst_message_new_new_clock:
654 * @src: (transfer none): The object originating the message.
655 * @clock: (transfer none): the new selected clock
657 * Create a new clock message. This message is posted whenever the
658 * pipeline selectes a new clock for the pipeline.
660 * Returns: (transfer full): The new new clock message.
665 gst_message_new_new_clock (GstObject * src, GstClock * clock)
668 GstStructure *structure;
670 structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
671 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
672 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
678 * gst_message_new_structure_change:
679 * @src: (transfer none): The object originating the message.
680 * @type: The change type.
681 * @owner: (transfer none): The owner element of @src.
682 * @busy: Whether the structure change is busy.
684 * Create a new structure change message. This message is posted when the
685 * structure of a pipeline is in the process of being changed, for example
686 * when pads are linked or unlinked.
688 * @src should be the sinkpad that unlinked or linked.
690 * Returns: (transfer full): the new structure change message.
697 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
698 GstElement * owner, gboolean busy)
701 GstStructure *structure;
703 g_return_val_if_fail (GST_IS_PAD (src), NULL);
704 /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
705 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
707 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
708 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
709 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
710 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
712 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
719 * gst_message_new_segment_start:
720 * @src: (transfer none): The object originating the message.
721 * @format: The format of the position being played
722 * @position: The position of the segment being played
724 * Create a new segment message. This message is posted by elements that
725 * start playback of a segment as a result of a segment seek. This message
726 * is not received by the application but is used for maintenance reasons in
727 * container elements.
729 * Returns: (transfer full): the new segment start message.
734 gst_message_new_segment_start (GstObject * src, GstFormat format,
738 GstStructure *structure;
740 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
741 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
742 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
743 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
749 * gst_message_new_segment_done:
750 * @src: (transfer none): the object originating the message.
751 * @format: The format of the position being done
752 * @position: The position of the segment being done
754 * Create a new segment done message. This message is posted by elements that
755 * finish playback of a segment as a result of a segment seek. This message
756 * is received by the application after all elements that posted a segment_start
757 * have posted the segment_done.
759 * Returns: (transfer full): the new segment done message.
764 gst_message_new_segment_done (GstObject * src, GstFormat format,
768 GstStructure *structure;
770 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
771 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
772 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
773 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
779 * gst_message_new_application:
780 * @src: (transfer none): the object originating the message.
781 * @structure: (transfer full): the structure for the message. The message
782 * will take ownership of the structure.
784 * Create a new application-typed message. GStreamer will never create these
785 * messages; they are a gift from us to you. Enjoy.
787 * Returns: (transfer full): The new application message.
792 gst_message_new_application (GstObject * src, GstStructure * structure)
794 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
798 * gst_message_new_element:
799 * @src: (transfer none): The object originating the message.
800 * @structure: (transfer full): The structure for the message. The message
801 * will take ownership of the structure.
803 * Create a new element-specific message. This is meant as a generic way of
804 * allowing one-way communication from an element to an application, for example
805 * "the firewire cable was unplugged". The format of the message should be
806 * documented in the element's documentation. The structure field can be NULL.
808 * Returns: (transfer full): The new element message.
813 gst_message_new_element (GstObject * src, GstStructure * structure)
815 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
819 * gst_message_new_duration:
820 * @src: (transfer none): The object originating the message.
821 * @format: The format of the duration
822 * @duration: The new duration
824 * Create a new duration message. This message is posted by elements that
825 * know the duration of a stream in a specific format. This message
826 * is received by bins and is used to calculate the total duration of a
827 * pipeline. Elements may post a duration message with a duration of
828 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
829 * cached duration should be discarded. The new duration can then be
830 * retrieved via a query.
832 * Returns: (transfer full): The new duration message.
837 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
840 GstStructure *structure;
842 structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION),
843 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
844 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
845 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
851 * gst_message_new_async_start:
852 * @src: (transfer none): The object originating the message.
854 * This message is posted by elements when they start an ASYNC state change.
856 * Returns: (transfer full): The new async_start message.
861 gst_message_new_async_start (GstObject * src)
865 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
871 * gst_message_new_async_done:
872 * @src: (transfer none): The object originating the message.
873 * @reset_time: if the running_time should be reset
875 * The message is posted when elements completed an ASYNC state change.
876 * @reset_time is set to TRUE when the element requests a new running_time
877 * before going to PLAYING.
879 * Returns: (transfer full): The new async_done message.
884 gst_message_new_async_done (GstObject * src, gboolean reset_time)
887 GstStructure *structure;
889 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
890 GST_QUARK (RESET_TIME), G_TYPE_BOOLEAN, reset_time, NULL);
891 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
897 * gst_message_new_latency:
898 * @src: (transfer none): The object originating the message.
900 * This message can be posted by elements when their latency requirements have
903 * Returns: (transfer full): The new latency message.
910 gst_message_new_latency (GstObject * src)
914 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
920 * gst_message_new_request_state:
921 * @src: (transfer none): the object originating the message.
922 * @state: The new requested state
924 * This message can be posted by elements when they want to have their state
925 * changed. A typical use case would be an audio server that wants to pause the
926 * pipeline because a higher priority stream is being played.
928 * Returns: (transfer full): the new requst state message.
935 gst_message_new_request_state (GstObject * src, GstState state)
938 GstStructure *structure;
940 structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
941 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
942 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
948 * gst_message_get_structure:
949 * @message: The #GstMessage.
951 * Access the structure of the message.
953 * Returns: (transfer none): The structure of the message. The structure is
954 * still owned by the message, which means that you should not free it and
955 * that the pointer becomes invalid when you free the message.
960 gst_message_get_structure (GstMessage * message)
962 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
964 return GST_MESSAGE_STRUCTURE (message);
968 * gst_message_has_name:
969 * @message: The #GstMessage.
970 * @name: name to check
972 * Checks if @message has the given @name. This function is usually used to
973 * check the name of a custom message.
975 * Returns: %TRUE if @name matches the name of the message structure.
980 gst_message_has_name (GstMessage * message, const gchar * name)
982 GstStructure *structure;
984 g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
986 structure = GST_MESSAGE_STRUCTURE (message);
987 if (structure == NULL)
990 return gst_structure_has_name (structure, name);
994 * gst_message_parse_tag:
995 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
996 * @tag_list: (out callee-allocates): return location for the tag-list.
998 * Extracts the tag list from the GstMessage. The tag list returned in the
999 * output argument is a copy; the caller must free it when done.
1001 * Typical usage of this function might be:
1004 * switch (GST_MESSAGE_TYPE (msg)) {
1005 * case GST_MESSAGE_TAG: {
1006 * GstTagList *tags = NULL;
1008 * gst_message_parse_tag (msg, &tags);
1009 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1010 * handle_tags (tags);
1011 * gst_tag_list_unref (tags);
1022 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1024 g_return_if_fail (GST_IS_MESSAGE (message));
1025 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1026 g_return_if_fail (tag_list != NULL);
1028 gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1029 GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
1033 * gst_message_parse_buffering:
1034 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1035 * @percent: (out) (allow-none): Return location for the percent.
1037 * Extracts the buffering percent from the GstMessage. see also
1038 * gst_message_new_buffering().
1045 gst_message_parse_buffering (GstMessage * message, gint * percent)
1047 g_return_if_fail (GST_IS_MESSAGE (message));
1048 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1052 g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1053 (message), GST_QUARK (BUFFER_PERCENT)));
1057 * gst_message_set_buffering_stats:
1058 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1059 * @mode: a buffering mode
1060 * @avg_in: the average input rate
1061 * @avg_out: the average output rate
1062 * @buffering_left: amount of buffering time left in milliseconds
1064 * Configures the buffering stats values in @message.
1069 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1070 gint avg_in, gint avg_out, gint64 buffering_left)
1072 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1074 gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1075 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1076 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1077 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1078 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1082 * gst_message_parse_buffering_stats:
1083 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1084 * @mode: (out) (allow-none): a buffering mode, or NULL
1085 * @avg_in: (out) (allow-none): the average input rate, or NULL
1086 * @avg_out: (out) (allow-none): the average output rate, or NULL
1087 * @buffering_left: (out) (allow-none): amount of buffering time left in
1088 * milliseconds, or NULL
1090 * Extracts the buffering stats values from @message.
1095 gst_message_parse_buffering_stats (GstMessage * message,
1096 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1097 gint64 * buffering_left)
1099 GstStructure *structure;
1101 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1103 structure = GST_MESSAGE_STRUCTURE (message);
1105 *mode = (GstBufferingMode)
1106 g_value_get_enum (gst_structure_id_get_value (structure,
1107 GST_QUARK (BUFFERING_MODE)));
1109 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1110 GST_QUARK (AVG_IN_RATE)));
1112 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1113 GST_QUARK (AVG_OUT_RATE)));
1116 g_value_get_int64 (gst_structure_id_get_value (structure,
1117 GST_QUARK (BUFFERING_LEFT)));
1121 * gst_message_parse_state_changed:
1122 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1123 * @oldstate: (out) (allow-none): the previous state, or NULL
1124 * @newstate: (out) (allow-none): the new (current) state, or NULL
1125 * @pending: (out) (allow-none): the pending (target) state, or NULL
1127 * Extracts the old and new states from the GstMessage.
1129 * Typical usage of this function might be:
1132 * switch (GST_MESSAGE_TYPE (msg)) {
1133 * case GST_MESSAGE_STATE_CHANGED: {
1134 * GstState old_state, new_state;
1136 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1137 * g_print ("Element %s changed state from %s to %s.\n",
1138 * GST_OBJECT_NAME (msg->src),
1139 * gst_element_state_get_name (old_state),
1140 * gst_element_state_get_name (new_state));
1151 gst_message_parse_state_changed (GstMessage * message,
1152 GstState * oldstate, GstState * newstate, GstState * pending)
1154 GstStructure *structure;
1156 g_return_if_fail (GST_IS_MESSAGE (message));
1157 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1159 structure = GST_MESSAGE_STRUCTURE (message);
1161 *oldstate = (GstState)
1162 g_value_get_enum (gst_structure_id_get_value (structure,
1163 GST_QUARK (OLD_STATE)));
1165 *newstate = (GstState)
1166 g_value_get_enum (gst_structure_id_get_value (structure,
1167 GST_QUARK (NEW_STATE)));
1169 *pending = (GstState)
1170 g_value_get_enum (gst_structure_id_get_value (structure,
1171 GST_QUARK (PENDING_STATE)));
1175 * gst_message_parse_clock_provide:
1176 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1177 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1179 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1181 * Extracts the clock and ready flag from the GstMessage.
1182 * The clock object returned remains valid until the message is freed.
1187 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1190 const GValue *clock_gvalue;
1191 GstStructure *structure;
1193 g_return_if_fail (GST_IS_MESSAGE (message));
1194 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1196 structure = GST_MESSAGE_STRUCTURE (message);
1197 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1198 g_return_if_fail (clock_gvalue != NULL);
1199 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1203 g_value_get_boolean (gst_structure_id_get_value (structure,
1204 GST_QUARK (READY)));
1206 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1210 * gst_message_parse_clock_lost:
1211 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1212 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1214 * Extracts the lost clock from the GstMessage.
1215 * The clock object returned remains valid until the message is freed.
1220 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1222 const GValue *clock_gvalue;
1223 GstStructure *structure;
1225 g_return_if_fail (GST_IS_MESSAGE (message));
1226 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1228 structure = GST_MESSAGE_STRUCTURE (message);
1229 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1230 g_return_if_fail (clock_gvalue != NULL);
1231 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1234 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1238 * gst_message_parse_new_clock:
1239 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1240 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1243 * Extracts the new clock from the GstMessage.
1244 * The clock object returned remains valid until the message is freed.
1249 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1251 const GValue *clock_gvalue;
1252 GstStructure *structure;
1254 g_return_if_fail (GST_IS_MESSAGE (message));
1255 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1257 structure = GST_MESSAGE_STRUCTURE (message);
1258 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1259 g_return_if_fail (clock_gvalue != NULL);
1260 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1263 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1267 * gst_message_parse_structure_change:
1268 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1269 * @type: (out): A pointer to hold the change type
1270 * @owner: (out) (allow-none) (transfer none): The owner element of the
1272 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1273 * progress or has been completed
1275 * Extracts the change type and completion status from the GstMessage.
1282 gst_message_parse_structure_change (GstMessage * message,
1283 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1285 const GValue *owner_gvalue;
1286 GstStructure *structure;
1288 g_return_if_fail (GST_IS_MESSAGE (message));
1289 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1291 structure = GST_MESSAGE_STRUCTURE (message);
1292 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1293 g_return_if_fail (owner_gvalue != NULL);
1294 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1297 *type = (GstStructureChangeType)
1298 g_value_get_enum (gst_structure_id_get_value (structure,
1301 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1304 g_value_get_boolean (gst_structure_id_get_value (structure,
1309 * gst_message_parse_error:
1310 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1311 * @gerror: (out) (allow-none) (transfer full): location for the GError
1312 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1315 * Extracts the GError and debug string from the GstMessage. The values returned
1316 * in the output arguments are copies; the caller must free them when done.
1318 * Typical usage of this function might be:
1321 * switch (GST_MESSAGE_TYPE (msg)) {
1322 * case GST_MESSAGE_ERROR: {
1323 * GError *err = NULL;
1324 * gchar *dbg_info = NULL;
1326 * gst_message_parse_error (msg, &err, &dbg_info);
1327 * g_printerr ("ERROR from element %s: %s\n",
1328 * GST_OBJECT_NAME (msg->src), err->message);
1329 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1330 * g_error_free (err);
1331 * g_free (dbg_info);
1342 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1344 const GValue *error_gvalue;
1346 GstStructure *structure;
1348 g_return_if_fail (GST_IS_MESSAGE (message));
1349 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1351 structure = GST_MESSAGE_STRUCTURE (message);
1352 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1353 g_return_if_fail (error_gvalue != NULL);
1354 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1356 error_val = (GError *) g_value_get_boxed (error_gvalue);
1358 *gerror = g_error_copy (error_val);
1364 g_value_dup_string (gst_structure_id_get_value (structure,
1365 GST_QUARK (DEBUG)));
1369 * gst_message_parse_warning:
1370 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1371 * @gerror: (out) (allow-none) (transfer full): location for the GError
1372 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1375 * Extracts the GError and debug string from the GstMessage. The values returned
1376 * in the output arguments are copies; the caller must free them when done.
1381 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1384 const GValue *error_gvalue;
1386 GstStructure *structure;
1388 g_return_if_fail (GST_IS_MESSAGE (message));
1389 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1391 structure = GST_MESSAGE_STRUCTURE (message);
1392 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1393 g_return_if_fail (error_gvalue != NULL);
1394 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1396 error_val = (GError *) g_value_get_boxed (error_gvalue);
1398 *gerror = g_error_copy (error_val);
1404 g_value_dup_string (gst_structure_id_get_value (structure,
1405 GST_QUARK (DEBUG)));
1409 * gst_message_parse_info:
1410 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1411 * @gerror: (out) (allow-none) (transfer full): location for the GError
1412 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1415 * Extracts the GError and debug string from the GstMessage. The values returned
1416 * in the output arguments are copies; the caller must free them when done.
1423 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1425 const GValue *error_gvalue;
1427 GstStructure *structure;
1429 g_return_if_fail (GST_IS_MESSAGE (message));
1430 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1432 structure = GST_MESSAGE_STRUCTURE (message);
1433 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1434 g_return_if_fail (error_gvalue != NULL);
1435 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1437 error_val = (GError *) g_value_get_boxed (error_gvalue);
1439 *gerror = g_error_copy (error_val);
1445 g_value_dup_string (gst_structure_id_get_value (structure,
1446 GST_QUARK (DEBUG)));
1450 * gst_message_parse_segment_start:
1451 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1452 * @format: (out): Result location for the format, or NULL
1453 * @position: (out): Result location for the position, or NULL
1455 * Extracts the position and format from the segment start message.
1460 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1463 GstStructure *structure;
1465 g_return_if_fail (GST_IS_MESSAGE (message));
1466 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1468 structure = GST_MESSAGE_STRUCTURE (message);
1470 *format = (GstFormat)
1471 g_value_get_enum (gst_structure_id_get_value (structure,
1472 GST_QUARK (FORMAT)));
1475 g_value_get_int64 (gst_structure_id_get_value (structure,
1476 GST_QUARK (POSITION)));
1480 * gst_message_parse_segment_done:
1481 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1482 * @format: (out): Result location for the format, or NULL
1483 * @position: (out): Result location for the position, or NULL
1485 * Extracts the position and format from the segment start message.
1490 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1493 GstStructure *structure;
1495 g_return_if_fail (GST_IS_MESSAGE (message));
1496 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1498 structure = GST_MESSAGE_STRUCTURE (message);
1500 *format = (GstFormat)
1501 g_value_get_enum (gst_structure_id_get_value (structure,
1502 GST_QUARK (FORMAT)));
1505 g_value_get_int64 (gst_structure_id_get_value (structure,
1506 GST_QUARK (POSITION)));
1510 * gst_message_parse_duration:
1511 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1512 * @format: (out): Result location for the format, or NULL
1513 * @duration: (out): Result location for the duration, or NULL
1515 * Extracts the duration and format from the duration message. The duration
1516 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1517 * changed. Applications should always use a query to retrieve the duration
1523 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1526 GstStructure *structure;
1528 g_return_if_fail (GST_IS_MESSAGE (message));
1529 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1531 structure = GST_MESSAGE_STRUCTURE (message);
1533 *format = (GstFormat)
1534 g_value_get_enum (gst_structure_id_get_value (structure,
1535 GST_QUARK (FORMAT)));
1538 g_value_get_int64 (gst_structure_id_get_value (structure,
1539 GST_QUARK (DURATION)));
1543 * gst_message_parse_async_done:
1544 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1545 * @reset_time: (out): Result location for the reset_time or NULL
1547 * Extract the reset_time from the async_done message.
1552 gst_message_parse_async_done (GstMessage * message, gboolean * reset_time)
1554 GstStructure *structure;
1556 g_return_if_fail (GST_IS_MESSAGE (message));
1557 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1559 structure = GST_MESSAGE_STRUCTURE (message);
1562 g_value_get_boolean (gst_structure_id_get_value (structure,
1563 GST_QUARK (RESET_TIME)));
1567 * gst_message_parse_request_state:
1568 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1569 * @state: (out): Result location for the requested state or NULL
1571 * Extract the requested state from the request_state message.
1578 gst_message_parse_request_state (GstMessage * message, GstState * state)
1580 GstStructure *structure;
1582 g_return_if_fail (GST_IS_MESSAGE (message));
1583 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1585 structure = GST_MESSAGE_STRUCTURE (message);
1588 g_value_get_enum (gst_structure_id_get_value (structure,
1589 GST_QUARK (NEW_STATE)));
1593 * gst_message_new_stream_status:
1594 * @src: The object originating the message.
1595 * @type: The stream status type.
1596 * @owner: (transfer none): the owner element of @src.
1598 * Create a new stream status message. This message is posted when a streaming
1599 * thread is created/destroyed or when the state changed.
1601 * Returns: (transfer full): the new stream status message.
1608 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1611 GstMessage *message;
1612 GstStructure *structure;
1614 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1615 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1616 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1617 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1623 * gst_message_parse_stream_status:
1624 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1625 * @type: (out): A pointer to hold the status type
1626 * @owner: (out) (transfer none): The owner element of the message source
1628 * Extracts the stream status type and owner the GstMessage. The returned
1629 * owner remains valid for as long as the reference to @message is valid and
1630 * should thus not be unreffed.
1637 gst_message_parse_stream_status (GstMessage * message,
1638 GstStreamStatusType * type, GstElement ** owner)
1640 const GValue *owner_gvalue;
1641 GstStructure *structure;
1643 g_return_if_fail (GST_IS_MESSAGE (message));
1644 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1646 structure = GST_MESSAGE_STRUCTURE (message);
1647 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1648 g_return_if_fail (owner_gvalue != NULL);
1651 *type = (GstStreamStatusType)
1652 g_value_get_enum (gst_structure_id_get_value (structure,
1655 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1659 * gst_message_set_stream_status_object:
1660 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1661 * @object: the object controlling the streaming
1663 * Configures the object handling the streaming thread. This is usually a
1664 * GstTask object but other objects might be added in the future.
1669 gst_message_set_stream_status_object (GstMessage * message,
1670 const GValue * object)
1672 GstStructure *structure;
1674 g_return_if_fail (GST_IS_MESSAGE (message));
1675 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1677 structure = GST_MESSAGE_STRUCTURE (message);
1678 gst_structure_id_set_value (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;
1697 GstStructure *structure;
1699 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1700 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1703 structure = GST_MESSAGE_STRUCTURE (message);
1704 result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1710 * gst_message_new_step_done:
1711 * @src: The object originating the message.
1712 * @format: the format of @amount
1713 * @amount: the amount of stepped data
1714 * @rate: the rate of the stepped amount
1715 * @flush: is this an flushing step
1716 * @intermediate: is this an intermediate step
1717 * @duration: the duration of the data
1718 * @eos: the step caused EOS
1720 * This message is posted by elements when they complete a part, when @intermediate set
1721 * to TRUE, or a complete step operation.
1723 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1724 * @amount of media in format @format.
1726 * Returns: (transfer full): the new step_done message.
1733 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1734 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1737 GstMessage *message;
1738 GstStructure *structure;
1740 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
1741 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1742 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1743 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1744 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1745 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1746 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1747 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1748 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1754 * gst_message_parse_step_done:
1755 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1756 * @format: (out) (allow-none): result location for the format
1757 * @amount: (out) (allow-none): result location for the amount
1758 * @rate: (out) (allow-none): result location for the rate
1759 * @flush: (out) (allow-none): result location for the flush flag
1760 * @intermediate: (out) (allow-none): result location for the intermediate flag
1761 * @duration: (out) (allow-none): result location for the duration
1762 * @eos: (out) (allow-none): result location for the EOS flag
1764 * Extract the values the step_done message.
1771 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1772 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1773 guint64 * duration, gboolean * eos)
1775 GstStructure *structure;
1777 g_return_if_fail (GST_IS_MESSAGE (message));
1778 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1780 structure = GST_MESSAGE_STRUCTURE (message);
1781 gst_structure_id_get (structure,
1782 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1783 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1784 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1785 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1786 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1787 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1788 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1792 * gst_message_new_step_start:
1793 * @src: The object originating the message.
1794 * @active: if the step is active or queued
1795 * @format: the format of @amount
1796 * @amount: the amount of stepped data
1797 * @rate: the rate of the stepped amount
1798 * @flush: is this an flushing step
1799 * @intermediate: is this an intermediate step
1801 * This message is posted by elements when they accept or activate a new step
1802 * event for @amount in @format.
1804 * @active is set to FALSE when the element accepted the new step event and has
1805 * queued it for execution in the streaming threads.
1807 * @active is set to TRUE when the element has activated the step operation and
1808 * is now ready to start executing the step in the streaming thread. After this
1809 * message is emited, the application can queue a new step operation in the
1812 * Returns: (transfer full): The new step_start message.
1819 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1820 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1822 GstMessage *message;
1823 GstStructure *structure;
1825 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
1826 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1827 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1828 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1829 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1830 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1831 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1832 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1838 * gst_message_parse_step_start:
1839 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1840 * @active: (out) (allow-none): result location for the active flag
1841 * @format: (out) (allow-none): result location for the format
1842 * @amount: (out) (allow-none): result location for the amount
1843 * @rate: (out) (allow-none): result location for the rate
1844 * @flush: (out) (allow-none): result location for the flush flag
1845 * @intermediate: (out) (allow-none): result location for the intermediate flag
1847 * Extract the values from step_start message.
1854 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1855 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1856 gboolean * intermediate)
1858 GstStructure *structure;
1860 g_return_if_fail (GST_IS_MESSAGE (message));
1861 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1863 structure = GST_MESSAGE_STRUCTURE (message);
1864 gst_structure_id_get (structure,
1865 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1866 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1867 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1868 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1869 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1870 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1874 * gst_message_new_qos:
1875 * @src: The object originating the message.
1876 * @live: if the message was generated by a live element
1877 * @running_time: the running time of the buffer that generated the message
1878 * @stream_time: the stream time of the buffer that generated the message
1879 * @timestamp: the timestamps of the buffer that generated the message
1880 * @duration: the duration of the buffer that generated the message
1882 * A QOS message is posted on the bus whenever an element decides to drop a
1883 * buffer because of QoS reasons or whenever it changes its processing strategy
1884 * because of QoS reasons (quality adjustments such as processing at lower
1887 * This message can be posted by an element that performs synchronisation against the
1888 * clock (live) or it could be dropped by an element that performs QoS because of QOS
1889 * events received from a downstream element (!live).
1891 * @running_time, @stream_time, @timestamp, @duration should be set to the
1892 * respective running-time, stream-time, timestamp and duration of the (dropped)
1893 * buffer that generated the QoS event. Values can be left to
1894 * GST_CLOCK_TIME_NONE when unknown.
1896 * Returns: (transfer full): The new qos message.
1903 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1904 guint64 stream_time, guint64 timestamp, guint64 duration)
1906 GstMessage *message;
1907 GstStructure *structure;
1909 structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
1910 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1911 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1912 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1913 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1914 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1915 GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1916 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1917 GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1918 GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1919 GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1920 GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1921 message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1927 * gst_message_set_qos_values:
1928 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1929 * @jitter: The difference of the running-time against the deadline.
1930 * @proportion: Long term prediction of the ideal rate relative to normal rate
1931 * to get optimal quality.
1932 * @quality: An element dependent integer value that specifies the current
1933 * quality level of the element. The default maximum quality is 1000000.
1935 * Set the QoS values that have been calculated/analysed from the QoS data
1942 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
1943 gdouble proportion, gint quality)
1945 GstStructure *structure;
1947 g_return_if_fail (GST_IS_MESSAGE (message));
1948 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1950 structure = GST_MESSAGE_STRUCTURE (message);
1951 gst_structure_id_set (structure,
1952 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1953 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1954 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1958 * gst_message_set_qos_stats:
1959 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1960 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1961 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1962 * will likely use GST_FORMAT_DEFAULT (samples).
1963 * @processed: Total number of units correctly processed since the last state
1964 * change to READY or a flushing operation.
1965 * @dropped: Total number of units dropped since the last state change to READY
1966 * or a flushing operation.
1968 * Set the QoS stats representing the history of the current continuous pipeline
1971 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1972 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1979 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1980 guint64 processed, guint64 dropped)
1982 GstStructure *structure;
1984 g_return_if_fail (GST_IS_MESSAGE (message));
1985 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1987 structure = GST_MESSAGE_STRUCTURE (message);
1988 gst_structure_id_set (structure,
1989 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1990 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1991 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1995 * gst_message_parse_qos:
1996 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1997 * @live: (out) (allow-none): if the message was generated by a live element
1998 * @running_time: (out) (allow-none): the running time of the buffer that
1999 * generated the message
2000 * @stream_time: (out) (allow-none): the stream time of the buffer that
2001 * generated the message
2002 * @timestamp: (out) (allow-none): the timestamps of the buffer that
2003 * generated the message
2004 * @duration: (out) (allow-none): the duration of the buffer that
2005 * generated the message
2007 * Extract the timestamps and live status from the QoS message.
2009 * The returned values give the running_time, stream_time, timestamp and
2010 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2018 gst_message_parse_qos (GstMessage * message, gboolean * live,
2019 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2022 GstStructure *structure;
2024 g_return_if_fail (GST_IS_MESSAGE (message));
2025 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2027 structure = GST_MESSAGE_STRUCTURE (message);
2028 gst_structure_id_get (structure,
2029 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2030 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2031 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2032 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2033 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2037 * gst_message_parse_qos_values:
2038 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2039 * @jitter: (out) (allow-none): The difference of the running-time against
2041 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2042 * relative to normal rate to get optimal quality.
2043 * @quality: (out) (allow-none): An element dependent integer value that
2044 * specifies the current quality level of the element. The default
2045 * maximum quality is 1000000.
2047 * Extract the QoS values that have been calculated/analysed from the QoS data
2054 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2055 gdouble * proportion, gint * quality)
2057 GstStructure *structure;
2059 g_return_if_fail (GST_IS_MESSAGE (message));
2060 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2062 structure = GST_MESSAGE_STRUCTURE (message);
2063 gst_structure_id_get (structure,
2064 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2065 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2066 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2070 * gst_message_parse_qos_stats:
2071 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2072 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2073 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2074 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2076 * @processed: (out) (allow-none): Total number of units correctly processed
2077 * since the last state change to READY or a flushing operation.
2078 * @dropped: (out) (allow-none): Total number of units dropped since the last
2079 * state change to READY or a flushing operation.
2081 * Extract the QoS stats representing the history of the current continuous
2082 * pipeline playback period.
2084 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2085 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2092 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2093 guint64 * processed, guint64 * dropped)
2095 GstStructure *structure;
2097 g_return_if_fail (GST_IS_MESSAGE (message));
2098 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2100 structure = GST_MESSAGE_STRUCTURE (message);
2101 gst_structure_id_get (structure,
2102 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2103 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2104 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2108 * gst_message_new_progress:
2109 * @src: The object originating the message.
2110 * @type: a #GstProgressType
2111 * @code: a progress code
2112 * @text: free, user visible text describing the progress
2114 * Progress messages are posted by elements when they use an asynchronous task
2115 * to perform actions triggered by a state change.
2117 * @code contains a well defined string describing the action.
2118 * @test should contain a user visible string detailing the current action.
2120 * Returns: (transfer full): The new qos message.
2125 gst_message_new_progress (GstObject * src, GstProgressType type,
2126 const gchar * code, const gchar * text)
2128 GstMessage *message;
2129 GstStructure *structure;
2130 gint percent = 100, timeout = -1;
2132 g_return_val_if_fail (code != NULL, NULL);
2133 g_return_val_if_fail (text != NULL, NULL);
2135 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2138 structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2139 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2140 GST_QUARK (CODE), G_TYPE_STRING, code,
2141 GST_QUARK (TEXT), G_TYPE_STRING, text,
2142 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2143 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2144 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2150 * gst_message_parse_progress:
2151 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2152 * @type: (out) (allow-none): location for the type
2153 * @code: (out) (allow-none) (transfer full): location for the code
2154 * @text: (out) (allow-none) (transfer full): location for the text
2156 * Parses the progress @type, @code and @text.
2161 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2162 gchar ** code, gchar ** text)
2164 GstStructure *structure;
2166 g_return_if_fail (GST_IS_MESSAGE (message));
2167 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2169 structure = GST_MESSAGE_STRUCTURE (message);
2170 gst_structure_id_get (structure,
2171 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2172 GST_QUARK (CODE), G_TYPE_STRING, code,
2173 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2177 * gst_message_new_toc:
2178 * @src: the object originating the message.
2179 * @toc: #GstToc structure for the message.
2180 * @updated: whether TOC was updated or not.
2182 * Create a new TOC message. The message is posted by elements
2183 * that discovered or updated a TOC.
2185 * Returns: a new TOC message.
2192 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2194 GstStructure *toc_struct;
2196 g_return_val_if_fail (toc != NULL, NULL);
2198 toc_struct = __gst_toc_to_structure (toc);
2200 if (G_LIKELY (toc_struct != NULL)) {
2201 __gst_toc_structure_set_updated (toc_struct, updated);
2202 return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2208 * gst_message_parse_toc:
2209 * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2210 * @toc: (out): return location for the TOC.
2211 * @updated: (out): return location for the updated flag.
2213 * Extract thef TOC from the #GstMessage. The TOC returned in the
2214 * output argument is a copy; the caller must free it with
2215 * gst_toc_free() when done.
2222 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2224 g_return_if_fail (GST_IS_MESSAGE (message));
2225 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2226 g_return_if_fail (toc != NULL);
2228 *toc = __gst_toc_from_structure (GST_MESSAGE_STRUCTURE (message));
2230 if (updated != NULL)
2232 __gst_toc_structure_get_updated (GST_MESSAGE_STRUCTURE (message));