aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/recorder
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2026-08-01 21:14:46 +0200
committerdec05eba <dec05eba@protonmail.com>2026-08-01 21:14:46 +0200
commite8fca67df16025598f6ca7bcc31cfdcfb79feb7d (patch)
tree4e20ecf3f93b5800ef40a1f48aa94c696a075587 /include/recorder
parent2b47b9926966b6e81ffda188193eb80653c6f14f (diff)
Move audio/video codec setup from main.cpp into C modules
Adds gsr_recorder_settings, a library-friendly settings struct embedded in args_parser, so the new modules don't depend on the argument parser. The codec functions return errors instead of exiting.
Diffstat (limited to 'include/recorder')
-rw-r--r--include/recorder/audio_codec.h23
-rw-r--r--include/recorder/settings.h63
-rw-r--r--include/recorder/video_codec.h18
3 files changed, 104 insertions, 0 deletions
diff --git a/include/recorder/audio_codec.h b/include/recorder/audio_codec.h
new file mode 100644
index 0000000..d432abd
--- /dev/null
+++ b/include/recorder/audio_codec.h
@@ -0,0 +1,23 @@
+#ifndef GSR_RECORDER_AUDIO_CODEC_H
+#define GSR_RECORDER_AUDIO_CODEC_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "../defs.h"
+#include "../sound.h"
+
+#include <libavcodec/avcodec.h>
+
+#define GSR_AUDIO_SAMPLE_RATE 48000
+
+gsr_audio_format audio_codec_context_get_audio_format(const AVCodecContext *audio_codec_context);
+enum AVSampleFormat audio_format_to_sample_format(const gsr_audio_format audio_format);
+
+AVCodecContext* create_audio_codec_context(int fps, gsr_audio_codec audio_codec, bool mix_audio, int64_t audio_bitrate);
+bool open_audio(AVCodecContext *audio_codec_context, const char *ffmpeg_audio_opts);
+AVFrame* create_audio_frame(AVCodecContext *audio_codec_context);
+
+double audio_codec_get_desired_delay(gsr_audio_codec audio_codec, int fps);
+int audio_codec_get_frame_size(gsr_audio_codec audio_codec);
+
+#endif /* GSR_RECORDER_AUDIO_CODEC_H */
diff --git a/include/recorder/settings.h b/include/recorder/settings.h
new file mode 100644
index 0000000..8bb7f77
--- /dev/null
+++ b/include/recorder/settings.h
@@ -0,0 +1,63 @@
+#ifndef GSR_RECORDER_SETTINGS_H
+#define GSR_RECORDER_SETTINGS_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "../defs.h"
+#include "../vec2.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ gsr_video_encoder_hardware video_encoder;
+ gsr_pixel_format pixel_format;
+ gsr_framerate_mode framerate_mode;
+ gsr_color_range color_range;
+ gsr_tune tune;
+ gsr_video_codec video_codec;
+ gsr_audio_codec audio_codec;
+ gsr_bitrate_mode bitrate_mode;
+ gsr_video_quality video_quality;
+ gsr_replay_storage replay_storage;
+
+ const char *capture_source;
+ const char *container_format;
+ const char *filename;
+ const char *replay_recording_directory;
+ const char *portal_session_token_filepath;
+ const char *recording_saved_script;
+ const char *ffmpeg_opts;
+ const char *ffmpeg_video_opts;
+ const char *ffmpeg_audio_opts;
+ bool verbose;
+ bool gl_debug;
+ bool fallback_cpu_encoding;
+ bool low_power;
+ bool exclude_metadata;
+ bool record_cursor;
+ bool date_folders;
+ bool restore_portal_session;
+ bool restart_replay_on_save;
+ bool write_first_frame_ts;
+ bool is_replaying;
+ bool is_livestream;
+ bool is_output_piped;
+ bool low_latency_recording;
+ bool very_old_gpu;
+ int64_t video_bitrate;
+ int64_t audio_bitrate;
+ int64_t fps;
+ int64_t replay_buffer_size_secs;
+ double keyint;
+ vec2i output_resolution;
+ vec2i region_size;
+ vec2i region_position;
+} gsr_recorder_settings;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GSR_RECORDER_SETTINGS_H */
diff --git a/include/recorder/video_codec.h b/include/recorder/video_codec.h
new file mode 100644
index 0000000..9347a9e
--- /dev/null
+++ b/include/recorder/video_codec.h
@@ -0,0 +1,18 @@
+#ifndef GSR_RECORDER_VIDEO_CODEC_H
+#define GSR_RECORDER_VIDEO_CODEC_H
+
+#include <stdbool.h>
+#include "../defs.h"
+#include "../egl.h"
+#include "settings.h"
+
+#include <libavcodec/avcodec.h>
+
+int video_quality_to_h264_equivalent_qp(gsr_video_quality video_quality);
+enum AVPixelFormat get_pixel_format(gsr_video_codec video_codec, gsr_gpu_vendor vendor, bool use_software_video_encoder);
+
+AVCodecContext* create_video_codec_context(enum AVPixelFormat pix_fmt, const AVCodec *codec, const gsr_egl *egl, const gsr_recorder_settings *settings, int width, int height);
+bool open_video_software(AVCodecContext *codec_context, const gsr_recorder_settings *settings);
+bool open_video_hardware(AVCodecContext *codec_context, bool low_power, const gsr_egl *egl, const gsr_recorder_settings *settings);
+
+#endif /* GSR_RECORDER_VIDEO_CODEC_H */