[gst-devel] time handling

David I. Lehn dlehn at vt.edu
Thu Apr 18 01:47:02 CEST 2002

There was a brief discussion on IRC about time handling.  Started off by
noting gstbuffer.h in cvs has comment that says time field is in
nanoseconds.  Yet everything (?) uses microseconds right now.

64 bit ints can represent quite a long time in either us or ns.  ds
suggested using ns for people who may want to use the framework for data
acquisition apps.  also suggested using macros or functions to convert
between time values.  maybe we can get some elaboration on that. (hint

Ideally it would be nice to support runtime selection of time units as
appropriate.  Audio/video apps probably don't need ns while some apps
might require ns accuracy.  Changing at runtime will probably be slow,
messy, ugly, or all of the above.  Or maybe just a matter of using
functions and flipping around function pointers to other converters.

How about a compile time option and some typedefs and macros?  Probably
performance issues if you use wrong units and constant folding doesn't
happen.  But at least opens up possibility of higher accuracy

Perhaps need a compiler #warning when conversion that causes loss of
accuracy is used.  And maybe a typedef is too strong and a #define would

#if defined(GST_TIME_US)

typedef guint64 gst_time_t;

#define gst_time_from_us(s) (gst_time_t)(s)
#define gst_time_from_ns(s) (gst_time_t)((s)/1000)
#define gst_time_from_hms(hours,minutes,seconds) (gst_time_t)(...)

#define gst_time_to_us(t) (t)
#define gst_time_to_ns(t) (t*1000)

#elif defined(GST_TIME_NS)

typedef guint64 gst_time_t;
... conversion macros ...

#elif defined(GST_TIME_FANCY)

typedef struct _fancytime fancytime;
struct _fancytime {
	int hours;
	int minutes;
	int seconds;
typedef fancytime gst_time_t;
... conversion macros ...


In any case, maybe start using macros for whatever time unit we choose
now so expansion is possible in the future.  Or perhaps this is all


David I. Lehn <dlehn at vt.edu>  | http://crib.lehn.org:8080/~dlehn/
Computer Engineering Graduate @ Virginia Tech in sunny Blacksburg, VA

More information about the gstreamer-devel mailing list