From bdf4424de6d3fe0654bd092a986371fc5ee49099 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 17 Oct 2023 16:40:03 -0500 Subject: [PATCH 01/16] No need to clear logcat to setup tunnel --- client/setup-tunnel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/setup-tunnel.sh b/client/setup-tunnel.sh index 2424c08a..0e406666 100755 --- a/client/setup-tunnel.sh +++ b/client/setup-tunnel.sh @@ -8,6 +8,6 @@ set -x set -e -adb logcat -c +# adb logcat -c adb reverse tcp:61943 tcp:61943 adb reverse tcp:8080 tcp:8080 From 66a6ea4825869cabcabdf40e645cf5bb36a4699c Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 17 Oct 2023 16:50:40 -0500 Subject: [PATCH 02/16] Be sure that ws_cancel is actually there. --- client/src/em/em_connection.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/em/em_connection.c b/client/src/em/em_connection.c index e4c4b315..dca86531 100644 --- a/client/src/em/em_connection.c +++ b/client/src/em/em_connection.c @@ -616,7 +616,9 @@ static void emconn_connect_internal(EmConnection *emconn, enum em_status status) { em_connection_disconnect(emconn); - + if (!emconn->ws_cancel) { + emconn->ws_cancel = g_cancellable_new(); + } g_cancellable_reset(emconn->ws_cancel); ALOGI("RYLIE: calling soup_session_websocket_connect_async. websocket_uri = %s", emconn->websocket_uri); #if SOUP_MAJOR_VERSION == 2 From 4a78724af4ef5c2697d292aef9eb4129d69d020a Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 17 Oct 2023 17:03:31 -0500 Subject: [PATCH 03/16] Do not update the connection state from the deep notify callback. It lies. --- client/src/em/em_connection.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/em/em_connection.c b/client/src/em/em_connection.c index dca86531..15637a50 100644 --- a/client/src/em/em_connection.c +++ b/client/src/em/em_connection.c @@ -340,8 +340,9 @@ emconn_webrtc_deep_notify_callback(GstObject *self, GstObject *prop_object, GPar { GstWebRTCPeerConnectionState state; g_object_get(prop_object, "connection-state", &state, NULL); - ALOGI("RYLIE: deep-notify callback says peer connection state is %s", peer_connection_state_to_string(state)); - emconn_update_status_from_peer_connection_state(emconn, state); + ALOGV("RYLIE: deep-notify callback says peer connection state is %s - but it lies sometimes", + peer_connection_state_to_string(state)); + // emconn_update_status_from_peer_connection_state(emconn, state); } static void From b673abe350cf52316fa99a788230d11dfeb4418e Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 17 Oct 2023 17:22:17 -0500 Subject: [PATCH 04/16] Set glib log domain --- server/src/ems/gst/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/ems/gst/CMakeLists.txt b/server/src/ems/gst/CMakeLists.txt index 2e512c30..383af5d7 100644 --- a/server/src/ems/gst/CMakeLists.txt +++ b/server/src/ems/gst/CMakeLists.txt @@ -26,3 +26,4 @@ target_include_directories( ${JSONGLIB_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ) +target_compile_definitions(ems_gst PUBLIC G_LOG_DOMAIN="ElectricMapleServer") From c5256b2cb322c5f81bb0300b267b73843d784fe3 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Mon, 29 Jan 2024 09:51:49 -0600 Subject: [PATCH 05/16] Improve logging on the server --- server/src/ems/ems_compositor.cpp | 2 +- server/src/ems/gst/ems_gstreamer_pipeline.c | 16 ++++++++-------- server/src/test/webrtc_client.c | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/src/ems/ems_compositor.cpp b/server/src/ems/ems_compositor.cpp index 08e5fe63..8613c864 100644 --- a/server/src/ems/ems_compositor.cpp +++ b/server/src/ems/ems_compositor.cpp @@ -233,7 +233,7 @@ compositor_init_vulkan(struct ems_compositor *c) // Init command pool. constexpr VkCommandPoolCreateFlags flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; - U_LOG_E("%s", vk_result_string(ret)); + // U_LOG_I("%s", vk_result_string(ret)); ret = vk_cmd_pool_init(vk, &c->cmd_pool, flags); if (ret != VK_SUCCESS) { EMS_COMP_ERROR(c, "vk_cmd_pool_init: %s", vk_result_string(ret)); diff --git a/server/src/ems/gst/ems_gstreamer_pipeline.c b/server/src/ems/gst/ems_gstreamer_pipeline.c index d8dc5618..00cc726d 100644 --- a/server/src/ems/gst/ems_gstreamer_pipeline.c +++ b/server/src/ems/gst/ems_gstreamer_pipeline.c @@ -171,7 +171,7 @@ on_offer_created(GstPromise *promise, GstElement *webrtcbin) static void webrtc_on_data_channel_cb(GstElement *webrtcbin, GObject *data_channel, struct ems_gstreamer_pipeline *egp) { - U_LOG_E("called!!!!"); + U_LOG_I("called!!!!"); } @@ -187,7 +187,7 @@ webrtc_on_ice_candidate_cb(GstElement *webrtcbin, guint mlineindex, gchar *candi static void data_channel_error_cb(GstWebRTCDataChannel *datachannel, struct ems_gstreamer_pipeline *egp) { - U_LOG_E("error\n"); + U_LOG_E("error"); } gboolean @@ -205,7 +205,7 @@ datachannel_send_message(GstWebRTCDataChannel *datachannel) static void data_channel_open_cb(GstWebRTCDataChannel *datachannel, struct ems_gstreamer_pipeline *egp) { - U_LOG_E("data channel opened\n"); + U_LOG_I("data channel opened"); egp->timeout_src_id = g_timeout_add_seconds(3, G_SOURCE_FUNC(datachannel_send_message), datachannel); } @@ -213,7 +213,7 @@ data_channel_open_cb(GstWebRTCDataChannel *datachannel, struct ems_gstreamer_pip static void data_channel_close_cb(GstWebRTCDataChannel *datachannel, struct ems_gstreamer_pipeline *egp) { - U_LOG_E("data channel closed\n"); + U_LOG_I("data channel closed"); g_clear_handle_id(&egp->timeout_src_id, g_source_remove); g_clear_object(&egp->data_channel); @@ -240,7 +240,7 @@ data_channel_message_data_cb(GstWebRTCDataChannel *datachannel, GBytes *data, st static void data_channel_message_string_cb(GstWebRTCDataChannel *datachannel, gchar *str, struct ems_gstreamer_pipeline *egp) { - U_LOG_E("Received data channel message: %s\n", str); + U_LOG_I("Received data channel message: %s\n", str); } @@ -277,7 +277,7 @@ webrtc_client_connected_cb(EmsSignalingServer *server, EmsClientId client_id, st U_LOG_E("Couldn't make datachannel!"); assert(false); } else { - U_LOG_E("Successfully created datachannel!"); + U_LOG_I("Successfully created datachannel!"); g_signal_connect(egp->data_channel, "on-open", G_CALLBACK(data_channel_open_cb), egp); g_signal_connect(egp->data_channel, "on-close", G_CALLBACK(data_channel_close_cb), egp); @@ -536,7 +536,7 @@ loop_thread(void *data) void ems_gstreamer_pipeline_play(struct gstreamer_pipeline *gp) { - U_LOG_E("Starting pipeline"); + U_LOG_I("Starting pipeline"); struct ems_gstreamer_pipeline *egp = (struct ems_gstreamer_pipeline *)gp; main_loop = g_main_loop_new(NULL, FALSE); @@ -556,7 +556,7 @@ void ems_gstreamer_pipeline_stop(struct gstreamer_pipeline *gp) { struct ems_gstreamer_pipeline *egp = (struct ems_gstreamer_pipeline *)gp; - U_LOG_E("Stopping pipeline"); + U_LOG_I("Stopping pipeline"); // Settle the pipeline. U_LOG_T("Sending EOS"); diff --git a/server/src/test/webrtc_client.c b/server/src/test/webrtc_client.c index 1e596423..e89739a1 100644 --- a/server/src/test/webrtc_client.c +++ b/server/src/test/webrtc_client.c @@ -49,7 +49,7 @@ data_channel_error_cb(GstWebRTCDataChannel *datachannel, void *data) static void data_channel_close_cb(GstWebRTCDataChannel *datachannel, gpointer timeout_src_id) { - U_LOG_E("Data channel closed"); + U_LOG_I("Data channel closed"); g_source_remove(GPOINTER_TO_UINT(timeout_src_id)); g_clear_object(&datachannel); @@ -58,13 +58,13 @@ data_channel_close_cb(GstWebRTCDataChannel *datachannel, gpointer timeout_src_id static void data_channel_message_data_cb(GstWebRTCDataChannel *datachannel, GBytes *data, void *user_data) { - U_LOG_E("Received data channel message data: %u", (uint32_t)g_bytes_get_size(data)); + U_LOG_I("Received data channel message data: %u", (uint32_t)g_bytes_get_size(data)); } static void data_channel_message_string_cb(GstWebRTCDataChannel *datachannel, gchar *str, void *user_data) { - U_LOG_E("Received data channel message string: %s", str); + U_LOG_I("Received data channel message string: %s", str); } static gboolean @@ -80,7 +80,7 @@ webrtc_on_data_channel_cb(GstElement *webrtcbin, GstWebRTCDataChannel *data_chan { guint timeout_src_id; - U_LOG_E("Successfully created datachannel"); + U_LOG_I("Successfully created datachannel"); g_assert_null(datachannel); From 0e0d08038c02d075c2644d798bca69b77790786a Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 7 Nov 2023 14:57:48 -0600 Subject: [PATCH 06/16] Install server --- server/src/ems/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/ems/CMakeLists.txt b/server/src/ems/CMakeLists.txt index 5ba7c547..a0ca847b 100644 --- a/server/src/ems/CMakeLists.txt +++ b/server/src/ems/CMakeLists.txt @@ -49,3 +49,5 @@ target_link_libraries( ) target_link_libraries(ems_streaming_server PRIVATE st_gui xrt-external-imgui-sdl2 aux_ogl) + +install(TARGETS ems_streaming_server RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) From 304d3fc724766aff583c1213b996fc1ed196db33 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 7 Nov 2023 14:57:59 -0600 Subject: [PATCH 07/16] Quiet client debug messages --- client/src/em/em_stream_client.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/src/em/em_stream_client.c b/client/src/em/em_stream_client.c index 8c3fe98a..28b7b2d6 100644 --- a/client/src/em/em_stream_client.c +++ b/client/src/em/em_stream_client.c @@ -51,7 +51,6 @@ struct em_sc_sample GstSample *sample; }; - struct _EmStreamClient { GMainLoop *loop; @@ -590,7 +589,6 @@ em_stream_client_try_pull_sample(EmStreamClient *sc, struct timespec *out_decode { if (!sc->appsink) { // not setup yet. - ALOGV("%s: no app sink yet, waiting for connection", __FUNCTION__); return NULL; } From 953590fdd7f2f3888458580640b22e4f60fd44ac Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 7 Nov 2023 15:01:21 -0600 Subject: [PATCH 08/16] Add C4 diagrams --- c4-system-context.drawio | 863 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 863 insertions(+) create mode 100644 c4-system-context.drawio diff --git a/c4-system-context.drawio b/c4-system-context.drawio new file mode 100644 index 00000000..6c4fe2e5 --- /dev/null +++ b/c4-system-context.drawio @@ -0,0 +1,863 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 255c372aa1532138339f4403b8ebeccc7076c975 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Mon, 20 Nov 2023 18:47:26 -0500 Subject: [PATCH 09/16] Gitignore the extracted deps --- client/deps/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 client/deps/.gitignore diff --git a/client/deps/.gitignore b/client/deps/.gitignore new file mode 100644 index 00000000..6cb211c5 --- /dev/null +++ b/client/deps/.gitignore @@ -0,0 +1,2 @@ +gstreamer_android +*.tar.xz From db9bfcc3bbd1d9e51fab8808c6cc2d061f46f5ce Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Wed, 20 Dec 2023 16:21:39 -0600 Subject: [PATCH 10/16] Small cleanup of poll and render frame --- client/src/em/em_remote_experience.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/client/src/em/em_remote_experience.cpp b/client/src/em/em_remote_experience.cpp index 14353bc8..bbec6d60 100644 --- a/client/src/em/em_remote_experience.cpp +++ b/client/src/em/em_remote_experience.cpp @@ -335,13 +335,9 @@ em_remote_experience_poll_and_render_frame(EmRemoteExperience *exp) if (0 != clock_gettime(CLOCK_MONOTONIC, &beginTime)) { ALOGE("%s: clock_gettime failed, which is very unexpected", __FUNCTION__); // TODO how to handle this? + return EM_POLL_RENDER_RESULT_SHOULD_NOT_RENDER; } - // Locate views, set up layers - XrView views[2] = {}; - views[0].type = XR_TYPE_VIEW; - views[1].type = XR_TYPE_VIEW; - XrViewLocateInfo locateInfo = {.type = XR_TYPE_VIEW_LOCATE_INFO, .viewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, @@ -350,12 +346,18 @@ em_remote_experience_poll_and_render_frame(EmRemoteExperience *exp) XrViewState viewState = {.type = XR_TYPE_VIEW_STATE}; - uint32_t viewCount = 2; - result = xrLocateViews(session, &locateInfo, &viewState, 2, &viewCount, views); + // Locate views, set up layers + XrView views[2] = {}; + views[0].type = XR_TYPE_VIEW; + views[1].type = XR_TYPE_VIEW; + + uint32_t viewCount = 0; + result = xrLocateViews(session, &locateInfo, &viewState, sizeof(views) / sizeof(views[0]), &viewCount, views); if (XR_FAILED(result)) { ALOGE("Failed to locate views"); // TODO how to handle this? + return EM_POLL_RENDER_RESULT_SHOULD_NOT_RENDER; } XrCompositionLayerProjection layer = {}; From 79a305237fd5340717ba9bb5d22d896b8eb88814 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Wed, 20 Dec 2023 16:22:11 -0600 Subject: [PATCH 11/16] Dump per-eye FOV once --- client/src/em/em_remote_experience.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/src/em/em_remote_experience.cpp b/client/src/em/em_remote_experience.cpp index bbec6d60..eb8f8286 100644 --- a/client/src/em/em_remote_experience.cpp +++ b/client/src/em/em_remote_experience.cpp @@ -446,6 +446,15 @@ em_remote_experience_inner_poll_and_render_frame(EmRemoteExperience *exp, uint32_t width = exp->eye_extents.width; uint32_t height = exp->eye_extents.height; + static bool showedFov = false; + if (!showedFov) { + showedFov = true; + ALOGI("RYLIE XrFovf 0: L %0.3f R %0.3f U %0.3f D %0.3f", views[0].fov.angleLeft, + views[0].fov.angleRight, views[0].fov.angleUp, views[0].fov.angleDown); + ALOGI("RYLIE XrFovf 1: L %0.3f R %0.3f U %0.3f D %0.3f", views[1].fov.angleLeft, + views[1].fov.angleRight, views[1].fov.angleUp, views[1].fov.angleDown); + } + projectionLayer->space = exp->xr_owned.worldSpace; projectionViews[0].subImage.swapchain = exp->xr_owned.swapchain; From 47b08357744b11abef32eb1cb86d8465c750cf62 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Wed, 20 Dec 2023 16:31:26 -0600 Subject: [PATCH 12/16] Format FOV as xrt_fov --- client/src/em/em_remote_experience.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/src/em/em_remote_experience.cpp b/client/src/em/em_remote_experience.cpp index eb8f8286..e7c77e37 100644 --- a/client/src/em/em_remote_experience.cpp +++ b/client/src/em/em_remote_experience.cpp @@ -449,10 +449,14 @@ em_remote_experience_inner_poll_and_render_frame(EmRemoteExperience *exp, static bool showedFov = false; if (!showedFov) { showedFov = true; - ALOGI("RYLIE XrFovf 0: L %0.3f R %0.3f U %0.3f D %0.3f", views[0].fov.angleLeft, - views[0].fov.angleRight, views[0].fov.angleUp, views[0].fov.angleDown); - ALOGI("RYLIE XrFovf 1: L %0.3f R %0.3f U %0.3f D %0.3f", views[1].fov.angleLeft, - views[1].fov.angleRight, views[1].fov.angleUp, views[1].fov.angleDown); + ALOGI( + "RYLIE XrFovf 0: (xrt_fov){ .angle_left = %0.03ff, .angle_right = %0.03ff, .angle_up = %0.03ff, " + ".angle_down = %0.03ff }", + views[0].fov.angleLeft, views[0].fov.angleRight, views[0].fov.angleUp, views[0].fov.angleDown); + ALOGI( + "RYLIE XrFovf 1: (xrt_fov){ .angle_left = %0.03ff, .angle_right = %0.03ff, .angle_up = %0.03ff, " + ".angle_down = %0.03ff }", + views[1].fov.angleLeft, views[1].fov.angleRight, views[1].fov.angleUp, views[1].fov.angleDown); } projectionLayer->space = exp->xr_owned.worldSpace; From ad7479f275102257c03433176a48818db0988463 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Wed, 20 Dec 2023 16:31:38 -0600 Subject: [PATCH 13/16] Hard code real Quest 2 FOV for now --- server/src/ems/ems_hmd.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/server/src/ems/ems_hmd.cpp b/server/src/ems/ems_hmd.cpp index 63193c27..1c097d0b 100644 --- a/server/src/ems/ems_hmd.cpp +++ b/server/src/ems/ems_hmd.cpp @@ -203,24 +203,22 @@ ems_hmd_create(ems_instance &emsi) // TODO: Find out the remote device's actual FOV. Or maybe remove this because I think get_view_poses lets us // set the FOV dynamically. - const double hFOV = 90 * (M_PI / 180.0); - const double vFOV = 96.73 * (M_PI / 180.0); - // center of projection - const double hCOP = 0.529; - const double vCOP = 0.5; - if ( - /* right eye */ - !math_compute_fovs(1, hCOP, hFOV, 1, vCOP, vFOV, &eh->base.hmd->distortion.fov[1]) || - /* - * left eye - same as right eye, except the horizontal center of projection is moved in the opposite - * direction now - */ - !math_compute_fovs(1, 1.0 - hCOP, hFOV, 1, vCOP, vFOV, &eh->base.hmd->distortion.fov[0])) { - // If those failed, it means our math was impossible. - EMS_ERROR(eh, "Failed to setup basic device info"); - ems_hmd_destroy(&eh->base); - return NULL; - } + + eh->base.hmd->distortion.fov[0] = (xrt_fov){ + // .angle_left = -0.75f, + .angle_left = -0.855f, + .angle_right = 0.785f, + .angle_up = 0.838f, + .angle_down = -0.873f, + }; + eh->base.hmd->distortion.fov[1] = (xrt_fov){ + .angle_left = -0.785f, + // .angle_right = 0.75f, + .angle_right = 0.855f, + .angle_up = 0.838f, + .angle_down = -0.873f, + }; + // TODO: Ditto, figure out the device's actual resolution const int panel_w = 1080; const int panel_h = 1200; From ee0274b8061940f529b15521e7dcca1b2342fff7 Mon Sep 17 00:00:00 2001 From: Frederic Plourde Date: Tue, 7 Nov 2023 15:57:43 -0500 Subject: [PATCH 14/16] Use __func__ instead of __FUNCTION__ in C --- server/src/ems/gst/ems_signaling_server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/ems/gst/ems_signaling_server.c b/server/src/ems/gst/ems_signaling_server.c index 274a0744..a956d6d2 100644 --- a/server/src/ems/gst/ems_signaling_server.c +++ b/server/src/ems/gst/ems_signaling_server.c @@ -134,7 +134,7 @@ message_cb(SoupWebsocketConnection *connection, gint type, GBytes *message, gpoi static void ems_signaling_server_remove_websocket_connection(EmsSignalingServer *server, SoupWebsocketConnection *connection) { - g_info("%s", __FUNCTION__); + g_info("%s", __func__); EmsClientId client_id; client_id = g_object_get_data(G_OBJECT(connection), "client_id"); @@ -155,7 +155,7 @@ closed_cb(SoupWebsocketConnection *connection, gpointer user_data) static void ems_signaling_server_add_websocket_connection(EmsSignalingServer *server, SoupWebsocketConnection *connection) { - g_info("%s", __FUNCTION__); + g_info("%s", __func__); g_object_ref(connection); server->websocket_connections = g_slist_append(server->websocket_connections, connection); g_object_set_data(G_OBJECT(connection), "client_id", connection); @@ -215,7 +215,7 @@ ems_signaling_server_send_to_websocket_client(EmsSignalingServer *server, EmsCli { SoupWebsocketConnection *connection = client_id; SoupWebsocketState socket_state; - g_info("%s", __FUNCTION__); + g_info("%s", __func__); if (!g_slist_find(server->websocket_connections, connection)) { g_warning("Unknown websocket connection."); From 459796af8437549a7084203f7d21f3ccc2da65da Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 17 Oct 2023 17:36:56 -0500 Subject: [PATCH 15/16] Work toward clean shutdown --- client/src/main.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/client/src/main.cpp b/client/src/main.cpp index 47bf2258..e0258c05 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -67,6 +67,9 @@ struct em_state uint32_t height; EmConnection *connection; + + bool shouldStop; + bool stopped; }; em_state state = {}; @@ -77,7 +80,10 @@ onAppCmd(struct android_app *app, int32_t cmd) switch (cmd) { case APP_CMD_START: ALOGE("APP_CMD_START"); break; case APP_CMD_RESUME: ALOGE("APP_CMD_RESUME"); break; - case APP_CMD_PAUSE: ALOGE("APP_CMD_PAUSE"); break; + case APP_CMD_PAUSE: + ALOGE("APP_CMD_PAUSE - setting shouldStop"); + state.shouldStop = true; + break; case APP_CMD_STOP: ALOGE("APP_CMD_STOP - shutting down connection"); em_connection_disconnect(state.connection); @@ -152,10 +158,17 @@ poll_events(struct android_app *app, struct em_state &state) case XR_SESSION_STATE_FOCUSED: ALOGI("OpenXR session is now FOCUSED"); break; case XR_SESSION_STATE_STOPPING: ALOGI("OpenXR session is now STOPPING"); + state.shouldStop = true; xrEndSession(state.session); break; - case XR_SESSION_STATE_LOSS_PENDING: ALOGI("OpenXR session is now LOSS_PENDING"); break; - case XR_SESSION_STATE_EXITING: ALOGI("OpenXR session is now EXITING"); break; + case XR_SESSION_STATE_LOSS_PENDING: + ALOGI("OpenXR session is now LOSS_PENDING"); + state.shouldStop = true; + break; + case XR_SESSION_STATE_EXITING: + ALOGI("OpenXR session is now EXITING"); + state.shouldStop = true; + break; default: break; } @@ -369,9 +382,14 @@ android_main(struct android_app *app) // Main rendering loop. ALOGI("DEBUG: Starting main loop.\n"); while (!app->destroyRequested) { - if (poll_events(app, state)) { + if (!state.stopped && poll_events(app, state)) { em_remote_experience_poll_and_render_frame(remote_experience); } + if (state.shouldStop && !state.stopped) { + ALOGI("Calling em_stream_client_stop"); + em_stream_client_stop(stream_client); + state.stopped = true; + } } ALOGI("DEBUG: Exited main loop, cleaning up.\n"); From 863a7ec87be732be189f99db3bf6e866f37efea2 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Tue, 17 Oct 2023 17:37:23 -0500 Subject: [PATCH 16/16] Clear connection in SC upon stop. --- client/src/em/em_stream_client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/em/em_stream_client.c b/client/src/em/em_stream_client.c index 28b7b2d6..515d22da 100644 --- a/client/src/em/em_stream_client.c +++ b/client/src/em/em_stream_client.c @@ -580,6 +580,7 @@ em_stream_client_stop(EmStreamClient *sc) gst_clear_object(&sc->pipeline); gst_clear_object(&sc->appsink); gst_clear_object(&sc->context); + gst_clear_object(&sc->connection); sc->pipeline_is_running = false; }