- Removed unused locking from the cothreads
[platform/upstream/gstreamer.git] / gst / gstclock.h
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
24 #ifndef __GST_CLOCK_H__
25 #define __GST_CLOCK_H__
26
27 #include <gst/gstobject.h>
28
29 G_BEGIN_DECLS
30
31 #define GST_TYPE_CLOCK \
32   (gst_clock_get_type())
33 #define GST_CLOCK(obj) \
34   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CLOCK,GstClock))
35 #define GST_CLOCK_CLASS(klass) \
36   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CLOCK,GstClockClass))
37 #define GST_IS_CLOCK(obj) \
38   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CLOCK))
39 #define GST_IS_CLOCK_CLASS(obj) \
40   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CLOCK))
41         
42 typedef guint64         GstClockTime;
43 typedef gint64          GstClockTimeDiff;
44 typedef gpointer        GstClockID;
45
46 #define GST_CLOCK_TIME_NONE  ((guint64)-1)
47
48 #define GST_SECOND  ((guint64)G_USEC_PER_SEC * 1000LL)
49 #define GST_MSECOND ((guint64)GST_SECOND/1000LL)
50 #define GST_USECOND ((guint64)GST_SECOND/1000000LL)
51 #define GST_NSECOND ((guint64)GST_SECOND/1000000000LL)
52
53 #define GST_CLOCK_DIFF(s, e)            (GstClockTimeDiff)((s)-(e))
54 #define GST_TIMEVAL_TO_TIME(tv)         ((tv).tv_sec * GST_SECOND + (tv).tv_usec * GST_USECOND)
55 #define GST_TIME_TO_TIMEVAL(t,tv)                       \
56 G_STMT_START {                                          \
57   (tv).tv_sec  = (t) / GST_SECOND;                      \
58   (tv).tv_usec = ((t) / GST_USECOND) % GST_MSECOND;     \
59 } G_STMT_END
60
61 typedef struct _GstClock        GstClock;
62 typedef struct _GstClockClass   GstClockClass;
63
64 typedef void (*GstClockCallback) (GstClock *clock, GstClockTime time, GstClockID id, gpointer user_data);
65
66 typedef enum
67 {
68   GST_CLOCK_STOPPED     = 0,
69   GST_CLOCK_TIMEOUT     = 1,
70   GST_CLOCK_EARLY       = 2,
71   GST_CLOCK_ERROR       = 3,
72 } GstClockReturn;
73
74 struct _GstClock {
75   GstObject      object;
76
77   GstClockTime   start_time;
78   GstClockTime   last_time;
79   gboolean       accept_discont;
80   gdouble        speed;
81   gboolean       active;
82   GList         *entries;
83   gboolean       async_supported;
84
85   GMutex        *active_mutex;
86   GCond         *active_cond;
87 };
88
89 struct _GstClockClass {
90   GstObjectClass        parent_class;
91
92   /* vtable */
93   GstClockTime          (*get_internal_time)    (GstClock *clock);
94
95   void                  (*set_resolution)       (GstClock *clock, guint64 resolution);
96   guint64               (*get_resolution)       (GstClock *clock);
97
98   /* signals */
99 };
100
101 GType                   gst_clock_get_type              (void);
102
103 void                    gst_clock_set_speed             (GstClock *clock, gdouble speed);
104 gdouble                 gst_clock_get_speed             (GstClock *clock);
105
106 void                    gst_clock_set_active            (GstClock *clock, gboolean active);
107 gboolean                gst_clock_is_active             (GstClock *clock);
108 void                    gst_clock_reset                 (GstClock *clock);
109 gboolean                gst_clock_handle_discont        (GstClock *clock, guint64 time);
110 gboolean                gst_clock_async_supported       (GstClock *clock);
111
112 GstClockTime            gst_clock_get_time              (GstClock *clock);
113
114 GstClockReturn          gst_clock_wait                  (GstClock *clock, GstClockTime time, GstClockTimeDiff *jitter);
115 GstClockID              gst_clock_wait_async            (GstClock *clock, GstClockTime time, 
116                                                          GstClockCallback func, gpointer user_data);
117 void                    gst_clock_cancel_wait_async     (GstClock *clock, GstClockID id);
118 GstClockID              gst_clock_notify_async          (GstClock *clock, GstClockTime interval, 
119                                                          GstClockCallback func, gpointer user_data);
120 void                    gst_clock_remove_notify_async   (GstClock *clock, GstClockID id);
121 GstClockReturn          gst_clock_wait_id               (GstClock *clock, GstClockID id, GstClockTimeDiff *jitter);
122
123 GstClockID              gst_clock_get_next_id           (GstClock *clock);
124 void                    gst_clock_unlock_id             (GstClock *clock, GstClockID id);
125
126 GstClockTime            gst_clock_id_get_time           (GstClockID id);
127
128 void                    gst_clock_set_resolution        (GstClock *clock, guint64 resolution);
129 guint64                 gst_clock_get_resolution        (GstClock *clock);
130
131 G_END_DECLS
132
133 #endif /* __GST_CLOCK_H__ */