singe/src/record.h
2026-10-05 22:12:53 -05:00

68 lines
2.7 KiB
C

/*
*
* Singe 3
* Copyright (C) 2006-2026 Scott Duensing <scott@kangaroopunch.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
#ifndef RECORD_H
#define RECORD_H
#include <stdbool.h>
#include <stdint.h>
#include <SDL3/SDL.h>
#include <SDL3_mixer/SDL_mixer.h>
// Recording: the finished picture and the finished mix written to an MP4. The picture is H.264
// from the platform's own hardware encoder where there is one, and MPEG-4 otherwise; the sound is
// AAC. Frames are handed over on the engine's thread and the sound on the mixer's; both are
// encoded and written on a thread of the recorder's own, so recording costs the game the copy of
// each frame and little else.
#define RECORD_LIVE_FPS 60 // A recording on the real clock is this many frames a second
// Hands over one finished frame: its pixels, the time it was shown on the engine's clock, in
// milliseconds. A frame whose time falls in the same output frame as the last one is skipped. On
// the real clock a frame is dropped rather than waited for when the encoder is behind; on a
// deterministic clock it is never dropped, and the engine waits instead.
void recordFrame(const SDL_Surface *surface, uint64_t milliseconds);
bool recordIsRecording(void);
// The file being written, or NULL.
const char *recordPath(void);
// Starts writing to path: width by height (each made even), frames frameMs apart (a deterministic
// step) or 0 for RECORD_LIVE_FPS on the real clock, the sound from mixer, which is latencyMs ahead
// of the picture. The time now on the engine's clock is the start of the recording. False, with
// the reason in SDL_GetError, when it cannot start.
bool recordStart(const char *path, int32_t width, int32_t height, int32_t frameMs, MIX_Mixer *mixer, int32_t latencyMs, uint64_t milliseconds);
// Finishes the file. Safe when nothing is recording.
void recordStop(void);
// The encoder in use, for the trace: "h264_vaapi", "mpeg4", and so on, or NULL.
const char *recordVideoEncoder(void);
#endif // RECORD_H