From 20acf975d9e177358573d5e82780c3e472275490 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 1 Oct 2026 17:46:55 +0300 Subject: [PATCH] Return final video metadata from the preparation worker --- src/chat/chat_msg.c | 15 +++++++-------- src/video/video.c | 10 ++++++---- src/video/video.h | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/chat/chat_msg.c b/src/chat/chat_msg.c index c2391663..b531dd70 100644 --- a/src/chat/chat_msg.c +++ b/src/chat/chat_msg.c @@ -251,7 +251,7 @@ static void on_media_registered(void* arg, int err, const struct media_index_res u_free(sig_msg); u_free(json); u_free(full_data); u_free(mctx); } -static void on_video_prepared(void* arg, int err) { +static void on_video_prepared(void* arg, int err, const struct video_info* vi) { struct media_submit_ctx* mctx = (struct media_submit_ctx*)arg; struct chat_core_ctx* cc = CC(mctx->inst); @@ -263,13 +263,12 @@ static void on_video_prepared(void* arg, int err) { } /* после транскода знаем итоговую длительность и размеры — для тела сообщения */ - struct video_info vi; - if (video_get_info(mctx->media_dest, &vi) == 0 && vi.is_video) { - mctx->duration_ms = vi.duration_ms; - mctx->width = vi.width; - mctx->height = vi.height; + if (vi && vi->is_video) { + mctx->duration_ms = vi->duration_ms; + mctx->width = vi->width; + mctx->height = vi->height; DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "%s: video prepared %dx%d dur=%lldms", - CC_ID, vi.width, vi.height, (long long)vi.duration_ms); + CC_ID, vi->width, vi->height, (long long)vi->duration_ms); } char media_base[1024]; @@ -343,7 +342,7 @@ void chat_core_submit_media_message(struct UTUN_INSTANCE* inst, struct chat_msg_ if (req->media_video) { if (video_transcode_start(inst->media_async, inst->ua, req->media_src, req->media_dest, on_video_prepared, mctx) < 0) - on_video_prepared(mctx, -1); + on_video_prepared(mctx, -1, NULL); return; } diff --git a/src/video/video.c b/src/video/video.c index 35591c86..26f5175a 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -46,7 +46,7 @@ int video_get_info(const char* path, struct video_info* out) { (void)path; (void int video_needs_transcode(const struct video_info* info) { (void)info; return 1; } int video_transcode_start(struct media_async* owner, struct UASYNC* ua, const char* src, const char* dst, - void (*done)(void* arg, int err), void* arg) { + void (*done)(void* arg, int err, const struct video_info* info), void* arg) { (void)owner; (void)ua; (void)src; (void)dst; (void)done; (void)arg; DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "video: built without FFmpeg (HAVE_FFMPEG undefined)"); return -1; @@ -191,7 +191,8 @@ struct vc_ctx { char src[1024]; char dst[1024]; struct UASYNC* ua; - void (*done)(void* arg, int err); + void (*done)(void* arg, int err, const struct video_info* info); + struct video_info result; void* arg; int err; @@ -529,7 +530,7 @@ static void vc_done_trampoline(void* raw, int error) { struct vc_ctx* ctx = (struct vc_ctx*)raw; vc_active_set(0); vc_progress_set(-1); - if (ctx->done) ctx->done(ctx->arg, error ? error : ctx->err); + if (ctx->done) ctx->done(ctx->arg, error ? error : ctx->err, &ctx->result); u_free(ctx); } @@ -567,11 +568,12 @@ static void vc_thread_entry(void* raw) { vc_cleanup(ctx); out: + if (!ctx->err && video_get_info(ctx->dst, &ctx->result)) ctx->err = -1; return; } int video_transcode_start(struct media_async* owner, struct UASYNC* ua, const char* src, const char* dst, - void (*done)(void* arg, int err), void* arg) { + void (*done)(void* arg, int err, const struct video_info* info), void* arg) { if (!owner || !ua || !src || !dst || !done) { DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "video: transcode_start invalid args"); return -1; diff --git a/src/video/video.h b/src/video/video.h index 098bc3e6..909c5329 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -58,7 +58,7 @@ int video_needs_transcode(const struct video_info* info); struct media_async; int video_transcode_start(struct media_async* owner, struct UASYNC* ua, const char* src, const char* dst, - void (*done)(void* arg, int err), void* arg); + void (*done)(void* arg, int err, const struct video_info* info), void* arg); /* Прогресс активного транскода в промилле 0..1000, -1 если транскода нет. */ int video_transcode_get_progress(void);