aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2026-08-01 21:17:53 +0200
committerdec05eba <dec05eba@protonmail.com>2026-08-01 21:17:53 +0200
commitd02955183135dbc72072492cdfcb35f2387e2c00 (patch)
treee12defe454c7a7e3661bd1cabd9e11ef5d68d44e /include
parente8fca67df16025598f6ca7bcc31cfdcfb79feb7d (diff)
Move video/audio codec selection from main.cpp into codec_select module
Codec selection returns gsr_error values instead of exiting, and takes gsr_recorder_settings instead of the argument parser.
Diffstat (limited to 'include')
-rw-r--r--include/recorder/codec_select.h30
-rw-r--r--include/recorder/error.h31
2 files changed, 61 insertions, 0 deletions
diff --git a/include/recorder/codec_select.h b/include/recorder/codec_select.h
new file mode 100644
index 0000000..ff4b064
--- /dev/null
+++ b/include/recorder/codec_select.h
@@ -0,0 +1,30 @@
+#ifndef GSR_RECORDER_CODEC_SELECT_H
+#define GSR_RECORDER_CODEC_SELECT_H
+
+#include <stdbool.h>
+#include "../defs.h"
+#include "../egl.h"
+#include "../vec2.h"
+#include "../codec_query/codec_query.h"
+#include "settings.h"
+
+#include <libavcodec/avcodec.h>
+
+typedef struct gsr_video_encoder gsr_video_encoder;
+
+gsr_video_encoder* create_video_encoder(gsr_egl *egl, const gsr_recorder_settings *settings);
+
+bool get_supported_video_codecs(gsr_egl *egl, gsr_video_codec video_codec, bool use_software_video_encoder, bool cleanup, gsr_supported_video_codecs *video_codecs);
+void set_supported_video_codecs_ffmpeg(gsr_supported_video_codecs *supported_video_codecs, gsr_supported_video_codecs *supported_video_codecs_vulkan, gsr_gpu_vendor vendor);
+
+vec2i codec_get_max_resolution(gsr_video_codec video_codec, bool use_software_video_encoder, const gsr_supported_video_codecs *supported_video_codecs);
+bool codec_supports_resolution(vec2i codec_max_resolution, vec2i capture_resolution);
+/* Returns -1 if none is available */
+gsr_video_codec select_appropriate_video_codec_automatically(vec2i video_size, const gsr_supported_video_codecs *supported_video_codecs);
+void force_cpu_encoding(gsr_recorder_settings *settings);
+
+gsr_audio_codec select_audio_codec_with_fallback(gsr_audio_codec audio_codec, const char *file_extension, bool uses_amix);
+/* Returns a |gsr_error| value. |settings| video codec and encoder are updated to the codec that was selected */
+int select_video_codec_with_fallback(vec2i video_size, gsr_recorder_settings *settings, const char *file_extension, gsr_egl *egl, bool *low_power, const AVCodec **video_codec);
+
+#endif /* GSR_RECORDER_CODEC_SELECT_H */
diff --git a/include/recorder/error.h b/include/recorder/error.h
new file mode 100644
index 0000000..75f1416
--- /dev/null
+++ b/include/recorder/error.h
@@ -0,0 +1,31 @@
+#ifndef GSR_RECORDER_ERROR_H
+#define GSR_RECORDER_ERROR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The negated value of each error is the exit code that gpu-screen-recorder exits with */
+typedef enum {
+ GSR_ERROR_OK = 0,
+ GSR_ERROR_GENERIC = -1,
+ GSR_ERROR_AUDIO_SETUP_FAILED = -2,
+ GSR_ERROR_CAPTURE_FAILED = -3,
+ GSR_ERROR_VIDEO_CODEC_QUERY_FAILED = -11,
+ GSR_ERROR_OPENGL_LOAD_FAILED = -22,
+ GSR_ERROR_AUDIO_DEVICE_NOT_FOUND = -50,
+ GSR_ERROR_MONITOR_NOT_FOUND = -51,
+ GSR_ERROR_NO_VIDEO_CODEC_AVAILABLE = -52,
+ GSR_ERROR_VIDEO_CODEC_RESOLUTION_UNSUPPORTED = -53,
+ GSR_ERROR_VIDEO_CODEC_UNSUPPORTED = -54
+} gsr_error;
+
+static inline int gsr_error_to_exit_code(int error) {
+ return error < 0 ? -error : 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GSR_RECORDER_ERROR_H */