mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 00:13:01 +08:00
Add oboe-wrapper local vcpkg port
... because we switched to unmodified oboe. The wrapper is built as separate local vcpkg port that depends on oboe. Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
This commit is contained in:
parent
7bafe142ca
commit
0dfb1ae776
1
build.rs
1
build.rs
@ -70,6 +70,7 @@ fn install_android_deps() {
|
||||
);
|
||||
println!("cargo:rustc-link-lib=ndk_compat");
|
||||
println!("cargo:rustc-link-lib=oboe");
|
||||
println!("cargo:rustc-link-lib=oboe_wrapper");
|
||||
println!("cargo:rustc-link-lib=c++");
|
||||
println!("cargo:rustc-link-lib=OpenSLES");
|
||||
}
|
||||
|
15
res/vcpkg/oboe-wrapper/CMakeLists.txt
Normal file
15
res/vcpkg/oboe-wrapper/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(oboe_wrapper CXX)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
add_library(oboe_wrapper STATIC
|
||||
oboe.cc
|
||||
)
|
||||
|
||||
target_include_directories(oboe_wrapper PRIVATE "${CURRENT_INSTALLED_DIR}/include")
|
||||
|
||||
install(TARGETS oboe_wrapper
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
8
res/vcpkg/oboe-wrapper/portfile.cmake
Normal file
8
res/vcpkg/oboe-wrapper/portfile.cmake
Normal file
@ -0,0 +1,8 @@
|
||||
vcpkg_configure_cmake(
|
||||
SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}"
|
||||
OPTIONS
|
||||
-DCURRENT_INSTALLED_DIR=${CURRENT_INSTALLED_DIR}
|
||||
PREFER_NINJA
|
||||
)
|
||||
|
||||
vcpkg_cmake_install()
|
19
res/vcpkg/oboe-wrapper/vcpkg.json
Normal file
19
res/vcpkg/oboe-wrapper/vcpkg.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "oboe-wrapper",
|
||||
"version": "0",
|
||||
"description": "None",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "vcpkg-cmake-config",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "oboe",
|
||||
"host": false
|
||||
}
|
||||
]
|
||||
}
|
147
src/oboe.patch
147
src/oboe.patch
@ -1,147 +0,0 @@
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 51a45b2..75be96a 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -60,7 +60,7 @@ set (oboe_sources
|
||||
src/common/Version.cpp
|
||||
)
|
||||
|
||||
-add_library(oboe ${oboe_sources})
|
||||
+ add_library(oboe STATIC ${oboe_sources})
|
||||
|
||||
# Specify directories which the compiler should look for headers
|
||||
target_include_directories(oboe
|
||||
@@ -91,4 +91,4 @@ install(TARGETS oboe
|
||||
ARCHIVE DESTINATION lib/${ANDROID_ABI})
|
||||
|
||||
# Also install the headers
|
||||
-install(DIRECTORY include/oboe DESTINATION include)
|
||||
\ No newline at end of file
|
||||
+install(DIRECTORY include/oboe DESTINATION include)
|
||||
diff --git a/src/common/AudioStreamBuilder.cpp b/src/common/AudioStreamBuilder.cpp
|
||||
index dffcd75..79984a4 100644
|
||||
--- a/src/common/AudioStreamBuilder.cpp
|
||||
+++ b/src/common/AudioStreamBuilder.cpp
|
||||
@@ -215,3 +215,122 @@ Result AudioStreamBuilder::openStream(std::shared_ptr<AudioStream> &sharedStream
|
||||
}
|
||||
|
||||
} // namespace oboe
|
||||
+
|
||||
+#include <oboe/Oboe.h>
|
||||
+#include <math.h>
|
||||
+#include <deque>
|
||||
+#include <pthread.h>
|
||||
+
|
||||
+// I got link problem with std::mutex, so use pthread instead
|
||||
+class CThreadLock
|
||||
+{
|
||||
+public:
|
||||
+ CThreadLock();
|
||||
+ virtual ~CThreadLock();
|
||||
+
|
||||
+ void Lock();
|
||||
+ void Unlock();
|
||||
+
|
||||
+private:
|
||||
+ pthread_mutex_t mutexlock;
|
||||
+};
|
||||
+
|
||||
+CThreadLock::CThreadLock()
|
||||
+{
|
||||
+ // init lock here
|
||||
+ pthread_mutex_init(&mutexlock, 0);
|
||||
+}
|
||||
+
|
||||
+CThreadLock::~CThreadLock()
|
||||
+{
|
||||
+ // deinit lock here
|
||||
+ pthread_mutex_destroy(&mutexlock);
|
||||
+}
|
||||
+void CThreadLock::Lock()
|
||||
+{
|
||||
+ // lock
|
||||
+ pthread_mutex_lock(&mutexlock);
|
||||
+}
|
||||
+void CThreadLock::Unlock()
|
||||
+{
|
||||
+ // unlock
|
||||
+ pthread_mutex_unlock(&mutexlock);
|
||||
+}
|
||||
+
|
||||
+class Player : public oboe::AudioStreamDataCallback
|
||||
+{
|
||||
+public:
|
||||
+ ~Player() {
|
||||
+ outStream->requestStop();
|
||||
+ }
|
||||
+
|
||||
+ Player(int channels, int sample_rate)
|
||||
+ {
|
||||
+ this->channels = channels;
|
||||
+ oboe::AudioStreamBuilder builder;
|
||||
+ // The builder set methods can be chained for convenience.
|
||||
+ builder.setSharingMode(oboe::SharingMode::Exclusive)
|
||||
+ ->setPerformanceMode(oboe::PerformanceMode::LowLatency)
|
||||
+ ->setChannelCount(channels)
|
||||
+ ->setSampleRate(sample_rate)
|
||||
+ ->setFormat(oboe::AudioFormat::Float)
|
||||
+ ->setDataCallback(this)
|
||||
+ ->openManagedStream(outStream);
|
||||
+ // Typically, start the stream after querying some stream information, as well as some input from the user
|
||||
+ outStream->requestStart();
|
||||
+ }
|
||||
+
|
||||
+ oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData, int32_t numFrames) override
|
||||
+ {
|
||||
+ float *floatData = (float *)audioData;
|
||||
+ int i = 0;
|
||||
+ mtx.Lock();
|
||||
+ auto n = channels * numFrames;
|
||||
+ for (; i < n && i < (int)buffer.size(); ++i, ++floatData)
|
||||
+ {
|
||||
+ *floatData = buffer.front();
|
||||
+ buffer.pop_front();
|
||||
+ }
|
||||
+ mtx.Unlock();
|
||||
+ for (; i < n; ++i, ++floatData)
|
||||
+ {
|
||||
+ *floatData = 0;
|
||||
+ }
|
||||
+ return oboe::DataCallbackResult::Continue;
|
||||
+ }
|
||||
+
|
||||
+ void push(const float *v, int n)
|
||||
+ {
|
||||
+ mtx.Lock();
|
||||
+ for (auto i = 0; i < n; ++i, ++v)
|
||||
+ buffer.push_back(*v);
|
||||
+ // in case memory overuse
|
||||
+ if (buffer.size() > 48 * 1024 * 120)
|
||||
+ buffer.clear();
|
||||
+ mtx.Unlock();
|
||||
+ }
|
||||
+
|
||||
+private:
|
||||
+ oboe::ManagedStream outStream;
|
||||
+ int channels;
|
||||
+ std::deque<float> buffer;
|
||||
+ CThreadLock mtx;
|
||||
+};
|
||||
+
|
||||
+extern "C"
|
||||
+{
|
||||
+ void *create_oboe_player(int channels, int sample_rate)
|
||||
+ {
|
||||
+ return new Player(channels, sample_rate);
|
||||
+ }
|
||||
+
|
||||
+ void push_oboe_data(void *player, const float* v, int n)
|
||||
+ {
|
||||
+ static_cast<Player *>(player)->push(v, n);
|
||||
+ }
|
||||
+
|
||||
+ void destroy_oboe_player(void *player)
|
||||
+ {
|
||||
+ delete static_cast<Player *>(player);
|
||||
+ }
|
||||
+}
|
@ -24,6 +24,10 @@
|
||||
"name": "oboe",
|
||||
"platform": "android"
|
||||
},
|
||||
{
|
||||
"name": "oboe-wrapper",
|
||||
"platform": "android"
|
||||
},
|
||||
{
|
||||
"name": "opus",
|
||||
"host": true
|
||||
|
Loading…
Reference in New Issue
Block a user