Skip to content

Commit

Permalink
Fixes and build script to cross compile mythtv for Windows (#382)
Browse files Browse the repository at this point in the history
* Fixes and build script to cross compile mythtv using mingw

* Remove unused mythpainter header

The Windows build now supports opengl. The native directx video is no
longer working as the painter has refactored and the ffmpeg apis have
changed.

* Update mythtv/libs/libmythbase/mythcommandlineparser.cpp

Co-authored-by: Mark Spieth <mspieth@users.noreply.github.com>

* Remove unused stdlib header

* Add install prefix for mythplugins

Adding an install prefix to the windows build script for the
mythplugins.

* define O_NONBLOCK

O_NONBLOCK is undefined for the mingw Windows build.

* Add TODO for Windows build

* Update SetPathname for Windows

SetPathname is working under Windows and does not need the conditional
code.

* Custom usleep no longer required for Windows

The Windows build can compile without a custom usleep function.

* c++ defines not required on Windows build

The cplusplus defines are not required for the Windows build.

* Remove inline readdir_r for Windows

The inline readdir_r is causing compile errors and is no longer required
when using mingw.

* Add missing std::cerr for windows build

* Remove whitespace

* Update Wait for Windows build

The wait function now uses chrono instead of an integer.

* Fix MUI_PUBLIC define for Windows buid

Define MUI_API. This fixes the MUI_PUBLIC define in mythuiexp.h

* Fix threading model for Windows build

The threads can be disabled using disable-w32threads

* Add MUI_API define for windows build

Add MUI_API define for the mythplugins in the windows build.

* Fix whitespace

* Add missing std to endl function

* MUI_API define no longer required

The MUI_API define is no longer required for the windows build.
MythDialog has been updated and no longer uses this marking.

Co-authored-by: Mark Spieth <mspieth@users.noreply.github.com>
  • Loading branch information
arobro and mspieth committed Sep 3, 2021
1 parent 757e275 commit 8899ca5
Show file tree
Hide file tree
Showing 31 changed files with 670 additions and 82 deletions.
2 changes: 1 addition & 1 deletion mythtv/external/libmythdvdnav/dvdread/dvd_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static dvd_input_t file_open(const char *target,
}

/* Open the device */
#if !defined(WIN32) && !defined(__OS2__)
#if !defined(__OS2__)
dev->fd = MythFileOpen(target, O_RDONLY);
#else
dev->fd = mythfile_open(target, O_RDONLY | O_BINARY);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/libmyth.pro
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mingw | win32-msvc* {
SOURCES += audio/audiooutputdx.cpp
HEADERS += mediamonitor-windows.h audio/audiooutputwin.h
HEADERS += audio/audiooutputdx.h
LIBS += -lwinmm -lws2_32 -luser32
LIBS += -lwinmm -lws2_32 -luser32 -lsamplerate
}

macx {
Expand Down
61 changes: 19 additions & 42 deletions mythtv/libs/libmythbase/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
# include <sys/wait.h> // For WIFEXITED on Mac OS X
#endif

#ifdef _WIN32
# include <cstdlib> // for rand()
# include <ctime>
# include <sys/time.h>
#ifdef _MSC_VER
#include <cstdlib> // for rand()
#include <ctime>
#include <sys/time.h>
#endif
#if defined(USING_MINGW)
#include <time.h>
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -137,13 +140,17 @@
//used in videodevice only - that code is not windows-compatible anyway
# define minor(X) 0

using uint = unsigned int;
#if defined(__cplusplus)
using uint = unsigned int;
#else
typedef unsigned int uint;
#endif
#endif

#if defined(__cplusplus) && defined(_WIN32)
# include <QtGlobal>

#if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
#if QT_VERSION >= QT_VERSION_CHECK(5,10,0) && !defined(USING_MINGW)
#include <QRandomGenerator>
static inline void srandom(unsigned int /*seed*/) { }
static inline long int random(void)
Expand All @@ -157,11 +164,6 @@
# define setenv(x, y, z) ::SetEnvironmentVariableA(x, y)
# define unsetenv(x) 0

inline unsigned sleep(unsigned int x)
{
Sleep(x * 1000);
return 0;
}

struct statfs {
// long f_type; /* type of filesystem */
Expand Down Expand Up @@ -264,7 +266,7 @@
# define seteuid(x) 0
#endif // _WIN32

#if defined(_WIN32) && !defined(gmtime_r)
#if _MSC_VER && !defined(gmtime_r)
// FFmpeg libs already have a workaround, use it if the headers are included,
// use this otherwise.
static __inline struct tm *gmtime_r(const time_t *timep, struct tm *result)
Expand All @@ -281,7 +283,7 @@ static __inline struct tm *gmtime_r(const time_t *timep, struct tm *result)
}
#endif

#if defined(_WIN32) && !defined(localtime_r)
#if _MSC_VER && !defined(localtime_r)
// FFmpeg libs already have a workaround, use it if the headers are included,
// use this otherwise.
static __inline struct tm *localtime_r(const time_t *timep, struct tm *result)
Expand Down Expand Up @@ -335,35 +337,6 @@ static __inline struct tm *localtime_r(const time_t *timep, struct tm *result)
# define ftello(stream) ftello64(stream)
#endif

#if defined(USING_MINGW) && defined(FILENAME_MAX)
# include <cerrno>
# include <cstddef>
# include <cstring>
# include <dirent.h>
static inline int readdir_r(
DIR *dirp, struct dirent *entry, struct dirent **result)
{
errno = 0;
struct dirent *tmp = readdir(dirp);
if (tmp && entry)
{
int offset = offsetof(struct dirent, d_name);
memcpy(entry, tmp, offset);
strncpy(entry->d_name, tmp->d_name, FILENAME_MAX);
tmp->d_name[strlen(entry->d_name)] = '\0';
if (result)
*result = entry;
return 0;
}
else
{
if (result)
*result = nullptr;
return errno;
}
}
#endif

#ifdef Q_OS_ANDROID
#ifndef S_IREAD
#define S_IREAD S_IRUSR
Expand All @@ -387,4 +360,8 @@ static __inline struct tm *localtime_r(const time_t *timep, struct tm *result)
# define LZO_COMPILE_TIME_ASSERT( a )
#endif

#ifndef O_NONBLOCK
# define O_NONBLOCK 04000
#endif

#endif // COMPAT_H
3 changes: 2 additions & 1 deletion mythtv/libs/libmythbase/libmythbase.pro
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ unix {
mingw | win32-msvc* {
SOURCES += mythsystemwindows.cpp
HEADERS += mythsystemwindows.h
LIBS += -lzip
}

# Install headers to same location as libmyth to make things easier
Expand Down Expand Up @@ -150,7 +151,7 @@ using_libdns_sd {

using_x11:DEFINES += USING_X11

mingw:LIBS += -lws2_32
mingw:LIBS += -lws2_32 -lz

win32-msvc* {

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythcommandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,7 @@ bool setUser(const QString &username)
return true;

#ifdef _WIN32
cerr << "--user option is not supported on Windows" << endl;
std::cerr << "--user option is not supported on Windows" << std::endl;
return false;
#else // ! _WIN32
#if defined(__linux__) || defined(__LINUX__)
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythbase/mythmiscutil.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifdef _WIN32
#include <sys/stat.h>
#endif

#include "mythmiscutil.h"

Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythbase/mythmiscutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <QString>
#include <QDir>

#ifdef _WIN32
#undef mkdir
#endif

#include "mythbaseexp.h"
#include "mythsystem.h"

Expand Down
5 changes: 5 additions & 0 deletions mythtv/libs/libmythbase/mythsystemlegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <fcntl.h>
#include <unistd.h>

#include <signal.h>

// QT headers
#include <QCoreApplication>

Expand Down Expand Up @@ -300,6 +302,9 @@ void MythSystemLegacy::Signal(MythSignal sig)
if (m_status != GENERIC_EXIT_RUNNING)
return;

#ifndef SIGTRAP /* For Mingw */
#define SIGTRAP -1
#endif
int posix_signal = SIGTRAP;
switch (sig)
{
Expand Down
14 changes: 10 additions & 4 deletions mythtv/libs/libmythbase/mythsystemwindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void MythSystemLegacySignalManager::run(void)
LOG(VB_GENERAL, LOG_INFO, "Starting process signal handler");
while( run_system )
{
usleep(50000); // sleep 50ms
usleep(50ms);
while( run_system )
{
// handle cleanup and signalling for closed processes
Expand Down Expand Up @@ -569,7 +569,7 @@ void MythSystemLegacyWindows::Term(bool force)
if( force )
{
// send KILL if it does not exit within one second
if( m_parent->Wait(1) == GENERIC_EXIT_RUNNING )
if( m_parent->Wait(1s) == GENERIC_EXIT_RUNNING )
Signal(SIGKILL);
}
}
Expand Down Expand Up @@ -707,14 +707,20 @@ void MythSystemLegacyWindows::Fork(std::chrono::seconds timeout)
if (dir.length() > 0)
pDir = (LPCWSTR)dir.utf16();

char sCmdChar[256];
sprintf(sCmdChar, "%ls", (LPWSTR)sCmd.utf16() );

char pDirChar[256];
sprintf(pDirChar, "%ls", pDir);

bool success = CreateProcess( nullptr,
(LPWSTR)sCmd.utf16(), // command line
sCmdChar, // command line
nullptr, // process security attributes
nullptr, // primary thread security attributes
bInherit, // handles are inherited
0, // creation flags
nullptr, // use parent's environment
pDir, // use parent's current directory
pDirChar, // use parent's current directory
&si, // STARTUPINFO pointer
&pi); // receives PROCESS_INFORMATION

Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythmetadata/libmythmetadata.pro
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ using_mheg:LIBS += -L../libmythfreemheg -lmythfreemheg-$${LIBVERSION}
using_live:LIBS += -L../libmythlivemedia -lmythlivemedia-$${LIBVERSION}

mingw:LIBS += -lws2_32
mingw:LIBS += libbluray

win32-msvc* {

Expand Down
24 changes: 24 additions & 0 deletions mythtv/libs/libmythtv/captions/xine_demux_sputext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@
#define LINE_LEN 1000
#define LINE_LEN_QUOT "1000"

#ifdef _WIN32
#include <stdlib.h>
#include <ctype.h>

char *strcasestr(const char *str, const char *pattern) {
size_t i;

if (!*pattern)
return (char*)str;

for (; *str; str++) {
if (toupper((unsigned char)*str) == toupper((unsigned char)*pattern)) {
for (i = 1;; i++) {
if (!pattern[i])
return (char*)str;
if (toupper((unsigned char)str[i]) != toupper((unsigned char)pattern[i]))
break;
}
}
}
return NULL;
}
#endif

/*
* Demuxer code start
*/
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ extern "C" {
#include "libavutil/display.h"
}

#ifdef _WIN32
#undef mkdir
#endif

// MythTV headers
#include "mythtvexp.h"
#include "mythconfig.h"
Expand Down
16 changes: 11 additions & 5 deletions mythtv/libs/libmythtv/libmythtv.pro
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ INCLUDEPATH += $$DEPENDPATH
QMAKE_CXXFLAGS += $${FREETYPE_CFLAGS}
}

mingw: LIBS += -liconv

macx {
OBJECTIVE_HEADERS += util-osx.h
OBJECTIVE_SOURCES += util-osx.mm
Expand Down Expand Up @@ -360,6 +362,10 @@ using_frontend {
LIBS += -L../../external/libmythbluray -lmythbluray-$${LIBVERSION}
!win32-msvc*:POST_TARGETDEPS += ../../external/libmythbluray/libmythbluray-$${MYTH_LIB_EXT}
}
using_libbluray_external:mingw {
LIBS += -lbluray
}

using_libbluray_external:android {
LIBS += -lbluray -lxml2
}
Expand Down Expand Up @@ -1116,16 +1122,16 @@ use_hidesyms {

mingw:DEFINES += USING_MINGW

mingw | win32-msvc* {
mingw || win32-msvc* {

HEADERS += videoout_d3d.h
SOURCES += videoout_d3d.cpp
#HEADERS += videoout_d3d.h
#SOURCES += videoout_d3d.cpp

using_dxva2: DEFINES += USING_DXVA2
using_dxva2: HEADERS += dxva2decoder.h
using_dxva2: SOURCES += dxva2decoder.cpp

LIBS += -lws2_32
LIBS += -lws2_32 -lfreetype -lz
}

win32-msvc* {
Expand Down Expand Up @@ -1165,7 +1171,7 @@ using_backend:using_mp3lame: LIBS += -lmp3lame
using_backend: LIBS += -llzo2
LIBS += $$EXTRA_LIBS $$QMAKE_LIBS_DYNLOAD

!win32-msvc* {
!mingw || win32-msvc* {
POST_TARGETDEPS += ../libmyth/libmyth-$${MYTH_SHLIB_EXT}
POST_TARGETDEPS += ../../external/FFmpeg/libswresample/$$avLibName(swresample)
POST_TARGETDEPS += ../../external/FFmpeg/libavutil/$$avLibName(avutil)
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/mythvideooutgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ MythVideoOutputGPU *MythVideoOutputGPU::Create(MythMainWindow* MainWindow, MythR
QStringList renderers;

#ifdef _WIN32
if (render->Type() == kRenderDirect3D9)
renderers += VideoOutputD3D::GetAllowedRenderers(CodecID, VideoDispDim);
// if (render->Type() == kRenderDirect3D9)
// renderers += VideoOutputD3D::GetAllowedRenderers(CodecID, VideoDispDim);
#endif

#ifdef USING_OPENGL
Expand Down Expand Up @@ -132,8 +132,8 @@ MythVideoOutputGPU *MythVideoOutputGPU::Create(MythMainWindow* MainWindow, MythR
MythVideoOutputGPU* video = nullptr;

#ifdef _WIN32
if (renderer == "direct3d")
video = new VideoOutputD3D();
// if (renderer == "direct3d")
// video = new VideoOutputD3D();
#endif
#ifdef USING_OPENGL
if (!video && renderer.contains("opengl") && openglrender)
Expand Down
7 changes: 3 additions & 4 deletions mythtv/libs/libmythui/libmythui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,12 @@ cygwin:DEFINES += _WIN32
mingw :DEFINES += USING_MINGW

mingw | win32-msvc*{
HEADERS += mythpainter_d3d9.h mythrender_d3d9.h
SOURCES += mythpainter_d3d9.cpp mythrender_d3d9.cpp
# HEADERS += mythpainter_d3d9.h mythrender_d3d9.h
# SOURCES += mythpainter_d3d9.cpp mythrender_d3d9.cpp
HEADERS += platforms/mythdisplaywindows.h
SOURCES += platforms/mythdisplaywindows.cpp
DEFINES += NODRAWTEXT
LIBS += -lGdi32 -lUser32

LIBS += -luser32 -lgdi32
using_dxva2: DEFINES += USING_DXVA2
}

Expand Down
3 changes: 0 additions & 3 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
#include "mythscreensaver.h"
#include "devices/mythinputdevicehandler.h"

#ifdef _WIN32
#include "mythpainter_d3d9.h"
#endif

#ifdef Q_OS_ANDROID
#include <QtAndroid>
Expand Down
Loading

0 comments on commit 8899ca5

Please sign in to comment.