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