Stop recording when pipewire target window is closed or when pressing close in the desktop environments record button

This commit is contained in:
dec05eba
2024-07-19 22:08:04 +02:00
parent 739fab83ba
commit 637d306a24
4 changed files with 19 additions and 21 deletions

View File

@@ -68,6 +68,9 @@ typedef struct {
gsr_pipewire_data_version server_version; gsr_pipewire_data_version server_version;
gsr_pipewire_video_info video_info; gsr_pipewire_video_info video_info;
gsr_pipewire_dmabuf_data dmabuf_data; gsr_pipewire_dmabuf_data dmabuf_data;
bool started;
bool stopped;
} gsr_pipewire; } gsr_pipewire;
/* /*
@@ -79,5 +82,6 @@ bool gsr_pipewire_init(gsr_pipewire *self, int pipewire_fd, uint32_t pipewire_no
void gsr_pipewire_deinit(gsr_pipewire *self); void gsr_pipewire_deinit(gsr_pipewire *self);
bool gsr_pipewire_map_texture(gsr_pipewire *self, unsigned int texture_id, unsigned int cursor_texture_id, gsr_pipewire_region *region, gsr_pipewire_region *cursor_region, int *plane_fd); bool gsr_pipewire_map_texture(gsr_pipewire *self, unsigned int texture_id, unsigned int cursor_texture_id, gsr_pipewire_region *region, gsr_pipewire_region *cursor_region, int *plane_fd);
bool gsr_pipewire_recording_stopped(gsr_pipewire *self);
#endif /* GSR_PIPEWIRE_H */ #endif /* GSR_PIPEWIRE_H */

View File

@@ -25,9 +25,6 @@ typedef struct {
typedef struct { typedef struct {
gsr_capture_kms_params params; gsr_capture_kms_params params;
bool should_stop;
bool stop_is_error;
gsr_kms_client kms_client; gsr_kms_client kms_client;
gsr_kms_response kms_response; gsr_kms_response kms_response;
@@ -477,13 +474,7 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c
} }
static bool gsr_capture_kms_should_stop(gsr_capture *cap, bool *err) { static bool gsr_capture_kms_should_stop(gsr_capture *cap, bool *err) {
gsr_capture_kms *cap_kms = cap->priv; (void)cap;
if(cap_kms->should_stop) {
if(err)
*err = cap_kms->stop_is_error;
return true;
}
if(err) if(err)
*err = false; *err = false;
return false; return false;

View File

@@ -15,9 +15,6 @@
typedef struct { typedef struct {
gsr_capture_portal_params params; gsr_capture_portal_params params;
bool should_stop;
bool stop_is_error;
unsigned int input_texture_id; unsigned int input_texture_id;
unsigned int cursor_texture_id; unsigned int cursor_texture_id;
@@ -328,16 +325,10 @@ static int gsr_capture_portal_capture(gsr_capture *cap, AVFrame *frame, gsr_colo
} }
static bool gsr_capture_portal_should_stop(gsr_capture *cap, bool *err) { static bool gsr_capture_portal_should_stop(gsr_capture *cap, bool *err) {
gsr_capture_portal *cap_portal = cap->priv; gsr_capture_portal *self = cap->priv;
if(cap_portal->should_stop) {
if(err)
*err = cap_portal->stop_is_error;
return true;
}
if(err) if(err)
*err = false; *err = false;
return false; return gsr_pipewire_recording_stopped(&self->pipewire);
} }
static void gsr_capture_portal_capture_end(gsr_capture *cap, AVFrame *frame) { static void gsr_capture_portal_capture_end(gsr_capture *cap, AVFrame *frame) {

View File

@@ -246,6 +246,14 @@ static void on_param_changed_cb(void *user_data, uint32_t id, const struct spa_p
static void on_state_changed_cb(void *user_data, enum pw_stream_state old, enum pw_stream_state state, const char *error) { static void on_state_changed_cb(void *user_data, enum pw_stream_state old, enum pw_stream_state state, const char *error) {
(void)old; (void)old;
gsr_pipewire *self = user_data; gsr_pipewire *self = user_data;
if(state == PW_STREAM_STATE_STREAMING)
self->started = true;
if(self->started && state == PW_STREAM_STATE_PAUSED) {
self->started = false;
self->stopped = true;
}
fprintf(stderr, "gsr info: pipewire: stream %p state: \"%s\" (error: %s)\n", fprintf(stderr, "gsr info: pipewire: stream %p state: \"%s\" (error: %s)\n",
(void*)self->stream, pw_stream_state_as_string(state), (void*)self->stream, pw_stream_state_as_string(state),
error ? error : "none"); error ? error : "none");
@@ -627,3 +635,7 @@ bool gsr_pipewire_map_texture(gsr_pipewire *self, unsigned int texture_id, unsig
pthread_mutex_unlock(&self->mutex); pthread_mutex_unlock(&self->mutex);
return true; return true;
} }
bool gsr_pipewire_recording_stopped(gsr_pipewire *self) {
return self->stopped;
}