Skip to content

Commit

Permalink
change addon code to allow windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AlwinEsch committed Jan 26, 2020
1 parent 7b4937b commit 8a87559
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 45 deletions.
70 changes: 45 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ project(inputstream.ffmpegdirect)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})

find_package(PkgConfig)
if(WIN32)
find_package(LibXml2 REQUIRED)
find_package(Iconv REQUIRED)
find_package(OpenSSL REQUIRED)
endif()
find_package(p8-platform REQUIRED)
find_package(Kodi REQUIRED)
find_package(FFMPEG REQUIRED)
Expand All @@ -16,7 +21,6 @@ set(CATCHUP_SOURCES src/StreamManager.cpp
src/stream/FFmpegLog.cpp
src/stream/FFmpegStream.cpp
src/stream/commons/Exception.cpp
src/stream/platform/posix/XTimeUtils.cpp
src/stream/threads/Atomics.cpp
src/stream/threads/Event.cpp
src/stream/threads/Thread.cpp
Expand All @@ -35,8 +39,6 @@ set(CATCHUP_HEADERS src/StreamManager.h
src/stream/FFmpegStream.h
src/stream/IManageDemuxPacket.h
src/stream/commons/Exception.h
src/stream/platform/posix/PlatformDefs.h
src/stream/platform/posix/XTimeUtils.h
src/stream/threads/Atomics.h
src/stream/threads/Condition.h
src/stream/threads/CriticalSection.h
Expand All @@ -55,38 +57,56 @@ set(CATCHUP_HEADERS src/StreamManager.h
src/stream/url/UrlOptions.h
src/stream/url/Variant.h)

if(NOT WIN32)
list(APPEND CATCHUP_SOURCES src/stream/platform/posix/XTimeUtils.cpp)

list(APPEND CATCHUP_HEADERS src/stream/platform/posix/PlatformDefs.h
src/stream/platform/posix/XTimeUtils.h)
endif()

include_directories(${p8-platform_INCLUDE_DIRS}
${INCLUDES}
${FFMPEG_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
${BZIP2_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIRS}
${KODI_INCLUDE_DIR}/..) # Hack way with "/..", need bigger Kodi cmake rework to match right include ways (becomes done in future)

list(APPEND DEPLIBS ${p8-platform_LIBRARIES} ${FFMPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES})
list(APPEND DEPLIBS ${p8-platform_LIBRARIES}
${FFMPEG_LIBRARIES}
${ZLIB_LIBRARIES}
${BZIP2_LIBRARIES})
if(WIN32)
list(APPEND DEPLIBS ${ICONV_LIBRARIES}
${OPENSSL_LIBRARIES}
${LIBXML2_LIBRARIES})
endif()

# to see linker output
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v")

if(CORE_SYSTEM_NAME MATCHES "windows")
list(APPEND DEPLIBS Winmm.lib WS2_32.lib)
list(APPEND DEPLIBS Winmm.lib WS2_32.lib Bcrypt.lib Secur32.lib)
endif()

if(CORE_SYSTEM_NAME MATCHES "osx")
find_library(AUDIOTOOLBOX AudioToolbox)
find_library(COREFOUNDATION CoreFoundation)
find_library(COREMEDIA CoreMedia)
find_library(VIDEOTOOLBOX VideoToolbox)

include_directories(${AVFOUNDATION}
${COCOA}
${COREFOUNDATION}
${COREMEDIA}
${COREVIDEO}
${COREMEDIAIO}
${VIDEOTOOLBOX}
${COCOA})

list(APPEND DEPLIBS ${AUDIOTOOLBOX} ${COREFOUNDATION} ${COREMEDIA} ${VIDEOTOOLBOX})
if(CORE_SYSTEM_NAME STREQUAL osx OR
CORE_SYSTEM_NAME STREQUAL darwin_embedded)
find_library(AUDIOTOOLBOX AudioToolbox)
find_library(COREFOUNDATION CoreFoundation)
find_library(COREMEDIA CoreMedia)
find_library(VIDEOTOOLBOX VideoToolbox)

include_directories(${AVFOUNDATION}
${COCOA}
${COREFOUNDATION}
${COREMEDIA}
${COREVIDEO}
${COREMEDIAIO}
${VIDEOTOOLBOX}
${COCOA})

list(APPEND DEPLIBS ${AUDIOTOOLBOX} ${COREFOUNDATION} ${COREMEDIA} ${VIDEOTOOLBOX})
endif()

addon_version(inputstream.ffmpegdirect CATCHUP)
Expand All @@ -97,10 +117,10 @@ build_addon(inputstream.ffmpegdirect CATCHUP DEPLIBS)
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS "${FFMPEG_LDFLAGS}")

if(CORE_SYSTEM_NAME STREQUAL windowsstore)
# fix linking
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/LTCG /defaultlib:vccorlib.lib /defaultlib:msvcrt.lib")
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS_RELEASE "/LTCG /defaultlib:vccorlib.lib /defaultlib:msvcrt.lib")
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS_DEBUG "/LTCG /defaultlib:vccorlibd.lib /defaultlib:msvcrtd.lib")
# fix linking
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/LTCG /defaultlib:vccorlib.lib /defaultlib:msvcrt.lib")
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS_RELEASE "/LTCG /defaultlib:vccorlib.lib /defaultlib:msvcrt.lib")
set_target_properties(inputstream.ffmpegdirect PROPERTIES LINK_FLAGS_DEBUG "/LTCG /defaultlib:vccorlibd.lib /defaultlib:msvcrtd.lib")
endif()

