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