diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index ec62584247..53f8979b03 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -31,7 +31,12 @@ #include #include #include + +#ifdef _MSC_VER +#include +#else #include +#endif /** Define this if you want an automatic deinterlace (if necessary) when the * consumer's producer is not running at normal speed. diff --git a/src/framework/mlt_log.c b/src/framework/mlt_log.c index da22b705ee..4eb5569c62 100644 --- a/src/framework/mlt_log.c +++ b/src/framework/mlt_log.c @@ -23,10 +23,15 @@ #include "mlt_service.h" #include + #ifndef NDEBUG +#ifdef _MSC_VER +#include +#else #include #include #endif +#endif static int log_level = MLT_LOG_WARNING; diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index 904c9e0296..0d4417dad6 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -33,7 +33,6 @@ #include // for stat() #include // for stat() #include // for strftime() and gtime() -#include // for stat() /* Forward references. */ diff --git a/src/framework/mlt_slices.c b/src/framework/mlt_slices.c index 3f5b3210fa..d91743ecd2 100644 --- a/src/framework/mlt_slices.c +++ b/src/framework/mlt_slices.c @@ -28,10 +28,14 @@ #include #include #include -#include + #ifdef _WIN32 #include +#else +// For _SC_NPROCESSORS_ONLN +#include #endif + #define MAX_SLICES 32 #define ENV_SLICES "MLT_SLICES_COUNT" diff --git a/src/melt/io.c b/src/melt/io.c index 21c6fbf011..7f6859dde4 100644 --- a/src/melt/io.c +++ b/src/melt/io.c @@ -28,6 +28,7 @@ #include #ifndef _WIN32 #include +#include #else // MinGW defines struct timespec in pthread.h #include @@ -35,8 +36,6 @@ #include #include #endif -#include -#include /* Application header files */ #include "io.h" diff --git a/src/melt/melt.c b/src/melt/melt.c index aa99200544..88b6de1838 100644 --- a/src/melt/melt.c +++ b/src/melt/melt.c @@ -22,12 +22,18 @@ #endif #include #include -#include #include #include #include #include + +#ifdef _MSC_VER +#ifndef STDIN_FILENO +#define STDIN_FILENO _fileno(stdin) +#endif +#else #include +#endif #include diff --git a/src/modules/core/consumer_multi.c b/src/modules/core/consumer_multi.c index 8c327b5325..4b32fc8c92 100644 --- a/src/modules/core/consumer_multi.c +++ b/src/modules/core/consumer_multi.c @@ -22,7 +22,6 @@ #include #include #include -#include // Forward references static int start(mlt_consumer consumer); diff --git a/src/modules/plusgpl/consumer_cbrts.c b/src/modules/plusgpl/consumer_cbrts.c index 03b67a74fb..80d1db0ebc 100644 --- a/src/modules/plusgpl/consumer_cbrts.c +++ b/src/modules/plusgpl/consumer_cbrts.c @@ -51,6 +51,11 @@ #include #include +#ifdef _MSC_VER +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#endif + #define TSP_BYTES (188) #define MAX_PID (8192) #define SCR_HZ (27000000ULL) diff --git a/src/modules/sdl2/CMakeLists.txt b/src/modules/sdl2/CMakeLists.txt index 56299bb633..e46abb04f7 100644 --- a/src/modules/sdl2/CMakeLists.txt +++ b/src/modules/sdl2/CMakeLists.txt @@ -15,7 +15,7 @@ target_compile_options(mltsdl2 PRIVATE ${MLT_COMPILE_OPTIONS}) target_include_directories(mltsdl2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(mltsdl2 PRIVATE mlt Threads::Threads SDL2::SDL2) if(MSVC) - target_link_libraries(mltsdl2 PRIVATE PThreads4W::PThreads4W) + target_link_libraries(mltsdl2 PRIVATE PThreads4W::PThreads4W msvccompat) else() target_link_libraries(mltsdl2 PRIVATE m) endif() diff --git a/src/modules/sdl2/consumer_sdl2.c b/src/modules/sdl2/consumer_sdl2.c index 33668f683e..19e8caabc0 100644 --- a/src/modules/sdl2/consumer_sdl2.c +++ b/src/modules/sdl2/consumer_sdl2.c @@ -31,7 +31,12 @@ #include #include #include + +#ifdef _MSC_VER +#include +#else #include +#endif #undef MLT_IMAGE_FORMAT // only yuv422 working currently diff --git a/src/modules/sdl2/consumer_sdl2_audio.c b/src/modules/sdl2/consumer_sdl2_audio.c index 06592df109..bf8d1664ce 100644 --- a/src/modules/sdl2/consumer_sdl2_audio.c +++ b/src/modules/sdl2/consumer_sdl2_audio.c @@ -31,7 +31,12 @@ #include #include #include + +#ifdef _MSC_VER +#include +#else #include +#endif MLT_EXPORT extern pthread_mutex_t mlt_sdl_mutex; diff --git a/src/msvc/CMakeLists.txt b/src/msvc/CMakeLists.txt index f657cde6fe..69f5ae7d17 100644 --- a/src/msvc/CMakeLists.txt +++ b/src/msvc/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(msvccompat STATIC libgen.c) +add_library(msvccompat STATIC libgen.c gettimeofday.c) target_include_directories(msvccompat PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/msvc/gettimeofday.c b/src/msvc/gettimeofday.c new file mode 100644 index 0000000000..c61ecb90f2 --- /dev/null +++ b/src/msvc/gettimeofday.c @@ -0,0 +1,70 @@ +/* + * Copied from vcpkg: + * https://github.com/microsoft/vcpkg/blob/master/ports/gettimeofday/gettimeofday.c + * + * Originally copied from PostgreSQL source: + * http://doxygen.postgresql.org/gettimeofday_8c_source.html + * + */ + +/* + * gettimeofday.c + * Win32 gettimeofday() replacement + * + * src/port/gettimeofday.c + * + * Copyright (c) 2003 SRA, Inc. + * Copyright (c) 2003 SKC, Inc. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without a + * written agreement is hereby granted, provided that the above + * copyright notice and this paragraph and the following two + * paragraphs appear in all copies. + * + * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING + * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS + * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#ifdef _MSC_VER + +#include + + +/* FILETIME of Jan 1 1970 00:00:00. */ +static const unsigned __int64 epoch = 116444736000000000Ui64; + +/* + * timezone information is stored outside the kernel so tzp isn't used anymore. + * + * Note: this function is not for Win32 high precision timing purpose. See + * elapsed_time(). + */ +int +gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + FILETIME file_time; + SYSTEMTIME system_time; + ULARGE_INTEGER ularge; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + ularge.LowPart = file_time.dwLowDateTime; + ularge.HighPart = file_time.dwHighDateTime; + + tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + + return 0; +} + +#endif /* _MSC_VER */ diff --git a/src/msvc/gettimeofday.h b/src/msvc/gettimeofday.h new file mode 100644 index 0000000000..86cb8220cc --- /dev/null +++ b/src/msvc/gettimeofday.h @@ -0,0 +1,19 @@ +/* + * Copied from vcpkg: + * https://github.com/microsoft/vcpkg/blob/master/ports/gettimeofday/gettimeofday.h + * + */ + +#ifndef _MY_GETTIMEOFDAY_H_ +#define _MY_GETTIMEOFDAY_H_ + +#ifdef _MSC_VER + +#include +#include + +int gettimeofday(struct timeval * tp, struct timezone * tzp); + +#endif /* _MSC_VER */ + +#endif /* _MY_GETTIMEOFDAY_H_ */ diff --git a/src/win32/strptime.c b/src/win32/strptime.c index 15456533cb..e70eb3eb39 100644 --- a/src/win32/strptime.c +++ b/src/win32/strptime.c @@ -51,6 +51,13 @@ __RCSID("$NetBSD: strptime.c,v 1.36 2012/03/13 21:13:48 christos Exp $"); __weak_alias(strptime,_strptime) #endif */ + +#ifdef _MSC_VER +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#endif + + typedef unsigned char u_char; typedef unsigned int uint; typedef unsigned __int64 uint64_t;