Browse Source

Return final video metadata from the preparation worker

master
evgeny 2 weeks ago
parent
commit
20acf975d9
  1. 15
      src/chat/chat_msg.c
  2. 10
      src/video/video.c
  3. 2
      src/video/video.h

15
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;
}

10
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;

2
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);

Loading…
Cancel
Save