gst_caps_to_string: print NULL caps correctly
[platform/upstream/gstreamer.git] / gst / gstevent.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstevent.h: Header for GstEvent subsystem
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #ifndef __GST_EVENT_H__
25 #define __GST_EVENT_H__
26
27 #include <gst/gsttypes.h>
28 #include <gst/gstdata.h>
29 #include <gst/gstformat.h>
30 #include <gst/gstobject.h>
31
32 G_BEGIN_DECLS
33
34 typedef enum {
35   GST_EVENT_UNKNOWN             = 0,
36   GST_EVENT_EOS                 = 1,
37   GST_EVENT_FLUSH               = 2,
38   GST_EVENT_EMPTY               = 3,
39   GST_EVENT_DISCONTINUOUS       = 4,
40   GST_EVENT_NEW_MEDIA           = 5,
41   GST_EVENT_QOS                 = 6,
42   GST_EVENT_SEEK                = 7,
43   GST_EVENT_SEEK_SEGMENT        = 8,
44   GST_EVENT_SEGMENT_DONE        = 9,
45   GST_EVENT_SIZE                = 10,
46   GST_EVENT_RATE                = 11,
47   GST_EVENT_FILLER              = 12,
48   GST_EVENT_TS_OFFSET           = 13,
49   GST_EVENT_INTERRUPT           = 14
50 } GstEventType;
51
52 extern GType _gst_event_type;
53
54 #define GST_EVENT_TRACE_NAME    "GstEvent"
55
56 #define GST_TYPE_EVENT          (_gst_event_type)
57 #define GST_EVENT(event)        ((GstEvent*)(event))
58 #define GST_IS_EVENT(event)     (GST_DATA_TYPE(event) == GST_TYPE_EVENT)
59
60 #define GST_EVENT_TYPE(event)           (GST_EVENT(event)->type)
61 #define GST_EVENT_TIMESTAMP(event)      (GST_EVENT(event)->timestamp)
62 #define GST_EVENT_SRC(event)            (GST_EVENT(event)->src)
63
64 #define GST_EVENT_IS_INTERRUPT(event) (GST_EVENT_TYPE (event) == GST_EVENT_INTERRUPT)
65
66 #define GST_SEEK_FORMAT_SHIFT   0
67 #define GST_SEEK_METHOD_SHIFT   16
68 #define GST_SEEK_FLAGS_SHIFT    20
69 #define GST_SEEK_FORMAT_MASK    0x0000ffff
70 #define GST_SEEK_METHOD_MASK    0x000f0000
71 #define GST_SEEK_FLAGS_MASK     0xfff00000
72
73 typedef enum {
74   GST_EVENT_FLAG_NONE           = 0,
75
76   /* indicates negative rates are supported */
77   GST_RATE_FLAG_NEGATIVE        = (1 << 1) 
78 } GstEventFlag;
79
80 typedef struct
81 {
82   GstEventType  type;
83   GstEventFlag  flags;
84 } GstEventMask;
85
86 #ifdef G_HAVE_ISO_VARARGS
87 #define GST_EVENT_MASK_FUNCTION(type,functionname, ...)      \
88 static const GstEventMask*                              \
89 functionname (type pad)                                 \
90 {                                                       \
91   static const GstEventMask masks[] = {                 \
92     __VA_ARGS__,                                        \
93     { 0, }                                              \
94   };                                                    \
95   return masks;                                         \
96 }
97 #elif defined(G_HAVE_GNUC_VARARGS)
98 #define GST_EVENT_MASK_FUNCTION(type,functionname, a...)     \
99 static const GstEventMask*                              \
100 functionname (type pad)                                 \
101 {                                                       \
102   static const GstEventMask masks[] = {                 \
103     a,                                                  \
104     { 0, }                                              \
105   };                                                    \
106   return masks;                                         \
107 }
108 #endif
109
110 /* seek events, extends GstEventFlag */
111 typedef enum {
112   /* | with some format */
113   /* | with one of these */
114   GST_SEEK_METHOD_CUR           = (1 << (GST_SEEK_METHOD_SHIFT + 0)),
115   GST_SEEK_METHOD_SET           = (1 << (GST_SEEK_METHOD_SHIFT + 1)),
116   GST_SEEK_METHOD_END           = (1 << (GST_SEEK_METHOD_SHIFT + 2)),
117
118   /* | with optional seek flags */
119   /* seek flags */
120   GST_SEEK_FLAG_FLUSH           = (1 << (GST_SEEK_FLAGS_SHIFT + 0)),
121   GST_SEEK_FLAG_ACCURATE        = (1 << (GST_SEEK_FLAGS_SHIFT + 1)),
122   GST_SEEK_FLAG_KEY_UNIT        = (1 << (GST_SEEK_FLAGS_SHIFT + 2)),
123   GST_SEEK_FLAG_SEGMENT_LOOP    = (1 << (GST_SEEK_FLAGS_SHIFT + 3))
124         
125 } GstSeekType;
126
127 typedef enum {
128   GST_SEEK_CERTAIN,
129   GST_SEEK_FUZZY
130 } GstSeekAccuracy;
131
132 typedef struct
133 {
134   GstFormat     format;
135   gint64        value;
136 } GstFormatValue;
137
138 #define GST_EVENT_SEEK_TYPE(event)              (GST_EVENT(event)->event_data.seek.type)
139 #define GST_EVENT_SEEK_FORMAT(event)            (GST_EVENT_SEEK_TYPE(event) & GST_SEEK_FORMAT_MASK)
140 #define GST_EVENT_SEEK_METHOD(event)            (GST_EVENT_SEEK_TYPE(event) & GST_SEEK_METHOD_MASK)
141 #define GST_EVENT_SEEK_FLAGS(event)             (GST_EVENT_SEEK_TYPE(event) & GST_SEEK_FLAGS_MASK)
142 #define GST_EVENT_SEEK_OFFSET(event)            (GST_EVENT(event)->event_data.seek.offset)
143 #define GST_EVENT_SEEK_ENDOFFSET(event)         (GST_EVENT(event)->event_data.seek.endoffset)
144 #define GST_EVENT_SEEK_ACCURACY(event)          (GST_EVENT(event)->event_data.seek.accuracy)
145
146 #define GST_EVENT_DISCONT_NEW_MEDIA(event)      (GST_EVENT(event)->event_data.discont.new_media)
147 #define GST_EVENT_DISCONT_OFFSET(event,i)       (GST_EVENT(event)->event_data.discont.offsets[i])
148 #define GST_EVENT_DISCONT_OFFSET_LEN(event)     (GST_EVENT(event)->event_data.discont.noffsets)
149
150 #define GST_EVENT_SIZE_FORMAT(event)            (GST_EVENT(event)->event_data.size.format)
151 #define GST_EVENT_SIZE_VALUE(event)             (GST_EVENT(event)->event_data.size.value)
152
153 #define GST_EVENT_RATE_VALUE(event)             (GST_EVENT(event)->event_data.rate.value)
154
155 struct _GstEvent {
156   GstData data;
157
158   GstEventType  type;
159   guint64       timestamp;
160   GstObject     *src;
161
162   union {
163     struct {
164       GstSeekType       type;
165       gint64            offset;
166       gint64            endoffset;
167       GstSeekAccuracy   accuracy;
168     } seek;
169     struct {
170       GstFormatValue    offsets[8];
171       gint              noffsets;
172       gboolean          new_media;
173     } discont;
174     struct {
175       GstFormat         format;
176       gint64            value;
177     } size;
178     struct {
179       gdouble           value;
180     } rate;
181   } event_data;
182 };
183
184 void            _gst_event_initialize           (void);
185         
186 GType           gst_event_get_type              (void);
187 GstEvent*       gst_event_new                   (GstEventType type);
188
189 /* refcounting */
190 #define         gst_event_ref(ev)               GST_EVENT (gst_data_ref (GST_DATA (ev)))
191 #define         gst_event_ref_by_count(ev,c)    GST_EVENT (gst_data_ref_by_count (GST_DATA (ev), c))
192 #define         gst_event_unref(ev)             gst_data_unref (GST_DATA (ev))
193 /* copy buffer */
194 #define         gst_event_copy(ev)              GST_EVENT (gst_data_copy (GST_DATA (ev)))
195
196 gboolean        gst_event_masks_contains        (const GstEventMask *masks, GstEventMask *mask);
197
198 /* seek event */
199 GstEvent*       gst_event_new_seek              (GstSeekType type, gint64 offset);
200
201 GstEvent*       gst_event_new_segment_seek      (GstSeekType type, gint64 start, gint64 stop);
202
203
204 /* size events */
205 GstEvent*       gst_event_new_size              (GstFormat format, gint64 value);
206
207 /* discontinous event */
208 GstEvent*       gst_event_new_discontinuous     (gboolean new_media,
209                                                  GstFormat format1, ...);
210 gboolean        gst_event_discont_get_value     (GstEvent *event, GstFormat format, gint64 *value);
211 gboolean        gst_event_has_new_media         (GstEvent *event);
212
213 #define         gst_event_new_filler()          gst_event_new(GST_EVENT_FILLER)
214
215 /* flush events */
216 #define         gst_event_new_flush()           gst_event_new(GST_EVENT_FLUSH)
217
218 G_END_DECLS
219
220 #endif /* __GST_EVENT_H__ */