Enable microphone support

This commit is contained in:
Patrick Nicolas
2024-03-15 15:17:35 +01:00
parent c006e6c31b
commit f2dc24c316
11 changed files with 112 additions and 35 deletions
+55 -27
View File
@@ -69,6 +69,15 @@ public:
}
};
struct Void
{
static std::string type()
{
return "V";
}
constexpr static const auto call_method = &_JNIEnv::CallVoidMethod;
};
namespace details
{
@@ -78,6 +87,10 @@ struct deleter
{
jni_thread::env().DeleteLocalRef(j);
}
void operator()(jobjectArray j)
{
jni_thread::env().DeleteLocalRef(j);
}
};
template <typename... Args>
@@ -106,6 +119,21 @@ auto handle(const T & t, Args &&... args)
{
return std::tuple_cat(std::make_tuple(t.handle()), handle(std::forward<Args>(args)...));
}
template <typename T>
struct type_map
{
using type = T;
};
template <>
struct type_map<void>
{
using type = jni::Void;
};
template <typename T>
using type_map_t = type_map<T>::type;
} // namespace details
struct klass
@@ -122,11 +150,13 @@ struct klass
{
auto & env = jni_thread::env();
self.reset(env.GetObjectClass(instance));
assert(self.get());
}
klass(const char * name) :
self(jni_thread::env().FindClass(name))
{
assert(self.get());
}
template <typename T>
@@ -138,15 +168,6 @@ struct klass
}
};
struct Void
{
static std::string type()
{
return "V";
}
constexpr static const auto call_method = &_JNIEnv::CallVoidMethod;
};
struct Bool
{
static std::string type()
@@ -171,6 +192,7 @@ struct Bool
struct Int
{
constexpr static auto static_field = &_JNIEnv::GetStaticIntField;
constexpr static const auto call_method = &_JNIEnv::CallIntMethod;
static std::string type()
{
@@ -190,24 +212,6 @@ struct Int
}
};
namespace details
{
template <typename T>
struct type_map
{
using type = T;
};
template <>
struct type_map<void>
{
using type = jni::Void;
};
template <typename T>
using type_map_t = type_map<T>::type;
}; // namespace details
template <details::string_literal Type>
struct object
{
@@ -233,6 +237,7 @@ struct object
auto & env = jni_thread::env();
std::string signature = "(" + details::build_type(args...) + ")" + R1::type();
auto method_id = env.GetMethodID(klass(), method, signature.c_str());
assert(method_id);
auto handles = details::handle(std::forward<Args>(args)...);
return R(std::apply([&](auto &... t) {
return (env.*R1::call_method)(*this, method_id, t...);
@@ -282,4 +287,27 @@ struct string : public string_t
return res;
}
};
template <typename T>
struct array
{
static std::string type()
{
return std::string("[") + T::type();
}
std::unique_ptr<std::remove_pointer_t<jobjectArray>, details::deleter> self;
auto handle() const
{
return self.get();
}
array(T& element)
{
auto & env = jni_thread::env();
self.reset(env.NewObjectArray(1, element.klass(), element));
}
};
} // namespace jni