Skip to content

Commit

Permalink
Removed dependency on boost
Browse files Browse the repository at this point in the history
  • Loading branch information
WalkerKnapp committed Dec 31, 2019
1 parent dca87e6 commit 1a8e753
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 109 deletions.
57 changes: 0 additions & 57 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,57 +0,0 @@
[submodule "devolay-natives/lib/dll"]
path = devolay-natives/lib/dll
url = https://github.com/boostorg/dll.git
[submodule "devolay-natives.lib.dll"]
branch = develop
[submodule "devolay-natives/lib/config"]
path = devolay-natives/lib/config
url = https://github.com/boostorg/config.git
branch = develop
[submodule "devolay-natives/lib/predef"]
path = devolay-natives/lib/predef
url = https://github.com/boostorg/predef.git
branch = develop
[submodule "devolay-natives/lib/core"]
path = devolay-natives/lib/core
url = https://github.com/boostorg/core.git
branch = develop
[submodule "devolay-natives/lib/type_traits"]
path = devolay-natives/lib/type_traits
url = https://github.com/boostorg/type_traits.git
branch = develop
[submodule "devolay-natives/lib/throw_exception"]
path = devolay-natives/lib/throw_exception
url = https://github.com/boostorg/throw_exception.git
branch = develop
[submodule "devolay-natives/lib/assert"]
path = devolay-natives/lib/assert
url = https://github.com/boostorg/assert.git
branch = develop
[submodule "devolay-natives/lib/static_assert"]
path = devolay-natives/lib/static_assert
url = https://github.com/boostorg/static_assert.git
branch = develop
[submodule "devolay-natives/lib/system"]
path = devolay-natives/lib/system
url = https://github.com/boostorg/system.git
branch = develop
[submodule "devolay-natives/lib/winapi"]
path = devolay-natives/lib/winapi
url = https://github.com/boostorg/winapi.git
branch = develop
[submodule "devolay-natives/lib/move"]
path = devolay-natives/lib/move
url = https://github.com/boostorg/move.git
branch = develop
[submodule "devolay-natives/lib/smart_ptr"]
path = devolay-natives/lib/smart_ptr
url = https://github.com/boostorg/smart_ptr.git
branch = develop
[submodule "devolay-natives/lib/mpl"]
path = devolay-natives/lib/mpl
url = https://github.com/boostorg/mpl.git
branch = develop
[submodule "devolay-natives/lib/preprocessor"]
path = devolay-natives/lib/preprocessor
url = https://github.com/boostorg/preprocessor
branch = develop
21 changes: 13 additions & 8 deletions devolay-natives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ library {
binaries.configureEach {
// Force the CPP library to build C instead
def compileTask = compileTask.get()
def linkExecutable = linkTask.get()
//compileTask.source.from fileTree(dir: "src/main/c", include: "*\*\/*.c")

if (toolChain instanceof VisualCpp) {
compileTask.compilerArgs.add("/std:c++latest")
} else if (toolChain instanceof GccCompatibleToolChain) {
compileTask.compilerArgs.add("-std=c++17")
compileTask.compilerArgs.add("-lstdc++fs")

linkExecutable.linkerArgs.add("-lstdc++fs")
}
}
}
Expand All @@ -40,18 +44,19 @@ components.main.binaries.whenElementFinalized { binary ->
System.out.println("Linking/Including NDI(tm) SDK Path")

if(System.getenv("NDI_SDK_DIR") == null) {
throw new IllegalStateException("NDI SDK not found: NDI_SDK_DIR environment variable does not exist.")
throw new IllegalStateException("NDI SDK not found: NDI_SDK_DIR environment variable does not exist.")
}

def ndiSdkPath = file(System.getenv("NDI_SDK_DIR")).toPath();
def ndiIncludePath
if(Files.exists(ndiSdkPath.resolve("Include"))) {
ndiIncludePath = ndiSdkPath.resolve("Include")
} else if(Files.exists(ndiSdkPath.resolve("include"))) {
ndiIncludePath = ndiSdkPath.resolve("include")
} else {
throw new IllegalStateException("Could not find NDI Include folder. Check your NDI install and your NDI_SDK_DIR environment variable.")
}

if(Files.exists(ndiSdkPath.resolve("Include"))) {
ndiIncludePath = ndiSdkPath.resolve("Include")
} else if(Files.exists(ndiSdkPath.resolve("include"))) {
ndiIncludePath = ndiSdkPath.resolve("include")
} else {
throw new IllegalStateException("Could not find NDI Include folder. Check your NDI install and your NDI_SDK_DIR environment variable.")
}

def architectureName = binary.getTargetPlatform().getTargetMachine().getArchitecture().getName()

Expand Down
1 change: 0 additions & 1 deletion devolay-natives/lib/assert
Submodule assert deleted from b45979
1 change: 0 additions & 1 deletion devolay-natives/lib/config
Submodule config deleted from cda275
1 change: 0 additions & 1 deletion devolay-natives/lib/core
Submodule core deleted from f52dec
1 change: 0 additions & 1 deletion devolay-natives/lib/dll
Submodule dll deleted from 8f39a3
1 change: 0 additions & 1 deletion devolay-natives/lib/move
Submodule move deleted from 0304ee
1 change: 0 additions & 1 deletion devolay-natives/lib/mpl
Submodule mpl deleted from e01a10
1 change: 0 additions & 1 deletion devolay-natives/lib/predef
Submodule predef deleted from 73d7b4
1 change: 0 additions & 1 deletion devolay-natives/lib/preprocessor
Submodule preprocessor deleted from c436de
1 change: 0 additions & 1 deletion devolay-natives/lib/smart_ptr
Submodule smart_ptr deleted from a73410
1 change: 0 additions & 1 deletion devolay-natives/lib/static_assert
Submodule static_assert deleted from cb6d8f
1 change: 0 additions & 1 deletion devolay-natives/lib/system
Submodule system deleted from c556ab
1 change: 0 additions & 1 deletion devolay-natives/lib/throw_exception
Submodule throw_exception deleted from e2e802
1 change: 0 additions & 1 deletion devolay-natives/lib/type_traits
Submodule type_traits deleted from 4a32bc
1 change: 0 additions & 1 deletion devolay-natives/lib/winapi
Submodule winapi deleted from 65b9c9
58 changes: 42 additions & 16 deletions devolay-natives/src/main/cpp/devolay.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include <jni.h>
#include "devolay.h"

#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <atomic>

#include "devolay.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <stdlib.h>
#include <dlfcn.h>
#endif

#define BOOST_DLL_USE_STD_FS
#define _CPPUNWIND
#include <boost/dll.hpp>
#include <filesystem>

#include "../headers/com_walker_devolay_Devolay.h"

namespace fs = boost::dll::fs;
namespace fs = std::filesystem;

//static std::shared_ptr<NDIlib_v3> ndiLib;
static boost::dll::shared_library *ndiLibraryRef = nullptr;
static const NDIlib_v3 *ndiLib = (NDIlib_v3 *)calloc(1, sizeof(NDIlib_v3));

const NDIlib_v3 *getNDILib() {
Expand All @@ -37,32 +37,58 @@ jint Java_com_walker_devolay_Devolay_nLoadLibraries(JNIEnv * env, jclass jClazz)

for(const std::string& possiblePath : locations) {
fs::path possibleLibPath(possiblePath);
possibleLibPath += "/";
//possibleLibPath += "/";
possibleLibPath += NDILIB_LIBRARY_NAME;

printf("Testing for NDI at %s\n", possibleLibPath.string().c_str());
printf("Testing for NDI at %s\n", possibleLibPath.c_str());

if(fs::exists(possibleLibPath) && fs::is_regular_file(possibleLibPath)) {
printf("Found NDI library at '%s'\n", possibleLibPath.string().c_str());
printf("Found NDI library at '%s'\n", possibleLibPath.c_str());

// Load NDI library
#ifdef _WIN32
HMODULE hNDILib = LoadLibraryA(possibleLibPath.c_str());

if(hNDILib) {
const NDIlib_v3* (*NDIlib_v3_load)(void) = NULL;
*((FARPROC*)&NDIlib_v3_load) = GetProcAddress(hNDILib, "NDIlib_v3_load");

if (NDIlib_v3_load != nullptr) {
ndiLib = NDIlib_v3_load();

ndiLibraryRef = new boost::dll::shared_library(possibleLibPath);
ndiLib->NDIlib_initialize();
return 0;
} else {
FreeLibrary(hNDILib);

printf("Failed to load NDI_v3_load function.");
return -2;
}
} else {
printf("Library failed to load.");
}
#else
void *hNDILib = dlopen(possibleLibPath.c_str(), RTLD_LOCAL | RTLD_LAZY);

if(ndiLibraryRef) {
if(hNDILib) {
const NDIlib_v3* (*NDIlib_v3_load)(void) = NULL;
NDIlib_v3_load = ndiLibraryRef->get<const NDIlib_v3 *()>("NDIlib_v3_load");
*((void**)&NDIlib_v3_load) = dlsym(hNDILib, "NDIlib_v3_load");

if (NDIlib_v3_load != nullptr) {
ndiLib = NDIlib_v3_load();

ndiLib->NDIlib_initialize();
return 0;
} else {
dlclose(hNDILib);

printf("Failed to load NDI_v3_load function.");
return -2;
}
} else {
printf("Library failed to load.");
}
#endif
}
}

Expand Down
5 changes: 4 additions & 1 deletion devolay-natives/src/main/cpp/devolay.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

#ifndef DEVOLAY_DEVOLAY_H
#define DEVOLAY_DEVOLAY_H

#include <stdint.h>
#include <cstddef>

#include <Processing.NDI.Lib.h>
typedef __int64_t __int64;
#include <jni.h>

extern const NDIlib_v3 *getNDILib();

Expand Down
1 change: 0 additions & 1 deletion devolay-natives/src/main/cpp/finder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "devolay.h"
#include <Processing.NDI.Lib.h>

#include "com_walker_devolay_DevolayFinder.h"

Expand Down
3 changes: 0 additions & 3 deletions devolay-natives/src/main/cpp/frames.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "devolay.h"

#include <jni.h>
#include <cstdio>

#include <Processing.NDI.Lib.h>

#include "../headers/com_walker_devolay_DevolayAudioFrame.h"
#include "../headers/com_walker_devolay_DevolayAudioFrameInterleaved16s.h"
#include "../headers/com_walker_devolay_DevolayAudioFrameInterleaved32s.h"
Expand Down
3 changes: 0 additions & 3 deletions devolay-natives/src/main/cpp/performance.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "devolay.h"

#include <jni.h>
#include <Processing.NDI.Lib.h>

#include "com_walker_devolay_DevolayPerformanceData.h"

jlong Java_com_walker_devolay_DevolayPerformanceData_createPerformanceStruct(JNIEnv *env, jclass jClazz) {
Expand Down
2 changes: 0 additions & 2 deletions devolay-natives/src/main/cpp/receiver.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "devolay.h"
#include <jni.h>
#include <Processing.NDI.Lib.h>

#include "com_walker_devolay_DevolayReceiver.h"

Expand Down
2 changes: 0 additions & 2 deletions devolay-natives/src/main/cpp/sender.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "devolay.h"
#include <jni.h>
#include <Processing.NDI.Lib.h>
#include <functional>

#include "../headers/com_walker_devolay_DevolaySender.h"
Expand Down
3 changes: 1 addition & 2 deletions devolay-natives/src/main/cpp/source.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "devolay.h"
#include <jni.h>

#include <cstdio>
#include <Processing.NDI.Lib.h>

#include "../headers/com_walker_devolay_DevolaySource.h"

Expand Down

0 comments on commit 1a8e753

Please sign in to comment.