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