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