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