aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--README.md7
-rw-r--r--include/replay_buffer.h10
-rw-r--r--meson.build2
-rw-r--r--project.conf2
-rw-r--r--src/codec_query/vaapi.c2
-rw-r--r--src/main.cpp12
-rw-r--r--src/replay_buffer.c60
8 files changed, 58 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index 00f92e1..5172b61 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ tests/compile_commands.json
.vscode/
build/
+debug-build/
*.o
gpu-screen-recorder
diff --git a/README.md b/README.md
index 997d9a8..a8c4c8a 100644
--- a/README.md
+++ b/README.md
@@ -85,9 +85,7 @@ These are the dependencies needed to build GPU Screen Recorder:
* libva (and libva-drm)
* libdrm
* libcap
-* wayland-client
-* wayland-egl
-* wayland-scanner
+* wayland (wayland-client, wayland-egl, wayland-scanner)
## Runtime dependencies
There are also additional dependencies needed at runtime depending on your GPU vendor:
@@ -137,7 +135,8 @@ This can be used for example to show a notification when a replay has been saved
The replay buffer is stored in ram (as encoded video), so don't use a too large replay time and/or video quality unless you have enough ram to store it.
## Recording while using replay/streaming
You can record a regular video while using replay/streaming by launching GPU Screen Recorder with the `-ro` option to specify a directory where to save the recording.\
-To start/stop (and save) recording use the SIGRTMIN signal, for example `pkill -SIGRTMIN -f gpu-screen-recorder`. The name of the video will be displayed in stdout when saving the video.
+To start/stop (and save) recording use the SIGRTMIN signal, for example `pkill -SIGRTMIN -f gpu-screen-recorder`. The name of the video will be displayed in stdout when saving the video.\
+This way of recording while using replay/streaming is more efficient than running GPU Screen Recorder multiple times since this way it only records the screen and encodes the video once.
## Controlling GPU Screen Recorder remotely
To save a video in replay mode, you need to send signal SIGUSR1 to gpu screen recorder. You can do this by running `pkill -SIGUSR1 -f gpu-screen-recorder`.\
To stop recording send SIGINT to gpu screen recorder. You can do this by running `pkill -SIGINT -f gpu-screen-recorder` or pressing `Ctrl-C` in the terminal that runs gpu screen recorder. When recording a regular non-replay video this will also save the video.\
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 */
diff --git a/meson.build b/meson.build
index 521c1c0..5874b95 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,4 @@
-project('gpu-screen-recorder', ['c', 'cpp'], version : '5.4.0', default_options : ['warning_level=2'])
+project('gpu-screen-recorder', ['c', 'cpp'], version : '5.4.1', default_options : ['warning_level=2'])
add_project_arguments('-Wshadow', language : ['c', 'cpp'])
if get_option('buildtype') == 'debug'
diff --git a/project.conf b/project.conf
index 7de29ff..a9a83ae 100644
--- a/project.conf
+++ b/project.conf
@@ -1,7 +1,7 @@
[package]
name = "gpu-screen-recorder"
type = "executable"
-version = "5.4.0"
+version = "5.4.1"
platforms = ["posix"]
[config]
diff --git a/src/codec_query/vaapi.c b/src/codec_query/vaapi.c
index 2c74d96..8930a6c 100644
--- a/src/codec_query/vaapi.c
+++ b/src/codec_query/vaapi.c
@@ -116,7 +116,7 @@ static bool get_supported_video_codecs(VADisplay va_dpy, gsr_supported_video_cod
int va_minor = 0;
if(vaInitialize(va_dpy, &va_major, &va_minor) != VA_STATUS_SUCCESS) {
fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vaapi: vaInitialize failed\n");
- goto fail;
+ return false;
}
int num_profiles = vaMaxNumProfiles(va_dpy);
diff --git a/src/main.cpp b/src/main.cpp
index 117d5fd..73af76d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1270,13 +1270,13 @@ static void save_replay_async(AVCodecContext *video_codec_context, int video_str
}
const size_t audio_start_index = gsr_replay_buffer_find_keyframe(replay_buffer, video_start_index, video_stream_index, true);
- if(audio_start_index == (size_t)-1) {
- fprintf(stderr, "gsr error: failed to save replay: failed to find an audio keyframe. perhaps replay was saved too fast, before anything has been recorded\n");
- return;
- }
+ // if(audio_start_index == (size_t)-1) {
+ // fprintf(stderr, "gsr error: failed to save replay: failed to find an audio keyframe. perhaps replay was saved too fast, before anything has been recorded\n");
+ // return;
+ // }
const int64_t video_pts_offset = gsr_replay_buffer_get_packet_at_index(replay_buffer, video_start_index)->packet.pts;
- const int64_t audio_pts_offset = gsr_replay_buffer_get_packet_at_index(replay_buffer, audio_start_index)->packet.pts;
+ const int64_t audio_pts_offset = audio_start_index == (size_t)-1 ? 0 : gsr_replay_buffer_get_packet_at_index(replay_buffer, audio_start_index)->packet.pts;
gsr_replay_buffer cloned_replay_buffer;
if(!gsr_replay_buffer_clone(replay_buffer, &cloned_replay_buffer)) {
@@ -3665,7 +3665,7 @@ int main(int argc, char **argv) {
if(new_replay_recording_state) {
std::lock_guard<std::mutex> lock(audio_filter_mutex);
replay_recording_items.clear();
- replay_recording_filepath = create_new_recording_filepath_from_timestamp(arg_parser.replay_recording_directory, "Recording", file_extension, arg_parser.date_folders);
+ replay_recording_filepath = create_new_recording_filepath_from_timestamp(arg_parser.replay_recording_directory, "Video", file_extension, arg_parser.date_folders);
replay_recording_start_result = start_recording_create_streams(replay_recording_filepath.c_str(), arg_parser.container_format, video_codec_context, audio_tracks, hdr, capture);
if(replay_recording_start_result.av_format_context) {
const size_t video_recording_destination_id = gsr_encoder_add_recording_destination(&encoder, video_codec_context, replay_recording_start_result.av_format_context, replay_recording_start_result.video_stream, video_frame->pts);
diff --git a/src/replay_buffer.c b/src/replay_buffer.c
index d858992..739b02b 100644
--- a/src/replay_buffer.c
+++ b/src/replay_buffer.c
@@ -54,7 +54,7 @@ bool gsr_replay_buffer_init(gsr_replay_buffer *self, size_t replay_buffer_num_pa
assert(replay_buffer_num_packets > 0);
memset(self, 0, sizeof(*self));
self->mutex_initialized = false;
- self->owns_mutex = true;
+ self->original_replay_buffer = NULL;
if(pthread_mutex_init(&self->mutex, NULL) != 0)
return false;
@@ -70,10 +70,28 @@ bool gsr_replay_buffer_init(gsr_replay_buffer *self, size_t replay_buffer_num_pa
return true;
}
-void gsr_replay_buffer_deinit(gsr_replay_buffer *self) {
+static void gsr_replay_buffer_lock(gsr_replay_buffer *self) {
+ if(self->original_replay_buffer) {
+ gsr_replay_buffer_lock(self->original_replay_buffer);
+ return;
+ }
+
if(self->mutex_initialized)
pthread_mutex_lock(&self->mutex);
+}
+static void gsr_replay_buffer_unlock(gsr_replay_buffer *self) {
+ if(self->original_replay_buffer) {
+ gsr_replay_buffer_unlock(self->original_replay_buffer);
+ return;
+ }
+
+ if(self->mutex_initialized)
+ pthread_mutex_unlock(&self->mutex);
+}
+
+void gsr_replay_buffer_deinit(gsr_replay_buffer *self) {
+ gsr_replay_buffer_lock(self);
for(size_t i = 0; i < self->num_packets; ++i) {
if(self->packets[i]) {
gsr_av_packet_unref(self->packets[i]);
@@ -81,9 +99,7 @@ void gsr_replay_buffer_deinit(gsr_replay_buffer *self) {
}
}
self->num_packets = 0;
-
- if(self->mutex_initialized)
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
if(self->packets) {
free(self->packets);
@@ -93,17 +109,19 @@ void gsr_replay_buffer_deinit(gsr_replay_buffer *self) {
self->capacity_num_packets = 0;
self->index = 0;
- if(self->mutex_initialized && self->owns_mutex) {
+ if(self->mutex_initialized && !self->original_replay_buffer) {
pthread_mutex_destroy(&self->mutex);
self->mutex_initialized = false;
}
+
+ self->original_replay_buffer = NULL;
}
bool gsr_replay_buffer_append(gsr_replay_buffer *self, const AVPacket *av_packet, double timestamp) {
- pthread_mutex_lock(&self->mutex);
+ gsr_replay_buffer_lock(self);
gsr_av_packet *packet = gsr_av_packet_create(av_packet, timestamp);
if(!packet) {
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
return false;
}
@@ -118,12 +136,12 @@ bool gsr_replay_buffer_append(gsr_replay_buffer *self, const AVPacket *av_packet
if(self->num_packets > self->capacity_num_packets)
self->num_packets = self->capacity_num_packets;
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
return true;
}
void gsr_replay_buffer_clear(gsr_replay_buffer *self) {
- pthread_mutex_lock(&self->mutex);
+ gsr_replay_buffer_lock(self);
for(size_t i = 0; i < self->num_packets; ++i) {
if(self->packets[i]) {
gsr_av_packet_unref(self->packets[i]);
@@ -132,7 +150,7 @@ void gsr_replay_buffer_clear(gsr_replay_buffer *self) {
}
self->num_packets = 0;
self->index = 0;
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
}
gsr_av_packet* gsr_replay_buffer_get_packet_at_index(gsr_replay_buffer *self, size_t index) {
@@ -147,17 +165,17 @@ gsr_av_packet* gsr_replay_buffer_get_packet_at_index(gsr_replay_buffer *self, si
return self->packets[offset];
}
-bool gsr_replay_buffer_clone(const gsr_replay_buffer *self, gsr_replay_buffer *destination) {
- pthread_mutex_lock(&destination->mutex);
+bool gsr_replay_buffer_clone(gsr_replay_buffer *self, gsr_replay_buffer *destination) {
+ gsr_replay_buffer_lock(self);
memset(destination, 0, sizeof(*destination));
- destination->owns_mutex = false;
+ destination->original_replay_buffer = self;
destination->mutex = self->mutex;
destination->capacity_num_packets = self->capacity_num_packets;
destination->mutex_initialized = self->mutex_initialized;
destination->index = self->index;
destination->packets = calloc(destination->capacity_num_packets, sizeof(gsr_av_packet*));
if(!destination->packets) {
- pthread_mutex_unlock(&destination->mutex);
+ gsr_replay_buffer_unlock(self);
return false;
}
@@ -166,17 +184,17 @@ bool gsr_replay_buffer_clone(const gsr_replay_buffer *self, gsr_replay_buffer *d
destination->packets[i] = gsr_av_packet_ref(self->packets[i]);
}
- pthread_mutex_unlock(&destination->mutex);
+ gsr_replay_buffer_unlock(self);
return true;
}
/* Binary search */
size_t gsr_replay_buffer_find_packet_index_by_time_passed(gsr_replay_buffer *self, int seconds) {
- pthread_mutex_lock(&self->mutex);
+ gsr_replay_buffer_lock(self);
const double now = clock_get_monotonic_seconds();
if(self->num_packets == 0) {
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
return 0;
}
@@ -199,14 +217,14 @@ size_t gsr_replay_buffer_find_packet_index_by_time_passed(gsr_replay_buffer *sel
}
}
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
return index;
}
size_t gsr_replay_buffer_find_keyframe(gsr_replay_buffer *self, size_t start_index, int stream_index, bool invert_stream_index) {
assert(start_index < self->num_packets);
size_t keyframe_index = (size_t)-1;
- pthread_mutex_lock(&self->mutex);
+ gsr_replay_buffer_lock(self);
for(size_t i = start_index; i < self->num_packets; ++i) {
const gsr_av_packet *packet = gsr_replay_buffer_get_packet_at_index(self, i);
if((packet->packet.flags & AV_PKT_FLAG_KEY) && (invert_stream_index ? packet->packet.stream_index != stream_index : packet->packet.stream_index == stream_index)) {
@@ -214,6 +232,6 @@ size_t gsr_replay_buffer_find_keyframe(gsr_replay_buffer *self, size_t start_ind
break;
}
}
- pthread_mutex_unlock(&self->mutex);
+ gsr_replay_buffer_unlock(self);
return keyframe_index;
}