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"
69 GstStructure *structure;
72 #define GST_MESSAGE_SLICE_SIZE(m) (((GstMessageImpl *)(m))->slice_size)
73 #define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure)
82 static GstMessageQuarks message_quarks[] = {
83 {GST_MESSAGE_UNKNOWN, "unknown", 0},
84 {GST_MESSAGE_EOS, "eos", 0},
85 {GST_MESSAGE_ERROR, "error", 0},
86 {GST_MESSAGE_WARNING, "warning", 0},
87 {GST_MESSAGE_INFO, "info", 0},
88 {GST_MESSAGE_TAG, "tag", 0},
89 {GST_MESSAGE_BUFFERING, "buffering", 0},
90 {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
91 {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
92 {GST_MESSAGE_STEP_DONE, "step-done", 0},
93 {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
94 {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
95 {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
96 {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
97 {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
98 {GST_MESSAGE_APPLICATION, "application", 0},
99 {GST_MESSAGE_ELEMENT, "element", 0},
100 {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
101 {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
102 {GST_MESSAGE_DURATION, "duration", 0},
103 {GST_MESSAGE_LATENCY, "latency", 0},
104 {GST_MESSAGE_ASYNC_START, "async-start", 0},
105 {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
106 {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
107 {GST_MESSAGE_STEP_START, "step-start", 0},
108 {GST_MESSAGE_QOS, "qos", 0},
109 {GST_MESSAGE_PROGRESS, "progress", 0},
110 {GST_MESSAGE_TOC, "toc", 0},
114 static GType _gst_message_type = 0;
115 GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
118 _priv_gst_message_initialize (void)
122 GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
124 /* the GstMiniObject types need to be class_ref'd once before it can be
125 * done from multiple threads;
126 * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
127 gst_message_get_type ();
129 for (i = 0; message_quarks[i].name; i++) {
130 message_quarks[i].quark =
131 g_quark_from_static_string (message_quarks[i].name);
134 _gst_message_type = gst_message_get_type ();
138 * gst_message_type_get_name:
139 * @type: the message type
141 * Get a printable name for the given message type. Do not modify or free.
143 * Returns: a reference to the static name of the message.
146 gst_message_type_get_name (GstMessageType type)
150 for (i = 0; message_quarks[i].name; i++) {
151 if (type == message_quarks[i].type)
152 return message_quarks[i].name;
158 * gst_message_type_to_quark:
159 * @type: the message type
161 * Get the unique quark for the given message type.
163 * Returns: the quark associated with the message type
166 gst_message_type_to_quark (GstMessageType type)
170 for (i = 0; message_quarks[i].name; i++) {
171 if (type == message_quarks[i].type)
172 return message_quarks[i].quark;
178 _gst_message_free (GstMessage * message)
180 GstStructure *structure;
182 g_return_if_fail (message != NULL);
184 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
185 GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
187 if (GST_MESSAGE_SRC (message)) {
188 gst_object_unref (GST_MESSAGE_SRC (message));
189 GST_MESSAGE_SRC (message) = NULL;
192 if (message->lock.p) {
193 GST_MESSAGE_LOCK (message);
194 GST_MESSAGE_SIGNAL (message);
195 GST_MESSAGE_UNLOCK (message);
198 structure = GST_MESSAGE_STRUCTURE (message);
200 gst_structure_set_parent_refcount (structure, NULL);
201 gst_structure_free (structure);
204 g_slice_free1 (GST_MESSAGE_SLICE_SIZE (message), message);
208 gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type,
212 _gst_message_copy (GstMessage * message)
214 GstMessageImpl *copy;
215 GstStructure *structure;
217 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
218 GST_MESSAGE_TYPE_NAME (message),
219 GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
221 copy = g_slice_new0 (GstMessageImpl);
223 gst_message_init (copy, sizeof (GstMessageImpl), GST_MESSAGE_TYPE (message),
224 GST_MESSAGE_SRC (message));
226 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
227 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
229 structure = GST_MESSAGE_STRUCTURE (message);
231 GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
232 gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
233 ©->message.mini_object.refcount);
235 GST_MESSAGE_STRUCTURE (copy) = NULL;
238 return GST_MESSAGE_CAST (copy);
242 gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type,
245 gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type);
247 message->message.mini_object.copy =
248 (GstMiniObjectCopyFunction) _gst_message_copy;
249 message->message.mini_object.free =
250 (GstMiniObjectFreeFunction) _gst_message_free;
252 GST_MESSAGE_SLICE_SIZE (message) = size;
254 GST_MESSAGE_TYPE (message) = type;
256 gst_object_ref (src);
257 GST_MESSAGE_SRC (message) = src;
258 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
259 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
264 * gst_message_new_custom:
265 * @type: The #GstMessageType to distinguish messages
266 * @src: The object originating the message.
267 * @structure: (transfer full): the structure for the message. The message
268 * will take ownership of the structure.
270 * Create a new custom-typed message. This can be used for anything not
271 * handled by other message-specific functions to pass a message to the
272 * app. The structure field can be NULL.
274 * Returns: (transfer full): The new message.
279 gst_message_new_custom (GstMessageType type, GstObject * src,
280 GstStructure * structure)
282 GstMessageImpl *message;
284 message = g_slice_new0 (GstMessageImpl);
286 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
287 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
288 gst_message_type_get_name (type));
291 /* structure must not have a parent */
292 if (!gst_structure_set_parent_refcount (structure,
293 &message->message.mini_object.refcount))
296 gst_message_init (message, sizeof (GstMessageImpl), type, src);
298 GST_MESSAGE_STRUCTURE (message) = structure;
300 return GST_MESSAGE_CAST (message);
305 g_slice_free1 (GST_MESSAGE_SLICE_SIZE (message), message);
306 g_warning ("structure is already owned by another object");
312 * gst_message_get_seqnum:
313 * @message: A #GstMessage.
315 * Retrieve the sequence number of a message.
317 * Messages have ever-incrementing sequence numbers, which may also be set
318 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
319 * to indicate that a message corresponds to some other set of messages or
320 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
321 * is considered good practice to make this correspondence when possible, though
322 * it is not required.
324 * Note that events and messages share the same sequence number incrementor;
325 * two events or messages will never have the same sequence number unless
326 * that correspondence was made explicitly.
328 * Returns: The message's sequence number.
335 gst_message_get_seqnum (GstMessage * message)
337 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
339 return GST_MESSAGE_SEQNUM (message);
343 * gst_message_set_seqnum:
344 * @message: A #GstMessage.
345 * @seqnum: A sequence number.
347 * Set the sequence number of a message.
349 * This function might be called by the creator of a message to indicate that
350 * the message relates to other messages or events. See gst_message_get_seqnum()
351 * for more information.
358 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
360 g_return_if_fail (GST_IS_MESSAGE (message));
362 GST_MESSAGE_SEQNUM (message) = seqnum;
366 * gst_message_new_eos:
367 * @src: (transfer none): The object originating the message.
369 * Create a new eos message. This message is generated and posted in
370 * the sink elements of a GstBin. The bin will only forward the EOS
371 * message to the application if all sinks have posted an EOS message.
373 * Returns: (transfer full): The new eos message.
378 gst_message_new_eos (GstObject * src)
382 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
388 * gst_message_new_error:
389 * @src: (transfer none): The object originating the message.
390 * @error: (transfer none): The GError for this message.
391 * @debug: A debugging string.
393 * Create a new error message. The message will copy @error and
394 * @debug. This message is posted by element when a fatal event
395 * occured. The pipeline will probably (partially) stop. The application
396 * receiving this message should stop the pipeline.
398 * Returns: (transfer full): the new error message.
403 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
406 GstStructure *structure;
408 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
409 GST_QUARK (GERROR), G_TYPE_ERROR, error,
410 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
411 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
417 * gst_message_new_warning:
418 * @src: (transfer none): The object originating the message.
419 * @error: (transfer none): The GError for this message.
420 * @debug: A debugging string.
422 * Create a new warning message. The message will make copies of @error and
425 * Returns: (transfer full): The new warning message.
430 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
433 GstStructure *structure;
435 structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
436 GST_QUARK (GERROR), G_TYPE_ERROR, error,
437 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
438 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
444 * gst_message_new_info:
445 * @src: (transfer none): The object originating the message.
446 * @error: (transfer none): The GError for this message.
447 * @debug: A debugging string.
449 * Create a new info message. The message will make copies of @error and
454 * Returns: (transfer full): the new info message.
459 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
462 GstStructure *structure;
464 structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
465 GST_QUARK (GERROR), G_TYPE_ERROR, error,
466 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
467 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
473 * gst_message_new_tag:
474 * @src: (transfer none): The object originating the message.
475 * @tag_list: (transfer full): the tag list for the message.
477 * Create a new tag message. The message will take ownership of the tag list.
478 * The message is posted by elements that discovered a new taglist.
480 * Returns: (transfer full): the new tag message.
485 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
489 GValue val = G_VALUE_INIT;
491 g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
493 s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
494 g_value_init (&val, GST_TYPE_TAG_LIST);
495 g_value_take_boxed (&val, tag_list);
496 gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
497 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
502 * gst_message_new_buffering:
503 * @src: (transfer none): The object originating the message.
504 * @percent: The buffering percent
506 * Create a new buffering message. This message can be posted by an element that
507 * needs to buffer data before it can continue processing. @percent should be a
508 * value between 0 and 100. A value of 100 means that the buffering completed.
510 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
511 * @percent is 100, the application can set the pipeline (back) to PLAYING.
512 * The application must be prepared to receive BUFFERING messages in the
513 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
514 * message with @percent set to 100, which can happen after the pipeline
515 * completed prerolling.
519 * Returns: (transfer full): The new buffering message.
524 gst_message_new_buffering (GstObject * src, gint percent)
527 GstStructure *structure;
529 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
531 structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
532 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
533 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
534 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
535 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
536 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
537 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
538 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
544 * gst_message_new_state_changed:
545 * @src: (transfer none): the object originating the message
546 * @oldstate: the previous state
547 * @newstate: the new (current) state
548 * @pending: the pending (target) state
550 * Create a state change message. This message is posted whenever an element
553 * Returns: (transfer full): the new state change message.
558 gst_message_new_state_changed (GstObject * src,
559 GstState oldstate, GstState newstate, GstState pending)
562 GstStructure *structure;
564 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
565 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
566 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
567 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
568 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
574 * gst_message_new_state_dirty:
575 * @src: (transfer none): the object originating the message
577 * Create a state dirty message. This message is posted whenever an element
578 * changed its state asynchronously and is used internally to update the
579 * states of container objects.
581 * Returns: (transfer full): the new state dirty message.
586 gst_message_new_state_dirty (GstObject * src)
590 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
596 * gst_message_new_clock_provide:
597 * @src: (transfer none): the object originating the message.
598 * @clock: (transfer none): the clock it provides
599 * @ready: TRUE if the sender can provide a clock
601 * Create a clock provide message. This message is posted whenever an
602 * element is ready to provide a clock or lost its ability to provide
603 * a clock (maybe because it paused or became EOS).
605 * This message is mainly used internally to manage the clock
608 * Returns: (transfer full): the new provide clock message.
613 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
617 GstStructure *structure;
619 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
620 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
621 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
622 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
628 * gst_message_new_clock_lost:
629 * @src: (transfer none): the object originating the message.
630 * @clock: (transfer none): the clock that was lost
632 * Create a clock lost message. This message is posted whenever the
633 * clock is not valid anymore.
635 * If this message is posted by the pipeline, the pipeline will
636 * select a new clock again when it goes to PLAYING. It might therefore
637 * be needed to set the pipeline to PAUSED and PLAYING again.
639 * Returns: (transfer full): The new clock lost message.
644 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
647 GstStructure *structure;
649 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
650 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
651 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
657 * gst_message_new_new_clock:
658 * @src: (transfer none): The object originating the message.
659 * @clock: (transfer none): the new selected clock
661 * Create a new clock message. This message is posted whenever the
662 * pipeline selectes a new clock for the pipeline.
664 * Returns: (transfer full): The new new clock message.
669 gst_message_new_new_clock (GstObject * src, GstClock * clock)
672 GstStructure *structure;
674 structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
675 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
676 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
682 * gst_message_new_structure_change:
683 * @src: (transfer none): The object originating the message.
684 * @type: The change type.
685 * @owner: (transfer none): The owner element of @src.
686 * @busy: Whether the structure change is busy.
688 * Create a new structure change message. This message is posted when the
689 * structure of a pipeline is in the process of being changed, for example
690 * when pads are linked or unlinked.
692 * @src should be the sinkpad that unlinked or linked.
694 * Returns: (transfer full): the new structure change message.
701 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
702 GstElement * owner, gboolean busy)
705 GstStructure *structure;
707 g_return_val_if_fail (GST_IS_PAD (src), NULL);
708 /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
709 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
711 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
712 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
713 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
714 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
716 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
723 * gst_message_new_segment_start:
724 * @src: (transfer none): The object originating the message.
725 * @format: The format of the position being played
726 * @position: The position of the segment being played
728 * Create a new segment message. This message is posted by elements that
729 * start playback of a segment as a result of a segment seek. This message
730 * is not received by the application but is used for maintenance reasons in
731 * container elements.
733 * Returns: (transfer full): the new segment start message.
738 gst_message_new_segment_start (GstObject * src, GstFormat format,
742 GstStructure *structure;
744 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
745 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
746 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
747 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
753 * gst_message_new_segment_done:
754 * @src: (transfer none): the object originating the message.
755 * @format: The format of the position being done
756 * @position: The position of the segment being done
758 * Create a new segment done message. This message is posted by elements that
759 * finish playback of a segment as a result of a segment seek. This message
760 * is received by the application after all elements that posted a segment_start
761 * have posted the segment_done.
763 * Returns: (transfer full): the new segment done message.
768 gst_message_new_segment_done (GstObject * src, GstFormat format,
772 GstStructure *structure;
774 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
775 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
776 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
777 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
783 * gst_message_new_application:
784 * @src: (transfer none): the object originating the message.
785 * @structure: (transfer full): the structure for the message. The message
786 * will take ownership of the structure.
788 * Create a new application-typed message. GStreamer will never create these
789 * messages; they are a gift from us to you. Enjoy.
791 * Returns: (transfer full): The new application message.
796 gst_message_new_application (GstObject * src, GstStructure * structure)
798 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
802 * gst_message_new_element:
803 * @src: (transfer none): The object originating the message.
804 * @structure: (transfer full): The structure for the message. The message
805 * will take ownership of the structure.
807 * Create a new element-specific message. This is meant as a generic way of
808 * allowing one-way communication from an element to an application, for example
809 * "the firewire cable was unplugged". The format of the message should be
810 * documented in the element's documentation. The structure field can be NULL.
812 * Returns: (transfer full): The new element message.
817 gst_message_new_element (GstObject * src, GstStructure * structure)
819 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
823 * gst_message_new_duration:
824 * @src: (transfer none): The object originating the message.
825 * @format: The format of the duration
826 * @duration: The new duration
828 * Create a new duration message. This message is posted by elements that
829 * know the duration of a stream in a specific format. This message
830 * is received by bins and is used to calculate the total duration of a
831 * pipeline. Elements may post a duration message with a duration of
832 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
833 * cached duration should be discarded. The new duration can then be
834 * retrieved via a query.
836 * Returns: (transfer full): The new duration message.
841 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
844 GstStructure *structure;
846 structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION),
847 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
848 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
849 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
855 * gst_message_new_async_start:
856 * @src: (transfer none): The object originating the message.
858 * This message is posted by elements when they start an ASYNC state change.
860 * Returns: (transfer full): The new async_start message.
865 gst_message_new_async_start (GstObject * src)
869 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
875 * gst_message_new_async_done:
876 * @src: (transfer none): The object originating the message.
877 * @running_time: the desired running_time
879 * The message is posted when elements completed an ASYNC state change.
880 * @running_time contains the time of the desired running_time when this
881 * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
882 * means that the element has no clock interaction and thus doesn't care about
883 * the running_time of the pipeline.
885 * Returns: (transfer full): The new async_done message.
890 gst_message_new_async_done (GstObject * src, GstClockTime running_time)
893 GstStructure *structure;
895 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
896 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
897 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
903 * gst_message_new_latency:
904 * @src: (transfer none): The object originating the message.
906 * This message can be posted by elements when their latency requirements have
909 * Returns: (transfer full): The new latency message.
916 gst_message_new_latency (GstObject * src)
920 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
926 * gst_message_new_request_state:
927 * @src: (transfer none): the object originating the message.
928 * @state: The new requested state
930 * This message can be posted by elements when they want to have their state
931 * changed. A typical use case would be an audio server that wants to pause the
932 * pipeline because a higher priority stream is being played.
934 * Returns: (transfer full): the new requst state message.
941 gst_message_new_request_state (GstObject * src, GstState state)
944 GstStructure *structure;
946 structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
947 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
948 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
954 * gst_message_get_structure:
955 * @message: The #GstMessage.
957 * Access the structure of the message.
959 * Returns: (transfer none): The structure of the message. The structure is
960 * still owned by the message, which means that you should not free it and
961 * that the pointer becomes invalid when you free the message.
966 gst_message_get_structure (GstMessage * message)
968 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
970 return GST_MESSAGE_STRUCTURE (message);
974 * gst_message_has_name:
975 * @message: The #GstMessage.
976 * @name: name to check
978 * Checks if @message has the given @name. This function is usually used to
979 * check the name of a custom message.
981 * Returns: %TRUE if @name matches the name of the message structure.
986 gst_message_has_name (GstMessage * message, const gchar * name)
988 GstStructure *structure;
990 g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
992 structure = GST_MESSAGE_STRUCTURE (message);
993 if (structure == NULL)
996 return gst_structure_has_name (structure, name);
1000 * gst_message_parse_tag:
1001 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1002 * @tag_list: (out callee-allocates): return location for the tag-list.
1004 * Extracts the tag list from the GstMessage. The tag list returned in the
1005 * output argument is a copy; the caller must free it when done.
1007 * Typical usage of this function might be:
1010 * switch (GST_MESSAGE_TYPE (msg)) {
1011 * case GST_MESSAGE_TAG: {
1012 * GstTagList *tags = NULL;
1014 * gst_message_parse_tag (msg, &tags);
1015 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1016 * handle_tags (tags);
1017 * gst_tag_list_unref (tags);
1028 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1030 g_return_if_fail (GST_IS_MESSAGE (message));
1031 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1032 g_return_if_fail (tag_list != NULL);
1034 gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1035 GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
1039 * gst_message_parse_buffering:
1040 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1041 * @percent: (out) (allow-none): Return location for the percent.
1043 * Extracts the buffering percent from the GstMessage. see also
1044 * gst_message_new_buffering().
1051 gst_message_parse_buffering (GstMessage * message, gint * percent)
1053 g_return_if_fail (GST_IS_MESSAGE (message));
1054 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1058 g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1059 (message), GST_QUARK (BUFFER_PERCENT)));
1063 * gst_message_set_buffering_stats:
1064 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1065 * @mode: a buffering mode
1066 * @avg_in: the average input rate
1067 * @avg_out: the average output rate
1068 * @buffering_left: amount of buffering time left in milliseconds
1070 * Configures the buffering stats values in @message.
1075 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1076 gint avg_in, gint avg_out, gint64 buffering_left)
1078 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1080 gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1081 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1082 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1083 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1084 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1088 * gst_message_parse_buffering_stats:
1089 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1090 * @mode: (out) (allow-none): a buffering mode, or NULL
1091 * @avg_in: (out) (allow-none): the average input rate, or NULL
1092 * @avg_out: (out) (allow-none): the average output rate, or NULL
1093 * @buffering_left: (out) (allow-none): amount of buffering time left in
1094 * milliseconds, or NULL
1096 * Extracts the buffering stats values from @message.
1101 gst_message_parse_buffering_stats (GstMessage * message,
1102 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1103 gint64 * buffering_left)
1105 GstStructure *structure;
1107 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1109 structure = GST_MESSAGE_STRUCTURE (message);
1111 *mode = (GstBufferingMode)
1112 g_value_get_enum (gst_structure_id_get_value (structure,
1113 GST_QUARK (BUFFERING_MODE)));
1115 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1116 GST_QUARK (AVG_IN_RATE)));
1118 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1119 GST_QUARK (AVG_OUT_RATE)));
1122 g_value_get_int64 (gst_structure_id_get_value (structure,
1123 GST_QUARK (BUFFERING_LEFT)));
1127 * gst_message_parse_state_changed:
1128 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1129 * @oldstate: (out) (allow-none): the previous state, or NULL
1130 * @newstate: (out) (allow-none): the new (current) state, or NULL
1131 * @pending: (out) (allow-none): the pending (target) state, or NULL
1133 * Extracts the old and new states from the GstMessage.
1135 * Typical usage of this function might be:
1138 * switch (GST_MESSAGE_TYPE (msg)) {
1139 * case GST_MESSAGE_STATE_CHANGED: {
1140 * GstState old_state, new_state;
1142 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1143 * g_print ("Element %s changed state from %s to %s.\n",
1144 * GST_OBJECT_NAME (msg->src),
1145 * gst_element_state_get_name (old_state),
1146 * gst_element_state_get_name (new_state));
1157 gst_message_parse_state_changed (GstMessage * message,
1158 GstState * oldstate, GstState * newstate, GstState * pending)
1160 GstStructure *structure;
1162 g_return_if_fail (GST_IS_MESSAGE (message));
1163 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1165 structure = GST_MESSAGE_STRUCTURE (message);
1167 *oldstate = (GstState)
1168 g_value_get_enum (gst_structure_id_get_value (structure,
1169 GST_QUARK (OLD_STATE)));
1171 *newstate = (GstState)
1172 g_value_get_enum (gst_structure_id_get_value (structure,
1173 GST_QUARK (NEW_STATE)));
1175 *pending = (GstState)
1176 g_value_get_enum (gst_structure_id_get_value (structure,
1177 GST_QUARK (PENDING_STATE)));
1181 * gst_message_parse_clock_provide:
1182 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1183 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1185 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1187 * Extracts the clock and ready flag from the GstMessage.
1188 * The clock object returned remains valid until the message is freed.
1193 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1196 const GValue *clock_gvalue;
1197 GstStructure *structure;
1199 g_return_if_fail (GST_IS_MESSAGE (message));
1200 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1202 structure = GST_MESSAGE_STRUCTURE (message);
1203 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1204 g_return_if_fail (clock_gvalue != NULL);
1205 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1209 g_value_get_boolean (gst_structure_id_get_value (structure,
1210 GST_QUARK (READY)));
1212 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1216 * gst_message_parse_clock_lost:
1217 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1218 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1220 * Extracts the lost clock from the GstMessage.
1221 * The clock object returned remains valid until the message is freed.
1226 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1228 const GValue *clock_gvalue;
1229 GstStructure *structure;
1231 g_return_if_fail (GST_IS_MESSAGE (message));
1232 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1234 structure = GST_MESSAGE_STRUCTURE (message);
1235 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1236 g_return_if_fail (clock_gvalue != NULL);
1237 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1240 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1244 * gst_message_parse_new_clock:
1245 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1246 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1249 * Extracts the new clock from the GstMessage.
1250 * The clock object returned remains valid until the message is freed.
1255 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1257 const GValue *clock_gvalue;
1258 GstStructure *structure;
1260 g_return_if_fail (GST_IS_MESSAGE (message));
1261 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1263 structure = GST_MESSAGE_STRUCTURE (message);
1264 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1265 g_return_if_fail (clock_gvalue != NULL);
1266 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1269 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1273 * gst_message_parse_structure_change:
1274 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1275 * @type: (out): A pointer to hold the change type
1276 * @owner: (out) (allow-none) (transfer none): The owner element of the
1278 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1279 * progress or has been completed
1281 * Extracts the change type and completion status from the GstMessage.
1288 gst_message_parse_structure_change (GstMessage * message,
1289 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1291 const GValue *owner_gvalue;
1292 GstStructure *structure;
1294 g_return_if_fail (GST_IS_MESSAGE (message));
1295 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1297 structure = GST_MESSAGE_STRUCTURE (message);
1298 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1299 g_return_if_fail (owner_gvalue != NULL);
1300 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1303 *type = (GstStructureChangeType)
1304 g_value_get_enum (gst_structure_id_get_value (structure,
1307 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1310 g_value_get_boolean (gst_structure_id_get_value (structure,
1315 * gst_message_parse_error:
1316 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1317 * @gerror: (out) (allow-none) (transfer full): location for the GError
1318 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1321 * Extracts the GError and debug string from the GstMessage. The values returned
1322 * in the output arguments are copies; the caller must free them when done.
1324 * Typical usage of this function might be:
1327 * switch (GST_MESSAGE_TYPE (msg)) {
1328 * case GST_MESSAGE_ERROR: {
1329 * GError *err = NULL;
1330 * gchar *dbg_info = NULL;
1332 * gst_message_parse_error (msg, &err, &dbg_info);
1333 * g_printerr ("ERROR from element %s: %s\n",
1334 * GST_OBJECT_NAME (msg->src), err->message);
1335 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1336 * g_error_free (err);
1337 * g_free (dbg_info);
1348 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1350 const GValue *error_gvalue;
1352 GstStructure *structure;
1354 g_return_if_fail (GST_IS_MESSAGE (message));
1355 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1357 structure = GST_MESSAGE_STRUCTURE (message);
1358 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1359 g_return_if_fail (error_gvalue != NULL);
1360 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1362 error_val = (GError *) g_value_get_boxed (error_gvalue);
1364 *gerror = g_error_copy (error_val);
1370 g_value_dup_string (gst_structure_id_get_value (structure,
1371 GST_QUARK (DEBUG)));
1375 * gst_message_parse_warning:
1376 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1377 * @gerror: (out) (allow-none) (transfer full): location for the GError
1378 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1381 * Extracts the GError and debug string from the GstMessage. The values returned
1382 * in the output arguments are copies; the caller must free them when done.
1387 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1390 const GValue *error_gvalue;
1392 GstStructure *structure;
1394 g_return_if_fail (GST_IS_MESSAGE (message));
1395 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1397 structure = GST_MESSAGE_STRUCTURE (message);
1398 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1399 g_return_if_fail (error_gvalue != NULL);
1400 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1402 error_val = (GError *) g_value_get_boxed (error_gvalue);
1404 *gerror = g_error_copy (error_val);
1410 g_value_dup_string (gst_structure_id_get_value (structure,
1411 GST_QUARK (DEBUG)));
1415 * gst_message_parse_info:
1416 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1417 * @gerror: (out) (allow-none) (transfer full): location for the GError
1418 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1421 * Extracts the GError and debug string from the GstMessage. The values returned
1422 * in the output arguments are copies; the caller must free them when done.
1429 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1431 const GValue *error_gvalue;
1433 GstStructure *structure;
1435 g_return_if_fail (GST_IS_MESSAGE (message));
1436 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1438 structure = GST_MESSAGE_STRUCTURE (message);
1439 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1440 g_return_if_fail (error_gvalue != NULL);
1441 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1443 error_val = (GError *) g_value_get_boxed (error_gvalue);
1445 *gerror = g_error_copy (error_val);
1451 g_value_dup_string (gst_structure_id_get_value (structure,
1452 GST_QUARK (DEBUG)));
1456 * gst_message_parse_segment_start:
1457 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1458 * @format: (out): Result location for the format, or NULL
1459 * @position: (out): Result location for the position, or NULL
1461 * Extracts the position and format from the segment start message.
1466 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1469 GstStructure *structure;
1471 g_return_if_fail (GST_IS_MESSAGE (message));
1472 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1474 structure = GST_MESSAGE_STRUCTURE (message);
1476 *format = (GstFormat)
1477 g_value_get_enum (gst_structure_id_get_value (structure,
1478 GST_QUARK (FORMAT)));
1481 g_value_get_int64 (gst_structure_id_get_value (structure,
1482 GST_QUARK (POSITION)));
1486 * gst_message_parse_segment_done:
1487 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1488 * @format: (out): Result location for the format, or NULL
1489 * @position: (out): Result location for the position, or NULL
1491 * Extracts the position and format from the segment start message.
1496 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1499 GstStructure *structure;
1501 g_return_if_fail (GST_IS_MESSAGE (message));
1502 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1504 structure = GST_MESSAGE_STRUCTURE (message);
1506 *format = (GstFormat)
1507 g_value_get_enum (gst_structure_id_get_value (structure,
1508 GST_QUARK (FORMAT)));
1511 g_value_get_int64 (gst_structure_id_get_value (structure,
1512 GST_QUARK (POSITION)));
1516 * gst_message_parse_duration:
1517 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1518 * @format: (out): Result location for the format, or NULL
1519 * @duration: (out): Result location for the duration, or NULL
1521 * Extracts the duration and format from the duration message. The duration
1522 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1523 * changed. Applications should always use a query to retrieve the duration
1529 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1532 GstStructure *structure;
1534 g_return_if_fail (GST_IS_MESSAGE (message));
1535 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1537 structure = GST_MESSAGE_STRUCTURE (message);
1539 *format = (GstFormat)
1540 g_value_get_enum (gst_structure_id_get_value (structure,
1541 GST_QUARK (FORMAT)));
1544 g_value_get_int64 (gst_structure_id_get_value (structure,
1545 GST_QUARK (DURATION)));
1549 * gst_message_parse_async_done:
1550 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1551 * @running_time: (out): Result location for the running_time or NULL
1553 * Extract the running_time from the async_done message.
1558 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
1560 GstStructure *structure;
1562 g_return_if_fail (GST_IS_MESSAGE (message));
1563 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1565 structure = GST_MESSAGE_STRUCTURE (message);
1568 g_value_get_uint64 (gst_structure_id_get_value (structure,
1569 GST_QUARK (RUNNING_TIME)));
1573 * gst_message_parse_request_state:
1574 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1575 * @state: (out): Result location for the requested state or NULL
1577 * Extract the requested state from the request_state message.
1584 gst_message_parse_request_state (GstMessage * message, GstState * state)
1586 GstStructure *structure;
1588 g_return_if_fail (GST_IS_MESSAGE (message));
1589 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1591 structure = GST_MESSAGE_STRUCTURE (message);
1594 g_value_get_enum (gst_structure_id_get_value (structure,
1595 GST_QUARK (NEW_STATE)));
1599 * gst_message_new_stream_status:
1600 * @src: The object originating the message.
1601 * @type: The stream status type.
1602 * @owner: (transfer none): the owner element of @src.
1604 * Create a new stream status message. This message is posted when a streaming
1605 * thread is created/destroyed or when the state changed.
1607 * Returns: (transfer full): the new stream status message.
1614 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1617 GstMessage *message;
1618 GstStructure *structure;
1620 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1621 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1622 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1623 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1629 * gst_message_parse_stream_status:
1630 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1631 * @type: (out): A pointer to hold the status type
1632 * @owner: (out) (transfer none): The owner element of the message source
1634 * Extracts the stream status type and owner the GstMessage. The returned
1635 * owner remains valid for as long as the reference to @message is valid and
1636 * should thus not be unreffed.
1643 gst_message_parse_stream_status (GstMessage * message,
1644 GstStreamStatusType * type, GstElement ** owner)
1646 const GValue *owner_gvalue;
1647 GstStructure *structure;
1649 g_return_if_fail (GST_IS_MESSAGE (message));
1650 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1652 structure = GST_MESSAGE_STRUCTURE (message);
1653 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1654 g_return_if_fail (owner_gvalue != NULL);
1657 *type = (GstStreamStatusType)
1658 g_value_get_enum (gst_structure_id_get_value (structure,
1661 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1665 * gst_message_set_stream_status_object:
1666 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1667 * @object: the object controlling the streaming
1669 * Configures the object handling the streaming thread. This is usually a
1670 * GstTask object but other objects might be added in the future.
1675 gst_message_set_stream_status_object (GstMessage * message,
1676 const GValue * object)
1678 GstStructure *structure;
1680 g_return_if_fail (GST_IS_MESSAGE (message));
1681 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1683 structure = GST_MESSAGE_STRUCTURE (message);
1684 gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
1688 * gst_message_get_stream_status_object:
1689 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1691 * Extracts the object managing the streaming thread from @message.
1693 * Returns: a GValue containing the object that manages the streaming thread.
1694 * This object is usually of type GstTask but other types can be added in the
1695 * future. The object remains valid as long as @message is valid.
1700 gst_message_get_stream_status_object (GstMessage * message)
1702 const GValue *result;
1703 GstStructure *structure;
1705 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1706 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1709 structure = GST_MESSAGE_STRUCTURE (message);
1710 result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1716 * gst_message_new_step_done:
1717 * @src: The object originating the message.
1718 * @format: the format of @amount
1719 * @amount: the amount of stepped data
1720 * @rate: the rate of the stepped amount
1721 * @flush: is this an flushing step
1722 * @intermediate: is this an intermediate step
1723 * @duration: the duration of the data
1724 * @eos: the step caused EOS
1726 * This message is posted by elements when they complete a part, when @intermediate set
1727 * to TRUE, or a complete step operation.
1729 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1730 * @amount of media in format @format.
1732 * Returns: (transfer full): the new step_done message.
1739 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1740 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1743 GstMessage *message;
1744 GstStructure *structure;
1746 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
1747 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1748 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1749 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1750 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1751 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1752 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1753 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1754 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1760 * gst_message_parse_step_done:
1761 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1762 * @format: (out) (allow-none): result location for the format
1763 * @amount: (out) (allow-none): result location for the amount
1764 * @rate: (out) (allow-none): result location for the rate
1765 * @flush: (out) (allow-none): result location for the flush flag
1766 * @intermediate: (out) (allow-none): result location for the intermediate flag
1767 * @duration: (out) (allow-none): result location for the duration
1768 * @eos: (out) (allow-none): result location for the EOS flag
1770 * Extract the values the step_done message.
1777 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1778 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1779 guint64 * duration, gboolean * eos)
1781 GstStructure *structure;
1783 g_return_if_fail (GST_IS_MESSAGE (message));
1784 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1786 structure = GST_MESSAGE_STRUCTURE (message);
1787 gst_structure_id_get (structure,
1788 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1789 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1790 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1791 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1792 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1793 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1794 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1798 * gst_message_new_step_start:
1799 * @src: The object originating the message.
1800 * @active: if the step is active or queued
1801 * @format: the format of @amount
1802 * @amount: the amount of stepped data
1803 * @rate: the rate of the stepped amount
1804 * @flush: is this an flushing step
1805 * @intermediate: is this an intermediate step
1807 * This message is posted by elements when they accept or activate a new step
1808 * event for @amount in @format.
1810 * @active is set to FALSE when the element accepted the new step event and has
1811 * queued it for execution in the streaming threads.
1813 * @active is set to TRUE when the element has activated the step operation and
1814 * is now ready to start executing the step in the streaming thread. After this
1815 * message is emited, the application can queue a new step operation in the
1818 * Returns: (transfer full): The new step_start message.
1825 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1826 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1828 GstMessage *message;
1829 GstStructure *structure;
1831 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
1832 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1833 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1834 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1835 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1836 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1837 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1838 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1844 * gst_message_parse_step_start:
1845 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1846 * @active: (out) (allow-none): result location for the active flag
1847 * @format: (out) (allow-none): result location for the format
1848 * @amount: (out) (allow-none): result location for the amount
1849 * @rate: (out) (allow-none): result location for the rate
1850 * @flush: (out) (allow-none): result location for the flush flag
1851 * @intermediate: (out) (allow-none): result location for the intermediate flag
1853 * Extract the values from step_start message.
1860 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1861 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1862 gboolean * intermediate)
1864 GstStructure *structure;
1866 g_return_if_fail (GST_IS_MESSAGE (message));
1867 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1869 structure = GST_MESSAGE_STRUCTURE (message);
1870 gst_structure_id_get (structure,
1871 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1872 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1873 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1874 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1875 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1876 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1880 * gst_message_new_qos:
1881 * @src: The object originating the message.
1882 * @live: if the message was generated by a live element
1883 * @running_time: the running time of the buffer that generated the message
1884 * @stream_time: the stream time of the buffer that generated the message
1885 * @timestamp: the timestamps of the buffer that generated the message
1886 * @duration: the duration of the buffer that generated the message
1888 * A QOS message is posted on the bus whenever an element decides to drop a
1889 * buffer because of QoS reasons or whenever it changes its processing strategy
1890 * because of QoS reasons (quality adjustments such as processing at lower
1893 * This message can be posted by an element that performs synchronisation against the
1894 * clock (live) or it could be dropped by an element that performs QoS because of QOS
1895 * events received from a downstream element (!live).
1897 * @running_time, @stream_time, @timestamp, @duration should be set to the
1898 * respective running-time, stream-time, timestamp and duration of the (dropped)
1899 * buffer that generated the QoS event. Values can be left to
1900 * GST_CLOCK_TIME_NONE when unknown.
1902 * Returns: (transfer full): The new qos message.
1909 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1910 guint64 stream_time, guint64 timestamp, guint64 duration)
1912 GstMessage *message;
1913 GstStructure *structure;
1915 structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
1916 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1917 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1918 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1919 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1920 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1921 GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1922 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1923 GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1924 GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1925 GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1926 GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1927 message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1933 * gst_message_set_qos_values:
1934 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1935 * @jitter: The difference of the running-time against the deadline.
1936 * @proportion: Long term prediction of the ideal rate relative to normal rate
1937 * to get optimal quality.
1938 * @quality: An element dependent integer value that specifies the current
1939 * quality level of the element. The default maximum quality is 1000000.
1941 * Set the QoS values that have been calculated/analysed from the QoS data
1948 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
1949 gdouble proportion, gint quality)
1951 GstStructure *structure;
1953 g_return_if_fail (GST_IS_MESSAGE (message));
1954 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1956 structure = GST_MESSAGE_STRUCTURE (message);
1957 gst_structure_id_set (structure,
1958 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1959 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1960 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1964 * gst_message_set_qos_stats:
1965 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1966 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1967 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1968 * will likely use GST_FORMAT_DEFAULT (samples).
1969 * @processed: Total number of units correctly processed since the last state
1970 * change to READY or a flushing operation.
1971 * @dropped: Total number of units dropped since the last state change to READY
1972 * or a flushing operation.
1974 * Set the QoS stats representing the history of the current continuous pipeline
1977 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1978 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1985 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1986 guint64 processed, guint64 dropped)
1988 GstStructure *structure;
1990 g_return_if_fail (GST_IS_MESSAGE (message));
1991 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1993 structure = GST_MESSAGE_STRUCTURE (message);
1994 gst_structure_id_set (structure,
1995 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1996 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1997 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2001 * gst_message_parse_qos:
2002 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2003 * @live: (out) (allow-none): if the message was generated by a live element
2004 * @running_time: (out) (allow-none): the running time of the buffer that
2005 * generated the message
2006 * @stream_time: (out) (allow-none): the stream time of the buffer that
2007 * generated the message
2008 * @timestamp: (out) (allow-none): the timestamps of the buffer that
2009 * generated the message
2010 * @duration: (out) (allow-none): the duration of the buffer that
2011 * generated the message
2013 * Extract the timestamps and live status from the QoS message.
2015 * The returned values give the running_time, stream_time, timestamp and
2016 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2024 gst_message_parse_qos (GstMessage * message, gboolean * live,
2025 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2028 GstStructure *structure;
2030 g_return_if_fail (GST_IS_MESSAGE (message));
2031 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2033 structure = GST_MESSAGE_STRUCTURE (message);
2034 gst_structure_id_get (structure,
2035 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2036 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2037 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2038 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2039 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2043 * gst_message_parse_qos_values:
2044 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2045 * @jitter: (out) (allow-none): The difference of the running-time against
2047 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2048 * relative to normal rate to get optimal quality.
2049 * @quality: (out) (allow-none): An element dependent integer value that
2050 * specifies the current quality level of the element. The default
2051 * maximum quality is 1000000.
2053 * Extract the QoS values that have been calculated/analysed from the QoS data
2060 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2061 gdouble * proportion, gint * quality)
2063 GstStructure *structure;
2065 g_return_if_fail (GST_IS_MESSAGE (message));
2066 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2068 structure = GST_MESSAGE_STRUCTURE (message);
2069 gst_structure_id_get (structure,
2070 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2071 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2072 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2076 * gst_message_parse_qos_stats:
2077 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2078 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2079 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2080 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2082 * @processed: (out) (allow-none): Total number of units correctly processed
2083 * since the last state change to READY or a flushing operation.
2084 * @dropped: (out) (allow-none): Total number of units dropped since the last
2085 * state change to READY or a flushing operation.
2087 * Extract the QoS stats representing the history of the current continuous
2088 * pipeline playback period.
2090 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2091 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2098 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2099 guint64 * processed, guint64 * dropped)
2101 GstStructure *structure;
2103 g_return_if_fail (GST_IS_MESSAGE (message));
2104 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2106 structure = GST_MESSAGE_STRUCTURE (message);
2107 gst_structure_id_get (structure,
2108 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2109 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2110 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2114 * gst_message_new_progress:
2115 * @src: The object originating the message.
2116 * @type: a #GstProgressType
2117 * @code: a progress code
2118 * @text: free, user visible text describing the progress
2120 * Progress messages are posted by elements when they use an asynchronous task
2121 * to perform actions triggered by a state change.
2123 * @code contains a well defined string describing the action.
2124 * @test should contain a user visible string detailing the current action.
2126 * Returns: (transfer full): The new qos message.
2131 gst_message_new_progress (GstObject * src, GstProgressType type,
2132 const gchar * code, const gchar * text)
2134 GstMessage *message;
2135 GstStructure *structure;
2136 gint percent = 100, timeout = -1;
2138 g_return_val_if_fail (code != NULL, NULL);
2139 g_return_val_if_fail (text != NULL, NULL);
2141 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2144 structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2145 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2146 GST_QUARK (CODE), G_TYPE_STRING, code,
2147 GST_QUARK (TEXT), G_TYPE_STRING, text,
2148 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2149 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2150 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2156 * gst_message_parse_progress:
2157 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2158 * @type: (out) (allow-none): location for the type
2159 * @code: (out) (allow-none) (transfer full): location for the code
2160 * @text: (out) (allow-none) (transfer full): location for the text
2162 * Parses the progress @type, @code and @text.
2167 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2168 gchar ** code, gchar ** text)
2170 GstStructure *structure;
2172 g_return_if_fail (GST_IS_MESSAGE (message));
2173 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2175 structure = GST_MESSAGE_STRUCTURE (message);
2176 gst_structure_id_get (structure,
2177 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2178 GST_QUARK (CODE), G_TYPE_STRING, code,
2179 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2183 * gst_message_new_toc:
2184 * @src: the object originating the message.
2185 * @toc: #GstToc structure for the message.
2186 * @updated: whether TOC was updated or not.
2188 * Create a new TOC message. The message is posted by elements
2189 * that discovered or updated a TOC.
2191 * Returns: a new TOC message.
2198 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2200 GstStructure *toc_struct;
2202 g_return_val_if_fail (toc != NULL, NULL);
2204 toc_struct = __gst_toc_to_structure (toc);
2206 if (G_LIKELY (toc_struct != NULL)) {
2207 __gst_toc_structure_set_updated (toc_struct, updated);
2208 return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2214 * gst_message_parse_toc:
2215 * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2216 * @toc: (out): return location for the TOC.
2217 * @updated: (out): return location for the updated flag.
2219 * Extract thef TOC from the #GstMessage. The TOC returned in the
2220 * output argument is a copy; the caller must free it with
2221 * gst_toc_free() when done.
2228 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2230 g_return_if_fail (GST_IS_MESSAGE (message));
2231 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2232 g_return_if_fail (toc != NULL);
2234 *toc = __gst_toc_from_structure (GST_MESSAGE_STRUCTURE (message));
2236 if (updated != NULL)
2238 __gst_toc_structure_get_updated (GST_MESSAGE_STRUCTURE (message));
2242 * gst_message_new_reset_time:
2243 * @src: (transfer none): The object originating the message.
2244 * @running_time: the requested running-time
2246 * This message is posted when the pipeline running-time should be reset to
2247 * @running_time, like after a flushing seek.
2249 * Returns: (transfer full): The new reset_time message.
2254 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2256 GstMessage *message;
2257 GstStructure *structure;
2259 structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2260 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2261 message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2267 * gst_message_parse_reset_time:
2268 * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2269 * @running_time: (out): Result location for the running_time or NULL
2271 * Extract the running-time from the RESET_TIME message.
2276 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2278 GstStructure *structure;
2280 g_return_if_fail (GST_IS_MESSAGE (message));
2281 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2283 structure = GST_MESSAGE_STRUCTURE (message);
2286 g_value_get_uint64 (gst_structure_id_get_value (structure,
2287 GST_QUARK (RUNNING_TIME)));