Fixed some stuff for linux
This commit is contained in:
parent
24c6c4d32c
commit
8436557418
1
env.sh
Normal file
1
env.sh
Normal file
@ -0,0 +1 @@
|
||||
export teaclient_deploy_secret=e6b580eb10890f3660f07d26243dbafb275b7c1ed30a2ea1c0f802f971a5ca424805a28f82882d9cf5aa47b592d7d7c00f44564a7ebfcb9801c549a71ddf6e9b
|
@ -122,5 +122,5 @@ function deploy_client() {
|
||||
#install_npm
|
||||
#compile_scripts
|
||||
#compile_native
|
||||
package_client
|
||||
#deploy_client
|
||||
#package_client
|
||||
deploy_client
|
||||
|
@ -1,46 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "Filter.h"
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include <fvad.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -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();
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <tomcrypt.h>
|
||||
#include <fstream>
|
||||
#include <misc/base64.h>
|
||||
#include <misc/strobf.h>
|
||||
|
||||
#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;
|
||||
|
@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "ring_buffer.h"
|
||||
#include <cassert>
|
||||
|
||||
#ifdef HAVE_SOUNDIO
|
||||
using namespace tc;
|
||||
@ -49,11 +50,17 @@ void ring_buffer::clear() {
|
||||
}
|
||||
#else
|
||||
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <cassert>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#else
|
||||
#include <cstdlib>
|
||||
#include <sys/mman.h>
|
||||
#include <zconf.h>
|
||||
#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;
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user