gstmessage: New GST_MESSAGE_STREAM_START
[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   {GST_MESSAGE_TOC, "toc", 0},
108   {GST_MESSAGE_STREAM_START, "stream-start", 0},
109   {0, NULL, 0}
110 };
111
112 static GType _gst_message_type = 0;
113 GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
114
115 void
116 _priv_gst_message_initialize (void)
117 {
118   gint i;
119
120   GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
121
122   /* the GstMiniObject types need to be class_ref'd once before it can be
123    * done from multiple threads;
124    * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
125   gst_message_get_type ();
126
127   for (i = 0; message_quarks[i].name; i++) {
128     message_quarks[i].quark =
129         g_quark_from_static_string (message_quarks[i].name);
130   }
131
132   _gst_message_type = gst_message_get_type ();
133 }
134
135 /**
136  * gst_message_type_get_name:
137  * @type: the message type
138  *
139  * Get a printable name for the given message type. Do not modify or free.
140  *
141  * Returns: a reference to the static name of the message.
142  */
143 const gchar *
144 gst_message_type_get_name (GstMessageType type)
145 {
146   gint i;
147
148   for (i = 0; message_quarks[i].name; i++) {
149     if (type == message_quarks[i].type)
150       return message_quarks[i].name;
151   }
152   return "unknown";
153 }
154
155 /**
156  * gst_message_type_to_quark:
157  * @type: the message type
158  *
159  * Get the unique quark for the given message type.
160  *
161  * Returns: the quark associated with the message type
162  */
163 GQuark
164 gst_message_type_to_quark (GstMessageType type)
165 {
166   gint i;
167
168   for (i = 0; message_quarks[i].name; i++) {
169     if (type == message_quarks[i].type)
170       return message_quarks[i].quark;
171   }
172   return 0;
173 }
174
175 static void
176 _gst_message_free (GstMessage * message)
177 {
178   GstStructure *structure;
179
180   g_return_if_fail (message != NULL);
181
182   GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
183       GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message));
184
185   if (GST_MESSAGE_SRC (message)) {
186     gst_object_unref (GST_MESSAGE_SRC (message));
187     GST_MESSAGE_SRC (message) = NULL;
188   }
189
190   if (message->lock.p) {
191     GST_MESSAGE_LOCK (message);
192     GST_MESSAGE_SIGNAL (message);
193     GST_MESSAGE_UNLOCK (message);
194   }
195
196   structure = GST_MESSAGE_STRUCTURE (message);
197   if (structure) {
198     gst_structure_set_parent_refcount (structure, NULL);
199     gst_structure_free (structure);
200   }
201
202   g_slice_free1 (sizeof (GstMessageImpl), message);
203 }
204
205 static void
206 gst_message_init (GstMessageImpl * message, GstMessageType type,
207     GstObject * src);
208
209 static GstMessage *
210 _gst_message_copy (GstMessage * message)
211 {
212   GstMessageImpl *copy;
213   GstStructure *structure;
214
215   GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
216       GST_MESSAGE_TYPE_NAME (message),
217       GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
218
219   copy = g_slice_new0 (GstMessageImpl);
220
221   gst_message_init (copy, GST_MESSAGE_TYPE (message),
222       GST_MESSAGE_SRC (message));
223
224   GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
225   GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
226
227   structure = GST_MESSAGE_STRUCTURE (message);
228   if (structure) {
229     GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
230     gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
231         &copy->message.mini_object.refcount);
232   } else {
233     GST_MESSAGE_STRUCTURE (copy) = NULL;
234   }
235
236   return GST_MESSAGE_CAST (copy);
237 }
238
239 static void
240 gst_message_init (GstMessageImpl * message, GstMessageType type,
241     GstObject * src)
242 {
243   gst_mini_object_init (GST_MINI_OBJECT_CAST (message), 0, _gst_message_type,
244       (GstMiniObjectCopyFunction) _gst_message_copy, NULL,
245       (GstMiniObjectFreeFunction) _gst_message_free);
246
247   GST_MESSAGE_TYPE (message) = type;
248   if (src)
249     gst_object_ref (src);
250   GST_MESSAGE_SRC (message) = src;
251   GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
252   GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
253 }
254
255
256 /**
257  * gst_message_new_custom:
258  * @type: The #GstMessageType to distinguish messages
259  * @src: The object originating the message.
260  * @structure: (transfer full): the structure for the message. The message
261  *     will take ownership of the structure.
262  *
263  * Create a new custom-typed message. This can be used for anything not
264  * handled by other message-specific functions to pass a message to the
265  * app. The structure field can be NULL.
266  *
267  * Returns: (transfer full): The new message.
268  *
269  * MT safe.
270  */
271 GstMessage *
272 gst_message_new_custom (GstMessageType type, GstObject * src,
273     GstStructure * structure)
274 {
275   GstMessageImpl *message;
276
277   message = g_slice_new0 (GstMessageImpl);
278
279   GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
280       (src ? GST_OBJECT_NAME (src) : "NULL"), message,
281       gst_message_type_get_name (type));
282
283   if (structure) {
284     /* structure must not have a parent */
285     if (!gst_structure_set_parent_refcount (structure,
286             &message->message.mini_object.refcount))
287       goto had_parent;
288   }
289   gst_message_init (message, type, src);
290
291   GST_MESSAGE_STRUCTURE (message) = structure;
292
293   return GST_MESSAGE_CAST (message);
294
295   /* ERRORS */
296 had_parent:
297   {
298     g_slice_free1 (sizeof (GstMessageImpl), message);
299     g_warning ("structure is already owned by another object");
300     return NULL;
301   }
302 }
303
304 /**
305  * gst_message_get_seqnum:
306  * @message: A #GstMessage.
307  *
308  * Retrieve the sequence number of a message.
309  *
310  * Messages have ever-incrementing sequence numbers, which may also be set
311  * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
312  * to indicate that a message corresponds to some other set of messages or
313  * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
314  * is considered good practice to make this correspondence when possible, though
315  * it is not required.
316  *
317  * Note that events and messages share the same sequence number incrementor;
318  * two events or messages will never have the same sequence number unless
319  * that correspondence was made explicitly.
320  *
321  * Returns: The message's sequence number.
322  *
323  * MT safe.
324  *
325  * Since: 0.10.22
326  */
327 guint32
328 gst_message_get_seqnum (GstMessage * message)
329 {
330   g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
331
332   return GST_MESSAGE_SEQNUM (message);
333 }
334
335 /**
336  * gst_message_set_seqnum:
337  * @message: A #GstMessage.
338  * @seqnum: A sequence number.
339  *
340  * Set the sequence number of a message.
341  *
342  * This function might be called by the creator of a message to indicate that
343  * the message relates to other messages or events. See gst_message_get_seqnum()
344  * for more information.
345  *
346  * MT safe.
347  *
348  * Since: 0.10.22
349  */
350 void
351 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
352 {
353   g_return_if_fail (GST_IS_MESSAGE (message));
354
355   GST_MESSAGE_SEQNUM (message) = seqnum;
356 }
357
358 /**
359  * gst_message_new_eos:
360  * @src: (transfer none): The object originating the message.
361  *
362  * Create a new eos message. This message is generated and posted in
363  * the sink elements of a GstBin. The bin will only forward the EOS
364  * message to the application if all sinks have posted an EOS message.
365  *
366  * Returns: (transfer full): The new eos message.
367  *
368  * MT safe.
369  */
370 GstMessage *
371 gst_message_new_eos (GstObject * src)
372 {
373   GstMessage *message;
374
375   message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
376
377   return message;
378 }
379
380 /**
381  * gst_message_new_error:
382  * @src: (transfer none): The object originating the message.
383  * @error: (transfer none): The GError for this message.
384  * @debug: A debugging string.
385  *
386  * Create a new error message. The message will copy @error and
387  * @debug. This message is posted by element when a fatal event
388  * occured. The pipeline will probably (partially) stop. The application
389  * receiving this message should stop the pipeline.
390  *
391  * Returns: (transfer full): the new error message.
392  *
393  * MT safe.
394  */
395 GstMessage *
396 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
397 {
398   GstMessage *message;
399   GstStructure *structure;
400
401   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
402       GST_QUARK (GERROR), G_TYPE_ERROR, error,
403       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
404   message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
405
406   return message;
407 }
408
409 /**
410  * gst_message_new_warning:
411  * @src: (transfer none): The object originating the message.
412  * @error: (transfer none): The GError for this message.
413  * @debug: A debugging string.
414  *
415  * Create a new warning message. The message will make copies of @error and
416  * @debug.
417  *
418  * Returns: (transfer full): The new warning message.
419  *
420  * MT safe.
421  */
422 GstMessage *
423 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
424 {
425   GstMessage *message;
426   GstStructure *structure;
427
428   structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
429       GST_QUARK (GERROR), G_TYPE_ERROR, error,
430       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
431   message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
432
433   return message;
434 }
435
436 /**
437  * gst_message_new_info:
438  * @src: (transfer none): The object originating the message.
439  * @error: (transfer none): The GError for this message.
440  * @debug: A debugging string.
441  *
442  * Create a new info message. The message will make copies of @error and
443  * @debug.
444  *
445  * MT safe.
446  *
447  * Returns: (transfer full): the new info message.
448  *
449  * Since: 0.10.12
450  */
451 GstMessage *
452 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
453 {
454   GstMessage *message;
455   GstStructure *structure;
456
457   structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
458       GST_QUARK (GERROR), G_TYPE_ERROR, error,
459       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
460   message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
461
462   return message;
463 }
464
465 /**
466  * gst_message_new_tag:
467  * @src: (transfer none): The object originating the message.
468  * @tag_list: (transfer full): the tag list for the message.
469  *
470  * Create a new tag message. The message will take ownership of the tag list.
471  * The message is posted by elements that discovered a new taglist.
472  *
473  * Returns: (transfer full): the new tag message.
474  *
475  * MT safe.
476  */
477 GstMessage *
478 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
479 {
480   GstStructure *s;
481   GstMessage *message;
482   GValue val = G_VALUE_INIT;
483
484   g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
485
486   s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
487   g_value_init (&val, GST_TYPE_TAG_LIST);
488   g_value_take_boxed (&val, tag_list);
489   gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
490   message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
491   return message;
492 }
493
494 /**
495  * gst_message_new_buffering:
496  * @src: (transfer none): The object originating the message.
497  * @percent: The buffering percent
498  *
499  * Create a new buffering message. This message can be posted by an element that
500  * needs to buffer data before it can continue processing. @percent should be a
501  * value between 0 and 100. A value of 100 means that the buffering completed.
502  *
503  * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
504  * @percent is 100, the application can set the pipeline (back) to PLAYING.
505  * The application must be prepared to receive BUFFERING messages in the
506  * PREROLLING state and may only set the pipeline to PLAYING after receiving a
507  * message with @percent set to 100, which can happen after the pipeline
508  * completed prerolling. 
509  *
510  * MT safe.
511  *
512  * Returns: (transfer full): The new buffering message.
513  *
514  * Since: 0.10.11
515  */
516 GstMessage *
517 gst_message_new_buffering (GstObject * src, gint percent)
518 {
519   GstMessage *message;
520   GstStructure *structure;
521
522   g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
523
524   structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
525       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
526       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
527       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
528       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
529       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
530       GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
531   message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
532
533   return message;
534 }
535
536 /**
537  * gst_message_new_state_changed:
538  * @src: (transfer none): the object originating the message
539  * @oldstate: the previous state
540  * @newstate: the new (current) state
541  * @pending: the pending (target) state
542  *
543  * Create a state change message. This message is posted whenever an element
544  * changed its state.
545  *
546  * Returns: (transfer full): the new state change message.
547  *
548  * MT safe.
549  */
550 GstMessage *
551 gst_message_new_state_changed (GstObject * src,
552     GstState oldstate, GstState newstate, GstState pending)
553 {
554   GstMessage *message;
555   GstStructure *structure;
556
557   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
558       GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
559       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
560       GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
561   message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
562
563   return message;
564 }
565
566 /**
567  * gst_message_new_state_dirty:
568  * @src: (transfer none): the object originating the message
569  *
570  * Create a state dirty message. This message is posted whenever an element
571  * changed its state asynchronously and is used internally to update the
572  * states of container objects.
573  *
574  * Returns: (transfer full): the new state dirty message.
575  *
576  * MT safe.
577  */
578 GstMessage *
579 gst_message_new_state_dirty (GstObject * src)
580 {
581   GstMessage *message;
582
583   message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
584
585   return message;
586 }
587
588 /**
589  * gst_message_new_clock_provide:
590  * @src: (transfer none): the object originating the message.
591  * @clock: (transfer none): the clock it provides
592  * @ready: TRUE if the sender can provide a clock
593  *
594  * Create a clock provide message. This message is posted whenever an
595  * element is ready to provide a clock or lost its ability to provide
596  * a clock (maybe because it paused or became EOS).
597  *
598  * This message is mainly used internally to manage the clock
599  * selection.
600  *
601  * Returns: (transfer full): the new provide clock message.
602  *
603  * MT safe.
604  */
605 GstMessage *
606 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
607     gboolean ready)
608 {
609   GstMessage *message;
610   GstStructure *structure;
611
612   structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
613       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
614       GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
615   message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
616
617   return message;
618 }
619
620 /**
621  * gst_message_new_clock_lost:
622  * @src: (transfer none): the object originating the message.
623  * @clock: (transfer none): the clock that was lost
624  *
625  * Create a clock lost message. This message is posted whenever the
626  * clock is not valid anymore.
627  *
628  * If this message is posted by the pipeline, the pipeline will
629  * select a new clock again when it goes to PLAYING. It might therefore
630  * be needed to set the pipeline to PAUSED and PLAYING again.
631  *
632  * Returns: (transfer full): The new clock lost message.
633  *
634  * MT safe.
635  */
636 GstMessage *
637 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
638 {
639   GstMessage *message;
640   GstStructure *structure;
641
642   structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
643       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
644   message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
645
646   return message;
647 }
648
649 /**
650  * gst_message_new_new_clock:
651  * @src: (transfer none): The object originating the message.
652  * @clock: (transfer none): the new selected clock
653  *
654  * Create a new clock message. This message is posted whenever the
655  * pipeline selectes a new clock for the pipeline.
656  *
657  * Returns: (transfer full): The new new clock message.
658  *
659  * MT safe.
660  */
661 GstMessage *
662 gst_message_new_new_clock (GstObject * src, GstClock * clock)
663 {
664   GstMessage *message;
665   GstStructure *structure;
666
667   structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
668       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
669   message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
670
671   return message;
672 }
673
674 /**
675  * gst_message_new_structure_change:
676  * @src: (transfer none): The object originating the message.
677  * @type: The change type.
678  * @owner: (transfer none): The owner element of @src.
679  * @busy: Whether the structure change is busy.
680  *
681  * Create a new structure change message. This message is posted when the
682  * structure of a pipeline is in the process of being changed, for example
683  * when pads are linked or unlinked.
684  *
685  * @src should be the sinkpad that unlinked or linked.
686  *
687  * Returns: (transfer full): the new structure change message.
688  *
689  * MT safe.
690  *
691  * Since: 0.10.22.
692  */
693 GstMessage *
694 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
695     GstElement * owner, gboolean busy)
696 {
697   GstMessage *message;
698   GstStructure *structure;
699
700   g_return_val_if_fail (GST_IS_PAD (src), NULL);
701   /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
702   g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
703
704   structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
705       GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
706       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
707       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
708
709   message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
710       structure);
711
712   return message;
713 }
714
715 /**
716  * gst_message_new_segment_start:
717  * @src: (transfer none): The object originating the message.
718  * @format: The format of the position being played
719  * @position: The position of the segment being played
720  *
721  * Create a new segment message. This message is posted by elements that
722  * start playback of a segment as a result of a segment seek. This message
723  * is not received by the application but is used for maintenance reasons in
724  * container elements.
725  *
726  * Returns: (transfer full): the new segment start message.
727  *
728  * MT safe.
729  */
730 GstMessage *
731 gst_message_new_segment_start (GstObject * src, GstFormat format,
732     gint64 position)
733 {
734   GstMessage *message;
735   GstStructure *structure;
736
737   structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
738       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
739       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
740   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
741
742   return message;
743 }
744
745 /**
746  * gst_message_new_segment_done:
747  * @src: (transfer none): the object originating the message.
748  * @format: The format of the position being done
749  * @position: The position of the segment being done
750  *
751  * Create a new segment done message. This message is posted by elements that
752  * finish playback of a segment as a result of a segment seek. This message
753  * is received by the application after all elements that posted a segment_start
754  * have posted the segment_done.
755  *
756  * Returns: (transfer full): the new segment done message.
757  *
758  * MT safe.
759  */
760 GstMessage *
761 gst_message_new_segment_done (GstObject * src, GstFormat format,
762     gint64 position)
763 {
764   GstMessage *message;
765   GstStructure *structure;
766
767   structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
768       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
769       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
770   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
771
772   return message;
773 }
774
775 /**
776  * gst_message_new_application:
777  * @src: (transfer none): the object originating the message.
778  * @structure: (transfer full): the structure for the message. The message
779  *     will take ownership of the structure.
780  *
781  * Create a new application-typed message. GStreamer will never create these
782  * messages; they are a gift from us to you. Enjoy.
783  *
784  * Returns: (transfer full): The new application message.
785  *
786  * MT safe.
787  */
788 GstMessage *
789 gst_message_new_application (GstObject * src, GstStructure * structure)
790 {
791   return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
792 }
793
794 /**
795  * gst_message_new_element:
796  * @src: (transfer none): The object originating the message.
797  * @structure: (transfer full): The structure for the message. The message
798  *     will take ownership of the structure.
799  *
800  * Create a new element-specific message. This is meant as a generic way of
801  * allowing one-way communication from an element to an application, for example
802  * "the firewire cable was unplugged". The format of the message should be
803  * documented in the element's documentation. The structure field can be NULL.
804  *
805  * Returns: (transfer full): The new element message.
806  *
807  * MT safe.
808  */
809 GstMessage *
810 gst_message_new_element (GstObject * src, GstStructure * structure)
811 {
812   return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
813 }
814
815 /**
816  * gst_message_new_duration:
817  * @src: (transfer none): The object originating the message.
818  * @format: The format of the duration
819  * @duration: The new duration 
820  *
821  * Create a new duration message. This message is posted by elements that
822  * know the duration of a stream in a specific format. This message
823  * is received by bins and is used to calculate the total duration of a
824  * pipeline. Elements may post a duration message with a duration of
825  * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the 
826  * cached duration should be discarded. The new duration can then be 
827  * retrieved via a query.
828  *
829  * Returns: (transfer full): The new duration message.
830  *
831  * MT safe.
832  */
833 GstMessage *
834 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
835 {
836   GstMessage *message;
837   GstStructure *structure;
838
839   structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION),
840       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
841       GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
842   message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
843
844   return message;
845 }
846
847 /**
848  * gst_message_new_async_start:
849  * @src: (transfer none): The object originating the message.
850  *
851  * This message is posted by elements when they start an ASYNC state change.
852  *
853  * Returns: (transfer full): The new async_start message.
854  *
855  * MT safe.
856  */
857 GstMessage *
858 gst_message_new_async_start (GstObject * src)
859 {
860   GstMessage *message;
861
862   message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
863
864   return message;
865 }
866
867 /**
868  * gst_message_new_async_done:
869  * @src: (transfer none): The object originating the message.
870  * @running_time: the desired running_time
871  *
872  * The message is posted when elements completed an ASYNC state change.
873  * @running_time contains the time of the desired running_time when this
874  * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
875  * means that the element has no clock interaction and thus doesn't care about
876  * the running_time of the pipeline.
877  *
878  * Returns: (transfer full): The new async_done message.
879  *
880  * MT safe.
881  */
882 GstMessage *
883 gst_message_new_async_done (GstObject * src, GstClockTime running_time)
884 {
885   GstMessage *message;
886   GstStructure *structure;
887
888   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
889       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
890   message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
891
892   return message;
893 }
894
895 /**
896  * gst_message_new_latency:
897  * @src: (transfer none): The object originating the message.
898  *
899  * This message can be posted by elements when their latency requirements have
900  * changed.
901  *
902  * Returns: (transfer full): The new latency message.
903  *
904  * MT safe.
905  *
906  * Since: 0.10.12
907  */
908 GstMessage *
909 gst_message_new_latency (GstObject * src)
910 {
911   GstMessage *message;
912
913   message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
914
915   return message;
916 }
917
918 /**
919  * gst_message_new_request_state:
920  * @src: (transfer none): the object originating the message.
921  * @state: The new requested state
922  *
923  * This message can be posted by elements when they want to have their state
924  * changed. A typical use case would be an audio server that wants to pause the
925  * pipeline because a higher priority stream is being played.
926  *
927  * Returns: (transfer full): the new requst state message.
928  *
929  * MT safe.
930  *
931  * Since: 0.10.23
932  */
933 GstMessage *
934 gst_message_new_request_state (GstObject * src, GstState state)
935 {
936   GstMessage *message;
937   GstStructure *structure;
938
939   structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
940       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
941   message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
942
943   return message;
944 }
945
946 /**
947  * gst_message_get_structure:
948  * @message: The #GstMessage.
949  *
950  * Access the structure of the message.
951  *
952  * Returns: (transfer none): The structure of the message. The structure is
953  * still owned by the message, which means that you should not free it and
954  * that the pointer becomes invalid when you free the message.
955  *
956  * MT safe.
957  */
958 const GstStructure *
959 gst_message_get_structure (GstMessage * message)
960 {
961   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
962
963   return GST_MESSAGE_STRUCTURE (message);
964 }
965
966 /**
967  * gst_message_has_name:
968  * @message: The #GstMessage.
969  * @name: name to check
970  *
971  * Checks if @message has the given @name. This function is usually used to
972  * check the name of a custom message.
973  *
974  * Returns: %TRUE if @name matches the name of the message structure.
975  *
976  * Since: 0.10.20
977  */
978 gboolean
979 gst_message_has_name (GstMessage * message, const gchar * name)
980 {
981   GstStructure *structure;
982
983   g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
984
985   structure = GST_MESSAGE_STRUCTURE (message);
986   if (structure == NULL)
987     return FALSE;
988
989   return gst_structure_has_name (structure, name);
990 }
991
992 /**
993  * gst_message_parse_tag:
994  * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
995  * @tag_list: (out callee-allocates): return location for the tag-list.
996  *
997  * Extracts the tag list from the GstMessage. The tag list returned in the
998  * output argument is a copy; the caller must free it when done.
999  *
1000  * Typical usage of this function might be:
1001  * |[
1002  *   ...
1003  *   switch (GST_MESSAGE_TYPE (msg)) {
1004  *     case GST_MESSAGE_TAG: {
1005  *       GstTagList *tags = NULL;
1006  *       
1007  *       gst_message_parse_tag (msg, &amp;tags);
1008  *       g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
1009  *       handle_tags (tags);
1010  *       gst_tag_list_unref (tags);
1011  *       break;
1012  *     }
1013  *     ...
1014  *   }
1015  *   ...
1016  * ]|
1017  *
1018  * MT safe.
1019  */
1020 void
1021 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
1022 {
1023   g_return_if_fail (GST_IS_MESSAGE (message));
1024   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
1025   g_return_if_fail (tag_list != NULL);
1026
1027   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
1028       GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
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  * @running_time: (out): Result location for the running_time or NULL
1545  *
1546  * Extract the running_time from the async_done message.
1547  *
1548  * MT safe.
1549  */
1550 void
1551 gst_message_parse_async_done (GstMessage * message, GstClockTime * running_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 (running_time)
1560     *running_time =
1561         g_value_get_uint64 (gst_structure_id_get_value (structure,
1562             GST_QUARK (RUNNING_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 }
2174
2175 /**
2176  * gst_message_new_toc:
2177  * @src: the object originating the message.
2178  * @toc: (transfer none): #GstToc structure for the message.
2179  * @updated: whether TOC was updated or not.
2180  *
2181  * Create a new TOC message. The message is posted by elements
2182  * that discovered or updated a TOC.
2183  *
2184  * Returns: (transfer full): a new TOC message.
2185  *
2186  * MT safe.
2187  *
2188  * Since: 0.10.37
2189  */
2190 GstMessage *
2191 gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
2192 {
2193   GstStructure *toc_struct;
2194
2195   g_return_val_if_fail (toc != NULL, NULL);
2196
2197   toc_struct = gst_structure_new_id (GST_QUARK (MESSAGE_TOC),
2198       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2199       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2200
2201   return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
2202 }
2203
2204 /**
2205  * gst_message_parse_toc:
2206  * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
2207  * @toc: (out) (transfer full): return location for the TOC.
2208  * @updated: (out): return location for the updated flag.
2209  *
2210  * Extract thef TOC from the #GstMessage. The TOC returned in the
2211  * output argument is a copy; the caller must free it with
2212  * gst_toc_unref() when done.
2213  *
2214  * MT safe.
2215  *
2216  * Since: 0.10.37
2217  */
2218 void
2219 gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
2220 {
2221   g_return_if_fail (GST_IS_MESSAGE (message));
2222   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
2223   g_return_if_fail (toc != NULL);
2224
2225   gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
2226       GST_QUARK (TOC), GST_TYPE_TOC, toc,
2227       GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
2228 }
2229
2230 /**
2231  * gst_message_new_reset_time:
2232  * @src: (transfer none): The object originating the message.
2233  * @running_time: the requested running-time
2234  *
2235  * This message is posted when the pipeline running-time should be reset to
2236  * @running_time, like after a flushing seek.
2237  *
2238  * Returns: (transfer full): The new reset_time message.
2239  *
2240  * MT safe.
2241  */
2242 GstMessage *
2243 gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
2244 {
2245   GstMessage *message;
2246   GstStructure *structure;
2247
2248   structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
2249       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
2250   message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
2251
2252   return message;
2253 }
2254
2255 /**
2256  * gst_message_parse_reset_time:
2257  * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
2258  * @running_time: (out): Result location for the running_time or NULL
2259  *
2260  * Extract the running-time from the RESET_TIME message.
2261  *
2262  * MT safe.
2263  */
2264 void
2265 gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
2266 {
2267   GstStructure *structure;
2268
2269   g_return_if_fail (GST_IS_MESSAGE (message));
2270   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
2271
2272   structure = GST_MESSAGE_STRUCTURE (message);
2273   if (running_time)
2274     *running_time =
2275         g_value_get_uint64 (gst_structure_id_get_value (structure,
2276             GST_QUARK (RUNNING_TIME)));
2277 }
2278
2279 /**
2280  * gst_message_new_stream_start:
2281  * @src: (transfer none): The object originating the message.
2282  *
2283  * Create a new stream_start message. This message is generated and posted in
2284  * the sink elements of a GstBin. The bin will only forward the STREAM_START
2285  * message to the application if all sinks have posted an STREAM_START message.
2286  *
2287  * Returns: (transfer full): The new stream_start message.
2288  *
2289  * MT safe.
2290  */
2291 GstMessage *
2292 gst_message_new_stream_start (GstObject * src)
2293 {
2294   GstMessage *message;
2295
2296   message = gst_message_new_custom (GST_MESSAGE_STREAM_START, src, NULL);
2297
2298   return message;
2299 }