Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / guicast / bctimer.C
blobc92bfec3a6c945c48e1829bd8bc019abea87fdd4
1 #include "bctimer.h"
2 #include <sys/time.h>
3 #include <sys/types.h>
4 #include <unistd.h>
6 Timer::Timer()
8         update();
11 Timer::~Timer()
15 int Timer::update()
17         gettimeofday(&current_time, 0);
18         return 0;
21 int64_t Timer::get_difference(struct timeval *result)
23         gettimeofday(&new_time, 0);
24         
25         result->tv_usec = new_time.tv_usec - current_time.tv_usec;
26         result->tv_sec = new_time.tv_sec - current_time.tv_sec;
27         if(result->tv_usec < 0) 
28         {
29                 result->tv_usec += 1000000; 
30                 result->tv_sec--; 
31         }
32         
33         return (int64_t)result->tv_sec * 1000 + (int64_t)result->tv_usec / 1000;
36 int64_t Timer::get_difference()
38         gettimeofday(&new_time, 0);
40         new_time.tv_usec -= current_time.tv_usec;
41         new_time.tv_sec -= current_time.tv_sec;
42         if(new_time.tv_usec < 0)
43         {
44                 new_time.tv_usec += 1000000;
45                 new_time.tv_sec--;
46         }
48         return (int64_t)new_time.tv_sec * 1000 + 
49                 (int64_t)new_time.tv_usec / 1000;
52 int64_t Timer::get_scaled_difference(long denominator)
54         get_difference(&new_time);
55         return (int64_t)new_time.tv_sec * denominator + 
56                 (int64_t)((double)new_time.tv_usec / 1000000 * denominator);
59 int Timer::delay(long milliseconds)
61         struct timeval delay_duration;
62         delay_duration.tv_sec = 0;
63         delay_duration.tv_usec = milliseconds * 1000;
64         select(0,  NULL,  NULL, NULL, &delay_duration);
65         return 0;
68 //      Local Variables:
69 //      mode: C++
70 //      c-file-style: "linux"
71 //      End: