From f15c97d11a3265f456296a84def351b42b01f3cb Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 13 Oct 2026 20:09:14 +0200 Subject: [PATCH] Size Android publisher buffers for the signed batch format --- src/stream/stream.h | 4 ++-- tools/chatgui-android/libutun_lite/stream_bridge.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stream/stream.h b/src/stream/stream.h index 4b563625..4625a87a 100644 --- a/src/stream/stream.h +++ b/src/stream/stream.h @@ -17,7 +17,7 @@ struct UTUN_INSTANCE; struct STREAM_HANDLE; struct stream_service; -struct stream_parameters { uint8_t n, r; uint16_t block_size; }; +struct stream_parameters { uint8_t n, r; uint16_t block_size; }; /* block_size — максимум RS-части. */ enum stream_event_type { STREAM_EVENT_DATA, STREAM_EVENT_GAP, STREAM_EVENT_END, STREAM_EVENT_CLOSED }; enum stream_close_reason { @@ -69,7 +69,7 @@ int stream_watch_sources(struct UTUN_INSTANCE *inst, uint64_t group_id); /* Локальный owner удерживает эффективный ACTIVE; желаемый frontend-режим ядро восстанавливает после последнего close. */ int stream_service_needs_activity(const struct UTUN_INSTANCE *inst); -/* out заранее NULL. parameters=NULL — 6+2 и полный подписанный блок 1300 байт. +/* out заранее NULL. parameters=NULL — 6+2, часть до 1300 байт и одна подпись пачки внутри RS. * Одна публикация этого узла в группе; новый запуск получает новый source_epoch. */ int stream_publish_open(struct UTUN_INSTANCE *inst, uint64_t group_id, const struct stream_parameters *parameters, struct STREAM_HANDLE **out); diff --git a/tools/chatgui-android/libutun_lite/stream_bridge.c b/tools/chatgui-android/libutun_lite/stream_bridge.c index 3abae87e..eeb41702 100644 --- a/tools/chatgui-android/libutun_lite/stream_bridge.c +++ b/tools/chatgui-android/libutun_lite/stream_bridge.c @@ -161,7 +161,8 @@ static void media_close(struct android_media_session *s, int kind) { /* Сформировать ограниченную пачку: аудио целиком, видео с продолжениями и несколькими началами. */ static int media_publish(void) { struct stream_media_block block = {.format = publisher.format}; - uint8_t wire[7080]; size_t capacity = stream_publish_capacity(publisher.handle), used = STREAM_MEDIA_HEADER_SIZE; + uint8_t wire[STREAM_DEFAULT_INPUT_CAPACITY]; + size_t capacity = stream_publish_capacity(publisher.handle), used = STREAM_MEDIA_HEADER_SIZE; if (capacity > sizeof(wire) || capacity < 256) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "Android publisher invalid capacity=%zu", capacity); return STREAM_ERR_STATE; } @@ -263,7 +264,7 @@ static void media_process(void *arg) { size_t pending = video_queue.bytes + audio_queue.bytes - (video_queue.head ? video_queue.head->offset : 0); uint64_t oldest = video_queue.head ? video_queue.head->created : audio_queue.head->created; if (audio_queue.head && audio_queue.head->created < oldest) oldest = audio_queue.head->created; - if (!publisher.stopping && pending + STREAM_MEDIA_HEADER_SIZE + STREAM_MEDIA_VIDEO_SIZE < 7080 + if (!publisher.stopping && pending + STREAM_MEDIA_HEADER_SIZE + STREAM_MEDIA_VIDEO_SIZE < stream_publish_capacity(publisher.handle) && now - oldest < 20000) break; int result = media_publish(); if (result < 0) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "Android media publish failed result=%d", result); media_close(&publisher, 6); break; }