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