diff options
author | Matthew Wozniak <me@woz.blue> | 2024-11-18 21:05:46 -0500 |
---|---|---|
committer | Matthew Wozniak <me@woz.blue> | 2024-11-18 21:05:46 -0500 |
commit | 2fee53f8cb846aedc8bf921c3ad6654993dd2222 (patch) | |
tree | 4e40d7b63b8ea44a8765d0de6358b2d8a4189a3f /render.c | |
parent | 0f942c806786bdf1fa608d5cf32fdf8a418236b0 (diff) | |
download | rt-2fee53f8cb846aedc8bf921c3ad6654993dd2222.tar.gz rt-2fee53f8cb846aedc8bf921c3ad6654993dd2222.zip |
Fix 5288 issue/multiple demos
Diffstat (limited to 'render.c')
-rw-r--r-- | render.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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 <libavformat/avformat.h> #include <libavcodec/avcodec.h> #include <libavcodec/codec_id.h> +#include <libavutil/channel_layout.h> +#include <libavutil/mathematics.h> #include <libavutil/error.h> #include <libavutil/opt.h> #include <libavutil/log.h> @@ -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"); |