From 0d74452783422a1733616b81ca84d0c3f16e96a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:03:54 +0000 Subject: [PATCH 1/9] build(deps): bump code/mobile/android/PhoneVR/ALVR Bumps [code/mobile/android/PhoneVR/ALVR](https://github.com/PhoneVR-Developers/ALVR-phonevr) from `1d121fa` to `bff1789`. - [Commits](https://github.com/PhoneVR-Developers/ALVR-phonevr/compare/1d121fa7e0761ef26473c6b3f3fbd9b6051ce033...bff1789183eaf6266a774d9054411893d7b23a82) --- updated-dependencies: - dependency-name: code/mobile/android/PhoneVR/ALVR dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- code/mobile/android/PhoneVR/ALVR | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/mobile/android/PhoneVR/ALVR b/code/mobile/android/PhoneVR/ALVR index 1d121fa7..bff17891 160000 --- a/code/mobile/android/PhoneVR/ALVR +++ b/code/mobile/android/PhoneVR/ALVR @@ -1 +1 @@ -Subproject commit 1d121fa7e0761ef26473c6b3f3fbd9b6051ce033 +Subproject commit bff1789183eaf6266a774d9054411893d7b23a82 From 6cf436bf447701e921498c67799748456518a98e Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Mon, 9 Dec 2024 07:13:15 +0530 Subject: [PATCH 2/9] Update ALVR to latest master --- code/mobile/android/PhoneVR/ALVR | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/mobile/android/PhoneVR/ALVR b/code/mobile/android/PhoneVR/ALVR index bff17891..32965375 160000 --- a/code/mobile/android/PhoneVR/ALVR +++ b/code/mobile/android/PhoneVR/ALVR @@ -1 +1 @@ -Subproject commit bff1789183eaf6266a774d9054411893d7b23a82 +Subproject commit 3296537507bc06002cb9edbc6e4b82966e296071 From e5d03a74d60a4152b65de0a3030cbf4e5ac32b18 Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Mon, 9 Dec 2024 07:14:13 +0530 Subject: [PATCH 3/9] fix: gradle using cached jni_libs even when new libs are available --- code/mobile/android/PhoneVR/app/build.gradle | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/mobile/android/PhoneVR/app/build.gradle b/code/mobile/android/PhoneVR/app/build.gradle index 399bcf30..36b9f363 100644 --- a/code/mobile/android/PhoneVR/app/build.gradle +++ b/code/mobile/android/PhoneVR/app/build.gradle @@ -207,14 +207,21 @@ task deleteNdk(type: Delete) { delete "../ALVR/target/" } +task deleteGradleJniCache(type: Delete) +{ + // delete merged_jni_libs + delete "build/intermediates/merged_jni_libs" +} + task buildClientLib { + dependsOn deleteGradleJniCache doLast { exec { workingDir '../ALVR' if(defaultALVRFlavour.length() > 0) - commandLine 'cargo', 'xtask', 'build-client-lib', '--no-stdcpp', defaultALVRFlavour + commandLine 'cargo', 'xtask', 'build-client-lib', '--all-targets', '--no-stdcpp', defaultALVRFlavour else - commandLine 'cargo', 'xtask', 'build-client-lib', '--no-stdcpp' + commandLine 'cargo', 'xtask', 'build-client-lib', '--all-targets', '--no-stdcpp' } } } From 968df01755b8ccf6c47264e5fa2a8a9948de46e1 Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Mon, 9 Dec 2024 07:14:33 +0530 Subject: [PATCH 4/9] init update --- .../PhoneVR/app/src/main/AndroidManifest.xml | 1 + .../PhoneVR/app/src/main/cpp/alvr_main.cpp | 114 ++++++++++++------ .../android/PhoneVR/app/src/main/cpp/utils.h | 4 +- 3 files changed, 78 insertions(+), 41 deletions(-) diff --git a/code/mobile/android/PhoneVR/app/src/main/AndroidManifest.xml b/code/mobile/android/PhoneVR/app/src/main/AndroidManifest.xml index c193327f..cec5caaf 100644 --- a/code/mobile/android/PhoneVR/app/src/main/AndroidManifest.xml +++ b/code/mobile/android/PhoneVR/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + NewGlobalRef(obj); @@ -170,12 +188,12 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia alvr_initialize_android_context((void *) CTX.javaVm, (void *) CTX.javaContext); + alvr_initialize_logging(); float refreshRatesBuffer[1] = {refreshRate}; AlvrClientCapabilities caps = {}; caps.default_view_height = viewHeight; caps.default_view_width = viewWidth; - caps.external_decoder = false; caps.refresh_rates = refreshRatesBuffer; caps.refresh_rates_count = 1; caps.foveated_encoding = @@ -190,9 +208,14 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia CTX.headTracker = CardboardHeadTracker_create(); } +void initialize_decoder(AlvrDecoderConfig config) { + alvr_create_decoder(config); +} + extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_destroyNative(JNIEnv *, jobject) { alvr_destroy_opengl(); + alvr_destroy_decoder(); alvr_destroy(); CardboardHeadTracker_destroy(CTX.headTracker); @@ -328,18 +351,18 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); GL(glTexImage2D(GL_TEXTURE_2D, 0, - GL_RGB, + GL_RGBA8, CTX.screenWidth / 2, CTX.screenHeight, 0, - GL_RGB, + GL_RGBA, GL_UNSIGNED_BYTE, nullptr)); } const uint32_t *targetViews[2] = {(uint32_t *) &CTX.lobbyTextures[0], (uint32_t *) &CTX.lobbyTextures[1]}; - alvr_resume_opengl(CTX.screenWidth / 2, CTX.screenHeight, targetViews, 1, true); + alvr_resume_opengl(CTX.screenWidth / 2, CTX.screenHeight, targetViews, 1); CTX.renderingParamsChanged = false; CTX.glContextRecreated = false; @@ -360,7 +383,7 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render if (event.tag == ALVR_EVENT_STREAMING_STARTED) { info("ALVR Poll Event: ALVR_EVENT_STREAMING_STARTED, generating and binding " "textures..."); - auto config = event.STREAMING_STARTED; + CTX.StreamingConfig = event.STREAMING_STARTED; auto settings_len = alvr_get_settings_json(nullptr); auto settings_buffer = std::vector(settings_len); @@ -382,8 +405,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, - config.view_width, - config.view_height, + CTX.StreamingConfig.view_width, + CTX.StreamingConfig.view_height, 0, GL_RGB, GL_UNSIGNED_BYTE, @@ -400,13 +423,22 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render const uint32_t *textureHandles[2] = {&leftIntHandle, &rightIntHandle}; auto render_config = AlvrStreamConfig{}; - render_config.view_resolution_width = config.view_width; - render_config.view_resolution_height = config.view_height; + render_config.view_resolution_width = CTX.StreamingConfig.view_width; + render_config.view_resolution_height = CTX.StreamingConfig.view_height; render_config.swapchain_textures = textureHandles; render_config.swapchain_length = 1; render_config.enable_foveation = false; if (!settings_json["video"].is_null()) { + CTX.decoderConfig.force_software_decoder = settings_json["video"]["force_software_decoder"]; + CTX.decoderConfig.buffering_history_weight = settings_json["video"]["buffering_history_weight"]; + CTX.decoderConfig.max_buffering_frames = settings_json["video"]["max_buffering_frames"]; + + info("settings_json[video][force_software_decoder] is %s ", settings_json["video"]["force_software_decoder"].dump().c_str()); + info("settings_json[video][buffering_history_weight] is %s ", settings_json["video"]["buffering_history_weight"].dump().c_str()); + info("settings_json[video][max_buffering_frames] is %s ", settings_json["video"]["max_buffering_frames"].dump().c_str()); + info( "settings_json[video][mediacodec_extra_options] is %s ", settings_json["video"]["mediacodec_extra_options"].dump().c_str()); + if (!settings_json["video"]["foveated_encoding"].is_null()) { info("settings_json.video.foveated_encoding is %s", settings_json["video"]["foveated_encoding"].dump().c_str()); @@ -471,6 +503,10 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render GL(glDeleteTextures(2, CTX.streamTextures)); info("ALVR Poll Event: ALVR_EVENT_STREAMING_STOPPED, Stream stopped deleted " "textures."); + } else if (event.tag == ALVR_EVENT_DECODER_CONFIG) { + info("ALVR Poll Event: ALVR_EVENT_DECODER_CONFIG, "); + CTX.decoderConfig.codec = event.DECODER_CONFIG.codec; + initialize_decoder(CTX.decoderConfig); } } @@ -485,43 +521,41 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render if (CTX.streaming) { void *streamHardwareBuffer = nullptr; - AlvrViewParams dummyViewParams; - auto timestampNs = alvr_get_frame(&dummyViewParams, &streamHardwareBuffer); + uint64_t timestampNs; + alvr_get_frame(×tampNs, &streamHardwareBuffer); - if (timestampNs == -1) { - return; - } + const AlvrStreamViewParams viewParams[2] = { + {0, getReprojectionRotationDelta(), CTX.fovArr[kLeft]}, + {0, getReprojectionRotationDelta(), CTX.fovArr[kRight]}, + }; - uint32_t swapchainIndices[2] = {0, 0}; - alvr_render_stream_opengl(streamHardwareBuffer, swapchainIndices); + alvr_render_stream_opengl(streamHardwareBuffer, viewParams); alvr_report_submit(timestampNs, 0); viewsDescs[0].texture = CTX.streamTextures[0]; viewsDescs[1].texture = CTX.streamTextures[1]; } else { + info("Getting pose for Rendering Lobby..."); AlvrPose pose = getPose(GetBootTimeNano() + VSYNC_QUEUE_INTERVAL_NS); - AlvrViewInput viewInputs[2] = {}; + AlvrLobbyViewParams viewInputs[2] = {}; for (int eye = 0; eye < 2; eye++) { float headToEye[3] = {CTX.eyeOffsets[eye], 0.0, 0.0}; // offset head pos to Eye Position offsetPosWithQuat(pose.orientation, headToEye, viewInputs[eye].pose.position); + viewInputs[eye].swapchain_index = 0; viewInputs[eye].pose.orientation = pose.orientation; viewInputs[eye].fov = getFov((CardboardEye) eye); - viewInputs[eye].swapchain_index = 0; } - alvr_render_lobby_opengl(viewInputs); + info("Rendering Lobby..."); + alvr_render_lobby_opengl(viewInputs, true); viewsDescs[0].texture = CTX.lobbyTextures[0]; viewsDescs[1].texture = CTX.lobbyTextures[1]; } - // Note: the Cardboard SDK does not support reprojection! - // todo: manually implement it? - - // info("nativeRendered: Rendering to Display..."); CardboardDistortionRenderer_renderEyeToDisplay(CTX.distortionRenderer, 0, 0, @@ -530,6 +564,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render CTX.screenHeight, &viewsDescs[0], &viewsDescs[1]); + + info("nativeRendered: Rendered to Display"); } catch (const json::exception &e) { error(std::string(std::string(__FUNCTION__) + std::string(__FILE_NAME__) + std::string(e.what())) diff --git a/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h b/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h index bc31f22b..e0a10877 100644 --- a/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h +++ b/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h @@ -34,7 +34,7 @@ void log(AlvrLogLevel level, alvr_log(level, buf); - switch (level) { + /*switch (level) { case ALVR_LOG_LEVEL_DEBUG: __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s", buf); break; @@ -47,7 +47,7 @@ void log(AlvrLogLevel level, case ALVR_LOG_LEVEL_WARN: __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "%s", buf); break; - } + }*/ va_end(args); } From 5627e7a3576686b8451ccc84eeac3c1186d82772 Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Mon, 9 Dec 2024 07:19:22 +0530 Subject: [PATCH 5/9] fix lint --- .../PhoneVR/app/src/main/cpp/alvr_main.cpp | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp b/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp index ee3765aa..3edbf4ad 100644 --- a/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp +++ b/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp @@ -49,7 +49,10 @@ struct NativeContext { AlvrDeviceMotion deviceMotion = {}; AlvrQuat recentReprojectionRotation = { - 0, 0, 0, 0, + 0, + 0, + 0, + 0, }; // ALVR StreamingStarted event's config @@ -140,16 +143,16 @@ void updateViewConfigs(uint64_t targetTimestampNs = 0) { CTX.deviceMotion.device_id = HEAD_ID; CTX.deviceMotion.pose = headPose; -// float headToEye[3] = {CTX.eyeOffsets[kLeft], 0.0, 0.0}; -// -// CTX.viewParams[kLeft].pose = headPose; -// offsetPosWithQuat(headPose.orientation, headToEye, CTX.viewParams[kLeft].pose.position); -// CTX.viewParams[kLeft].fov = CTX.fovArr[kLeft]; -// -// headToEye[0] = CTX.eyeOffsets[kRight]; -// CTX.viewParams[kRight].pose = headPose; -// offsetPosWithQuat(headPose.orientation, headToEye, CTX.viewParams[kRight].pose.position); -// CTX.viewParams[kRight].fov = CTX.fovArr[kRight]; + // float headToEye[3] = {CTX.eyeOffsets[kLeft], 0.0, 0.0}; + // + // CTX.viewParams[kLeft].pose = headPose; + // offsetPosWithQuat(headPose.orientation, headToEye, CTX.viewParams[kLeft].pose.position); + // CTX.viewParams[kLeft].fov = CTX.fovArr[kLeft]; + // + // headToEye[0] = CTX.eyeOffsets[kRight]; + // CTX.viewParams[kRight].pose = headPose; + // offsetPosWithQuat(headPose.orientation, headToEye, CTX.viewParams[kRight].pose.position); + // CTX.viewParams[kRight].fov = CTX.fovArr[kRight]; } void inputThread() { @@ -161,9 +164,9 @@ void inputThread() { auto targetTimestampNs = GetBootTimeNano(); updateViewConfigs(targetTimestampNs); - memcpy(&CTX.recentReprojectionRotation, &CTX.deviceMotion.pose.orientation, sizeof(AlvrQuat)); - alvr_send_tracking( - targetTimestampNs, &CTX.deviceMotion, 1, nullptr, nullptr); + memcpy( + &CTX.recentReprojectionRotation, &CTX.deviceMotion.pose.orientation, sizeof(AlvrQuat)); + alvr_send_tracking(targetTimestampNs, &CTX.deviceMotion, 1, nullptr, nullptr); deadline += std::chrono::nanoseconds((uint64_t) (1e9 / 60.f / 3)); std::this_thread::sleep_until(deadline); @@ -208,9 +211,7 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia CTX.headTracker = CardboardHeadTracker_create(); } -void initialize_decoder(AlvrDecoderConfig config) { - alvr_create_decoder(config); -} +void initialize_decoder(AlvrDecoderConfig config) { alvr_create_decoder(config); } extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_destroyNative(JNIEnv *, jobject) { @@ -430,14 +431,21 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render render_config.enable_foveation = false; if (!settings_json["video"].is_null()) { - CTX.decoderConfig.force_software_decoder = settings_json["video"]["force_software_decoder"]; - CTX.decoderConfig.buffering_history_weight = settings_json["video"]["buffering_history_weight"]; - CTX.decoderConfig.max_buffering_frames = settings_json["video"]["max_buffering_frames"]; - - info("settings_json[video][force_software_decoder] is %s ", settings_json["video"]["force_software_decoder"].dump().c_str()); - info("settings_json[video][buffering_history_weight] is %s ", settings_json["video"]["buffering_history_weight"].dump().c_str()); - info("settings_json[video][max_buffering_frames] is %s ", settings_json["video"]["max_buffering_frames"].dump().c_str()); - info( "settings_json[video][mediacodec_extra_options] is %s ", settings_json["video"]["mediacodec_extra_options"].dump().c_str()); + CTX.decoderConfig.force_software_decoder = + settings_json["video"]["force_software_decoder"]; + CTX.decoderConfig.buffering_history_weight = + settings_json["video"]["buffering_history_weight"]; + CTX.decoderConfig.max_buffering_frames = + settings_json["video"]["max_buffering_frames"]; + + info("settings_json[video][force_software_decoder] is %s ", + settings_json["video"]["force_software_decoder"].dump().c_str()); + info("settings_json[video][buffering_history_weight] is %s ", + settings_json["video"]["buffering_history_weight"].dump().c_str()); + info("settings_json[video][max_buffering_frames] is %s ", + settings_json["video"]["max_buffering_frames"].dump().c_str()); + info("settings_json[video][mediacodec_extra_options] is %s ", + settings_json["video"]["mediacodec_extra_options"].dump().c_str()); if (!settings_json["video"]["foveated_encoding"].is_null()) { info("settings_json.video.foveated_encoding is %s", From 2ad8735a72d41f0a42b968bd041b54f0fa821874 Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Tue, 10 Dec 2024 07:14:39 +0530 Subject: [PATCH 6/9] wip --- .../PhoneVR/app/src/main/cpp/alvr_main.cpp | 108 ++++++++++++------ .../android/PhoneVR/app/src/main/cpp/utils.h | 48 +++++--- 2 files changed, 107 insertions(+), 49 deletions(-) diff --git a/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp b/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp index 3edbf4ad..3fcccd2a 100644 --- a/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp +++ b/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp @@ -1,5 +1,6 @@ #include "alvr_client_core.h" #include "cardboard.h" +#include #include #include #include @@ -44,26 +45,34 @@ struct NativeContext { GLuint lobbyTextures[2] = {0, 0}; GLuint streamTextures[2] = {0, 0}; + EGLContext eglCurrentContext = nullptr; + EGLSurface eglCurrentDrawSurface = nullptr; + EGLSurface eglCurrentReadSurface = nullptr; + EGLDisplay eglCurrentDisplay = nullptr; + bool cachedEglConfig = false; + float eyeOffsets[2] = {0.0, 0.0}; AlvrFov fovArr[2] = {}; + AlvrViewParams viewParams[2] = {}; AlvrDeviceMotion deviceMotion = {}; AlvrQuat recentReprojectionRotation = { 0, 0, 0, - 0, + 1, }; // ALVR StreamingStarted event's config - StreamingStarted_Body StreamingConfig; + StreamingStarted_Body streamingConfig; AlvrDecoderConfig decoderConfig; NativeContext() { - memset(&fovArr, 0, (sizeof(fovArr)) / sizeof(int)); - memset(&deviceMotion, 0, (sizeof(deviceMotion)) / sizeof(int)); - memset(&StreamingConfig, 0, sizeof(StreamingConfig)); + memset(&fovArr, 0, sizeof(fovArr)); + memset(&deviceMotion, 0, sizeof(deviceMotion)); + memset(&streamingConfig, 0, sizeof(streamingConfig)); memset(&decoderConfig, 0, sizeof(decoderConfig)); + memset(&viewParams, 0, sizeof(viewParams)); } }; @@ -134,7 +143,7 @@ AlvrPose getPose(uint64_t timestampNs = 0) { return pose; } -void updateViewConfigs(uint64_t targetTimestampNs = 0) { +void updateHeadPose(uint64_t targetTimestampNs = 0) { if (!targetTimestampNs) targetTimestampNs = GetBootTimeNano(); @@ -142,17 +151,23 @@ void updateViewConfigs(uint64_t targetTimestampNs = 0) { CTX.deviceMotion.device_id = HEAD_ID; CTX.deviceMotion.pose = headPose; +} - // float headToEye[3] = {CTX.eyeOffsets[kLeft], 0.0, 0.0}; - // - // CTX.viewParams[kLeft].pose = headPose; - // offsetPosWithQuat(headPose.orientation, headToEye, CTX.viewParams[kLeft].pose.position); - // CTX.viewParams[kLeft].fov = CTX.fovArr[kLeft]; - // - // headToEye[0] = CTX.eyeOffsets[kRight]; - // CTX.viewParams[kRight].pose = headPose; - // offsetPosWithQuat(headPose.orientation, headToEye, CTX.viewParams[kRight].pose.position); - // CTX.viewParams[kRight].fov = CTX.fovArr[kRight]; +void updateViewConfigs(uint64_t targetTimestampNs = 0) { + updateHeadPose(targetTimestampNs); + + float headToEye[3] = {CTX.eyeOffsets[kLeft], 0.0, 0.0}; + + CTX.viewParams[kLeft].pose = CTX.deviceMotion.pose; + offsetPosWithQuat( + CTX.deviceMotion.pose.orientation, headToEye, CTX.viewParams[kLeft].pose.position); + CTX.viewParams[kLeft].fov = CTX.fovArr[kLeft]; + + headToEye[0] = CTX.eyeOffsets[kRight]; + CTX.viewParams[kRight].pose = CTX.deviceMotion.pose; + offsetPosWithQuat( + CTX.deviceMotion.pose.orientation, headToEye, CTX.viewParams[kRight].pose.position); + CTX.viewParams[kRight].fov = CTX.fovArr[kRight]; } void inputThread() { @@ -162,12 +177,13 @@ void inputThread() { while (CTX.streaming) { auto targetTimestampNs = GetBootTimeNano(); - updateViewConfigs(targetTimestampNs); + updateHeadPose(targetTimestampNs); memcpy( &CTX.recentReprojectionRotation, &CTX.deviceMotion.pose.orientation, sizeof(AlvrQuat)); alvr_send_tracking(targetTimestampNs, &CTX.deviceMotion, 1, nullptr, nullptr); + // Todo: Adapt to the Screen's framerate not 60 deadline += std::chrono::nanoseconds((uint64_t) (1e9 / 60.f / 3)); std::this_thread::sleep_until(deadline); } @@ -213,9 +229,28 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia void initialize_decoder(AlvrDecoderConfig config) { alvr_create_decoder(config); } +void makeGLContextCurrent() { + if (!CTX.cachedEglConfig) { + CTX.eglCurrentContext = eglGetCurrentContext(); + CTX.eglCurrentDrawSurface = eglGetCurrentSurface(EGL_DRAW); + CTX.eglCurrentDisplay = eglGetCurrentDisplay(); + CTX.eglCurrentReadSurface = eglGetCurrentSurface(EGL_READ); + CTX.cachedEglConfig = true; + } + + if (!eglMakeCurrent(CTX.eglCurrentDisplay, + CTX.eglCurrentDrawSurface, + CTX.eglCurrentReadSurface, + CTX.eglCurrentContext)) { + error("eglMakeCurrent() returned error %s", eglGetErrorString()); + } +} + extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_destroyNative(JNIEnv *, jobject) { - alvr_destroy_opengl(); + EGL_MAKE_CURRENT(alvr_destroy_opengl()); + CTX.cachedEglConfig = false; + alvr_destroy_decoder(); alvr_destroy(); @@ -259,7 +294,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_pauseN extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_surfaceCreatedNative(JNIEnv *, jobject) { - alvr_initialize_opengl(); + + EGL_MAKE_CURRENT(alvr_initialize_opengl()); CTX.glContextRecreated = true; } @@ -325,14 +361,15 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render CTX.fovArr[kLeft] = getFov(kLeft); CTX.fovArr[kRight] = getFov(kRight); + updateViewConfigs(); info("renderingParamsChanged, updating new view configs (FOV) to alvr"); - // alvr_send_views_config(fovArr, CTX.eyeOffsets[0] - CTX.eyeOffsets[1]); + alvr_send_view_params(CTX.viewParams); } // Note: if GL context is recreated, old resources are already freed. if (CTX.renderingParamsChanged && !CTX.glContextRecreated) { info("Pausing ALVR since glContext is not recreated, deleting textures"); - alvr_pause_opengl(); + EGL_MAKE_CURRENT(alvr_pause_opengl()); GL(glDeleteTextures(2, CTX.lobbyTextures)); } @@ -363,7 +400,9 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render const uint32_t *targetViews[2] = {(uint32_t *) &CTX.lobbyTextures[0], (uint32_t *) &CTX.lobbyTextures[1]}; - alvr_resume_opengl(CTX.screenWidth / 2, CTX.screenHeight, targetViews, 1); + + EGL_MAKE_CURRENT( + alvr_resume_opengl(CTX.screenWidth / 2, CTX.screenHeight, targetViews, 1)); CTX.renderingParamsChanged = false; CTX.glContextRecreated = false; @@ -378,13 +417,14 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render alvr_hud_message(&message_buffer[0]); info("ALVR Poll Event: HUD Message Update - %s", &message_buffer[0]); - if (message_length > 0) - alvr_update_hud_message_opengl(&message_buffer[0]); + if (message_length > 0) { + EGL_MAKE_CURRENT(alvr_update_hud_message_opengl(&message_buffer[0])); + } } if (event.tag == ALVR_EVENT_STREAMING_STARTED) { info("ALVR Poll Event: ALVR_EVENT_STREAMING_STARTED, generating and binding " "textures..."); - CTX.StreamingConfig = event.STREAMING_STARTED; + CTX.streamingConfig = event.STREAMING_STARTED; auto settings_len = alvr_get_settings_json(nullptr); auto settings_buffer = std::vector(settings_len); @@ -406,8 +446,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, - CTX.StreamingConfig.view_width, - CTX.StreamingConfig.view_height, + CTX.streamingConfig.view_width, + CTX.streamingConfig.view_height, 0, GL_RGB, GL_UNSIGNED_BYTE, @@ -424,8 +464,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render const uint32_t *textureHandles[2] = {&leftIntHandle, &rightIntHandle}; auto render_config = AlvrStreamConfig{}; - render_config.view_resolution_width = CTX.StreamingConfig.view_width; - render_config.view_resolution_height = CTX.StreamingConfig.view_height; + render_config.view_resolution_width = CTX.streamingConfig.view_width; + render_config.view_resolution_height = CTX.streamingConfig.view_height; render_config.swapchain_textures = textureHandles; render_config.swapchain_length = 1; @@ -494,7 +534,7 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render info("render_config.foveation_edge_ratio_y: %f", render_config.foveation_edge_ratio_y); - alvr_start_stream_opengl(render_config); + EGL_MAKE_CURRENT(alvr_start_stream_opengl(render_config)); info("ALVR Poll Event: ALVR_EVENT_STREAMING_STARTED, opengl stream started and " "input " @@ -532,12 +572,12 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render uint64_t timestampNs; alvr_get_frame(×tampNs, &streamHardwareBuffer); - const AlvrStreamViewParams viewParams[2] = { + const AlvrStreamViewParams streamViewParams[2] = { {0, getReprojectionRotationDelta(), CTX.fovArr[kLeft]}, {0, getReprojectionRotationDelta(), CTX.fovArr[kRight]}, }; - alvr_render_stream_opengl(streamHardwareBuffer, viewParams); + EGL_MAKE_CURRENT(alvr_render_stream_opengl(streamHardwareBuffer, streamViewParams)); alvr_report_submit(timestampNs, 0); @@ -558,7 +598,7 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render viewInputs[eye].fov = getFov((CardboardEye) eye); } info("Rendering Lobby..."); - alvr_render_lobby_opengl(viewInputs, true); + EGL_MAKE_CURRENT(alvr_render_lobby_opengl(viewInputs, true)); viewsDescs[0].texture = CTX.lobbyTextures[0]; viewsDescs[1].texture = CTX.lobbyTextures[1]; @@ -573,7 +613,7 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render &viewsDescs[0], &viewsDescs[1]); - info("nativeRendered: Rendered to Display"); + info("Rendered to Display"); } catch (const json::exception &e) { error(std::string(std::string(__FUNCTION__) + std::string(__FILE_NAME__) + std::string(e.what())) diff --git a/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h b/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h index e0a10877..e10af66b 100644 --- a/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h +++ b/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h @@ -34,21 +34,6 @@ void log(AlvrLogLevel level, alvr_log(level, buf); - /*switch (level) { - case ALVR_LOG_LEVEL_DEBUG: - __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s", buf); - break; - case ALVR_LOG_LEVEL_INFO: - __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "%s", buf); - break; - case ALVR_LOG_LEVEL_ERROR: - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", buf); - break; - case ALVR_LOG_LEVEL_WARN: - __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "%s", buf); - break; - }*/ - va_end(args); } @@ -87,4 +72,37 @@ static const char *GlErrorString(GLenum error) { func; \ GLCheckErrors(__FILE__, __LINE__) +#define CASE_STR(value) \ + case value: \ + return #value; +const char *eglGetErrorString() { + EGLint error = eglGetError(); + switch (error) { + CASE_STR(EGL_SUCCESS) + CASE_STR(EGL_NOT_INITIALIZED) + CASE_STR(EGL_BAD_ACCESS) + CASE_STR(EGL_BAD_ALLOC) + CASE_STR(EGL_BAD_ATTRIBUTE) + CASE_STR(EGL_BAD_CONTEXT) + CASE_STR(EGL_BAD_CONFIG) + CASE_STR(EGL_BAD_CURRENT_SURFACE) + CASE_STR(EGL_BAD_DISPLAY) + CASE_STR(EGL_BAD_SURFACE) + CASE_STR(EGL_BAD_MATCH) + CASE_STR(EGL_BAD_PARAMETER) + CASE_STR(EGL_BAD_NATIVE_PIXMAP) + CASE_STR(EGL_BAD_NATIVE_WINDOW) + CASE_STR(EGL_CONTEXT_LOST) + default: + return "Unknown"; + } +} +#undef CASE_STR + +void makeGLContextCurrent(); + +#define EGL_MAKE_CURRENT(func) \ + func; \ + makeGLContextCurrent() + #endif // PHONEVR_UTILS_H From 5113523c25a2ff1d600d29ad8734bac18d326f8b Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Wed, 11 Dec 2024 06:14:39 +0530 Subject: [PATCH 7/9] try using alvr-org/PR 2567 --- code/mobile/android/PhoneVR/ALVR | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/mobile/android/PhoneVR/ALVR b/code/mobile/android/PhoneVR/ALVR index 32965375..938ccba1 160000 --- a/code/mobile/android/PhoneVR/ALVR +++ b/code/mobile/android/PhoneVR/ALVR @@ -1 +1 @@ -Subproject commit 3296537507bc06002cb9edbc6e4b82966e296071 +Subproject commit 938ccba1186e957142a06687b2275b7c15ed9d9a From 7215104aa770bbbb585eac3e7e734bcca9bc1656 Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Wed, 11 Dec 2024 06:14:50 +0530 Subject: [PATCH 8/9] Update gradle --- .../android/PhoneVR/gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/mobile/android/PhoneVR/gradle/wrapper/gradle-wrapper.properties b/code/mobile/android/PhoneVR/gradle/wrapper/gradle-wrapper.properties index 5ef3a45b..adc0d415 100644 --- a/code/mobile/android/PhoneVR/gradle/wrapper/gradle-wrapper.properties +++ b/code/mobile/android/PhoneVR/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Apr 25 03:20:28 IST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 2a2ecf5ee9a8e49e35fcdaeb97b9488e0eb135fb Mon Sep 17 00:00:00 2001 From: Harsha Raghu Date: Wed, 11 Dec 2024 06:15:08 +0530 Subject: [PATCH 9/9] wip 2 --- .../android/PhoneVR/app/src/main/cpp/alvr_main.cpp | 11 +++++------ code/mobile/android/PhoneVR/app/src/main/cpp/utils.h | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp b/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp index 3fcccd2a..8a9f983d 100644 --- a/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp +++ b/code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp @@ -238,12 +238,11 @@ void makeGLContextCurrent() { CTX.cachedEglConfig = true; } - if (!eglMakeCurrent(CTX.eglCurrentDisplay, - CTX.eglCurrentDrawSurface, - CTX.eglCurrentReadSurface, - CTX.eglCurrentContext)) { - error("eglMakeCurrent() returned error %s", eglGetErrorString()); - } + GL(eglMakeCurrent(CTX.eglCurrentDisplay, + CTX.eglCurrentDrawSurface, + CTX.eglCurrentReadSurface, + CTX.eglCurrentContext)); + info("eglMakeCurrent() returned error %s", eglGetErrorString()); } extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_destroyNative(JNIEnv *, diff --git a/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h b/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h index e10af66b..0830329e 100644 --- a/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h +++ b/code/mobile/android/PhoneVR/app/src/main/cpp/utils.h @@ -101,8 +101,7 @@ const char *eglGetErrorString() { void makeGLContextCurrent(); -#define EGL_MAKE_CURRENT(func) \ - func; \ - makeGLContextCurrent() +#define EGL_MAKE_CURRENT(func) func; +// makeGLContextCurrent() #endif // PHONEVR_UTILS_H