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
+6 -1
View File
@@ -219,6 +219,10 @@ scenes::lobby::lobby()
preferred_refresh_rate = rate.get_double();
session.set_refresh_rate(preferred_refresh_rate);
}
auto mic = root["microphone"];
if (mic.is_bool())
microphone = mic.get_bool();
}
catch(std::exception& e)
{
@@ -287,6 +291,7 @@ void scenes::lobby::save_config()
<< "\"show_performance_metrics\":" << std::boolalpha << show_performance_metrics;
if (preferred_refresh_rate != 0.)
json << ",\"preferred_refresh_rate\":" << preferred_refresh_rate ;
json << ",\"microphone\":" << std::boolalpha << microphone;
json << "}";
}
@@ -528,7 +533,7 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
{
auto session = async_session.get();
if (session)
next_scene = stream::create(std::move(session), show_performance_metrics);
next_scene = stream::create(std::move(session), show_performance_metrics, microphone);
async_session.reset();
}
+1
View File
@@ -113,6 +113,7 @@ class lobby : public scene_impl<lobby>
float preferred_refresh_rate = 0;
bool show_performance_metrics = false;
bool microphone = false;
void gui_connecting();
void gui_server_list();
+31
View File
@@ -29,6 +29,10 @@
#include <spdlog/fmt/fmt.h>
#include <utils/strings.h>
#ifdef __ANDROID__
#include "jnipp.h"
#endif
#include "IconsFontAwesome6.h"
static void CenterTextH(const std::string& text)
@@ -352,6 +356,33 @@ void scenes::lobby::gui_settings()
}
}
if (ImGui::Checkbox("Enable microphone", &microphone))
{
#ifdef __ANDROID__
if (microphone)
{
jni::object<""> act(application::native_app()->activity->clazz);
auto app = act.call<jni::object<"android/app/Application">>("getApplication");
auto ctx = app.call<jni::object<"android/content/Context">>("getApplicationContext");
jni::string permission("android.permission.RECORD_AUDIO");
auto result = ctx.call<jni::Int>("checkSelfPermission", permission);
if (result != 0 /*PERMISSION_GRANTED*/)
{
spdlog::info("RECORD_AUDIO permission not granted, requesting it");
jni::array permissions(permission);
act.call<void>("requestPermissions", permissions, jni::Int(0));
}
else
{
spdlog::info("RECORD_AUDIO permission already granted");
}
}
#endif
save_config();
}
vibrate_on_hover();
if (ImGui::Checkbox("Show performance metrics", &show_performance_metrics))
save_config();
vibrate_on_hover();
+3 -1
View File
@@ -74,7 +74,7 @@ static const std::array supported_formats =
vk::Format::eB8G8R8A8Srgb
};
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, bool show_performance_metrics)
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, bool show_performance_metrics, bool enable_microphone)
{
std::shared_ptr<stream> self{new stream};
spdlog::info("decoder_mutex.native_handle() = {}", (void*)self->decoder_mutex.native_handle());
@@ -112,6 +112,8 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.hand_tracking = application::get_hand_tracking_supported();
audio::get_audio_description(info);
if (not enable_microphone)
info.microphone = {};
self->network_session->send_control(info);
+1 -1
View File
@@ -117,7 +117,7 @@ private:
public:
~stream();
static std::shared_ptr<stream> create(std::unique_ptr<wivrn_session> session, bool show_performance_metrics);
static std::shared_ptr<stream> create(std::unique_ptr<wivrn_session> session, bool show_performance_metrics, bool enable_microphone);
void render(XrTime predicted_display_time, bool should_render) override;
void on_focused() override;