2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
4 * gstmessage.c: GstMessage subsystem
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * @short_description: Lightweight objects to signal the application of
26 * @see_also: #GstBus, #GstMiniObject, #GstElement
28 * Messages are implemented as a subclass of #GstMiniObject with a generic
29 * #GstStructure as the content. This allows for writing custom messages without
30 * requiring an API change while allowing a wide range of different types
33 * Messages are posted by objects in the pipeline and are passed to the
34 * application using the #GstBus.
36 * The basic use pattern of posting a message on a #GstBus is as follows:
39 * <title>Posting a #GstMessage</title>
41 * gst_bus_post (bus, gst_message_new_eos());
45 * A #GstElement usually posts messages on the bus provided by the parent
46 * container using gst_element_post_message().
48 * Last reviewed on 2005-11-09 (0.9.4)
52 #include "gst_private.h"
53 #include <string.h> /* memcpy */
55 #include "gstenumtypes.h"
57 #include "gstmessage.h"
58 #include "gsttaglist.h"
67 GstStructure *structure;
70 #define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure)
79 static GstMessageQuarks message_quarks[] = {
80 {GST_MESSAGE_UNKNOWN, "unknown", 0},
81 {GST_MESSAGE_EOS, "eos", 0},
82 {GST_MESSAGE_ERROR, "error", 0},
83 {GST_MESSAGE_WARNING, "warning", 0},
84 {GST_MESSAGE_INFO, "info", 0},
85 {GST_MESSAGE_TAG, "tag", 0},
86 {GST_MESSAGE_BUFFERING, "buffering", 0},
87 {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
88 {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
89 {GST_MESSAGE_STEP_DONE, "step-done", 0},
90 {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
91 {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
92 {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
93 {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
94 {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
95 {GST_MESSAGE_APPLICATION, "application", 0},
96 {GST_MESSAGE_ELEMENT, "element", 0},
97 {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
98 {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
99 {GST_MESSAGE_DURATION, "duration", 0},
100 {GST_MESSAGE_LATENCY, "latency", 0},
101 {GST_MESSAGE_ASYNC_START, "async-start", 0},
102 {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
103 {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
104 {GST_MESSAGE_STEP_START, "step-start", 0},
105 {GST_MESSAGE_QOS, "qos", 0},
106 {GST_MESSAGE_PROGRESS, "progress", 0},
107 {GST_MESSAGE_TOC, "toc", 0},
111 static GType _gst_message_type = 0;
112 GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
115 _priv_gst_message_initialize (void)
119 GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
121 /* the GstMiniObject types need to be class_ref'd once before it can be
122 * done from multiple threads;
123 * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
124 gst_message_get_type ();
126 for (i = 0; message_quarks[i].name; i++) {
127 message_quarks[i].quark =
128 g_quark_from_static_string (message_quarks[i].name);
131 _gst_message_type = gst_message_get_type ();
135 * gst_message_type_get_name:
136 * @type: the message type
138 * Get a printable name for the given message type. Do not modify or free.
140 * Returns: a reference to the static name of the message.
143 gst_message_type_get_name (GstMessageType type)
147 for (i = 0; message_quarks[i].name; i++) {
148 if (type == message_quarks[i].type)
149 return message_quarks[i].name;
155 * gst_message_type_to_quark:
156 * @type: the message type
158 * Get the unique quark for the given message type.
160 * Returns: the quark associated with the message type
163 gst_message_type_to_quark (GstMessageType type)
167 for (i = 0; message_quarks[i].name; i++) {
168 if (type == message_quarks[i].type)
169 return message_quarks[i].quark;
175 _gst_message_free (GstMessage * message)
177 GstStructure *structure;
179 g_return_if_fail (message != NULL);
181 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
182 GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
184 if (GST_MESSAGE_SRC (message)) {
185 gst_object_unref (GST_MESSAGE_SRC (message));
186 GST_MESSAGE_SRC (message) = NULL;
189 if (message->lock.p) {
190 GST_MESSAGE_LOCK (message);
191 GST_MESSAGE_SIGNAL (message);
192 GST_MESSAGE_UNLOCK (message);
195 structure = GST_MESSAGE_STRUCTURE (message);
197 gst_structure_set_parent_refcount (structure, NULL);
198 gst_structure_free (structure);
201 g_slice_free1 (sizeof (GstMessageImpl), message);
205 gst_message_init (GstMessageImpl * message, GstMessageType type,
209 _gst_message_copy (GstMessage * message)
211 GstMessageImpl *copy;
212 GstStructure *structure;
214 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
215 GST_MESSAGE_TYPE_NAME (message),
216 GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
218 copy = g_slice_new0 (GstMessageImpl);
220 gst_message_init (copy, GST_MESSAGE_TYPE (message),
221 GST_MESSAGE_SRC (message));
223 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
224 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
226 structure = GST_MESSAGE_STRUCTURE (message);
228 GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
229 gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
230 ©->message.mini_object.refcount);
232 GST_MESSAGE_STRUCTURE (copy) = NULL;
235 return GST_MESSAGE_CAST (copy);
239 gst_message_init (GstMessageImpl * message, GstMessageType type,
242 gst_mini_object_init (GST_MINI_OBJECT_CAST (message), 0, _gst_message_type,
243 (GstMiniObjectCopyFunction) _gst_message_copy, NULL,
244 (GstMiniObjectFreeFunction) _gst_message_free);
246 GST_MESSAGE_TYPE (message) = type;
248 gst_object_ref (src);
249 GST_MESSAGE_SRC (message) = src;
250 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
251 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
256 * gst_message_new_custom:
257 * @type: The #GstMessageType to distinguish messages
258 * @src: The object originating the message.
259 * @structure: (transfer full): the structure for the message. The message
260 * will take ownership of the structure.
262 * Create a new custom-typed message. This can be used for anything not
263 * handled by other message-specific functions to pass a message to the
264 * app. The structure field can be NULL.
266 * Returns: (transfer full): The new message.
271 gst_message_new_custom (GstMessageType type, GstObject * src,
272 GstStructure * structure)
274 GstMessageImpl *message;
276 message = g_slice_new0 (GstMessageImpl);
278 GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
279 (src ? GST_OBJECT_NAME (src) : "NULL"), message,
280 gst_message_type_get_name (type));
283 /* structure must not have a parent */
284 if (!gst_structure_set_parent_refcount (structure,
285 &message->message.mini_object.refcount))
288 gst_message_init (message, type, src);
290 GST_MESSAGE_STRUCTURE (message) = structure;
292 return GST_MESSAGE_CAST (message);
297 g_slice_free1 (sizeof (GstMessageImpl), message);
298 g_warning ("structure is already owned by another object");
304 * gst_message_get_seqnum:
305 * @message: A #GstMessage.
307 * Retrieve the sequence number of a message.
309 * Messages have ever-incrementing sequence numbers, which may also be set
310 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
311 * to indicate that a message corresponds to some other set of messages or
312 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
313 * is considered good practice to make this correspondence when possible, though
314 * it is not required.
316 * Note that events and messages share the same sequence number incrementor;
317 * two events or messages will never have the same sequence number unless
318 * that correspondence was made explicitly.
320 * Returns: The message's sequence number.
327 gst_message_get_seqnum (GstMessage * message)
329 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
331 return GST_MESSAGE_SEQNUM (message);
335 * gst_message_set_seqnum:
336 * @message: A #GstMessage.
337 * @seqnum: A sequence number.
339 * Set the sequence number of a message.
341 * This function might be called by the creator of a message to indicate that
342 * the message relates to other messages or events. See gst_message_get_seqnum()
343 * for more information.
350 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
352 g_return_if_fail (GST_IS_MESSAGE (message));
354 GST_MESSAGE_SEQNUM (message) = seqnum;
358 * gst_message_new_eos:
359 * @src: (transfer none): The object originating the message.
361 * Create a new eos message. This message is generated and posted in
362 * the sink elements of a GstBin. The bin will only forward the EOS
363 * message to the application if all sinks have posted an EOS message.
365 * Returns: (transfer full): The new eos message.
370 gst_message_new_eos (GstObject * src)
374 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
380 * gst_message_new_error:
381 * @src: (transfer none): The object originating the message.
382 * @error: (transfer none): The GError for this message.
383 * @debug: A debugging string.
385 * Create a new error message. The message will copy @error and
386 * @debug. This message is posted by element when a fatal event
387 * occured. The pipeline will probably (partially) stop. The application
388 * receiving this message should stop the pipeline.
390 * Returns: (transfer full): the new error message.
395 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
398 GstStructure *structure;
400 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
401 GST_QUARK (GERROR), G_TYPE_ERROR, error,
402 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
403 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
409 * gst_message_new_warning:
410 * @src: (transfer none): The object originating the message.
411 * @error: (transfer none): The GError for this message.
412 * @debug: A debugging string.
414 * Create a new warning message. The message will make copies of @error and
417 * Returns: (transfer full): The new warning message.
422 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
425 GstStructure *structure;
427 structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
428 GST_QUARK (GERROR), G_TYPE_ERROR, error,
429 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
430 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
436 * gst_message_new_info:
437 * @src: (transfer none): The object originating the message.
438 * @error: (transfer none): The GError for this message.
439 * @debug: A debugging string.
441 * Create a new info message. The message will make copies of @error and
446 * Returns: (transfer full): the new info message.
451 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
454 GstStructure *structure;
456 structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
457 GST_QUARK (GERROR), G_TYPE_ERROR, error,
458 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
459 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
465 * gst_message_new_tag:
466 * @src: (transfer none): The object originating the message.
467 * @tag_list: (transfer full): the tag list for the message.
469 * Create a new tag message. The message will take ownership of the tag list.
470 * The message is posted by elements that discovered a new taglist.
472 * Returns: (transfer full): the new tag message.
477 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
481 GValue val = G_VALUE_INIT;
483 g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
485 s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
486 g_value_init (&val, GST_TYPE_TAG_LIST);
487 g_value_take_boxed (&val, tag_list);
488 gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
489 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
494 * gst_message_new_buffering:
495 * @src: (transfer none): The object originating the message.
496 * @percent: The buffering percent
498 * Create a new buffering message. This message can be posted by an element that
499 * needs to buffer data before it can continue processing. @percent should be a
500 * value between 0 and 100. A value of 100 means that the buffering completed.
502 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
503 * @percent is 100, the application can set the pipeline (back) to PLAYING.
504 * The application must be prepared to receive BUFFERING messages in the
505 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
506 * message with @percent set to 100, which can happen after the pipeline
507 * completed prerolling.
511 * Returns: (transfer full): The new buffering message.
516 gst_message_new_buffering (GstObject * src, gint percent)
519 GstStructure *structure;
521 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
523 structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
524 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
525 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
526 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
527 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
528 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
529 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
530 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
536 * gst_message_new_state_changed:
537 * @src: (transfer none): the object originating the message
538 * @oldstate: the previous state
539 * @newstate: the new (current) state
540 * @pending: the pending (target) state
542 * Create a state change message. This message is posted whenever an element
545 * Returns: (transfer full): the new state change message.
550 gst_message_new_state_changed (GstObject * src,
551 GstState oldstate, GstState newstate, GstState pending)
554 GstStructure *structure;
556 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
557 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
558 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
559 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
560 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
566 * gst_message_new_state_dirty:
567 * @src: (transfer none): the object originating the message
569 * Create a state dirty message. This message is posted whenever an element
570 * changed its state asynchronously and is used internally to update the
571 * states of container objects.
573 * Returns: (transfer full): the new state dirty message.
578 gst_message_new_state_dirty (GstObject * src)
582 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
588 * gst_message_new_clock_provide:
589 * @src: (transfer none): the object originating the message.
590 * @clock: (transfer none): the clock it provides
591 * @ready: TRUE if the sender can provide a clock
593 * Create a clock provide message. This message is posted whenever an
594 * element is ready to provide a clock or lost its ability to provide
595 * a clock (maybe because it paused or became EOS).
597 * This message is mainly used internally to manage the clock
600 * Returns: (transfer full): the new provide clock message.
605 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
609 GstStructure *structure;
611 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
612 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
613 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
614 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
620 * gst_message_new_clock_lost:
621 * @src: (transfer none): the object originating the message.
622 * @clock: (transfer none): the clock that was lost
624 * Create a clock lost message. This message is posted whenever the
625 * clock is not valid anymore.
627 * If this message is posted by the pipeline, the pipeline will
628 * select a new clock again when it goes to PLAYING. It might therefore
629 * be needed to set the pipeline to PAUSED and PLAYING again.
631 * Returns: (transfer full): The new clock lost message.
636 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
639 GstStructure *structure;
641 structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
642 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
643 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
649 * gst_message_new_new_clock:
650 * @src: (transfer none): The object originating the message.
651 * @clock: (transfer none): the new selected clock
653 * Create a new clock message. This message is posted whenever the
654 * pipeline selectes a new clock for the pipeline.
656 * Returns: (transfer full): The new new clock message.
661 gst_message_new_new_clock (GstObject * src, GstClock * clock)
664 GstStructure *structure;
666 structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
667 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
668 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
674 * gst_message_new_structure_change:
675 * @src: (transfer none): The object originating the message.
676 * @type: The change type.
677 * @owner: (transfer none): The owner element of @src.
678 * @busy: Whether the structure change is busy.
680 * Create a new structure change message. This message is posted when the
681 * structure of a pipeline is in the process of being changed, for example
682 * when pads are linked or unlinked.
684 * @src should be the sinkpad that unlinked or linked.
686 * Returns: (transfer full): the new structure change message.
693 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
694 GstElement * owner, gboolean busy)
697 GstStructure *structure;
699 g_return_val_if_fail (GST_IS_PAD (src), NULL);
700 /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
701 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
703 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
704 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
705 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
706 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
708 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
715 * gst_message_new_segment_start:
716 * @src: (transfer none): The object originating the message.
717 * @format: The format of the position being played
718 * @position: The position of the segment being played
720 * Create a new segment message. This message is posted by elements that
721 * start playback of a segment as a result of a segment seek. This message
722 * is not received by the application but is used for maintenance reasons in
723 * container elements.
725 * Returns: (transfer full): the new segment start message.
730 gst_message_new_segment_start (GstObject * src, GstFormat format,
734 GstStructure *structure;
736 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
737 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
738 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
739 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
745 * gst_message_new_segment_done:
746 * @src: (transfer none): the object originating the message.
747 * @format: The format of the position being done
748 * @position: The position of the segment being done
750 * Create a new segment done message. This message is posted by elements that
751 * finish playback of a segment as a result of a segment seek. This message
752 * is received by the application after all elements that posted a segment_start
753 * have posted the segment_done.
755 * Returns: (transfer full): the new segment done message.
760 gst_message_new_segment_done (GstObject * src, GstFormat format,
764 GstStructure *structure;
766 structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
767 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
768 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
769 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
775 * gst_message_new_application:
776 * @src: (transfer none): the object originating the message.
777 * @structure: (transfer full): the structure for the message. The message
778 * will take ownership of the structure.
780 * Create a new application-typed message. GStreamer will never create these
781 * messages; they are a gift from us to you. Enjoy.
783 * Returns: (transfer full): The new application message.
788 gst_message_new_application (GstObject * src, GstStructure * structure)
790 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
794 * gst_message_new_element:
795 * @src: (transfer none): The object originating the message.
796 * @structure: (transfer full): The structure for the message. The message
797 * will take ownership of the structure.
799 * Create a new element-specific message. This is meant as a generic way of
800 * allowing one-way communication from an element to an application, for example
801 * "the firewire cable was unplugged". The format of the message should be
802 * documented in the element's documentation. The structure field can be NULL.
804 * Returns: (transfer full): The new element message.
809 gst_message_new_element (GstObject * src, GstStructure * structure)
811 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
815 * gst_message_new_duration:
816 * @src: (transfer none): The object originating the message.
817 * @format: The format of the duration
818 * @duration: The new duration
820 * Create a new duration message. This message is posted by elements that
821 * know the duration of a stream in a specific format. This message
822 * is received by bins and is used to calculate the total duration of a
823 * pipeline. Elements may post a duration message with a duration of
824 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
825 * cached duration should be discarded. The new duration can then be
826 * retrieved via a query.
828 * Returns: (transfer full): The new duration message.
833 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
836 GstStructure *structure;
838 structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION),
839 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
840 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
841 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
847 * gst_message_new_async_start:
848 * @src: (transfer none): The object originating the message.
850 * This message is posted by elements when they start an ASYNC state change.
852 * Returns: (transfer full): The new async_start message.
857 gst_message_new_async_start (GstObject * src)
861 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
867 * gst_message_new_async_done:
868 * @src: (transfer none): The object originating the message.
869 * @running_time: the desired running_time
871 * The message is posted when elements completed an ASYNC state change.
872 * @running_time contains the time of the desired running_time when this
873 * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
874 * means that the element has no clock interaction and thus doesn't care about
875 * the running_time of the pipeline.
877 * Returns: (transfer full): The new async_done message.
882 gst_message_new_async_done (GstObject * src, GstClockTime running_time)
885 GstStructure *structure;
887 structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
888 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
889 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
895 * gst_message_new_latency:
896 * @src: (transfer none): The object originating the message.
898 * This message can be posted by elements when their latency requirements have
901 * Returns: (transfer full): The new latency message.
908 gst_message_new_latency (GstObject * src)
912 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
918 * gst_message_new_request_state:
919 * @src: (transfer none): the object originating the message.
920 * @state: The new requested state
922 * This message can be posted by elements when they want to have their state
923 * changed. A typical use case would be an audio server that wants to pause the
924 * pipeline because a higher priority stream is being played.
926 * Returns: (transfer full): the new requst state message.
933 gst_message_new_request_state (GstObject * src, GstState state)
936 GstStructure *structure;
938 structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
939 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
940 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
946 * gst_message_get_structure:
947 * @message: The #GstMessage.
949 * Access the structure of the message.
951 * Returns: (transfer none): The structure of the message. The structure is
952 * still owned by the message, which means that you should not free it and
953 * that the pointer becomes invalid when you free the message.
958 gst_message_get_structure (GstMessage * message)
960 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
962 return GST_MESSAGE_STRUCTURE (message);
966 * gst_message_has_name:
967 * @message: The #GstMessage.
968 * @name: name to check
970 * Checks if @message has the given @name. This function is usually used to
971 * check the name of a custom message.
973 * Returns: %TRUE if @name matches the name of the message structure.
978 gst_message_has_name (GstMessage * message, const gchar * name)
980 GstStructure *structure;
982 g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
984 structure = GST_MESSAGE_STRUCTURE (message);
985 if (structure == NULL)
988 return gst_structure_has_name (structure, name);
992 * gst_message_parse_tag:
993 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
994 * @tag_list: (out callee-allocates): return location for the tag-list.
996 * Extracts the tag list from the GstMessage. The tag list returned in the
997 * output argument is a copy; the caller must free it when done.
999 * Typical usage of this function might be:
1002 * switch (GST_MESSAGE_TYPE (msg)) {
1003 * case GST_MESSAGE_TAG: {
1004 * GstTagList *tags = NULL;
1006 * gst_message_parse_tag (msg, &tags);
1007 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1008 * handle_tags (tags);
1009 * gst_tag_list_unref (tags);
1020 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1022 g_return_if_fail (GST_IS_MESSAGE (message));
1023 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1024 g_return_if_fail (tag_list != NULL);
1026 gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1027 GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
1031 * gst_message_parse_buffering:
1032 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1033 * @percent: (out) (allow-none): Return location for the percent.
1035 * Extracts the buffering percent from the GstMessage. see also
1036 * gst_message_new_buffering().
1043 gst_message_parse_buffering (GstMessage * message, gint * percent)
1045 g_return_if_fail (GST_IS_MESSAGE (message));
1046 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1050 g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1051 (message), GST_QUARK (BUFFER_PERCENT)));
1055 * gst_message_set_buffering_stats:
1056 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1057 * @mode: a buffering mode
1058 * @avg_in: the average input rate
1059 * @avg_out: the average output rate
1060 * @buffering_left: amount of buffering time left in milliseconds
1062 * Configures the buffering stats values in @message.
1067 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1068 gint avg_in, gint avg_out, gint64 buffering_left)
1070 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1072 gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1073 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1074 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1075 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1076 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1080 * gst_message_parse_buffering_stats:
1081 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1082 * @mode: (out) (allow-none): a buffering mode, or NULL
1083 * @avg_in: (out) (allow-none): the average input rate, or NULL
1084 * @avg_out: (out) (allow-none): the average output rate, or NULL
1085 * @buffering_left: (out) (allow-none): amount of buffering time left in
1086 * milliseconds, or NULL
1088 * Extracts the buffering stats values from @message.
1093 gst_message_parse_buffering_stats (GstMessage * message,
1094 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1095 gint64 * buffering_left)
1097 GstStructure *structure;
1099 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1101 structure = GST_MESSAGE_STRUCTURE (message);
1103 *mode = (GstBufferingMode)
1104 g_value_get_enum (gst_structure_id_get_value (structure,
1105 GST_QUARK (BUFFERING_MODE)));
1107 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1108 GST_QUARK (AVG_IN_RATE)));
1110 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1111 GST_QUARK (AVG_OUT_RATE)));
1114 g_value_get_int64 (gst_structure_id_get_value (structure,
1115 GST_QUARK (BUFFERING_LEFT)));
1119 * gst_message_parse_state_changed:
1120 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1121 * @oldstate: (out) (allow-none): the previous state, or NULL
1122 * @newstate: (out) (allow-none): the new (current) state, or NULL
1123 * @pending: (out) (allow-none): the pending (target) state, or NULL
1125 * Extracts the old and new states from the GstMessage.
1127 * Typical usage of this function might be:
1130 * switch (GST_MESSAGE_TYPE (msg)) {
1131 * case GST_MESSAGE_STATE_CHANGED: {
1132 * GstState old_state, new_state;
1134 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1135 * g_print ("Element %s changed state from %s to %s.\n",
1136 * GST_OBJECT_NAME (msg->src),
1137 * gst_element_state_get_name (old_state),
1138 * gst_element_state_get_name (new_state));
1149 gst_message_parse_state_changed (GstMessage * message,
1150 GstState * oldstate, GstState * newstate, GstState * pending)
1152 GstStructure *structure;
1154 g_return_if_fail (GST_IS_MESSAGE (message));
1155 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1157 structure = GST_MESSAGE_STRUCTURE (message);
1159 *oldstate = (GstState)
1160 g_value_get_enum (gst_structure_id_get_value (structure,
1161 GST_QUARK (OLD_STATE)));
1163 *newstate = (GstState)
1164 g_value_get_enum (gst_structure_id_get_value (structure,
1165 GST_QUARK (NEW_STATE)));
1167 *pending = (GstState)
1168 g_value_get_enum (gst_structure_id_get_value (structure,
1169 GST_QUARK (PENDING_STATE)));
1173 * gst_message_parse_clock_provide:
1174 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1175 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1177 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1179 * Extracts the clock and ready flag from the GstMessage.
1180 * The clock object returned remains valid until the message is freed.
1185 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1188 const GValue *clock_gvalue;
1189 GstStructure *structure;
1191 g_return_if_fail (GST_IS_MESSAGE (message));
1192 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1194 structure = GST_MESSAGE_STRUCTURE (message);
1195 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1196 g_return_if_fail (clock_gvalue != NULL);
1197 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1201 g_value_get_boolean (gst_structure_id_get_value (structure,
1202 GST_QUARK (READY)));
1204 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1208 * gst_message_parse_clock_lost:
1209 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1210 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1212 * Extracts the lost clock from the GstMessage.
1213 * The clock object returned remains valid until the message is freed.
1218 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1220 const GValue *clock_gvalue;
1221 GstStructure *structure;
1223 g_return_if_fail (GST_IS_MESSAGE (message));
1224 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1226 structure = GST_MESSAGE_STRUCTURE (message);
1227 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1228 g_return_if_fail (clock_gvalue != NULL);
1229 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1232 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1236 * gst_message_parse_new_clock:
1237 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1238 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1241 * Extracts the new clock from the GstMessage.
1242 * The clock object returned remains valid until the message is freed.
1247 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1249 const GValue *clock_gvalue;
1250 GstStructure *structure;
1252 g_return_if_fail (GST_IS_MESSAGE (message));
1253 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1255 structure = GST_MESSAGE_STRUCTURE (message);
1256 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1257 g_return_if_fail (clock_gvalue != NULL);
1258 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1261 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1265 * gst_message_parse_structure_change:
1266 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1267 * @type: (out): A pointer to hold the change type
1268 * @owner: (out) (allow-none) (transfer none): The owner element of the
1270 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1271 * progress or has been completed
1273 * Extracts the change type and completion status from the GstMessage.
1280 gst_message_parse_structure_change (GstMessage * message,
1281 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1283 const GValue *owner_gvalue;
1284 GstStructure *structure;
1286 g_return_if_fail (GST_IS_MESSAGE (message));
1287 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1289 structure = GST_MESSAGE_STRUCTURE (message);
1290 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1291 g_return_if_fail (owner_gvalue != NULL);
1292 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1295 *type = (GstStructureChangeType)
1296 g_value_get_enum (gst_structure_id_get_value (structure,
1299 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1302 g_value_get_boolean (gst_structure_id_get_value (structure,
1307 * gst_message_parse_error:
1308 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1309 * @gerror: (out) (allow-none) (transfer full): location for the GError
1310 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1313 * Extracts the GError and debug string from the GstMessage. The values returned
1314 * in the output arguments are copies; the caller must free them when done.
1316 * Typical usage of this function might be:
1319 * switch (GST_MESSAGE_TYPE (msg)) {
1320 * case GST_MESSAGE_ERROR: {
1321 * GError *err = NULL;
1322 * gchar *dbg_info = NULL;
1324 * gst_message_parse_error (msg, &err, &dbg_info);
1325 * g_printerr ("ERROR from element %s: %s\n",
1326 * GST_OBJECT_NAME (msg->src), err->message);
1327 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1328 * g_error_free (err);
1329 * g_free (dbg_info);
1340 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1342 const GValue *error_gvalue;
1344 GstStructure *structure;
1346 g_return_if_fail (GST_IS_MESSAGE (message));
1347 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1349 structure = GST_MESSAGE_STRUCTURE (message);
1350 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1351 g_return_if_fail (error_gvalue != NULL);
1352 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1354 error_val = (GError *) g_value_get_boxed (error_gvalue);
1356 *gerror = g_error_copy (error_val);
1362 g_value_dup_string (gst_structure_id_get_value (structure,
1363 GST_QUARK (DEBUG)));
1367 * gst_message_parse_warning:
1368 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1369 * @gerror: (out) (allow-none) (transfer full): location for the GError
1370 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1373 * Extracts the GError and debug string from the GstMessage. The values returned
1374 * in the output arguments are copies; the caller must free them when done.
1379 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1382 const GValue *error_gvalue;
1384 GstStructure *structure;
1386 g_return_if_fail (GST_IS_MESSAGE (message));
1387 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1389 structure = GST_MESSAGE_STRUCTURE (message);
1390 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1391 g_return_if_fail (error_gvalue != NULL);
1392 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1394 error_val = (GError *) g_value_get_boxed (error_gvalue);
1396 *gerror = g_error_copy (error_val);
1402 g_value_dup_string (gst_structure_id_get_value (structure,
1403 GST_QUARK (DEBUG)));
1407 * gst_message_parse_info:
1408 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1409 * @gerror: (out) (allow-none) (transfer full): location for the GError
1410 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1413 * Extracts the GError and debug string from the GstMessage. The values returned
1414 * in the output arguments are copies; the caller must free them when done.
1421 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1423 const GValue *error_gvalue;
1425 GstStructure *structure;
1427 g_return_if_fail (GST_IS_MESSAGE (message));
1428 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1430 structure = GST_MESSAGE_STRUCTURE (message);
1431 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1432 g_return_if_fail (error_gvalue != NULL);
1433 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
1435 error_val = (GError *) g_value_get_boxed (error_gvalue);
1437 *gerror = g_error_copy (error_val);
1443 g_value_dup_string (gst_structure_id_get_value (structure,
1444 GST_QUARK (DEBUG)));
1448 * gst_message_parse_segment_start:
1449 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1450 * @format: (out): Result location for the format, or NULL
1451 * @position: (out): Result location for the position, or NULL
1453 * Extracts the position and format from the segment start message.
1458 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1461 GstStructure *structure;
1463 g_return_if_fail (GST_IS_MESSAGE (message));
1464 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1466 structure = GST_MESSAGE_STRUCTURE (message);
1468 *format = (GstFormat)
1469 g_value_get_enum (gst_structure_id_get_value (structure,
1470 GST_QUARK (FORMAT)));
1473 g_value_get_int64 (gst_structure_id_get_value (structure,
1474 GST_QUARK (POSITION)));
1478 * gst_message_parse_segment_done:
1479 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1480 * @format: (out): Result location for the format, or NULL
1481 * @position: (out): Result location for the position, or NULL
1483 * Extracts the position and format from the segment start message.
1488 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1491 GstStructure *structure;
1493 g_return_if_fail (GST_IS_MESSAGE (message));
1494 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1496 structure = GST_MESSAGE_STRUCTURE (message);
1498 *format = (GstFormat)
1499 g_value_get_enum (gst_structure_id_get_value (structure,
1500 GST_QUARK (FORMAT)));
1503 g_value_get_int64 (gst_structure_id_get_value (structure,
1504 GST_QUARK (POSITION)));
1508 * gst_message_parse_duration:
1509 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1510 * @format: (out): Result location for the format, or NULL
1511 * @duration: (out): Result location for the duration, or NULL
1513 * Extracts the duration and format from the duration message. The duration
1514 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1515 * changed. Applications should always use a query to retrieve the duration
1521 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1524 GstStructure *structure;
1526 g_return_if_fail (GST_IS_MESSAGE (message));
1527 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1529 structure = GST_MESSAGE_STRUCTURE (message);
1531 *format = (GstFormat)
1532 g_value_get_enum (gst_structure_id_get_value (structure,
1533 GST_QUARK (FORMAT)));
1536 g_value_get_int64 (gst_structure_id_get_value (structure,
1537 GST_QUARK (DURATION)));
1541 * gst_message_parse_async_done:
1542 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1543 * @running_time: (out): Result location for the running_time or NULL
1545 * Extract the running_time from the async_done message.
1550 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
1552 GstStructure *structure;
1554 g_return_if_fail (GST_IS_MESSAGE (message));
1555 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1557 structure = GST_MESSAGE_STRUCTURE (message);
1560 g_value_get_uint64 (gst_structure_id_get_value (structure,
1561 GST_QUARK (RUNNING_TIME)));
1565 * gst_message_parse_request_state:
1566 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1567 * @state: (out): Result location for the requested state or NULL
1569 * Extract the requested state from the request_state message.
1576 gst_message_parse_request_state (GstMessage * message, GstState * state)
1578 GstStructure *structure;
1580 g_return_if_fail (GST_IS_MESSAGE (message));
1581 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1583 structure = GST_MESSAGE_STRUCTURE (message);
1586 g_value_get_enum (gst_structure_id_get_value (structure,
1587 GST_QUARK (NEW_STATE)));
1591 * gst_message_new_stream_status:
1592 * @src: The object originating the message.
1593 * @type: The stream status type.
1594 * @owner: (transfer none): the owner element of @src.
1596 * Create a new stream status message. This message is posted when a streaming
1597 * thread is created/destroyed or when the state changed.
1599 * Returns: (transfer full): the new stream status message.
1606 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1609 GstMessage *message;
1610 GstStructure *structure;
1612 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1613 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1614 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1615 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1621 * gst_message_parse_stream_status:
1622 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1623 * @type: (out): A pointer to hold the status type
1624 * @owner: (out) (transfer none): The owner element of the message source
1626 * Extracts the stream status type and owner the GstMessage. The returned
1627 * owner remains valid for as long as the reference to @message is valid and
1628 * should thus not be unreffed.
1635 gst_message_parse_stream_status (GstMessage * message,
1636 GstStreamStatusType * type, GstElement ** owner)
1638 const GValue *owner_gvalue;
1639 GstStructure *structure;
1641 g_return_if_fail (GST_IS_MESSAGE (message));
1642 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1644 structure = GST_MESSAGE_STRUCTURE (message);
1645 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1646 g_return_if_fail (owner_gvalue != NULL);
1649 *type = (GstStreamStatusType)
1650 g_value_get_enum (gst_structure_id_get_value (structure,
1653 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1657 * gst_message_set_stream_status_object:
1658 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1659 * @object: the object controlling the streaming
1661 * Configures the object handling the streaming thread. This is usually a
1662 * GstTask object but other objects might be added in the future.
1667 gst_message_set_stream_status_object (GstMessage * message,
1668 const GValue * object)
1670 GstStructure *structure;
1672 g_return_if_fail (GST_IS_MESSAGE (message));
1673 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1675 structure = GST_MESSAGE_STRUCTURE (message);
1676 gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
1680 * gst_message_get_stream_status_object:
1681 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1683 * Extracts the object managing the streaming thread from @message.
1685 * Returns: a GValue containing the object that manages the streaming thread.
1686 * This object is usually of type GstTask but other types can be added in the
1687 * future. The object remains valid as long as @message is valid.
1692 gst_message_get_stream_status_object (GstMessage * message)
1694 const GValue *result;
1695 GstStructure *structure;
1697 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1698 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1701 structure = GST_MESSAGE_STRUCTURE (message);
1702 result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1708 * gst_message_new_step_done:
1709 * @src: The object originating the message.
1710 * @format: the format of @amount
1711 * @amount: the amount of stepped data
1712 * @rate: the rate of the stepped amount
1713 * @flush: is this an flushing step
1714 * @intermediate: is this an intermediate step
1715 * @duration: the duration of the data
1716 * @eos: the step caused EOS
1718 * This message is posted by elements when they complete a part, when @intermediate set
1719 * to TRUE, or a complete step operation.
1721 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1722 * @amount of media in format @format.
1724 * Returns: (transfer full): the new step_done message.
1731 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1732 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1735 GstMessage *message;
1736 GstStructure *structure;
1738 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
1739 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1740 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1741 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1742 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1743 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1744 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1745 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1746 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1752 * gst_message_parse_step_done:
1753 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1754 * @format: (out) (allow-none): result location for the format
1755 * @amount: (out) (allow-none): result location for the amount
1756 * @rate: (out) (allow-none): result location for the rate
1757 * @flush: (out) (allow-none): result location for the flush flag
1758 * @intermediate: (out) (allow-none): result location for the intermediate flag
1759 * @duration: (out) (allow-none): result location for the duration
1760 * @eos: (out) (allow-none): result location for the EOS flag
1762 * Extract the values the step_done message.
1769 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1770 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1771 guint64 * duration, gboolean * eos)
1773 GstStructure *structure;
1775 g_return_if_fail (GST_IS_MESSAGE (message));
1776 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1778 structure = GST_MESSAGE_STRUCTURE (message);
1779 gst_structure_id_get (structure,
1780 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1781 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1782 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1783 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1784 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1785 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1786 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1790 * gst_message_new_step_start:
1791 * @src: The object originating the message.
1792 * @active: if the step is active or queued
1793 * @format: the format of @amount
1794 * @amount: the amount of stepped data
1795 * @rate: the rate of the stepped amount
1796 * @flush: is this an flushing step
1797 * @intermediate: is this an intermediate step
1799 * This message is posted by elements when they accept or activate a new step
1800 * event for @amount in @format.
1802 * @active is set to FALSE when the element accepted the new step event and has
1803 * queued it for execution in the streaming threads.
1805 * @active is set to TRUE when the element has activated the step operation and
1806 * is now ready to start executing the step in the streaming thread. After this
1807 * message is emited, the application can queue a new step operation in the
1810 * Returns: (transfer full): The new step_start message.
1817 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1818 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1820 GstMessage *message;
1821 GstStructure *structure;
1823 structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
1824 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1825 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1826 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1827 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1828 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1829 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1830 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1836 * gst_message_parse_step_start:
1837 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1838 * @active: (out) (allow-none): result location for the active flag
1839 * @format: (out) (allow-none): result location for the format
1840 * @amount: (out) (allow-none): result location for the amount
1841 * @rate: (out) (allow-none): result location for the rate
1842 * @flush: (out) (allow-none): result location for the flush flag
1843 * @intermediate: (out) (allow-none): result location for the intermediate flag
1845 * Extract the values from step_start message.
1852 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1853 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1854 gboolean * intermediate)
1856 GstStructure *structure;
1858 g_return_if_fail (GST_IS_MESSAGE (message));
1859 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1861 structure = GST_MESSAGE_STRUCTURE (message);
1862 gst_structure_id_get (structure,
1863 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1864 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1865 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1866 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1867 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1868 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1872 * gst_message_new_qos:
1873 * @src: The object originating the message.
1874 * @live: if the message was generated by a live element
1875 * @running_time: the running time of the buffer that generated the message
1876 * @stream_time: the stream time of the buffer that generated the message
1877 * @timestamp: the timestamps of the buffer that generated the message
1878 * @duration: the duration of the buffer that generated the message
1880 * A QOS message is posted on the bus whenever an element decides to drop a
1881 * buffer because of QoS reasons or whenever it changes its processing strategy
1882 * because of QoS reasons (quality adjustments such as processing at lower
1885 * This message can be posted by an element that performs synchronisation against the
1886 * clock (live) or it could be dropped by an element that performs QoS because of QOS
1887 * events received from a downstream element (!live).
1889 * @running_time, @stream_time, @timestamp, @duration should be set to the
1890 * respective running-time, stream-time, timestamp and duration of the (dropped)
1891 * buffer that generated the QoS event. Values can be left to
1892 * GST_CLOCK_TIME_NONE when unknown.
1894 * Returns: (transfer full): The new qos message.
1901 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1902 guint64 stream_time, guint64 timestamp, guint64 duration)
1904 GstMessage *message;
1905 GstStructure *structure;
1907 structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
1908 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1909 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1910 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1911 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1912 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1913 GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1914 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1915 GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1916 GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1917 GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1918 GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1919 message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1925 * gst_message_set_qos_values:
1926 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1927 * @jitter: The difference of the running-time against the deadline.
1928 * @proportion: Long term prediction of the ideal rate relative to normal rate
1929 * to get optimal quality.
1930 * @quality: An element dependent integer value that specifies the current
1931 * quality level of the element. The default maximum quality is 1000000.
1933 * Set the QoS values that have been calculated/analysed from the QoS data
1940 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
1941 gdouble proportion, gint quality)
1943 GstStructure *structure;
1945 g_return_if_fail (GST_IS_MESSAGE (message));
1946 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1948 structure = GST_MESSAGE_STRUCTURE (message);
1949 gst_structure_id_set (structure,
1950 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1951 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1952 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1956 * gst_message_set_qos_stats:
1957 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1958 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1959 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1960 * will likely use GST_FORMAT_DEFAULT (samples).
1961 * @processed: Total number of units correctly processed since the last state
1962 * change to READY or a flushing operation.
1963 * @dropped: Total number of units dropped since the last state change to READY
1964 * or a flushing operation.
1966 * Set the QoS stats representing the history of the current continuous pipeline
1969 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1970 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1977 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1978 guint64 processed, guint64 dropped)
1980 GstStructure *structure;
1982 g_return_if_fail (GST_IS_MESSAGE (message));
1983 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1985 structure = GST_MESSAGE_STRUCTURE (message);
1986 gst_structure_id_set (structure,
1987 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1988 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1989 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1993 * gst_message_parse_qos:
1994 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1995 * @live: (out) (allow-none): if the message was generated by a live element
1996 * @running_time: (out) (allow-none): the running time of the buffer that
1997 * generated the message
1998 * @stream_time: (out) (allow-none): the stream time of the buffer that
1999 * generated the message
2000 * @timestamp: (out) (allow-none): the timestamps of the buffer that
2001 * generated the message
2002 * @duration: (out) (allow-none): the duration of the buffer that
2003 * generated the message
2005 * Extract the timestamps and live status from the QoS message.
2007 * The returned values give the running_time, stream_time, timestamp and
2008 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2016 gst_message_parse_qos (GstMessage * message, gboolean * live,
2017 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2020 GstStructure *structure;
2022 g_return_if_fail (GST_IS_MESSAGE (message));
2023 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2025 structure = GST_MESSAGE_STRUCTURE (message);
2026 gst_structure_id_get (structure,
2027 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2028 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2029 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2030 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2031 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2035 * gst_message_parse_qos_values:
2036 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2037 * @jitter: (out) (allow-none): The difference of the running-time against
2039 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2040 * relative to normal rate to get optimal quality.
2041 * @quality: (out) (allow-none): An element dependent integer value that
2042 * specifies the current quality level of the element. The default
2043 * maximum quality is 1000000.
2045 * Extract the QoS values that have been calculated/analysed from the QoS data
2052 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2053 gdouble * proportion, gint * quality)
2055 GstStructure *structure;
2057 g_return_if_fail (GST_IS_MESSAGE (message));
2058 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2060 structure = GST_MESSAGE_STRUCTURE (message);
2061 gst_structure_id_get (structure,
2062 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2063 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2064 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2068 * gst_message_parse_qos_stats:
2069 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2070 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2071 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2072 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2074 * @processed: (out) (allow-none): Total number of units correctly processed
2075 * since the last state change to READY or a flushing operation.
2076 * @dropped: (out) (allow-none): Total number of units dropped since the last
2077 * state change to READY or a flushing operation.
2079 * Extract the QoS stats representing the history of the current continuous
2080 * pipeline playback period.
2082 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2083 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2090 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2091 guint64 * processed, guint64 * dropped)
2093 GstStructure *structure;
2095 g_return_if_fail (GST_IS_MESSAGE (message));
2096 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2098 structure = GST_MESSAGE_STRUCTURE (message);
2099 gst_structure_id_get (structure,
2100 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2101 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2102 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2106 * gst_message_new_progress:
2107 * @src: The object originating the message.
2108 * @type: a #GstProgressType
2109 * @code: a progress code
2110 * @text: free, user visible text describing the progress
2112 * Progress messages are posted by elements when they use an asynchronous task
2113 * to perform actions triggered by a state change.
2115 * @code contains a well defined string describing the action.
2116 * @test should contain a user visible string detailing the current action.
2118 * Returns: (transfer full): The new qos message.
2123 gst_message_new_progress (GstObject * src, GstProgressType type,
2124 const gchar * code, const gchar * text)
2126 GstMessage *message;
2127 GstStructure *structure;
2128 gint percent = 100, timeout = -1;
2130 g_return_val_if_fail (code != NULL, NULL);
2131 g_return_val_if_fail (text != NULL, NULL);
2133 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2136 structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2137 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2138 GST_QUARK (CODE), G_TYPE_STRING, code,
2139 GST_QUARK (TEXT), G_TYPE_STRING, text,
2140 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2141 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2142 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2148 * gst_message_parse_progress:
2149 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2150 * @type: (out) (allow-none): location for the type
2151 * @code: (out) (allow-none) (transfer full): location for the code
2152 * @text: (out) (allow-none) (transfer full): location for the text
2154 * Parses the progress @type, @code and @text.
2159 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2160 gchar ** code, gchar ** text)
2162 GstStructure *structure;
2164 g_return_if_fail (GST_IS_MESSAGE (message));
2165 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2167 structure = GST_MESSAGE_STRUCTURE (message);
2168 gst_structure_id_get (structure,
2169 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2170 GST_QUARK (CODE), G_TYPE_STRING, code,
2171 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2175 * gst_message_new_toc:
2176 * @src: the object originating the message.
2177 * @toc: (transfer none): #GstToc structure for the message.
2178 * @updated: whether TOC was updated or not.
2180 * Create a new TOC message. The message is posted by elements
2181 * that discovered or updated a TOC.
2183 * Returns: (transfer full): a new TOC message.
2190 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2192 GstStructure *toc_struct;
2194 g_return_val_if_fail (toc != NULL, NULL);
2196 toc_struct = gst_structure_new_id (GST_QUARK (MESSAGE_TOC),
2197 GST_QUARK (TOC), GST_TYPE_TOC, toc,
2198 GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2200 return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2204 * gst_message_parse_toc:
2205 * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2206 * @toc: (out) (transfer full): return location for the TOC.
2207 * @updated: (out): return location for the updated flag.
2209 * Extract thef TOC from the #GstMessage. The TOC returned in the
2210 * output argument is a copy; the caller must free it with
2211 * gst_toc_unref() when done.
2218 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2220 g_return_if_fail (GST_IS_MESSAGE (message));
2221 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2222 g_return_if_fail (toc != NULL);
2224 gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2225 GST_QUARK (TOC), GST_TYPE_TOC, toc,
2226 GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2230 * gst_message_new_reset_time:
2231 * @src: (transfer none): The object originating the message.
2232 * @running_time: the requested running-time
2234 * This message is posted when the pipeline running-time should be reset to
2235 * @running_time, like after a flushing seek.
2237 * Returns: (transfer full): The new reset_time message.
2242 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2244 GstMessage *message;
2245 GstStructure *structure;
2247 structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2248 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2249 message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2255 * gst_message_parse_reset_time:
2256 * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2257 * @running_time: (out): Result location for the running_time or NULL
2259 * Extract the running-time from the RESET_TIME message.
2264 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2266 GstStructure *structure;
2268 g_return_if_fail (GST_IS_MESSAGE (message));
2269 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2271 structure = GST_MESSAGE_STRUCTURE (message);
2274 g_value_get_uint64 (gst_structure_id_get_value (structure,
2275 GST_QUARK (RUNNING_TIME)));