2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
4 * gstmessage.c: GstMessage subsystem
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * @short_description: Lightweight objects to signal the application of
26 * @see_also: #GstBus, #GstMiniObject, #GstElement
28 * Messages are implemented as a subclass of #GstMiniObject with a generic
29 * #GstStructure as the content. This allows for writing custom messages without
30 * requiring an API change while allowing a wide range of different types
33 * Messages are posted by objects in the pipeline and are passed to the
34 * application using the #GstBus.
36 * The basic use pattern of posting a message on a #GstBus is as follows:
39 * <title>Posting a #GstMessage</title>
41 * gst_bus_post (bus, gst_message_new_eos());
45 * A #GstElement usually posts messages on the bus provided by the parent
46 * container using gst_element_post_message().
48 * Last reviewed on 2005-11-09 (0.9.4)
52 #include "gst_private.h"
53 #include <string.h> /* memcpy */
55 #include "gstenumtypes.h"
57 #include "gstmessage.h"
58 #include "gsttaglist.h"
63 static GType _gst_message_type = 0;
69 GstStructure *structure;
72 #define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure)
81 static GstMessageQuarks message_quarks[] = {
82 {GST_MESSAGE_UNKNOWN, "unknown", 0},
83 {GST_MESSAGE_EOS, "eos", 0},
84 {GST_MESSAGE_ERROR, "error", 0},
85 {GST_MESSAGE_WARNING, "warning", 0},
86 {GST_MESSAGE_INFO, "info", 0},
87 {GST_MESSAGE_TAG, "tag", 0},
88 {GST_MESSAGE_BUFFERING, "buffering", 0},
89 {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
90 {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
91 {GST_MESSAGE_STEP_DONE, "step-done", 0},
92 {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
93 {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
94 {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
95 {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
96 {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
97 {GST_MESSAGE_APPLICATION, "application", 0},
98 {GST_MESSAGE_ELEMENT, "element", 0},
99 {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
100 {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
101 {GST_MESSAGE_DURATION, "duration", 0},
102 {GST_MESSAGE_LATENCY, "latency", 0},
103 {GST_MESSAGE_ASYNC_START, "async-start", 0},
104 {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
105 {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
106 {GST_MESSAGE_STEP_START, "step-start", 0},
107 {GST_MESSAGE_QOS, "qos", 0},
108 {GST_MESSAGE_PROGRESS, "progress", 0},
113 _gst_message_initialize (void)
117 GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
119 /* the GstMiniObject types need to be class_ref'd once before it can be
120 * done from multiple threads;
121 * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
122 gst_message_get_type ();
124 for (i = 0; message_quarks[i].name; i++) {
125 message_quarks[i].quark =
126 g_quark_from_static_string (message_quarks[i].name);
131 * gst_message_type_get_name:
132 * @type: the message type
134 * Get a printable name for the given message type. Do not modify or free.
136 * Returns: a reference to the static name of the message.
139 gst_message_type_get_name (GstMessageType type)
143 for (i = 0; message_quarks[i].name; i++) {
144 if (type == message_quarks[i].type)
145 return message_quarks[i].name;
151 * gst_message_type_to_quark:
152 * @type: the message type
154 * Get the unique quark for the given message type.
156 * Returns: the quark associated with the message type
159 gst_message_type_to_quark (GstMessageType type)
163 for (i = 0; message_quarks[i].name; i++) {
164 if (type == message_quarks[i].type)
165 return message_quarks[i].quark;
171 gst_message_get_type (void)
173 if (G_UNLIKELY (_gst_message_type == 0)) {
174 _gst_message_type = gst_mini_object_register ("GstMessage");
176 return _gst_message_type;
181 _gst_message_free (GstMessage * message)
183 GstStructure *structure;
185 g_return_if_fail (message != NULL);
187 GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p", message);
189 if (GST_MESSAGE_SRC (message)) {
190 gst_object_unref (GST_MESSAGE_SRC (message));
191 GST_MESSAGE_SRC (message) = NULL;
195 GST_MESSAGE_LOCK (message);
196 GST_MESSAGE_SIGNAL (message);
197 GST_MESSAGE_UNLOCK (message);
200 structure = GST_MESSAGE_STRUCTURE (message);
202 gst_structure_set_parent_refcount (structure, NULL);
203 gst_structure_free (structure);
206 g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
210 _gst_message_copy (GstMessage * message)
212 GstMessageImpl *copy;
213 GstStructure *structure;
215 GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p", message);
217 copy = g_slice_new0 (GstMessageImpl);
219 gst_mini_object_init (GST_MINI_OBJECT_CAST (copy),
220 _gst_message_type, sizeof (GstMessageImpl));
222 copy->message.mini_object.copy =
223 (GstMiniObjectCopyFunction) _gst_message_copy;
224 copy->message.mini_object.free =
225 (GstMiniObjectFreeFunction) _gst_message_free;
227 GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
228 GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
229 GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
230 if (GST_MESSAGE_SRC (message)) {
231 GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
234 GST_MESSAGE_GET_LOCK (copy) = GST_MESSAGE_GET_LOCK (message);
235 GST_MESSAGE_COND (copy) = GST_MESSAGE_COND (message);
237 structure = GST_MESSAGE_STRUCTURE (message);
239 copy->structure = gst_structure_copy (structure);
240 gst_structure_set_parent_refcount (copy->structure,
241 ©->message.mini_object.refcount);
244 return GST_MESSAGE_CAST (copy);
248 * gst_message_new_custom:
249 * @type: The #GstMessageType to distinguish messages
250 * @src: The object originating the message.
251 * @structure: (transfer full): the structure for the message. The message
252 * will take ownership of the structure.
254 * Create a new custom-typed message. This can be used for anything not
255 * handled by other message-specific functions to pass a message to the
256 * app. The structure field can be NULL.
258 * Returns: (transfer full): The new message.
263 gst_message_new_custom (GstMessageType type, GstObject * src,
264 GstStructure * structure)
266 GstMessageImpl *message;
268 message = g_slice_new0 (GstMessageImpl);
270 gst_mini_object_init (GST_MINI_OBJECT_CAST (message),
271 _gst_message_type, sizeof (GstMessageImpl));
273 message->message.mini_object.copy =
274 (GstMiniObjectCopyFunction) _gst_message_copy;
275 message->message.mini_object.free =
276 (GstMiniObjectFreeFunction) _gst_message_free;
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));
282 GST_MESSAGE_TYPE (message) = type;
284 gst_object_ref (src);
285 GST_MESSAGE_SRC (message) = src;
286 GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
287 GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
290 gst_structure_set_parent_refcount (structure,
291 &message->message.mini_object.refcount);
293 message->structure = structure;
295 return GST_MESSAGE_CAST (message);
299 * gst_message_get_seqnum:
300 * @message: A #GstMessage.
302 * Retrieve the sequence number of a message.
304 * Messages have ever-incrementing sequence numbers, which may also be set
305 * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
306 * to indicate that a message corresponds to some other set of messages or
307 * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
308 * is considered good practice to make this correspondence when possible, though
309 * it is not required.
311 * Note that events and messages share the same sequence number incrementor;
312 * two events or messages will never not have the same sequence number unless
313 * that correspondence was made explicitly.
315 * Returns: The message's sequence number.
322 gst_message_get_seqnum (GstMessage * message)
324 g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
326 return GST_MESSAGE_SEQNUM (message);
330 * gst_message_set_seqnum:
331 * @message: A #GstMessage.
332 * @seqnum: A sequence number.
334 * Set the sequence number of a message.
336 * This function might be called by the creator of a message to indicate that
337 * the message relates to other messages or events. See gst_message_get_seqnum()
338 * for more information.
345 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
347 g_return_if_fail (GST_IS_MESSAGE (message));
349 GST_MESSAGE_SEQNUM (message) = seqnum;
353 * gst_message_new_eos:
354 * @src: (transfer none): The object originating the message.
356 * Create a new eos message. This message is generated and posted in
357 * the sink elements of a GstBin. The bin will only forward the EOS
358 * message to the application if all sinks have posted an EOS message.
360 * Returns: (transfer full): The new eos message.
365 gst_message_new_eos (GstObject * src)
369 message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
375 * gst_message_new_error:
376 * @src: (transfer none): The object originating the message.
377 * @error: (transfer none): The GError for this message.
378 * @debug: A debugging string.
380 * Create a new error message. The message will copy @error and
381 * @debug. This message is posted by element when a fatal event
382 * occured. The pipeline will probably (partially) stop. The application
383 * receiving this message should stop the pipeline.
385 * Returns: (transfer full): the new error message.
390 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
393 GstStructure *structure;
395 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ERROR),
396 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
397 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
398 message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
404 * gst_message_new_warning:
405 * @src: (transfer none): The object originating the message.
406 * @error: (transfer none): The GError for this message.
407 * @debug: A debugging string.
409 * Create a new warning message. The message will make copies of @error and
412 * Returns: (transfer full): The new warning message.
417 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
420 GstStructure *structure;
422 structure = gst_structure_id_new (GST_QUARK (MESSAGE_WARNING),
423 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
424 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
425 message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
431 * gst_message_new_info:
432 * @src: (transfer none): The object originating the message.
433 * @error: (transfer none): The GError for this message.
434 * @debug: A debugging string.
436 * Create a new info message. The message will make copies of @error and
441 * Returns: (transfer full): the new info message.
446 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
449 GstStructure *structure;
451 structure = gst_structure_id_new (GST_QUARK (MESSAGE_INFO),
452 GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
453 GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
454 message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
460 * gst_message_new_tag:
461 * @src: (transfer none): The object originating the message.
462 * @tag_list: (transfer full): the tag list for the message.
464 * Create a new tag message. The message will take ownership of the tag list.
465 * The message is posted by elements that discovered a new taglist.
467 * Returns: (transfer full): the new tag message.
472 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
476 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
479 gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
485 * gst_message_new_tag_full:
486 * @src: (transfer none): the object originating the message.
487 * @pad: (transfer none): the originating pad for the tag.
488 * @tag_list: (transfer full): the tag list for the message.
490 * Create a new tag message. The message will take ownership of the tag list.
491 * The message is posted by elements that discovered a new taglist.
495 * Returns: (transfer full): the new tag message.
500 gst_message_new_tag_full (GstObject * src, GstPad * pad, GstTagList * tag_list)
505 g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
506 g_return_val_if_fail (pad == NULL || GST_IS_PAD (pad), NULL);
508 s = (GstStructure *) tag_list;
510 gst_structure_set (s, "source-pad", GST_TYPE_PAD, pad, NULL);
512 message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
518 * gst_message_new_buffering:
519 * @src: (transfer none): The object originating the message.
520 * @percent: The buffering percent
522 * Create a new buffering message. This message can be posted by an element that
523 * needs to buffer data before it can continue processing. @percent should be a
524 * value between 0 and 100. A value of 100 means that the buffering completed.
526 * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
527 * @percent is 100, the application can set the pipeline (back) to PLAYING.
528 * The application must be prepared to receive BUFFERING messages in the
529 * PREROLLING state and may only set the pipeline to PLAYING after receiving a
530 * message with @percent set to 100, which can happen after the pipeline
531 * completed prerolling.
535 * Returns: (transfer full): The new buffering message.
540 gst_message_new_buffering (GstObject * src, gint percent)
543 GstStructure *structure;
545 g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
547 structure = gst_structure_id_new (GST_QUARK (MESSAGE_BUFFERING),
548 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
549 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
550 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
551 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
552 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
553 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
554 message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
560 * gst_message_new_state_changed:
561 * @src: (transfer none): the object originating the message
562 * @oldstate: the previous state
563 * @newstate: the new (current) state
564 * @pending: the pending (target) state
566 * Create a state change message. This message is posted whenever an element
569 * Returns: (transfer full): the new state change message.
574 gst_message_new_state_changed (GstObject * src,
575 GstState oldstate, GstState newstate, GstState pending)
578 GstStructure *structure;
580 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STATE),
581 GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
582 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
583 GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
584 message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
590 * gst_message_new_state_dirty:
591 * @src: (transfer none): the object originating the message
593 * Create a state dirty message. This message is posted whenever an element
594 * changed its state asynchronously and is used internally to update the
595 * states of container objects.
597 * Returns: (transfer full): the new state dirty message.
602 gst_message_new_state_dirty (GstObject * src)
606 message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
612 * gst_message_new_clock_provide:
613 * @src: (transfer none): the object originating the message.
614 * @clock: (transfer none): the clock it provides
615 * @ready: TRUE if the sender can provide a clock
617 * Create a clock provide message. This message is posted whenever an
618 * element is ready to provide a clock or lost its ability to provide
619 * a clock (maybe because it paused or became EOS).
621 * This message is mainly used internally to manage the clock
624 * Returns: (transfer full): the new provide clock message.
629 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
633 GstStructure *structure;
635 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
636 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
637 GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
638 message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
644 * gst_message_new_clock_lost:
645 * @src: (transfer none): the object originating the message.
646 * @clock: (transfer none): the clock that was lost
648 * Create a clock lost message. This message is posted whenever the
649 * clock is not valid anymore.
651 * If this message is posted by the pipeline, the pipeline will
652 * select a new clock again when it goes to PLAYING. It might therefore
653 * be needed to set the pipeline to PAUSED and PLAYING again.
655 * Returns: (transfer full): The new clock lost message.
660 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
663 GstStructure *structure;
665 structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_LOST),
666 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
667 message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
673 * gst_message_new_new_clock:
674 * @src: (transfer none): The object originating the message.
675 * @clock: (transfer none): the new selected clock
677 * Create a new clock message. This message is posted whenever the
678 * pipeline selectes a new clock for the pipeline.
680 * Returns: (transfer full): The new new clock message.
685 gst_message_new_new_clock (GstObject * src, GstClock * clock)
688 GstStructure *structure;
690 structure = gst_structure_id_new (GST_QUARK (MESSAGE_NEW_CLOCK),
691 GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
692 message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
698 * gst_message_new_structure_change:
699 * @src: (transfer none): The object originating the message.
700 * @type: The change type.
701 * @owner: (transfer none): The owner element of @src.
702 * @busy: Whether the structure change is busy.
704 * Create a new structure change message. This message is posted when the
705 * structure of a pipeline is in the process of being changed, for example
706 * when pads are linked or unlinked.
708 * @src should be the sinkpad that unlinked or linked.
710 * Returns: (transfer full): the new structure change message.
717 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
718 GstElement * owner, gboolean busy)
721 GstStructure *structure;
723 g_return_val_if_fail (GST_IS_PAD (src), NULL);
724 /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
725 g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
727 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
728 GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
729 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
730 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
732 message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
739 * gst_message_new_segment_start:
740 * @src: (transfer none): The object originating the message.
741 * @format: The format of the position being played
742 * @position: The position of the segment being played
744 * Create a new segment message. This message is posted by elements that
745 * start playback of a segment as a result of a segment seek. This message
746 * is not received by the application but is used for maintenance reasons in
747 * container elements.
749 * Returns: (transfer full): the new segment start message.
754 gst_message_new_segment_start (GstObject * src, GstFormat format,
758 GstStructure *structure;
760 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_START),
761 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
762 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
763 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
769 * gst_message_new_segment_done:
770 * @src: (transfer none): the object originating the message.
771 * @format: The format of the position being done
772 * @position: The position of the segment being done
774 * Create a new segment done message. This message is posted by elements that
775 * finish playback of a segment as a result of a segment seek. This message
776 * is received by the application after all elements that posted a segment_start
777 * have posted the segment_done.
779 * Returns: (transfer full): the new segment done message.
784 gst_message_new_segment_done (GstObject * src, GstFormat format,
788 GstStructure *structure;
790 structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_DONE),
791 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
792 GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
793 message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
799 * gst_message_new_application:
800 * @src: (transfer none): the object originating the message.
801 * @structure: (transfer full): the structure for the message. The message
802 * will take ownership of the structure.
804 * Create a new application-typed message. GStreamer will never create these
805 * messages; they are a gift from us to you. Enjoy.
807 * Returns: (transfer full): The new application message.
812 gst_message_new_application (GstObject * src, GstStructure * structure)
814 return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
818 * gst_message_new_element:
819 * @src: (transfer none): The object originating the message.
820 * @structure: (transfer full): The structure for the message. The message
821 * will take ownership of the structure.
823 * Create a new element-specific message. This is meant as a generic way of
824 * allowing one-way communication from an element to an application, for example
825 * "the firewire cable was unplugged". The format of the message should be
826 * documented in the element's documentation. The structure field can be NULL.
828 * Returns: (transfer full): The new element message.
833 gst_message_new_element (GstObject * src, GstStructure * structure)
835 return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
839 * gst_message_new_duration:
840 * @src: (transfer none): The object originating the message.
841 * @format: The format of the duration
842 * @duration: The new duration
844 * Create a new duration message. This message is posted by elements that
845 * know the duration of a stream in a specific format. This message
846 * is received by bins and is used to calculate the total duration of a
847 * pipeline. Elements may post a duration message with a duration of
848 * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
849 * cached duration should be discarded. The new duration can then be
850 * retrieved via a query.
852 * Returns: (transfer full): The new duration message.
857 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
860 GstStructure *structure;
862 structure = gst_structure_id_new (GST_QUARK (MESSAGE_DURATION),
863 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
864 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
865 message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
871 * gst_message_new_async_start:
872 * @src: (transfer none): The object originating the message.
873 * @new_base_time: if a new base_time should be set on the element
875 * This message is posted by elements when they start an ASYNC state change.
876 * @new_base_time is set to TRUE when the element lost its state when it was
879 * Returns: (transfer full): The new async_start message.
886 gst_message_new_async_start (GstObject * src, gboolean new_base_time)
889 GstStructure *structure;
891 structure = gst_structure_id_new (GST_QUARK (MESSAGE_ASYNC_START),
892 GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
893 message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
899 * gst_message_new_async_done:
900 * @src: (transfer none): The object originating the message.
902 * The message is posted when elements completed an ASYNC state change.
904 * Returns: (transfer full): The new async_done message.
911 gst_message_new_async_done (GstObject * src)
915 message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
921 * gst_message_new_latency:
922 * @src: (transfer none): The object originating the message.
924 * This message can be posted by elements when their latency requirements have
927 * Returns: (transfer full): The new latency message.
934 gst_message_new_latency (GstObject * src)
938 message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
944 * gst_message_new_request_state:
945 * @src: (transfer none): the object originating the message.
946 * @state: The new requested state
948 * This message can be posted by elements when they want to have their state
949 * changed. A typical use case would be an audio server that wants to pause the
950 * pipeline because a higher priority stream is being played.
952 * Returns: (transfer full): the new requst state message.
959 gst_message_new_request_state (GstObject * src, GstState state)
962 GstStructure *structure;
964 structure = gst_structure_id_new (GST_QUARK (MESSAGE_REQUEST_STATE),
965 GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
966 message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
972 * gst_message_get_structure:
973 * @message: The #GstMessage.
975 * Access the structure of the message.
977 * Returns: (transfer none): The structure of the message. The structure is
978 * still owned by the message, which means that you should not free it and
979 * that the pointer becomes invalid when you free the message.
984 gst_message_get_structure (GstMessage * message)
986 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
988 return GST_MESSAGE_STRUCTURE (message);
992 * gst_message_has_name:
993 * @message: The #GstMessage.
994 * @name: name to check
996 * Checks if @message has the given @name. This function is usually used to
997 * check the name of a custom message.
999 * Returns: %TRUE if @name matches the name of the message structure.
1004 gst_message_has_name (GstMessage * message, const gchar * name)
1006 GstStructure *structure;
1008 g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
1010 structure = GST_MESSAGE_STRUCTURE (message);
1011 if (structure == NULL)
1014 return gst_structure_has_name (structure, name);
1018 * gst_message_parse_tag:
1019 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1020 * @tag_list: (out callee-allocates): return location for the tag-list.
1022 * Extracts the tag list from the GstMessage. The tag list returned in the
1023 * output argument is a copy; the caller must free it when done.
1025 * Typical usage of this function might be:
1028 * switch (GST_MESSAGE_TYPE (msg)) {
1029 * case GST_MESSAGE_TAG: {
1030 * GstTagList *tags = NULL;
1032 * gst_message_parse_tag (msg, &tags);
1033 * g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1034 * handle_tags (tags);
1035 * gst_tag_list_free (tags);
1046 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1050 g_return_if_fail (GST_IS_MESSAGE (message));
1051 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1052 g_return_if_fail (tag_list != NULL);
1054 ret = gst_structure_copy (GST_MESSAGE_STRUCTURE (message));
1055 gst_structure_remove_field (ret, "source-pad");
1057 *tag_list = (GstTagList *) ret;
1061 * gst_message_parse_tag_full:
1062 * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1063 * @pad: (out callee-allocates): location where the originating pad is stored,
1065 * @tag_list: (out callee-allocates): return location for the tag-list.
1067 * Extracts the tag list from the GstMessage. The tag list returned in the
1068 * output argument is a copy; the caller must free it when done.
1075 gst_message_parse_tag_full (GstMessage * message, GstPad ** pad,
1076 GstTagList ** tag_list)
1080 g_return_if_fail (GST_IS_MESSAGE (message));
1081 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1082 g_return_if_fail (tag_list != NULL);
1084 ret = gst_structure_copy (GST_MESSAGE_STRUCTURE (message));
1086 if (gst_structure_has_field (ret, "source-pad") && pad) {
1089 v = gst_structure_get_value (ret, "source-pad");
1090 if (v && G_VALUE_HOLDS (v, GST_TYPE_PAD))
1091 *pad = g_value_dup_object (v);
1097 gst_structure_remove_field (ret, "source-pad");
1099 *tag_list = (GstTagList *) ret;
1103 * gst_message_parse_buffering:
1104 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1105 * @percent: (out) (allow-none): Return location for the percent.
1107 * Extracts the buffering percent from the GstMessage. see also
1108 * gst_message_new_buffering().
1115 gst_message_parse_buffering (GstMessage * message, gint * percent)
1117 g_return_if_fail (GST_IS_MESSAGE (message));
1118 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1122 g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1123 (message), GST_QUARK (BUFFER_PERCENT)));
1127 * gst_message_set_buffering_stats:
1128 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1129 * @mode: a buffering mode
1130 * @avg_in: the average input rate
1131 * @avg_out: the average output rate
1132 * @buffering_left: amount of buffering time left in milliseconds
1134 * Configures the buffering stats values in @message.
1139 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1140 gint avg_in, gint avg_out, gint64 buffering_left)
1142 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1144 gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1145 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1146 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1147 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1148 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1152 * gst_message_parse_buffering_stats:
1153 * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1154 * @mode: (out) (allow-none): a buffering mode, or NULL
1155 * @avg_in: (out) (allow-none): the average input rate, or NULL
1156 * @avg_out: (out) (allow-none): the average output rate, or NULL
1157 * @buffering_left: (out) (allow-none): amount of buffering time left in
1158 * milliseconds, or NULL
1160 * Extracts the buffering stats values from @message.
1165 gst_message_parse_buffering_stats (GstMessage * message,
1166 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1167 gint64 * buffering_left)
1169 GstStructure *structure;
1171 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1173 structure = GST_MESSAGE_STRUCTURE (message);
1175 *mode = g_value_get_enum (gst_structure_id_get_value (structure,
1176 GST_QUARK (BUFFERING_MODE)));
1178 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1179 GST_QUARK (AVG_IN_RATE)));
1181 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1182 GST_QUARK (AVG_OUT_RATE)));
1185 g_value_get_int64 (gst_structure_id_get_value (structure,
1186 GST_QUARK (BUFFERING_LEFT)));
1190 * gst_message_parse_state_changed:
1191 * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1192 * @oldstate: (out) (allow-none): the previous state, or NULL
1193 * @newstate: (out) (allow-none): the new (current) state, or NULL
1194 * @pending: (out) (allow-none): the pending (target) state, or NULL
1196 * Extracts the old and new states from the GstMessage.
1198 * Typical usage of this function might be:
1201 * switch (GST_MESSAGE_TYPE (msg)) {
1202 * case GST_MESSAGE_STATE_CHANGED: {
1203 * GstState old_state, new_state;
1205 * gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1206 * g_print ("Element %s changed state from %s to %s.\n",
1207 * GST_OBJECT_NAME (msg->src),
1208 * gst_element_state_get_name (old_state),
1209 * gst_element_state_get_name (new_state));
1220 gst_message_parse_state_changed (GstMessage * message,
1221 GstState * oldstate, GstState * newstate, GstState * pending)
1223 GstStructure *structure;
1225 g_return_if_fail (GST_IS_MESSAGE (message));
1226 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1228 structure = GST_MESSAGE_STRUCTURE (message);
1231 g_value_get_enum (gst_structure_id_get_value (structure,
1232 GST_QUARK (OLD_STATE)));
1235 g_value_get_enum (gst_structure_id_get_value (structure,
1236 GST_QUARK (NEW_STATE)));
1238 *pending = g_value_get_enum (gst_structure_id_get_value (structure,
1239 GST_QUARK (PENDING_STATE)));
1243 * gst_message_parse_clock_provide:
1244 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1245 * @clock: (out) (allow-none) (transfer none): a pointer to hold a clock
1247 * @ready: (out) (allow-none): a pointer to hold the ready flag, or NULL
1249 * Extracts the clock and ready flag from the GstMessage.
1250 * The clock object returned remains valid until the message is freed.
1255 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1258 const GValue *clock_gvalue;
1259 GstStructure *structure;
1261 g_return_if_fail (GST_IS_MESSAGE (message));
1262 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1264 structure = GST_MESSAGE_STRUCTURE (message);
1265 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1266 g_return_if_fail (clock_gvalue != NULL);
1267 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1271 g_value_get_boolean (gst_structure_id_get_value (structure,
1272 GST_QUARK (READY)));
1274 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1278 * gst_message_parse_clock_lost:
1279 * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1280 * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1282 * Extracts the lost clock from the GstMessage.
1283 * The clock object returned remains valid until the message is freed.
1288 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1290 const GValue *clock_gvalue;
1291 GstStructure *structure;
1293 g_return_if_fail (GST_IS_MESSAGE (message));
1294 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1296 structure = GST_MESSAGE_STRUCTURE (message);
1297 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1298 g_return_if_fail (clock_gvalue != NULL);
1299 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1302 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1306 * gst_message_parse_new_clock:
1307 * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1308 * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1311 * Extracts the new clock from the GstMessage.
1312 * The clock object returned remains valid until the message is freed.
1317 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1319 const GValue *clock_gvalue;
1320 GstStructure *structure;
1322 g_return_if_fail (GST_IS_MESSAGE (message));
1323 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1325 structure = GST_MESSAGE_STRUCTURE (message);
1326 clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1327 g_return_if_fail (clock_gvalue != NULL);
1328 g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1331 *clock = (GstClock *) g_value_get_object (clock_gvalue);
1335 * gst_message_parse_structure_change:
1336 * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1337 * @type: (out): A pointer to hold the change type
1338 * @owner: (out) (allow-none) (transfer none): The owner element of the
1340 * @busy: (out) (allow-none): a pointer to hold whether the change is in
1341 * progress or has been completed
1343 * Extracts the change type and completion status from the GstMessage.
1350 gst_message_parse_structure_change (GstMessage * message,
1351 GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1353 const GValue *owner_gvalue;
1354 GstStructure *structure;
1356 g_return_if_fail (GST_IS_MESSAGE (message));
1357 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1359 structure = GST_MESSAGE_STRUCTURE (message);
1360 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1361 g_return_if_fail (owner_gvalue != NULL);
1362 g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1365 *type = g_value_get_enum (gst_structure_id_get_value (structure,
1368 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1371 g_value_get_boolean (gst_structure_id_get_value (structure,
1376 * gst_message_parse_error:
1377 * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1378 * @gerror: (out) (allow-none) (transfer full): location for the GError
1379 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1382 * Extracts the GError and debug string from the GstMessage. The values returned
1383 * in the output arguments are copies; the caller must free them when done.
1385 * Typical usage of this function might be:
1388 * switch (GST_MESSAGE_TYPE (msg)) {
1389 * case GST_MESSAGE_ERROR: {
1390 * GError *err = NULL;
1391 * gchar *dbg_info = NULL;
1393 * gst_message_parse_error (msg, &err, &dbg_info);
1394 * g_printerr ("ERROR from element %s: %s\n",
1395 * GST_OBJECT_NAME (msg->src), err->message);
1396 * g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1397 * g_error_free (err);
1398 * g_free (dbg_info);
1409 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1411 const GValue *error_gvalue;
1413 GstStructure *structure;
1415 g_return_if_fail (GST_IS_MESSAGE (message));
1416 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1418 structure = GST_MESSAGE_STRUCTURE (message);
1419 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1420 g_return_if_fail (error_gvalue != NULL);
1421 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1423 error_val = (GError *) g_value_get_boxed (error_gvalue);
1425 *gerror = g_error_copy (error_val);
1431 g_value_dup_string (gst_structure_id_get_value (structure,
1432 GST_QUARK (DEBUG)));
1436 * gst_message_parse_warning:
1437 * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1438 * @gerror: (out) (allow-none) (transfer full): location for the GError
1439 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1442 * Extracts the GError and debug string from the GstMessage. The values returned
1443 * in the output arguments are copies; the caller must free them when done.
1448 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1451 const GValue *error_gvalue;
1453 GstStructure *structure;
1455 g_return_if_fail (GST_IS_MESSAGE (message));
1456 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1458 structure = GST_MESSAGE_STRUCTURE (message);
1459 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1460 g_return_if_fail (error_gvalue != NULL);
1461 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1463 error_val = (GError *) g_value_get_boxed (error_gvalue);
1465 *gerror = g_error_copy (error_val);
1471 g_value_dup_string (gst_structure_id_get_value (structure,
1472 GST_QUARK (DEBUG)));
1476 * gst_message_parse_info:
1477 * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1478 * @gerror: (out) (allow-none) (transfer full): location for the GError
1479 * @debug: (out) (allow-none) (transfer full): location for the debug message,
1482 * Extracts the GError and debug string from the GstMessage. The values returned
1483 * in the output arguments are copies; the caller must free them when done.
1490 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1492 const GValue *error_gvalue;
1494 GstStructure *structure;
1496 g_return_if_fail (GST_IS_MESSAGE (message));
1497 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1499 structure = GST_MESSAGE_STRUCTURE (message);
1500 error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
1501 g_return_if_fail (error_gvalue != NULL);
1502 g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1504 error_val = (GError *) g_value_get_boxed (error_gvalue);
1506 *gerror = g_error_copy (error_val);
1512 g_value_dup_string (gst_structure_id_get_value (structure,
1513 GST_QUARK (DEBUG)));
1517 * gst_message_parse_segment_start:
1518 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1519 * @format: (out): Result location for the format, or NULL
1520 * @position: (out): Result location for the position, or NULL
1522 * Extracts the position and format from the segment start message.
1527 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1530 GstStructure *structure;
1532 g_return_if_fail (GST_IS_MESSAGE (message));
1533 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1535 structure = GST_MESSAGE_STRUCTURE (message);
1538 g_value_get_enum (gst_structure_id_get_value (structure,
1539 GST_QUARK (FORMAT)));
1542 g_value_get_int64 (gst_structure_id_get_value (structure,
1543 GST_QUARK (POSITION)));
1547 * gst_message_parse_segment_done:
1548 * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1549 * @format: (out): Result location for the format, or NULL
1550 * @position: (out): Result location for the position, or NULL
1552 * Extracts the position and format from the segment start message.
1557 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1560 GstStructure *structure;
1562 g_return_if_fail (GST_IS_MESSAGE (message));
1563 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1565 structure = GST_MESSAGE_STRUCTURE (message);
1568 g_value_get_enum (gst_structure_id_get_value (structure,
1569 GST_QUARK (FORMAT)));
1572 g_value_get_int64 (gst_structure_id_get_value (structure,
1573 GST_QUARK (POSITION)));
1577 * gst_message_parse_duration:
1578 * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1579 * @format: (out): Result location for the format, or NULL
1580 * @duration: (out): Result location for the duration, or NULL
1582 * Extracts the duration and format from the duration message. The duration
1583 * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1584 * changed. Applications should always use a query to retrieve the duration
1590 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1593 GstStructure *structure;
1595 g_return_if_fail (GST_IS_MESSAGE (message));
1596 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1598 structure = GST_MESSAGE_STRUCTURE (message);
1601 g_value_get_enum (gst_structure_id_get_value (structure,
1602 GST_QUARK (FORMAT)));
1605 g_value_get_int64 (gst_structure_id_get_value (structure,
1606 GST_QUARK (DURATION)));
1610 * gst_message_parse_async_start:
1611 * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1612 * @new_base_time: (out): Result location for the new_base_time or NULL
1614 * Extract the new_base_time from the async_start message.
1621 gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
1623 GstStructure *structure;
1625 g_return_if_fail (GST_IS_MESSAGE (message));
1626 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_START);
1628 structure = GST_MESSAGE_STRUCTURE (message);
1631 g_value_get_boolean (gst_structure_id_get_value (structure,
1632 GST_QUARK (NEW_BASE_TIME)));
1636 * gst_message_parse_request_state:
1637 * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1638 * @state: (out): Result location for the requested state or NULL
1640 * Extract the requested state from the request_state message.
1647 gst_message_parse_request_state (GstMessage * message, GstState * state)
1649 GstStructure *structure;
1651 g_return_if_fail (GST_IS_MESSAGE (message));
1652 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1654 structure = GST_MESSAGE_STRUCTURE (message);
1656 *state = g_value_get_enum (gst_structure_id_get_value (structure,
1657 GST_QUARK (NEW_STATE)));
1661 * gst_message_new_stream_status:
1662 * @src: The object originating the message.
1663 * @type: The stream status type.
1664 * @owner: (transfer none): the owner element of @src.
1666 * Create a new stream status message. This message is posted when a streaming
1667 * thread is created/destroyed or when the state changed.
1669 * Returns: (transfer full): the new stream status message.
1676 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1679 GstMessage *message;
1680 GstStructure *structure;
1682 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STREAM_STATUS),
1683 GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1684 GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1685 message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1691 * gst_message_parse_stream_status:
1692 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1693 * @type: (out): A pointer to hold the status type
1694 * @owner: (out) (transfer none): The owner element of the message source
1696 * Extracts the stream status type and owner the GstMessage. The returned
1697 * owner remains valid for as long as the reference to @message is valid and
1698 * should thus not be unreffed.
1705 gst_message_parse_stream_status (GstMessage * message,
1706 GstStreamStatusType * type, GstElement ** owner)
1708 const GValue *owner_gvalue;
1709 GstStructure *structure;
1711 g_return_if_fail (GST_IS_MESSAGE (message));
1712 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1714 structure = GST_MESSAGE_STRUCTURE (message);
1715 owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1716 g_return_if_fail (owner_gvalue != NULL);
1719 *type = g_value_get_enum (gst_structure_id_get_value (structure,
1722 *owner = (GstElement *) g_value_get_object (owner_gvalue);
1726 * gst_message_set_stream_status_object:
1727 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1728 * @object: the object controlling the streaming
1730 * Configures the object handling the streaming thread. This is usually a
1731 * GstTask object but other objects might be added in the future.
1736 gst_message_set_stream_status_object (GstMessage * message,
1737 const GValue * object)
1739 GstStructure *structure;
1741 g_return_if_fail (GST_IS_MESSAGE (message));
1742 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1744 structure = GST_MESSAGE_STRUCTURE (message);
1745 gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
1749 * gst_message_get_stream_status_object:
1750 * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1752 * Extracts the object managing the streaming thread from @message.
1754 * Returns: a GValue containing the object that manages the streaming thread.
1755 * This object is usually of type GstTask but other types can be added in the
1756 * future. The object remains valid as long as @message is valid.
1761 gst_message_get_stream_status_object (GstMessage * message)
1763 const GValue *result;
1764 GstStructure *structure;
1766 g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1767 g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1770 structure = GST_MESSAGE_STRUCTURE (message);
1771 result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1777 * gst_message_new_step_done:
1778 * @src: The object originating the message.
1779 * @format: the format of @amount
1780 * @amount: the amount of stepped data
1781 * @rate: the rate of the stepped amount
1782 * @flush: is this an flushing step
1783 * @intermediate: is this an intermediate step
1784 * @duration: the duration of the data
1785 * @eos: the step caused EOS
1787 * This message is posted by elements when they complete a part, when @intermediate set
1788 * to TRUE, or a complete step operation.
1790 * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1791 * @amount of media in format @format.
1793 * Returns: (transfer full): the new step_done message.
1800 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1801 gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1804 GstMessage *message;
1805 GstStructure *structure;
1807 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_DONE),
1808 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1809 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1810 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1811 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1812 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1813 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1814 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1815 message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1821 * gst_message_parse_step_done:
1822 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1823 * @format: (out) (allow-none): result location for the format
1824 * @amount: (out) (allow-none): result location for the amount
1825 * @rate: (out) (allow-none): result location for the rate
1826 * @flush: (out) (allow-none): result location for the flush flag
1827 * @intermediate: (out) (allow-none): result location for the intermediate flag
1828 * @duration: (out) (allow-none): result location for the duration
1829 * @eos: (out) (allow-none): result location for the EOS flag
1831 * Extract the values the step_done message.
1838 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1839 guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1840 guint64 * duration, gboolean * eos)
1842 GstStructure *structure;
1844 g_return_if_fail (GST_IS_MESSAGE (message));
1845 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1847 structure = GST_MESSAGE_STRUCTURE (message);
1848 gst_structure_id_get (structure,
1849 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1850 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1851 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1852 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1853 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1854 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1855 GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1859 * gst_message_new_step_start:
1860 * @src: The object originating the message.
1861 * @active: if the step is active or queued
1862 * @format: the format of @amount
1863 * @amount: the amount of stepped data
1864 * @rate: the rate of the stepped amount
1865 * @flush: is this an flushing step
1866 * @intermediate: is this an intermediate step
1868 * This message is posted by elements when they accept or activate a new step
1869 * event for @amount in @format.
1871 * @active is set to FALSE when the element accepted the new step event and has
1872 * queued it for execution in the streaming threads.
1874 * @active is set to TRUE when the element has activated the step operation and
1875 * is now ready to start executing the step in the streaming thread. After this
1876 * message is emited, the application can queue a new step operation in the
1879 * Returns: (transfer full): The new step_start message.
1886 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1887 guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1889 GstMessage *message;
1890 GstStructure *structure;
1892 structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_START),
1893 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1894 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1895 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1896 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1897 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1898 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1899 message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1905 * gst_message_parse_step_start:
1906 * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1907 * @active: (out) (allow-none): result location for the active flag
1908 * @format: (out) (allow-none): result location for the format
1909 * @amount: (out) (allow-none): result location for the amount
1910 * @rate: (out) (allow-none): result location for the rate
1911 * @flush: (out) (allow-none): result location for the flush flag
1912 * @intermediate: (out) (allow-none): result location for the intermediate flag
1914 * Extract the values from step_start message.
1921 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1922 GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1923 gboolean * intermediate)
1925 GstStructure *structure;
1927 g_return_if_fail (GST_IS_MESSAGE (message));
1928 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1930 structure = GST_MESSAGE_STRUCTURE (message);
1931 gst_structure_id_get (structure,
1932 GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1933 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1934 GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1935 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1936 GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1937 GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1941 * gst_message_new_qos:
1942 * @src: The object originating the message.
1943 * @live: if the message was generated by a live element
1944 * @running_time: the running time of the buffer that generated the message
1945 * @stream_time: the stream time of the buffer that generated the message
1946 * @timestamp: the timestamps of the buffer that generated the message
1947 * @duration: the duration of the buffer that generated the message
1949 * A QOS message is posted on the bus whenever an element decides to drop a
1950 * buffer because of QoS reasons or whenever it changes its processing strategy
1951 * because of QoS reasons (quality adjustments such as processing at lower
1954 * This message can be posted by an element that performs synchronisation against the
1955 * clock (live) or it could be dropped by an element that performs QoS because of QOS
1956 * events received from a downstream element (!live).
1958 * @running_time, @stream_time, @timestamp, @duration should be set to the
1959 * respective running-time, stream-time, timestamp and duration of the (dropped)
1960 * buffer that generated the QoS event. Values can be left to
1961 * GST_CLOCK_TIME_NONE when unknown.
1963 * Returns: (transfer full): The new qos message.
1970 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1971 guint64 stream_time, guint64 timestamp, guint64 duration)
1973 GstMessage *message;
1974 GstStructure *structure;
1976 structure = gst_structure_id_new (GST_QUARK (MESSAGE_QOS),
1977 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1978 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1979 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1980 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1981 GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1982 GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1983 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1984 GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1985 GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1986 GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1987 GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1988 message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1994 * gst_message_set_qos_values:
1995 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1996 * @jitter: The difference of the running-time against the deadline.
1997 * @proportion: Long term prediction of the ideal rate relative to normal rate
1998 * to get optimal quality.
1999 * @quality: An element dependent integer value that specifies the current
2000 * quality level of the element. The default maximum quality is 1000000.
2002 * Set the QoS values that have been calculated/analysed from the QoS data
2009 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
2010 gdouble proportion, gint quality)
2012 GstStructure *structure;
2014 g_return_if_fail (GST_IS_MESSAGE (message));
2015 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2017 structure = GST_MESSAGE_STRUCTURE (message);
2018 gst_structure_id_set (structure,
2019 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2020 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2021 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2025 * gst_message_set_qos_stats:
2026 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2027 * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
2028 * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
2029 * will likely use GST_FORMAT_DEFAULT (samples).
2030 * @processed: Total number of units correctly processed since the last state
2031 * change to READY or a flushing operation.
2032 * @dropped: Total number of units dropped since the last state change to READY
2033 * or a flushing operation.
2035 * Set the QoS stats representing the history of the current continuous pipeline
2038 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2039 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2046 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
2047 guint64 processed, guint64 dropped)
2049 GstStructure *structure;
2051 g_return_if_fail (GST_IS_MESSAGE (message));
2052 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2054 structure = GST_MESSAGE_STRUCTURE (message);
2055 gst_structure_id_set (structure,
2056 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2057 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2058 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2062 * gst_message_parse_qos:
2063 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2064 * @live: (out) (allow-none): if the message was generated by a live element
2065 * @running_time: (out) (allow-none): the running time of the buffer that
2066 * generated the message
2067 * @stream_time: (out) (allow-none): the stream time of the buffer that
2068 * generated the message
2069 * @timestamp: (out) (allow-none): the timestamps of the buffer that
2070 * generated the message
2071 * @duration: (out) (allow-none): the duration of the buffer that
2072 * generated the message
2074 * Extract the timestamps and live status from the QoS message.
2076 * The returned values give the running_time, stream_time, timestamp and
2077 * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2085 gst_message_parse_qos (GstMessage * message, gboolean * live,
2086 guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2089 GstStructure *structure;
2091 g_return_if_fail (GST_IS_MESSAGE (message));
2092 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2094 structure = GST_MESSAGE_STRUCTURE (message);
2095 gst_structure_id_get (structure,
2096 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2097 GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2098 GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2099 GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2100 GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2104 * gst_message_parse_qos_values:
2105 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2106 * @jitter: (out) (allow-none): The difference of the running-time against
2108 * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2109 * relative to normal rate to get optimal quality.
2110 * @quality: (out) (allow-none): An element dependent integer value that
2111 * specifies the current quality level of the element. The default
2112 * maximum quality is 1000000.
2114 * Extract the QoS values that have been calculated/analysed from the QoS data
2121 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2122 gdouble * proportion, gint * quality)
2124 GstStructure *structure;
2126 g_return_if_fail (GST_IS_MESSAGE (message));
2127 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2129 structure = GST_MESSAGE_STRUCTURE (message);
2130 gst_structure_id_get (structure,
2131 GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2132 GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2133 GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2137 * gst_message_parse_qos_stats:
2138 * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2139 * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2140 * Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2141 * Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2143 * @processed: (out) (allow-none): Total number of units correctly processed
2144 * since the last state change to READY or a flushing operation.
2145 * @dropped: (out) (allow-none): Total number of units dropped since the last
2146 * state change to READY or a flushing operation.
2148 * Extract the QoS stats representing the history of the current continuous
2149 * pipeline playback period.
2151 * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2152 * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2159 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2160 guint64 * processed, guint64 * dropped)
2162 GstStructure *structure;
2164 g_return_if_fail (GST_IS_MESSAGE (message));
2165 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2167 structure = GST_MESSAGE_STRUCTURE (message);
2168 gst_structure_id_get (structure,
2169 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2170 GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2171 GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2175 * gst_message_new_progress:
2176 * @src: The object originating the message.
2177 * @type: a #GstProgressType
2178 * @code: a progress code
2179 * @text: free, user visible text describing the progress
2181 * Progress messages are posted by elements when they use an asynchronous task
2182 * to perform actions triggered by a state change.
2184 * @code contains a well defined string describing the action.
2185 * @test should contain a user visible string detailing the current action.
2187 * Returns: (transfer full): The new qos message.
2192 gst_message_new_progress (GstObject * src, GstProgressType type,
2193 const gchar * code, const gchar * text)
2195 GstMessage *message;
2196 GstStructure *structure;
2197 gint percent = 100, timeout = -1;
2199 g_return_val_if_fail (code != NULL, NULL);
2200 g_return_val_if_fail (text != NULL, NULL);
2202 if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2205 structure = gst_structure_id_new (GST_QUARK (MESSAGE_PROGRESS),
2206 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2207 GST_QUARK (CODE), G_TYPE_STRING, code,
2208 GST_QUARK (TEXT), G_TYPE_STRING, text,
2209 GST_QUARK (PERCENT), G_TYPE_INT, percent,
2210 GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2211 message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2217 * gst_message_parse_progress:
2218 * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2219 * @type: (out) (allow-none): location for the type
2220 * @code: (out) (allow-none) (transfer full): location for the code
2221 * @text: (out) (allow-none) (transfer full): location for the text
2223 * Parses the progress @type, @code and @text.
2228 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2229 gchar ** code, gchar ** text)
2231 GstStructure *structure;
2233 g_return_if_fail (GST_IS_MESSAGE (message));
2234 g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2236 structure = GST_MESSAGE_STRUCTURE (message);
2237 gst_structure_id_get (structure,
2238 GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2239 GST_QUARK (CODE), G_TYPE_STRING, code,
2240 GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);