From 5677e8ec5f6b4c50a96024bba9e67c62a98b564c Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 14 Oct 2026 01:09:30 +0200 Subject: [PATCH] Initialize the publication media format with the selected codec --- tests/test_android_stream.c | 10 +++++----- tools/chatgui-android/libutun_lite/stream_bridge.c | 7 ++++--- tools/chatgui-android/libutun_lite/stream_bridge.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_android_stream.c b/tests/test_android_stream.c index 8530af90..0fe33e65 100644 --- a/tests/test_android_stream.c +++ b/tests/test_android_stream.c @@ -73,16 +73,16 @@ int main(void) { CHECK(android_stream_watch(group) == 0); test_clock_poll(ua, 100); CHECK(source_events == 1 && source_group == group && !strcmp(source_snapshot, "[]")); CHECK(!stream_service_needs_activity(inst)); - CHECK(android_stream_open(1, group, 0, 1280, 720, 90, 1, 0) == 0); + CHECK(android_stream_open(1, group, 0, 1280, 720, 90, 1, 0, STREAM_MEDIA_H264) == 0); size_t size = 0; u_free(wait_event(1, 4, &size)); char *sources = NULL; CHECK(stream_sources_json(inst, group, &sources) == STREAM_OK); CHECK(strstr(sources, "epoch") && strstr(sources, "name")); u_free(sources); test_clock_poll(ua, 100); CHECK(source_events == 2 && strstr(source_snapshot, "epoch")); struct stream_member_state member; CHECK(stream_member_load(inst, group, inst->node_id, &member, NULL) == STREAM_OK && member.published); - CHECK(android_stream_open(5, group, inst->node_id, 0, 0, 0, 1, member.source.source_epoch ^ 1) == 0); + CHECK(android_stream_open(5, group, inst->node_id, 0, 0, 0, 1, member.source.source_epoch ^ 1, STREAM_MEDIA_H264) == 0); uint8_t *error = wait_event(5, 6, &size); CHECK(error[1] == STREAM_CLOSE_SOURCE_CHANGED); u_free(error); - CHECK(android_stream_open(2, group, inst->node_id, 0, 0, 0, 1, member.source.source_epoch) == 0); + CHECK(android_stream_open(2, group, inst->node_id, 0, 0, 0, 1, member.source.source_epoch, STREAM_MEDIA_H264) == 0); u_free(wait_event(2, 4, &size)); CHECK(source_events == 2); /* Подписка не меняет каталог публикаций. */ for (unsigned i = 0; i < sizeof(video); i++) video[i] = (uint8_t)i; @@ -151,7 +151,7 @@ int main(void) { while ((output = android_stream_pull(2, &size))) u_free(output); CHECK(!strcmp(source_snapshot, "[]")); current_format.rotation = 0; current_format.audio_codec = 0; - CHECK(android_stream_open(3, group, 0, 1280, 720, 0, 0, 0) == 0); u_free(wait_event(3, 4, &size)); + CHECK(android_stream_open(3, group, 0, 1280, 720, 0, 0, 0, STREAM_MEDIA_H264) == 0); u_free(wait_event(3, 4, &size)); pthread_t thread; CHECK(pthread_create(&thread, NULL, producer, NULL) == 0); while (!__atomic_load_n(&producer_started, __ATOMIC_ACQUIRE)) {} android_stream_detach(inst); @@ -159,7 +159,7 @@ int main(void) { CHECK(feed(3, 1, 900000, 1, video, sizeof(video)) == -1); while ((output = android_stream_pull(3, &size))) u_free(output); android_stream_attach(inst); - CHECK(android_stream_open(4, group, 0, 1280, 720, 0, 0, 0) == 0); android_stream_stop(4); + CHECK(android_stream_open(4, group, 0, 1280, 720, 0, 0, 0, STREAM_MEDIA_H264) == 0); android_stream_stop(4); u_free(wait_event(4, 5, &size)); android_stream_detach(inst); uasync_mark_stopped(ua); utun_instance_destroy(inst); uasync_destroy(ua, 0); u_free(source_snapshot); diff --git a/tools/chatgui-android/libutun_lite/stream_bridge.c b/tools/chatgui-android/libutun_lite/stream_bridge.c index 00ae5d07..0b5080d9 100644 --- a/tools/chatgui-android/libutun_lite/stream_bridge.c +++ b/tools/chatgui-android/libutun_lite/stream_bridge.c @@ -386,7 +386,7 @@ void android_stream_detach(struct UTUN_INSTANCE *inst) { /* Команда содержит идентификаторы, а не borrowed pointer ядра. */ int android_stream_open(uint64_t id, uint64_t group, uint64_t source, unsigned width, unsigned height, - unsigned rotation, int audio, uint64_t expected_epoch) { + unsigned rotation, int audio, uint64_t expected_epoch, unsigned codec) { if (!id || !group || (source && !expected_epoch) || (!source && (!width || width > 4096 || !height || height > 4096 || rotation > 270 || rotation % 90))) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "Android stream open invalid id=%llu group=%llx source=%llx epoch=%llx dimensions=%ux%u", @@ -396,13 +396,14 @@ int android_stream_open(uint64_t id, uint64_t group, uint64_t source, unsigned w pthread_mutex_lock(&media_lock); struct android_media_session *s = source ? &viewer : &publisher; int result = -1; - if (s->id || id == publisher.id || id == viewer.id || !media_inst || !uasync_is_running(media_inst->ua)) { + if (codec < STREAM_MEDIA_H264 || codec > STREAM_MEDIA_H266 || s->id || id == publisher.id || id == viewer.id + || !media_inst || !uasync_is_running(media_inst->ua)) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "Android stream open busy/detached id=%llu", (unsigned long long)id); } else if (media_schedule() == 0) { *s = (struct android_media_session){.id = id, .group = group, .source = source, .expected_epoch = expected_epoch, .opening = 1, .need_key = 1, .listen_audio = !!audio, .position = -1, .video_ahead = STREAM_MEDIA_READ_AHEAD_US, .audio_ahead = STREAM_MEDIA_READ_AHEAD_US, - .format = {(uint16_t)width, (uint16_t)height, (uint16_t)rotation, STREAM_MEDIA_H264, audio ? STREAM_MEDIA_OPUS_STEREO : 0, 1}}; + .format = {(uint16_t)width, (uint16_t)height, (uint16_t)rotation, (uint8_t)codec, audio ? STREAM_MEDIA_OPUS_STEREO : 0, 1}}; result = 0; } pthread_mutex_unlock(&media_lock); return result; diff --git a/tools/chatgui-android/libutun_lite/stream_bridge.h b/tools/chatgui-android/libutun_lite/stream_bridge.h index 72472eaf..cb4b09f6 100644 --- a/tools/chatgui-android/libutun_lite/stream_bridge.h +++ b/tools/chatgui-android/libutun_lite/stream_bridge.h @@ -26,7 +26,7 @@ int android_stream_attach(struct UTUN_INSTANCE *inst); void android_stream_detach(struct UTUN_INSTANCE *inst); /* source=0 — publisher; source!=0 — viewer с обязательным expected_epoch. Команда принята=0, результат через pull. */ int android_stream_open(uint64_t id, uint64_t group, uint64_t source, unsigned width, unsigned height, - unsigned rotation, int audio, uint64_t expected_epoch); + unsigned rotation, int audio, uint64_t expected_epoch, unsigned codec); /* Наблюдение выбранного канала через CHAT_EVT_STREAM_SOURCES; group=0 снимает его. */ int android_stream_watch(uint64_t group); /* Видео содержит revision/размер/поворот; новая revision принимается атомарно с KEY. Для аудио format=NULL. */