?? hust_time.c
字號:
/* time.c - timeadd, timesub, timeflatten, timeunflatten, timecmp */#include "hust_util.h"#include "hust_rtplibcommon.h"/*----------------------------------------------------------------------- * timeadd - add two struct timespecs *----------------------------------------------------------------------- */struct timespectimeadd(struct timespec a, struct timespec b){ b.tv_sec = -b.tv_sec; b.tv_nsec = -b.tv_nsec; return timesub(a, b);}/*----------------------------------------------------------------------- * timesub - subtract struct timespec b from a *----------------------------------------------------------------------- */struct timespectimesub(struct timespec a, struct timespec b){ struct timespec c; c.tv_sec = a.tv_sec - b.tv_sec; c.tv_nsec = a.tv_nsec - b.tv_nsec; /* borrow if necessary */ if (c.tv_nsec < 0) { c.tv_nsec += 1000000000; c.tv_sec--; } else if (c.tv_nsec > 1000000000) { c.tv_nsec -= 1000000000; c.tv_sec++; } return c;}/*----------------------------------------------------------------------- * timeflatten - convert a struct timespec to a flat time value *----------------------------------------------------------------------- */mediatime_t timeflatten(struct timespec t, int clkrt){ int rv; double d; rv = t.tv_sec * clkrt; d = (double) t.tv_nsec * .000000001; d *= (double) clkrt; rv += (int) d; return rv;}/*------------------------------------------------------------------------ * timeunflatten - convert a flat time value to a struct timespec *------------------------------------------------------------------------ */struct timespectimeunflatten(mediatime_t t, int clkrt){ struct timespec ts; double d; ts.tv_sec = t / clkrt; d = ((double) (t % clkrt)) / ((double) clkrt); ts.tv_nsec = (int) (d * (double) 1000000000); return ts;}/*------------------------------------------------------------------------ * timecmp - compare two strucxt timespecs. Return -1 if a is after b, * 1 if b is after a, or 0 if equal. Yes, this is backward wrt to * convention. *------------------------------------------------------------------------ */inttimecmp(struct timespec a, struct timespec b){ if (a.tv_sec < b.tv_sec) return 1; if (a.tv_sec > b.tv_sec) return -1; if (a.tv_nsec < b.tv_nsec) return 1; if (a.tv_nsec > b.tv_nsec) return -1; return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -