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