From 3484bd11c2440c0dbf8e789a6b2972c85f50310c Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Thu, 7 Jan 2021 19:19:35 +0200 Subject: [PATCH] waver : bump version to v1.3.2 - single-threaded app - new message indicator - audio capture indicator - emscripten compatibility --- examples/ggwave-common.cpp | 59 +++++++++++++++++++++++++++++ examples/ggwave-common.h | 5 +++ examples/waver/common.cpp | 31 ++++----------- examples/waver/common.h | 4 +- examples/waver/index-tmpl.html | 2 +- examples/waver/main.cpp | 69 +--------------------------------- 6 files changed, 74 insertions(+), 96 deletions(-) diff --git a/examples/ggwave-common.cpp b/examples/ggwave-common.cpp index afd00b9..6607d27 100644 --- a/examples/ggwave-common.cpp +++ b/examples/ggwave-common.cpp @@ -1,6 +1,15 @@ #include "ggwave-common.h" +#include +#include + #include +#include +#include + +namespace { +void dummy() {} +} std::map parseCmdArguments(int argc, char ** argv) { int last = argc; @@ -15,3 +24,53 @@ std::map parseCmdArguments(int argc, char ** argv) { return res; } + +std::vector readFile(const char* filename) { + std::ifstream file(filename, std::ios::binary); + if (!file.is_open() || !file.good()) return {}; + + file.unsetf(std::ios::skipws); + std::streampos fileSize; + + file.seekg(0, std::ios::end); + fileSize = file.tellg(); + file.seekg(0, std::ios::beg); + + std::vector vec; + vec.reserve(fileSize); + + vec.insert(vec.begin(), + std::istream_iterator(file), + std::istream_iterator()); + + return vec; +} + +std::string getBinaryPath() { +#ifdef __EMSCRIPTEN__ + return ""; +#endif + std::string result; + void* p = reinterpret_cast(dummy); + + Dl_info info; + dladdr(p, &info); + + if (*info.dli_fname == '/') { + result = info.dli_fname; + } else { + char buff[2048]; + auto len = readlink("/proc/self/exe", buff, sizeof(buff) - 1); + if (len > 0) { + buff[len] = 0; + result = buff; + } + } + + auto slash = result.rfind('/'); + if (slash != std::string::npos) { + result.erase(slash + 1); + } + + return result; +} diff --git a/examples/ggwave-common.h b/examples/ggwave-common.h index 5258b18..dcc769b 100644 --- a/examples/ggwave-common.h +++ b/examples/ggwave-common.h @@ -3,6 +3,7 @@ #include #include #include +#include // some basic helper methods for the examples @@ -11,4 +12,8 @@ float getTime_ms(const T & tStart, const T & tEnd) { return ((float)(std::chrono::duration_cast(tEnd - tStart).count()))/1000.0; } +std::vector readFile(const char* filename); + +std::string getBinaryPath(); + std::map parseCmdArguments(int argc, char ** argv); diff --git a/examples/waver/common.cpp b/examples/waver/common.cpp index a552b6b..492c239 100644 --- a/examples/waver/common.cpp +++ b/examples/waver/common.cpp @@ -14,12 +14,10 @@ #include #include -#include #include #include #include #include -#include #include #include #include @@ -188,8 +186,6 @@ struct Input { }; struct Buffer { - std::mutex mutex; - State stateCore; Input inputCore; @@ -197,9 +193,9 @@ struct Buffer { Input inputUI; }; +bool g_isRunning; GGWave * g_ggWave; Buffer g_buffer; -std::atomic g_isRunning; // file send data struct BroadcastInfo { @@ -497,7 +493,7 @@ void updateCore() { static GGWave::TxRxData lastRxData; { - std::lock_guard lock(g_buffer.mutex); + //std::lock_guard lock(g_buffer.mutex); if (g_buffer.inputCore.update) { inputCurrent = std::move(g_buffer.inputCore); g_buffer.inputCore.update = false; @@ -565,23 +561,11 @@ void updateCore() { } { - std::lock_guard lock(g_buffer.mutex); + //std::lock_guard lock(g_buffer.mutex); g_buffer.stateCore.apply(g_buffer.stateUI); } } -std::thread initMainAndRunCore() { - initMain(); - - return std::thread([&]() { - while (g_isRunning) { - updateCore(); - - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } - }); -} - void renderMain() { g_fileServer.update(); @@ -642,7 +626,7 @@ void renderMain() { static State stateCurrent; { - std::lock_guard lock(g_buffer.mutex); + //std::lock_guard lock(g_buffer.mutex); g_buffer.stateUI.apply(stateCurrent); } @@ -814,7 +798,7 @@ void renderMain() { ImGui::BeginChild("Settings:main", ImGui::GetContentRegionAvail(), true); ImGui::Text("%s", ""); ImGui::Text("%s", ""); - ImGui::Text("Waver v1.3.1"); + ImGui::Text("Waver v1.3.2"); ImGui::Separator(); ImGui::Text("%s", ""); @@ -1521,7 +1505,7 @@ void renderMain() { ImGui::GetIO().KeysDown[ImGui::GetIO().KeyMap[ImGuiKey_Enter]] = false; { - std::lock_guard lock(g_buffer.mutex); + //std::lock_guard lock(g_buffer.mutex); if (g_buffer.inputUI.update) { g_buffer.inputCore = std::move(g_buffer.inputUI); g_buffer.inputUI.update = false; @@ -1529,7 +1513,6 @@ void renderMain() { } } -void deinitMain(std::thread & worker) { +void deinitMain() { g_isRunning = false; - worker.join(); } diff --git a/examples/waver/common.h b/examples/waver/common.h index 51e31f3..5bbe55b 100644 --- a/examples/waver/common.h +++ b/examples/waver/common.h @@ -2,14 +2,12 @@ #include "ggwave-common-sdl2.h" -#include #include -std::thread initMainAndRunCore(); void initMain(); void updateCore(); void renderMain(); -void deinitMain(std::thread & worker); +void deinitMain(); // share info diff --git a/examples/waver/index-tmpl.html b/examples/waver/index-tmpl.html index eb2a9e3..84fdd91 100644 --- a/examples/waver/index-tmpl.html +++ b/examples/waver/index-tmpl.html @@ -180,7 +180,7 @@ window.onerror = function() { console.log("onerror: " + JSON.stringify(event)); if (checkSharedArrayBuffer() == false) { - document.getElementById('container_status').innerHTML = "It seems your browser does not have SharedArrayBuffer support enabled.

