From 2fee53f8cb846aedc8bf921c3ad6654993dd2222 Mon Sep 17 00:00:00 2001 From: Matthew Wozniak Date: Mon, 18 Nov 2024 21:05:46 -0500 Subject: Fix 5288 issue/multiple demos --- render.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/render.c b/render.c index ec841e7..aafa882 100644 --- a/render.c +++ b/render.c @@ -15,8 +15,6 @@ */ #include "api.h" -#include "libavutil/channel_layout.h" -#include "libavutil/mathematics.h" #include "log.h" #include "hook.h" #include "render.h" @@ -26,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -69,7 +69,6 @@ struct renderctx { AVFrame *aframe; AVFrame *aframe_tmp; struct SwrContext *swr; - u64 nextpts; }; static struct renderctx ctx = { 0 }; @@ -102,7 +101,10 @@ bool encode(AVCodecContext *codec, AVFrame *frame, AVStream *stream) { } bool do_frame(struct videomode *this, struct movieinfo *info) { + (void)(info); // unused param is_rendering = true; + + static int nextpts = 0; static struct { u8 bgr[3]; } *pixels = 0; if (!pixels) pixels = malloc(args.width * args.height * sizeof(*pixels)); @@ -118,7 +120,7 @@ bool do_frame(struct videomode *this, struct movieinfo *info) { sws_scale(ctx.sws, (const u8 **)&pixels, &stride, 0, args.height, ctx.yuv_frame->data, ctx.yuv_frame->linesize); - ctx.yuv_frame->pts = info->curframe; + ctx.yuv_frame->pts = nextpts++; ctx.yuv_frame->time_base = ctx.vcodec_ctx->time_base; ctx.yuv_frame->duration = 1; @@ -135,7 +137,7 @@ void VIRTUAL hook_write_movie_frame(struct videomode *this, bool do_audio_frame(void) { if (!is_rendering) return true; - + static u64 nextpts = 0; static int frame_idx = 0; #define CLIP16(n) (i16)(n < -32768 ? -32768 : (n > 32767 ? 32767 : n)) @@ -151,8 +153,8 @@ bool do_audio_frame(void) { ctx.aframe_tmp->nb_samples) < 0) bail("failed to resample audio frame"); - ctx.aframe->pts = ctx.nextpts; - ctx.nextpts += ctx.aframe->nb_samples; + ctx.aframe->pts = nextpts; + nextpts += ctx.aframe->nb_samples; encode(ctx.acodec_ctx, ctx.aframe, ctx.astream); frame_idx = 0; } @@ -316,8 +318,6 @@ bool render_init(void) { if (swr_init(ctx.swr) < 0) bail("failed to init resampler"); - ctx.nextpts = 0; - // audio frame ctx.aframe = av_frame_alloc(); if (!ctx.aframe) bail("failed to alloc audio frame"); -- cgit v1.2.3-54-g00ecf