diff --git a/binding.gyp b/binding.gyp index ba02250..a15b7f5 100644 --- a/binding.gyp +++ b/binding.gyp @@ -8,10 +8,33 @@ "src/node-srt.cc" ], "include_dirs": [ - "", "contributors": [ - "Jonas Rydholm Birmé (Eyevinn Technology AB)" + "Jonas Rydholm Birmé (Eyevinn Technology AB)", + "Dillon Pentz " ], "license": "MIT", "devDependencies": { diff --git a/scripts/build-srt-sdk.js b/scripts/build-srt-sdk.js index a131395..4506ca0 100644 --- a/scripts/build-srt-sdk.js +++ b/scripts/build-srt-sdk.js @@ -1,9 +1,10 @@ const path = require('path'); const fs = require('fs'); +const process = require('process'); const clone = require('git-clone'); const { spawnSync } = require('child_process'); -const SRT_REPO = "git@github.com:Haivision/srt.git"; +const SRT_REPO = "https://github.com/Haivision/srt.git"; const SRT_VERSION = "v1.4.1"; const depsPath = path.join(__dirname, '../', 'deps'); @@ -16,28 +17,78 @@ if (!fs.existsSync(depsPath)) { if (!fs.existsSync(buildDir)) { console.log(`Cloning ${SRT_REPO}:${SRT_VERSION}`); clone(SRT_REPO, srtSourcePath, { checkout: SRT_VERSION }, () => { - console.log("Running ./configure"); - const configure = spawnSync('./configure', [ '--prefix', buildDir ], { cwd: srtSourcePath, shell: true } ); - console.log(configure.stdout.toString()); - if (configure.status) { - console.log(configure.stderr.toString()); - process.exit(configure.status); - } + if (process.platform === "win32") { + process.env.SRT_ROOT = srtSourcePath; + fs.mkdirSync(buildDir); - console.log("Running make"); - const make = spawnSync('make', [], { cwd: srtSourcePath, shell: true }); - console.log(make.stdout.toString()); - if (make.status) { - console.log(make.stderr.toString()); - process.exit(make.status); - } + console.log("Building OpenSSL"); + const openssl = spawnSync('vcpkg', [ 'install', 'openssl', '--triplet', `${process.arch}-windows` ], { cwd: process.env.VCPKG_ROOT, shell: true } ); + if (openssl.stdout) + console.log(openssl.stdout.toString()); + if (openssl.status) { + console.log(openssl.stderr.toString()); + process.exit(openssl.status); + } + + console.log("Building pthreads"); + const pthreads = spawnSync('vcpkg', [ 'install', 'pthreads', '--triplet', `${process.arch}-windows` ], { cwd: process.env.VCPKG_ROOT, shell: true } ); + if (pthreads.stdout) + console.log(pthreads.stdout.toString()); + if (pthreads.status) { + console.log(pthreads.stderr.toString()); + process.exit(pthreads.status); + } + + console.log("Integrate vcpkg build system"); + const integrate = spawnSync('vcpkg', [ 'integrate', 'install' ], { cwd: process.env.VCPKG_ROOT, shell: true } ); + if (integrate.stdout) + console.log(integrate.stdout.toString()); + if (integrate.status) { + console.log(integrate.stderr.toString()); + process.exit(integrate.status); + } + + console.log("Running cmake generator"); + const generator = spawnSync('cmake', [ srtSourcePath, '-DCMAKE_BUILD_TYPE=Release', '-G"Visual Studio 16 2019"', '-A', process.arch, '-DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT%\\scripts\\buildsystems\\vcpkg.cmake' ], { cwd: buildDir, shell: true } ); + if (generator.stdout) + console.log(generator.stdout.toString()); + if (generator.status) { + console.log(generator.stderr.toString()); + process.exit(generator.status); + } + + console.log("Running cmake build"); + const build = spawnSync('cmake', [ '--build', buildDir, '--config', 'Release' ], { cwd: buildDir, shell: true } ); + if (build.stdout) + console.log(build.stdout.toString()); + if (build.status) { + console.log(build.stderr.toString()); + process.exit(build.status); + } + } else { + console.log("Running ./configure"); + const configure = spawnSync('./configure', [ '--prefix', buildDir ], { cwd: srtSourcePath, shell: true } ); + console.log(configure.stdout.toString()); + if (configure.status) { + console.log(configure.stderr.toString()); + process.exit(configure.status); + } + + console.log("Running make"); + const make = spawnSync('make', [], { cwd: srtSourcePath, shell: true }); + console.log(make.stdout.toString()); + if (make.status) { + console.log(make.stderr.toString()); + process.exit(make.status); + } - console.log("Running make install"); - const install = spawnSync('make', [ 'install' ], { cwd: srtSourcePath, shell: true }); - console.log(install.stdout.toString()); - if (install.status) { - console.log(install.stderr.toString()); - process.exit(install.status); + console.log("Running make install"); + const install = spawnSync('make', [ 'install' ], { cwd: srtSourcePath, shell: true }); + console.log(install.stdout.toString()); + if (install.status) { + console.log(install.stderr.toString()); + process.exit(install.status); + } } }); } \ No newline at end of file diff --git a/src/node-srt.cc b/src/node-srt.cc index abd554d..d4bc7eb 100644 --- a/src/node-srt.cc +++ b/src/node-srt.cc @@ -1,5 +1,10 @@ +#if defined(_WIN32) +#include +#pragma comment(lib, "ws2_32.lib") +#elif !defined(_WIN32) #include #include +#endif #include "node-srt.h" Napi::FunctionReference NodeSRT::constructor; @@ -170,15 +175,19 @@ Napi::Value NodeSRT::Read(const Napi::CallbackInfo& info) { Napi::Number chunkSize = info[1].As(); size_t bufferSize = uint32_t(chunkSize); - uint8_t buffer[bufferSize]; - memset(&buffer, 0, bufferSize); + uint8_t *buffer = (uint8_t *)malloc(bufferSize); + memset(buffer, 0, bufferSize); int nb = srt_recvmsg(socketValue, (char *)buffer, (int)bufferSize); if (nb == SRT_ERROR) { Napi::Error::New(env, srt_getlasterror_str()).ThrowAsJavaScriptException(); return Napi::Number::New(env, SRT_ERROR); } - return Napi::Buffer::Copy(env, buffer, nb); + + Napi::Value nbuff = Napi::Buffer::Copy(env, buffer, nb); + free(buffer); + + return nbuff; } Napi::Value NodeSRT::Write(const Napi::CallbackInfo& info) {