1 | /* GStreamer |
---|
2 | * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
---|
3 | * 2000 Wim Taymans <wtay@chello.be> |
---|
4 | * |
---|
5 | * gstclock.h: Header for clock 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 | #ifndef __GST_CLOCK_H__ |
---|
24 | #define __GST_CLOCK_H__ |
---|
25 | |
---|
26 | #include <gst/gstobject.h> |
---|
27 | |
---|
28 | G_BEGIN_DECLS |
---|
29 | |
---|
30 | /* --- standard type macros --- */ |
---|
31 | #define GST_TYPE_CLOCK (gst_clock_get_type ()) |
---|
32 | #define GST_CLOCK(clock) (G_TYPE_CHECK_INSTANCE_CAST ((clock), GST_TYPE_CLOCK, GstClock)) |
---|
33 | #define GST_IS_CLOCK(clock) (G_TYPE_CHECK_INSTANCE_TYPE ((clock), GST_TYPE_CLOCK)) |
---|
34 | #define GST_CLOCK_CLASS(cclass) (G_TYPE_CHECK_CLASS_CAST ((cclass), GST_TYPE_CLOCK, GstClockClass)) |
---|
35 | #define GST_IS_CLOCK_CLASS(cclass) (G_TYPE_CHECK_CLASS_TYPE ((cclass), GST_TYPE_CLOCK)) |
---|
36 | #define GST_CLOCK_GET_CLASS(clock) (G_TYPE_INSTANCE_GET_CLASS ((clock), GST_TYPE_CLOCK, GstClockClass)) |
---|
37 | |
---|
38 | typedef guint64 GstClockTime; |
---|
39 | typedef gint64 GstClockTimeDiff; |
---|
40 | typedef gpointer GstClockID; |
---|
41 | |
---|
42 | #define GST_CLOCK_TIME_NONE ((GstClockTime)-1) |
---|
43 | #define GST_CLOCK_TIME_IS_VALID(time) ((time) != GST_CLOCK_TIME_NONE) |
---|
44 | |
---|
45 | #define GST_SECOND (G_USEC_PER_SEC * G_GINT64_CONSTANT (1000)) |
---|
46 | #define GST_MSECOND (GST_SECOND / G_GINT64_CONSTANT (1000)) |
---|
47 | #define GST_USECOND (GST_SECOND / G_GINT64_CONSTANT (1000000)) |
---|
48 | #define GST_NSECOND (GST_SECOND / G_GINT64_CONSTANT (1000000000)) |
---|
49 | |
---|
50 | #define GST_CLOCK_DIFF(s, e) (GstClockTimeDiff)((s) - (e)) |
---|
51 | #define GST_TIMEVAL_TO_TIME(tv) ((tv).tv_sec * GST_SECOND + (tv).tv_usec * GST_USECOND) |
---|
52 | #define GST_TIME_TO_TIMEVAL(t,tv) \ |
---|
53 | G_STMT_START { \ |
---|
54 | (tv).tv_sec = (t) / GST_SECOND; \ |
---|
55 | (tv).tv_usec = ((t) - (tv).tv_sec * GST_SECOND) / GST_USECOND; \ |
---|
56 | } G_STMT_END |
---|
57 | |
---|
58 | #define GST_CLOCK_ENTRY_TRACE_NAME "GstClockEntry" |
---|
59 | |
---|
60 | typedef struct _GstClockEntry GstClockEntry; |
---|
61 | typedef struct _GstClock GstClock; |
---|
62 | typedef struct _GstClockClass GstClockClass; |
---|
63 | |
---|
64 | /* --- prototype for async callbacks --- */ |
---|
65 | typedef gboolean (*GstClockCallback) (GstClock *clock, GstClockTime time, |
---|
66 | GstClockID id, gpointer user_data); |
---|
67 | |
---|
68 | typedef enum { |
---|
69 | /* --- protected --- */ |
---|
70 | GST_CLOCK_ENTRY_OK, |
---|
71 | GST_CLOCK_ENTRY_EARLY, |
---|
72 | GST_CLOCK_ENTRY_RESTART |
---|
73 | } GstClockEntryStatus; |
---|
74 | |
---|
75 | typedef enum { |
---|
76 | /* --- protected --- */ |
---|
77 | GST_CLOCK_ENTRY_SINGLE, |
---|
78 | GST_CLOCK_ENTRY_PERIODIC |
---|
79 | } GstClockEntryType; |
---|
80 | |
---|
81 | #define GST_CLOCK_ENTRY(entry) ((GstClockEntry *)(entry)) |
---|
82 | #define GST_CLOCK_ENTRY_CLOCK(entry) ((entry)->clock) |
---|
83 | #define GST_CLOCK_ENTRY_TYPE(entry) ((entry)->type) |
---|
84 | #define GST_CLOCK_ENTRY_TIME(entry) ((entry)->time) |
---|
85 | #define GST_CLOCK_ENTRY_INTERVAL(entry) ((entry)->interval) |
---|
86 | #define GST_CLOCK_ENTRY_STATUS(entry) ((entry)->status) |
---|
87 | |
---|
88 | struct _GstClockEntry { |
---|
89 | /* --- protected --- */ |
---|
90 | GstClock *clock; |
---|
91 | GstClockEntryType type; |
---|
92 | GstClockTime time; |
---|
93 | GstClockTime interval; |
---|
94 | GstClockEntryStatus status; |
---|
95 | GstClockCallback func; |
---|
96 | gpointer user_data; |
---|
97 | }; |
---|
98 | |
---|
99 | typedef enum |
---|
100 | { |
---|
101 | GST_CLOCK_STOPPED = 0, |
---|
102 | GST_CLOCK_TIMEOUT = 1, |
---|
103 | GST_CLOCK_EARLY = 2, |
---|
104 | GST_CLOCK_ERROR = 3, |
---|
105 | GST_CLOCK_UNSUPPORTED = 4 |
---|
106 | } GstClockReturn; |
---|
107 | |
---|
108 | typedef enum |
---|
109 | { |
---|
110 | GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC = (1 << 1), |
---|
111 | GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC = (1 << 2), |
---|
112 | GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC = (1 << 3), |
---|
113 | GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC = (1 << 4), |
---|
114 | GST_CLOCK_FLAG_CAN_SET_RESOLUTION = (1 << 5), |
---|
115 | GST_CLOCK_FLAG_CAN_SET_SPEED = (1 << 6) |
---|
116 | } GstClockFlags; |
---|
117 | |
---|
118 | #define GST_CLOCK_FLAGS(clock) (GST_CLOCK(clock)->flags) |
---|
119 | |
---|
120 | struct _GstClock { |
---|
121 | GstObject object; |
---|
122 | |
---|
123 | GstClockFlags flags; |
---|
124 | |
---|
125 | /* --- protected --- */ |
---|
126 | GstClockTime start_time; |
---|
127 | GstClockTime last_time; |
---|
128 | gint64 max_diff; |
---|
129 | |
---|
130 | /* --- private --- */ |
---|
131 | guint64 resolution; |
---|
132 | GList *entries; |
---|
133 | GMutex *active_mutex; |
---|
134 | GCond *active_cond; |
---|
135 | gboolean stats; |
---|
136 | |
---|
137 | GstClockTime last_event; |
---|
138 | GstClockTime max_event_diff; |
---|
139 | |
---|
140 | gpointer _gst_reserved[GST_PADDING]; |
---|
141 | }; |
---|
142 | |
---|
143 | struct _GstClockClass { |
---|
144 | GstObjectClass parent_class; |
---|
145 | |
---|
146 | /* vtable */ |
---|
147 | gdouble (*change_speed) (GstClock *clock, |
---|
148 | gdouble oldspeed, gdouble newspeed); |
---|
149 | gdouble (*get_speed) (GstClock *clock); |
---|
150 | guint64 (*change_resolution) (GstClock *clock, guint64 old_resolution, |
---|
151 | guint64 new_resolution); |
---|
152 | guint64 (*get_resolution) (GstClock *clock); |
---|
153 | |
---|
154 | GstClockTime (*get_internal_time) (GstClock *clock); |
---|
155 | |
---|
156 | /* waiting on an ID */ |
---|
157 | GstClockEntryStatus (*wait) (GstClock *clock, GstClockEntry *entry); |
---|
158 | GstClockEntryStatus (*wait_async) (GstClock *clock, GstClockEntry *entry); |
---|
159 | void (*unschedule) (GstClock *clock, GstClockEntry *entry); |
---|
160 | void (*unlock) (GstClock *clock, GstClockEntry *entry); |
---|
161 | gpointer _gst_reserved[GST_PADDING]; |
---|
162 | }; |
---|
163 | |
---|
164 | GType gst_clock_get_type (void); |
---|
165 | |
---|
166 | gdouble gst_clock_set_speed (GstClock *clock, gdouble speed); |
---|
167 | gdouble gst_clock_get_speed (GstClock *clock); |
---|
168 | |
---|
169 | guint64 gst_clock_set_resolution (GstClock *clock, guint64 resolution); |
---|
170 | guint64 gst_clock_get_resolution (GstClock *clock); |
---|
171 | |
---|
172 | void gst_clock_set_active (GstClock *clock, gboolean active); |
---|
173 | gboolean gst_clock_is_active (GstClock *clock); |
---|
174 | void gst_clock_reset (GstClock *clock); |
---|
175 | gboolean gst_clock_handle_discont (GstClock *clock, guint64 time); |
---|
176 | |
---|
177 | GstClockTime gst_clock_get_time (GstClock *clock); |
---|
178 | GstClockTime gst_clock_get_event_time (GstClock *clock); |
---|
179 | GstClockTime gst_clock_get_event_time_delay (GstClock *clock, GstClockTime delay); |
---|
180 | |
---|
181 | |
---|
182 | GstClockID gst_clock_get_next_id (GstClock *clock); |
---|
183 | |
---|
184 | /* creating IDs that can be used to get notifications */ |
---|
185 | GstClockID gst_clock_new_single_shot_id (GstClock *clock, |
---|
186 | GstClockTime time); |
---|
187 | GstClockID gst_clock_new_periodic_id (GstClock *clock, |
---|
188 | GstClockTime start_time, |
---|
189 | GstClockTime interval); |
---|
190 | |
---|
191 | /* operations on IDs */ |
---|
192 | GstClockTime gst_clock_id_get_time (GstClockID id); |
---|
193 | GstClockReturn gst_clock_id_wait (GstClockID id, |
---|
194 | GstClockTimeDiff *jitter); |
---|
195 | GstClockReturn gst_clock_id_wait_async (GstClockID id, |
---|
196 | GstClockCallback func, |
---|
197 | gpointer user_data); |
---|
198 | void gst_clock_id_unschedule (GstClockID id); |
---|
199 | void gst_clock_id_unlock (GstClockID id); |
---|
200 | void gst_clock_id_free (GstClockID id); |
---|
201 | |
---|
202 | |
---|
203 | G_END_DECLS |
---|
204 | |
---|
205 | #endif /* __GST_CLOCK_H__ */ |
---|