aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2026-08-06 13:02:59 +0200
committerdec05eba <dec05eba@protonmail.com>2026-08-06 13:02:59 +0200
commite31968fc4074df739c00947b993ee19be4ef1caa (patch)
tree57f2d57cd9392bf28fe57e82bc25017a4c4d9d59 /include
parent5db30f3fb99545524fc80f87ecc488972aec1711 (diff)
Faster shutdown time when several gb of replay data is in ram
Diffstat (limited to 'include')
-rw-r--r--include/encoder/encoder.h6
-rw-r--r--include/recorder/recorder.h3
-rw-r--r--include/replay_buffer/replay_buffer.h8
3 files changed, 15 insertions, 2 deletions
diff --git a/include/encoder/encoder.h b/include/encoder/encoder.h
index b46deb5..15009f1 100644
--- a/include/encoder/encoder.h
+++ b/include/encoder/encoder.h
@@ -41,7 +41,11 @@ typedef struct {
} gsr_encoder;
bool gsr_encoder_init(gsr_encoder *self, gsr_replay_storage replay_storage, size_t replay_buffer_num_packets, double replay_buffer_time, const char *replay_directory);
-void gsr_encoder_deinit(gsr_encoder *self);
+/*
+ When |exiting| is set the memory of the replay buffer is left to the operating system to free, which makes
+ this much faster when the replay buffer holds several gigabytes of data. See gsr_replay_buffer_destroy_at_exit.
+*/
+void gsr_encoder_deinit(gsr_encoder *self, bool exiting);
void gsr_encoder_receive_packets(gsr_encoder *self, AVCodecContext *codec_context, int64_t pts, int stream_index);
/* Returns the id to the recording destination, or -1 on error */
diff --git a/include/recorder/recorder.h b/include/recorder/recorder.h
index 5721a98..9ff13bd 100644
--- a/include/recorder/recorder.h
+++ b/include/recorder/recorder.h
@@ -39,7 +39,8 @@ typedef struct {
/* Returns NULL on failure and sets |error| to a |gsr_error| value */
gsr_recorder* gsr_recorder_create(const gsr_recorder_params *params, const gsr_recorder_callbacks *callbacks, int *error);
-void gsr_recorder_destroy(gsr_recorder *self);
+/* This is only called when the program is exiting, so memory that the operating system frees on exit isn't free'd. Only set exiting to true if the program is exiting */
+void gsr_recorder_destroy(gsr_recorder *self, bool exiting);
/* Returns a |gsr_error| value. Records until gsr_recorder_stop is called or until the capture target is gone */
int gsr_recorder_run(gsr_recorder *self);
diff --git a/include/replay_buffer/replay_buffer.h b/include/replay_buffer/replay_buffer.h
index c036b1c..3ac452a 100644
--- a/include/replay_buffer/replay_buffer.h
+++ b/include/replay_buffer/replay_buffer.h
@@ -14,6 +14,7 @@ typedef struct {
struct gsr_replay_buffer {
void (*destroy)(gsr_replay_buffer *self);
+ void (*destroy_at_exit)(gsr_replay_buffer *self);
bool (*append)(gsr_replay_buffer *self, const AVPacket *av_packet, double timestamp);
void (*clear)(gsr_replay_buffer *self);
AVPacket* (*iterator_get_packet)(gsr_replay_buffer *self, gsr_replay_buffer_iterator iterator);
@@ -32,6 +33,13 @@ struct gsr_replay_buffer {
gsr_replay_buffer* gsr_replay_buffer_create(gsr_replay_storage replay_storage, const char *replay_directory, double replay_buffer_time, size_t replay_buffer_num_packets);
void gsr_replay_buffer_destroy(gsr_replay_buffer *self);
+/*
+ Only frees the resources that the operating system doesn't free when the process exits, such as files,
+ and leaves the memory to the operating system to free. Freeing a replay buffer that holds several gigabytes
+ of data takes seconds, which is time wasted when the process is exiting anyway.
+ |self| can't be used after this.
+*/
+void gsr_replay_buffer_destroy_at_exit(gsr_replay_buffer *self);
bool gsr_replay_buffer_append(gsr_replay_buffer *self, const AVPacket *av_packet, double timestamp);
void gsr_replay_buffer_clear(gsr_replay_buffer *self);