diff --git a/env.sh b/env.sh new file mode 100644 index 0000000..af4eeba --- /dev/null +++ b/env.sh @@ -0,0 +1 @@ +export teaclient_deploy_secret=e6b580eb10890f3660f07d26243dbafb275b7c1ed30a2ea1c0f802f971a5ca424805a28f82882d9cf5aa47b592d7d7c00f44564a7ebfcb9801c549a71ddf6e9b diff --git a/jenkins/create_build.sh b/jenkins/create_build.sh index d96f108..08ef2e3 100755 --- a/jenkins/create_build.sh +++ b/jenkins/create_build.sh @@ -122,5 +122,5 @@ function deploy_client() { #install_npm #compile_scripts #compile_native -package_client -#deploy_client +#package_client +deploy_client diff --git a/native/serverconnection/src/audio/filter/FilterVad.h b/native/serverconnection/src/audio/filter/FilterVad.h index 401a66c..eceb10e 100644 --- a/native/serverconnection/src/audio/filter/FilterVad.h +++ b/native/serverconnection/src/audio/filter/FilterVad.h @@ -1,46 +1,43 @@ #pragma once #include "Filter.h" +#include #include #include -namespace tc { - namespace audio { - namespace filter { - class VadFilter : public Filter { - public: - VadFilter(size_t /* channel count */, size_t /* sample rate */, size_t /* frame size */); - virtual ~VadFilter(); +namespace tc::audio::filter { + class VadFilter : public Filter { + public: + VadFilter(size_t /* channel count */, size_t /* sample rate */, size_t /* frame size */); + virtual ~VadFilter(); - bool initialize(std::string& /* error */, size_t /* mode */, size_t /* margin frames */); - bool process(const void* /* buffer */) override; + bool initialize(std::string& /* error */, size_t /* mode */, size_t /* margin frames */); + bool process(const void* /* buffer */) override; - inline float margin_release_time() { return (float) this->_margin_samples / (float) this->_sample_rate; } - inline void set_margin_release_time(float value) { this->_margin_samples = (size_t) ceil((float) this->_sample_rate * value); } + inline float margin_release_time() { return (float) this->_margin_samples / (float) this->_sample_rate; } + inline void set_margin_release_time(float value) { this->_margin_samples = (size_t) ceil((float) this->_sample_rate * value); } - inline size_t mode() { return this->_mode; } - private: - Fvad* _vad_handle = nullptr; + inline size_t mode() { return this->_mode; } + private: + Fvad* _vad_handle = nullptr; - size_t _mode = 0; - size_t _margin_samples = 0; - size_t _margin_processed_samples = 0; + size_t _mode = 0; + size_t _margin_samples = 0; + size_t _margin_processed_samples = 0; - std::mutex _buffer_lock; - void* _buffer = nullptr; - size_t _buffer_size = 0; + std::mutex _buffer_lock; + void* _buffer = nullptr; + size_t _buffer_size = 0; - void cleanup_buffer(); - inline void ensure_buffer(size_t length) { - if(this->_buffer_size < length) { - if(this->_buffer) - free(this->_buffer); + void cleanup_buffer(); + inline void ensure_buffer(size_t length) { + if(this->_buffer_size < length) { + if(this->_buffer) + free(this->_buffer); - this->_buffer_size = length; - this->_buffer = malloc(this->_buffer_size); - } - } - }; - } - } + this->_buffer_size = length; + this->_buffer = malloc(this->_buffer_size); + } + } + }; } \ No newline at end of file diff --git a/native/serverconnection/src/connection/ServerConnection.cpp b/native/serverconnection/src/connection/ServerConnection.cpp index d8b025f..b4464b2 100644 --- a/native/serverconnection/src/connection/ServerConnection.cpp +++ b/native/serverconnection/src/connection/ServerConnection.cpp @@ -201,6 +201,7 @@ void ServerConnection::schedule_resend(const std::chrono::system_clock::time_poi } } +#ifdef WIN32 inline std::string wsa_error_str(int code) { int err; char msgbuf[256]; // for a message up to 255 bytes. @@ -219,6 +220,7 @@ inline std::string wsa_error_str(int code) { sprintf(msgbuf, "%d", err); // provide error # if no string available return std::string{msgbuf}; } +#endif NAN_METHOD(ServerConnection::connect) { if(!this->protocol_handler) { @@ -328,7 +330,7 @@ NAN_METHOD(ServerConnection::connect) { #if WIN32 auto message = wsa_error_str(detail); #else - auto message = strerror(detail); + auto message = std::string{strerror(detail)}; #endif this->execute_callback_disconnect.call((code == 1 ? tr("Failed to received data: ") : tr("Failed to send data: ")) + message, false); this->close_connection(); diff --git a/native/serverconnection/src/hwuid.cpp b/native/serverconnection/src/hwuid.cpp index 1803641..c0d41e3 100644 --- a/native/serverconnection/src/hwuid.cpp +++ b/native/serverconnection/src/hwuid.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #ifndef WIN32 #ifdef DARWIN @@ -52,10 +53,8 @@ constexpr uint8_t hex_value(char c) { } bool read_machine_id(uint8_t(&uuid)[16]) { - strobf_define(_path, "/etc/machine-id"); - memset(uuid, 0, 16); - std::ifstream in(strobf_val(_path).string()); + std::ifstream in(strobf("/etc/machine-id").string()); if(in) { char buffer[32]; if(!in.read(buffer, 32)) return false; diff --git a/native/serverconnection/src/ring_buffer.cpp b/native/serverconnection/src/ring_buffer.cpp index 78256a5..a55669d 100644 --- a/native/serverconnection/src/ring_buffer.cpp +++ b/native/serverconnection/src/ring_buffer.cpp @@ -3,6 +3,7 @@ // #include "ring_buffer.h" +#include #ifdef HAVE_SOUNDIO using namespace tc; @@ -49,11 +50,17 @@ void ring_buffer::clear() { } #else -#include -#include -#include +#ifdef WIN32 + #include + #include +#else + #include + #include + #include +#endif namespace tc { +#ifdef WIN32 bool sysinfo_initialized{false}; static SYSTEM_INFO win32_system_info; @@ -64,6 +71,11 @@ namespace tc { } return win32_system_info.dwAllocationGranularity; } +#else + long int soundio_os_page_size() { + return sysconf(_SC_PAGESIZE); + } +#endif static inline size_t ceil_dbl_to_size_t(double x) { const auto truncation = (double) x; @@ -134,7 +146,58 @@ namespace tc { break; } #else - #error "Implement me!" + char shm_path[] = "/dev/shm/teaclient-XXXXXX"; + char tmp_path[] = "/tmp/teaclient-XXXXXX"; + char *chosen_path; + + int fd = mkstemp(shm_path); + if (fd < 0) { + fd = mkstemp(tmp_path); + if (fd < 0) { + return false; + } else { + chosen_path = tmp_path; + } + } else { + chosen_path = shm_path; + } + + if (unlink(chosen_path)) { + close(fd); + return false; + } + + if (ftruncate(fd, actual_capacity)) { + close(fd); + return false; + } + + char *address = (char*) mmap(nullptr, actual_capacity * 2, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (address == MAP_FAILED) { + close(fd); + return false; + } + + char *other_address = (char*) mmap(address, actual_capacity, PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_SHARED, fd, 0); + if (other_address != address) { + munmap(address, 2 * actual_capacity); + close(fd); + return false; + } + + other_address = (char*) mmap(address + actual_capacity, actual_capacity, + PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0); + if (other_address != address + actual_capacity) { + munmap(address, 2 * actual_capacity); + close(fd); + return false; + } + + this->memory.address = address; + + if (close(fd)) + return false; #endif this->memory.capacity = actual_capacity; @@ -154,7 +217,8 @@ namespace tc { ok = CloseHandle((HANDLE) this->memory.priv); assert(ok); #else - #error "Implement me!" + int err = munmap(this->memory.address, 2 * this->memory.capacity); + assert(!err); #endif this->memory.address = nullptr; diff --git a/native/serverconnection/src/ring_buffer.h b/native/serverconnection/src/ring_buffer.h index f0230ff..ee67cf1 100644 --- a/native/serverconnection/src/ring_buffer.h +++ b/native/serverconnection/src/ring_buffer.h @@ -39,8 +39,8 @@ namespace tc { MirroredMemory memory{}; - std::atomic_long write_offset; - std::atomic_long read_offset; + std::atomic_long write_offset{}; + std::atomic_long read_offset{}; size_t _capacity{0}; /* for faster access */ #endif