From 57a59df9831051a9824c09530db651a5edb47475 Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 14 Oct 2026 22:36:03 +0200 Subject: [PATCH] Bind shared call video port to desktop and Android core lifetime --- src/Makefile.am | 4 ++++ tools/chatgui-android/libutun_lite/instance_lite.c | 7 ++++++- tools/chatgui/transport/utun_node.cpp | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index e22e6c00..3e3ddc38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -189,6 +189,8 @@ utun_CORE_SOURCES = \ call/call_video.h \ call/call_video_transport.c \ call/call_video_transport.h \ + call/call_video_port.c \ + call/call_video_port.h \ call/call_priv.h \ call/call_headless.c \ radio/radio.c \ @@ -347,6 +349,8 @@ libutun_a_SOURCES = \ call/call_video.h \ call/call_video_transport.c \ call/call_video_transport.h \ + call/call_video_port.c \ + call/call_video_port.h \ call/call_priv.h \ call/call_headless.c \ radio/radio.c \ diff --git a/tools/chatgui-android/libutun_lite/instance_lite.c b/tools/chatgui-android/libutun_lite/instance_lite.c index 6c50ce30..81b9f893 100644 --- a/tools/chatgui-android/libutun_lite/instance_lite.c +++ b/tools/chatgui-android/libutun_lite/instance_lite.c @@ -30,6 +30,7 @@ #include "../jni_bridge/android_jni_bridge.h" #include "standby.h" #include "stream_bridge.h" +#include "call/call_video_port.h" #include #include #include @@ -314,6 +315,7 @@ static void* instance_thread(void* arg) { } /* sockets are now created — sync my addresses to DB */ + call_video_port_attach(g_inst); chat_core_sync_my_addresses(g_inst); fire_local_sockets_event(); @@ -357,6 +359,7 @@ static void* instance_thread(void* arg) { __atomic_store_n(&g_running, 0, __ATOMIC_RELEASE); struct UTUN_INSTANCE* old_inst = g_inst; g_inst = NULL; + call_video_port_detach(old_inst); android_stream_detach(old_inst); utun_instance_destroy(old_inst); my_inst = NULL; @@ -393,6 +396,7 @@ static void* instance_thread(void* arg) { IL_LOGE("poll exit: core/chat/stream bridge start failed"); break; } chat_core_sync_my_addresses(g_inst); + call_video_port_attach(g_inst); fire_local_sockets_event(); if (g_inst->config->global.name[0]) chat_core_update_my_name(g_inst, g_inst->config->global.name); etcp_router_bind(g_inst, ETCP_RT_ID_CHAT_SYNC, NULL); @@ -415,6 +419,7 @@ static void* instance_thread(void* arg) { if (my_inst) { chat_event_post(my_inst, CHAT_EVT_SERVICE_STOPPED, NULL, 0); g_inst = NULL; + call_video_port_detach(my_inst); android_stream_detach(my_inst); utun_instance_destroy(my_inst); my_inst = NULL; @@ -435,7 +440,7 @@ static void* instance_thread(void* arg) { но собственные объекты этого потока надо закрыть, иначе течёт fd. */ IL_LOGI("cleanup (stale thread gen=%d vs %d): destroying own inst=%p ua=%p to avoid fd leak", my_gen, g_generation, (void*)my_inst, (void*)my_ua); - if (my_inst) { android_stream_detach(my_inst); utun_instance_destroy(my_inst); my_inst = NULL; } + if (my_inst) { call_video_port_detach(my_inst); android_stream_detach(my_inst); utun_instance_destroy(my_inst); my_inst = NULL; } if (my_ua) { udp_log_detach(my_ua); uasync_destroy(my_ua, 0); my_ua = NULL; } } __atomic_store_n(&g_thread_running, 0, __ATOMIC_RELEASE); diff --git a/tools/chatgui/transport/utun_node.cpp b/tools/chatgui/transport/utun_node.cpp index 2da8c79c..fa50bee0 100644 --- a/tools/chatgui/transport/utun_node.cpp +++ b/tools/chatgui/transport/utun_node.cpp @@ -26,6 +26,7 @@ extern "C" { #include "chat/db_sync.h" #include "call/call.h" #include "call/call_audio.h" +#include "call/call_video_port.h" #include "radio/radio_audio.h" #include "dm/dm_core.h" #include "dm/dm_mailbox.h" @@ -246,6 +247,7 @@ void UtunNode::runLoop() { uasync_destroy(ua, 0); m_ua = nullptr; return; } call_audio_init(m_instance); + call_video_port_attach(m_instance); radio_audio_init(m_instance); if (!gui_stream_attach(m_instance)) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "desktop stream bridge initialization failed"); @@ -268,6 +270,7 @@ void UtunNode::runLoop() { if (m_instance) { DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "runLoop: destroying instance in worker thread"); gui_stream_detach(m_instance); + call_video_port_detach(m_instance); call_audio_destroy(m_instance); radio_audio_destroy(m_instance); utun_instance_destroy(m_instance);