From 81f155bf6306a2aa378b03920ed2b6f44e013016 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 21 Apr 2025 23:02:29 +0200 Subject: Refactor video encoding packet receiving, replay buffer and finish SIGRTMIN for recording while replay/replaying. Add -ro option to specify the directory --- include/replay_buffer.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/replay_buffer.h (limited to 'include/replay_buffer.h') diff --git a/include/replay_buffer.h b/include/replay_buffer.h new file mode 100644 index 0000000..e99b844 --- /dev/null +++ b/include/replay_buffer.h @@ -0,0 +1,41 @@ +#ifndef GSR_REPLAY_BUFFER_H +#define GSR_REPLAY_BUFFER_H + +#include +#include +#include + +typedef struct { + AVPacket packet; + int ref_counter; + double timestamp; +} gsr_av_packet; + +gsr_av_packet* gsr_av_packet_create(const AVPacket *av_packet, double timestamp); +gsr_av_packet* gsr_av_packet_ref(gsr_av_packet *self); +void gsr_av_packet_unref(gsr_av_packet *self); + +typedef struct { + gsr_av_packet **packets; + size_t capacity_num_packets; + size_t num_packets; + size_t index; + pthread_mutex_t mutex; + bool mutex_initialized; + bool owns_mutex; +} gsr_replay_buffer; + +bool gsr_replay_buffer_init(gsr_replay_buffer *self, size_t replay_buffer_num_packets); +void gsr_replay_buffer_deinit(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); +gsr_av_packet* gsr_replay_buffer_get_packet_at_index(gsr_replay_buffer *self, size_t index); +/* The clone has to be deinitialized before the replay buffer it clones */ +bool gsr_replay_buffer_clone(const gsr_replay_buffer *self, gsr_replay_buffer *destination); +/* Returns 0 if replay buffer is empty */ +size_t gsr_replay_buffer_find_packet_index_by_time_passed(gsr_replay_buffer *self, int seconds); +/* Returns -1 if not found */ +size_t gsr_replay_buffer_find_keyframe(gsr_replay_buffer *self, size_t start_index, int stream_index, bool invert_stream_index); + +#endif /* GSR_REPLAY_BUFFER_H */ \ No newline at end of file -- cgit v1.2.3-70-g09d2