FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.35k stars 72 forks source link

Add Windows implementation #124

Closed aelmod closed 1 year ago

aelmod commented 1 year ago

Added Windows implementation for MinGW64 compiler.

For now sound does not work on Windows

On environment all required plugins has installed (wasapisrc or directsoundsrc dlls presents). When I manually set any Windows supported audiosink (using -as argument) the following error appears:

gst_parse_launch error (audio 1):
 no property "sync" in element "wasapisrc0"

When I remove g_string_append (launch, " sync=false"):

gst_parse_launch error (audio 1):
 could not link level0 to wasapisrc0

With autoaudiosink as audiosink other errors (gstream warnings) apeared. I will take a look this issue

fduncanh commented 1 year ago

interesting!

fduncanh commented 1 year ago

for the moment, I will just observe your progress, and maybe make any "tweeks" to the code you need (like uint -> unsigned int)

There is windows code in some variants of RpiPlay like https://github.com/wegank/ludimus

also in the most recent surviving version (2019) of the original dsafa22 code (RPiPlay was based on an earlier version of this) https://github.com/jiangban/AirplayServer

aelmod commented 1 year ago

for the moment, I will just observe your progress, and maybe make any "tweeks" to the code you need (like uint -> unsigned int)

There is windows code in some variants of RpiPlay like https://github.com/wegank/ludimus

also in the most recent surviving version (2019) of the original dsafa22 code (RPiPlay was based on an earlier version of this) https://github.com/jiangban/AirplayServer

I really appreciate these updates and the links. In the ludimus repository, I found the gstreamer initialization string with which the sound worked, albeit in debug mode and with glitches. I will try to find out what the problem is with gstreamer, but we have a long-standing mutual dislike for each other :) So I will take a look on other implemetation like SDL or native Windows rendering if it will not fixed for a long

fduncanh commented 1 year ago

@aelmod

I have created a UxPlay branch "win32" which now has all your work on the code (plus some further tweaks to make it compile cleanly on mingw_64), but doesnt yet have the CMakeLists.txt or the BUILD_WINDOWS.md.

Maybe you can add them as a PR to the win32 branch. I want to credit you for your work on this. Thanks!

aelmod commented 1 year ago

Thanks a lot for your updates! I think I can close this PR?

fduncanh commented 1 year ago

I have added the code fixes to the main branch now.

I am looking at your lib/CMakeLists.txt right now

It would be interesting to know whether your fixes for windows also work on other windows build systems.

Can you explain your choices in raop_rtp_mirror.c


#ifdef __MINGW64__
#include "ws2ipdef.h"

#define TCP_KEEPIDLE SO_KEEPALIVE
#define TCP_KEEPINTVL SO_KEEPALIVE
#define TCP_KEEPCNT SO_KEEPALIVE

#endif

(I replaced "ws2ipdef.h" by , seems to work.)

aelmod commented 1 year ago

(I replaced "ws2ipdef.h" by , seems to work.)

It's ok, this is a better header choice than I did for MinGW. For WinAPI with MSVC better to include ws2ipdef.h

aelmod commented 1 year ago

Can you explain your choices in raop_rtp_mirror.c


#ifdef __MINGW64__
#include "ws2ipdef.h"

#define TCP_KEEPIDLE SO_KEEPALIVE
#define TCP_KEEPINTVL SO_KEEPALIVE
#define TCP_KEEPCNT SO_KEEPALIVE

#endif

TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT already implemented in Windows API (MSVC): https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options But MinGW64 not support these macros so far: https://github.com/msys2/MINGW-packages/issues/6191

After investigating, I realized that it is not correct to replace TCP_KEEPINTVL with SO_KEEPALIVE and TCP_KEEPCNT with SO_KEEPALIVE. MinGW has linkage WinAPI functions without any modification, so these macros can have code which implemented in native (MSVC) code in ws2ipdef.h header. I can create pull request, or you can replace defining of TCP_KEEPCNT by 16 and TCP_KEEPINTVL by 17. This will work for Windows 10, version 1703 and higher

image

aelmod commented 1 year ago

It was also incorrect from my side to hardcode the path to the Bonjour SDK, because it creates environment variable while installing, so in lib/CMakeLists.txt is correct to use that variable:

    if ( MINGW )
      set(DNSSD "$ENV{BONJOUR_SDK_HOME}/Lib/x64/dnssd.lib")
      set(DNSSD_INCLUDE_DIR "$ENV{BONJOUR_SDK_HOME}/Include")
    else()

instead of hardcoded C:/Program...

aelmod commented 1 year ago

I have created PR with these fixes, please take a look: https://github.com/FDH2/UxPlay/pull/125

fduncanh commented 1 year ago

great work! now added to main branch