Merged the timestuff removal, done by simeon

(cherry picked from commit bc5a301d01ac323bafcc434e33f6043678749f14)
This commit is contained in:
Christian Thaeter 2008-03-26 13:18:26 +01:00 committed by Ichthyostega
parent e737b9ef1b
commit 15bab21da8
7 changed files with 1 additions and 442 deletions

View file

@ -24,7 +24,6 @@ liblumi_a_CPPFLAGS = -I$(top_srcdir)/src/
liblumi_a_SOURCES = \
$(liblumi_a_srcdir)/plugin.c \
$(liblumi_a_srcdir)/error.c \
$(liblumi_a_srcdir)/time.c \
$(liblumi_a_srcdir)/framerate.c \
$(liblumi_a_srcdir)/mutex.c \
$(liblumi_a_srcdir)/rwlock.c \
@ -35,7 +34,6 @@ liblumi_a_SOURCES = \
noinst_HEADERS += \
$(liblumi_a_srcdir)/plugin.h \
$(liblumi_a_srcdir)/error.h \
$(liblumi_a_srcdir)/time.h \
$(liblumi_a_srcdir)/framerate.h \
$(liblumi_a_srcdir)/locking.h \
$(liblumi_a_srcdir)/mutex.h \

View file

@ -25,7 +25,6 @@
#include <limits.h>
#include "lib/error.h"
#include "lib/time.h"
/**
* @file Framerate calculations, header.

View file

@ -1,26 +0,0 @@
/*
time.h - Time and frame calculations
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "lib/error.h"
LUMIERA_ERROR_DEFINE(TIME_OVERFLOW, "Time overflow");
LUMIERA_ERROR_DEFINE(TIME_UNDERFLOW, "Time underflow");
LUMIERA_ERROR_DEFINE(TIME_NEGATIVE, "Time negative");

View file

@ -1,279 +0,0 @@
/*
time.h - Time calculations
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LUMIERA_TIME_H
#define LUMIERA_TIME_H
#include <sys/time.h>
#include <time.h>
#include <math.h>
#include "lib/error.h"
/*
* @file Time calculations.
this time functions are small macro like wrapers, they are all inlined for performance reasons
time is passed around as pointers, this pointer must never be NULL.
timehandling is a delicate business, be careful of precision errors accumulating
lumiera_time is starting from zero, never becomes negative.
TODO explain how to use time
*/
/* over or underflow (tried to make a movie which has negative length? or more than some hundreds days?) */
LUMIERA_ERROR_DECLARE(TIME_OVERFLOW);
LUMIERA_ERROR_DECLARE(TIME_UNDERFLOW);
LUMIERA_ERROR_DECLARE(TIME_NEGATIVE);
/*
Note: we measure time starting from zero,
time never becomes negative
(I didnt checked if the time types are signed)
*/
typedef struct timeval lumiera_time;
typedef lumiera_time* LumieraTime;
/**
* normalize time after operations.
* used internally
*/
static inline void
lumiera_time_normalize (LumieraTime time)
{
REQUIRE (time);
if (time->tv_usec >= 1000000)
{
time->tv_sec += (time->tv_usec / 1000000);
time->tv_usec = (time->tv_usec % 1000000);
}
}
/**
* set a time value to zero.
* @param time Time to clear
* @return time as given
*/
static inline LumieraTime
lumiera_time_clear (LumieraTime time)
{
if(time)
{
time->tv_sec = 0;
time->tv_usec = 0;
}
return time;
}
/**
* get current time.
* @param time Time to put current time into.
* @return time as given
*/
static inline LumieraTime
lumiera_time_current (LumieraTime time)
{
if (time)
{
/* gettime should never ever fail in a correct program */
if (gettimeofday (time, NULL))
LUMIERA_DIE;
}
return time;
}
/**
* init from floating point representation.
* @param time The time to be set
* @param fp Time in double
* @return time as given upon success, NULL if double time given was negative or given time didn't point
* anywhere
*/
static inline LumieraTime
lumiera_time_set_double (LumieraTime time, double fp)
{
if (time)
{
if (fp >= 0.0)
{
time->tv_sec = fp;
time->tv_usec = round((fp - time->tv_sec) * 1000000.0);
return time;
}
else
{
time->tv_sec = (time_t)-1;
time->tv_usec = (suseconds_t)-1;
lumiera_error_set(LUMIERA_ERROR_TIME_NEGATIVE);
}
}
return NULL;
}
/**
* initialize with seconds and microseconds.
* @param time Time to set
* @param sec Seconds to set
* @param usec Microseconds to set
* @param Time as given
*/
static inline LumieraTime
lumiera_time_init (LumieraTime time, time_t sec, suseconds_t usec)
{
if (time)
{
time->tv_sec = sec;
time->tv_usec = usec;
lumiera_time_normalize (time);
}
return time;
}
/**
* get the seconds part from a time.
* @param time Time to get seconds from
* @return Seconds elapsed, -1 on error
*/
static inline time_t
lumiera_time_sec (LumieraTime time)
{
if (time)
return time->tv_sec;
else
return (time_t)-1;
}
/**
* get the microseconds part of a time.
* @param time Time to get microseconds from
* @return Microseconds elapsed, -1 on error
*/
static inline suseconds_t
lumiera_time_usec (LumieraTime time)
{
if (time)
return time->tv_usec;
else
return (suseconds_t)-1;
}
/**
* convert to floating point repesentation.
* @param time Time to get floating point representation from
* @return Floating point representation of time. NAN on error.
*/
static inline double
lumiera_time_double_get (LumieraTime time)
{
if (time)
{
double fp;
fp = time->tv_sec;
fp += time->tv_usec / 1000000.0;
return fp;
}
return NAN;
}
/**
* copy time
* @param dest Time-pointer to copy to
* @param src Time-source to copy from
* @return dest as given
*/
static inline LumieraTime
lumiera_time_copy (LumieraTime dest, const LumieraTime src)
{
if (dest && src)
{
dest->tv_sec = src->tv_sec;
dest->tv_usec = src->tv_usec;
}
return dest;
}
/**
* add time.
* @param dest The result of the add
* @param src Time to add to dest
* @return dest as given, or NULL on overflow.
*/
static inline LumieraTime
lumiera_time_add (LumieraTime dest, const LumieraTime src)
{
if (dest && src)
{
time_t t = dest->tv_sec;
dest->tv_sec += src->tv_sec;
dest->tv_usec += src->tv_usec;
lumiera_time_normalize (dest);
if (dest->tv_sec < t)
{
lumiera_error_set (LUMIERA_ERROR_TIME_OVERFLOW);
return NULL;
}
}
return dest;
}
/**
* substact time.
* @param dest The result of subtract
* @param src Time to subtract from dest
* @return dest as given, or NULL on underflow.
*/
static inline LumieraTime
lumiera_time_sub (LumieraTime dest, const LumieraTime src)
{
if (dest && src)
{
time_t t = dest->tv_sec;
dest->tv_sec -= src->tv_sec;
if (dest->tv_usec >= src->tv_usec)
dest->tv_usec -= src->tv_usec;
else
{
--dest->tv_sec;
dest->tv_usec += 1000000 - src->tv_usec;
}
lumiera_time_normalize (dest);
if (dest->tv_sec > t)
{
lumiera_error_set (LUMIERA_ERROR_TIME_UNDERFLOW);
return NULL;
}
}
return dest;
}
#endif

