Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not expose internals unneeded by the external API #340

Merged
merged 5 commits into from Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion common/filelist_win32.maf
@@ -1,6 +1,5 @@

PUBLIC HEADERS
win/wintime.h
win/syslog_defs.h
#
# These are included by platform_sys.h header contained in ../srtcore/filelist.maf
Expand Down
36 changes: 23 additions & 13 deletions common/win/wintime.h
Expand Up @@ -9,18 +9,13 @@
extern "C" {
#endif

#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 1
#endif

int clock_gettime(int X, struct timespec *ts);

#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#if !defined(_MSC_VER)
#define SRTCOMPAT_WINTIME_STATIC_INLINE_DECL static inline
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
// NOTE: MVC Does not like static inline for C functions in some versions.
// so just use static for MVC.
#define SRTCOMPAT_WINTIME_STATIC_INLINE_DECL static
#endif


#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
#define _TIMEZONE_DEFINED
Expand All @@ -31,11 +26,26 @@ struct timezone
};
#endif

void timeradd(struct timeval *a, struct timeval *b, struct timeval *result);
int gettimeofday(struct timeval* tp, struct timezone* tz);
void SRTCompat_timeradd(
struct timeval *a, struct timeval *b, struct timeval *result);
SRTCOMPAT_WINTIME_STATIC_INLINE_DECL void timeradd(
struct timeval *a, struct timeval *b, struct timeval *result)
{
SRTCompat_timeradd(a, b, result);
}

int SRTCompat_gettimeofday(
struct timeval* tp, struct timezone* tz);
SRTCOMPAT_WINTIME_STATIC_INLINE_DECL int gettimeofday(
struct timeval* tp, struct timezone* tz)
{
return SRTCompat_gettimeofday(tp, tz);
}

#undef SRTCOMPAT_WINTIME_STATIC_INLINE_DECL

#ifdef __cplusplus
}
#endif

#endif
#endif // INC__WIN_WINTIME
49 changes: 3 additions & 46 deletions common/win_time.cpp
Expand Up @@ -13,52 +13,10 @@ written by
Haivision Systems Inc.
*****************************************************************************/

#include <win/wintime.h>
#include "win/wintime.h"
#include <sys/timeb.h>

#if 0
// Temporarily blocked. Needs to be fixed.
// Currently unused, but may be useful in future.
int clock_gettime(int X, struct timespec *ts)
{
LARGE_INTEGER t;
FILETIME f;
double microseconds;
static LARGE_INTEGER offset;
static double frequencyToMicroseconds;
static int initialized = 0;
static BOOL usePerformanceCounter = 0;

if (!initialized) {
LARGE_INTEGER performanceFrequency;
initialized = 1;
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
if (usePerformanceCounter) {
QueryPerformanceCounter(&offset);
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
} else {
offset = getFILETIMEoffset();
frequencyToMicroseconds = 10.;
}
}
if (usePerformanceCounter) QueryPerformanceCounter(&t);
else {
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
}

t.QuadPart -= offset.QuadPart;
microseconds = (double)t.QuadPart / frequencyToMicroseconds;
t.QuadPart = microseconds;
tv->tv_sec = t.QuadPart / 1000000;
tv->tv_usec = t.QuadPart % 1000000;
return (0);
}
#endif

void timeradd(struct timeval *a, struct timeval *b, struct timeval *result)
void SRTCompat_timeradd(struct timeval *a, struct timeval *b, struct timeval *result)
{
result->tv_sec = a->tv_sec + b->tv_sec;
result->tv_usec = a->tv_usec + b->tv_usec;
Expand All @@ -69,7 +27,7 @@ void timeradd(struct timeval *a, struct timeval *b, struct timeval *result)
}
}

int gettimeofday(struct timeval* tp, struct timezone* tz)
int SRTCompat_gettimeofday(struct timeval* tp, struct timezone* tz)
{
static LARGE_INTEGER tickFrequency, epochOffset;

Expand Down Expand Up @@ -105,4 +63,3 @@ int gettimeofday(struct timeval* tp, struct timezone* tz)
}
return 0;
}

4 changes: 4 additions & 0 deletions srtcore/api.cpp
Expand Up @@ -63,6 +63,10 @@ modified by
#include "threadname.h"
#include "srt.h"

#ifdef WIN32
#include <win/wintime.h>
#endif

using namespace std;

extern logging::LogConfig srt_logger_config;
Expand Down
1 change: 0 additions & 1 deletion srtcore/platform_sys.h
Expand Up @@ -17,7 +17,6 @@
#include <windows.h>
#include <inttypes.h>
#include <stdint.h>
#include "win/wintime.h"
#if defined(_MSC_VER)
#pragma warning(disable:4251)
#endif
Expand Down