Skip to content

Commit 6339523

Browse files
committed
Add MSVC compat file for gettimeofday
Borrowed from https://github.com/microsoft/vcpkg/blob/master/ports/gettimeofday/
1 parent 339239c commit 6339523

8 files changed

Lines changed: 111 additions & 2 deletions

File tree

src/framework/mlt_consumer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
#include <stdio.h>
3232
#include <stdlib.h>
3333
#include <string.h>
34+
35+
#ifdef _MSC_VER
36+
#include <gettimeofday.h>
37+
#else
3438
#include <sys/time.h>
39+
#endif
3540

3641
/** Define this if you want an automatic deinterlace (if necessary) when the
3742
* consumer's producer is not running at normal speed.

src/framework/mlt_log.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
#include "mlt_service.h"
2424

2525
#include <string.h>
26+
2627
#ifndef NDEBUG
28+
#ifdef _MSC_VER
29+
#include <gettimeofday.h>
30+
#else
2731
#include <sys/time.h>
2832
#include <time.h>
2933
#endif
34+
#endif
3035

3136
static int log_level = MLT_LOG_WARNING;
3237

src/modules/sdl2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ target_compile_options(mltsdl2 PRIVATE ${MLT_COMPILE_OPTIONS})
1515
target_include_directories(mltsdl2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
1616
target_link_libraries(mltsdl2 PRIVATE mlt Threads::Threads SDL2::SDL2)
1717
if(MSVC)
18-
target_link_libraries(mltsdl2 PRIVATE PThreads4W::PThreads4W)
18+
target_link_libraries(mltsdl2 PRIVATE PThreads4W::PThreads4W msvccompat)
1919
else()
2020
target_link_libraries(mltsdl2 PRIVATE m)
2121
endif()

src/modules/sdl2/consumer_sdl2.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
#include <stdio.h>
3232
#include <stdlib.h>
3333
#include <string.h>
34+
35+
#ifdef _MSC_VER
36+
#include <gettimeofday.h>
37+
#else
3438
#include <sys/time.h>
39+
#endif
3540

3641
#undef MLT_IMAGE_FORMAT // only yuv422 working currently
3742

src/modules/sdl2/consumer_sdl2_audio.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
#include <stdio.h>
3232
#include <stdlib.h>
3333
#include <string.h>
34+
35+
#ifdef _MSC_VER
36+
#include <gettimeofday.h>
37+
#else
3438
#include <sys/time.h>
39+
#endif
3540

3641
MLT_EXPORT extern pthread_mutex_t mlt_sdl_mutex;
3742

src/msvc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_library(msvccompat STATIC libgen.c)
1+
add_library(msvccompat STATIC libgen.c gettimeofday.c)
22

33
target_include_directories(msvccompat PUBLIC
44
${CMAKE_CURRENT_SOURCE_DIR}

src/msvc/gettimeofday.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copied from vcpkg:
3+
* https://github.com/microsoft/vcpkg/blob/master/ports/gettimeofday/gettimeofday.c
4+
*
5+
* Originally copied from PostgreSQL source:
6+
* http://doxygen.postgresql.org/gettimeofday_8c_source.html
7+
*
8+
*/
9+
10+
/*
11+
* gettimeofday.c
12+
* Win32 gettimeofday() replacement
13+
*
14+
* src/port/gettimeofday.c
15+
*
16+
* Copyright (c) 2003 SRA, Inc.
17+
* Copyright (c) 2003 SKC, Inc.
18+
*
19+
* Permission to use, copy, modify, and distribute this software and
20+
* its documentation for any purpose, without fee, and without a
21+
* written agreement is hereby granted, provided that the above
22+
* copyright notice and this paragraph and the following two
23+
* paragraphs appear in all copies.
24+
*
25+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
26+
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
27+
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
28+
* DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
29+
* OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*
31+
* THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
32+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33+
* A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
34+
* IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
35+
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36+
*/
37+
38+
#ifdef _MSC_VER
39+
40+
#include <winsock2.h>
41+
42+
43+
/* FILETIME of Jan 1 1970 00:00:00. */
44+
static const unsigned __int64 epoch = 116444736000000000Ui64;
45+
46+
/*
47+
* timezone information is stored outside the kernel so tzp isn't used anymore.
48+
*
49+
* Note: this function is not for Win32 high precision timing purpose. See
50+
* elapsed_time().
51+
*/
52+
int
53+
gettimeofday(struct timeval * tp, struct timezone * tzp)
54+
{
55+
FILETIME file_time;
56+
SYSTEMTIME system_time;
57+
ULARGE_INTEGER ularge;
58+
59+
GetSystemTime(&system_time);
60+
SystemTimeToFileTime(&system_time, &file_time);
61+
ularge.LowPart = file_time.dwLowDateTime;
62+
ularge.HighPart = file_time.dwHighDateTime;
63+
64+
tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L);
65+
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
66+
67+
return 0;
68+
}
69+
70+
#endif /* _MSC_VER */

src/msvc/gettimeofday.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copied from vcpkg:
3+
* https://github.com/microsoft/vcpkg/blob/master/ports/gettimeofday/gettimeofday.h
4+
*
5+
*/
6+
7+
#ifndef _MY_GETTIMEOFDAY_H_
8+
#define _MY_GETTIMEOFDAY_H_
9+
10+
#ifdef _MSC_VER
11+
12+
#include <winsock2.h>
13+
#include <time.h>
14+
15+
int gettimeofday(struct timeval * tp, struct timezone * tzp);
16+
17+
#endif /* _MSC_VER */
18+
19+
#endif /* _MY_GETTIMEOFDAY_H_ */

0 commit comments

Comments
 (0)