• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
_priv_gst_message_initialize(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 *
gst_message_type_get_name(GstMessageType type)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
gst_message_type_to_quark(GstMessageType type)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
_gst_message_dispose(GstMessage * message)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
_gst_message_free(GstMessage * message)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 *
_gst_message_copy(GstMessage * message)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
gst_message_init(GstMessageImpl * message,GstMessageType type,GstObject * src)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 *
gst_message_new_custom(GstMessageType type,GstObject * src,GstStructure * structure)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
gst_message_get_seqnum(GstMessage * message)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
gst_message_set_seqnum(GstMessage * message,guint32 seqnum)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 *
gst_message_new_eos(GstObject * src)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 *
gst_message_new_error_with_details(GstObject * src,GError * error,const gchar * debug,GstStructure * details)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 *
gst_message_new_error(GstObject * src,GError * error,const gchar * debug)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
gst_message_parse_error_details(GstMessage * message,const GstStructure ** structure)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 *
gst_message_new_warning_with_details(GstObject * src,GError * error,const gchar * debug,GstStructure * details)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 *
gst_message_new_warning(GstObject * src,GError * error,const gchar * debug)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
gst_message_parse_warning_details(GstMessage * message,const GstStructure ** structure)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 *
gst_message_new_info_with_details(GstObject * src,GError * error,const gchar * debug,GstStructure * details)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 *
gst_message_new_info(GstObject * src,GError * error,const gchar * debug)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
gst_message_parse_info_details(GstMessage * message,const GstStructure ** structure)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 *
gst_message_new_tag(GstObject * src,GstTagList * tag_list)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 *
gst_message_new_buffering(GstObject * src,gint percent)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 *
gst_message_new_state_changed(GstObject * src,GstState oldstate,GstState newstate,GstState pending)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 *
gst_message_new_state_dirty(GstObject * src)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 *
gst_message_new_clock_provide(GstObject * src,GstClock * clock,gboolean ready)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 *
gst_message_new_clock_lost(GstObject * src,GstClock * clock)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 *
gst_message_new_new_clock(GstObject * src,GstClock * clock)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 *
gst_message_new_structure_change(GstObject * src,GstStructureChangeType type,GstElement * owner,gboolean busy)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 *
gst_message_new_segment_start(GstObject * src,GstFormat format,gint64 position)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 *
gst_message_new_segment_done(GstObject * src,GstFormat format,gint64 position)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 *
gst_message_new_application(GstObject * src,GstStructure * structure)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 *
gst_message_new_element(GstObject * src,GstStructure * structure)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 *
gst_message_new_duration_changed(GstObject * src)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 *
gst_message_new_async_start(GstObject * src)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 *
gst_message_new_async_done(GstObject * src,GstClockTime running_time)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 *
gst_message_new_latency(GstObject * src)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 *
gst_message_new_request_state(GstObject * src,GstState state)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 *
gst_message_get_structure(GstMessage * message)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 *
gst_message_writable_structure(GstMessage * message)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
gst_message_has_name(GstMessage * message,const gchar * name)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
gst_message_parse_tag(GstMessage * message,GstTagList ** tag_list)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
gst_message_parse_buffering(GstMessage * message,gint * percent)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 #ifdef OHOS_EXT_FUNC
1290 // ohos.ext.func.0012
1291 /**
1292  * gst_message_new_buffering_time:
1293  * @src: (transfer none) (allow-none): The object originating the message.
1294  * @buffering_time: The buffering time
1295  * @mq_num_id: The multiqueue id
1296  *
1297  * Create a new buffering time message. This message can be posted by a multiqueue that
1298  * needs to report buffering time
1299  *
1300  * MT safe.
1301  *
1302  * Returns: (transfer full) (nullable): The new buffering time message.
1303  */
1304 GstMessage *
gst_message_new_buffering_time(GstObject * src,gint64 buffering_time,guint mq_num_id)1305 gst_message_new_buffering_time (GstObject * src, gint64 buffering_time, guint mq_num_id)
1306 {
1307   GstMessage *message;
1308   GstStructure *structure;
1309 
1310   structure = gst_structure_new ("message-buffering-time",
1311       "buffering-time", G_TYPE_INT64, buffering_time,
1312       "mq-num-id", G_TYPE_UINT, mq_num_id, NULL);
1313   message = gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
1314 
1315   return message;
1316 }
1317 
1318 /**
1319  * gst_message_parse_buffering_time:
1320  * @message: A valid #GstMessage of type GST_QUARK_MESSAGE_BUFFERING_TIME.
1321  * @buffering_time: (out) (allow-none): The buffering time, or %NULL
1322  * @mq_num_id: (out) (allow-none): The multiqueue id, or %NULL
1323  *
1324  * Extracts the buffering time values from @message.
1325  */
1326 void
gst_message_parse_buffering_time(GstMessage * message,gint64 * buffering_time,guint * mq_num_id)1327 gst_message_parse_buffering_time (GstMessage * message, gint64 * buffering_time, guint * mq_num_id)
1328 {
1329   GstStructure *structure;
1330 
1331   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT);
1332 
1333   structure = GST_MESSAGE_STRUCTURE (message);
1334   if (buffering_time) {
1335     (void)gst_structure_get_int64(structure, "buffering-time", buffering_time);
1336   }
1337 
1338   if (mq_num_id) {
1339     (void)gst_structure_get_uint(structure, "mq-num-id", mq_num_id);
1340   }
1341 }
1342 
1343 // ohos.ext.func.0013
1344 /**
1345  * gst_message_new_mq_num_use_buffering:
1346  * @src: (transfer none) (allow-none): The object originating the message.
1347  * @mq_num_use_buffering: The number of multiqueue use buffering
1348  *
1349  * Create a new multiqueue num use buffering message. This message can be posted by a multiqueue that
1350  * needs to report the number of multiqueue use buffering
1351  *
1352  * MT safe.
1353  *
1354  * Returns: (transfer full) (nullable): The new multiqueue num use buffering message.
1355  */
1356 GstMessage *
gst_message_new_mq_num_use_buffering(GstObject * src,guint mq_num_use_buffering)1357 gst_message_new_mq_num_use_buffering (GstObject * src, guint mq_num_use_buffering)
1358 {
1359   GstMessage *message;
1360   GstStructure *structure;
1361 
1362   structure = gst_structure_new ("message-mq-num-use-buffering",
1363             "mq_num_use_buffering", G_TYPE_UINT, mq_num_use_buffering, NULL);
1364   message = gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
1365 
1366   return message;
1367 }
1368 
1369 /**
1370  * gst_message_parse_mq_num_use_buffering:
1371  * @message: A valid #GstMessage of type mq_num_use_buffering.
1372  * @mq_num_use_buffering: (out) (allow-none): The number of multiqueue use bufferig, or %NULL
1373  *
1374  * Extracts the multiqueue num use buffering values from @message.
1375  */
1376 void
gst_message_parse_mq_num_use_buffering(GstMessage * message,guint * mq_num_use_buffering)1377 gst_message_parse_mq_num_use_buffering (GstMessage * message, guint * mq_num_use_buffering)
1378 {
1379   GstStructure *structure;
1380 
1381   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT);
1382 
1383   structure = GST_MESSAGE_STRUCTURE (message);
1384   if (mq_num_use_buffering) {
1385     (void)gst_structure_get_uint(structure, "mq_num_use_buffering", mq_num_use_buffering);
1386   }
1387 }
1388 
1389 // ohos.ext.func.0014
1390 /**
1391  * gst_message_new_resolution_changed:
1392  * @src: (transfer none) (allow-none): The object originating the message.
1393  * @width: video of width
1394  * @height: video of height
1395  *
1396  * Create a new resolution changed message. This message can be posted by demux that
1397  * needs to report the resolution changed
1398  *
1399  * MT safe.
1400  *
1401  * Returns: (transfer full) (nullable): The new resolution changed message.
1402  */
1403 GstMessage *
gst_message_new_resolution_changed(GstObject * src,gint width,gint height)1404 gst_message_new_resolution_changed (GstObject * src, gint width, gint height)
1405 {
1406   GstMessage *message;
1407   GstStructure *structure;
1408   structure = gst_structure_new ("resolution-changed",
1409             "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
1410   message = gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
1411   return message;
1412 }
1413 
1414 /**
1415  * gst_message_parse_resulution_changed:
1416  * @message: A valid #GstMessage of type resolution-changed.
1417  * @width: (out) (allow-none): video of width, or %NULL
1418  * @height: (out) (allow-none): video of height, or %NULL
1419  *
1420  * Extracts the resolution changed values from @message.
1421  */
1422 void
gst_message_parse_resulution_changed(GstMessage * message,gint * width,gint * height)1423 gst_message_parse_resulution_changed (GstMessage * message, gint * width, gint * height)
1424 {
1425   GstStructure *structure;
1426   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT);
1427   structure = GST_MESSAGE_STRUCTURE (message);
1428   if (width && height) {
1429     (void)gst_structure_get_int(structure, "width", width);
1430     (void)gst_structure_get_int(structure, "height", height);
1431   }
1432 }
1433 
1434 // ohos.ext.func.0032
1435 /**
1436  * gst_message_new_video_rotation:
1437  * @src: (transfer none) (allow-none): The object originating the message.
1438  * @rotation: video of rotation
1439  *
1440  * Create a new video rotation message. This message can be posted by demux that
1441  * needs to report the video rotation
1442  *
1443  * MT safe.
1444  *
1445  * Returns: (transfer full) (nullable): The new video rotation message.
1446  */
1447 GstMessage *
gst_message_new_video_rotation(GstObject * src,const gchar * rotation)1448 gst_message_new_video_rotation (GstObject * src, const gchar *rotation)
1449 {
1450   GstMessage *message;
1451   GstStructure *structure;
1452   structure = gst_structure_new ("video-rotation", "rotation", G_TYPE_STRING, rotation, NULL);
1453   message = gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
1454   return message;
1455 }
1456 
1457 /**
1458  * gst_message_parse_video_rotation:
1459  * @message: A valid #GstMessage of type video-rotation.
1460  * @rotation: (out) (allow-none): video of rotation, or %NULL
1461  *
1462  * Extracts the video rotation values from @message.
1463  */
1464 void
gst_message_parse_video_rotation(GstMessage * message,gchar ** rotation)1465 gst_message_parse_video_rotation (GstMessage * message, gchar **rotation)
1466 {
1467   GstStructure *structure;
1468   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT);
1469   structure = GST_MESSAGE_STRUCTURE (message);
1470 
1471   *rotation = gst_structure_get_string(structure, "rotation");
1472 }
1473 #endif
1474 
1475 /**
1476  * gst_message_set_buffering_stats:
1477  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1478  * @mode: a buffering mode
1479  * @avg_in: the average input rate
1480  * @avg_out: the average output rate
1481  * @buffering_left: amount of buffering time left in milliseconds
1482  *
1483  * Configures the buffering stats values in @message.
1484  */
1485 void
gst_message_set_buffering_stats(GstMessage * message,GstBufferingMode mode,gint avg_in,gint avg_out,gint64 buffering_left)1486 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1487     gint avg_in, gint avg_out, gint64 buffering_left)
1488 {
1489   g_return_if_fail (GST_IS_MESSAGE (message));
1490   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1491 
1492   gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1493       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1494       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1495       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1496       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1497 }
1498 
1499 /**
1500  * gst_message_parse_buffering_stats:
1501  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1502  * @mode: (out) (allow-none): a buffering mode, or %NULL
1503  * @avg_in: (out) (allow-none): the average input rate, or %NULL
1504  * @avg_out: (out) (allow-none): the average output rate, or %NULL
1505  * @buffering_left: (out) (allow-none): amount of buffering time left in
1506  *     milliseconds, or %NULL
1507  *
1508  * Extracts the buffering stats values from @message.
1509  */
1510 void
gst_message_parse_buffering_stats(GstMessage * message,GstBufferingMode * mode,gint * avg_in,gint * avg_out,gint64 * buffering_left)1511 gst_message_parse_buffering_stats (GstMessage * message,
1512     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1513     gint64 * buffering_left)
1514 {
1515   GstStructure *structure;
1516 
1517   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1518 
1519   structure = GST_MESSAGE_STRUCTURE (message);
1520   if (mode)
1521     *mode = (GstBufferingMode)
1522         g_value_get_enum (gst_structure_id_get_value (structure,
1523             GST_QUARK (BUFFERING_MODE)));
1524   if (avg_in)
1525     *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1526             GST_QUARK (AVG_IN_RATE)));
1527   if (avg_out)
1528     *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1529             GST_QUARK (AVG_OUT_RATE)));
1530   if (buffering_left)
1531     *buffering_left =
1532         g_value_get_int64 (gst_structure_id_get_value (structure,
1533             GST_QUARK (BUFFERING_LEFT)));
1534 }
1535 
1536 /**
1537  * gst_message_parse_state_changed:
1538  * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1539  * @oldstate: (out) (allow-none): the previous state, or %NULL
1540  * @newstate: (out) (allow-none): the new (current) state, or %NULL
1541  * @pending: (out) (allow-none): the pending (target) state, or %NULL
1542  *
1543  * Extracts the old and new states from the GstMessage.
1544  *
1545  * Typical usage of this function might be:
1546  * |[<!-- language="C" -->
1547  *   ...
1548  *   switch (GST_MESSAGE_TYPE (msg)) {
1549  *     case GST_MESSAGE_STATE_CHANGED: {
1550  *       GstState old_state, new_state;
1551  *
1552  *       gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
1553  *       g_print ("Element %s changed state from %s to %s.\n",
1554  *           GST_OBJECT_NAME (msg->src),
1555  *           gst_element_state_get_name (old_state),
1556  *           gst_element_state_get_name (new_state));
1557  *       break;
1558  *     }
1559  *     ...
1560  *   }
1561  *   ...
1562  * ]|
1563  *
1564  * MT safe.
1565  */
1566 void
gst_message_parse_state_changed(GstMessage * message,GstState * oldstate,GstState * newstate,GstState * pending)1567 gst_message_parse_state_changed (GstMessage * message,
1568     GstState * oldstate, GstState * newstate, GstState * pending)
1569 {
1570   GstStructure *structure;
1571 
1572   g_return_if_fail (GST_IS_MESSAGE (message));
1573   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1574 
1575   structure = GST_MESSAGE_STRUCTURE (message);
1576   if (oldstate)
1577     *oldstate = (GstState)
1578         g_value_get_enum (gst_structure_id_get_value (structure,
1579             GST_QUARK (OLD_STATE)));
1580   if (newstate)
1581     *newstate = (GstState)
1582         g_value_get_enum (gst_structure_id_get_value (structure,
1583             GST_QUARK (NEW_STATE)));
1584   if (pending)
1585     *pending = (GstState)
1586         g_value_get_enum (gst_structure_id_get_value (structure,
1587             GST_QUARK (PENDING_STATE)));
1588 }
1589 
1590 /**
1591  * gst_message_parse_clock_provide:
1592  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1593  * @clock: (out) (allow-none) (transfer none): a pointer to  hold a clock
1594  *     object, or %NULL
1595  * @ready: (out) (allow-none): a pointer to hold the ready flag, or %NULL
1596  *
1597  * Extracts the clock and ready flag from the GstMessage.
1598  * The clock object returned remains valid until the message is freed.
1599  *
1600  * MT safe.
1601  */
1602 void
gst_message_parse_clock_provide(GstMessage * message,GstClock ** clock,gboolean * ready)1603 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1604     gboolean * ready)
1605 {
1606   const GValue *clock_gvalue;
1607   GstStructure *structure;
1608 
1609   g_return_if_fail (GST_IS_MESSAGE (message));
1610   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1611 
1612   structure = GST_MESSAGE_STRUCTURE (message);
1613   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1614   g_return_if_fail (clock_gvalue != NULL);
1615   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1616 
1617   if (ready)
1618     *ready =
1619         g_value_get_boolean (gst_structure_id_get_value (structure,
1620             GST_QUARK (READY)));
1621   if (clock)
1622     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1623 }
1624 
1625 /**
1626  * gst_message_parse_clock_lost:
1627  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1628  * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1629  *
1630  * Extracts the lost clock from the GstMessage.
1631  * The clock object returned remains valid until the message is freed.
1632  *
1633  * MT safe.
1634  */
1635 void
gst_message_parse_clock_lost(GstMessage * message,GstClock ** clock)1636 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1637 {
1638   const GValue *clock_gvalue;
1639   GstStructure *structure;
1640 
1641   g_return_if_fail (GST_IS_MESSAGE (message));
1642   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1643 
1644   structure = GST_MESSAGE_STRUCTURE (message);
1645   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1646   g_return_if_fail (clock_gvalue != NULL);
1647   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1648 
1649   if (clock)
1650     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1651 }
1652 
1653 /**
1654  * gst_message_parse_new_clock:
1655  * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1656  * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1657  *     new clock
1658  *
1659  * Extracts the new clock from the GstMessage.
1660  * The clock object returned remains valid until the message is freed.
1661  *
1662  * MT safe.
1663  */
1664 void
gst_message_parse_new_clock(GstMessage * message,GstClock ** clock)1665 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1666 {
1667   const GValue *clock_gvalue;
1668   GstStructure *structure;
1669 
1670   g_return_if_fail (GST_IS_MESSAGE (message));
1671   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1672 
1673   structure = GST_MESSAGE_STRUCTURE (message);
1674   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1675   g_return_if_fail (clock_gvalue != NULL);
1676   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1677 
1678   if (clock)
1679     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1680 }
1681 
1682 /**
1683  * gst_message_parse_structure_change:
1684  * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1685  * @type: (out): A pointer to hold the change type
1686  * @owner: (out) (allow-none) (transfer none): The owner element of the
1687  *     message source
1688  * @busy: (out) (allow-none): a pointer to hold whether the change is in
1689  *     progress or has been completed
1690  *
1691  * Extracts the change type and completion status from the GstMessage.
1692  *
1693  * MT safe.
1694  */
1695 void
gst_message_parse_structure_change(GstMessage * message,GstStructureChangeType * type,GstElement ** owner,gboolean * busy)1696 gst_message_parse_structure_change (GstMessage * message,
1697     GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1698 {
1699   const GValue *owner_gvalue;
1700   GstStructure *structure;
1701 
1702   g_return_if_fail (GST_IS_MESSAGE (message));
1703   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1704 
1705   structure = GST_MESSAGE_STRUCTURE (message);
1706   owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1707   g_return_if_fail (owner_gvalue != NULL);
1708   g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1709 
1710   if (type)
1711     *type = (GstStructureChangeType)
1712         g_value_get_enum (gst_structure_id_get_value (structure,
1713             GST_QUARK (TYPE)));
1714   if (owner)
1715     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1716   if (busy)
1717     *busy =
1718         g_value_get_boolean (gst_structure_id_get_value (structure,
1719             GST_QUARK (BUSY)));
1720 }
1721 
1722 /**
1723  * gst_message_parse_error:
1724  * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1725  * @gerror: (out) (allow-none) (transfer full): location for the GError
1726  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1727  *     or %NULL
1728  *
1729  * Extracts the GError and debug string from the GstMessage. The values returned
1730  * in the output arguments are copies; the caller must free them when done.
1731  *
1732  * Typical usage of this function might be:
1733  * |[<!-- language="C" -->
1734  *   ...
1735  *   switch (GST_MESSAGE_TYPE (msg)) {
1736  *     case GST_MESSAGE_ERROR: {
1737  *       GError *err = NULL;
1738  *       gchar *dbg_info = NULL;
1739  *
1740  *       gst_message_parse_error (msg, &err, &dbg_info);
1741  *       g_printerr ("ERROR from element %s: %s\n",
1742  *           GST_OBJECT_NAME (msg->src), err->message);
1743  *       g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1744  *       g_error_free (err);
1745  *       g_free (dbg_info);
1746  *       break;
1747  *     }
1748  *     ...
1749  *   }
1750  *   ...
1751  * ]|
1752  *
1753  * MT safe.
1754  */
1755 void
gst_message_parse_error(GstMessage * message,GError ** gerror,gchar ** debug)1756 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1757 {
1758   g_return_if_fail (GST_IS_MESSAGE (message));
1759   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1760 
1761   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1762       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1763       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1764 }
1765 
1766 /**
1767  * gst_message_parse_warning:
1768  * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1769  * @gerror: (out) (allow-none) (transfer full): location for the GError
1770  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1771  *     or %NULL
1772  *
1773  * Extracts the GError and debug string from the GstMessage. The values returned
1774  * in the output arguments are copies; the caller must free them when done.
1775  *
1776  * MT safe.
1777  */
1778 void
gst_message_parse_warning(GstMessage * message,GError ** gerror,gchar ** debug)1779 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1780     gchar ** debug)
1781 {
1782   g_return_if_fail (GST_IS_MESSAGE (message));
1783   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1784 
1785   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1786       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1787       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1788 }
1789 
1790 /**
1791  * gst_message_parse_info:
1792  * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1793  * @gerror: (out) (allow-none) (transfer full): location for the GError
1794  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1795  *     or %NULL
1796  *
1797  * Extracts the GError and debug string from the GstMessage. The values returned
1798  * in the output arguments are copies; the caller must free them when done.
1799  *
1800  * MT safe.
1801  */
1802 void
gst_message_parse_info(GstMessage * message,GError ** gerror,gchar ** debug)1803 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1804 {
1805   g_return_if_fail (GST_IS_MESSAGE (message));
1806   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1807 
1808   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1809       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1810       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1811 }
1812 
1813 /**
1814  * gst_message_parse_segment_start:
1815  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1816  * @format: (out) (allow-none): Result location for the format, or %NULL
1817  * @position: (out) (allow-none): Result location for the position, or %NULL
1818  *
1819  * Extracts the position and format from the segment start message.
1820  *
1821  * MT safe.
1822  */
1823 void
gst_message_parse_segment_start(GstMessage * message,GstFormat * format,gint64 * position)1824 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1825     gint64 * position)
1826 {
1827   GstStructure *structure;
1828 
1829   g_return_if_fail (GST_IS_MESSAGE (message));
1830   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1831 
1832   structure = GST_MESSAGE_STRUCTURE (message);
1833   if (format)
1834     *format = (GstFormat)
1835         g_value_get_enum (gst_structure_id_get_value (structure,
1836             GST_QUARK (FORMAT)));
1837   if (position)
1838     *position =
1839         g_value_get_int64 (gst_structure_id_get_value (structure,
1840             GST_QUARK (POSITION)));
1841 }
1842 
1843 /**
1844  * gst_message_parse_segment_done:
1845  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1846  * @format: (out) (allow-none): Result location for the format, or %NULL
1847  * @position: (out) (allow-none): Result location for the position, or %NULL
1848  *
1849  * Extracts the position and format from the segment done message.
1850  *
1851  * MT safe.
1852  */
1853 void
gst_message_parse_segment_done(GstMessage * message,GstFormat * format,gint64 * position)1854 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1855     gint64 * position)
1856 {
1857   GstStructure *structure;
1858 
1859   g_return_if_fail (GST_IS_MESSAGE (message));
1860   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1861 
1862   structure = GST_MESSAGE_STRUCTURE (message);
1863   if (format)
1864     *format = (GstFormat)
1865         g_value_get_enum (gst_structure_id_get_value (structure,
1866             GST_QUARK (FORMAT)));
1867   if (position)
1868     *position =
1869         g_value_get_int64 (gst_structure_id_get_value (structure,
1870             GST_QUARK (POSITION)));
1871 }
1872 
1873 /**
1874  * gst_message_parse_async_done:
1875  * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1876  * @running_time: (out) (allow-none): Result location for the running_time or %NULL
1877  *
1878  * Extract the running_time from the async_done message.
1879  *
1880  * MT safe.
1881  */
1882 void
gst_message_parse_async_done(GstMessage * message,GstClockTime * running_time)1883 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
1884 {
1885   GstStructure *structure;
1886 
1887   g_return_if_fail (GST_IS_MESSAGE (message));
1888   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1889 
1890   structure = GST_MESSAGE_STRUCTURE (message);
1891   if (running_time)
1892     *running_time =
1893         g_value_get_uint64 (gst_structure_id_get_value (structure,
1894             GST_QUARK (RUNNING_TIME)));
1895 }
1896 
1897 /**
1898  * gst_message_parse_request_state:
1899  * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1900  * @state: (out) (allow-none): Result location for the requested state or %NULL
1901  *
1902  * Extract the requested state from the request_state message.
1903  *
1904  * MT safe.
1905  */
1906 void
gst_message_parse_request_state(GstMessage * message,GstState * state)1907 gst_message_parse_request_state (GstMessage * message, GstState * state)
1908 {
1909   GstStructure *structure;
1910 
1911   g_return_if_fail (GST_IS_MESSAGE (message));
1912   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1913 
1914   structure = GST_MESSAGE_STRUCTURE (message);
1915   if (state)
1916     *state = (GstState)
1917         g_value_get_enum (gst_structure_id_get_value (structure,
1918             GST_QUARK (NEW_STATE)));
1919 }
1920 
1921 /**
1922  * gst_message_new_stream_status:
1923  * @src: The object originating the message.
1924  * @type: The stream status type.
1925  * @owner: (transfer none): the owner element of @src.
1926  *
1927  * Create a new stream status message. This message is posted when a streaming
1928  * thread is created/destroyed or when the state changed.
1929  *
1930  * Returns: (transfer full): the new stream status message.
1931  *
1932  * MT safe.
1933  */
1934 GstMessage *
gst_message_new_stream_status(GstObject * src,GstStreamStatusType type,GstElement * owner)1935 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1936     GstElement * owner)
1937 {
1938   GstMessage *message;
1939   GstStructure *structure;
1940 
1941   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1942       GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1943       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1944   message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1945 
1946   return message;
1947 }
1948 
1949 /**
1950  * gst_message_parse_stream_status:
1951  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1952  * @type: (out): A pointer to hold the status type
1953  * @owner: (out) (transfer none): The owner element of the message source
1954  *
1955  * Extracts the stream status type and owner the GstMessage. The returned
1956  * owner remains valid for as long as the reference to @message is valid and
1957  * should thus not be unreffed.
1958  *
1959  * MT safe.
1960  */
1961 void
gst_message_parse_stream_status(GstMessage * message,GstStreamStatusType * type,GstElement ** owner)1962 gst_message_parse_stream_status (GstMessage * message,
1963     GstStreamStatusType * type, GstElement ** owner)
1964 {
1965   const GValue *owner_gvalue;
1966   GstStructure *structure;
1967 
1968   g_return_if_fail (GST_IS_MESSAGE (message));
1969   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1970 
1971   structure = GST_MESSAGE_STRUCTURE (message);
1972   owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1973   g_return_if_fail (owner_gvalue != NULL);
1974 
1975   if (type)
1976     *type = (GstStreamStatusType)
1977         g_value_get_enum (gst_structure_id_get_value (structure,
1978             GST_QUARK (TYPE)));
1979   if (owner)
1980     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1981 }
1982 
1983 /**
1984  * gst_message_set_stream_status_object:
1985  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1986  * @object: the object controlling the streaming
1987  *
1988  * Configures the object handling the streaming thread. This is usually a
1989  * GstTask object but other objects might be added in the future.
1990  */
1991 void
gst_message_set_stream_status_object(GstMessage * message,const GValue * object)1992 gst_message_set_stream_status_object (GstMessage * message,
1993     const GValue * object)
1994 {
1995   GstStructure *structure;
1996 
1997   g_return_if_fail (GST_IS_MESSAGE (message));
1998   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1999 
2000   structure = GST_MESSAGE_STRUCTURE (message);
2001   gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
2002 }
2003 
2004 /**
2005  * gst_message_get_stream_status_object:
2006  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
2007  *
2008  * Extracts the object managing the streaming thread from @message.
2009  *
2010  * Returns: (nullable): a GValue containing the object that manages the
2011  * streaming thread. This object is usually of type GstTask but other types can
2012  * be added in the future. The object remains valid as long as @message is
2013  * valid.
2014  */
2015 const GValue *
gst_message_get_stream_status_object(GstMessage * message)2016 gst_message_get_stream_status_object (GstMessage * message)
2017 {
2018   const GValue *result;
2019   GstStructure *structure;
2020 
2021   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
2022   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
2023       NULL);
2024 
2025   structure = GST_MESSAGE_STRUCTURE (message);
2026   result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
2027 
2028   return result;
2029 }
2030 
2031 /**
2032  * gst_message_new_step_done:
2033  * @src: The object originating the message.
2034  * @format: the format of @amount
2035  * @amount: the amount of stepped data
2036  * @rate: the rate of the stepped amount
2037  * @flush: is this an flushing step
2038  * @intermediate: is this an intermediate step
2039  * @duration: the duration of the data
2040  * @eos: the step caused EOS
2041  *
2042  * This message is posted by elements when they complete a part, when @intermediate set
2043  * to %TRUE, or a complete step operation.
2044  *
2045  * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
2046  * @amount of media in format @format.
2047  *
2048  * Returns: (transfer full): the new step_done message.
2049  *
2050  * MT safe.
2051  */
2052 GstMessage *
gst_message_new_step_done(GstObject * src,GstFormat format,guint64 amount,gdouble rate,gboolean flush,gboolean intermediate,guint64 duration,gboolean eos)2053 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
2054     gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
2055     gboolean eos)
2056 {
2057   GstMessage *message;
2058   GstStructure *structure;
2059 
2060   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
2061       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2062       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
2063       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
2064       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
2065       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
2066       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
2067       GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
2068   message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
2069 
2070   return message;
2071 }
2072 
2073 /**
2074  * gst_message_parse_step_done:
2075  * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
2076  * @format: (out) (allow-none): result location for the format
2077  * @amount: (out) (allow-none): result location for the amount
2078  * @rate: (out) (allow-none): result location for the rate
2079  * @flush: (out) (allow-none): result location for the flush flag
2080  * @intermediate: (out) (allow-none): result location for the intermediate flag
2081  * @duration: (out) (allow-none): result location for the duration
2082  * @eos: (out) (allow-none): result location for the EOS flag
2083  *
2084  * Extract the values the step_done message.
2085  *
2086  * MT safe.
2087  */
2088 void
gst_message_parse_step_done(GstMessage * message,GstFormat * format,guint64 * amount,gdouble * rate,gboolean * flush,gboolean * intermediate,guint64 * duration,gboolean * eos)2089 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
2090     guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
2091     guint64 * duration, gboolean * eos)
2092 {
2093   GstStructure *structure;
2094 
2095   g_return_if_fail (GST_IS_MESSAGE (message));
2096   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
2097 
2098   structure = GST_MESSAGE_STRUCTURE (message);
2099   gst_structure_id_get (structure,
2100       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2101       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
2102       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
2103       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
2104       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
2105       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
2106       GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
2107 }
2108 
2109 /**
2110  * gst_message_new_step_start:
2111  * @src: The object originating the message.
2112  * @active: if the step is active or queued
2113  * @format: the format of @amount
2114  * @amount: the amount of stepped data
2115  * @rate: the rate of the stepped amount
2116  * @flush: is this an flushing step
2117  * @intermediate: is this an intermediate step
2118  *
2119  * This message is posted by elements when they accept or activate a new step
2120  * event for @amount in @format.
2121  *
2122  * @active is set to %FALSE when the element accepted the new step event and has
2123  * queued it for execution in the streaming threads.
2124  *
2125  * @active is set to %TRUE when the element has activated the step operation and
2126  * is now ready to start executing the step in the streaming thread. After this
2127  * message is emitted, the application can queue a new step operation in the
2128  * element.
2129  *
2130  * Returns: (transfer full): The new step_start message.
2131  *
2132  * MT safe.
2133  */
2134 GstMessage *
gst_message_new_step_start(GstObject * src,gboolean active,GstFormat format,guint64 amount,gdouble rate,gboolean flush,gboolean intermediate)2135 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
2136     guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
2137 {
2138   GstMessage *message;
2139   GstStructure *structure;
2140 
2141   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
2142       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
2143       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2144       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
2145       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
2146       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
2147       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
2148   message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
2149 
2150   return message;
2151 }
2152 
2153 /**
2154  * gst_message_parse_step_start:
2155  * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
2156  * @active: (out) (allow-none): result location for the active flag
2157  * @format: (out) (allow-none): result location for the format
2158  * @amount: (out) (allow-none): result location for the amount
2159  * @rate: (out) (allow-none): result location for the rate
2160  * @flush: (out) (allow-none): result location for the flush flag
2161  * @intermediate: (out) (allow-none): result location for the intermediate flag
2162  *
2163  * Extract the values from step_start message.
2164  *
2165  * MT safe.
2166  */
2167 void
gst_message_parse_step_start(GstMessage * message,gboolean * active,GstFormat * format,guint64 * amount,gdouble * rate,gboolean * flush,gboolean * intermediate)2168 gst_message_parse_step_start (GstMessage * message, gboolean * active,
2169     GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
2170     gboolean * intermediate)
2171 {
2172   GstStructure *structure;
2173 
2174   g_return_if_fail (GST_IS_MESSAGE (message));
2175   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
2176 
2177   structure = GST_MESSAGE_STRUCTURE (message);
2178   gst_structure_id_get (structure,
2179       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
2180       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2181       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
2182       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
2183       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
2184       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
2185 }
2186 
2187 /**
2188  * gst_message_new_qos:
2189  * @src: The object originating the message.
2190  * @live: if the message was generated by a live element
2191  * @running_time: the running time of the buffer that generated the message
2192  * @stream_time: the stream time of the buffer that generated the message
2193  * @timestamp: the timestamps of the buffer that generated the message
2194  * @duration: the duration of the buffer that generated the message
2195  *
2196  * A QOS message is posted on the bus whenever an element decides to drop a
2197  * buffer because of QoS reasons or whenever it changes its processing strategy
2198  * because of QoS reasons (quality adjustments such as processing at lower
2199  * accuracy).
2200  *
2201  * This message can be posted by an element that performs synchronisation against the
2202  * clock (live) or it could be dropped by an element that performs QoS because of QOS
2203  * events received from a downstream element (!live).
2204  *
2205  * @running_time, @stream_time, @timestamp, @duration should be set to the
2206  * respective running-time, stream-time, timestamp and duration of the (dropped)
2207  * buffer that generated the QoS event. Values can be left to
2208  * GST_CLOCK_TIME_NONE when unknown.
2209  *
2210  * Returns: (transfer full): The new qos message.
2211  *
2212  * MT safe.
2213  */
2214 GstMessage *
gst_message_new_qos(GstObject * src,gboolean live,guint64 running_time,guint64 stream_time,guint64 timestamp,guint64 duration)2215 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
2216     guint64 stream_time, guint64 timestamp, guint64 duration)
2217 {
2218   GstMessage *message;
2219   GstStructure *structure;
2220 
2221   structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
2222       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2223       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2224       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2225       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2226       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
2227       GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
2228       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
2229       GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
2230       GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
2231       GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
2232       GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
2233   message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
2234 
2235   return message;
2236 }
2237 
2238 /**
2239  * gst_message_set_qos_values:
2240  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2241  * @jitter: The difference of the running-time against the deadline.
2242  * @proportion: Long term prediction of the ideal rate relative to normal rate
2243  * to get optimal quality.
2244  * @quality: An element dependent integer value that specifies the current
2245  * quality level of the element. The default maximum quality is 1000000.
2246  *
2247  * Set the QoS values that have been calculated/analysed from the QoS data
2248  *
2249  * MT safe.
2250  */
2251 void
gst_message_set_qos_values(GstMessage * message,gint64 jitter,gdouble proportion,gint quality)2252 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
2253     gdouble proportion, gint quality)
2254 {
2255   GstStructure *structure;
2256 
2257   g_return_if_fail (GST_IS_MESSAGE (message));
2258   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2259 
2260   structure = GST_MESSAGE_STRUCTURE (message);
2261   gst_structure_id_set (structure,
2262       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2263       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2264       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2265 }
2266 
2267 /**
2268  * gst_message_set_qos_stats:
2269  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2270  * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
2271  * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
2272  * will likely use GST_FORMAT_DEFAULT (samples).
2273  * @processed: Total number of units correctly processed since the last state
2274  * change to READY or a flushing operation.
2275  * @dropped: Total number of units dropped since the last state change to READY
2276  * or a flushing operation.
2277  *
2278  * Set the QoS stats representing the history of the current continuous pipeline
2279  * playback period.
2280  *
2281  * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2282  * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2283  *
2284  * MT safe.
2285  */
2286 void
gst_message_set_qos_stats(GstMessage * message,GstFormat format,guint64 processed,guint64 dropped)2287 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
2288     guint64 processed, guint64 dropped)
2289 {
2290   GstStructure *structure;
2291 
2292   g_return_if_fail (GST_IS_MESSAGE (message));
2293   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2294 
2295   structure = GST_MESSAGE_STRUCTURE (message);
2296   gst_structure_id_set (structure,
2297       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2298       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2299       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2300 }
2301 
2302 /**
2303  * gst_message_parse_qos:
2304  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2305  * @live: (out) (allow-none): if the message was generated by a live element
2306  * @running_time: (out) (allow-none): the running time of the buffer that
2307  *     generated the message
2308  * @stream_time: (out) (allow-none): the stream time of the buffer that
2309  *     generated the message
2310  * @timestamp: (out) (allow-none): the timestamps of the buffer that
2311  *     generated the message
2312  * @duration: (out) (allow-none): the duration of the buffer that
2313  *     generated the message
2314  *
2315  * Extract the timestamps and live status from the QoS message.
2316  *
2317  * The returned values give the running_time, stream_time, timestamp and
2318  * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
2319  * values.
2320  *
2321  * MT safe.
2322  */
2323 void
gst_message_parse_qos(GstMessage * message,gboolean * live,guint64 * running_time,guint64 * stream_time,guint64 * timestamp,guint64 * duration)2324 gst_message_parse_qos (GstMessage * message, gboolean * live,
2325     guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
2326     guint64 * duration)
2327 {
2328   GstStructure *structure;
2329 
2330   g_return_if_fail (GST_IS_MESSAGE (message));
2331   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2332 
2333   structure = GST_MESSAGE_STRUCTURE (message);
2334   gst_structure_id_get (structure,
2335       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
2336       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
2337       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
2338       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
2339       GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
2340 }
2341 
2342 /**
2343  * gst_message_parse_qos_values:
2344  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2345  * @jitter: (out) (allow-none): The difference of the running-time against
2346  *     the deadline.
2347  * @proportion: (out) (allow-none): Long term prediction of the ideal rate
2348  *     relative to normal rate to get optimal quality.
2349  * @quality: (out) (allow-none): An element dependent integer value that
2350  *     specifies the current quality level of the element. The default
2351  *     maximum quality is 1000000.
2352  *
2353  * Extract the QoS values that have been calculated/analysed from the QoS data
2354  *
2355  * MT safe.
2356  */
2357 void
gst_message_parse_qos_values(GstMessage * message,gint64 * jitter,gdouble * proportion,gint * quality)2358 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
2359     gdouble * proportion, gint * quality)
2360 {
2361   GstStructure *structure;
2362 
2363   g_return_if_fail (GST_IS_MESSAGE (message));
2364   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2365 
2366   structure = GST_MESSAGE_STRUCTURE (message);
2367   gst_structure_id_get (structure,
2368       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
2369       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
2370       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
2371 }
2372 
2373 /**
2374  * gst_message_parse_qos_stats:
2375  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
2376  * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
2377  *     Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
2378  *     Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
2379  *     (samples).
2380  * @processed: (out) (allow-none): Total number of units correctly processed
2381  *     since the last state change to READY or a flushing operation.
2382  * @dropped: (out) (allow-none): Total number of units dropped since the last
2383  *     state change to READY or a flushing operation.
2384  *
2385  * Extract the QoS stats representing the history of the current continuous
2386  * pipeline playback period.
2387  *
2388  * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
2389  * invalid. Values of -1 for either @processed or @dropped mean unknown values.
2390  *
2391  * MT safe.
2392  */
2393 void
gst_message_parse_qos_stats(GstMessage * message,GstFormat * format,guint64 * processed,guint64 * dropped)2394 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
2395     guint64 * processed, guint64 * dropped)
2396 {
2397   GstStructure *structure;
2398 
2399   g_return_if_fail (GST_IS_MESSAGE (message));
2400   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
2401 
2402   structure = GST_MESSAGE_STRUCTURE (message);
2403   gst_structure_id_get (structure,
2404       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
2405       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
2406       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
2407 }
2408 
2409 /**
2410  * gst_message_new_progress:
2411  * @src: The object originating the message.
2412  * @type: a #GstProgressType
2413  * @code: a progress code
2414  * @text: free, user visible text describing the progress
2415  *
2416  * Progress messages are posted by elements when they use an asynchronous task
2417  * to perform actions triggered by a state change.
2418  *
2419  * @code contains a well defined string describing the action.
2420  * @text should contain a user visible string detailing the current action.
2421  *
2422  * Returns: (transfer full) (nullable): The new qos message.
2423  */
2424 GstMessage *
gst_message_new_progress(GstObject * src,GstProgressType type,const gchar * code,const gchar * text)2425 gst_message_new_progress (GstObject * src, GstProgressType type,
2426     const gchar * code, const gchar * text)
2427 {
2428   GstMessage *message;
2429   GstStructure *structure;
2430   gint percent = 100, timeout = -1;
2431 
2432   g_return_val_if_fail (code != NULL, NULL);
2433   g_return_val_if_fail (text != NULL, NULL);
2434 
2435   if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2436     percent = 0;
2437 
2438   structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2439       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2440       GST_QUARK (CODE), G_TYPE_STRING, code,
2441       GST_QUARK (TEXT), G_TYPE_STRING, text,
2442       GST_QUARK (PERCENT), G_TYPE_INT, percent,
2443       GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2444   message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2445 
2446   return message;
2447 }
2448 
2449 /**
2450  * gst_message_parse_progress:
2451  * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2452  * @type: (out) (allow-none): location for the type
2453  * @code: (out) (allow-none) (transfer full): location for the code
2454  * @text: (out) (allow-none) (transfer full): location for the text
2455  *
2456  * Parses the progress @type, @code and @text.
2457  */
2458 void
gst_message_parse_progress(GstMessage * message,GstProgressType * type,gchar ** code,gchar ** text)2459 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2460     gchar ** code, gchar ** text)
2461 {
2462   GstStructure *structure;
2463 
2464   g_return_if_fail (GST_IS_MESSAGE (message));
2465   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2466 
2467   structure = GST_MESSAGE_STRUCTURE (message);
2468   gst_structure_id_get (structure,
2469       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2470       GST_QUARK (CODE), G_TYPE_STRING, code,
2471       GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2472 }
2473 
2474 /**
2475  * gst_message_new_toc:
2476  * @src: the object originating the message.
2477  * @toc: (transfer none): #GstToc structure for the message.
2478  * @updated: whether TOC was updated or not.
2479  *
2480  * Create a new TOC message. The message is posted by elements
2481  * that discovered or updated a TOC.
2482  *
2483  * Returns: (transfer full): a new TOC message.
2484  *
2485  * MT safe.
2486  */
2487 GstMessage *
gst_message_new_toc(GstObject * src,GstToc * toc,gboolean updated)2488 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2489 {
2490   GstStructure *toc_struct;
2491 
2492   g_return_val_if_fail (toc != NULL, NULL);
2493 
2494   toc_struct = gst_structure_new_id (GST_QUARK (MESSAGE_TOC),
2495       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2496       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2497 
2498   return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2499 }
2500 
2501 /**
2502  * gst_message_parse_toc:
2503  * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2504  * @toc: (out) (transfer full): return location for the TOC.
2505  * @updated: (out): return location for the updated flag.
2506  *
2507  * Extract the TOC from the #GstMessage. The TOC returned in the
2508  * output argument is a copy; the caller must free it with
2509  * gst_toc_unref() when done.
2510  *
2511  * MT safe.
2512  */
2513 void
gst_message_parse_toc(GstMessage * message,GstToc ** toc,gboolean * updated)2514 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2515 {
2516   g_return_if_fail (GST_IS_MESSAGE (message));
2517   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2518   g_return_if_fail (toc != NULL);
2519 
2520   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2521       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2522       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2523 }
2524 
2525 /**
2526  * gst_message_new_reset_time:
2527  * @src: (transfer none) (allow-none): The object originating the message.
2528  * @running_time: the requested running-time
2529  *
2530  * This message is posted when the pipeline running-time should be reset to
2531  * @running_time, like after a flushing seek.
2532  *
2533  * Returns: (transfer full): The new reset_time message.
2534  *
2535  * MT safe.
2536  */
2537 GstMessage *
gst_message_new_reset_time(GstObject * src,GstClockTime running_time)2538 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2539 {
2540   GstMessage *message;
2541   GstStructure *structure;
2542 
2543   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (running_time), NULL);
2544 
2545   structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2546       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2547   message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2548 
2549   return message;
2550 }
2551 
2552 /**
2553  * gst_message_parse_reset_time:
2554  * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2555  * @running_time: (out) (allow-none): Result location for the running_time or
2556  *      %NULL
2557  *
2558  * Extract the running-time from the RESET_TIME message.
2559  *
2560  * MT safe.
2561  */
2562 void
gst_message_parse_reset_time(GstMessage * message,GstClockTime * running_time)2563 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2564 {
2565   GstStructure *structure;
2566 
2567   g_return_if_fail (GST_IS_MESSAGE (message));
2568   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2569 
2570   structure = GST_MESSAGE_STRUCTURE (message);
2571   if (running_time)
2572     *running_time =
2573         g_value_get_uint64 (gst_structure_id_get_value (structure,
2574             GST_QUARK (RUNNING_TIME)));
2575 }
2576 
2577 /**
2578  * gst_message_new_stream_start:
2579  * @src: (transfer none) (allow-none): The object originating the message.
2580  *
2581  * Create a new stream_start message. This message is generated and posted in
2582  * the sink elements of a GstBin. The bin will only forward the STREAM_START
2583  * message to the application if all sinks have posted an STREAM_START message.
2584  *
2585  * Returns: (transfer full): The new stream_start message.
2586  *
2587  * MT safe.
2588  */
2589 GstMessage *
gst_message_new_stream_start(GstObject * src)2590 gst_message_new_stream_start (GstObject * src)
2591 {
2592   GstMessage *message;
2593   GstStructure *s;
2594 
2595   s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_STREAM_START));
2596   message = gst_message_new_custom (GST_MESSAGE_STREAM_START, src, s);
2597 
2598   return message;
2599 }
2600 
2601 
2602 /**
2603  * gst_message_set_group_id:
2604  * @message: the message
2605  * @group_id: the group id
2606  *
2607  * Sets the group id on the stream-start message.
2608  *
2609  * All streams that have the same group id are supposed to be played
2610  * together, i.e. all streams inside a container file should have the
2611  * same group id but different stream ids. The group id should change
2612  * each time the stream is started, resulting in different group ids
2613  * each time a file is played for example.
2614  *
2615  * MT safe.
2616  *
2617  * Since: 1.2
2618  */
2619 void
gst_message_set_group_id(GstMessage * message,guint group_id)2620 gst_message_set_group_id (GstMessage * message, guint group_id)
2621 {
2622   GstStructure *structure;
2623 
2624   g_return_if_fail (GST_IS_MESSAGE (message));
2625   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START);
2626   g_return_if_fail (gst_message_is_writable (message));
2627   g_return_if_fail (group_id != GST_GROUP_ID_INVALID);
2628 
2629   structure = GST_MESSAGE_STRUCTURE (message);
2630   gst_structure_id_set (structure, GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id,
2631       NULL);
2632 }
2633 
2634 /**
2635  * gst_message_parse_group_id:
2636  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_START.
2637  * @group_id: (out) (allow-none): Result location for the group id or
2638  *      %NULL
2639  *
2640  * Extract the group from the STREAM_START message.
2641  *
2642  * Returns: %TRUE if the message had a group id set, %FALSE otherwise
2643  *
2644  * MT safe.
2645  *
2646  * Since: 1.2
2647  */
2648 gboolean
gst_message_parse_group_id(GstMessage * message,guint * group_id)2649 gst_message_parse_group_id (GstMessage * message, guint * group_id)
2650 {
2651   GstStructure *structure;
2652   const GValue *v;
2653 
2654   g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
2655   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START,
2656       FALSE);
2657 
2658   if (!group_id)
2659     return TRUE;
2660 
2661   *group_id = 0;
2662 
2663   structure = GST_MESSAGE_STRUCTURE (message);
2664 
2665   v = gst_structure_id_get_value (structure, GST_QUARK (GROUP_ID));
2666   if (!v)
2667     return FALSE;
2668 
2669   *group_id = g_value_get_uint (v);
2670   return TRUE;
2671 }
2672 
2673 /**
2674  * gst_message_new_need_context:
2675  * @src: (transfer none) (allow-none): The object originating the message.
2676  * @context_type: The context type that is needed
2677  *
2678  * This message is posted when an element needs a specific #GstContext.
2679  *
2680  * Returns: (transfer full): The new need-context message.
2681  *
2682  * MT safe.
2683  *
2684  * Since: 1.2
2685  */
2686 GstMessage *
gst_message_new_need_context(GstObject * src,const gchar * context_type)2687 gst_message_new_need_context (GstObject * src, const gchar * context_type)
2688 {
2689   GstMessage *message;
2690   GstStructure *structure;
2691 
2692   g_return_val_if_fail (context_type != NULL, NULL);
2693 
2694   structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEED_CONTEXT),
2695       GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2696   message = gst_message_new_custom (GST_MESSAGE_NEED_CONTEXT, src, structure);
2697 
2698   return message;
2699 }
2700 
2701 /**
2702  * gst_message_parse_context_type:
2703  * @message: a GST_MESSAGE_NEED_CONTEXT type message
2704  * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2705  *
2706  * Parse a context type from an existing GST_MESSAGE_NEED_CONTEXT message.
2707  *
2708  * Returns: a #gboolean indicating if the parsing succeeded.
2709  *
2710  * Since: 1.2
2711  */
2712 gboolean
gst_message_parse_context_type(GstMessage * message,const gchar ** context_type)2713 gst_message_parse_context_type (GstMessage * message,
2714     const gchar ** context_type)
2715 {
2716   GstStructure *structure;
2717   const GValue *value;
2718 
2719   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT,
2720       FALSE);
2721 
2722   structure = GST_MESSAGE_STRUCTURE (message);
2723 
2724   if (context_type) {
2725     value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2726     *context_type = g_value_get_string (value);
2727   }
2728 
2729   return TRUE;
2730 }
2731 
2732 /**
2733  * gst_message_new_have_context:
2734  * @src: (transfer none) (allow-none): The object originating the message.
2735  * @context: (transfer full): the context
2736  *
2737  * This message is posted when an element has a new local #GstContext.
2738  *
2739  * Returns: (transfer full): The new have-context message.
2740  *
2741  * MT safe.
2742  *
2743  * Since: 1.2
2744  */
2745 GstMessage *
gst_message_new_have_context(GstObject * src,GstContext * context)2746 gst_message_new_have_context (GstObject * src, GstContext * context)
2747 {
2748   GstMessage *message;
2749   GstStructure *structure;
2750 
2751   structure = gst_structure_new_id (GST_QUARK (MESSAGE_HAVE_CONTEXT),
2752       GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2753   message = gst_message_new_custom (GST_MESSAGE_HAVE_CONTEXT, src, structure);
2754   gst_context_unref (context);
2755 
2756   return message;
2757 }
2758 
2759 /**
2760  * gst_message_parse_have_context:
2761  * @message: A valid #GstMessage of type GST_MESSAGE_HAVE_CONTEXT.
2762  * @context: (out) (transfer full) (allow-none): Result location for the
2763  *      context or %NULL
2764  *
2765  * Extract the context from the HAVE_CONTEXT message.
2766  *
2767  * MT safe.
2768  *
2769  * Since: 1.2
2770  */
2771 void
gst_message_parse_have_context(GstMessage * message,GstContext ** context)2772 gst_message_parse_have_context (GstMessage * message, GstContext ** context)
2773 {
2774   g_return_if_fail (GST_IS_MESSAGE (message));
2775   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_HAVE_CONTEXT);
2776 
2777   if (context)
2778     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2779         GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2780 }
2781 
2782 /**
2783  * gst_message_new_device_added:
2784  * @src: The #GstObject that created the message
2785  * @device: (transfer none): The new #GstDevice
2786  *
2787  * Creates a new device-added message. The device-added message is produced by
2788  * #GstDeviceProvider or a #GstDeviceMonitor. They announce the appearance
2789  * of monitored devices.
2790  *
2791  * Returns: a newly allocated #GstMessage
2792  *
2793  * Since: 1.4
2794  */
2795 GstMessage *
gst_message_new_device_added(GstObject * src,GstDevice * device)2796 gst_message_new_device_added (GstObject * src, GstDevice * device)
2797 {
2798   GstMessage *message;
2799   GstStructure *structure;
2800 
2801   g_return_val_if_fail (device != NULL, NULL);
2802   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2803 
2804   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_ADDED),
2805       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2806   message = gst_message_new_custom (GST_MESSAGE_DEVICE_ADDED, src, structure);
2807 
2808   return message;
2809 }
2810 
2811 /**
2812  * gst_message_parse_device_added:
2813  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_ADDED
2814  * @device: (out) (allow-none) (transfer full): A location where to store a
2815  *  pointer to the new #GstDevice, or %NULL
2816  *
2817  * Parses a device-added message. The device-added message is produced by
2818  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the appearance
2819  * of monitored devices.
2820  *
2821  * Since: 1.4
2822  */
2823 void
gst_message_parse_device_added(GstMessage * message,GstDevice ** device)2824 gst_message_parse_device_added (GstMessage * message, GstDevice ** device)
2825 {
2826   g_return_if_fail (GST_IS_MESSAGE (message));
2827   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_ADDED);
2828 
2829   if (device)
2830     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2831         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2832 }
2833 
2834 /**
2835  * gst_message_new_device_removed:
2836  * @src: The #GstObject that created the message
2837  * @device: (transfer none): The removed #GstDevice
2838  *
2839  * Creates a new device-removed message. The device-removed message is produced
2840  * by #GstDeviceProvider or a #GstDeviceMonitor. They announce the
2841  * disappearance of monitored devices.
2842  *
2843  * Returns: a newly allocated #GstMessage
2844  *
2845  * Since: 1.4
2846  */
2847 GstMessage *
gst_message_new_device_removed(GstObject * src,GstDevice * device)2848 gst_message_new_device_removed (GstObject * src, GstDevice * device)
2849 {
2850   GstMessage *message;
2851   GstStructure *structure;
2852 
2853   g_return_val_if_fail (device != NULL, NULL);
2854   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2855 
2856   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_REMOVED),
2857       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2858   message = gst_message_new_custom (GST_MESSAGE_DEVICE_REMOVED, src, structure);
2859 
2860   return message;
2861 }
2862 
2863 /**
2864  * gst_message_parse_device_removed:
2865  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_REMOVED
2866  * @device: (out) (allow-none) (transfer full): A location where to store a
2867  *  pointer to the removed #GstDevice, or %NULL
2868  *
2869  * Parses a device-removed message. The device-removed message is produced by
2870  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the
2871  * disappearance of monitored devices.
2872  *
2873  * Since: 1.4
2874  */
2875 void
gst_message_parse_device_removed(GstMessage * message,GstDevice ** device)2876 gst_message_parse_device_removed (GstMessage * message, GstDevice ** device)
2877 {
2878   g_return_if_fail (GST_IS_MESSAGE (message));
2879   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_REMOVED);
2880 
2881   if (device)
2882     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2883         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2884 }
2885 
2886 /**
2887  * gst_message_new_device_changed:
2888  * @src: The #GstObject that created the message
2889  * @device: (transfer none): The newly created device representing @replaced_device
2890  *         with its new configuration.
2891  *
2892  * Creates a new device-changed message. The device-changed message is produced
2893  * by #GstDeviceProvider or a #GstDeviceMonitor. They announce that a device
2894  * properties has changed and @device represent the new modified version of @changed_device.
2895  *
2896  * Returns: a newly allocated #GstMessage
2897  *
2898  * Since: 1.16
2899  */
2900 GstMessage *
gst_message_new_device_changed(GstObject * src,GstDevice * device,GstDevice * changed_device)2901 gst_message_new_device_changed (GstObject * src, GstDevice * device,
2902     GstDevice * changed_device)
2903 {
2904   GstMessage *message;
2905   GstStructure *structure;
2906 
2907   g_return_val_if_fail (device != NULL, NULL);
2908   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2909 
2910   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_CHANGED),
2911       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device,
2912       GST_QUARK (DEVICE_CHANGED), GST_TYPE_DEVICE, changed_device, NULL);
2913   message = gst_message_new_custom (GST_MESSAGE_DEVICE_CHANGED, src, structure);
2914 
2915   return message;
2916 }
2917 
2918 /**
2919  * gst_message_parse_device_changed:
2920  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_CHANGED
2921  * @device: (out) (allow-none) (transfer full): A location where to store a
2922  *  pointer to the updated version of the #GstDevice, or %NULL
2923  * @changed_device: (out) (allow-none) (transfer full): A location where to store a
2924  *  pointer to the old version of the #GstDevice, or %NULL
2925  *
2926  * Parses a device-changed message. The device-changed message is produced by
2927  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the
2928  * disappearance of monitored devices. * It announce that a device properties has
2929  * changed and @device represents the new modified version of @changed_device.
2930  *
2931  * Since: 1.16
2932  */
2933 void
gst_message_parse_device_changed(GstMessage * message,GstDevice ** device,GstDevice ** changed_device)2934 gst_message_parse_device_changed (GstMessage * message, GstDevice ** device,
2935     GstDevice ** changed_device)
2936 {
2937   g_return_if_fail (GST_IS_MESSAGE (message));
2938   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_CHANGED);
2939 
2940   if (device)
2941     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2942         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2943 
2944   if (changed_device)
2945     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2946         GST_QUARK (DEVICE_CHANGED), GST_TYPE_DEVICE, changed_device, NULL);
2947 }
2948 
2949 /**
2950  * gst_message_new_property_notify:
2951  * @src: The #GstObject whose property changed (may or may not be a #GstElement)
2952  * @property_name: name of the property that changed
2953  * @val: (allow-none) (transfer full): new property value, or %NULL
2954  *
2955  * Returns: a newly allocated #GstMessage
2956  *
2957  * Since: 1.10
2958  */
2959 GstMessage *
gst_message_new_property_notify(GstObject * src,const gchar * property_name,GValue * val)2960 gst_message_new_property_notify (GstObject * src, const gchar * property_name,
2961     GValue * val)
2962 {
2963   GstStructure *structure;
2964   GValue name_val = G_VALUE_INIT;
2965 
2966   g_return_val_if_fail (property_name != NULL, NULL);
2967 
2968   structure = gst_structure_new_id_empty (GST_QUARK (MESSAGE_PROPERTY_NOTIFY));
2969   g_value_init (&name_val, G_TYPE_STRING);
2970   /* should already be interned, but let's make sure */
2971   g_value_set_static_string (&name_val, g_intern_string (property_name));
2972   gst_structure_id_take_value (structure, GST_QUARK (PROPERTY_NAME), &name_val);
2973   if (val != NULL)
2974     gst_structure_id_take_value (structure, GST_QUARK (PROPERTY_VALUE), val);
2975 
2976   return gst_message_new_custom (GST_MESSAGE_PROPERTY_NOTIFY, src, structure);
2977 }
2978 
2979 /**
2980  * gst_message_parse_property_notify:
2981  * @message: a #GstMessage of type %GST_MESSAGE_PROPERTY_NOTIFY
2982  * @object: (out) (allow-none) (transfer none): location where to store a
2983  *     pointer to the object whose property got changed, or %NULL
2984  * @property_name: (out) (transfer none) (allow-none): return location for
2985  *     the name of the property that got changed, or %NULL
2986  * @property_value: (out) (transfer none) (allow-none): return location for
2987  *     the new value of the property that got changed, or %NULL. This will
2988  *     only be set if the property notify watch was told to include the value
2989  *     when it was set up
2990  *
2991  * Parses a property-notify message. These will be posted on the bus only
2992  * when set up with gst_element_add_property_notify_watch() or
2993  * gst_element_add_property_deep_notify_watch().
2994  *
2995  * Since: 1.10
2996  */
2997 void
gst_message_parse_property_notify(GstMessage * message,GstObject ** object,const gchar ** property_name,const GValue ** property_value)2998 gst_message_parse_property_notify (GstMessage * message, GstObject ** object,
2999     const gchar ** property_name, const GValue ** property_value)
3000 {
3001   const GstStructure *s = GST_MESSAGE_STRUCTURE (message);
3002 
3003   g_return_if_fail (GST_IS_MESSAGE (message));
3004   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROPERTY_NOTIFY);
3005 
3006   if (object)
3007     *object = GST_MESSAGE_SRC (message);
3008 
3009   if (property_name) {
3010     const GValue *name_value;
3011 
3012     name_value = gst_structure_id_get_value (s, GST_QUARK (PROPERTY_NAME));
3013     *property_name = g_value_get_string (name_value);
3014   }
3015 
3016   if (property_value)
3017     *property_value =
3018         gst_structure_id_get_value (s, GST_QUARK (PROPERTY_VALUE));
3019 }
3020 
3021 /**
3022  * gst_message_new_stream_collection:
3023  * @src: The #GstObject that created the message
3024  * @collection: (transfer none): The #GstStreamCollection
3025  *
3026  * Creates a new stream-collection message. The message is used to announce new
3027  * #GstStreamCollection
3028  *
3029  * Returns: a newly allocated #GstMessage
3030  *
3031  * Since: 1.10
3032  */
3033 GstMessage *
gst_message_new_stream_collection(GstObject * src,GstStreamCollection * collection)3034 gst_message_new_stream_collection (GstObject * src,
3035     GstStreamCollection * collection)
3036 {
3037   GstMessage *message;
3038   GstStructure *structure;
3039 
3040   g_return_val_if_fail (collection != NULL, NULL);
3041   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
3042 
3043   structure =
3044       gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_COLLECTION),
3045       GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
3046   message =
3047       gst_message_new_custom (GST_MESSAGE_STREAM_COLLECTION, src, structure);
3048 
3049   return message;
3050 }
3051 
3052 /**
3053  * gst_message_parse_stream_collection:
3054  * @message: a #GstMessage of type %GST_MESSAGE_STREAM_COLLECTION
3055  * @collection: (out) (allow-none) (transfer full): A location where to store a
3056  *  pointer to the #GstStreamCollection, or %NULL
3057  *
3058  * Parses a stream-collection message.
3059  *
3060  * Since: 1.10
3061  */
3062 void
gst_message_parse_stream_collection(GstMessage * message,GstStreamCollection ** collection)3063 gst_message_parse_stream_collection (GstMessage * message,
3064     GstStreamCollection ** collection)
3065 {
3066   g_return_if_fail (GST_IS_MESSAGE (message));
3067   g_return_if_fail (GST_MESSAGE_TYPE (message) ==
3068       GST_MESSAGE_STREAM_COLLECTION);
3069 
3070   if (collection)
3071     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
3072         GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
3073 }
3074 
3075 /**
3076  * gst_message_new_streams_selected:
3077  * @src: The #GstObject that created the message
3078  * @collection: (transfer none): The #GstStreamCollection
3079  *
3080  * Creates a new steams-selected message. The message is used to announce
3081  * that an array of streams has been selected. This is generally in response
3082  * to a #GST_EVENT_SELECT_STREAMS event, or when an element (such as decodebin3)
3083  * makes an initial selection of streams.
3084  *
3085  * The message also contains the #GstStreamCollection to which the various streams
3086  * belong to.
3087  *
3088  * Users of gst_message_new_streams_selected() can add the selected streams with
3089  * gst_message_streams_selected_add().
3090  *
3091  * Returns: a newly allocated #GstMessage
3092  *
3093  * Since: 1.10
3094  */
3095 GstMessage *
gst_message_new_streams_selected(GstObject * src,GstStreamCollection * collection)3096 gst_message_new_streams_selected (GstObject * src,
3097     GstStreamCollection * collection)
3098 {
3099   GstMessage *message;
3100   GstStructure *structure;
3101   GValue val = G_VALUE_INIT;
3102 
3103   g_return_val_if_fail (collection != NULL, NULL);
3104   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
3105 
3106   structure =
3107       gst_structure_new_id (GST_QUARK (MESSAGE_STREAMS_SELECTED),
3108       GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
3109   g_value_init (&val, GST_TYPE_ARRAY);
3110   gst_structure_id_take_value (structure, GST_QUARK (STREAMS), &val);
3111   message =
3112       gst_message_new_custom (GST_MESSAGE_STREAMS_SELECTED, src, structure);
3113 
3114   return message;
3115 }
3116 
3117 /**
3118  * gst_message_streams_selected_get_size:
3119  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
3120  *
3121  * Returns the number of streams contained in the @message.
3122  *
3123  * Returns: The number of streams contained within.
3124  *
3125  * Since: 1.10
3126  */
3127 guint
gst_message_streams_selected_get_size(GstMessage * msg)3128 gst_message_streams_selected_get_size (GstMessage * msg)
3129 {
3130   const GValue *val;
3131 
3132   g_return_val_if_fail (GST_IS_MESSAGE (msg), 0);
3133   g_return_val_if_fail (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED,
3134       0);
3135 
3136   val =
3137       gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (msg),
3138       GST_QUARK (STREAMS));
3139   return gst_value_array_get_size (val);
3140 }
3141 
3142 /**
3143  * gst_message_streams_selected_add:
3144  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
3145  * @stream: (transfer none): a #GstStream to add to @message
3146  *
3147  * Adds the @stream to the @message.
3148  *
3149  * Since: 1.10
3150  */
3151 void
gst_message_streams_selected_add(GstMessage * msg,GstStream * stream)3152 gst_message_streams_selected_add (GstMessage * msg, GstStream * stream)
3153 {
3154   GValue *val;
3155   GValue to_add = G_VALUE_INIT;
3156 
3157   g_return_if_fail (GST_IS_MESSAGE (msg));
3158   g_return_if_fail (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED);
3159   g_return_if_fail (GST_IS_STREAM (stream));
3160 
3161   val =
3162       (GValue *) gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (msg),
3163       GST_QUARK (STREAMS));
3164   g_value_init (&to_add, GST_TYPE_STREAM);
3165   g_value_set_object (&to_add, stream);
3166   gst_value_array_append_and_take_value (val, &to_add);
3167 }
3168 
3169 /**
3170  * gst_message_streams_selected_get_stream:
3171  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
3172  * @idx: Index of the stream to retrieve
3173  *
3174  * Retrieves the #GstStream with index @index from the @message.
3175  *
3176  * Returns: (transfer full) (nullable): A #GstStream
3177  *
3178  * Since: 1.10
3179  */
3180 GstStream *
gst_message_streams_selected_get_stream(GstMessage * msg,guint idx)3181 gst_message_streams_selected_get_stream (GstMessage * msg, guint idx)
3182 {
3183   const GValue *streams, *val;
3184 
3185   g_return_val_if_fail (GST_IS_MESSAGE (msg), NULL);
3186   g_return_val_if_fail (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED,
3187       NULL);
3188 
3189   streams =
3190       gst_structure_id_get_value (GST_MESSAGE_STRUCTURE (msg),
3191       GST_QUARK (STREAMS));
3192   val = gst_value_array_get_value (streams, idx);
3193   if (val) {
3194     return (GstStream *) g_value_dup_object (val);
3195   }
3196 
3197   return NULL;
3198 }
3199 
3200 /**
3201  * gst_message_parse_streams_selected:
3202  * @message: a #GstMessage of type %GST_MESSAGE_STREAMS_SELECTED
3203  * @collection: (out) (allow-none) (transfer full): A location where to store a
3204  *  pointer to the #GstStreamCollection, or %NULL
3205  *
3206  * Parses a streams-selected message.
3207  *
3208  * Since: 1.10
3209  */
3210 void
gst_message_parse_streams_selected(GstMessage * message,GstStreamCollection ** collection)3211 gst_message_parse_streams_selected (GstMessage * message,
3212     GstStreamCollection ** collection)
3213 {
3214   g_return_if_fail (GST_IS_MESSAGE (message));
3215   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAMS_SELECTED);
3216 
3217   if (collection)
3218     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
3219         GST_QUARK (COLLECTION), GST_TYPE_STREAM_COLLECTION, collection, NULL);
3220 }
3221 
3222 /**
3223  * gst_message_new_redirect:
3224  * @src: The #GstObject whose property changed (may or may not be a #GstElement)
3225  * @location: (transfer none): location string for the new entry
3226  * @tag_list: (transfer full) (allow-none): tag list for the new entry
3227  * @entry_struct: (transfer full) (allow-none): structure for the new entry
3228  *
3229  * Creates a new redirect message and adds a new entry to it. Redirect messages
3230  * are posted when an element detects that the actual data has to be retrieved
3231  * from a different location. This is useful if such a redirection cannot be
3232  * handled inside a source element, for example when HTTP 302/303 redirects
3233  * return a non-HTTP URL.
3234  *
3235  * The redirect message can hold multiple entries. The first one is added
3236  * when the redirect message is created, with the given location, tag_list,
3237  * entry_struct arguments. Use gst_message_add_redirect_entry() to add more
3238  * entries.
3239  *
3240  * Each entry has a location, a tag list, and a structure. All of these are
3241  * optional. The tag list and structure are useful for additional metadata,
3242  * such as bitrate statistics for the given location.
3243  *
3244  * By default, message recipients should treat entries in the order they are
3245  * stored. The recipient should therefore try entry \#0 first, and if this
3246  * entry is not acceptable or working, try entry \#1 etc. Senders must make
3247  * sure that they add entries in this order. However, recipients are free to
3248  * ignore the order and pick an entry that is "best" for them. One example
3249  * would be a recipient that scans the entries for the one with the highest
3250  * bitrate tag.
3251  *
3252  * The specified location string is copied. However, ownership over the tag
3253  * list and structure are transferred to the message.
3254  *
3255  * Returns: a newly allocated #GstMessage
3256  *
3257  * Since: 1.10
3258  */
3259 GstMessage *
gst_message_new_redirect(GstObject * src,const gchar * location,GstTagList * tag_list,const GstStructure * entry_struct)3260 gst_message_new_redirect (GstObject * src, const gchar * location,
3261     GstTagList * tag_list, const GstStructure * entry_struct)
3262 {
3263   GstStructure *structure;
3264   GstMessage *message;
3265   GValue entry_locations_gvalue = G_VALUE_INIT;
3266   GValue entry_taglists_gvalue = G_VALUE_INIT;
3267   GValue entry_structures_gvalue = G_VALUE_INIT;
3268 
3269   g_return_val_if_fail (location != NULL, NULL);
3270 
3271   g_value_init (&entry_locations_gvalue, GST_TYPE_LIST);
3272   g_value_init (&entry_taglists_gvalue, GST_TYPE_LIST);
3273   g_value_init (&entry_structures_gvalue, GST_TYPE_LIST);
3274 
3275   structure = gst_structure_new_id_empty (GST_QUARK (MESSAGE_REDIRECT));
3276   gst_structure_id_take_value (structure, GST_QUARK (REDIRECT_ENTRY_LOCATIONS),
3277       &entry_locations_gvalue);
3278   gst_structure_id_take_value (structure, GST_QUARK (REDIRECT_ENTRY_TAGLISTS),
3279       &entry_taglists_gvalue);
3280   gst_structure_id_take_value (structure, GST_QUARK (REDIRECT_ENTRY_STRUCTURES),
3281       &entry_structures_gvalue);
3282 
3283   message = gst_message_new_custom (GST_MESSAGE_REDIRECT, src, structure);
3284   g_assert (message != NULL);
3285 
3286   gst_message_add_redirect_entry (message, location, tag_list, entry_struct);
3287 
3288   return message;
3289 }
3290 
3291 /**
3292  * gst_message_add_redirect_entry:
3293  * @message: a #GstMessage of type %GST_MESSAGE_REDIRECT
3294  * @location: (transfer none): location string for the new entry
3295  * @tag_list: (transfer full) (allow-none): tag list for the new entry
3296  * @entry_struct: (transfer full) (allow-none): structure for the new entry
3297  *
3298  * Creates and appends a new entry.
3299  *
3300  * The specified location string is copied. However, ownership over the tag
3301  * list and structure are transferred to the message.
3302  *
3303  * Since: 1.10
3304  */
3305 void
gst_message_add_redirect_entry(GstMessage * message,const gchar * location,GstTagList * tag_list,const GstStructure * entry_struct)3306 gst_message_add_redirect_entry (GstMessage * message, const gchar * location,
3307     GstTagList * tag_list, const GstStructure * entry_struct)
3308 {
3309   GValue val = G_VALUE_INIT;
3310   GstStructure *structure;
3311   GValue *entry_locations_gvalue;
3312   GValue *entry_taglists_gvalue;
3313   GValue *entry_structures_gvalue;
3314 
3315   g_return_if_fail (location != NULL);
3316   g_return_if_fail (GST_IS_MESSAGE (message));
3317   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REDIRECT);
3318 
3319   structure = GST_MESSAGE_STRUCTURE (message);
3320 
3321   entry_locations_gvalue =
3322       (GValue *) gst_structure_id_get_value (structure,
3323       GST_QUARK (REDIRECT_ENTRY_LOCATIONS));
3324   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_locations_gvalue));
3325   entry_taglists_gvalue =
3326       (GValue *) gst_structure_id_get_value (structure,
3327       GST_QUARK (REDIRECT_ENTRY_TAGLISTS));
3328   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_taglists_gvalue));
3329   entry_structures_gvalue =
3330       (GValue *) gst_structure_id_get_value (structure,
3331       GST_QUARK (REDIRECT_ENTRY_STRUCTURES));
3332   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_structures_gvalue));
3333 
3334   g_value_init (&val, G_TYPE_STRING);
3335   if (location)
3336     g_value_set_string (&val, location);
3337   gst_value_list_append_and_take_value (entry_locations_gvalue, &val);
3338 
3339   g_value_init (&val, GST_TYPE_TAG_LIST);
3340   if (tag_list)
3341     g_value_take_boxed (&val, tag_list);
3342   gst_value_list_append_and_take_value (entry_taglists_gvalue, &val);
3343 
3344   g_value_init (&val, GST_TYPE_STRUCTURE);
3345   if (entry_struct)
3346     g_value_take_boxed (&val, entry_struct);
3347   gst_value_list_append_and_take_value (entry_structures_gvalue, &val);
3348 }
3349 
3350 /**
3351  * gst_message_parse_redirect_entry:
3352  * @message: a #GstMessage of type %GST_MESSAGE_REDIRECT
3353  * @entry_index: index of the entry to parse
3354  * @location: (out) (transfer none) (allow-none): return location for
3355  *     the pointer to the entry's location string, or %NULL
3356  * @tag_list: (out) (transfer none) (allow-none): return location for
3357  *     the pointer to the entry's tag list, or %NULL
3358  * @entry_struct: (out) (transfer none) (allow-none): return location
3359  *     for the pointer to the entry's structure, or %NULL
3360  *
3361  * Parses the location and/or structure from the entry with the given index.
3362  * The index must be between 0 and gst_message_get_num_redirect_entries() - 1.
3363  * Returned pointers are valid for as long as this message exists.
3364  *
3365  * Since: 1.10
3366  */
3367 void
gst_message_parse_redirect_entry(GstMessage * message,gsize entry_index,const gchar ** location,GstTagList ** tag_list,const GstStructure ** entry_struct)3368 gst_message_parse_redirect_entry (GstMessage * message, gsize entry_index,
3369     const gchar ** location, GstTagList ** tag_list,
3370     const GstStructure ** entry_struct)
3371 {
3372   const GValue *val;
3373   GstStructure *structure;
3374   const GValue *entry_locations_gvalue;
3375   const GValue *entry_taglists_gvalue;
3376   const GValue *entry_structures_gvalue;
3377 
3378   g_return_if_fail (GST_IS_MESSAGE (message));
3379   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REDIRECT);
3380 
3381   if (G_UNLIKELY (!location && !tag_list && !entry_struct))
3382     return;
3383 
3384   structure = GST_MESSAGE_STRUCTURE (message);
3385 
3386   entry_locations_gvalue =
3387       gst_structure_id_get_value (structure,
3388       GST_QUARK (REDIRECT_ENTRY_LOCATIONS));
3389   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_locations_gvalue));
3390   entry_taglists_gvalue =
3391       gst_structure_id_get_value (structure,
3392       GST_QUARK (REDIRECT_ENTRY_TAGLISTS));
3393   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_taglists_gvalue));
3394   entry_structures_gvalue =
3395       gst_structure_id_get_value (structure,
3396       GST_QUARK (REDIRECT_ENTRY_STRUCTURES));
3397   g_return_if_fail (GST_VALUE_HOLDS_LIST (entry_structures_gvalue));
3398 
3399   if (location) {
3400     val = gst_value_list_get_value (entry_locations_gvalue, entry_index);
3401     g_return_if_fail (val != NULL);
3402     *location = g_value_get_string (val);
3403   }
3404 
3405   if (tag_list) {
3406     val = gst_value_list_get_value (entry_taglists_gvalue, entry_index);
3407     g_return_if_fail (val != NULL);
3408     *tag_list = (GstTagList *) g_value_get_boxed (val);
3409   }
3410 
3411   if (entry_struct) {
3412     val = gst_value_list_get_value (entry_structures_gvalue, entry_index);
3413     g_return_if_fail (val != NULL);
3414     *entry_struct = (const GstStructure *) g_value_get_boxed (val);
3415   }
3416 }
3417 
3418 /**
3419  * gst_message_get_num_redirect_entries:
3420  * @message: a #GstMessage of type %GST_MESSAGE_REDIRECT
3421  *
3422  * Returns: the number of entries stored in the message
3423  *
3424  * Since: 1.10
3425  */
3426 gsize
gst_message_get_num_redirect_entries(GstMessage * message)3427 gst_message_get_num_redirect_entries (GstMessage * message)
3428 {
3429   GstStructure *structure;
3430   const GValue *entry_locations_gvalue;
3431   const GValue *entry_taglists_gvalue;
3432   const GValue *entry_structures_gvalue;
3433   gsize size;
3434 
3435   g_return_val_if_fail (GST_IS_MESSAGE (message), 0);
3436   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REDIRECT, 0);
3437 
3438   structure = GST_MESSAGE_STRUCTURE (message);
3439 
3440   entry_locations_gvalue =
3441       gst_structure_id_get_value (structure,
3442       GST_QUARK (REDIRECT_ENTRY_LOCATIONS));
3443   g_return_val_if_fail (GST_VALUE_HOLDS_LIST (entry_locations_gvalue), 0);
3444   entry_taglists_gvalue =
3445       gst_structure_id_get_value (structure,
3446       GST_QUARK (REDIRECT_ENTRY_TAGLISTS));
3447   g_return_val_if_fail (GST_VALUE_HOLDS_LIST (entry_taglists_gvalue), 0);
3448   entry_structures_gvalue =
3449       gst_structure_id_get_value (structure,
3450       GST_QUARK (REDIRECT_ENTRY_STRUCTURES));
3451   g_return_val_if_fail (GST_VALUE_HOLDS_LIST (entry_structures_gvalue), 0);
3452 
3453   size = gst_value_list_get_size (entry_locations_gvalue);
3454 
3455   g_return_val_if_fail ((size ==
3456           gst_value_list_get_size (entry_structures_gvalue))
3457       && (size == gst_value_list_get_size (entry_taglists_gvalue)), 0);
3458 
3459   return size;
3460 }
3461 
3462 /**
3463  * gst_message_new_instant_rate_request:
3464  * @src: The #GstObject that posted the message
3465  * @rate_multiplier: the rate multiplier factor that should be applied
3466  *
3467  * Creates a new instant-rate-request message. Elements handling the
3468  * instant-rate-change event must post this message. The message is
3469  * handled at the pipeline, and allows the pipeline to select the
3470  * running time when the rate change should happen and to send an
3471  * @GST_EVENT_INSTANT_RATE_SYNC_TIME event to notify the elements
3472  * in the pipeline.
3473  *
3474  * Returns: a newly allocated #GstMessage
3475  *
3476  * Since: 1.18
3477  */
3478 GstMessage *
gst_message_new_instant_rate_request(GstObject * src,gdouble rate_multiplier)3479 gst_message_new_instant_rate_request (GstObject * src, gdouble rate_multiplier)
3480 {
3481   GstStructure *structure;
3482   GstMessage *message;
3483 
3484   g_return_val_if_fail (rate_multiplier != 0.0, NULL);
3485 
3486   structure = gst_structure_new_id (GST_QUARK (MESSAGE_INSTANT_RATE_REQUEST),
3487       GST_QUARK (RATE), G_TYPE_DOUBLE, rate_multiplier, NULL);
3488   message =
3489       gst_message_new_custom (GST_MESSAGE_INSTANT_RATE_REQUEST, src, structure);
3490 
3491   return message;
3492 }
3493 
3494 /**
3495  * gst_message_parse_instant_rate_request:
3496  * @message: a #GstMessage of type %GST_MESSAGE_INSTANT_RATE_REQUEST
3497  * @rate_multiplier: (out) (allow-none): return location for the rate, or %NULL
3498  *
3499  * Parses the rate_multiplier from the instant-rate-request message.
3500  *
3501  * Since: 1.18
3502  */
3503 void
gst_message_parse_instant_rate_request(GstMessage * message,gdouble * rate_multiplier)3504 gst_message_parse_instant_rate_request (GstMessage * message,
3505     gdouble * rate_multiplier)
3506 {
3507   GstStructure *structure;
3508 
3509   g_return_if_fail (GST_IS_MESSAGE (message));
3510   g_return_if_fail (GST_MESSAGE_TYPE (message) ==
3511       GST_MESSAGE_INSTANT_RATE_REQUEST);
3512 
3513   structure = GST_MESSAGE_STRUCTURE (message);
3514   gst_structure_id_get (structure, GST_QUARK (RATE), G_TYPE_DOUBLE,
3515       rate_multiplier, NULL);
3516 }
3517 
3518 /**
3519  * gst_message_ref: (skip)
3520  * @msg: the message to ref
3521  *
3522  * Convenience macro to increase the reference count of the message.
3523  *
3524  * Returns: @msg (for convenience when doing assignments)
3525  */
3526 GstMessage *
gst_message_ref(GstMessage * msg)3527 gst_message_ref (GstMessage * msg)
3528 {
3529   return (GstMessage *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (msg));
3530 }
3531 
3532 /**
3533  * gst_message_unref: (skip)
3534  * @msg: the message to unref
3535  *
3536  * Convenience macro to decrease the reference count of the message, possibly
3537  * freeing it.
3538  */
3539 void
gst_message_unref(GstMessage * msg)3540 gst_message_unref (GstMessage * msg)
3541 {
3542   gst_mini_object_unref (GST_MINI_OBJECT_CAST (msg));
3543 }
3544 
3545 /**
3546  * gst_clear_message: (skip)
3547  * @msg_ptr: a pointer to a #GstMessage reference
3548  *
3549  * Clears a reference to a #GstMessage.
3550  *
3551  * @msg_ptr must not be %NULL.
3552  *
3553  * If the reference is %NULL then this function does nothing. Otherwise, the
3554  * reference count of the message is decreased and the pointer is set to %NULL.
3555  *
3556  * Since: 1.16
3557  */
3558 void
gst_clear_message(GstMessage ** msg_ptr)3559 gst_clear_message (GstMessage ** msg_ptr)
3560 {
3561   gst_clear_mini_object ((GstMiniObject **) msg_ptr);
3562 }
3563 
3564 /**
3565  * gst_message_copy: (skip)
3566  * @msg: the message to copy
3567  *
3568  * Creates a copy of the message. Returns a copy of the message.
3569  *
3570  * Returns: (transfer full): a new copy of @msg.
3571  *
3572  * MT safe
3573  */
3574 GstMessage *
gst_message_copy(const GstMessage * msg)3575 gst_message_copy (const GstMessage * msg)
3576 {
3577   return
3578       GST_MESSAGE_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST
3579           (msg)));
3580 }
3581 
3582 /**
3583  * gst_message_replace: (skip)
3584  * @old_message: (inout) (transfer full) (nullable): pointer to a
3585  *     pointer to a #GstMessage to be replaced.
3586  * @new_message: (allow-none) (transfer none): pointer to a #GstMessage that will
3587  *     replace the message pointed to by @old_message.
3588  *
3589  * Modifies a pointer to a #GstMessage to point to a different #GstMessage. The
3590  * modification is done atomically (so this is useful for ensuring thread safety
3591  * in some cases), and the reference counts are updated appropriately (the old
3592  * message is unreffed, the new one is reffed).
3593  *
3594  * Either @new_message or the #GstMessage pointed to by @old_message may be %NULL.
3595  *
3596  * Returns: %TRUE if @new_message was different from @old_message
3597  */
3598 gboolean
gst_message_replace(GstMessage ** old_message,GstMessage * new_message)3599 gst_message_replace (GstMessage ** old_message, GstMessage * new_message)
3600 {
3601   return gst_mini_object_replace ((GstMiniObject **) old_message,
3602       (GstMiniObject *) new_message);
3603 }
3604 
3605 /**
3606  * gst_message_take:
3607  * @old_message: (inout) (transfer full): pointer to a pointer to a #GstMessage
3608  *     to be replaced.
3609  * @new_message: (transfer full) (allow-none): pointer to a #GstMessage that
3610  *     will replace the message pointed to by @old_message.
3611  *
3612  * Modifies a pointer to a #GstMessage to point to a different #GstMessage. This
3613  * function is similar to gst_message_replace() except that it takes ownership
3614  * of @new_message.
3615  *
3616  * Returns: %TRUE if @new_message was different from @old_message
3617  *
3618  * Since: 1.16
3619  */
3620 gboolean
gst_message_take(GstMessage ** old_message,GstMessage * new_message)3621 gst_message_take (GstMessage ** old_message, GstMessage * new_message)
3622 {
3623   return gst_mini_object_take ((GstMiniObject **) old_message,
3624       (GstMiniObject *) new_message);
3625 }
3626