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