View file

@ -1,129 +0,0 @@
TESTING "Time functions" ./test-time
TEST "time init" init 15 500000 <<END
out: 15 500000
END
TEST "time normalize" init 0 1500000 <<END
out: 1 500000
END
TEST "time to float" todouble 15 500000 <<END
out: 15.5
END
TEST "time to float, NULL gives a NaN" todoublenull <<END
out: nan
END
TEST "float to time" fromdouble 33.6666666661 <<END
out: 33 666667
END
TEST "float to time, round down" fromdouble 0.00000049 <<END
out: 0 0
END
TEST "float to time, round up" fromdouble 0.0000005 <<END
out: 0 1
END
TEST "current time" currenttime <<END
return: 0
END
TEST "add time, normalized" add 1000001 2000002 <<END
out: 3 3
END
TEST "substract time, normalized" sub 3000003 2000002 <<END
out: 1 1
END
PLANNED "overflow"
PLANNED "underflow"
# frame 1 begins at time 0
TEST "time to frame NTSC frame 1 begin" ntscframefromtime 0 0 <<END
out: 1
END
# and ends at 33365
TEST "time to frame NTSC frame 1 end" ntscframefromtime 0 33365 <<END
out: 1
END
# thus 33366 is start of frame 2
TEST "time to frame NTSC frame 2 begin" ntscframefromtime 0 33366 <<END
out: 2
END
# and 66732 is the end of frame 2
TEST "time to frame NTSC frame 2 end" ntscframefromtime 0 66732 <<END
out: 2
END
# this makes 66733 the start of frame 3
TEST "time to frame NTSC frame 3 begin" ntscframefromtime 0 66733 <<END
out: 3
END
# after 1 hour we are at frame 107893
TEST "time to frame NTSC after 1hour" ntscframefromtime 3600 0 <<END
out: 107893
END
# after 200 days we are at frame 517881601
TEST "time to frame NTSC after 200 days" ntscframefromtime 17280000 0 <<END
out: 517882118
END
TEST "frame to time NTSC frame 1" ntscframestart 1 <<END
out: 0 0
END
TEST "frame to time NTSC frame 2" ntscframestart 2 <<END
out: 0 33366
END
TEST "frame->time->frame conversion 2" ntscframecheck 2 <<END
out: frame 2 1
END
TEST "frame->time->frame conversion 3" ntscframecheck 3 <<END
out: frame 3 2
END
TEST "frame->time->frame conversion 4" ntscframecheck 4 <<END
out: frame 4 3
END
TEST "frame->time->frame conversion 5" ntscframecheck 5 <<END
out: frame 5 4
END
TEST "frame->time->frame conversion 6" ntscframecheck 6 <<END
out: frame 6 5
END
TEST "frame->time->frame conversion 7" ntscframecheck 7 <<END
out: frame 7 6
END
TEST "frame->time->frame conversion 8" ntscframecheck 8 <<END
out: frame 8 7
END
TEST "frame->time->frame conversion 9" ntscframecheck 9 <<END
out: frame 9 8
END
TEST "frame->time->frame conversion 100000" ntscframecheck 100000 <<END
out: frame 100000 99999
END
TEST "frame->time->frame conversion 999999" ntscframecheck 999999 <<END
out: frame 999999 999998
END
# how long are N frames on average (beware of precision!)
PLANNED "frame duration"
# how much frames fall in a certain timerange
PLANNED "frames in range"

View file

@ -23,10 +23,6 @@ test_error_SOURCES = $(tests_srcdir)/error/errortest.c
test_error_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/
test_error_LDADD = liblumi.a -lnobugmt -lpthread -ldl
check_PROGRAMS += test-time
test_time_SOURCES = $(tests_srcdir)/time/test-time.c
test_time_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/
test_time_LDADD = liblumi.a -lnobugmt -lpthread -ldl -lm
check_PROGRAMS += test-locking
test_locking_SOURCES = \

View file

@ -23,7 +23,7 @@
//#include <string.h>
#include "lib/llist.h"
#include "lib/framerate.h"
#include "src/lib/error.h"
LUMIERA_ERROR_DEFINE(TEST, "test error");