message: Only allow setting valid seqnum on messages
[platform/upstream/gstreamer.git] / gst / gstmessage.c
1 /* GStreamer
2  * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
3  *
4  * gstmessage.c: GstMessage subsystem
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /**
23  * SECTION:gstmessage
24  * @title: GstMessage
25  * @short_description: Lightweight objects to signal the application of
26  *                     pipeline events
27  * @see_also: #GstBus, #GstMiniObject, #GstElement
28  *
29  * Messages are implemented as a subclass of #GstMiniObject with a generic
30  * #GstStructure as the content. This allows for writing custom messages without
31  * requiring an API change while allowing a wide range of different types
32  * of messages.
33  *
34  * Messages are posted by objects in the pipeline and are passed to the
35  * application using the #GstBus.
36  *
37  * The basic use pattern of posting a message on a #GstBus is as follows:
38  * |[<!-- language="C" -->
39  *   gst_bus_post (bus, gst_message_new_eos());
40  * ]|
41  *
42  * A #GstElement usually posts messages on the bus provided by the parent
43  * container using gst_element_post_message().
44  */
45
46
47 #include "gst_private.h"
48 #include <string.h>             /* memcpy */
49 #include "gsterror.h"
50 #include "gstenumtypes.h"
51 #include "gstinfo.h"
52 #include "gstmessage.h"
53 #include "gsttaglist.h"
54 #include "gstutils.h"
55 #include "gstquark.h"
56 #include "gstvalue.h"
57
58
59 typedef struct
60 {
61   GstMessage message;
62
63   GstStructure *structure;
64 } GstMessageImpl;
65
66 #define GST_MESSAGE_STRUCTURE(m)  (((GstMessageImpl *)(m))->structure)
67
68 typedef struct
69 {
70   const gint type;
71   const gchar *name;
72   GQuark quark;
73 } GstMessageQuarks;
74
75 static GstMessageQuarks message_quarks[] = {
76   {GST_MESSAGE_UNKNOWN, "unknown", 0},
77   {GST_MESSAGE_EOS, "eos", 0},
78   {GST_MESSAGE_ERROR, "error", 0},
79   {GST_MESSAGE_WARNING, "warning", 0},
80   {GST_MESSAGE_INFO, "info", 0},
81   {GST_MESSAGE_TAG, "tag", 0},
82   {GST_MESSAGE_BUFFERING, "buffering", 0},
83   {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
84   {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
85   {GST_MESSAGE_STEP_DONE, "step-done", 0},
86   {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
87   {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
88   {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
89   {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
90   {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
91   {GST_MESSAGE_APPLICATION, "application", 0},
92   {GST_MESSAGE_ELEMENT, "element", 0},
93   {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
94   {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
95   {GST_MESSAGE_DURATION_CHANGED, "duration-changed", 0},
96   {GST_MESSAGE_LATENCY, "latency", 0},
97   {GST_MESSAGE_ASYNC_START, "async-start", 0},
98   {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
99   {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
100   {GST_MESSAGE_STEP_START, "step-start", 0},
101   {GST_MESSAGE_QOS, "qos", 0},
102   {GST_MESSAGE_PROGRESS, "progress", 0},
103   {GST_MESSAGE_TOC, "toc", 0},
104   {GST_MESSAGE_RESET_TIME, "reset-time", 0},
105   {GST_MESSAGE_STREAM_START, "stream-start", 0},
106   {GST_MESSAGE_NEED_CONTEXT, "need-context", 0},
107   {GST_MESSAGE_HAVE_CONTEXT, "have-context", 0},
108   {GST_MESSAGE_DEVICE_ADDED, "device-added", 0},
109   {GST_MESSAGE_DEVICE_REMOVED, "device-removed", 0},
110   {GST_MESSAGE_PROPERTY_NOTIFY, "property-notify", 0},
111   {GST_MESSAGE_STREAM_COLLECTION, "stream-collection", 0},
112   {GST_MESSAGE_STREAMS_SELECTED, "streams-selected", 0},
113   {GST_MESSAGE_REDIRECT, "redirect", 0},
114   {0, NULL, 0}
115 };
116
117 static GQuark details_quark = 0;
118
119 GType _gst_message_type = 0;
120 GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
121
122 void
123 _priv_gst_message_initialize (void)
124 {
125   gint i;
126
127   GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
128
129   for (i = 0; message_quarks[i].name; i++) {
130     message_quarks[i].quark =
131         g_quark_from_static_string (message_quarks[i].name);
132   }
133   details_quark = g_quark_from_static_string ("details");
134
135   _gst_message_type = gst_message_get_type ();
136 }
137
138 /**
139  * gst_message_type_get_name:
140  * @type: the message type
141  *
142  * Get a printable name for the given message type. Do not modify or free.
143  *
144  * Returns: a reference to the static name of the message.
145  */
146 const gchar *
147 gst_message_type_get_name (GstMessageType type)
148 {
149   gint i;
150
151   for (i = 0; message_quarks[i].name; i++) {
152     if (type == message_quarks[i].type)
153       return message_quarks[i].name;
154   }
155   return "unknown";
156 }
157
158 /**
159  * gst_message_type_to_quark:
160  * @type: the message type
161  *
162  * Get the unique quark for the given message type.
163  *
164  * Returns: the quark associated with the message type
165  */
166 GQuark
167 gst_message_type_to_quark (GstMessageType type)
168 {
169   gint i;
170
171   for (i = 0; message_quarks[i].name; i++) {
172     if (type == message_quarks[i].type)
173       return message_quarks[i].quark;
174   }
175   return 0;
176 }
177
178 static gboolean
179 _gst_message_dispose (GstMessage * message)
180 {
181   gboolean do_free = TRUE;
182
183   if (GST_MINI_OBJECT_FLAG_IS_SET (message, GST_MESSAGE_FLAG_ASYNC_DELIVERY)) {
184     /* revive message, so bus can finish with it and clean it up */
185     gst_message_ref (message);
186
187     GST_INFO ("[msg %p] signalling async free", message);
188
189     GST_MESSAGE_LOCK (message);
190     GST_MESSAGE_SIGNAL (message);
191     GST_MESSAGE_UNLOCK (message);
192
193     /* don't free it yet, let bus finish with it first */
194     do_free = FALSE;
195   }
196
197   return do_free;
198 }
199
200 static void
201 _gst_message_free (GstMessage * message)
202 {
203   GstStructure *structure;
204
205   g_return_if_fail (message != NULL);
206
207   GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
208       GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
209
210   if (GST_MESSAGE_SRC (message)) {
211     gst_object_unref (GST_MESSAGE_SRC (message));
212     GST_MESSAGE_SRC (message) = NULL;
213   }
214
215   structure = GST_MESSAGE_STRUCTURE (message);
216   if (structure) {
217     gst_structure_set_parent_refcount (structure, NULL);
218     gst_structure_free (structure);
219   }
220
221   g_slice_free1 (sizeof (GstMessageImpl), message);
222 }
223
224 static void
225 gst_message_init (GstMessageImpl * message, GstMessageType type,
226     GstObject * src);
227
228 static GstMessage *
229 _gst_message_copy (GstMessage * message)
230 {
231   GstMessageImpl *copy;
232   GstStructure *structure;
233
234   GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
235       GST_MESSAGE_TYPE_NAME (message),
236       GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
237
238   copy = g_slice_new0 (GstMessageImpl);
239
240   gst_message_init (copy, GST_MESSAGE_TYPE (message),
241       GST_MESSAGE_SRC (message));
242
243   GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
244   GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
245
246   structure = GST_MESSAGE_STRUCTURE (message);
247   if (structure) {
248     GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
249     gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
250         &copy->message.mini_object.refcount);
251   } else {
252     GST_MESSAGE_STRUCTURE (copy) = NULL;
253   }
254
255   return GST_MESSAGE_CAST (copy);
256 }
257
258 static void
259 gst_message_init (GstMessageImpl * message, GstMessageType type,
260     GstObject * src)
261 {
262   gst_mini_object_init (GST_MINI_OBJECT_CAST (message), 0, _gst_message_type,
263       (GstMiniObjectCopyFunction) _gst_message_copy,
264       (GstMiniObjectDisposeFunction) _gst_message_dispose,
265       (GstMiniObjectFreeFunction) _gst_message_free);
266
267   GST_MESSAGE_TYPE (message) = type;
268   if (src)
269     gst_object_ref (src);
270   GST_MESSAGE_SRC (message) = src;
271   GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
272   GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
273 }
274
275
276 /**
277  * gst_message_new_custom:
278  * @type: The #GstMessageType to distinguish messages
279  * @src: (transfer none) (allow-none): The object originating the message.
280  * @structure: (transfer full) (allow-none): the structure for the
281  *     message. The message will take ownership of the structure.
282  *
283  * Create a new custom-typed message. This can be used for anything not
284  * handled by other message-specific functions to pass a message to the
285  * app. The structure field can be %NULL.
286  *
287  * Returns: (transfer full) (nullable): The new message.
288  *
289  * MT safe.
290  */
291 GstMessage *
292 gst_message_new_custom (GstMessageType type, GstObject * src,
293     GstStructure * structure)
294 {
295   GstMessageImpl *message;
296
297   message = g_slice_new0 (GstMessageImpl);
298
299   GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
300       (src ? GST_OBJECT_NAME (src) : "NULL"), message,
301       gst_message_type_get_name (type));
302
303   if (structure) {
304     /* structure must not have a parent */
305     if (!gst_structure_set_parent_refcount (structure,
306             &message->message.mini_object.refcount))
307       goto had_parent;
308   }
309   gst_message_init (message, type, src);
310
311   GST_MESSAGE_STRUCTURE (message) = structure;
312
313   return GST_MESSAGE_CAST (message);
314
315   /* ERRORS */
316 had_parent:
317   {
318     g_slice_free1 (sizeof (GstMessageImpl), message);
319     g_warning ("structure is already owned by another object");
320     return NULL;
321   }
322 }
323
324 /**
325  * gst_message_get_seqnum:
326  * @message: A #GstMessage.
327  *
328  * Retrieve the sequence number of a message.
329  *
330  * Messages have ever-incrementing sequence numbers, which may also be set
331  * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
332  * to indicate that a message corresponds to some other set of messages or
333  * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
334  * is considered good practice to make this correspondence when possible, though
335  * it is not required.
336  *
337  * Note that events and messages share the same sequence number incrementor;
338  * two events or messages will never have the same sequence number unless
339  * that correspondence was made explicitly.
340  *
341  * Returns: The message's sequence number.
342  *
343  * MT safe.
344  */
345 guint32
346 gst_message_get_seqnum (GstMessage * message)
347 {
348   g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
349
350   return GST_MESSAGE_SEQNUM (message);
351 }
352
353 /**
354  * gst_message_set_seqnum:
355  * @message: A #GstMessage.
356  * @seqnum: A sequence number.
357  *
358  * Set the sequence number of a message.
359  *
360  * This function might be called by the creator of a message to indicate that
361  * the message relates to other messages or events. See gst_message_get_seqnum()
362  * for more information.
363  *
364  * MT safe.
365  */
366 void
367 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
368 {
369   g_return_if_fail (GST_IS_MESSAGE (message));
370   g_return_if_fail (seqnum != GST_SEQNUM_INVALID);
371
372   GST_MESSAGE_SEQNUM (message) = seqnum;
373 }
374
375 /**
376  * gst_message_new_eos:
377  * @src: (transfer none) (allow-none): The object originating the message.
378  *
379  * Create a new eos message. This message is generated and posted in
380  * the sink elements of a GstBin. The bin will only forward the EOS
381  * message to the application if all sinks have posted an EOS message.
382  *
383  * Returns: (transfer full): The new eos message.
384  *
385  * MT safe.
386  */
387 GstMessage *
388 gst_message_new_eos (GstObject * src)
389 {
390   GstMessage *message;
391
392   message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
393
394   return message;
395 }
396
397 /**
398  * gst_message_new_error_with_details:
399  * @src: (transfer none) (allow-none): The object originating the message.
400  * @error: (transfer none): The GError for this message.
401  * @debug: A debugging string.
402  * @details: (transfer full): (allow-none): A GstStructure with details
403  *
404  * Create a new error message. The message will copy @error and
405  * @debug. This message is posted by element when a fatal event
406  * occurred. The pipeline will probably (partially) stop. The application
407  * receiving this message should stop the pipeline.
408  *
409  * Returns: (transfer full) (nullable): the new error message.
410  *
411  * Since: 1.10
412  */
413 GstMessage *
414 gst_message_new_error_with_details (GstObject * src, GError * error,
415     const gchar * debug, GstStructure * details)
416 {
417   GstMessage *message;
418   GstStructure *structure;
419
420   if (debug && !g_utf8_validate (debug, -1, NULL)) {
421     debug = NULL;
422     g_warning ("Trying to set debug field of error message, but "
423         "string is not valid UTF-8. Please file a bug.");
424   }
425
426   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
427       GST_QUARK (GERROR), G_TYPE_ERROR, error,
428       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
429   message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
430   if (details) {
431     GValue v = G_VALUE_INIT;
432
433     g_value_init (&v, GST_TYPE_STRUCTURE);
434     g_value_take_boxed (&v, details);
435     gst_structure_id_take_value (GST_MESSAGE_STRUCTURE (message), details_quark,
436         &v);
437   }
438
439   return message;
440 }
441
442 /**
443  * gst_message_new_error:
444  * @src: (transfer none) (allow-none): The object originating the message.
445  * @error: (transfer none): The GError for this message.
446  * @debug: A debugging string.
447  *
448  * Create a new error message. The message will copy @error and
449  * @debug. This message is posted by element when a fatal event
450  * occurred. The pipeline will probably (partially) stop. The application
451  * receiving this message should stop the pipeline.
452  *
453  * Returns: (transfer full): the new error message.
454  *
455  * MT safe.
456  */
457 GstMessage *
458 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
459 {
460   return gst_message_new_error_with_details (src, error, debug, NULL);
461 }
462
463 /**
464  * gst_message_parse_error_details:
465  * @message: The message object
466  * @structure: (transfer none) (out): A pointer to the returned details
467  *
468  * Returns the optional details structure, may be NULL if none.
469  * The returned structure must not be freed.
470  *
471  * Since: 1.10
472  */
473 void
474 gst_message_parse_error_details (GstMessage * message,
475     const GstStructure ** structure)
476 {
477   const GValue *v;
478
479   g_return_if_fail (GST_IS_MESSAGE (message));
480   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
481   g_return_if_fail (structure != NULL);
482
483   *structure = NULL;
484   v = gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (message),
485       details_quark);
486   if (v) {
487     *structure = g_value_get_boxed (v);
488   }
489 }
490
491 /**
492  * gst_message_new_warning_with_details:
493  * @src: (transfer none) (allow-none): The object originating the message.
494  * @error: (transfer none): The GError for this message.
495  * @debug: A debugging string.
496  * @details: (transfer full): (allow-none): A GstStructure with details
497  *
498  * Create a new warning message. The message will make copies of @error and
499  * @debug.
500  *
501  * Returns: (transfer full) (nullable): the new warning message.
502  *
503  * Since: 1.10
504  */
505 GstMessage *
506 gst_message_new_warning_with_details (GstObject * src, GError * error,
507     const gchar * debug, GstStructure * details)
508 {
509   GstMessage *message;
510   GstStructure *structure;
511
512   if (debug && !g_utf8_validate (debug, -1, NULL)) {
513     debug = NULL;
514     g_warning ("Trying to set debug field of warning message, but "
515         "string is not valid UTF-8. Please file a bug.");
516   }
517
518   structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
519       GST_QUARK (GERROR), G_TYPE_ERROR, error,
520       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
521   message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
522   if (details) {
523     GValue v = G_VALUE_INIT;
524
525     g_value_init (&v, GST_TYPE_STRUCTURE);
526     g_value_take_boxed (&v, details);
527     gst_structure_id_take_value (GST_MESSAGE_STRUCTURE (message), details_quark,
528         &v);
529   }
530
531   return message;
532 }
533
534 /**
535  * gst_message_new_warning:
536  * @src: (transfer none) (allow-none): The object originating the message.
537  * @error: (transfer none): The GError for this message.
538  * @debug: A debugging string.
539  *
540  * Create a new warning message. The message will make copies of @error and
541  * @debug.
542  *
543  * Returns: (transfer full): the new warning message.
544  *
545  * MT safe.
546  */
547 GstMessage *
548 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
549 {
550   return gst_message_new_warning_with_details (src, error, debug, NULL);
551 }
552
553 /**
554  * gst_message_parse_warning_details:
555  * @message: The message object
556  * @structure: (transfer none) (out): A pointer to the returned details structure
557  *
558  * Returns the optional details structure, may be NULL if none
559  * The returned structure must not be freed.
560  *
561  * Since: 1.10
562  */
563 void
564 gst_message_parse_warning_details (GstMessage * message,
565     const GstStructure ** structure)
566 {
567   const GValue *v;
568
569   g_return_if_fail (GST_IS_MESSAGE (message));
570   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
571   g_return_if_fail (structure != NULL);
572
573   *structure = NULL;
574   v = gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (message),
575       details_quark);
576   if (v) {
577     *structure = g_value_get_boxed (v);
578   }
579 }
580
581 /**
582  * gst_message_new_info_with_details:
583  * @src: (transfer none) (allow-none): The object originating the message.
584  * @error: (transfer none): The GError for this message.
585  * @debug: A debugging string.
586  * @details: (transfer full): (allow-none): A GstStructure with details
587  *
588  * Create a new info message. The message will make copies of @error and
589  * @debug.
590  *
591  * Returns: (transfer full) (nullable): the new warning message.
592  *
593  * Since: 1.10
594  */
595 GstMessage *
596 gst_message_new_info_with_details (GstObject * src, GError * error,
597     const gchar * debug, GstStructure * details)
598 {
599   GstMessage *message;
600   GstStructure *structure;
601
602   if (debug && !g_utf8_validate (debug, -1, NULL)) {
603     debug = NULL;
604     g_warning ("Trying to set debug field of info message, but "
605         "string is not valid UTF-8. Please file a bug.");
606   }
607
608   structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
609       GST_QUARK (GERROR), G_TYPE_ERROR, error,
610       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
611   message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
612   if (details) {
613     GValue v = G_VALUE_INIT;
614
615     g_value_init (&v, GST_TYPE_STRUCTURE);
616     g_value_take_boxed (&v, details);
617     gst_structure_id_take_value (GST_MESSAGE_STRUCTURE (message), details_quark,
618         &v);
619   }
620
621   return message;
622 }
623
624 /**
625  * gst_message_new_info:
626  * @src: (transfer none) (allow-none): The object originating the message.
627  * @error: (transfer none): The GError for this message.
628  * @debug: A debugging string.
629  *
630  * Create a new info message. The message will make copies of @error and
631  * @debug.
632  *
633  * Returns: (transfer full): the new info message.
634  *
635  * MT safe.
636  */
637 GstMessage *
638 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
639 {
640   return gst_message_new_info_with_details (src, error, debug, NULL);
641 }
642
643 /**
644  * gst_message_parse_info_details:
645  * @message: The message object
646  * @structure: (transfer none) (out): A pointer to the returned details structure
647  *
648  * Returns the optional details structure, may be NULL if none
649  * The returned structure must not be freed.
650  *
651  * Since: 1.10
652  */
653 void
654 gst_message_parse_info_details (GstMessage * message,
655     const GstStructure ** structure)
656 {
657   const GValue *v;
658
659   g_return_if_fail (GST_IS_MESSAGE (message));
660   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
661   g_return_if_fail (structure != NULL);
662
663   *structure = NULL;
664   v = gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (message),
665       details_quark);
666   if (v) {
667     *structure = g_value_get_boxed (v);
668   }
669 }
670
671 /**
672  * gst_message_new_tag:
673  * @src: (transfer none) (allow-none): The object originating the message.
674  * @tag_list: (transfer full): the tag list for the message.
675  *
676  * Create a new tag message. The message will take ownership of the tag list.
677  * The message is posted by elements that discovered a new taglist.
678  *
679  * Returns: (transfer full): the new tag message.
680  *
681  * MT safe.
682  */
683 GstMessage *
684 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
685 {
686   GstStructure *s;
687   GstMessage *message;
688   GValue val = G_VALUE_INIT;
689
690   g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
691
692   s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
693   g_value_init (&val, GST_TYPE_TAG_LIST);
694   g_value_take_boxed (&val, tag_list);
695   gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
696   message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
697   return message;
698 }
699
700 /**
701  * gst_message_new_buffering:
702  * @src: (transfer none) (allow-none): The object originating the message.
703  * @percent: The buffering percent
704  *
705  * Create a new buffering message. This message can be posted by an element that
706  * needs to buffer data before it can continue processing. @percent should be a
707  * value between 0 and 100. A value of 100 means that the buffering completed.
708  *
709  * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
710  * @percent is 100, the application can set the pipeline (back) to PLAYING.
711  * The application must be prepared to receive BUFFERING messages in the
712  * PREROLLING state and may only set the pipeline to PLAYING after receiving a
713  * message with @percent set to 100, which can happen after the pipeline
714  * completed prerolling.
715  *
716  * MT safe.
717  *
718  * Returns: (transfer full) (nullable): The new buffering message.
719  */
720 GstMessage *
721 gst_message_new_buffering (GstObject * src, gint percent)
722 {
723   GstMessage *message;
724   GstStructure *structure;
725   gint64 buffering_left;
726
727   g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
728
729   buffering_left = (percent == 100 ? 0 : -1);
730
731   structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
732       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
733       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
734       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
735       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
736       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
737   message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
738
739   return message;
740 }
741
742 /**
743  * gst_message_new_state_changed:
744  * @src: (transfer none) (allow-none): The object originating the message.
745  * @oldstate: the previous state
746  * @newstate: the new (current) state
747  * @pending: the pending (target) state
748  *
749  * Create a state change message. This message is posted whenever an element
750  * changed its state.
751  *
752  * Returns: (transfer full): the new state change message.
753  *
754  * MT safe.
755  */
756 GstMessage *
757 gst_message_new_state_changed (GstObject * src,
758     GstState oldstate, GstState newstate, GstState pending)
759 {
760   GstMessage *message;
761   GstStructure *structure;
762
763   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
764       GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
765       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
766       GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
767   message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
768
769   return message;
770 }
771
772 /**
773  * gst_message_new_state_dirty:
774  * @src: (transfer none) (allow-none): The object originating the message
775  *
776  * Create a state dirty message. This message is posted whenever an element
777  * changed its state asynchronously and is used internally to update the
778  * states of container objects.
779  *
780  * Returns: (transfer full): the new state dirty message.
781  *
782  * MT safe.
783  */
784 GstMessage *
785 gst_message_new_state_dirty (GstObject * src)
786 {
787   GstMessage *message;
788
789   message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
790
791   return message;
792 }
793
794 /**
795  * gst_message_new_clock_provide:
796  * @src: (transfer none) (allow-none): The object originating the message.
797  * @clock: (transfer none): the clock it provides
798  * @ready: %TRUE if the sender can provide a clock
799  *
800  * Create a clock provide message. This message is posted whenever an
801  * element is ready to provide a clock or lost its ability to provide
802  * a clock (maybe because it paused or became EOS).
803  *
804  * This message is mainly used internally to manage the clock
805  * selection.
806  *
807  * Returns: (transfer full): the new provide clock message.
808  *
809  * MT safe.
810  */
811 GstMessage *
812 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
813     gboolean ready)
814 {
815   GstMessage *message;
816   GstStructure *structure;
817
818   structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
819       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
820       GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
821   message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
822
823   return message;
824 }
825
826 /**
827  * gst_message_new_clock_lost:
828  * @src: (transfer none) (allow-none): The object originating the message.
829  * @clock: (transfer none): the clock that was lost
830  *
831  * Create a clock lost message. This message is posted whenever the
832  * clock is not valid anymore.
833  *
834  * If this message is posted by the pipeline, the pipeline will
835  * select a new clock again when it goes to PLAYING. It might therefore
836  * be needed to set the pipeline to PAUSED and PLAYING again.
837  *
838  * Returns: (transfer full): The new clock lost message.
839  *
840  * MT safe.
841  */
842 GstMessage *
843 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
844 {
845   GstMessage *message;
846   GstStructure *structure;
847
848   structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
849       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
850   message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
851
852   return message;
853 }
854
855 /**
856  * gst_message_new_new_clock:
857  * @src: (transfer none) (allow-none): The object originating the message.
858  * @clock: (transfer none): the new selected clock
859  *
860  * Create a new clock message. This message is posted whenever the
861  * pipeline selects a new clock for the pipeline.
862  *
863  * Returns: (transfer full): The new new clock message.
864  *
865  * MT safe.
866  */
867 GstMessage *
868 gst_message_new_new_clock (GstObject * src, GstClock * clock)
869 {
870   GstMessage *message;
871   GstStructure *structure;
872
873   structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
874       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
875   message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
876
877   return message;
878 }
879
880 /**
881  * gst_message_new_structure_change:
882  * @src: (transfer none) (allow-none): The object originating the message.
883  * @type: The change type.
884  * @owner: (transfer none): The owner element of @src.
885  * @busy: Whether the structure change is busy.
886  *
887  * Create a new structure change message. This message is posted when the
888  * structure of a pipeline is in the process of being changed, for example
889  * when pads are linked or unlinked.
890  *
891  * @src should be the sinkpad that unlinked or linked.
892  *
893  * Returns: (transfer full): the new structure change message.
894  *
895  * MT safe.
896  */
897 GstMessage *
898 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
899     GstElement * owner, gboolean busy)
900 {
901   GstMessage *message;
902   GstStructure *structure;
903
904   g_return_val_if_fail (GST_IS_PAD (src), NULL);
905   /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
906   g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
907
908   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
909       GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
910       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
911       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
912
913   message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
914       structure);
915
916   return message;
917 }
918
919 /**
920  * gst_message_new_segment_start:
921  * @src: (transfer none) (allow-none): The object originating the message.
922  * @format: The format of the position being played
923  * @position: The position of the segment being played
924  *
925  * Create a new segment message. This message is posted by elements that
926  * start playback of a segment as a result of a segment seek. This message
927  * is not received by the application but is used for maintenance reasons in
928  * container elements.
929  *
930  * Returns: (transfer full): the new segment start message.
931  *
932  * MT safe.
933  */
934 GstMessage *
935 gst_message_new_segment_start (GstObject * src, GstFormat format,
936     gint64 position)
937 {
938   GstMessage *message;
939   GstStructure *structure;
940
941   structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
942       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
943       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
944   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
945
946   return message;
947 }
948
949 /**
950  * gst_message_new_segment_done:
951  * @src: (transfer none) (allow-none): The object originating the message.
952  * @format: The format of the position being done
953  * @position: The position of the segment being done
954  *
955  * Create a new segment done message. This message is posted by elements that
956  * finish playback of a segment as a result of a segment seek. This message
957  * is received by the application after all elements that posted a segment_start
958  * have posted the segment_done.
959  *
960  * Returns: (transfer full): the new segment done message.
961  *
962  * MT safe.
963  */
964 GstMessage *
965 gst_message_new_segment_done (GstObject * src, GstFormat format,
966     gint64 position)
967 {
968   GstMessage *message;
969   GstStructure *structure;
970
971   structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
972       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
973       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
974   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
975
976   return message;
977 }
978
979 /**
980  * gst_message_new_application:
981  * @src: (transfer none) (allow-none): The object originating the message.
982  * @structure: (transfer full): the structure for the message. The message
983  *     will take ownership of the structure.
984  *
985  * Create a new application-typed message. GStreamer will never create these
986  * messages; they are a gift from us to you. Enjoy.
987  *
988  * Returns: (transfer full) (nullable): The new application message.
989  *
990  * MT safe.
991  */
992 GstMessage *
993 gst_message_new_application (GstObject * src, GstStructure * structure)
994 {
995   g_return_val_if_fail (structure != NULL, NULL);
996
997   return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
998 }
999
1000 /**
1001  * gst_message_new_element:
1002  * @src: (transfer none) (allow-none): The object originating the message.
1003  * @structure: (transfer full): The structure for the
1004  *     message. The message will take ownership of the structure.
1005  *
1006  * Create a new element-specific message. This is meant as a generic way of
1007  * allowing one-way communication from an element to an application, for example
1008  * "the firewire cable was unplugged". The format of the message should be
1009  * documented in the element's documentation. The structure field can be %NULL.
1010  *
1011  * Returns: (transfer full) (nullable): The new element message.
1012  *
1013  * MT safe.
1014  */
1015 GstMessage *
1016 gst_message_new_element (GstObject * src, GstStructure * structure)
1017 {
1018   g_return_val_if_fail (structure != NULL, NULL);
1019
1020   return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
1021 }
1022
1023 /**
1024  * gst_message_new_duration_changed:
1025  * @src: (transfer none) (allow-none): The object originating the message.
1026  *
1027  * Create a new duration changed message. This message is posted by elements
1028  * that know the duration of a stream when the duration changes. This message
1029  * is received by bins and is used to calculate the total duration of a
1030  * pipeline.
1031  *
1032  * Returns: (transfer full): The new duration-changed message.
1033  *
1034  * MT safe.
1035  */
1036 GstMessage *
1037 gst_message_new_duration_changed (GstObject * src)
1038 {
1039   GstMessage *message;
1040
1041   message = gst_message_new_custom (GST_MESSAGE_DURATION_CHANGED, src,
1042       gst_structure_new_id_empty (GST_QUARK (MESSAGE_DURATION_CHANGED)));
1043
1044   return message;
1045 }
1046
1047 /**
1048  * gst_message_new_async_start:
1049  * @src: (transfer none) (allow-none): The object originating the message.
1050  *
1051  * This message is posted by elements when they start an ASYNC state change.
1052  *
1053  * Returns: (transfer full): The new async_start message.
1054  *
1055  * MT safe.
1056  */
1057 GstMessage *
1058 gst_message_new_async_start (GstObject * src)
1059 {
1060   GstMessage *message;
1061
1062   message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
1063
1064   return message;
1065 }
1066
1067 /**
1068  * gst_message_new_async_done:
1069  * @src: (transfer none) (allow-none): The object originating the message.
1070  * @running_time: the desired running_time
1071  *
1072  * The message is posted when elements completed an ASYNC state change.
1073  * @running_time contains the time of the desired running_time when this
1074  * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
1075  * means that the element has no clock interaction and thus doesn't care about
1076  * the running_time of the pipeline.
1077  *
1078  * Returns: (transfer full): The new async_done message.
1079  *
1080  * MT safe.
1081  */
1082 GstMessage *
1083 gst_message_new_async_done (GstObject * src, GstClockTime running_time)
1084 {
1085   GstMessage *message;
1086   GstStructure *structure;
1087
1088   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
1089       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
1090   message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
1091
1092   return message;
1093 }
1094
1095 /**
1096  * gst_message_new_latency:
1097  * @src: (transfer none) (allow-none): The object originating the message.
1098  *
1099  * This message can be posted by elements when their latency requirements have
1100  * changed.
1101  *
1102  * Returns: (transfer full): The new latency message.
1103  *
1104  * MT safe.
1105  */
1106 GstMessage *
1107 gst_message_new_latency (GstObject * src)
1108 {
1109   GstMessage *message;
1110
1111   message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
1112
1113   return message;
1114 }
1115
1116 /**
1117  * gst_message_new_request_state:
1118  * @src: (transfer none) (allow-none): The object originating the message.
1119  * @state: The new requested state
1120  *
1121  * This message can be posted by elements when they want to have their state
1122  * changed. A typical use case would be an audio server that wants to pause the
1123  * pipeline because a higher priority stream is being played.
1124  *
1125  * Returns: (transfer full): the new request state message.
1126  *
1127  * MT safe.
1128  */
1129 GstMessage *
1130 gst_message_new_request_state (GstObject * src, GstState state)
1131 {
1132   GstMessage *message;
1133   GstStructure *structure;
1134
1135   structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
1136       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
1137   message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
1138
1139   return message;
1140 }
1141
1142 /**
1143  * gst_message_get_structure:
1144  * @message: The #GstMessage.
1145  *
1146  * Access the structure of the message.
1147  *
1148  * Returns: (transfer none) (nullable): The structure of the message. The
1149  * structure is still owned by the message, which means that you should not
1150  * free it and that the pointer becomes invalid when you free the message.
1151  *
1152  * MT safe.
1153  */
1154 const GstStructure *
1155 gst_message_get_structure (GstMessage * message)
1156 {
1157   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1158
1159   return GST_MESSAGE_STRUCTURE (message);
1160 }
1161
1162 /**
1163  * gst_message_writable_structure:
1164  * @message: The #GstMessage.
1165  *
1166  * Get a writable version of the structure.
1167  *
1168  * Returns: (transfer none): The structure of the message. The structure
1169  * is still owned by the message, which means that you should not free
1170  * it and that the pointer becomes invalid when you free the message.
1171  * This function checks if @message is writable and will never return
1172  * %NULL.
1173  *
1174  * MT safe.
1175  *
1176  * Since: 1.14
1177  */
1178 GstStructure *
1179 gst_message_writable_structure (GstMessage * message)
1180 {
1181   GstStructure *structure;
1182
1183   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1184   g_return_val_if_fail (gst_message_is_writable (message), NULL);
1185
1186   structure = GST_MESSAGE_STRUCTURE (message);
1187
1188   if (structure == NULL) {
1189     structure =
1190         gst_structure_new_id_empty (gst_message_type_to_quark (GST_MESSAGE_TYPE
1191             (message)));
1192     gst_structure_set_parent_refcount (structure,
1193         &message->mini_object.refcount);
1194     GST_MESSAGE_STRUCTURE (message) = structure;
1195   }
1196   return structure;
1197 }
1198
1199 /**
1200  * gst_message_has_name:
1201  * @message: The #GstMessage.
1202  * @name: name to check
1203  *
1204  * Checks if @message has the given @name. This function is usually used to
1205  * check the name of a custom message.
1206  *
1207  * Returns: %TRUE if @name matches the name of the message structure.
1208  */
1209 gboolean
1210 gst_message_has_name (GstMessage * message, const gchar * name)
1211 {
1212   GstStructure *structure;
1213
1214   g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
1215
1216   structure = GST_MESSAGE_STRUCTURE (message);
1217   if (structure == NULL)
1218     return FALSE;
1219
1220   return gst_structure_has_name (structure, name);
1221 }
1222
1223 /**
1224  * gst_message_parse_tag:
1225  * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
1226  * @tag_list: (out callee-allocates): return location for the tag-list.
1227  *
1228  * Extracts the tag list from the GstMessage. The tag list returned in the
1229  * output argument is a copy; the caller must free it when done.
1230  *
1231  * Typical usage of this function might be:
1232  * |[<!-- language="C" -->
1233  *   ...
1234  *   switch (GST_MESSAGE_TYPE (msg)) {
1235  *     case GST_MESSAGE_TAG: {
1236  *       GstTagList *tags = NULL;
1237  *
1238  *       gst_message_parse_tag (msg, &amp;tags);
1239  *       g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1240  *       handle_tags (tags);
1241  *       gst_tag_list_unref (tags);
1242  *       break;
1243  *     }
1244  *     ...
1245  *   }
1246  *   ...
1247  * ]|
1248  *
1249  * MT safe.
1250  */
1251 void
1252 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1253 {
1254   g_return_if_fail (GST_IS_MESSAGE (message));
1255   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1256   g_return_if_fail (tag_list != NULL);
1257
1258   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1259       GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
1260 }
1261
1262 /**
1263  * gst_message_parse_buffering:
1264  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1265  * @percent: (out) (allow-none): Return location for the percent.
1266  *
1267  * Extracts the buffering percent from the GstMessage. see also
1268  * gst_message_new_buffering().
1269  *
1270  * MT safe.
1271  */
1272 void
1273 gst_message_parse_buffering (GstMessage * message, gint * percent)
1274 {
1275   g_return_if_fail (GST_IS_MESSAGE (message));
1276   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1277
1278   if (percent)
1279     *percent =
1280         g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1281             (message), GST_QUARK (BUFFER_PERCENT)));
1282 }
1283
1284 /**
1285  * gst_message_set_buffering_stats:
1286  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1287  * @mode: a buffering mode
1288  * @avg_in: the average input rate
1289  * @avg_out: the average output rate
1290  * @buffering_left: amount of buffering time left in milliseconds
1291  *
1292  * Configures the buffering stats values in @message.
1293  */
1294 void
1295 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1296     gint avg_in, gint avg_out, gint64 buffering_left)
1297 {
1298   g_return_if_fail (GST_IS_MESSAGE (message));
1299   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1300
1301   gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1302       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1303       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1304       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1305       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1306 }
1307
1308 /**
1309  * gst_message_parse_buffering_stats:
1310  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1311  * @mode: (out) (allow-none): a buffering mode, or %NULL
1312  * @avg_in: (out) (allow-none): the average input rate, or %NULL
1313  * @avg_out: (out) (allow-none): the average output rate, or %NULL
1314  * @buffering_left: (out) (allow-none): amount of buffering time left in
1315  *     milliseconds, or %NULL
1316  *
1317  * Extracts the buffering stats values from @message.
1318  */
1319 void
1320 gst_message_parse_buffering_stats (GstMessage * message,
1321     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1322     gint64 * buffering_left)
1323 {
1324   GstStructure *structure;
1325
1326   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1327
1328   structure = GST_MESSAGE_STRUCTURE (message);
1329   if (mode)
1330     *mode = (GstBufferingMode)
1331         g_value_get_enum (gst_structure_id_get_value (structure,
1332             GST_QUARK (BUFFERING_MODE)));
1333   if (avg_in)
1334     *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1335             GST_QUARK (AVG_IN_RATE)));
1336   if (avg_out)
1337     *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1338             GST_QUARK (AVG_OUT_RATE)));
1339   if (buffering_left)
1340     *buffering_left =
1341         g_value_get_int64 (gst_structure_id_get_value (structure,
1342             GST_QUARK (BUFFERING_LEFT)));
1343 }
1344
1345 /**
1346  * gst_message_parse_state_changed:
1347  * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1348  * @oldstate: (out) (allow-none): the previous state, or %NULL
1349  * @newstate: (out) (allow-none): the new (current) state, or %NULL
1350  * @pending: (out) (allow-none): the pending (target) state, or %NULL
1351  *
1352  * Extracts the old and new states from the GstMessage.
1353  *
1354  * Typical usage of this function might be:
1355  * |[<!-- language="C" -->
1356  *   ...
1357  *   switch (GST_MESSAGE_TYPE (msg)) {
1358  *     case GST_MESSAGE_STATE_CHANGED: {
1359  *       GstState old_state, new_state;
1360  *
1361  *       gst_message_parse_state_changed (msg, &amp;old_state, &amp;new_state, NULL);
1362  *       g_print ("Element %s changed state from %s to %s.\n",
1363  *           GST_OBJECT_NAME (msg->src),
1364  *           gst_element_state_get_name (old_state),
1365  *           gst_element_state_get_name (new_state));
1366  *       break;
1367  *     }
1368  *     ...
1369  *   }
1370  *   ...
1371  * ]|
1372  *
1373  * MT safe.
1374  */
1375 void
1376 gst_message_parse_state_changed (GstMessage * message,
1377     GstState * oldstate, GstState * newstate, GstState * pending)
1378 {
1379   GstStructure *structure;
1380
1381   g_return_if_fail (GST_IS_MESSAGE (message));
1382   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1383
1384   structure = GST_MESSAGE_STRUCTURE (message);
1385   if (oldstate)
1386     *oldstate = (GstState)
1387         g_value_get_enum (gst_structure_id_get_value (structure,
1388             GST_QUARK (OLD_STATE)));
1389   if (newstate)
1390     *newstate = (GstState)
1391         g_value_get_enum (gst_structure_id_get_value (structure,
1392             GST_QUARK (NEW_STATE)));
1393   if (pending)
1394     *pending = (GstState)
1395         g_value_get_enum (gst_structure_id_get_value (structure,
1396             GST_QUARK (PENDING_STATE)));
1397 }
1398
1399 /**
1400  * gst_message_parse_clock_provide:
1401  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1402  * @clock: (out) (allow-none) (transfer none): a pointer to  hold a clock
1403  *     object, or %NULL
1404  * @ready: (out) (allow-none): a pointer to hold the ready flag, or %NULL
1405  *
1406  * Extracts the clock and ready flag from the GstMessage.
1407  * The clock object returned remains valid until the message is freed.
1408  *
1409  * MT safe.
1410  */
1411 void
1412 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1413     gboolean * ready)
1414 {
1415   const GValue *clock_gvalue;
1416   GstStructure *structure;
1417
1418   g_return_if_fail (GST_IS_MESSAGE (message));
1419   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1420
1421   structure = GST_MESSAGE_STRUCTURE (message);
1422   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1423   g_return_if_fail (clock_gvalue != NULL);
1424   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1425
1426   if (ready)
1427     *ready =
1428         g_value_get_boolean (gst_structure_id_get_value (structure,
1429             GST_QUARK (READY)));
1430   if (clock)
1431     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1432 }
1433
1434 /**
1435  * gst_message_parse_clock_lost:
1436  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1437  * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1438  *
1439  * Extracts the lost clock from the GstMessage.
1440  * The clock object returned remains valid until the message is freed.
1441  *
1442  * MT safe.
1443  */
1444 void
1445 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1446 {
1447   const GValue *clock_gvalue;
1448   GstStructure *structure;
1449
1450   g_return_if_fail (GST_IS_MESSAGE (message));
1451   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1452
1453   structure = GST_MESSAGE_STRUCTURE (message);
1454   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1455   g_return_if_fail (clock_gvalue != NULL);
1456   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1457
1458   if (clock)
1459     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1460 }
1461
1462 /**
1463  * gst_message_parse_new_clock:
1464  * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1465  * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1466  *     new clock
1467  *
1468  * Extracts the new clock from the GstMessage.
1469  * The clock object returned remains valid until the message is freed.
1470  *
1471  * MT safe.
1472  */
1473 void
1474 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1475 {
1476   const GValue *clock_gvalue;
1477   GstStructure *structure;
1478
1479   g_return_if_fail (GST_IS_MESSAGE (message));
1480   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1481
1482   structure = GST_MESSAGE_STRUCTURE (message);
1483   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1484   g_return_if_fail (clock_gvalue != NULL);
1485   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1486
1487   if (clock)
1488     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1489 }
1490
1491 /**
1492  * gst_message_parse_structure_change:
1493  * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1494  * @type: (out): A pointer to hold the change type
1495  * @owner: (out) (allow-none) (transfer none): The owner element of the
1496  *     message source
1497  * @busy: (out) (allow-none): a pointer to hold whether the change is in
1498  *     progress or has been completed
1499  *
1500  * Extracts the change type and completion status from the GstMessage.
1501  *
1502  * MT safe.
1503  */
1504 void
1505 gst_message_parse_structure_change (GstMessage * message,
1506     GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1507 {
1508   const GValue *owner_gvalue;
1509   GstStructure *structure;
1510
1511   g_return_if_fail (GST_IS_MESSAGE (message));
1512   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1513
1514   structure = GST_MESSAGE_STRUCTURE (message);
1515   owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1516   g_return_if_fail (owner_gvalue != NULL);
1517   g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1518
1519   if (type)
1520     *type = (GstStructureChangeType)
1521         g_value_get_enum (gst_structure_id_get_value (structure,
1522             GST_QUARK (TYPE)));
1523   if (owner)
1524     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1525   if (busy)
1526     *busy =
1527         g_value_get_boolean (gst_structure_id_get_value (structure,
1528             GST_QUARK (BUSY)));
1529 }
1530
1531 /**
1532  * gst_message_parse_error:
1533  * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1534  * @gerror: (out) (allow-none) (transfer full): location for the GError
1535  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1536  *     or %NULL
1537  *
1538  * Extracts the GError and debug string from the GstMessage. The values returned
1539  * in the output arguments are copies; the caller must free them when done.
1540  *
1541  * Typical usage of this function might be:
1542  * |[<!-- language="C" -->
1543  *   ...
1544  *   switch (GST_MESSAGE_TYPE (msg)) {
1545  *     case GST_MESSAGE_ERROR: {
1546  *       GError *err = NULL;
1547  *       gchar *dbg_info = NULL;
1548  *
1549  *       gst_message_parse_error (msg, &amp;err, &amp;dbg_info);
1550  *       g_printerr ("ERROR from element %s: %s\n",
1551  *           GST_OBJECT_NAME (msg->src), err->message);
1552  *       g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1553  *       g_error_free (err);
1554  *       g_free (dbg_info);
1555  *       break;
1556  *     }
1557  *     ...
1558  *   }
1559  *   ...
1560  * ]|
1561  *
1562  * MT safe.
1563  */
1564 void
1565 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1566 {
1567   g_return_if_fail (GST_IS_MESSAGE (message));
1568   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1569
1570   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1571       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1572       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1573 }
1574
1575 /**
1576  * gst_message_parse_warning:
1577  * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1578  * @gerror: (out) (allow-none) (transfer full): location for the GError
1579  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1580  *     or %NULL
1581  *
1582  * Extracts the GError and debug string from the GstMessage. The values returned
1583  * in the output arguments are copies; the caller must free them when done.
1584  *
1585  * MT safe.
1586  */
1587 void
1588 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1589     gchar ** debug)
1590 {
1591   g_return_if_fail (GST_IS_MESSAGE (message));
1592   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1593
1594   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1595       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1596       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1597 }
1598
1599 /**
1600  * gst_message_parse_info:
1601  * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1602  * @gerror: (out) (allow-none) (transfer full): location for the GError
1603  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1604  *     or %NULL
1605  *
1606  * Extracts the GError and debug string from the GstMessage. The values returned
1607  * in the output arguments are copies; the caller must free them when done.
1608  *
1609  * MT safe.
1610  */
1611 void
1612 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1613 {
1614   g_return_if_fail (GST_IS_MESSAGE (message));
1615   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1616
1617   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1618       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1619       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1620 }
1621
1622 /**
1623  * gst_message_parse_segment_start:
1624  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1625  * @format: (out) (allow-none): Result location for the format, or %NULL
1626  * @position: (out) (allow-none): Result location for the position, or %NULL
1627  *
1628  * Extracts the position and format from the segment start message.
1629  *
1630  * MT safe.
1631  */
1632 void
1633 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1634     gint64 * position)
1635 {
1636   GstStructure *structure;
1637
1638   g_return_if_fail (GST_IS_MESSAGE (message));
1639   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1640
1641   structure = GST_MESSAGE_STRUCTURE (message);
1642   if (format)
1643     *format = (GstFormat)
1644         g_value_get_enum (gst_structure_id_get_value (structure,
1645             GST_QUARK (FORMAT)));
1646   if (position)
1647     *position =
1648         g_value_get_int64 (gst_structure_id_get_value (structure,
1649             GST_QUARK (POSITION)));
1650 }
1651
1652 /**
1653  * gst_message_parse_segment_done:
1654  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1655  * @format: (out) (allow-none): Result location for the format, or %NULL
1656  * @position: (out) (allow-none): Result location for the position, or %NULL
1657  *
1658  * Extracts the position and format from the segment done message.
1659  *
1660  * MT safe.
1661  */
1662 void
1663 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1664     gint64 * position)
1665 {
1666   GstStructure *structure;
1667
1668   g_return_if_fail (GST_IS_MESSAGE (message));
1669   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1670
1671   structure = GST_MESSAGE_STRUCTURE (message);
1672   if (format)
1673     *format = (GstFormat)
1674         g_value_get_enum (gst_structure_id_get_value (structure,
1675             GST_QUARK (FORMAT)));
1676   if (position)
1677     *position =
1678         g_value_get_int64 (gst_structure_id_get_value (structure,
1679             GST_QUARK (POSITION)));
1680 }
1681
1682 /**
1683  * gst_message_parse_async_done:
1684  * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1685  * @running_time: (out) (allow-none): Result location for the running_time or %NULL
1686  *
1687  * Extract the running_time from the async_done message.
1688  *
1689  * MT safe.
1690  */
1691 void
1692 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
1693 {
1694   GstStructure *structure;
1695
1696   g_return_if_fail (GST_IS_MESSAGE (message));
1697   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1698
1699   structure = GST_MESSAGE_STRUCTURE (message);
1700   if (running_time)
1701     *running_time =
1702         g_value_get_uint64 (gst_structure_id_get_value (structure,
1703             GST_QUARK (RUNNING_TIME)));
1704 }
1705
1706 /**
1707  * gst_message_parse_request_state:
1708  * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1709  * @state: (out) (allow-none): Result location for the requested state or %NULL
1710  *
1711  * Extract the requested state from the request_state message.
1712  *
1713  * MT safe.
1714  */
1715 void
1716 gst_message_parse_request_state (GstMessage * message, GstState * state)
1717 {
1718   GstStructure *structure;
1719
1720   g_return_if_fail (GST_IS_MESSAGE (message));
1721   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1722
1723   structure = GST_MESSAGE_STRUCTURE (message);
1724   if (state)
1725     *state = (GstState)
1726         g_value_get_enum (gst_structure_id_get_value (structure,
1727             GST_QUARK (NEW_STATE)));
1728 }
1729
1730 /**
1731  * gst_message_new_stream_status:
1732  * @src: The object originating the message.
1733  * @type: The stream status type.
1734  * @owner: (transfer none): the owner element of @src.
1735  *
1736  * Create a new stream status message. This message is posted when a streaming
1737  * thread is created/destroyed or when the state changed.
1738  *
1739  * Returns: (transfer full): the new stream status message.
1740  *
1741  * MT safe.
1742  */
1743 GstMessage *
1744 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1745     GstElement * owner)
1746 {
1747   GstMessage *message;
1748   GstStructure *structure;
1749
1750   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1751       GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1752       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1753   message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1754
1755   return message;
1756 }
1757
1758 /**
1759  * gst_message_parse_stream_status:
1760  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1761  * @type: (out): A pointer to hold the status type
1762  * @owner: (out) (transfer none): The owner element of the message source
1763  *
1764  * Extracts the stream status type and owner the GstMessage. The returned
1765  * owner remains valid for as long as the reference to @message is valid and
1766  * should thus not be unreffed.
1767  *
1768  * MT safe.
1769  */
1770 void
1771 gst_message_parse_stream_status (GstMessage * message,
1772     GstStreamStatusType * type, GstElement ** owner)
1773 {
1774   const GValue *owner_gvalue;
1775   GstStructure *structure;
1776
1777   g_return_if_fail (GST_IS_MESSAGE (message));
1778   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1779
1780   structure = GST_MESSAGE_STRUCTURE (message);
1781   owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1782   g_return_if_fail (owner_gvalue != NULL);
1783
1784   if (type)
1785     *type = (GstStreamStatusType)
1786         g_value_get_enum (gst_structure_id_get_value (structure,
1787             GST_QUARK (TYPE)));
1788   if (owner)
1789     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1790 }
1791
1792 /**
1793  * gst_message_set_stream_status_object:
1794  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1795  * @object: the object controlling the streaming
1796  *
1797  * Configures the object handling the streaming thread. This is usually a
1798  * GstTask object but other objects might be added in the future.
1799  */
1800 void
1801 gst_message_set_stream_status_object (GstMessage * message,
1802     const GValue * object)
1803 {
1804   GstStructure *structure;
1805
1806   g_return_if_fail (GST_IS_MESSAGE (message));
1807   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1808
1809   structure = GST_MESSAGE_STRUCTURE (message);
1810   gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
1811 }
1812
1813 /**
1814  * gst_message_get_stream_status_object:
1815  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1816  *
1817  * Extracts the object managing the streaming thread from @message.
1818  *
1819  * Returns: (nullable): a GValue containing the object that manages the
1820  * streaming thread. This object is usually of type GstTask but other types can
1821  * be added in the future. The object remains valid as long as @message is
1822  * valid.
1823  */
1824 const GValue *
1825 gst_message_get_stream_status_object (GstMessage * message)
1826 {
1827   const GValue *result;
1828   GstStructure *structure;
1829
1830   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1831   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1832       NULL);
1833
1834   structure = GST_MESSAGE_STRUCTURE (message);
1835   result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1836
1837   return result;
1838 }
1839
1840 /**
1841  * gst_message_new_step_done:
1842  * @src: The object originating the message.
1843  * @format: the format of @amount
1844  * @amount: the amount of stepped data
1845  * @rate: the rate of the stepped amount
1846  * @flush: is this an flushing step
1847  * @intermediate: is this an intermediate step
1848  * @duration: the duration of the data
1849  * @eos: the step caused EOS
1850  *
1851  * This message is posted by elements when they complete a part, when @intermediate set
1852  * to %TRUE, or a complete step operation.
1853  *
1854  * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1855  * @amount of media in format @format.
1856  *
1857  * Returns: (transfer full): the new step_done message.
1858  *
1859  * MT safe.
1860  */
1861 GstMessage *
1862 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1863     gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1864     gboolean eos)
1865 {
1866   GstMessage *message;
1867   GstStructure *structure;
1868
1869   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
1870       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1871       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1872       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1873       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1874       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1875       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1876       GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1877   message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1878
1879   return message;
1880 }
1881
1882 /**
1883  * gst_message_parse_step_done:
1884  * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1885  * @format: (out) (allow-none): result location for the format
1886  * @amount: (out) (allow-none): result location for the amount
1887  * @rate: (out) (allow-none): result location for the rate
1888  * @flush: (out) (allow-none): result location for the flush flag
1889  * @intermediate: (out) (allow-none): result location for the intermediate flag
1890  * @duration: (out) (allow-none): result location for the duration
1891  * @eos: (out) (allow-none): result location for the EOS flag
1892  *
1893  * Extract the values the step_done message.
1894  *
1895  * MT safe.
1896  */
1897 void
1898 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1899     guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1900     guint64 * duration, gboolean * eos)
1901 {
1902   GstStructure *structure;
1903
1904   g_return_if_fail (GST_IS_MESSAGE (message));
1905   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1906
1907   structure = GST_MESSAGE_STRUCTURE (message);
1908   gst_structure_id_get (structure,
1909       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1910       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1911       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1912       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1913       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1914       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1915       GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1916 }
1917
1918 /**
1919  * gst_message_new_step_start:
1920  * @src: The object originating the message.
1921  * @active: if the step is active or queued
1922  * @format: the format of @amount
1923  * @amount: the amount of stepped data
1924  * @rate: the rate of the stepped amount
1925  * @flush: is this an flushing step
1926  * @intermediate: is this an intermediate step
1927  *
1928  * This message is posted by elements when they accept or activate a new step
1929  * event for @amount in @format.
1930  *
1931  * @active is set to %FALSE when the element accepted the new step event and has
1932  * queued it for execution in the streaming threads.
1933  *
1934  * @active is set to %TRUE when the element has activated the step operation and
1935  * is now ready to start executing the step in the streaming thread. After this
1936  * message is emitted, the application can queue a new step operation in the
1937  * element.
1938  *
1939  * Returns: (transfer full): The new step_start message.
1940  *
1941  * MT safe.
1942  */
1943 GstMessage *
1944 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1945     guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1946 {
1947   GstMessage *message;
1948   GstStructure *structure;
1949
1950   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
1951       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1952       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1953       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1954       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1955       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1956       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1957   message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1958
1959   return message;
1960 }
1961
1962 /**
1963  * gst_message_parse_step_start:
1964  * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1965  * @active: (out) (allow-none): result location for the active flag
1966  * @format: (out) (allow-none): result location for the format
1967  * @amount: (out) (allow-none): result location for the amount
1968  * @rate: (out) (allow-none): result location for the rate
1969  * @flush: (out) (allow-none): result location for the flush flag
1970  * @intermediate: (out) (allow-none): result location for the intermediate flag
1971  *
1972  * Extract the values from step_start message.
1973  *
1974  * MT safe.
1975  */
1976 void
1977 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1978     GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1979     gboolean * intermediate)
1980 {
1981   GstStructure *structure;
1982
1983   g_return_if_fail (GST_IS_MESSAGE (message));
1984   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1985
1986   structure = GST_MESSAGE_STRUCTURE (message);
1987   gst_structure_id_get (structure,
1988       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1989       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1990       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1991       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1992       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1993       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1994 }
1995
1996 /**
1997  * gst_message_new_qos:
1998  * @src: The object originating the message.
1999  * @live: if the message was generated by a live element
2000  * @running_time: the running time of the buffer that generated the message
2001  * @stream_time: the stream time of the buffer that generated the message
2002  * @timestamp: the timestamps of the buffer that generated the message
2003  * @duration: the duration of the buffer that generated the message
2004  *
2005  * A QOS message is posted on the bus whenever an element decides to drop a
2006  * buffer because of QoS reasons or whenever it changes its processing strategy
2007  * because of QoS reasons (quality adjustments such as processing at lower
2008  * accuracy).
2009  *
2010  * This message can be posted by an element that performs synchronisation against the
2011  * clock (live) or it could be dropped by an element that performs QoS because of QOS
2012  * events received from a downstream element (!live).
2013  *
2014  * @running_time, @stream_time, @timestamp, @duration should be set to the
2015  * respective running-time, stream-time, timestamp and duration of the (dropped)
2016  * buffer that generated the QoS event. Values can be left to
2017  * GST_CLOCK_TIME_NONE when unknown.
2018  *
2019  * Returns: (transfer full): The new qos message.
2020  *
2021  * MT safe.
2022  */
2023 GstMessage *
2024 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
2025     guint64 stream_time, guint64 timestamp, guint64 duration)
2026 {
2027   GstMessage *message;
2028   GstStructure *structure;
2029
2030   structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
2031       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2032       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2033       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2034       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2035       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
2036       GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
2037       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
2038       GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
2039       GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
2040       GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
2041       GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
2042   message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
2043
2044   return message;
2045 }
2046
2047 /**
2048  * gst_message_set_qos_values:
2049  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2050  * @jitter: The difference of the running-time against the deadline.
2051  * @proportion: Long term prediction of the ideal rate relative to normal rate
2052  * to get optimal quality.
2053  * @quality: An element dependent integer value that specifies the current
2054  * quality level of the element. The default maximum quality is 1000000.
2055  *
2056  * Set the QoS values that have been calculated/analysed from the QoS data
2057  *
2058  * MT safe.
2059  */
2060 void
2061 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
2062     gdouble proportion, gint quality)
2063 {
2064   GstStructure *structure;
2065
2066   g_return_if_fail (GST_IS_MESSAGE (message));
2067   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2068
2069   structure = GST_MESSAGE_STRUCTURE (message);
2070   gst_structure_id_set (structure,
2071       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2072       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2073       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2074 }
2075
2076 /**
2077  * gst_message_set_qos_stats:
2078  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2079  * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
2080  * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
2081  * will likely use GST_FORMAT_DEFAULT (samples).
2082  * @processed: Total number of units correctly processed since the last state
2083  * change to READY or a flushing operation.
2084  * @dropped: Total number of units dropped since the last state change to READY
2085  * or a flushing operation.
2086  *
2087  * Set the QoS stats representing the history of the current continuous pipeline
2088  * playback period.
2089  *
2090  * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2091  * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2092  *
2093  * MT safe.
2094  */
2095 void
2096 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
2097     guint64 processed, guint64 dropped)
2098 {
2099   GstStructure *structure;
2100
2101   g_return_if_fail (GST_IS_MESSAGE (message));
2102   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2103
2104   structure = GST_MESSAGE_STRUCTURE (message);
2105   gst_structure_id_set (structure,
2106       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2107       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2108       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2109 }
2110
2111 /**
2112  * gst_message_parse_qos:
2113  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2114  * @live: (out) (allow-none): if the message was generated by a live element
2115  * @running_time: (out) (allow-none): the running time of the buffer that
2116  *     generated the message
2117  * @stream_time: (out) (allow-none): the stream time of the buffer that
2118  *     generated the message
2119  * @timestamp: (out) (allow-none): the timestamps of the buffer that
2120  *     generated the message
2121  * @duration: (out) (allow-none): the duration of the buffer that
2122  *     generated the message
2123  *
2124  * Extract the timestamps and live status from the QoS message.
2125  *
2126  * The returned values give the running_time, stream_time, timestamp and
2127  * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2128  * values.
2129  *
2130  * MT safe.
2131  */
2132 void
2133 gst_message_parse_qos (GstMessage * message, gboolean * live,
2134     guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2135     guint64 * duration)
2136 {
2137   GstStructure *structure;
2138
2139   g_return_if_fail (GST_IS_MESSAGE (message));
2140   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2141
2142   structure = GST_MESSAGE_STRUCTURE (message);
2143   gst_structure_id_get (structure,
2144       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2145       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2146       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2147       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2148       GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2149 }
2150
2151 /**
2152  * gst_message_parse_qos_values:
2153  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2154  * @jitter: (out) (allow-none): The difference of the running-time against
2155  *     the deadline.
2156  * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2157  *     relative to normal rate to get optimal quality.
2158  * @quality: (out) (allow-none): An element dependent integer value that
2159  *     specifies the current quality level of the element. The default
2160  *     maximum quality is 1000000.
2161  *
2162  * Extract the QoS values that have been calculated/analysed from the QoS data
2163  *
2164  * MT safe.
2165  */
2166 void
2167 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2168     gdouble * proportion, gint * quality)
2169 {
2170   GstStructure *structure;
2171
2172   g_return_if_fail (GST_IS_MESSAGE (message));
2173   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2174
2175   structure = GST_MESSAGE_STRUCTURE (message);
2176   gst_structure_id_get (structure,
2177       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2178       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2179       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2180 }
2181
2182 /**
2183  * gst_message_parse_qos_stats:
2184  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2185  * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2186  *     Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2187  *     Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2188  *     (samples).
2189  * @processed: (out) (allow-none): Total number of units correctly processed
2190  *     since the last state change to READY or a flushing operation.
2191  * @dropped: (out) (allow-none): Total number of units dropped since the last
2192  *     state change to READY or a flushing operation.
2193  *
2194  * Extract the QoS stats representing the history of the current continuous
2195  * pipeline playback period.
2196  *
2197  * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2198  * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2199  *
2200  * MT safe.
2201  */
2202 void
2203 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2204     guint64 * processed, guint64 * dropped)
2205 {
2206   GstStructure *structure;
2207
2208   g_return_if_fail (GST_IS_MESSAGE (message));
2209   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2210
2211   structure = GST_MESSAGE_STRUCTURE (message);
2212   gst_structure_id_get (structure,
2213       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2214       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2215       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2216 }
2217
2218 /**
2219  * gst_message_new_progress:
2220  * @src: The object originating the message.
2221  * @type: a #GstProgressType
2222  * @code: a progress code
2223  * @text: free, user visible text describing the progress
2224  *
2225  * Progress messages are posted by elements when they use an asynchronous task
2226  * to perform actions triggered by a state change.
2227  *
2228  * @code contains a well defined string describing the action.
2229  * @text should contain a user visible string detailing the current action.
2230  *
2231  * Returns: (transfer full) (nullable): The new qos message.
2232  */
2233 GstMessage *
2234 gst_message_new_progress (GstObject * src, GstProgressType type,
2235     const gchar * code, const gchar * text)
2236 {
2237   GstMessage *message;
2238   GstStructure *structure;
2239   gint percent = 100, timeout = -1;
2240
2241   g_return_val_if_fail (code != NULL, NULL);
2242   g_return_val_if_fail (text != NULL, NULL);
2243
2244   if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2245     percent = 0;
2246
2247   structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2248       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2249       GST_QUARK (CODE), G_TYPE_STRING, code,
2250       GST_QUARK (TEXT), G_TYPE_STRING, text,
2251       GST_QUARK (PERCENT), G_TYPE_INT, percent,
2252       GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2253   message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2254
2255   return message;
2256 }
2257
2258 /**
2259  * gst_message_parse_progress:
2260  * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2261  * @type: (out) (allow-none): location for the type
2262  * @code: (out) (allow-none) (transfer full): location for the code
2263  * @text: (out) (allow-none) (transfer full): location for the text
2264  *
2265  * Parses the progress @type, @code and @text.
2266  */
2267 void
2268 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2269     gchar ** code, gchar ** text)
2270 {
2271   GstStructure *structure;
2272
2273   g_return_if_fail (GST_IS_MESSAGE (message));
2274   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2275
2276   structure = GST_MESSAGE_STRUCTURE (message);
2277   gst_structure_id_get (structure,
2278       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2279       GST_QUARK (CODE), G_TYPE_STRING, code,
2280       GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2281 }
2282
2283 /**
2284  * gst_message_new_toc:
2285  * @src: the object originating the message.
2286  * @toc: (transfer none): #GstToc structure for the message.
2287  * @updated: whether TOC was updated or not.
2288  *
2289  * Create a new TOC message. The message is posted by elements
2290  * that discovered or updated a TOC.
2291  *
2292  * Returns: (transfer full): a new TOC message.
2293  *
2294  * MT safe.
2295  */
2296 GstMessage *
2297 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2298 {
2299   GstStructure *toc_struct;
2300
2301   g_return_val_if_fail (toc != NULL, NULL);
2302
2303   toc_struct = gst_structure_new_id (GST_QUARK (MESSAGE_TOC),
2304       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2305       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2306
2307   return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2308 }
2309
2310 /**
2311  * gst_message_parse_toc:
2312  * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2313  * @toc: (out) (transfer full): return location for the TOC.
2314  * @updated: (out): return location for the updated flag.
2315  *
2316  * Extract the TOC from the #GstMessage. The TOC returned in the
2317  * output argument is a copy; the caller must free it with
2318  * gst_toc_unref() when done.
2319  *
2320  * MT safe.
2321  */
2322 void
2323 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2324 {
2325   g_return_if_fail (GST_IS_MESSAGE (message));
2326   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2327   g_return_if_fail (toc != NULL);
2328
2329   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2330       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2331       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2332 }
2333
2334 /**
2335  * gst_message_new_reset_time:
2336  * @src: (transfer none) (allow-none): The object originating the message.
2337  * @running_time: the requested running-time
2338  *
2339  * This message is posted when the pipeline running-time should be reset to
2340  * @running_time, like after a flushing seek.
2341  *
2342  * Returns: (transfer full): The new reset_time message.
2343  *
2344  * MT safe.
2345  */
2346 GstMessage *
2347 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2348 {
2349   GstMessage *message;
2350   GstStructure *structure;
2351
2352   structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2353       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2354   message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2355
2356   return message;
2357 }
2358
2359 /**
2360  * gst_message_parse_reset_time:
2361  * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2362  * @running_time: (out) (allow-none): Result location for the running_time or
2363  *      %NULL
2364  *
2365  * Extract the running-time from the RESET_TIME message.
2366  *
2367  * MT safe.
2368  */
2369 void
2370 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2371 {
2372   GstStructure *structure;
2373
2374   g_return_if_fail (GST_IS_MESSAGE (message));
2375   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2376
2377   structure = GST_MESSAGE_STRUCTURE (message);
2378   if (running_time)
2379     *running_time =
2380         g_value_get_uint64 (gst_structure_id_get_value (structure,
2381             GST_QUARK (RUNNING_TIME)));
2382 }
2383
2384 /**
2385  * gst_message_new_stream_start:
2386  * @src: (transfer none) (allow-none): The object originating the message.
2387  *
2388  * Create a new stream_start message. This message is generated and posted in
2389  * the sink elements of a GstBin. The bin will only forward the STREAM_START
2390  * message to the application if all sinks have posted an STREAM_START message.
2391  *
2392  * Returns: (transfer full): The new stream_start message.
2393  *
2394  * MT safe.
2395  */
2396 GstMessage *
2397 gst_message_new_stream_start (GstObject * src)
2398 {
2399   GstMessage *message;
2400   GstStructure *s;
2401
2402   s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_STREAM_START));
2403   message = gst_message_new_custom (GST_MESSAGE_STREAM_START, src, s);
2404
2405   return message;
2406 }
2407
2408
2409 /**
2410  * gst_message_set_group_id:
2411  * @message: the message
2412  * @group_id: the group id
2413  *
2414  * Sets the group id on the stream-start message.
2415  *
2416  * All streams that have the same group id are supposed to be played
2417  * together, i.e. all streams inside a container file should have the
2418  * same group id but different stream ids. The group id should change
2419  * each time the stream is started, resulting in different group ids
2420  * each time a file is played for example.
2421  *
2422  * MT safe.
2423  *
2424  * Since: 1.2
2425  */
2426 void
2427 gst_message_set_group_id (GstMessage * message, guint group_id)
2428 {
2429   GstStructure *structure;
2430
2431   g_return_if_fail (GST_IS_MESSAGE (message));
2432   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START);
2433   g_return_if_fail (gst_message_is_writable (message));
2434
2435   structure = GST_MESSAGE_STRUCTURE (message);
2436   gst_structure_id_set (structure, GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id,
2437       NULL);
2438 }
2439
2440 /**
2441  * gst_message_parse_group_id:
2442  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_START.
2443  * @group_id: (out) (allow-none): Result location for the group id or
2444  *      %NULL
2445  *
2446  * Extract the group from the STREAM_START message.
2447  *
2448  * Returns: %TRUE if the message had a group id set, %FALSE otherwise
2449  *
2450  * MT safe.
2451  *
2452  * Since: 1.2
2453  */
2454 gboolean
2455 gst_message_parse_group_id (GstMessage * message, guint * group_id)
2456 {
2457   GstStructure *structure;
2458   const GValue *v;
2459
2460   g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
2461   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START,
2462       FALSE);
2463
2464   if (!group_id)
2465     return TRUE;
2466
2467   structure = GST_MESSAGE_STRUCTURE (message);
2468
2469   v = gst_structure_id_get_value (structure, GST_QUARK (GROUP_ID));
2470   if (!v)
2471     return FALSE;
2472
2473   *group_id = g_value_get_uint (v);
2474   return TRUE;
2475 }
2476
2477 /**
2478  * gst_message_new_need_context:
2479  * @src: (transfer none) (allow-none): The object originating the message.
2480  * @context_type: The context type that is needed
2481  *
2482  * This message is posted when an element needs a specific #GstContext.
2483  *
2484  * Returns: (transfer full): The new need-context message.
2485  *
2486  * MT safe.
2487  *
2488  * Since: 1.2
2489  */
2490 GstMessage *
2491 gst_message_new_need_context (GstObject * src, const gchar * context_type)
2492 {
2493   GstMessage *message;
2494   GstStructure *structure;
2495
2496   g_return_val_if_fail (context_type != NULL, NULL);
2497
2498   structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEED_CONTEXT),
2499       GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2500   message = gst_message_new_custom (GST_MESSAGE_NEED_CONTEXT, src, structure);
2501
2502   return message;
2503 }
2504
2505 /**
2506  * gst_message_parse_context_type:
2507  * @message: a GST_MESSAGE_NEED_CONTEXT type message
2508  * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2509  *
2510  * Parse a context type from an existing GST_MESSAGE_NEED_CONTEXT message.
2511  *
2512  * Returns: a #gboolean indicating if the parsing succeeded.
2513  *
2514  * Since: 1.2
2515  */
2516 gboolean
2517 gst_message_parse_context_type (GstMessage * message,
2518     const gchar ** context_type)
2519 {
2520   GstStructure *structure;
2521   const GValue *value;
2522
2523   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT,
2524       FALSE);
2525
2526   structure = GST_MESSAGE_STRUCTURE (message);
2527
2528   if (context_type) {
2529     value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2530     *context_type = g_value_get_string (value);
2531   }
2532
2533   return TRUE;
2534 }
2535
2536 /**
2537  * gst_message_new_have_context:
2538  * @src: (transfer none) (allow-none): The object originating the message.
2539  * @context: (transfer full): the context
2540  *
2541  * This message is posted when an element has a new local #GstContext.
2542  *
2543  * Returns: (transfer full): The new have-context message.
2544  *
2545  * MT safe.
2546  *
2547  * Since: 1.2
2548  */
2549 GstMessage *
2550 gst_message_new_have_context (GstObject * src, GstContext * context)
2551 {
2552   GstMessage *message;
2553   GstStructure *structure;
2554
2555   structure = gst_structure_new_id (GST_QUARK (MESSAGE_HAVE_CONTEXT),
2556       GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2557   message = gst_message_new_custom (GST_MESSAGE_HAVE_CONTEXT, src, structure);
2558   gst_context_unref (context);
2559
2560   return message;
2561 }
2562
2563 /**
2564  * gst_message_parse_have_context:
2565  * @message: A valid #GstMessage of type GST_MESSAGE_HAVE_CONTEXT.
2566  * @context: (out) (transfer full) (allow-none): Result location for the
2567  *      context or %NULL
2568  *
2569  * Extract the context from the HAVE_CONTEXT message.
2570  *
2571  * MT safe.
2572  *
2573  * Since: 1.2
2574  */
2575 void
2576 gst_message_parse_have_context (GstMessage * message, GstContext ** context)
2577 {
2578   g_return_if_fail (GST_IS_MESSAGE (message));
2579   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_HAVE_CONTEXT);
2580
2581   if (context)
2582     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2583         GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2584 }
2585
2586 /**
2587  * gst_message_new_device_added:
2588  * @src: The #GstObject that created the message
2589  * @device: (transfer none): The new #GstDevice
2590  *
2591  * Creates a new device-added message. The device-added message is produced by
2592  * #GstDeviceProvider or a #GstDeviceMonitor. They announce the appearance
2593  * of monitored devices.
2594  *
2595  * Returns: a newly allocated #GstMessage
2596  *
2597  * Since: 1.4
2598  */
2599 GstMessage *
2600 gst_message_new_device_added (GstObject * src, GstDevice * device)
2601 {
2602   GstMessage *message;
2603   GstStructure *structure;
2604
2605   g_return_val_if_fail (device != NULL, NULL);
2606   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2607
2608   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_ADDED),
2609       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2610   message = gst_message_new_custom (GST_MESSAGE_DEVICE_ADDED, src, structure);
2611
2612   return message;
2613 }
2614
2615 /**
2616  * gst_message_parse_device_added:
2617  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_ADDED
2618  * @device: (out) (allow-none) (transfer full): A location where to store a
2619  *  pointer to the new #GstDevice, or %NULL
2620  *
2621  * Parses a device-added message. The device-added message is produced by
2622  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the appearance
2623  * of monitored devices.
2624  *
2625  * Since: 1.4
2626  */
2627 void
2628 gst_message_parse_device_added (GstMessage * message, GstDevice ** device)
2629 {
2630   g_return_if_fail (GST_IS_MESSAGE (message));
2631   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_ADDED);
2632
2633   if (device)
2634     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2635         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2636 }
2637
2638 /**
2639  * gst_message_new_device_removed:
2640  * @src: The #GstObject that created the message
2641  * @device: (transfer none): The removed #GstDevice
2642  *
2643  * Creates a new device-removed message. The device-removed message is produced
2644  * by #GstDeviceProvider or a #GstDeviceMonitor. They announce the
2645  * disappearance of monitored devices.
2646  *
2647  * Returns: a newly allocated #GstMessage
2648  *
2649  * Since: 1.4
2650  */
2651 GstMessage *
2652 gst_message_new_device_removed (GstObject * src, GstDevice * device)
2653 {
2654   GstMessage *message;
2655   GstStructure *structure;
2656
2657   g_return_val_if_fail (device != NULL, NULL);
2658   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2659
2660   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_REMOVED),
2661       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2662   message = gst_message_new_custom (GST_MESSAGE_DEVICE_REMOVED, src, structure);
2663
2664   return message;
2665 }
2666
2667 /**
2668  * gst_message_parse_device_removed:
2669  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_REMOVED
2670  * @device: (out) (allow-none) (transfer full): A location where to store a
2671  *  pointer to the removed #GstDevice, or %NULL
2672  *
2673  * Parses a device-removed message. The device-removed message is produced by
2674  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the
2675  * disappearance of monitored devices.
2676  *
2677  * Since: 1.4
2678  */
2679 void
2680 gst_message_parse_device_removed (GstMessage * message, GstDevice ** device)
2681 {
2682   g_return_if_fail (GST_IS_MESSAGE (message));
2683   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_REMOVED);
2684
2685   if (device)
2686     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2687         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2688 }
2689
2690 /**
2691  * gst_message_new_property_notify:
2692  * @src: The #GstObject whose property changed (may or may not be a #GstElement)
2693  * @property_name: name of the property that changed
2694  * @val: (allow-none) (transfer full): new property value, or %NULL
2695  *
2696  * Returns: a newly allocated #GstMessage
2697  *
2698  * Since: 1.10
2699  */
2700 GstMessage *
2701 gst_message_new_property_notify (GstObject * src, const gchar * property_name,
2702     GValue * val)
2703 {
2704   GstStructure *structure;
2705   GValue name_val = G_VALUE_INIT;
2706
2707   g_return_val_if_fail (property_name != NULL, NULL);
2708
2709   structure = gst_structure_new_id_empty (GST_QUARK (MESSAGE_PROPERTY_NOTIFY));
2710   g_value_init (&name_val, G_TYPE_STRING);
2711   /* should already be interned, but let's make sure */
2712   g_value_set_static_string (&name_val, g_intern_string (property_name));
2713   gst_structure_id_take_value (structure, GST_QUARK (PROPERTY_NAME), &name_val);
2714   if (val != NULL)
2715     gst_structure_id_take_value (structure, GST_QUARK (PROPERTY_VALUE), val);
2716
2717   return gst_message_new_custom (GST_MESSAGE_PROPERTY_NOTIFY, src, structure);
2718 }
2719
2720 /**
2721  * gst_message_parse_property_notify:
2722  * @message: a #GstMessage of type %GST_MESSAGE_PROPERTY_NOTIFY
2723  * @object: (out) (allow-none) (transfer none): location where to store a
2724  *     pointer to the object whose property got changed, or %NULL
2725  * @property_name: (out) (transfer none) (allow-none): return location for
2726  *     the name of the property that got changed, or %NULL
2727  * @property_value: (out) (transfer none) (allow-none): return location for
2728  *     the new value of the property that got changed, or %NULL. This will
2729  *     only be set if the property notify watch was told to include the value
2730  *     when it was set up
2731  *
2732  * Parses a property-notify message. These will be posted on the bus only
2733  * when set up with gst_element_add_property_notify_watch() or
2734  * gst_element_add_property_deep_notify_watch().
2735  *
2736  * Since: 1.10
2737  */
2738 void
2739 gst_message_parse_property_notify (GstMessage * message, GstObject ** object,
2740     const gchar ** property_name, const GValue ** property_value)
2741 {
2742   const GstStructure *s = GST_MESSAGE_STRUCTURE (message);
2743
2744   g_return_if_fail (GST_IS_MESSAGE (message));
2745   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROPERTY_NOTIFY);
2746
2747   if (object)
2748     *object = GST_MESSAGE_SRC (message);
2749
2750   if (property_name) {
2751     const GValue *name_value;
2752
2753     name_value = gst_structure_id_get_value (s, GST_QUARK (PROPERTY_NAME));
2754     *property_name = g_value_get_string (name_value);
2755   }
2756
2757   if (property_value)
2758     *property_value =
2759         gst_structure_id_get_value (s, GST_QUARK (PROPERTY_VALUE));
2760 }
2761
2762 /**
2763  * gst_message_new_stream_collection:
2764  * @src: The #GstObject that created the message
2765  * @collection: (transfer none): The #GstStreamCollection
2766  *
2767  * Creates a new stream-collection message. The message is used to announce new
2768  * #GstStreamCollection
2769  *
2770  * Returns: a newly allocated #GstMessage
2771  *
2772  * Since: 1.10
2773  */
2774 GstMessage *
2775 gst_message_new_stream_collection (GstObject * src,
2776     GstStreamCollection * collection)
2777 {
2778   GstMessage *message;
2779   GstStructure *structure;
2780
2781   g_return_val_if_fail (collection != NULL, NULL);
2782   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
2783
2784   structure =
2785       gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_COLLECTION),
2786       GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
2787   message =
2788       gst_message_new_custom (GST_MESSAGE_STREAM_COLLECTION, src, structure);
2789
2790   return message;
2791 }
2792
2793 /**
2794  * gst_message_parse_stream_collection:
2795  * @message: a #GstMessage of type %GST_MESSAGE_STREAM_COLLECTION
2796  * @collection: (out) (allow-none) (transfer full): A location where to store a
2797  *  pointer to the #GstStreamCollection, or %NULL
2798  *
2799  * Parses a stream-collection message.
2800  *
2801  * Since: 1.10
2802  */
2803 void
2804 gst_message_parse_stream_collection (GstMessage * message,
2805     GstStreamCollection ** collection)
2806 {
2807   g_return_if_fail (GST_IS_MESSAGE (message));
2808   g_return_if_fail (GST_MESSAGE_TYPE (message) ==
2809       GST_MESSAGE_STREAM_COLLECTION);
2810
2811   if (collection)
2812     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2813         GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
2814 }
2815
2816 /**
2817  * gst_message_new_streams_selected:
2818  * @src: The #GstObject that created the message
2819  * @collection: (transfer none): The #GstStreamCollection
2820  *
2821  * Creates a new steams-selected message. The message is used to announce
2822  * that an array of streams has been selected. This is generally in response
2823  * to a #GST_EVENT_SELECT_STREAMS event, or when an element (such as decodebin3)
2824  * makes an initial selection of streams.
2825  *
2826  * The message also contains the #GstStreamCollection to which the various streams
2827  * belong to.
2828  *
2829  * Users of gst_message_new_streams_selected() can add the selected streams with
2830  * gst_message_streams_selected_add().
2831  *
2832  * Returns: a newly allocated #GstMessage
2833  *
2834  * Since: 1.10
2835  */
2836 GstMessage *
2837 gst_message_new_streams_selected (GstObject * src,
2838     GstStreamCollection * collection)
2839 {
2840   GstMessage *message;
2841   GstStructure *structure;
2842   GValue val = G_VALUE_INIT;
2843
2844   g_return_val_if_fail (collection != NULL, NULL);
2845   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
2846
2847   structure =
2848       gst_structure_new_id (GST_QUARK (MESSAGE_STREAMS_SELECTED),
2849       GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
2850   g_value_init (&val, GST_TYPE_ARRAY);
2851   gst_structure_id_take_value (structure, GST_QUARK (STREAMS), &val);
2852   message =
2853       gst_message_new_custom (GST_MESSAGE_STREAMS_SELECTED, src, structure);
2854
2855   return message;
2856 }
2857
2858 /**
2859  * gst_message_streams_selected_get_size:
2860  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
2861  *
2862  * Returns the number of streams contained in the @message.
2863  *
2864  * Returns: The number of streams contained within.
2865  *
2866  * Since: 1.10
2867  */
2868 guint
2869 gst_message_streams_selected_get_size (GstMessage * msg)
2870 {
2871   const GValue *val;
2872
2873   g_return_val_if_fail (GST_IS_MESSAGE (msg), 0);
2874   g_return_val_if_fail (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED,
2875       0);
2876
2877   val =
2878       gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (msg),
2879       GST_QUARK (STREAMS));
2880   return gst_value_array_get_size (val);
2881 }
2882
2883 /**
2884  * gst_message_streams_selected_add:
2885  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
2886  * @stream: (transfer none): a #GstStream to add to @message
2887  *
2888  * Adds the @stream to the @message.
2889  *
2890  * Since: 1.10
2891  */
2892 void
2893 gst_message_streams_selected_add (GstMessage * msg, GstStream * stream)
2894 {
2895   GValue *val;
2896   GValue to_add = G_VALUE_INIT;
2897
2898   g_return_if_fail (GST_IS_MESSAGE (msg));
2899   g_return_if_fail (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED);
2900   g_return_if_fail (GST_IS_STREAM (stream));
2901
2902   val =
2903       (GValue *) gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (msg),
2904       GST_QUARK (STREAMS));
2905   g_value_init (&to_add, GST_TYPE_STREAM);
2906   g_value_set_object (&to_add, stream);
2907   gst_value_array_append_and_take_value (val, &to_add);
2908 }
2909
2910 /**
2911  * gst_message_streams_selected_get_stream:
2912  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
2913  * @idx: Index of the stream to retrieve
2914  *
2915  * Retrieves the #GstStream with index @index from the @message.
2916  *
2917  * Returns: (transfer full) (nullable): A #GstStream
2918  *
2919  * Since: 1.10
2920  */
2921 GstStream *
2922 gst_message_streams_selected_get_stream (GstMessage * msg, guint idx)
2923 {
2924   const GValue *streams, *val;
2925
2926   g_return_val_if_fail (GST_IS_MESSAGE (msg), NULL);
2927   g_return_val_if_fail (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED,
2928       NULL);
2929
2930   streams =
2931       gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (msg),
2932       GST_QUARK (STREAMS));
2933   val = gst_value_array_get_value (streams, idx);
2934   if (val) {
2935     return (GstStream *) g_value_dup_object (val);
2936   }
2937
2938   return NULL;
2939 }
2940
2941 /**
2942  * gst_message_parse_streams_selected:
2943  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
2944  * @collection: (out) (allow-none) (transfer full): A location where to store a
2945  *  pointer to the #GstStreamCollection, or %NULL
2946  *
2947  * Parses a streams-selected message.
2948  *
2949  * Since: 1.10
2950  */
2951 void
2952 gst_message_parse_streams_selected (GstMessage * message,
2953     GstStreamCollection ** collection)
2954 {
2955   g_return_if_fail (GST_IS_MESSAGE (message));
2956   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAMS_SELECTED);
2957
2958   if (collection)
2959     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2960         GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
2961 }
2962
2963 /**
2964  * gst_message_new_redirect:
2965  * @src: The #GstObject whose property changed (may or may not be a #GstElement)
2966  * @location: (transfer none): location string for the new entry
2967  * @tag_list: (transfer full) (allow-none): tag list for the new entry
2968  * @entry_struct: (transfer full) (allow-none): structure for the new entry
2969  *
2970  * Creates a new redirect message and adds a new entry to it. Redirect messages
2971  * are posted when an element detects that the actual data has to be retrieved
2972  * from a different location. This is useful if such a redirection cannot be
2973  * handled inside a source element, for example when HTTP 302/303 redirects
2974  * return a non-HTTP URL.
2975  *
2976  * The redirect message can hold multiple entries. The first one is added
2977  * when the redirect message is created, with the given location, tag_list,
2978  * entry_struct arguments. Use gst_message_add_redirect_entry() to add more
2979  * entries.
2980  *
2981  * Each entry has a location, a tag list, and a structure. All of these are
2982  * optional. The tag list and structure are useful for additional metadata,
2983  * such as bitrate statistics for the given location.
2984  *
2985  * By default, message recipients should treat entries in the order they are
2986  * stored. The recipient should therefore try entry #0 first, and if this
2987  * entry is not acceptable or working, try entry #1 etc. Senders must make
2988  * sure that they add entries in this order. However, recipients are free to
2989  * ignore the order and pick an entry that is "best" for them. One example
2990  * would be a recipient that scans the entries for the one with the highest
2991  * bitrate tag.
2992  *
2993  * The specified location string is copied. However, ownership over the tag
2994  * list and structure are transferred to the message.
2995  *
2996  * Returns: a newly allocated #GstMessage
2997  *
2998  * Since: 1.10
2999  */
3000 GstMessage *
3001 gst_message_new_redirect (GstObject * src, const gchar * location,
3002     GstTagList * tag_list, const GstStructure * entry_struct)
3003 {
3004   GstStructure *structure;
3005   GstMessage *message;
3006   GValue entry_locations_gvalue = G_VALUE_INIT;
3007   GValue entry_taglists_gvalue = G_VALUE_INIT;
3008   GValue entry_structures_gvalue = G_VALUE_INIT;
3009
3010   g_return_val_if_fail (location != NULL, NULL);
3011
3012   g_value_init (&entry_locations_gvalue, GST_TYPE_LIST);
3013   g_value_init (&entry_taglists_gvalue, GST_TYPE_LIST);
3014   g_value_init (&entry_structures_gvalue, GST_TYPE_LIST);
3015
3016   structure = gst_structure_new_id_empty (GST_QUARK (MESSAGE_REDIRECT));
3017   gst_structure_id_take_value (structure, GST_QUARK (REDIRECT_ENTRY_LOCATIONS),
3018       &entry_locations_gvalue);
3019   gst_structure_id_take_value (structure, GST_QUARK (REDIRECT_ENTRY_TAGLISTS),
3020       &entry_taglists_gvalue);
3021   gst_structure_id_take_value (structure, GST_QUARK (REDIRECT_ENTRY_STRUCTURES),
3022       &entry_structures_gvalue);
3023
3024   message = gst_message_new_custom (GST_MESSAGE_REDIRECT, src, structure);
3025   g_assert (message != NULL);
3026
3027   gst_message_add_redirect_entry (message, location, tag_list, entry_struct);
3028
3029   return message;
3030 }
3031
3032 /**
3033  * gst_message_add_redirect_entry:
3034  * @message: a #GstMessage of type %GST_MESSAGE_REDIRECT
3035  * @location: (transfer none): location string for the new entry
3036  * @tag_list: (transfer full) (allow-none): tag list for the new entry
3037  * @entry_struct: (transfer full) (allow-none): structure for the new entry
3038  *
3039  * Creates and appends a new entry.
3040  *
3041  * The specified location string is copied. However, ownership over the tag
3042  * list and structure are transferred to the message.
3043  *
3044  * Since: 1.10
3045  */
3046 void
3047 gst_message_add_redirect_entry (GstMessage * message, const gchar * location,
3048     GstTagList * tag_list, const GstStructure * entry_struct)
3049 {
3050   GValue val = G_VALUE_INIT;
3051   GstStructure *structure;
3052   GValue *entry_locations_gvalue;
3053   GValue *entry_taglists_gvalue;
3054   GValue *entry_structures_gvalue;
3055
3056   g_return_if_fail (location != NULL);
3057   g_return_if_fail (GST_IS_MESSAGE (message));
3058   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REDIRECT);
3059
3060   structure = GST_MESSAGE_STRUCTURE (message);
3061
3062   entry_locations_gvalue =
3063       (GValue *) gst_structure_id_get_value (structure,
3064       GST_QUARK (REDIRECT_ENTRY_LOCATIONS));
3065   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_locations_gvalue));
3066   entry_taglists_gvalue =
3067       (GValue *) gst_structure_id_get_value (structure,
3068       GST_QUARK (REDIRECT_ENTRY_TAGLISTS));
3069   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_taglists_gvalue));
3070   entry_structures_gvalue =
3071       (GValue *) gst_structure_id_get_value (structure,
3072       GST_QUARK (REDIRECT_ENTRY_STRUCTURES));
3073   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_structures_gvalue));
3074
3075   g_value_init (&val, G_TYPE_STRING);
3076   if (location)
3077     g_value_set_string (&val, location);
3078   gst_value_list_append_and_take_value (entry_locations_gvalue, &val);
3079
3080   g_value_init (&val, GST_TYPE_TAG_LIST);
3081   if (tag_list)
3082     g_value_take_boxed (&val, tag_list);
3083   gst_value_list_append_and_take_value (entry_taglists_gvalue, &val);
3084
3085   g_value_init (&val, GST_TYPE_STRUCTURE);
3086   if (entry_struct)
3087     g_value_take_boxed (&val, entry_struct);
3088   gst_value_list_append_and_take_value (entry_structures_gvalue, &val);
3089 }
3090
3091 /**
3092  * gst_message_parse_redirect_entry:
3093  * @message: a #GstMessage of type %GST_MESSAGE_REDIRECT
3094  * @entry_index: index of the entry to parse
3095  * @location: (out) (transfer none) (allow-none): return location for
3096  *     the pointer to the entry's location string, or %NULL
3097  * @tag_list: (out) (transfer none) (allow-none): return location for
3098  *     the pointer to the entry's tag list, or %NULL
3099  * @entry_struct: (out) (transfer none) (allow-none): return location
3100  *     for the pointer to the entry's structure, or %NULL
3101  *
3102  * Parses the location and/or structure from the entry with the given index.
3103  * The index must be between 0 and gst_message_get_num_redirect_entries() - 1.
3104  * Returned pointers are valid for as long as this message exists.
3105  *
3106  * Since: 1.10
3107  */
3108 void
3109 gst_message_parse_redirect_entry (GstMessage * message, gsize entry_index,
3110     const gchar ** location, GstTagList ** tag_list,
3111     const GstStructure ** entry_struct)
3112 {
3113   const GValue *val;
3114   GstStructure *structure;
3115   const GValue *entry_locations_gvalue;
3116   const GValue *entry_taglists_gvalue;
3117   const GValue *entry_structures_gvalue;
3118
3119   g_return_if_fail (GST_IS_MESSAGE (message));
3120   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REDIRECT);
3121
3122   if (G_UNLIKELY (!location && !tag_list && !entry_struct))
3123     return;
3124
3125   structure = GST_MESSAGE_STRUCTURE (message);
3126
3127   entry_locations_gvalue =
3128       gst_structure_id_get_value (structure,
3129       GST_QUARK (REDIRECT_ENTRY_LOCATIONS));
3130   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_locations_gvalue));
3131   entry_taglists_gvalue =
3132       gst_structure_id_get_value (structure,
3133       GST_QUARK (REDIRECT_ENTRY_TAGLISTS));
3134   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_taglists_gvalue));
3135   entry_structures_gvalue =
3136       gst_structure_id_get_value (structure,
3137       GST_QUARK (REDIRECT_ENTRY_STRUCTURES));
3138   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_structures_gvalue));
3139
3140   if (location) {
3141     val = gst_value_list_get_value (entry_locations_gvalue, entry_index);
3142     g_return_if_fail (val != NULL);
3143     *location = g_value_get_string (val);
3144   }
3145
3146   if (tag_list) {
3147     val = gst_value_list_get_value (entry_taglists_gvalue, entry_index);
3148     g_return_if_fail (val != NULL);
3149     *tag_list = (GstTagList *) g_value_get_boxed (val);
3150   }
3151
3152   if (entry_struct) {
3153     val = gst_value_list_get_value (entry_structures_gvalue, entry_index);
3154     g_return_if_fail (val != NULL);
3155     *entry_struct = (const GstStructure *) g_value_get_boxed (val);
3156   }
3157 }
3158
3159 /**
3160  * gst_message_get_num_redirect_entries:
3161  * @message: a #GstMessage of type %GST_MESSAGE_REDIRECT
3162  *
3163  * Returns: the number of entries stored in the message
3164  *
3165  * Since: 1.10
3166  */
3167 gsize
3168 gst_message_get_num_redirect_entries (GstMessage * message)
3169 {
3170   GstStructure *structure;
3171   const GValue *entry_locations_gvalue;
3172   const GValue *entry_taglists_gvalue;
3173   const GValue *entry_structures_gvalue;
3174   gsize size;
3175
3176   g_return_val_if_fail (GST_IS_MESSAGE (message), 0);
3177   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REDIRECT, 0);
3178
3179   structure = GST_MESSAGE_STRUCTURE (message);
3180
3181   entry_locations_gvalue =
3182       gst_structure_id_get_value (structure,
3183       GST_QUARK (REDIRECT_ENTRY_LOCATIONS));
3184   g_return_val_if_fail (GST_VALUE_HOLDS_LIST (entry_locations_gvalue), 0);
3185   entry_taglists_gvalue =
3186       gst_structure_id_get_value (structure,
3187       GST_QUARK (REDIRECT_ENTRY_TAGLISTS));
3188   g_return_val_if_fail (GST_VALUE_HOLDS_LIST (entry_taglists_gvalue), 0);
3189   entry_structures_gvalue =
3190       gst_structure_id_get_value (structure,
3191       GST_QUARK (REDIRECT_ENTRY_STRUCTURES));
3192   g_return_val_if_fail (GST_VALUE_HOLDS_LIST (entry_structures_gvalue), 0);
3193
3194   size = gst_value_list_get_size (entry_locations_gvalue);
3195
3196   g_return_val_if_fail ((size ==
3197           gst_value_list_get_size (entry_structures_gvalue))
3198       && (size == gst_value_list_get_size (entry_taglists_gvalue)), 0);
3199
3200   return size;
3201 }