aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/recorder/replay_save.h10
-rw-r--r--include/replay_buffer/replay_buffer.h9
2 files changed, 17 insertions, 2 deletions
diff --git a/include/recorder/replay_save.h b/include/recorder/replay_save.h
index 7f48851..ac4eb98 100644
--- a/include/recorder/replay_save.h
+++ b/include/recorder/replay_save.h
@@ -37,14 +37,20 @@ typedef struct {
gsr_audio_pts_offset *audio_pts_offsets;
size_t num_audio_pts_offsets;
gsr_replay_buffer *cloned_replay_buffer;
+ /* The data that the replay buffer had before it was restarted, free'd on the replay save thread */
+ gsr_replay_buffer *restarted_replay_buffer_data;
gsr_encoder *encoder;
} gsr_replay_save;
void gsr_replay_save_init(gsr_replay_save *self);
bool gsr_replay_save_is_running(const gsr_replay_save *self);
-/* Returns false if the replay failed to start. |current_save_replay_seconds| can be GSR_SAVE_REPLAY_SECONDS_FULL to save the whole replay buffer */
-bool gsr_replay_save_start(gsr_replay_save *self, AVCodecContext *video_codec_context, int video_stream_index, const gsr_audio_capture *audio_capture, gsr_encoder *encoder, const gsr_recorder_settings *settings, const char *file_extension, bool hdr, gsr_video_sources *video_sources, int current_save_replay_seconds);
+/*
+ Returns false if the replay failed to start. |current_save_replay_seconds| can be GSR_SAVE_REPLAY_SECONDS_FULL to save the whole replay buffer.
+ The replay buffer of |encoder| is restarted (emptied) when |restart_replay| is set, which is done without blocking the
+ thread that appends to the replay buffer by free'ing the old data on the replay save thread.
+*/
+bool gsr_replay_save_start(gsr_replay_save *self, AVCodecContext *video_codec_context, int video_stream_index, const gsr_audio_capture *audio_capture, gsr_encoder *encoder, const gsr_recorder_settings *settings, const char *file_extension, bool hdr, gsr_video_sources *video_sources, int current_save_replay_seconds, bool restart_replay);
/* Returns true when the replay finished saving, in which case |success| and |output_filepath| are set. |output_filepath| is empty when nothing was saved */
bool gsr_replay_save_poll(gsr_replay_save *self, bool *success, const char **output_filepath);
/* Waits for an ongoing replay save to finish. Returns the same values as gsr_replay_save_poll */
diff --git a/include/replay_buffer/replay_buffer.h b/include/replay_buffer/replay_buffer.h
index 6e91103..c036b1c 100644
--- a/include/replay_buffer/replay_buffer.h
+++ b/include/replay_buffer/replay_buffer.h
@@ -21,6 +21,8 @@ struct gsr_replay_buffer {
uint8_t* (*iterator_get_packet_data)(gsr_replay_buffer *self, gsr_replay_buffer_iterator iterator);
/* The clone has to be destroyed before the replay buffer it clones is destroyed */
gsr_replay_buffer* (*clone)(gsr_replay_buffer *self);
+ /* Returns NULL on failure, in which case |self| is left untouched */
+ gsr_replay_buffer* (*take_data)(gsr_replay_buffer *self);
/* Returns {0, 0} if replay buffer is empty */
gsr_replay_buffer_iterator (*find_packet_index_by_time_passed)(gsr_replay_buffer *self, int seconds);
/* Returns {-1, 0} if not found */
@@ -38,6 +40,13 @@ AVPacket* gsr_replay_buffer_iterator_get_packet(gsr_replay_buffer *self, gsr_rep
uint8_t* gsr_replay_buffer_iterator_get_packet_data(gsr_replay_buffer *self, gsr_replay_buffer_iterator iterator);
/* The clone has to be destroyed before the replay buffer it clones is destroyed */
gsr_replay_buffer* gsr_replay_buffer_clone(gsr_replay_buffer *self);
+/*
+ Moves the data of |self| into a new replay buffer and leaves |self| empty and ready to be used again.
+ This is a cheap operation, unlike gsr_replay_buffer_clear, because freeing the data is deferred to
+ gsr_replay_buffer_destroy of the returned replay buffer, which can be done without blocking |self|.
+ Returns NULL on failure, in which case |self| is left untouched.
+*/
+gsr_replay_buffer* gsr_replay_buffer_take_data(gsr_replay_buffer *self);
/* Returns {0, 0} if replay buffer is empty */
gsr_replay_buffer_iterator gsr_replay_buffer_find_packet_index_by_time_passed(gsr_replay_buffer *self, int seconds);
/* Returns {-1, 0} if not found */