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