message: add allow-none to gst_message_new_ function
[platform/upstream/gstreamer.git] / gst / gstmessage.c
1 /* GStreamer
2  * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
3  *
4  * gstmessage.c: GstMessage subsystem
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /**
23  * SECTION:gstmessage
24  * @short_description: Lightweight objects to signal the application of
25  *                     pipeline events
26  * @see_also: #GstBus, #GstMiniObject, #GstElement
27  *
28  * Messages are implemented as a subclass of #GstMiniObject with a generic
29  * #GstStructure as the content. This allows for writing custom messages without
30  * requiring an API change while allowing a wide range of different types
31  * of messages.
32  *
33  * Messages are posted by objects in the pipeline and are passed to the
34  * application using the #GstBus.
35  *
36  * The basic use pattern of posting a message on a #GstBus is as follows:
37  * |[
38  *   gst_bus_post (bus, gst_message_new_eos());
39  * ]|
40  *
41  * A #GstElement usually posts messages on the bus provided by the parent
42  * container using gst_element_post_message().
43  */
44
45
46 #include "gst_private.h"
47 #include <string.h>             /* memcpy */
48 #include "gsterror.h"
49 #include "gstenumtypes.h"
50 #include "gstinfo.h"
51 #include "gstmessage.h"
52 #include "gsttaglist.h"
53 #include "gstutils.h"
54 #include "gstquark.h"
55
56
57 typedef struct
58 {
59   GstMessage message;
60
61   GstStructure *structure;
62 } GstMessageImpl;
63
64 #define GST_MESSAGE_STRUCTURE(m)  (((GstMessageImpl *)(m))->structure)
65
66 typedef struct
67 {
68   const gint type;
69   const gchar *name;
70   GQuark quark;
71 } GstMessageQuarks;
72
73 static GstMessageQuarks message_quarks[] = {
74   {GST_MESSAGE_UNKNOWN, "unknown", 0},
75   {GST_MESSAGE_EOS, "eos", 0},
76   {GST_MESSAGE_ERROR, "error", 0},
77   {GST_MESSAGE_WARNING, "warning", 0},
78   {GST_MESSAGE_INFO, "info", 0},
79   {GST_MESSAGE_TAG, "tag", 0},
80   {GST_MESSAGE_BUFFERING, "buffering", 0},
81   {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
82   {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
83   {GST_MESSAGE_STEP_DONE, "step-done", 0},
84   {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
85   {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
86   {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
87   {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
88   {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
89   {GST_MESSAGE_APPLICATION, "application", 0},
90   {GST_MESSAGE_ELEMENT, "element", 0},
91   {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
92   {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
93   {GST_MESSAGE_DURATION_CHANGED, "duration-changed", 0},
94   {GST_MESSAGE_LATENCY, "latency", 0},
95   {GST_MESSAGE_ASYNC_START, "async-start", 0},
96   {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
97   {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
98   {GST_MESSAGE_STEP_START, "step-start", 0},
99   {GST_MESSAGE_QOS, "qos", 0},
100   {GST_MESSAGE_PROGRESS, "progress", 0},
101   {GST_MESSAGE_TOC, "toc", 0},
102   {GST_MESSAGE_RESET_TIME, "reset-time", 0},
103   {GST_MESSAGE_STREAM_START, "stream-start", 0},
104   {GST_MESSAGE_NEED_CONTEXT, "need-context", 0},
105   {GST_MESSAGE_HAVE_CONTEXT, "have-context", 0},
106   {GST_MESSAGE_DEVICE_ADDED, "device-added", 0},
107   {GST_MESSAGE_DEVICE_REMOVED, "device-removed", 0},
108   {0, NULL, 0}
109 };
110
111 GType _gst_message_type = 0;
112 GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
113
114 void
115 _priv_gst_message_initialize (void)
116 {
117   gint i;
118
119   GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
120
121   for (i = 0; message_quarks[i].name; i++) {
122     message_quarks[i].quark =
123         g_quark_from_static_string (message_quarks[i].name);
124   }
125
126   _gst_message_type = gst_message_get_type ();
127 }
128
129 /**
130  * gst_message_type_get_name:
131  * @type: the message type
132  *
133  * Get a printable name for the given message type. Do not modify or free.
134  *
135  * Returns: a reference to the static name of the message.
136  */
137 const gchar *
138 gst_message_type_get_name (GstMessageType type)
139 {
140   gint i;
141
142   for (i = 0; message_quarks[i].name; i++) {
143     if (type == message_quarks[i].type)
144       return message_quarks[i].name;
145   }
146   return "unknown";
147 }
148
149 /**
150  * gst_message_type_to_quark:
151  * @type: the message type
152  *
153  * Get the unique quark for the given message type.
154  *
155  * Returns: the quark associated with the message type
156  */
157 GQuark
158 gst_message_type_to_quark (GstMessageType type)
159 {
160   gint i;
161
162   for (i = 0; message_quarks[i].name; i++) {
163     if (type == message_quarks[i].type)
164       return message_quarks[i].quark;
165   }
166   return 0;
167 }
168
169 static gboolean
170 _gst_message_dispose (GstMessage * message)
171 {
172   gboolean do_free = TRUE;
173
174   if (GST_MINI_OBJECT_FLAG_IS_SET (message, GST_MESSAGE_FLAG_ASYNC_DELIVERY)) {
175     /* revive message, so bus can finish with it and clean it up */
176     gst_message_ref (message);
177
178     GST_INFO ("[msg %p] signalling async free", message);
179
180     GST_MESSAGE_LOCK (message);
181     GST_MESSAGE_SIGNAL (message);
182     GST_MESSAGE_UNLOCK (message);
183
184     /* don't free it yet, let bus finish with it first */
185     do_free = FALSE;
186   }
187
188   return do_free;
189 }
190
191 static void
192 _gst_message_free (GstMessage * message)
193 {
194   GstStructure *structure;
195
196   g_return_if_fail (message != NULL);
197
198   GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
199       GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
200
201   if (GST_MESSAGE_SRC (message)) {
202     gst_object_unref (GST_MESSAGE_SRC (message));
203     GST_MESSAGE_SRC (message) = NULL;
204   }
205
206   structure = GST_MESSAGE_STRUCTURE (message);
207   if (structure) {
208     gst_structure_set_parent_refcount (structure, NULL);
209     gst_structure_free (structure);
210   }
211
212   g_slice_free1 (sizeof (GstMessageImpl), message);
213 }
214
215 static void
216 gst_message_init (GstMessageImpl * message, GstMessageType type,
217     GstObject * src);
218
219 static GstMessage *
220 _gst_message_copy (GstMessage * message)
221 {
222   GstMessageImpl *copy;
223   GstStructure *structure;
224
225   GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
226       GST_MESSAGE_TYPE_NAME (message),
227       GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
228
229   copy = g_slice_new0 (GstMessageImpl);
230
231   gst_message_init (copy, GST_MESSAGE_TYPE (message),
232       GST_MESSAGE_SRC (message));
233
234   GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
235   GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
236
237   structure = GST_MESSAGE_STRUCTURE (message);
238   if (structure) {
239     GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
240     gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
241         &copy->message.mini_object.refcount);
242   } else {
243     GST_MESSAGE_STRUCTURE (copy) = NULL;
244   }
245
246   return GST_MESSAGE_CAST (copy);
247 }
248
249 static void
250 gst_message_init (GstMessageImpl * message, GstMessageType type,
251     GstObject * src)
252 {
253   gst_mini_object_init (GST_MINI_OBJECT_CAST (message), 0, _gst_message_type,
254       (GstMiniObjectCopyFunction) _gst_message_copy,
255       (GstMiniObjectDisposeFunction) _gst_message_dispose,
256       (GstMiniObjectFreeFunction) _gst_message_free);
257
258   GST_MESSAGE_TYPE (message) = type;
259   if (src)
260     gst_object_ref (src);
261   GST_MESSAGE_SRC (message) = src;
262   GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
263   GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
264 }
265
266
267 /**
268  * gst_message_new_custom:
269  * @type: The #GstMessageType to distinguish messages
270  * @src: (transfer none) (allow-none): The object originating the message.
271  * @structure: (transfer full) (allow-none): the structure for the
272  *     message. The message will take ownership of the structure.
273  *
274  * Create a new custom-typed message. This can be used for anything not
275  * handled by other message-specific functions to pass a message to the
276  * app. The structure field can be %NULL.
277  *
278  * Returns: (transfer full): The new message.
279  *
280  * MT safe.
281  */
282 GstMessage *
283 gst_message_new_custom (GstMessageType type, GstObject * src,
284     GstStructure * structure)
285 {
286   GstMessageImpl *message;
287
288   message = g_slice_new0 (GstMessageImpl);
289
290   GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
291       (src ? GST_OBJECT_NAME (src) : "NULL"), message,
292       gst_message_type_get_name (type));
293
294   if (structure) {
295     /* structure must not have a parent */
296     if (!gst_structure_set_parent_refcount (structure,
297             &message->message.mini_object.refcount))
298       goto had_parent;
299   }
300   gst_message_init (message, type, src);
301
302   GST_MESSAGE_STRUCTURE (message) = structure;
303
304   return GST_MESSAGE_CAST (message);
305
306   /* ERRORS */
307 had_parent:
308   {
309     g_slice_free1 (sizeof (GstMessageImpl), message);
310     g_warning ("structure is already owned by another object");
311     return NULL;
312   }
313 }
314
315 /**
316  * gst_message_get_seqnum:
317  * @message: A #GstMessage.
318  *
319  * Retrieve the sequence number of a message.
320  *
321  * Messages have ever-incrementing sequence numbers, which may also be set
322  * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
323  * to indicate that a message corresponds to some other set of messages or
324  * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
325  * is considered good practice to make this correspondence when possible, though
326  * it is not required.
327  *
328  * Note that events and messages share the same sequence number incrementor;
329  * two events or messages will never have the same sequence number unless
330  * that correspondence was made explicitly.
331  *
332  * Returns: The message's sequence number.
333  *
334  * MT safe.
335  */
336 guint32
337 gst_message_get_seqnum (GstMessage * message)
338 {
339   g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
340
341   return GST_MESSAGE_SEQNUM (message);
342 }
343
344 /**
345  * gst_message_set_seqnum:
346  * @message: A #GstMessage.
347  * @seqnum: A sequence number.
348  *
349  * Set the sequence number of a message.
350  *
351  * This function might be called by the creator of a message to indicate that
352  * the message relates to other messages or events. See gst_message_get_seqnum()
353  * for more information.
354  *
355  * MT safe.
356  */
357 void
358 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
359 {
360   g_return_if_fail (GST_IS_MESSAGE (message));
361
362   GST_MESSAGE_SEQNUM (message) = seqnum;
363 }
364
365 /**
366  * gst_message_new_eos:
367  * @src: (transfer none) (allow-none): The object originating the message.
368  *
369  * Create a new eos message. This message is generated and posted in
370  * the sink elements of a GstBin. The bin will only forward the EOS
371  * message to the application if all sinks have posted an EOS message.
372  *
373  * Returns: (transfer full): The new eos message.
374  *
375  * MT safe.
376  */
377 GstMessage *
378 gst_message_new_eos (GstObject * src)
379 {
380   GstMessage *message;
381
382   message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
383
384   return message;
385 }
386
387 /**
388  * gst_message_new_error:
389  * @src: (transfer none) (allow-none): The object originating the message.
390  * @error: (transfer none): The GError for this message.
391  * @debug: A debugging string.
392  *
393  * Create a new error message. The message will copy @error and
394  * @debug. This message is posted by element when a fatal event
395  * occurred. The pipeline will probably (partially) stop. The application
396  * receiving this message should stop the pipeline.
397  *
398  * Returns: (transfer full): the new error message.
399  *
400  * MT safe.
401  */
402 GstMessage *
403 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
404 {
405   GstMessage *message;
406   GstStructure *structure;
407
408   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
409       GST_QUARK (GERROR), G_TYPE_ERROR, error,
410       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
411   message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
412
413   return message;
414 }
415
416 /**
417  * gst_message_new_warning:
418  * @src: (transfer none) (allow-none): The object originating the message.
419  * @error: (transfer none): The GError for this message.
420  * @debug: A debugging string.
421  *
422  * Create a new warning message. The message will make copies of @error and
423  * @debug.
424  *
425  * Returns: (transfer full): The new warning message.
426  *
427  * MT safe.
428  */
429 GstMessage *
430 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
431 {
432   GstMessage *message;
433   GstStructure *structure;
434
435   structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
436       GST_QUARK (GERROR), G_TYPE_ERROR, error,
437       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
438   message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
439
440   return message;
441 }
442
443 /**
444  * gst_message_new_info:
445  * @src: (transfer none) (allow-none): The object originating the message.
446  * @error: (transfer none): The GError for this message.
447  * @debug: A debugging string.
448  *
449  * Create a new info message. The message will make copies of @error and
450  * @debug.
451  *
452  * MT safe.
453  *
454  * Returns: (transfer full): the new info message.
455  */
456 GstMessage *
457 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
458 {
459   GstMessage *message;
460   GstStructure *structure;
461
462   structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
463       GST_QUARK (GERROR), G_TYPE_ERROR, error,
464       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
465   message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
466
467   return message;
468 }
469
470 /**
471  * gst_message_new_tag:
472  * @src: (transfer none) (allow-none): The object originating the message.
473  * @tag_list: (transfer full): the tag list for the message.
474  *
475  * Create a new tag message. The message will take ownership of the tag list.
476  * The message is posted by elements that discovered a new taglist.
477  *
478  * Returns: (transfer full): the new tag message.
479  *
480  * MT safe.
481  */
482 GstMessage *
483 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
484 {
485   GstStructure *s;
486   GstMessage *message;
487   GValue val = G_VALUE_INIT;
488
489   g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
490
491   s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
492   g_value_init (&val, GST_TYPE_TAG_LIST);
493   g_value_take_boxed (&val, tag_list);
494   gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
495   message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
496   return message;
497 }
498
499 /**
500  * gst_message_new_buffering:
501  * @src: (transfer none) (allow-none): The object originating the message.
502  * @percent: The buffering percent
503  *
504  * Create a new buffering message. This message can be posted by an element that
505  * needs to buffer data before it can continue processing. @percent should be a
506  * value between 0 and 100. A value of 100 means that the buffering completed.
507  *
508  * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
509  * @percent is 100, the application can set the pipeline (back) to PLAYING.
510  * The application must be prepared to receive BUFFERING messages in the
511  * PREROLLING state and may only set the pipeline to PLAYING after receiving a
512  * message with @percent set to 100, which can happen after the pipeline
513  * completed prerolling.
514  *
515  * MT safe.
516  *
517  * Returns: (transfer full): The new buffering message.
518  */
519 GstMessage *
520 gst_message_new_buffering (GstObject * src, gint percent)
521 {
522   GstMessage *message;
523   GstStructure *structure;
524   gint64 buffering_left;
525
526   g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
527
528   buffering_left = (percent == 100 ? 0 : -1);
529
530   structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
531       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
532       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
533       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
534       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
535       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
536   message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
537
538   return message;
539 }
540
541 /**
542  * gst_message_new_state_changed:
543  * @src: (transfer none) (allow-none): The object originating the message.
544  * @oldstate: the previous state
545  * @newstate: the new (current) state
546  * @pending: the pending (target) state
547  *
548  * Create a state change message. This message is posted whenever an element
549  * changed its state.
550  *
551  * Returns: (transfer full): the new state change message.
552  *
553  * MT safe.
554  */
555 GstMessage *
556 gst_message_new_state_changed (GstObject * src,
557     GstState oldstate, GstState newstate, GstState pending)
558 {
559   GstMessage *message;
560   GstStructure *structure;
561
562   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
563       GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
564       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
565       GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
566   message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
567
568   return message;
569 }
570
571 /**
572  * gst_message_new_state_dirty:
573  * @src: (transfer none) (allow-none): The object originating the message
574  *
575  * Create a state dirty message. This message is posted whenever an element
576  * changed its state asynchronously and is used internally to update the
577  * states of container objects.
578  *
579  * Returns: (transfer full): the new state dirty message.
580  *
581  * MT safe.
582  */
583 GstMessage *
584 gst_message_new_state_dirty (GstObject * src)
585 {
586   GstMessage *message;
587
588   message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
589
590   return message;
591 }
592
593 /**
594  * gst_message_new_clock_provide:
595  * @src: (transfer none) (allow-none): The object originating the message.
596  * @clock: (transfer none): the clock it provides
597  * @ready: %TRUE if the sender can provide a clock
598  *
599  * Create a clock provide message. This message is posted whenever an
600  * element is ready to provide a clock or lost its ability to provide
601  * a clock (maybe because it paused or became EOS).
602  *
603  * This message is mainly used internally to manage the clock
604  * selection.
605  *
606  * Returns: (transfer full): the new provide clock message.
607  *
608  * MT safe.
609  */
610 GstMessage *
611 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
612     gboolean ready)
613 {
614   GstMessage *message;
615   GstStructure *structure;
616
617   structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
618       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
619       GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
620   message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
621
622   return message;
623 }
624
625 /**
626  * gst_message_new_clock_lost:
627  * @src: (transfer none) (allow-none): The object originating the message.
628  * @clock: (transfer none): the clock that was lost
629  *
630  * Create a clock lost message. This message is posted whenever the
631  * clock is not valid anymore.
632  *
633  * If this message is posted by the pipeline, the pipeline will
634  * select a new clock again when it goes to PLAYING. It might therefore
635  * be needed to set the pipeline to PAUSED and PLAYING again.
636  *
637  * Returns: (transfer full): The new clock lost message.
638  *
639  * MT safe.
640  */
641 GstMessage *
642 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
643 {
644   GstMessage *message;
645   GstStructure *structure;
646
647   structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
648       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
649   message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
650
651   return message;
652 }
653
654 /**
655  * gst_message_new_new_clock:
656  * @src: (transfer none) (allow-none): The object originating the message.
657  * @clock: (transfer none): the new selected clock
658  *
659  * Create a new clock message. This message is posted whenever the
660  * pipeline selects a new clock for the pipeline.
661  *
662  * Returns: (transfer full): The new new clock message.
663  *
664  * MT safe.
665  */
666 GstMessage *
667 gst_message_new_new_clock (GstObject * src, GstClock * clock)
668 {
669   GstMessage *message;
670   GstStructure *structure;
671
672   structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
673       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
674   message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
675
676   return message;
677 }
678
679 /**
680  * gst_message_new_structure_change:
681  * @src: (transfer none) (allow-none): The object originating the message.
682  * @type: The change type.
683  * @owner: (transfer none): The owner element of @src.
684  * @busy: Whether the structure change is busy.
685  *
686  * Create a new structure change message. This message is posted when the
687  * structure of a pipeline is in the process of being changed, for example
688  * when pads are linked or unlinked.
689  *
690  * @src should be the sinkpad that unlinked or linked.
691  *
692  * Returns: (transfer full): the new structure change message.
693  *
694  * MT safe.
695  */
696 GstMessage *
697 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
698     GstElement * owner, gboolean busy)
699 {
700   GstMessage *message;
701   GstStructure *structure;
702
703   g_return_val_if_fail (GST_IS_PAD (src), NULL);
704   /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
705   g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
706
707   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
708       GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
709       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
710       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
711
712   message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
713       structure);
714
715   return message;
716 }
717
718 /**
719  * gst_message_new_segment_start:
720  * @src: (transfer none) (allow-none): The object originating the message.
721  * @format: The format of the position being played
722  * @position: The position of the segment being played
723  *
724  * Create a new segment message. This message is posted by elements that
725  * start playback of a segment as a result of a segment seek. This message
726  * is not received by the application but is used for maintenance reasons in
727  * container elements.
728  *
729  * Returns: (transfer full): the new segment start message.
730  *
731  * MT safe.
732  */
733 GstMessage *
734 gst_message_new_segment_start (GstObject * src, GstFormat format,
735     gint64 position)
736 {
737   GstMessage *message;
738   GstStructure *structure;
739
740   structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
741       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
742       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
743   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
744
745   return message;
746 }
747
748 /**
749  * gst_message_new_segment_done:
750  * @src: (transfer none) (allow-none): The object originating the message.
751  * @format: The format of the position being done
752  * @position: The position of the segment being done
753  *
754  * Create a new segment done message. This message is posted by elements that
755  * finish playback of a segment as a result of a segment seek. This message
756  * is received by the application after all elements that posted a segment_start
757  * have posted the segment_done.
758  *
759  * Returns: (transfer full): the new segment done message.
760  *
761  * MT safe.
762  */
763 GstMessage *
764 gst_message_new_segment_done (GstObject * src, GstFormat format,
765     gint64 position)
766 {
767   GstMessage *message;
768   GstStructure *structure;
769
770   structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
771       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
772       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
773   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
774
775   return message;
776 }
777
778 /**
779  * gst_message_new_application:
780  * @src: (transfer none) (allow-none): The object originating the message.
781  * @structure: (transfer full): the structure for the message. The message
782  *     will take ownership of the structure.
783  *
784  * Create a new application-typed message. GStreamer will never create these
785  * messages; they are a gift from us to you. Enjoy.
786  *
787  * Returns: (transfer full): The new application message.
788  *
789  * MT safe.
790  */
791 GstMessage *
792 gst_message_new_application (GstObject * src, GstStructure * structure)
793 {
794   g_return_val_if_fail (structure != NULL, NULL);
795
796   return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
797 }
798
799 /**
800  * gst_message_new_element:
801  * @src: (transfer none) (allow-none): The object originating the message.
802  * @structure: (transfer full): The structure for the
803  *     message. The message will take ownership of the structure.
804  *
805  * Create a new element-specific message. This is meant as a generic way of
806  * allowing one-way communication from an element to an application, for example
807  * "the firewire cable was unplugged". The format of the message should be
808  * documented in the element's documentation. The structure field can be %NULL.
809  *
810  * Returns: (transfer full): The new element message.
811  *
812  * MT safe.
813  */
814 GstMessage *
815 gst_message_new_element (GstObject * src, GstStructure * structure)
816 {
817   g_return_val_if_fail (structure != NULL, NULL);
818
819   return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
820 }
821
822 /**
823  * gst_message_new_duration_changed:
824  * @src: (transfer none) (allow-none): The object originating the message.
825  *
826  * Create a new duration changed message. This message is posted by elements
827  * that know the duration of a stream when the duration changes. This message
828  * is received by bins and is used to calculate the total duration of a
829  * pipeline. Elements may post a duration message with a duration of
830  * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the 
831  * cached duration should be discarded. The new duration can then be 
832  * retrieved via a query.
833  *
834  * Returns: (transfer full): The new duration-changed message.
835  *
836  * MT safe.
837  */
838 GstMessage *
839 gst_message_new_duration_changed (GstObject * src)
840 {
841   GstMessage *message;
842
843   message = gst_message_new_custom (GST_MESSAGE_DURATION_CHANGED, src,
844       gst_structure_new_id_empty (GST_QUARK (MESSAGE_DURATION_CHANGED)));
845
846   return message;
847 }
848
849 /**
850  * gst_message_new_async_start:
851  * @src: (transfer none) (allow-none): The object originating the message.
852  *
853  * This message is posted by elements when they start an ASYNC state change.
854  *
855  * Returns: (transfer full): The new async_start message.
856  *
857  * MT safe.
858  */
859 GstMessage *
860 gst_message_new_async_start (GstObject * src)
861 {
862   GstMessage *message;
863
864   message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
865
866   return message;
867 }
868
869 /**
870  * gst_message_new_async_done:
871  * @src: (transfer none) (allow-none): The object originating the message.
872  * @running_time: the desired running_time
873  *
874  * The message is posted when elements completed an ASYNC state change.
875  * @running_time contains the time of the desired running_time when this
876  * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
877  * means that the element has no clock interaction and thus doesn't care about
878  * the running_time of the pipeline.
879  *
880  * Returns: (transfer full): The new async_done message.
881  *
882  * MT safe.
883  */
884 GstMessage *
885 gst_message_new_async_done (GstObject * src, GstClockTime running_time)
886 {
887   GstMessage *message;
888   GstStructure *structure;
889
890   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
891       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
892   message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
893
894   return message;
895 }
896
897 /**
898  * gst_message_new_latency:
899  * @src: (transfer none) (allow-none): The object originating the message.
900  *
901  * This message can be posted by elements when their latency requirements have
902  * changed.
903  *
904  * Returns: (transfer full): The new latency message.
905  *
906  * MT safe.
907  */
908 GstMessage *
909 gst_message_new_latency (GstObject * src)
910 {
911   GstMessage *message;
912
913   message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
914
915   return message;
916 }
917
918 /**
919  * gst_message_new_request_state:
920  * @src: (transfer none) (allow-none): The object originating the message.
921  * @state: The new requested state
922  *
923  * This message can be posted by elements when they want to have their state
924  * changed. A typical use case would be an audio server that wants to pause the
925  * pipeline because a higher priority stream is being played.
926  *
927  * Returns: (transfer full): the new request state message.
928  *
929  * MT safe.
930  */
931 GstMessage *
932 gst_message_new_request_state (GstObject * src, GstState state)
933 {
934   GstMessage *message;
935   GstStructure *structure;
936
937   structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
938       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
939   message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
940
941   return message;
942 }
943
944 /**
945  * gst_message_get_structure:
946  * @message: The #GstMessage.
947  *
948  * Access the structure of the message.
949  *
950  * Returns: (transfer none): The structure of the message. The structure is
951  * still owned by the message, which means that you should not free it and
952  * that the pointer becomes invalid when you free the message.
953  *
954  * MT safe.
955  */
956 const GstStructure *
957 gst_message_get_structure (GstMessage * message)
958 {
959   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
960
961   return GST_MESSAGE_STRUCTURE (message);
962 }
963
964 /**
965  * gst_message_has_name:
966  * @message: The #GstMessage.
967  * @name: name to check
968  *
969  * Checks if @message has the given @name. This function is usually used to
970  * check the name of a custom message.
971  *
972  * Returns: %TRUE if @name matches the name of the message structure.
973  */
974 gboolean
975 gst_message_has_name (GstMessage * message, const gchar * name)
976 {
977   GstStructure *structure;
978
979   g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
980
981   structure = GST_MESSAGE_STRUCTURE (message);
982   if (structure == NULL)
983     return FALSE;
984
985   return gst_structure_has_name (structure, name);
986 }
987
988 /**
989  * gst_message_parse_tag:
990  * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
991  * @tag_list: (out callee-allocates): return location for the tag-list.
992  *
993  * Extracts the tag list from the GstMessage. The tag list returned in the
994  * output argument is a copy; the caller must free it when done.
995  *
996  * Typical usage of this function might be:
997  * |[
998  *   ...
999  *   switch (GST_MESSAGE_TYPE (msg)) {
1000  *     case GST_MESSAGE_TAG: {
1001  *       GstTagList *tags = NULL;
1002  *       
1003  *       gst_message_parse_tag (msg, &amp;tags);
1004  *       g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1005  *       handle_tags (tags);
1006  *       gst_tag_list_unref (tags);
1007  *       break;
1008  *     }
1009  *     ...
1010  *   }
1011  *   ...
1012  * ]|
1013  *
1014  * MT safe.
1015  */
1016 void
1017 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1018 {
1019   g_return_if_fail (GST_IS_MESSAGE (message));
1020   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1021   g_return_if_fail (tag_list != NULL);
1022
1023   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1024       GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
1025 }
1026
1027 /**
1028  * gst_message_parse_buffering:
1029  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1030  * @percent: (out) (allow-none): Return location for the percent.
1031  *
1032  * Extracts the buffering percent from the GstMessage. see also
1033  * gst_message_new_buffering().
1034  *
1035  * MT safe.
1036  */
1037 void
1038 gst_message_parse_buffering (GstMessage * message, gint * percent)
1039 {
1040   g_return_if_fail (GST_IS_MESSAGE (message));
1041   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1042
1043   if (percent)
1044     *percent =
1045         g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
1046             (message), GST_QUARK (BUFFER_PERCENT)));
1047 }
1048
1049 /**
1050  * gst_message_set_buffering_stats:
1051  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1052  * @mode: a buffering mode 
1053  * @avg_in: the average input rate
1054  * @avg_out: the average output rate
1055  * @buffering_left: amount of buffering time left in milliseconds
1056  *
1057  * Configures the buffering stats values in @message.
1058  */
1059 void
1060 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1061     gint avg_in, gint avg_out, gint64 buffering_left)
1062 {
1063   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1064
1065   gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
1066       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1067       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1068       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1069       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1070 }
1071
1072 /**
1073  * gst_message_parse_buffering_stats:
1074  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1075  * @mode: (out) (allow-none): a buffering mode, or %NULL
1076  * @avg_in: (out) (allow-none): the average input rate, or %NULL
1077  * @avg_out: (out) (allow-none): the average output rate, or %NULL
1078  * @buffering_left: (out) (allow-none): amount of buffering time left in
1079  *     milliseconds, or %NULL
1080  *
1081  * Extracts the buffering stats values from @message.
1082  */
1083 void
1084 gst_message_parse_buffering_stats (GstMessage * message,
1085     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1086     gint64 * buffering_left)
1087 {
1088   GstStructure *structure;
1089
1090   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1091
1092   structure = GST_MESSAGE_STRUCTURE (message);
1093   if (mode)
1094     *mode = (GstBufferingMode)
1095         g_value_get_enum (gst_structure_id_get_value (structure,
1096             GST_QUARK (BUFFERING_MODE)));
1097   if (avg_in)
1098     *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1099             GST_QUARK (AVG_IN_RATE)));
1100   if (avg_out)
1101     *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1102             GST_QUARK (AVG_OUT_RATE)));
1103   if (buffering_left)
1104     *buffering_left =
1105         g_value_get_int64 (gst_structure_id_get_value (structure,
1106             GST_QUARK (BUFFERING_LEFT)));
1107 }
1108
1109 /**
1110  * gst_message_parse_state_changed:
1111  * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1112  * @oldstate: (out) (allow-none): the previous state, or %NULL
1113  * @newstate: (out) (allow-none): the new (current) state, or %NULL
1114  * @pending: (out) (allow-none): the pending (target) state, or %NULL
1115  *
1116  * Extracts the old and new states from the GstMessage.
1117  *
1118  * Typical usage of this function might be:
1119  * |[
1120  *   ...
1121  *   switch (GST_MESSAGE_TYPE (msg)) {
1122  *     case GST_MESSAGE_STATE_CHANGED: {
1123  *       GstState old_state, new_state;
1124  *       
1125  *       gst_message_parse_state_changed (msg, &amp;old_state, &amp;new_state, NULL);
1126  *       g_print ("Element %s changed state from %s to %s.\n",
1127  *           GST_OBJECT_NAME (msg->src),
1128  *           gst_element_state_get_name (old_state),
1129  *           gst_element_state_get_name (new_state));
1130  *       break;
1131  *     }
1132  *     ...
1133  *   }
1134  *   ...
1135  * ]|
1136  *
1137  * MT safe.
1138  */
1139 void
1140 gst_message_parse_state_changed (GstMessage * message,
1141     GstState * oldstate, GstState * newstate, GstState * pending)
1142 {
1143   GstStructure *structure;
1144
1145   g_return_if_fail (GST_IS_MESSAGE (message));
1146   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1147
1148   structure = GST_MESSAGE_STRUCTURE (message);
1149   if (oldstate)
1150     *oldstate = (GstState)
1151         g_value_get_enum (gst_structure_id_get_value (structure,
1152             GST_QUARK (OLD_STATE)));
1153   if (newstate)
1154     *newstate = (GstState)
1155         g_value_get_enum (gst_structure_id_get_value (structure,
1156             GST_QUARK (NEW_STATE)));
1157   if (pending)
1158     *pending = (GstState)
1159         g_value_get_enum (gst_structure_id_get_value (structure,
1160             GST_QUARK (PENDING_STATE)));
1161 }
1162
1163 /**
1164  * gst_message_parse_clock_provide:
1165  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1166  * @clock: (out) (allow-none) (transfer none): a pointer to  hold a clock
1167  *     object, or %NULL
1168  * @ready: (out) (allow-none): a pointer to hold the ready flag, or %NULL
1169  *
1170  * Extracts the clock and ready flag from the GstMessage.
1171  * The clock object returned remains valid until the message is freed.
1172  *
1173  * MT safe.
1174  */
1175 void
1176 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1177     gboolean * ready)
1178 {
1179   const GValue *clock_gvalue;
1180   GstStructure *structure;
1181
1182   g_return_if_fail (GST_IS_MESSAGE (message));
1183   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1184
1185   structure = GST_MESSAGE_STRUCTURE (message);
1186   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1187   g_return_if_fail (clock_gvalue != NULL);
1188   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1189
1190   if (ready)
1191     *ready =
1192         g_value_get_boolean (gst_structure_id_get_value (structure,
1193             GST_QUARK (READY)));
1194   if (clock)
1195     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1196 }
1197
1198 /**
1199  * gst_message_parse_clock_lost:
1200  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1201  * @clock: (out) (allow-none) (transfer none): a pointer to hold the lost clock
1202  *
1203  * Extracts the lost clock from the GstMessage.
1204  * The clock object returned remains valid until the message is freed.
1205  *
1206  * MT safe.
1207  */
1208 void
1209 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1210 {
1211   const GValue *clock_gvalue;
1212   GstStructure *structure;
1213
1214   g_return_if_fail (GST_IS_MESSAGE (message));
1215   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1216
1217   structure = GST_MESSAGE_STRUCTURE (message);
1218   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1219   g_return_if_fail (clock_gvalue != NULL);
1220   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1221
1222   if (clock)
1223     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1224 }
1225
1226 /**
1227  * gst_message_parse_new_clock:
1228  * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1229  * @clock: (out) (allow-none) (transfer none): a pointer to hold the selected
1230  *     new clock
1231  *
1232  * Extracts the new clock from the GstMessage.
1233  * The clock object returned remains valid until the message is freed.
1234  *
1235  * MT safe.
1236  */
1237 void
1238 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1239 {
1240   const GValue *clock_gvalue;
1241   GstStructure *structure;
1242
1243   g_return_if_fail (GST_IS_MESSAGE (message));
1244   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1245
1246   structure = GST_MESSAGE_STRUCTURE (message);
1247   clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
1248   g_return_if_fail (clock_gvalue != NULL);
1249   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1250
1251   if (clock)
1252     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1253 }
1254
1255 /**
1256  * gst_message_parse_structure_change:
1257  * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1258  * @type: (out): A pointer to hold the change type
1259  * @owner: (out) (allow-none) (transfer none): The owner element of the
1260  *     message source
1261  * @busy: (out) (allow-none): a pointer to hold whether the change is in
1262  *     progress or has been completed
1263  *
1264  * Extracts the change type and completion status from the GstMessage.
1265  *
1266  * MT safe.
1267  */
1268 void
1269 gst_message_parse_structure_change (GstMessage * message,
1270     GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1271 {
1272   const GValue *owner_gvalue;
1273   GstStructure *structure;
1274
1275   g_return_if_fail (GST_IS_MESSAGE (message));
1276   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1277
1278   structure = GST_MESSAGE_STRUCTURE (message);
1279   owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1280   g_return_if_fail (owner_gvalue != NULL);
1281   g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1282
1283   if (type)
1284     *type = (GstStructureChangeType)
1285         g_value_get_enum (gst_structure_id_get_value (structure,
1286             GST_QUARK (TYPE)));
1287   if (owner)
1288     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1289   if (busy)
1290     *busy =
1291         g_value_get_boolean (gst_structure_id_get_value (structure,
1292             GST_QUARK (BUSY)));
1293 }
1294
1295 /**
1296  * gst_message_parse_error:
1297  * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1298  * @gerror: (out) (allow-none) (transfer full): location for the GError
1299  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1300  *     or %NULL
1301  *
1302  * Extracts the GError and debug string from the GstMessage. The values returned
1303  * in the output arguments are copies; the caller must free them when done.
1304  *
1305  * Typical usage of this function might be:
1306  * |[
1307  *   ...
1308  *   switch (GST_MESSAGE_TYPE (msg)) {
1309  *     case GST_MESSAGE_ERROR: {
1310  *       GError *err = NULL;
1311  *       gchar *dbg_info = NULL;
1312  *       
1313  *       gst_message_parse_error (msg, &amp;err, &amp;dbg_info);
1314  *       g_printerr ("ERROR from element %s: %s\n",
1315  *           GST_OBJECT_NAME (msg->src), err->message);
1316  *       g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
1317  *       g_error_free (err);
1318  *       g_free (dbg_info);
1319  *       break;
1320  *     }
1321  *     ...
1322  *   }
1323  *   ...
1324  * ]|
1325  *
1326  * MT safe.
1327  */
1328 void
1329 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1330 {
1331   g_return_if_fail (GST_IS_MESSAGE (message));
1332   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1333
1334   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1335       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1336       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1337 }
1338
1339 /**
1340  * gst_message_parse_warning:
1341  * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1342  * @gerror: (out) (allow-none) (transfer full): location for the GError
1343  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1344  *     or %NULL
1345  *
1346  * Extracts the GError and debug string from the GstMessage. The values returned
1347  * in the output arguments are copies; the caller must free them when done.
1348  *
1349  * MT safe.
1350  */
1351 void
1352 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1353     gchar ** debug)
1354 {
1355   g_return_if_fail (GST_IS_MESSAGE (message));
1356   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1357
1358   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1359       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1360       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1361 }
1362
1363 /**
1364  * gst_message_parse_info:
1365  * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1366  * @gerror: (out) (allow-none) (transfer full): location for the GError
1367  * @debug: (out) (allow-none) (transfer full): location for the debug message,
1368  *     or %NULL
1369  *
1370  * Extracts the GError and debug string from the GstMessage. The values returned
1371  * in the output arguments are copies; the caller must free them when done.
1372  *
1373  * MT safe.
1374  */
1375 void
1376 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1377 {
1378   g_return_if_fail (GST_IS_MESSAGE (message));
1379   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1380
1381   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1382       GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
1383       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
1384 }
1385
1386 /**
1387  * gst_message_parse_segment_start:
1388  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1389  * @format: (out) (allow-none): Result location for the format, or %NULL
1390  * @position: (out) (allow-none): Result location for the position, or %NULL
1391  *
1392  * Extracts the position and format from the segment start message.
1393  *
1394  * MT safe.
1395  */
1396 void
1397 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1398     gint64 * position)
1399 {
1400   GstStructure *structure;
1401
1402   g_return_if_fail (GST_IS_MESSAGE (message));
1403   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1404
1405   structure = GST_MESSAGE_STRUCTURE (message);
1406   if (format)
1407     *format = (GstFormat)
1408         g_value_get_enum (gst_structure_id_get_value (structure,
1409             GST_QUARK (FORMAT)));
1410   if (position)
1411     *position =
1412         g_value_get_int64 (gst_structure_id_get_value (structure,
1413             GST_QUARK (POSITION)));
1414 }
1415
1416 /**
1417  * gst_message_parse_segment_done:
1418  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1419  * @format: (out) (allow-none): Result location for the format, or %NULL
1420  * @position: (out) (allow-none): Result location for the position, or %NULL
1421  *
1422  * Extracts the position and format from the segment done message.
1423  *
1424  * MT safe.
1425  */
1426 void
1427 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1428     gint64 * position)
1429 {
1430   GstStructure *structure;
1431
1432   g_return_if_fail (GST_IS_MESSAGE (message));
1433   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1434
1435   structure = GST_MESSAGE_STRUCTURE (message);
1436   if (format)
1437     *format = (GstFormat)
1438         g_value_get_enum (gst_structure_id_get_value (structure,
1439             GST_QUARK (FORMAT)));
1440   if (position)
1441     *position =
1442         g_value_get_int64 (gst_structure_id_get_value (structure,
1443             GST_QUARK (POSITION)));
1444 }
1445
1446 /**
1447  * gst_message_parse_async_done:
1448  * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1449  * @running_time: (out) (allow-none): Result location for the running_time or %NULL
1450  *
1451  * Extract the running_time from the async_done message.
1452  *
1453  * MT safe.
1454  */
1455 void
1456 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
1457 {
1458   GstStructure *structure;
1459
1460   g_return_if_fail (GST_IS_MESSAGE (message));
1461   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
1462
1463   structure = GST_MESSAGE_STRUCTURE (message);
1464   if (running_time)
1465     *running_time =
1466         g_value_get_uint64 (gst_structure_id_get_value (structure,
1467             GST_QUARK (RUNNING_TIME)));
1468 }
1469
1470 /**
1471  * gst_message_parse_request_state:
1472  * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1473  * @state: (out) (allow-none): Result location for the requested state or %NULL
1474  *
1475  * Extract the requested state from the request_state message.
1476  *
1477  * MT safe.
1478  */
1479 void
1480 gst_message_parse_request_state (GstMessage * message, GstState * state)
1481 {
1482   GstStructure *structure;
1483
1484   g_return_if_fail (GST_IS_MESSAGE (message));
1485   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1486
1487   structure = GST_MESSAGE_STRUCTURE (message);
1488   if (state)
1489     *state = (GstState)
1490         g_value_get_enum (gst_structure_id_get_value (structure,
1491             GST_QUARK (NEW_STATE)));
1492 }
1493
1494 /**
1495  * gst_message_new_stream_status:
1496  * @src: The object originating the message.
1497  * @type: The stream status type.
1498  * @owner: (transfer none): the owner element of @src.
1499  *
1500  * Create a new stream status message. This message is posted when a streaming
1501  * thread is created/destroyed or when the state changed.
1502  * 
1503  * Returns: (transfer full): the new stream status message.
1504  *
1505  * MT safe.
1506  */
1507 GstMessage *
1508 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1509     GstElement * owner)
1510 {
1511   GstMessage *message;
1512   GstStructure *structure;
1513
1514   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
1515       GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1516       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1517   message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1518
1519   return message;
1520 }
1521
1522 /**
1523  * gst_message_parse_stream_status:
1524  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1525  * @type: (out): A pointer to hold the status type
1526  * @owner: (out) (transfer none): The owner element of the message source
1527  *
1528  * Extracts the stream status type and owner the GstMessage. The returned
1529  * owner remains valid for as long as the reference to @message is valid and
1530  * should thus not be unreffed.
1531  *
1532  * MT safe.
1533  */
1534 void
1535 gst_message_parse_stream_status (GstMessage * message,
1536     GstStreamStatusType * type, GstElement ** owner)
1537 {
1538   const GValue *owner_gvalue;
1539   GstStructure *structure;
1540
1541   g_return_if_fail (GST_IS_MESSAGE (message));
1542   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1543
1544   structure = GST_MESSAGE_STRUCTURE (message);
1545   owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
1546   g_return_if_fail (owner_gvalue != NULL);
1547
1548   if (type)
1549     *type = (GstStreamStatusType)
1550         g_value_get_enum (gst_structure_id_get_value (structure,
1551             GST_QUARK (TYPE)));
1552   if (owner)
1553     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1554 }
1555
1556 /**
1557  * gst_message_set_stream_status_object:
1558  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1559  * @object: the object controlling the streaming
1560  *
1561  * Configures the object handling the streaming thread. This is usually a
1562  * GstTask object but other objects might be added in the future.
1563  */
1564 void
1565 gst_message_set_stream_status_object (GstMessage * message,
1566     const GValue * object)
1567 {
1568   GstStructure *structure;
1569
1570   g_return_if_fail (GST_IS_MESSAGE (message));
1571   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1572
1573   structure = GST_MESSAGE_STRUCTURE (message);
1574   gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
1575 }
1576
1577 /**
1578  * gst_message_get_stream_status_object:
1579  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1580  *
1581  * Extracts the object managing the streaming thread from @message.
1582  *
1583  * Returns: a GValue containing the object that manages the streaming thread.
1584  * This object is usually of type GstTask but other types can be added in the
1585  * future. The object remains valid as long as @message is valid.
1586  */
1587 const GValue *
1588 gst_message_get_stream_status_object (GstMessage * message)
1589 {
1590   const GValue *result;
1591   GstStructure *structure;
1592
1593   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1594   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1595       NULL);
1596
1597   structure = GST_MESSAGE_STRUCTURE (message);
1598   result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
1599
1600   return result;
1601 }
1602
1603 /**
1604  * gst_message_new_step_done:
1605  * @src: The object originating the message.
1606  * @format: the format of @amount
1607  * @amount: the amount of stepped data
1608  * @rate: the rate of the stepped amount
1609  * @flush: is this an flushing step
1610  * @intermediate: is this an intermediate step
1611  * @duration: the duration of the data
1612  * @eos: the step caused EOS
1613  *
1614  * This message is posted by elements when they complete a part, when @intermediate set
1615  * to %TRUE, or a complete step operation.
1616  *
1617  * @duration will contain the amount of time (in GST_FORMAT_TIME) of the stepped
1618  * @amount of media in format @format.
1619  *
1620  * Returns: (transfer full): the new step_done message.
1621  *
1622  * MT safe.
1623  */
1624 GstMessage *
1625 gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
1626     gdouble rate, gboolean flush, gboolean intermediate, guint64 duration,
1627     gboolean eos)
1628 {
1629   GstMessage *message;
1630   GstStructure *structure;
1631
1632   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
1633       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1634       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1635       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1636       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1637       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1638       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1639       GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1640   message = gst_message_new_custom (GST_MESSAGE_STEP_DONE, src, structure);
1641
1642   return message;
1643 }
1644
1645 /**
1646  * gst_message_parse_step_done:
1647  * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1648  * @format: (out) (allow-none): result location for the format
1649  * @amount: (out) (allow-none): result location for the amount
1650  * @rate: (out) (allow-none): result location for the rate
1651  * @flush: (out) (allow-none): result location for the flush flag
1652  * @intermediate: (out) (allow-none): result location for the intermediate flag
1653  * @duration: (out) (allow-none): result location for the duration
1654  * @eos: (out) (allow-none): result location for the EOS flag
1655  *
1656  * Extract the values the step_done message.
1657  *
1658  * MT safe.
1659  */
1660 void
1661 gst_message_parse_step_done (GstMessage * message, GstFormat * format,
1662     guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
1663     guint64 * duration, gboolean * eos)
1664 {
1665   GstStructure *structure;
1666
1667   g_return_if_fail (GST_IS_MESSAGE (message));
1668   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
1669
1670   structure = GST_MESSAGE_STRUCTURE (message);
1671   gst_structure_id_get (structure,
1672       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1673       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1674       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1675       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1676       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate,
1677       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1678       GST_QUARK (EOS), G_TYPE_BOOLEAN, eos, NULL);
1679 }
1680
1681 /**
1682  * gst_message_new_step_start:
1683  * @src: The object originating the message.
1684  * @active: if the step is active or queued
1685  * @format: the format of @amount
1686  * @amount: the amount of stepped data
1687  * @rate: the rate of the stepped amount
1688  * @flush: is this an flushing step
1689  * @intermediate: is this an intermediate step
1690  *
1691  * This message is posted by elements when they accept or activate a new step
1692  * event for @amount in @format. 
1693  *
1694  * @active is set to %FALSE when the element accepted the new step event and has
1695  * queued it for execution in the streaming threads.
1696  *
1697  * @active is set to %TRUE when the element has activated the step operation and
1698  * is now ready to start executing the step in the streaming thread. After this
1699  * message is emitted, the application can queue a new step operation in the
1700  * element.
1701  *
1702  * Returns: (transfer full): The new step_start message. 
1703  *
1704  * MT safe.
1705  */
1706 GstMessage *
1707 gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
1708     guint64 amount, gdouble rate, gboolean flush, gboolean intermediate)
1709 {
1710   GstMessage *message;
1711   GstStructure *structure;
1712
1713   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
1714       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1715       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1716       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1717       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1718       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1719       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1720   message = gst_message_new_custom (GST_MESSAGE_STEP_START, src, structure);
1721
1722   return message;
1723 }
1724
1725 /**
1726  * gst_message_parse_step_start:
1727  * @message: A valid #GstMessage of type GST_MESSAGE_STEP_DONE.
1728  * @active: (out) (allow-none): result location for the active flag
1729  * @format: (out) (allow-none): result location for the format
1730  * @amount: (out) (allow-none): result location for the amount
1731  * @rate: (out) (allow-none): result location for the rate
1732  * @flush: (out) (allow-none): result location for the flush flag
1733  * @intermediate: (out) (allow-none): result location for the intermediate flag
1734  *
1735  * Extract the values from step_start message.
1736  *
1737  * MT safe.
1738  */
1739 void
1740 gst_message_parse_step_start (GstMessage * message, gboolean * active,
1741     GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
1742     gboolean * intermediate)
1743 {
1744   GstStructure *structure;
1745
1746   g_return_if_fail (GST_IS_MESSAGE (message));
1747   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
1748
1749   structure = GST_MESSAGE_STRUCTURE (message);
1750   gst_structure_id_get (structure,
1751       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
1752       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1753       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
1754       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
1755       GST_QUARK (FLUSH), G_TYPE_BOOLEAN, flush,
1756       GST_QUARK (INTERMEDIATE), G_TYPE_BOOLEAN, intermediate, NULL);
1757 }
1758
1759 /**
1760  * gst_message_new_qos:
1761  * @src: The object originating the message.
1762  * @live: if the message was generated by a live element
1763  * @running_time: the running time of the buffer that generated the message
1764  * @stream_time: the stream time of the buffer that generated the message
1765  * @timestamp: the timestamps of the buffer that generated the message
1766  * @duration: the duration of the buffer that generated the message
1767  *
1768  * A QOS message is posted on the bus whenever an element decides to drop a
1769  * buffer because of QoS reasons or whenever it changes its processing strategy
1770  * because of QoS reasons (quality adjustments such as processing at lower
1771  * accuracy).
1772  *
1773  * This message can be posted by an element that performs synchronisation against the
1774  * clock (live) or it could be dropped by an element that performs QoS because of QOS
1775  * events received from a downstream element (!live).
1776  *
1777  * @running_time, @stream_time, @timestamp, @duration should be set to the
1778  * respective running-time, stream-time, timestamp and duration of the (dropped)
1779  * buffer that generated the QoS event. Values can be left to
1780  * GST_CLOCK_TIME_NONE when unknown.
1781  *
1782  * Returns: (transfer full): The new qos message.
1783  *
1784  * MT safe.
1785  */
1786 GstMessage *
1787 gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
1788     guint64 stream_time, guint64 timestamp, guint64 duration)
1789 {
1790   GstMessage *message;
1791   GstStructure *structure;
1792
1793   structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
1794       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1795       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1796       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1797       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1798       GST_QUARK (DURATION), G_TYPE_UINT64, duration,
1799       GST_QUARK (JITTER), G_TYPE_INT64, (gint64) 0,
1800       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, (gdouble) 1.0,
1801       GST_QUARK (QUALITY), G_TYPE_INT, (gint) 1000000,
1802       GST_QUARK (FORMAT), GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
1803       GST_QUARK (PROCESSED), G_TYPE_UINT64, (guint64) - 1,
1804       GST_QUARK (DROPPED), G_TYPE_UINT64, (guint64) - 1, NULL);
1805   message = gst_message_new_custom (GST_MESSAGE_QOS, src, structure);
1806
1807   return message;
1808 }
1809
1810 /**
1811  * gst_message_set_qos_values:
1812  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1813  * @jitter: The difference of the running-time against the deadline.
1814  * @proportion: Long term prediction of the ideal rate relative to normal rate
1815  * to get optimal quality.
1816  * @quality: An element dependent integer value that specifies the current
1817  * quality level of the element. The default maximum quality is 1000000.
1818  *
1819  * Set the QoS values that have been calculated/analysed from the QoS data
1820  *
1821  * MT safe.
1822  */
1823 void
1824 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
1825     gdouble proportion, gint quality)
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_QOS);
1831
1832   structure = GST_MESSAGE_STRUCTURE (message);
1833   gst_structure_id_set (structure,
1834       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1835       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1836       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1837 }
1838
1839 /**
1840  * gst_message_set_qos_stats:
1841  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1842  * @format: Units of the 'processed' and 'dropped' fields. Video sinks and video
1843  * filters will use GST_FORMAT_BUFFERS (frames). Audio sinks and audio filters
1844  * will likely use GST_FORMAT_DEFAULT (samples).
1845  * @processed: Total number of units correctly processed since the last state
1846  * change to READY or a flushing operation.
1847  * @dropped: Total number of units dropped since the last state change to READY
1848  * or a flushing operation.
1849  *
1850  * Set the QoS stats representing the history of the current continuous pipeline
1851  * playback period.
1852  *
1853  * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1854  * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1855  *
1856  * MT safe.
1857  */
1858 void
1859 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
1860     guint64 processed, guint64 dropped)
1861 {
1862   GstStructure *structure;
1863
1864   g_return_if_fail (GST_IS_MESSAGE (message));
1865   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1866
1867   structure = GST_MESSAGE_STRUCTURE (message);
1868   gst_structure_id_set (structure,
1869       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1870       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1871       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1872 }
1873
1874 /**
1875  * gst_message_parse_qos:
1876  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1877  * @live: (out) (allow-none): if the message was generated by a live element
1878  * @running_time: (out) (allow-none): the running time of the buffer that
1879  *     generated the message
1880  * @stream_time: (out) (allow-none): the stream time of the buffer that
1881  *     generated the message
1882  * @timestamp: (out) (allow-none): the timestamps of the buffer that
1883  *     generated the message
1884  * @duration: (out) (allow-none): the duration of the buffer that
1885  *     generated the message
1886  *
1887  * Extract the timestamps and live status from the QoS message.
1888  *
1889  * The returned values give the running_time, stream_time, timestamp and
1890  * duration of the dropped buffer. Values of GST_CLOCK_TIME_NONE mean unknown
1891  * values.
1892  *
1893  * MT safe.
1894  */
1895 void
1896 gst_message_parse_qos (GstMessage * message, gboolean * live,
1897     guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
1898     guint64 * duration)
1899 {
1900   GstStructure *structure;
1901
1902   g_return_if_fail (GST_IS_MESSAGE (message));
1903   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1904
1905   structure = GST_MESSAGE_STRUCTURE (message);
1906   gst_structure_id_get (structure,
1907       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
1908       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
1909       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
1910       GST_QUARK (TIMESTAMP), G_TYPE_UINT64, timestamp,
1911       GST_QUARK (DURATION), G_TYPE_UINT64, duration, NULL);
1912 }
1913
1914 /**
1915  * gst_message_parse_qos_values:
1916  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1917  * @jitter: (out) (allow-none): The difference of the running-time against
1918  *     the deadline.
1919  * @proportion: (out) (allow-none): Long term prediction of the ideal rate
1920  *     relative to normal rate to get optimal quality.
1921  * @quality: (out) (allow-none): An element dependent integer value that
1922  *     specifies the current quality level of the element. The default
1923  *     maximum quality is 1000000.
1924  *
1925  * Extract the QoS values that have been calculated/analysed from the QoS data
1926  *
1927  * MT safe.
1928  */
1929 void
1930 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
1931     gdouble * proportion, gint * quality)
1932 {
1933   GstStructure *structure;
1934
1935   g_return_if_fail (GST_IS_MESSAGE (message));
1936   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1937
1938   structure = GST_MESSAGE_STRUCTURE (message);
1939   gst_structure_id_get (structure,
1940       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
1941       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
1942       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
1943 }
1944
1945 /**
1946  * gst_message_parse_qos_stats:
1947  * @message: A valid #GstMessage of type GST_MESSAGE_QOS.
1948  * @format: (out) (allow-none): Units of the 'processed' and 'dropped' fields.
1949  *     Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
1950  *     Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT
1951  *     (samples).
1952  * @processed: (out) (allow-none): Total number of units correctly processed
1953  *     since the last state change to READY or a flushing operation.
1954  * @dropped: (out) (allow-none): Total number of units dropped since the last
1955  *     state change to READY or a flushing operation.
1956  *
1957  * Extract the QoS stats representing the history of the current continuous
1958  * pipeline playback period.
1959  *
1960  * When @format is @GST_FORMAT_UNDEFINED both @dropped and @processed are
1961  * invalid. Values of -1 for either @processed or @dropped mean unknown values.
1962  *
1963  * MT safe.
1964  */
1965 void
1966 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
1967     guint64 * processed, guint64 * dropped)
1968 {
1969   GstStructure *structure;
1970
1971   g_return_if_fail (GST_IS_MESSAGE (message));
1972   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
1973
1974   structure = GST_MESSAGE_STRUCTURE (message);
1975   gst_structure_id_get (structure,
1976       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1977       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
1978       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
1979 }
1980
1981 /**
1982  * gst_message_new_progress:
1983  * @src: The object originating the message.
1984  * @type: a #GstProgressType
1985  * @code: a progress code
1986  * @text: free, user visible text describing the progress
1987  *
1988  * Progress messages are posted by elements when they use an asynchronous task
1989  * to perform actions triggered by a state change.
1990  *
1991  * @code contains a well defined string describing the action.
1992  * @test should contain a user visible string detailing the current action.
1993  *
1994  * Returns: (transfer full): The new qos message.
1995  */
1996 GstMessage *
1997 gst_message_new_progress (GstObject * src, GstProgressType type,
1998     const gchar * code, const gchar * text)
1999 {
2000   GstMessage *message;
2001   GstStructure *structure;
2002   gint percent = 100, timeout = -1;
2003
2004   g_return_val_if_fail (code != NULL, NULL);
2005   g_return_val_if_fail (text != NULL, NULL);
2006
2007   if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
2008     percent = 0;
2009
2010   structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
2011       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2012       GST_QUARK (CODE), G_TYPE_STRING, code,
2013       GST_QUARK (TEXT), G_TYPE_STRING, text,
2014       GST_QUARK (PERCENT), G_TYPE_INT, percent,
2015       GST_QUARK (TIMEOUT), G_TYPE_INT, timeout, NULL);
2016   message = gst_message_new_custom (GST_MESSAGE_PROGRESS, src, structure);
2017
2018   return message;
2019 }
2020
2021 /**
2022  * gst_message_parse_progress:
2023  * @message: A valid #GstMessage of type GST_MESSAGE_PROGRESS.
2024  * @type: (out) (allow-none): location for the type
2025  * @code: (out) (allow-none) (transfer full): location for the code
2026  * @text: (out) (allow-none) (transfer full): location for the text
2027  *
2028  * Parses the progress @type, @code and @text.
2029  */
2030 void
2031 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
2032     gchar ** code, gchar ** text)
2033 {
2034   GstStructure *structure;
2035
2036   g_return_if_fail (GST_IS_MESSAGE (message));
2037   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
2038
2039   structure = GST_MESSAGE_STRUCTURE (message);
2040   gst_structure_id_get (structure,
2041       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
2042       GST_QUARK (CODE), G_TYPE_STRING, code,
2043       GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
2044 }
2045
2046 /**
2047  * gst_message_new_toc:
2048  * @src: the object originating the message.
2049  * @toc: (transfer none): #GstToc structure for the message.
2050  * @updated: whether TOC was updated or not.
2051  *
2052  * Create a new TOC message. The message is posted by elements
2053  * that discovered or updated a TOC.
2054  *
2055  * Returns: (transfer full): a new TOC message.
2056  *
2057  * MT safe.
2058  */
2059 GstMessage *
2060 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2061 {
2062   GstStructure *toc_struct;
2063
2064   g_return_val_if_fail (toc != NULL, NULL);
2065
2066   toc_struct = gst_structure_new_id (GST_QUARK (MESSAGE_TOC),
2067       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2068       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2069
2070   return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2071 }
2072
2073 /**
2074  * gst_message_parse_toc:
2075  * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2076  * @toc: (out) (transfer full): return location for the TOC.
2077  * @updated: (out): return location for the updated flag.
2078  *
2079  * Extract the TOC from the #GstMessage. The TOC returned in the
2080  * output argument is a copy; the caller must free it with
2081  * gst_toc_unref() when done.
2082  *
2083  * MT safe.
2084  */
2085 void
2086 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2087 {
2088   g_return_if_fail (GST_IS_MESSAGE (message));
2089   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2090   g_return_if_fail (toc != NULL);
2091
2092   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2093       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2094       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2095 }
2096
2097 /**
2098  * gst_message_new_reset_time:
2099  * @src: (transfer none) (allow-none): The object originating the message.
2100  * @running_time: the requested running-time
2101  *
2102  * This message is posted when the pipeline running-time should be reset to
2103  * @running_time, like after a flushing seek.
2104  *
2105  * Returns: (transfer full): The new reset_time message.
2106  *
2107  * MT safe.
2108  */
2109 GstMessage *
2110 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2111 {
2112   GstMessage *message;
2113   GstStructure *structure;
2114
2115   structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2116       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2117   message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2118
2119   return message;
2120 }
2121
2122 /**
2123  * gst_message_parse_reset_time:
2124  * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2125  * @running_time: (out) (allow-none): Result location for the running_time or
2126  *      %NULL
2127  *
2128  * Extract the running-time from the RESET_TIME message.
2129  *
2130  * MT safe.
2131  */
2132 void
2133 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2134 {
2135   GstStructure *structure;
2136
2137   g_return_if_fail (GST_IS_MESSAGE (message));
2138   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2139
2140   structure = GST_MESSAGE_STRUCTURE (message);
2141   if (running_time)
2142     *running_time =
2143         g_value_get_uint64 (gst_structure_id_get_value (structure,
2144             GST_QUARK (RUNNING_TIME)));
2145 }
2146
2147 /**
2148  * gst_message_new_stream_start:
2149  * @src: (transfer none) (allow-none): The object originating the message.
2150  *
2151  * Create a new stream_start message. This message is generated and posted in
2152  * the sink elements of a GstBin. The bin will only forward the STREAM_START
2153  * message to the application if all sinks have posted an STREAM_START message.
2154  *
2155  * Returns: (transfer full): The new stream_start message.
2156  *
2157  * MT safe.
2158  */
2159 GstMessage *
2160 gst_message_new_stream_start (GstObject * src)
2161 {
2162   GstMessage *message;
2163   GstStructure *s;
2164
2165   s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_STREAM_START));
2166   message = gst_message_new_custom (GST_MESSAGE_STREAM_START, src, s);
2167
2168   return message;
2169 }
2170
2171
2172 /**
2173  * gst_message_set_group_id:
2174  * @message: the message
2175  * @group_id: the group id
2176  *
2177  * Sets the group id on the stream-start message.
2178  *
2179  * All streams that have the same group id are supposed to be played
2180  * together, i.e. all streams inside a container file should have the
2181  * same group id but different stream ids. The group id should change
2182  * each time the stream is started, resulting in different group ids
2183  * each time a file is played for example.
2184  *
2185  * MT safe.
2186  *
2187  * Since: 1.2
2188  */
2189 void
2190 gst_message_set_group_id (GstMessage * message, guint group_id)
2191 {
2192   GstStructure *structure;
2193
2194   g_return_if_fail (GST_IS_MESSAGE (message));
2195   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START);
2196   g_return_if_fail (gst_message_is_writable (message));
2197
2198   structure = GST_MESSAGE_STRUCTURE (message);
2199   gst_structure_id_set (structure, GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id,
2200       NULL);
2201 }
2202
2203 /**
2204  * gst_message_parse_group_id:
2205  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_START.
2206  * @group_id: (out) (allow-none): Result location for the group id or
2207  *      %NULL
2208  *
2209  * Extract the group from the STREAM_START message.
2210  *
2211  * Returns: %TRUE if the message had a group id set, %FALSE otherwise
2212  *
2213  * MT safe.
2214  *
2215  * Since: 1.2
2216  */
2217 gboolean
2218 gst_message_parse_group_id (GstMessage * message, guint * group_id)
2219 {
2220   GstStructure *structure;
2221   const GValue *v;
2222
2223   g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
2224   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_START,
2225       FALSE);
2226
2227   if (!group_id)
2228     return TRUE;
2229
2230   structure = GST_MESSAGE_STRUCTURE (message);
2231
2232   v = gst_structure_id_get_value (structure, GST_QUARK (GROUP_ID));
2233   if (!v)
2234     return FALSE;
2235
2236   *group_id = g_value_get_uint (v);
2237   return TRUE;
2238 }
2239
2240 /**
2241  * gst_message_new_need_context:
2242  * @src: (transfer none) (allow-none): The object originating the message.
2243  * @context_type: The context type that is needed
2244  *
2245  * This message is posted when an element needs a specific #GstContext.
2246  *
2247  * Returns: (transfer full): The new need-context message.
2248  *
2249  * MT safe.
2250  *
2251  * Since: 1.2
2252  */
2253 GstMessage *
2254 gst_message_new_need_context (GstObject * src, const gchar * context_type)
2255 {
2256   GstMessage *message;
2257   GstStructure *structure;
2258
2259   g_return_val_if_fail (context_type != NULL, NULL);
2260
2261   structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEED_CONTEXT),
2262       GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2263   message = gst_message_new_custom (GST_MESSAGE_NEED_CONTEXT, src, structure);
2264
2265   return message;
2266 }
2267
2268 /**
2269  * gst_message_parse_context_type:
2270  * @message: a GST_MESSAGE_NEED_CONTEXT type message
2271  * @context_type: (out) (allow-none): the context type, or %NULL
2272  *
2273  * Parse a context type from an existing GST_MESSAGE_NEED_CONTEXT message.
2274  *
2275  * Returns: a #gboolean indicating if the parsing succeeded.
2276  *
2277  * Since: 1.2
2278  */
2279 gboolean
2280 gst_message_parse_context_type (GstMessage * message,
2281     const gchar ** context_type)
2282 {
2283   GstStructure *structure;
2284   const GValue *value;
2285
2286   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT,
2287       FALSE);
2288
2289   structure = GST_MESSAGE_STRUCTURE (message);
2290
2291   if (context_type) {
2292     value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2293     *context_type = g_value_get_string (value);
2294   }
2295
2296   return TRUE;
2297 }
2298
2299 /**
2300  * gst_message_new_have_context:
2301  * @src: (transfer none) (allow-none): The object originating the message.
2302  * @context: (transfer full): the context
2303  *
2304  * This message is posted when an element has a new local #GstContext.
2305  *
2306  * Returns: (transfer full): The new have-context message.
2307  *
2308  * MT safe.
2309  *
2310  * Since: 1.2
2311  */
2312 GstMessage *
2313 gst_message_new_have_context (GstObject * src, GstContext * context)
2314 {
2315   GstMessage *message;
2316   GstStructure *structure;
2317
2318   structure = gst_structure_new_id (GST_QUARK (MESSAGE_HAVE_CONTEXT),
2319       GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2320   message = gst_message_new_custom (GST_MESSAGE_HAVE_CONTEXT, src, structure);
2321   gst_context_unref (context);
2322
2323   return message;
2324 }
2325
2326 /**
2327  * gst_message_parse_have_context:
2328  * @message: A valid #GstMessage of type GST_MESSAGE_HAVE_CONTEXT.
2329  * @context: (out) (transfer full) (allow-none): Result location for the
2330  *      context or %NULL
2331  *
2332  * Extract the context from the HAVE_CONTEXT message.
2333  *
2334  * MT safe.
2335  *
2336  * Since: 1.2
2337  */
2338 void
2339 gst_message_parse_have_context (GstMessage * message, GstContext ** context)
2340 {
2341   g_return_if_fail (GST_IS_MESSAGE (message));
2342   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_HAVE_CONTEXT);
2343
2344   if (context)
2345     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2346         GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2347 }
2348
2349 /**
2350  * gst_message_new_device_added:
2351  * @src: The #GstObject that created the message
2352  * @device: (transfer none): The new #GstDevice
2353  *
2354  * Creates a new device-added message. The device-added message is produced by
2355  * #GstDeviceProvider or a #GstDeviceMonitor. They announce the appearance
2356  * of monitored devices.
2357  *
2358  * Returns: a newly allocated #GstMessage
2359  *
2360  * Since: 1.4
2361  */
2362 GstMessage *
2363 gst_message_new_device_added (GstObject * src, GstDevice * device)
2364 {
2365   GstMessage *message;
2366   GstStructure *structure;
2367
2368   g_return_val_if_fail (device != NULL, NULL);
2369   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2370
2371   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_ADDED),
2372       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2373   message = gst_message_new_custom (GST_MESSAGE_DEVICE_ADDED, src, structure);
2374
2375   return message;
2376 }
2377
2378 /**
2379  * gst_message_parse_device_added:
2380  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_ADDED
2381  * @device: (out) (allow-none) (transfer none): A location where to store a
2382  *  pointer to the new #GstDevice, or %NULL
2383  * 
2384  * Parses a device-added message. The device-added message is produced by
2385  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the appearance
2386  * of monitored devices.
2387  *
2388  * Since: 1.4
2389  */
2390 void
2391 gst_message_parse_device_added (GstMessage * message, GstDevice ** device)
2392 {
2393   g_return_if_fail (GST_IS_MESSAGE (message));
2394   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_ADDED);
2395
2396   if (device)
2397     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2398         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2399 }
2400
2401 /**
2402  * gst_message_new_device_removed:
2403  * @src: The #GstObject that created the message
2404  * @device: (transfer none): The removed #GstDevice
2405  *
2406  * Creates a new device-removed message. The device-removed message is produced
2407  * by #GstDeviceProvider or a #GstDeviceMonitor. They announce the
2408  * disappearance of monitored devices.
2409  *
2410  * Returns: a newly allocated #GstMessage
2411  *
2412  * Since: 1.4
2413  */
2414 GstMessage *
2415 gst_message_new_device_removed (GstObject * src, GstDevice * device)
2416 {
2417   GstMessage *message;
2418   GstStructure *structure;
2419
2420   g_return_val_if_fail (device != NULL, NULL);
2421   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
2422
2423   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DEVICE_REMOVED),
2424       GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2425   message = gst_message_new_custom (GST_MESSAGE_DEVICE_REMOVED, src, structure);
2426
2427   return message;
2428 }
2429
2430 /**
2431  * gst_message_parse_device_removed:
2432  * @message: a #GstMessage of type %GST_MESSAGE_DEVICE_REMOVED
2433  * @device: (out) (allow-none) (transfer none): A location where to store a
2434  *  pointer to the removed #GstDevice, or %NULL
2435  *
2436  * Parses a device-removed message. The device-removed message is produced by
2437  * #GstDeviceProvider or a #GstDeviceMonitor. It announces the
2438  * disappearance of monitored devices.
2439  *
2440  * Since: 1.4
2441  */
2442 void
2443 gst_message_parse_device_removed (GstMessage * message, GstDevice ** device)
2444 {
2445   g_return_if_fail (GST_IS_MESSAGE (message));
2446   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DEVICE_REMOVED);
2447
2448   if (device)
2449     gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2450         GST_QUARK (DEVICE), GST_TYPE_DEVICE, device, NULL);
2451 }