diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/encoder/encoder.h | 44 | ||||
-rw-r--r-- | include/encoder/video/video.h | 28 | ||||
-rw-r--r-- | include/replay_buffer.h | 10 |
3 files changed, 51 insertions, 31 deletions
diff --git a/include/encoder/encoder.h b/include/encoder/encoder.h new file mode 100644 index 0000000..8f03149 --- /dev/null +++ b/include/encoder/encoder.h @@ -0,0 +1,44 @@ +#ifndef GSR_ENCODER_H +#define GSR_ENCODER_H + +#include "../replay_buffer.h" +#include <stdbool.h> +#include <stdint.h> +#include <stddef.h> +#include <pthread.h> + +#define GSR_MAX_RECORDING_DESTINATIONS 128 + +typedef struct AVCodecContext AVCodecContext; +typedef struct AVFormatContext AVFormatContext; +typedef struct AVStream AVStream; + +typedef struct { + size_t id; + AVCodecContext *codec_context; + AVFormatContext *format_context; + AVStream *stream; + int64_t start_pts; + bool has_received_keyframe; +} gsr_encoder_recording_destination; + +typedef struct { + gsr_replay_buffer replay_buffer; + bool has_replay_buffer; + pthread_mutex_t file_write_mutex; + bool mutex_created; + + gsr_encoder_recording_destination recording_destinations[GSR_MAX_RECORDING_DESTINATIONS]; + size_t num_recording_destinations; + size_t recording_destination_id_counter; +} gsr_encoder; + +bool gsr_encoder_init(gsr_encoder *self, size_t replay_buffer_num_packets); +void gsr_encoder_deinit(gsr_encoder *self); + +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 */ +size_t gsr_encoder_add_recording_destination(gsr_encoder *self, AVCodecContext *codec_context, AVFormatContext *format_context, AVStream *stream, int64_t start_pts); +bool gsr_encoder_remove_recording_destination(gsr_encoder *self, size_t id); + +#endif /* GSR_ENCODER_H */ diff --git a/include/encoder/video/video.h b/include/encoder/video/video.h index 97f63e8..7a706b5 100644 --- a/include/encoder/video/video.h +++ b/include/encoder/video/video.h @@ -2,27 +2,13 @@ #define GSR_ENCODER_VIDEO_H #include "../../color_conversion.h" -#include "../../replay_buffer.h" #include <stdbool.h> -#include <stdint.h> -#include <pthread.h> #define GSR_MAX_RECORDING_DESTINATIONS 128 typedef struct gsr_video_encoder gsr_video_encoder; typedef struct AVCodecContext AVCodecContext; -typedef struct AVFormatContext AVFormatContext; typedef struct AVFrame AVFrame; -typedef struct AVStream AVStream; - -typedef struct { - size_t id; - AVCodecContext *codec_context; - AVFormatContext *format_context; - AVStream *stream; - int64_t start_pts; - bool has_received_keyframe; -} gsr_video_encoder_recording_destination; struct gsr_video_encoder { bool (*start)(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame); @@ -33,24 +19,12 @@ struct gsr_video_encoder { void *priv; bool started; - gsr_replay_buffer replay_buffer; - bool has_replay_buffer; - pthread_mutex_t file_write_mutex; - - gsr_video_encoder_recording_destination recording_destinations[GSR_MAX_RECORDING_DESTINATIONS]; - size_t num_recording_destinations; - size_t recording_destination_id; }; /* Set |replay_buffer_time_seconds| and |fps| to 0 to disable replay buffer */ -bool gsr_video_encoder_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame, size_t replay_buffer_num_packets); +bool gsr_video_encoder_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame); void gsr_video_encoder_destroy(gsr_video_encoder *encoder, AVCodecContext *video_codec_context); void gsr_video_encoder_copy_textures_to_frame(gsr_video_encoder *encoder, AVFrame *frame, gsr_color_conversion *color_conversion); void gsr_video_encoder_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color); -void gsr_video_encoder_receive_packets(gsr_video_encoder *encoder, AVCodecContext *codec_context, int64_t pts, int stream_index); -/* Returns the id to the recording destination, or -1 on error */ -size_t gsr_video_encoder_add_recording_destination(gsr_video_encoder *encoder, AVCodecContext *codec_context, AVFormatContext *format_context, AVStream *stream, int64_t start_pts); -bool gsr_video_encoder_remove_recording_destination(gsr_video_encoder *encoder, size_t id); - #endif /* GSR_ENCODER_VIDEO_H */ diff --git a/include/replay_buffer.h b/include/replay_buffer.h index e99b844..600b94b 100644 --- a/include/replay_buffer.h +++ b/include/replay_buffer.h @@ -5,6 +5,8 @@ #include <stdbool.h> #include <libavcodec/packet.h> +typedef struct gsr_replay_buffer gsr_replay_buffer; + typedef struct { AVPacket packet; int ref_counter; @@ -15,15 +17,15 @@ 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 { +struct gsr_replay_buffer { 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; + gsr_replay_buffer *original_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); @@ -32,7 +34,7 @@ bool gsr_replay_buffer_append(gsr_replay_buffer *self, const AVPacket *av_packet 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); +bool gsr_replay_buffer_clone(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 */ |