include(CPack)
45 changes: 45 additions & 0 deletions FindIconv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#.rst:
# FindICONV
# --------
# Finds the ICONV library
#
# This will define the following variables::
#
# ICONV_FOUND - system has ICONV
# ICONV_INCLUDE_DIRS - the ICONV include directory
# ICONV_LIBRARIES - the ICONV libraries
#
# and the following imported targets::
#
# ICONV::ICONV - The ICONV library

find_path(ICONV_INCLUDE_DIR NAMES iconv.h)

find_library(ICONV_LIBRARY NAMES iconv libiconv c)

set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
include(CheckFunctionExists)
check_function_exists(iconv HAVE_ICONV_FUNCTION)
if(NOT HAVE_ICONV_FUNCTION)
check_function_exists(libiconv HAVE_LIBICONV_FUNCTION2)
set(HAVE_ICONV_FUNCTION ${HAVE_LIBICONV_FUNCTION2})
unset(HAVE_LIBICONV_FUNCTION2)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Iconv
REQUIRED_VARS ICONV_LIBRARY ICONV_INCLUDE_DIR HAVE_ICONV_FUNCTION)

if(ICONV_FOUND)
set(ICONV_LIBRARIES ${ICONV_LIBRARY})
set(ICONV_INCLUDE_DIRS ${ICONV_INCLUDE_DIR})

if(NOT TARGET ICONV::ICONV)
add_library(ICONV::ICONV UNKNOWN IMPORTED)
set_target_properties(ICONV::ICONV PROPERTIES
IMPORTED_LOCATION "${ICONV_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${ICONV_INCLUDE_DIR}")
endif()
endif()

mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARY HAVE_ICONV_FUNCTION)
9 changes: 4 additions & 5 deletions src/stream/FFmpegStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

// #include <kodi/addon-instance/Inputstream.h>

#ifdef TARGET_POSIX
#include "platform/posix/XTimeUtils.h"
#endif
#include <chrono>
#include <ctime>

#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
Expand Down Expand Up @@ -1197,7 +1196,7 @@ bool FFmpegStream::SeekTime(double time, bool backwards, double* startpts)
if (pkt)
m_demuxPacketMamnager->FreeDemuxPacketFromInputStreamAPI(pkt);
else
Sleep(10);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
m_pkt.result = -1;
av_packet_unref(&m_pkt.pkt);

Expand Down Expand Up @@ -2046,4 +2045,4 @@ bool FFmpegStream::SeekChapter(int chapter)
AVChapter* ch = m_pFormatContext->chapters[chapter - 1];
double dts = ConvertTimestamp(ch->start, ch->time_base.den, ch->time_base.num);
return SeekTime(DVD_TIME_TO_MSEC(dts), true);
}
}
2 changes: 2 additions & 0 deletions src/stream/platform/posix/PlatformDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <pthread.h>
#include <string.h>
#if defined(TARGET_DARWIN)
Expand Down
8 changes: 3 additions & 5 deletions src/stream/threads/platform/win/ThreadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* See LICENSES/README.md for more information.
*/

#include "utils/log.h"

#include "platform/win32/WIN32Util.h"

#include <kodi/General.h>
#include <process.h>
#include <windows.h>

Expand Down Expand Up @@ -42,7 +39,8 @@ void CThread::SetThreadInfo()
{
}

CWIN32Util::SetThreadLocalLocale(true); // avoid crashing with setlocale(), see https://connect.microsoft.com/VisualStudio/feedback/details/794122
// avoid crashing with setlocale(), see https://connect.microsoft.com/VisualStudio/feedback/details/794122
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
}

std::uintptr_t CThread::GetCurrentThreadNativeHandle()
Expand Down
32 changes: 22 additions & 10 deletions src/stream/url/URL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ bool IsURL(const std::string& strFile)
return strFile.find("://") != std::string::npos;
}

bool IsDOSPath(const std::string& path)
{
if (path.size() > 1 && path[1] == ':' && isalpha(path[0]))
return true;

// windows network drives
if (path.size() > 1 && path[0] == '\\' && path[1] == '\\')
return true;

return false;
}

std::string ValidatePath(const std::string &path)//, bool bFixDoubleSlashes /* = false */)
{
std::string result = path;
Expand All @@ -48,22 +60,22 @@ std::string ValidatePath(const std::string &path)//, bool bFixDoubleSlashes /* =

// check the path for incorrect slashes
#ifdef TARGET_WINDOWS
if (URIUtils::IsDOSPath(path))
if (IsDOSPath(path))
{
StringUtils::Replace(result, '/', '\\');
/* The double slash correction should only be used when *absolutely*
necessary! This applies to certain DLLs or use from Python DLLs/scripts
that incorrectly generate double (back) slashes.
*/
if (bFixDoubleSlashes && !result.empty())
{
// Fixup for double back slashes (but ignore the \\ of unc-paths)
for (size_t x = 1; x < result.size() - 1; x++)
{
if (result[x] == '\\' && result[x+1] == '\\')
result.erase(x, 1);
}
}
// if (bFixDoubleSlashes && !result.empty())
// {
// // Fixup for double back slashes (but ignore the \\ of unc-paths)
// for (size_t x = 1; x < result.size() - 1; x++)
// {
// if (result[x] == '\\' && result[x+1] == '\\')
// result.erase(x, 1);
// }
// }
}
else if (path.find("://") != std::string::npos || path.find(":\\\\") != std::string::npos)
#endif
Expand Down

0 comments on commit 8a87559

Please sign in to comment.