bufferlist: fix a comment
[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 #define GST_MESSAGE_SEQNUM(e) ((GstMessage*)e)->abidata.ABI.seqnum
64
65 static void gst_message_finalize (GstMessage * message);
66 static GstMessage *_gst_message_copy (GstMessage * message);
67
68 static GstMiniObjectClass *parent_class = NULL;
69
70 void
71 _gst_message_initialize (void)
72 {
73   GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
74
75   /* the GstMiniObject types need to be class_ref'd once before it can be
76    * done from multiple threads;
77    * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
78   g_type_class_ref (gst_message_get_type ());
79 }
80
81 typedef struct
82 {
83   const gint type;
84   const gchar *name;
85   GQuark quark;
86 } GstMessageQuarks;
87
88 static GstMessageQuarks message_quarks[] = {
89   {GST_MESSAGE_UNKNOWN, "unknown", 0},
90   {GST_MESSAGE_EOS, "eos", 0},
91   {GST_MESSAGE_ERROR, "error", 0},
92   {GST_MESSAGE_WARNING, "warning", 0},
93   {GST_MESSAGE_INFO, "info", 0},
94   {GST_MESSAGE_TAG, "tag", 0},
95   {GST_MESSAGE_BUFFERING, "buffering", 0},
96   {GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
97   {GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
98   {GST_MESSAGE_STEP_DONE, "step-done", 0},
99   {GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
100   {GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
101   {GST_MESSAGE_NEW_CLOCK, "new-clock", 0},
102   {GST_MESSAGE_STRUCTURE_CHANGE, "structure-change", 0},
103   {GST_MESSAGE_STREAM_STATUS, "stream-status", 0},
104   {GST_MESSAGE_APPLICATION, "application", 0},
105   {GST_MESSAGE_ELEMENT, "element", 0},
106   {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
107   {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
108   {GST_MESSAGE_DURATION, "duration", 0},
109   {GST_MESSAGE_LATENCY, "latency", 0},
110   {GST_MESSAGE_ASYNC_START, "async-start", 0},
111   {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
112   {GST_MESSAGE_REQUEST_STATE, "request-state", 0},
113   {0, NULL, 0}
114 };
115
116 /**
117  * gst_message_type_get_name:
118  * @type: the message type
119  *
120  * Get a printable name for the given message type. Do not modify or free.
121  *
122  * Returns: a reference to the static name of the message.
123  */
124 const gchar *
125 gst_message_type_get_name (GstMessageType type)
126 {
127   gint i;
128
129   for (i = 0; message_quarks[i].name; i++) {
130     if (type == message_quarks[i].type)
131       return message_quarks[i].name;
132   }
133   return "unknown";
134 }
135
136 /**
137  * gst_message_type_to_quark:
138  * @type: the message type
139  *
140  * Get the unique quark for the given message type.
141  *
142  * Returns: the quark associated with the message type
143  */
144 GQuark
145 gst_message_type_to_quark (GstMessageType type)
146 {
147   gint i;
148
149   for (i = 0; message_quarks[i].name; i++) {
150     if (type == message_quarks[i].type)
151       return message_quarks[i].quark;
152   }
153   return 0;
154 }
155
156 #define _do_init \
157 { \
158   gint i; \
159   \
160   for (i = 0; message_quarks[i].name; i++) { \
161     message_quarks[i].quark = \
162         g_quark_from_static_string (message_quarks[i].name); \
163   } \
164 }
165
166 G_DEFINE_TYPE_WITH_CODE (GstMessage, gst_message, GST_TYPE_MINI_OBJECT,
167     _do_init);
168
169 static void
170 gst_message_class_init (GstMessageClass * klass)
171 {
172   parent_class = g_type_class_peek_parent (klass);
173
174   klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_message_copy;
175   klass->mini_object_class.finalize =
176       (GstMiniObjectFinalizeFunction) gst_message_finalize;
177 }
178
179 static void
180 gst_message_init (GstMessage * message)
181 {
182   GST_CAT_LOG (GST_CAT_MESSAGE, "new message %p", message);
183   GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
184 }
185
186 static void
187 gst_message_finalize (GstMessage * message)
188 {
189   g_return_if_fail (message != NULL);
190
191   GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p", message);
192
193   if (GST_MESSAGE_SRC (message)) {
194     gst_object_unref (GST_MESSAGE_SRC (message));
195     GST_MESSAGE_SRC (message) = NULL;
196   }
197
198   if (message->lock) {
199     GST_MESSAGE_LOCK (message);
200     GST_MESSAGE_SIGNAL (message);
201     GST_MESSAGE_UNLOCK (message);
202   }
203
204   if (message->structure) {
205     gst_structure_set_parent_refcount (message->structure, NULL);
206     gst_structure_free (message->structure);
207   }
208
209   GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (message));
210 }
211
212 static GstMessage *
213 _gst_message_copy (GstMessage * message)
214 {
215   GstMessage *copy;
216
217   GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p", message);
218
219   copy = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
220
221   /* FIXME, need to copy relevant data from the miniobject. */
222   //memcpy (copy, message, sizeof (GstMessage));
223
224   GST_MESSAGE_GET_LOCK (copy) = GST_MESSAGE_GET_LOCK (message);
225   GST_MESSAGE_COND (copy) = GST_MESSAGE_COND (message);
226   GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
227   GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
228   GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
229
230   if (GST_MESSAGE_SRC (message)) {
231     GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
232   }
233
234   if (message->structure) {
235     copy->structure = gst_structure_copy (message->structure);
236     gst_structure_set_parent_refcount (copy->structure,
237         &copy->mini_object.refcount);
238   }
239
240   return copy;
241 }
242
243 /**
244  * gst_message_new_custom:
245  * @type: The #GstMessageType to distinguish messages
246  * @src: The object originating the message.
247  * @structure: The structure for the message. The message will take ownership of
248  * the structure.
249  *
250  * Create a new custom-typed message. This can be used for anything not
251  * handled by other message-specific functions to pass a message to the
252  * app. The structure field can be NULL.
253  *
254  * Returns: The new message.
255  *
256  * MT safe.
257  */
258 GstMessage *
259 gst_message_new_custom (GstMessageType type, GstObject * src,
260     GstStructure * structure)
261 {
262   GstMessage *message;
263
264   message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
265
266   GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
267       (src ? GST_OBJECT_NAME (src) : "NULL"), message,
268       gst_message_type_get_name (type));
269
270   message->type = type;
271
272   if (src)
273     gst_object_ref (src);
274   message->src = src;
275
276   if (structure) {
277     gst_structure_set_parent_refcount (structure,
278         &message->mini_object.refcount);
279   }
280   message->structure = structure;
281
282   GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
283
284   return message;
285 }
286
287 /**
288  * gst_message_get_seqnum:
289  * @message: A #GstMessage.
290  *
291  * Retrieve the sequence number of a message.
292  *
293  * Messages have ever-incrementing sequence numbers, which may also be set
294  * explicitly via gst_message_set_seqnum(). Sequence numbers are typically used
295  * to indicate that a message corresponds to some other set of messages or
296  * events, for example a SEGMENT_DONE message corresponding to a SEEK event. It
297  * is considered good practice to make this correspondence when possible, though
298  * it is not required.
299  *
300  * Note that events and messages share the same sequence number incrementor;
301  * two events or messages will never not have the same sequence number unless
302  * that correspondence was made explicitly.
303  *
304  * Returns: The message's sequence number.
305  *
306  * Since: 0.10.22
307  *
308  * MT safe.
309  */
310 guint32
311 gst_message_get_seqnum (GstMessage * message)
312 {
313   g_return_val_if_fail (GST_IS_MESSAGE (message), -1);
314
315   return GST_MESSAGE_SEQNUM (message);
316 }
317
318 /**
319  * gst_message_set_seqnum:
320  * @message: A #GstMessage.
321  * @seqnum: A sequence number.
322  *
323  * Set the sequence number of a message.
324  *
325  * This function might be called by the creator of a message to indicate that
326  * the message relates to other messages or events. See gst_message_get_seqnum()
327  * for more information.
328  *
329  * Since: 0.10.22
330  *
331  * MT safe.
332  */
333 void
334 gst_message_set_seqnum (GstMessage * message, guint32 seqnum)
335 {
336   g_return_if_fail (GST_IS_MESSAGE (message));
337
338   GST_MESSAGE_SEQNUM (message) = seqnum;
339 }
340
341 /**
342  * gst_message_new_eos:
343  * @src: The object originating the message.
344  *
345  * Create a new eos message. This message is generated and posted in
346  * the sink elements of a GstBin. The bin will only forward the EOS
347  * message to the application if all sinks have posted an EOS message.
348  *
349  * Returns: The new eos message.
350  *
351  * MT safe.
352  */
353 GstMessage *
354 gst_message_new_eos (GstObject * src)
355 {
356   GstMessage *message;
357
358   message = gst_message_new_custom (GST_MESSAGE_EOS, src, NULL);
359
360   return message;
361 }
362
363 /**
364  * gst_message_new_error:
365  * @src: The object originating the message.
366  * @error: The GError for this message.
367  * @debug: A debugging string.
368  *
369  * Create a new error message. The message will copy @error and
370  * @debug. This message is posted by element when a fatal event
371  * occured. The pipeline will probably (partially) stop. The application
372  * receiving this message should stop the pipeline.
373  *
374  * Returns: The new error message.
375  *
376  * MT safe.
377  */
378 GstMessage *
379 gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
380 {
381   GstMessage *message;
382   GstStructure *structure;
383
384   structure = gst_structure_empty_new ("GstMessageError");
385   gst_structure_id_set (structure,
386       GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
387       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
388   message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
389
390   return message;
391 }
392
393 /**
394  * gst_message_new_warning:
395  * @src: The object originating the message.
396  * @error: The GError for this message.
397  * @debug: A debugging string.
398  *
399  * Create a new warning message. The message will make copies of @error and
400  * @debug.
401  *
402  * Returns: The new warning message.
403  *
404  * MT safe.
405  */
406 GstMessage *
407 gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
408 {
409   GstMessage *message;
410   GstStructure *structure;
411
412   structure = gst_structure_empty_new ("GstMessageWarning");
413   gst_structure_id_set (structure,
414       GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
415       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
416   message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
417
418   return message;
419 }
420
421 /**
422  * gst_message_new_info:
423  * @src: The object originating the message.
424  * @error: The GError for this message.
425  * @debug: A debugging string.
426  *
427  * Create a new info message. The message will make copies of @error and
428  * @debug.
429  *
430  * Returns: The new info message.
431  *
432  * Since: 0.10.12
433  *
434  * MT safe.
435  */
436 GstMessage *
437 gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
438 {
439   GstMessage *message;
440   GstStructure *structure;
441
442   structure = gst_structure_empty_new ("GstMessageInfo");
443   gst_structure_id_set (structure, GST_QUARK (GERROR), GST_TYPE_G_ERROR,
444       error, GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
445   message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
446
447   return message;
448 }
449
450 /**
451  * gst_message_new_tag:
452  * @src: The object originating the message.
453  * @tag_list: The tag list for the message.
454  *
455  * Create a new tag message. The message will take ownership of the tag list.
456  * The message is posted by elements that discovered a new taglist.
457  *
458  * Returns: The new tag message.
459  *
460  * MT safe.
461  */
462 GstMessage *
463 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
464 {
465   GstMessage *message;
466
467   g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
468
469   message =
470       gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
471
472   return message;
473 }
474
475 /**
476  * gst_message_new_buffering:
477  * @src: The object originating the message.
478  * @percent: The buffering percent
479  *
480  * Create a new buffering message. This message can be posted by an element that
481  * needs to buffer data before it can continue processing. @percent should be a
482  * value between 0 and 100. A value of 100 means that the buffering completed.
483  *
484  * When @percent is < 100 the application should PAUSE a PLAYING pipeline. When
485  * @percent is 100, the application can set the pipeline (back) to PLAYING.
486  * The application must be prepared to receive BUFFERING messages in the
487  * PREROLLING state and may only set the pipeline to PLAYING after receiving a
488  * message with @percent set to 100, which can happen after the pipeline
489  * completed prerolling. 
490  *
491  * Returns: The new buffering message.
492  *
493  * Since: 0.10.11
494  *
495  * MT safe.
496  */
497 GstMessage *
498 gst_message_new_buffering (GstObject * src, gint percent)
499 {
500   GstMessage *message;
501   GstStructure *structure;
502
503   g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
504
505   structure = gst_structure_empty_new ("GstMessageBuffering");
506   gst_structure_id_set (structure,
507       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
508       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
509       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
510       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
511       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
512       GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
513   message = gst_message_new_custom (GST_MESSAGE_BUFFERING, src, structure);
514
515   return message;
516 }
517
518 /**
519  * gst_message_new_state_changed:
520  * @src: the object originating the message
521  * @oldstate: the previous state
522  * @newstate: the new (current) state
523  * @pending: the pending (target) state
524  *
525  * Create a state change message. This message is posted whenever an element
526  * changed its state.
527  *
528  * Returns: The new state change message.
529  *
530  * MT safe.
531  */
532 GstMessage *
533 gst_message_new_state_changed (GstObject * src,
534     GstState oldstate, GstState newstate, GstState pending)
535 {
536   GstMessage *message;
537   GstStructure *structure;
538
539   structure = gst_structure_empty_new ("GstMessageState");
540   gst_structure_id_set (structure,
541       GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
542       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
543       GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
544   message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src, structure);
545
546   return message;
547 }
548
549 /**
550  * gst_message_new_state_dirty:
551  * @src: the object originating the message
552  *
553  * Create a state dirty message. This message is posted whenever an element
554  * changed its state asynchronously and is used internally to update the
555  * states of container objects.
556  *
557  * Returns: The new state dirty message.
558  *
559  * MT safe.
560  */
561 GstMessage *
562 gst_message_new_state_dirty (GstObject * src)
563 {
564   GstMessage *message;
565
566   message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
567
568   return message;
569 }
570
571 /**
572  * gst_message_new_clock_provide:
573  * @src: The object originating the message.
574  * @clock: The clock it provides
575  * @ready: TRUE if the sender can provide a clock
576  *
577  * Create a clock provide message. This message is posted whenever an
578  * element is ready to provide a clock or lost its ability to provide
579  * a clock (maybe because it paused or became EOS).
580  *
581  * This message is mainly used internally to manage the clock
582  * selection.
583  *
584  * Returns: The new provide clock message.
585  *
586  * MT safe.
587  */
588 GstMessage *
589 gst_message_new_clock_provide (GstObject * src, GstClock * clock,
590     gboolean ready)
591 {
592   GstMessage *message;
593   GstStructure *structure;
594
595   structure = gst_structure_empty_new ("GstMessageClockProvide");
596   gst_structure_id_set (structure,
597       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
598       GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
599   message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
600
601   return message;
602 }
603
604 /**
605  * gst_message_new_clock_lost:
606  * @src: The object originating the message.
607  * @clock: the clock that was lost
608  *
609  * Create a clock lost message. This message is posted whenever the
610  * clock is not valid anymore.
611  *
612  * If this message is posted by the pipeline, the pipeline will
613  * select a new clock again when it goes to PLAYING. It might therefore
614  * be needed to set the pipeline to PAUSED and PLAYING again.
615  *
616  * Returns: The new clock lost message.
617  *
618  * MT safe.
619  */
620 GstMessage *
621 gst_message_new_clock_lost (GstObject * src, GstClock * clock)
622 {
623   GstMessage *message;
624   GstStructure *structure;
625
626   structure = gst_structure_empty_new ("GstMessageClockLost");
627   gst_structure_id_set (structure,
628       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
629   message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
630
631   return message;
632 }
633
634 /**
635  * gst_message_new_new_clock:
636  * @src: The object originating the message.
637  * @clock: the new selected clock
638  *
639  * Create a new clock message. This message is posted whenever the
640  * pipeline selectes a new clock for the pipeline.
641  *
642  * Returns: The new new clock message.
643  *
644  * MT safe.
645  */
646 GstMessage *
647 gst_message_new_new_clock (GstObject * src, GstClock * clock)
648 {
649   GstMessage *message;
650   GstStructure *structure;
651
652   structure = gst_structure_empty_new ("GstMessageNewClock");
653   gst_structure_id_set (structure,
654       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
655   message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
656
657   return message;
658 }
659
660 /**
661  * gst_message_new_structure_change:
662  * @src: The object originating the message.
663  * @type: The change type.
664  * @owner: The owner element of @src.
665  * @busy: Whether the structure change is busy.
666  *
667  * Create a new structure change message. This message is posted when the
668  * structure of a pipeline is in the process of being changed, for example
669  * when pads are linked or unlinked.
670  *
671  * @src should be the srcpad that unlinked or linked.
672  *
673  * Returns: The new structure change message.
674  *
675  * MT safe.
676  *
677  * Since: 0.10.22.
678  */
679 GstMessage *
680 gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
681     GstElement * owner, gboolean busy)
682 {
683   GstMessage *message;
684   GstStructure *structure;
685
686   g_return_val_if_fail (GST_IS_PAD (src), NULL);
687   g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SRC, NULL);
688   g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
689
690   structure = gst_structure_empty_new ("GstMessageStructureChange");
691   gst_structure_id_set (structure,
692       GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
693       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
694       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
695
696   message = gst_message_new_custom (GST_MESSAGE_STRUCTURE_CHANGE, src,
697       structure);
698
699   return message;
700 }
701
702 /**
703  * gst_message_new_segment_start:
704  * @src: The object originating the message.
705  * @format: The format of the position being played
706  * @position: The position of the segment being played
707  *
708  * Create a new segment message. This message is posted by elements that
709  * start playback of a segment as a result of a segment seek. This message
710  * is not received by the application but is used for maintenance reasons in
711  * container elements.
712  *
713  * Returns: The new segment start message.
714  *
715  * MT safe.
716  */
717 GstMessage *
718 gst_message_new_segment_start (GstObject * src, GstFormat format,
719     gint64 position)
720 {
721   GstMessage *message;
722   GstStructure *structure;
723
724   structure = gst_structure_empty_new ("GstMessageSegmentStart");
725   gst_structure_id_set (structure,
726       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
727       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
728   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
729
730   return message;
731 }
732
733 /**
734  * gst_message_new_segment_done:
735  * @src: The object originating the message.
736  * @format: The format of the position being done
737  * @position: The position of the segment being done
738  *
739  * Create a new segment done message. This message is posted by elements that
740  * finish playback of a segment as a result of a segment seek. This message
741  * is received by the application after all elements that posted a segment_start
742  * have posted the segment_done.
743  *
744  * Returns: The new segment done message.
745  *
746  * MT safe.
747  */
748 GstMessage *
749 gst_message_new_segment_done (GstObject * src, GstFormat format,
750     gint64 position)
751 {
752   GstMessage *message;
753   GstStructure *structure;
754
755   structure = gst_structure_empty_new ("GstMessageSegmentDone");
756   gst_structure_id_set (structure,
757       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
758       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
759   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
760
761   return message;
762 }
763
764 /**
765  * gst_message_new_application:
766  * @src: The object originating the message.
767  * @structure: The structure for the message. The message will take ownership of
768  * the structure.
769  *
770  * Create a new application-typed message. GStreamer will never create these
771  * messages; they are a gift from us to you. Enjoy.
772  *
773  * Returns: The new application message.
774  *
775  * MT safe.
776  */
777 GstMessage *
778 gst_message_new_application (GstObject * src, GstStructure * structure)
779 {
780   return gst_message_new_custom (GST_MESSAGE_APPLICATION, src, structure);
781 }
782
783 /**
784  * gst_message_new_element:
785  * @src: The object originating the message.
786  * @structure: The structure for the message. The message will take ownership of
787  * the structure.
788  *
789  * Create a new element-specific message. This is meant as a generic way of
790  * allowing one-way communication from an element to an application, for example
791  * "the firewire cable was unplugged". The format of the message should be
792  * documented in the element's documentation. The structure field can be NULL.
793  *
794  * Returns: The new element message.
795  *
796  * MT safe.
797  */
798 GstMessage *
799 gst_message_new_element (GstObject * src, GstStructure * structure)
800 {
801   return gst_message_new_custom (GST_MESSAGE_ELEMENT, src, structure);
802 }
803
804 /**
805  * gst_message_new_duration:
806  * @src: The object originating the message.
807  * @format: The format of the duration
808  * @duration: The new duration 
809  *
810  * Create a new duration message. This message is posted by elements that
811  * know the duration of a stream in a specific format. This message
812  * is received by bins and is used to calculate the total duration of a
813  * pipeline. Elements may post a duration message with a duration of
814  * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the 
815  * cached duration should be discarded. The new duration can then be 
816  * retrieved via a query.
817  *
818  * Returns: The new duration message.
819  *
820  * MT safe.
821  */
822 GstMessage *
823 gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
824 {
825   GstMessage *message;
826   GstStructure *structure;
827
828   structure = gst_structure_empty_new ("GstMessageDuration");
829   gst_structure_id_set (structure,
830       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
831       GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
832   message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
833
834   return message;
835 }
836
837 /**
838  * gst_message_new_async_start:
839  * @src: The object originating the message.
840  * @new_base_time: if a new base_time should be set on the element
841  *
842  * This message is posted by elements when they start an ASYNC state change. 
843  * @new_base_time is set to TRUE when the element lost its state when it was
844  * PLAYING.
845  *
846  * Returns: The new async_start message. 
847  *
848  * MT safe.
849  *
850  * Since: 0.10.13
851  */
852 GstMessage *
853 gst_message_new_async_start (GstObject * src, gboolean new_base_time)
854 {
855   GstMessage *message;
856   GstStructure *structure;
857
858   structure = gst_structure_empty_new ("GstMessageAsyncStart");
859   gst_structure_id_set (structure,
860       GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
861   message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
862
863   return message;
864 }
865
866 /**
867  * gst_message_new_async_done:
868  * @src: The object originating the message.
869  *
870  * The message is posted when elements completed an ASYNC state change.
871  *
872  * Returns: The new async_done message.
873  *
874  * MT safe.
875  *
876  * Since: 0.10.13
877  */
878 GstMessage *
879 gst_message_new_async_done (GstObject * src)
880 {
881   GstMessage *message;
882
883   message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
884
885   return message;
886 }
887
888 /**
889  * gst_message_new_latency:
890  * @src: The object originating the message.
891  *
892  * This message can be posted by elements when their latency requirements have
893  * changed.
894  *
895  * Returns: The new latency message. 
896  *
897  * MT safe.
898  *
899  * Since: 0.10.12
900  */
901 GstMessage *
902 gst_message_new_latency (GstObject * src)
903 {
904   GstMessage *message;
905
906   message = gst_message_new_custom (GST_MESSAGE_LATENCY, src, NULL);
907
908   return message;
909 }
910
911 /**
912  * gst_message_new_request_state:
913  * @src: The object originating the message.
914  * @state: The new requested state
915  *
916  * This message can be posted by elements when they want to have their state
917  * changed. A typical use case would be an audio server that wants to pause the
918  * pipeline because a higher priority stream is being played.
919  *
920  * Returns: The new requst state message. 
921  *
922  * MT safe.
923  *
924  * Since: 0.10.23
925  */
926 GstMessage *
927 gst_message_new_request_state (GstObject * src, GstState state)
928 {
929   GstMessage *message;
930   GstStructure *structure;
931
932   structure = gst_structure_empty_new ("GstMessageRequestState");
933   gst_structure_id_set (structure,
934       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
935   message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
936
937   return message;
938 }
939
940 /**
941  * gst_message_get_structure:
942  * @message: The #GstMessage.
943  *
944  * Access the structure of the message.
945  *
946  * Returns: The structure of the message. The structure is still
947  * owned by the message, which means that you should not free it and
948  * that the pointer becomes invalid when you free the message.
949  *
950  * MT safe.
951  */
952 const GstStructure *
953 gst_message_get_structure (GstMessage * message)
954 {
955   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
956
957   return message->structure;
958 }
959
960 /**
961  * gst_message_parse_tag:
962  * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
963  * @tag_list: Return location for the tag-list.
964  *
965  * Extracts the tag list from the GstMessage. The tag list returned in the
966  * output argument is a copy; the caller must free it when done.
967  *
968  * MT safe.
969  */
970 void
971 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
972 {
973   g_return_if_fail (GST_IS_MESSAGE (message));
974   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
975   g_return_if_fail (tag_list != NULL);
976
977   *tag_list = (GstTagList *) gst_structure_copy (message->structure);
978 }
979
980 /**
981  * gst_message_parse_buffering:
982  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
983  * @percent: Return location for the percent.
984  *
985  * Extracts the buffering percent from the GstMessage. see also
986  * gst_message_new_buffering().
987  *
988  * Since: 0.10.11
989  *
990  * MT safe.
991  */
992 void
993 gst_message_parse_buffering (GstMessage * message, gint * percent)
994 {
995   g_return_if_fail (GST_IS_MESSAGE (message));
996   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
997
998   if (percent)
999     *percent = g_value_get_int (gst_structure_id_get_value (message->structure,
1000             GST_QUARK (BUFFER_PERCENT)));
1001 }
1002
1003 /**
1004  * gst_message_set_buffering_stats:
1005  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1006  * @mode: a buffering mode 
1007  * @avg_in: the average input rate
1008  * @avg_out: the average output rate
1009  * @buffering_left: amount of buffering time left in milliseconds
1010  *
1011  * Configures the buffering stats values in @message.
1012  *
1013  * Since: 0.10.20
1014  */
1015 void
1016 gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
1017     gint avg_in, gint avg_out, gint64 buffering_left)
1018 {
1019   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1020
1021   gst_structure_id_set (message->structure,
1022       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1023       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1024       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1025       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1026 }
1027
1028 /**
1029  * gst_message_parse_buffering_stats:
1030  * @message: A valid #GstMessage of type GST_MESSAGE_BUFFERING.
1031  * @mode: a buffering mode 
1032  * @avg_in: the average input rate
1033  * @avg_out: the average output rate
1034  * @buffering_left: amount of buffering time left in milliseconds.
1035  *
1036  * Extracts the buffering stats values from @message.
1037  *
1038  * Since: 0.10.20
1039  */
1040 void
1041 gst_message_parse_buffering_stats (GstMessage * message,
1042     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1043     gint64 * buffering_left)
1044 {
1045   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
1046
1047   if (mode)
1048     *mode = g_value_get_enum (gst_structure_id_get_value (message->structure,
1049             GST_QUARK (BUFFERING_MODE)));
1050   if (avg_in)
1051     *avg_in = g_value_get_int (gst_structure_id_get_value (message->structure,
1052             GST_QUARK (AVG_IN_RATE)));
1053   if (avg_out)
1054     *avg_out = g_value_get_int (gst_structure_id_get_value (message->structure,
1055             GST_QUARK (AVG_OUT_RATE)));
1056   if (buffering_left)
1057     *buffering_left =
1058         g_value_get_int64 (gst_structure_id_get_value (message->structure,
1059             GST_QUARK (BUFFERING_LEFT)));
1060 }
1061
1062 /**
1063  * gst_message_parse_state_changed:
1064  * @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
1065  * @oldstate: the previous state, or NULL
1066  * @newstate: the new (current) state, or NULL
1067  * @pending: the pending (target) state, or NULL
1068  *
1069  * Extracts the old and new states from the GstMessage.
1070  *
1071  * MT safe.
1072  */
1073 void
1074 gst_message_parse_state_changed (GstMessage * message,
1075     GstState * oldstate, GstState * newstate, GstState * pending)
1076 {
1077   g_return_if_fail (GST_IS_MESSAGE (message));
1078   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
1079
1080   if (oldstate)
1081     *oldstate =
1082         g_value_get_enum (gst_structure_id_get_value (message->structure,
1083             GST_QUARK (OLD_STATE)));
1084   if (newstate)
1085     *newstate =
1086         g_value_get_enum (gst_structure_id_get_value (message->structure,
1087             GST_QUARK (NEW_STATE)));
1088   if (pending)
1089     *pending = g_value_get_enum (gst_structure_id_get_value (message->structure,
1090             GST_QUARK (PENDING_STATE)));
1091 }
1092
1093 /**
1094  * gst_message_parse_clock_provide:
1095  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_PROVIDE.
1096  * @clock: A pointer to  hold a clock object.
1097  * @ready: A pointer to hold the ready flag.
1098  *
1099  * Extracts the clock and ready flag from the GstMessage.
1100  * The clock object returned remains valid until the message is freed.
1101  *
1102  * MT safe.
1103  */
1104 void
1105 gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
1106     gboolean * ready)
1107 {
1108   const GValue *clock_gvalue;
1109
1110   g_return_if_fail (GST_IS_MESSAGE (message));
1111   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
1112
1113   clock_gvalue =
1114       gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1115   g_return_if_fail (clock_gvalue != NULL);
1116   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1117
1118   if (ready)
1119     *ready =
1120         g_value_get_boolean (gst_structure_id_get_value (message->structure,
1121             GST_QUARK (READY)));
1122   if (clock)
1123     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1124 }
1125
1126 /**
1127  * gst_message_parse_clock_lost:
1128  * @message: A valid #GstMessage of type GST_MESSAGE_CLOCK_LOST.
1129  * @clock: A pointer to hold the lost clock
1130  *
1131  * Extracts the lost clock from the GstMessage.
1132  * The clock object returned remains valid until the message is freed.
1133  *
1134  * MT safe.
1135  */
1136 void
1137 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
1138 {
1139   const GValue *clock_gvalue;
1140
1141   g_return_if_fail (GST_IS_MESSAGE (message));
1142   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
1143
1144   clock_gvalue =
1145       gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1146   g_return_if_fail (clock_gvalue != NULL);
1147   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1148
1149   if (clock)
1150     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1151 }
1152
1153 /**
1154  * gst_message_parse_new_clock:
1155  * @message: A valid #GstMessage of type GST_MESSAGE_NEW_CLOCK.
1156  * @clock: A pointer to hold the selected new clock
1157  *
1158  * Extracts the new clock from the GstMessage.
1159  * The clock object returned remains valid until the message is freed.
1160  *
1161  * MT safe.
1162  */
1163 void
1164 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
1165 {
1166   const GValue *clock_gvalue;
1167
1168   g_return_if_fail (GST_IS_MESSAGE (message));
1169   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
1170
1171   clock_gvalue =
1172       gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
1173   g_return_if_fail (clock_gvalue != NULL);
1174   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
1175
1176   if (clock)
1177     *clock = (GstClock *) g_value_get_object (clock_gvalue);
1178 }
1179
1180 /**
1181  * gst_message_parse_structure_change:
1182  * @message: A valid #GstMessage of type GST_MESSAGE_STRUCTURE_CHANGE.
1183  * @type: A pointer to hold the change type
1184  * @owner: The owner element of the message source
1185  * @busy: A pointer to hold whether the change is in progress or has been
1186  * completed
1187  *
1188  * Extracts the change type and completion status from the GstMessage.
1189  *
1190  * MT safe.
1191  *
1192  * Since: 0.10.22
1193  */
1194 void
1195 gst_message_parse_structure_change (GstMessage * message,
1196     GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
1197 {
1198   const GValue *owner_gvalue;
1199
1200   g_return_if_fail (GST_IS_MESSAGE (message));
1201   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
1202
1203   owner_gvalue =
1204       gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1205   g_return_if_fail (owner_gvalue != NULL);
1206   g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
1207
1208   if (type)
1209     *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1210             GST_QUARK (TYPE)));
1211   if (owner)
1212     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1213   if (busy)
1214     *busy =
1215         g_value_get_boolean (gst_structure_id_get_value (message->structure,
1216             GST_QUARK (BUSY)));
1217 }
1218
1219 /**
1220  * gst_message_parse_error:
1221  * @message: A valid #GstMessage of type GST_MESSAGE_ERROR.
1222  * @gerror: Location for the GError
1223  * @debug: Location for the debug message, or NULL
1224  *
1225  * Extracts the GError and debug string from the GstMessage. The values returned
1226  * in the output arguments are copies; the caller must free them when done.
1227  *
1228  * MT safe.
1229  */
1230 void
1231 gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
1232 {
1233   const GValue *error_gvalue;
1234   GError *error_val;
1235
1236   g_return_if_fail (GST_IS_MESSAGE (message));
1237   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
1238
1239   error_gvalue =
1240       gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1241   g_return_if_fail (error_gvalue != NULL);
1242   g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1243
1244   error_val = (GError *) g_value_get_boxed (error_gvalue);
1245   if (error_val)
1246     *gerror = g_error_copy (error_val);
1247   else
1248     *gerror = NULL;
1249
1250   if (debug)
1251     *debug =
1252         g_value_dup_string (gst_structure_id_get_value (message->structure,
1253             GST_QUARK (DEBUG)));
1254 }
1255
1256 /**
1257  * gst_message_parse_warning:
1258  * @message: A valid #GstMessage of type GST_MESSAGE_WARNING.
1259  * @gerror: Location for the GError
1260  * @debug: Location for the debug message, or NULL
1261  *
1262  * Extracts the GError and debug string from the GstMessage. The values returned
1263  * in the output arguments are copies; the caller must free them when done.
1264  *
1265  * MT safe.
1266  */
1267 void
1268 gst_message_parse_warning (GstMessage * message, GError ** gerror,
1269     gchar ** debug)
1270 {
1271   const GValue *error_gvalue;
1272   GError *error_val;
1273
1274   g_return_if_fail (GST_IS_MESSAGE (message));
1275   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
1276
1277   error_gvalue =
1278       gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1279   g_return_if_fail (error_gvalue != NULL);
1280   g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1281
1282   error_val = (GError *) g_value_get_boxed (error_gvalue);
1283   if (error_val)
1284     *gerror = g_error_copy (error_val);
1285   else
1286     *gerror = NULL;
1287
1288   if (debug)
1289     *debug =
1290         g_value_dup_string (gst_structure_id_get_value (message->structure,
1291             GST_QUARK (DEBUG)));
1292 }
1293
1294 /**
1295  * gst_message_parse_info:
1296  * @message: A valid #GstMessage of type GST_MESSAGE_INFO.
1297  * @gerror: Location for the GError
1298  * @debug: Location for the debug message, or NULL
1299  *
1300  * Extracts the GError and debug string from the GstMessage. The values returned
1301  * in the output arguments are copies; the caller must free them when done.
1302  *
1303  * MT safe.
1304  *
1305  * Since: 0.10.12
1306  */
1307 void
1308 gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
1309 {
1310   const GValue *error_gvalue;
1311   GError *error_val;
1312
1313   g_return_if_fail (GST_IS_MESSAGE (message));
1314   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
1315
1316   error_gvalue =
1317       gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
1318   g_return_if_fail (error_gvalue != NULL);
1319   g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
1320
1321   error_val = (GError *) g_value_get_boxed (error_gvalue);
1322   if (error_val)
1323     *gerror = g_error_copy (error_val);
1324   else
1325     *gerror = NULL;
1326
1327   if (debug)
1328     *debug =
1329         g_value_dup_string (gst_structure_id_get_value (message->structure,
1330             GST_QUARK (DEBUG)));
1331 }
1332
1333 /**
1334  * gst_message_parse_segment_start:
1335  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_START.
1336  * @format: Result location for the format, or NULL
1337  * @position: Result location for the position, or NULL
1338  *
1339  * Extracts the position and format from the segment start message.
1340  *
1341  * MT safe.
1342  */
1343 void
1344 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
1345     gint64 * position)
1346 {
1347   g_return_if_fail (GST_IS_MESSAGE (message));
1348   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
1349
1350   if (format)
1351     *format =
1352         g_value_get_enum (gst_structure_id_get_value (message->structure,
1353             GST_QUARK (FORMAT)));
1354   if (position)
1355     *position =
1356         g_value_get_int64 (gst_structure_id_get_value (message->structure,
1357             GST_QUARK (POSITION)));
1358 }
1359
1360 /**
1361  * gst_message_parse_segment_done:
1362  * @message: A valid #GstMessage of type GST_MESSAGE_SEGMENT_DONE.
1363  * @format: Result location for the format, or NULL
1364  * @position: Result location for the position, or NULL
1365  *
1366  * Extracts the position and format from the segment start message.
1367  *
1368  * MT safe.
1369  */
1370 void
1371 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
1372     gint64 * position)
1373 {
1374   g_return_if_fail (GST_IS_MESSAGE (message));
1375   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
1376
1377   if (format)
1378     *format =
1379         g_value_get_enum (gst_structure_id_get_value (message->structure,
1380             GST_QUARK (FORMAT)));
1381   if (position)
1382     *position =
1383         g_value_get_int64 (gst_structure_id_get_value (message->structure,
1384             GST_QUARK (POSITION)));
1385 }
1386
1387 /**
1388  * gst_message_parse_duration:
1389  * @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
1390  * @format: Result location for the format, or NULL
1391  * @duration: Result location for the duration, or NULL
1392  *
1393  * Extracts the duration and format from the duration message. The duration
1394  * might be GST_CLOCK_TIME_NONE, which indicates that the duration has
1395  * changed. Applications should always use a query to retrieve the duration
1396  * of a pipeline.
1397  *
1398  * MT safe.
1399  */
1400 void
1401 gst_message_parse_duration (GstMessage * message, GstFormat * format,
1402     gint64 * duration)
1403 {
1404   g_return_if_fail (GST_IS_MESSAGE (message));
1405   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
1406
1407   if (format)
1408     *format =
1409         g_value_get_enum (gst_structure_id_get_value (message->structure,
1410             GST_QUARK (FORMAT)));
1411   if (duration)
1412     *duration =
1413         g_value_get_int64 (gst_structure_id_get_value (message->structure,
1414             GST_QUARK (DURATION)));
1415 }
1416
1417 /**
1418  * gst_message_parse_async_start:
1419  * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
1420  * @new_base_time: Result location for the new_base_time or NULL
1421  *
1422  * Extract the new_base_time from the async_start message. 
1423  *
1424  * MT safe.
1425  *
1426  * Since: 0.10.13
1427  */
1428 void
1429 gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
1430 {
1431   g_return_if_fail (GST_IS_MESSAGE (message));
1432   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_START);
1433
1434   if (new_base_time)
1435     *new_base_time =
1436         g_value_get_boolean (gst_structure_id_get_value (message->structure,
1437             GST_QUARK (NEW_BASE_TIME)));
1438 }
1439
1440 /**
1441  * gst_message_parse_request_state:
1442  * @message: A valid #GstMessage of type GST_MESSAGE_REQUEST_STATE.
1443  * @state: Result location for the requested state or NULL
1444  *
1445  * Extract the requested state from the request_state message.
1446  *
1447  * MT safe.
1448  *
1449  * Since: 0.10.23
1450  */
1451 void
1452 gst_message_parse_request_state (GstMessage * message, GstState * state)
1453 {
1454   g_return_if_fail (GST_IS_MESSAGE (message));
1455   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
1456
1457   if (state)
1458     *state = g_value_get_enum (gst_structure_id_get_value (message->structure,
1459             GST_QUARK (NEW_STATE)));
1460 }
1461
1462 /**
1463  * gst_message_new_stream_status:
1464  * @src: The object originating the message.
1465  * @type: The stream status type.
1466  * @owner: The owner element of @src.
1467  *
1468  * Create a new stream status message. This message is posted when a streaming
1469  * thread is created/destroyed or when the state changed.
1470  * 
1471  * Returns: The new stream status message.
1472  *
1473  * MT safe.
1474  *
1475  * Since: 0.10.24.
1476  */
1477 GstMessage *
1478 gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
1479     GstElement * owner)
1480 {
1481   GstMessage *message;
1482   GstStructure *structure;
1483
1484   structure = gst_structure_empty_new ("GstMessageStreamStatus");
1485   gst_structure_id_set (structure,
1486       GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
1487       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
1488   message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
1489
1490   return message;
1491 }
1492
1493 /**
1494  * gst_message_parse_stream_status:
1495  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1496  * @type: A pointer to hold the status type
1497  * @owner: The owner element of the message source
1498  *
1499  * Extracts the stream status type and owner the GstMessage. The returned
1500  * owner remains valid for as long as the reference to @message is valid and
1501  * should thus not be unreffed.
1502  *
1503  * Since: 0.10.24.
1504  *
1505  * MT safe.
1506  */
1507 void
1508 gst_message_parse_stream_status (GstMessage * message,
1509     GstStreamStatusType * type, GstElement ** owner)
1510 {
1511   const GValue *owner_gvalue;
1512
1513   g_return_if_fail (GST_IS_MESSAGE (message));
1514   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1515
1516   owner_gvalue =
1517       gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
1518   g_return_if_fail (owner_gvalue != NULL);
1519
1520   if (type)
1521     *type = g_value_get_enum (gst_structure_id_get_value (message->structure,
1522             GST_QUARK (TYPE)));
1523   if (owner)
1524     *owner = (GstElement *) g_value_get_object (owner_gvalue);
1525 }
1526
1527 /**
1528  * gst_message_set_stream_status_object:
1529  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1530  * @object: the object controlling the streaming
1531  *
1532  * Configures the object handling the streaming thread. This is usually a
1533  * GstTask object but other objects might be added in the future.
1534  *
1535  * Since: 0.10.24
1536  */
1537 void
1538 gst_message_set_stream_status_object (GstMessage * message,
1539     const GValue * object)
1540 {
1541   g_return_if_fail (GST_IS_MESSAGE (message));
1542   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
1543
1544   gst_structure_id_set_value (message->structure, GST_QUARK (OBJECT), object);
1545 }
1546
1547 /**
1548  * gst_message_get_stream_status_object:
1549  * @message: A valid #GstMessage of type GST_MESSAGE_STREAM_STATUS.
1550  *
1551  * Extracts the object managing the streaming thread from @message.
1552  *
1553  * Returns: a GValue containing the object that manages the streaming thread.
1554  * This object is usually of type GstTask but other types can be added in the
1555  * future. The object remains valid as long as @message is valid.
1556  *
1557  * Since: 0.10.24
1558  */
1559 const GValue *
1560 gst_message_get_stream_status_object (GstMessage * message)
1561 {
1562   const GValue *result;
1563
1564   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
1565   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
1566       NULL);
1567
1568   result = gst_structure_id_get_value (message->structure, GST_QUARK (OBJECT));
1569
1570   return result;
1571 }