2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "TimeUtils.h"
22 #include "XBDateTime.h"
23 #include "threads/SystemClock.h"
25 #if defined(TARGET_DARWIN)
26 #include <mach/mach_time.h>
27 #include <CoreVideo/CVHostTime.h>
28 #elif defined(TARGET_WINDOWS)
34 #include "TimeSmoother.h"
36 int64_t CurrentHostCounter(void)
38 #if defined(TARGET_DARWIN)
39 return( (int64_t)CVGetCurrentHostTime() );
40 #elif defined(TARGET_WINDOWS)
41 LARGE_INTEGER PerformanceCount;
42 QueryPerformanceCounter(&PerformanceCount);
43 return( (int64_t)PerformanceCount.QuadPart );
46 clock_gettime(CLOCK_MONOTONIC, &now);
47 return( ((int64_t)now.tv_sec * 1000000000L) + now.tv_nsec );
51 int64_t CurrentHostFrequency(void)
53 #if defined(TARGET_DARWIN)
54 return( (int64_t)CVGetHostClockFrequency() );
55 #elif defined(TARGET_WINDOWS)
56 LARGE_INTEGER Frequency;
57 QueryPerformanceFrequency(&Frequency);
58 return( (int64_t)Frequency.QuadPart );
60 return( (int64_t)1000000000L );
64 CTimeSmoother *CTimeUtils::frameTimer = NULL;
65 unsigned int CTimeUtils::frameTime = 0;
67 void CTimeUtils::UpdateFrameTime(bool flip)
70 frameTimer = new CTimeSmoother();
71 unsigned int currentTime = XbmcThreads::SystemClockMillis();
73 frameTimer->AddTimeStamp(currentTime);
74 frameTime = frameTimer->GetNextFrameTime(currentTime);
77 unsigned int CTimeUtils::GetFrameTime()
82 CDateTime CTimeUtils::GetLocalTime(time_t time)
86 tm *local = localtime(&time); // Conversion to local time
88 * Microsoft implementation of localtime returns NULL if on or before epoch.
89 * http://msdn.microsoft.com/en-us/library/bf12f0hc(VS.80).aspx
94 result = time; // Use the original time as close enough.