Try openning this page on a PC with latest Chrome browser."; + document.getElementById('container_status').innerHTML = "Failed to load the WebAssembly module.

Try openning this page on a PC with latest Chrome browser."; document.getElementById('container_status').style.color = "#ff0000"; document.getElementById('container_button').hidden = true; } diff --git a/examples/waver/main.cpp b/examples/waver/main.cpp index 5dff56b..b49bb03 100644 --- a/examples/waver/main.cpp +++ b/examples/waver/main.cpp @@ -14,69 +14,9 @@ #include #include -#include -#include - -#include #include -#include #include -namespace { -void dummy() {} -} - -std::string getBinaryPath() { -#ifdef __EMSCRIPTEN__ - return ""; -#endif - std::string result; - void* p = reinterpret_cast(dummy); - - Dl_info info; - dladdr(p, &info); - - if (*info.dli_fname == '/') { - result = info.dli_fname; - } else { - char buff[2048]; - auto len = readlink("/proc/self/exe", buff, sizeof(buff) - 1); - if (len > 0) { - buff[len] = 0; - result = buff; - } - } - - auto slash = result.rfind('/'); - if (slash != std::string::npos) { - result.erase(slash + 1); - } - - return result; -} - - -std::vector readFile(const char* filename) { - std::ifstream file(filename, std::ios::binary); - if (!file.is_open() || !file.good()) return {}; - - file.unsetf(std::ios::skipws); - std::streampos fileSize; - - file.seekg(0, std::ios::end); - fileSize = file.tellg(); - file.seekg(0, std::ios::beg); - - std::vector vec; - vec.reserve(fileSize); - - vec.insert(vec.begin(), - std::istream_iterator(file), - std::istream_iterator()); - - return vec; -} - // ImGui helpers bool ImGui_BeginFrame(SDL_Window * window) { @@ -289,7 +229,6 @@ int main(int argc, char** argv) { //addFile("test2.mpv", "test0.mov", std::vector(1024*1024*234 + 53827)); bool isInitialized = false; - std::thread worker; g_doInit = [&]() { if (GGWave_init(playbackId, captureId) == false) { @@ -297,11 +236,7 @@ int main(int argc, char** argv) { return false; } -#ifdef __EMSCRIPTEN__ initMain(); -#else - worker = initMainAndRunCore(); -#endif isInitialized = true; @@ -323,9 +258,7 @@ int main(int argc, char** argv) { renderMain(); updateMain(); -#ifdef __EMSCRIPTEN__ updateCore(); -#endif ImGui_EndFrame(window); @@ -344,7 +277,7 @@ int main(int argc, char** argv) { if (g_mainUpdate() == false) break; } - deinitMain(worker); + deinitMain(); GGWave_deinit(); // Cleanup