Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure gst EOS is correctly processed #14

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

In X11 mode, it may support other desktops (untested); in Wayland mode, other desktops are not supported (but may "work").

Requires:
Requires the following (development) packages:

* Gtk 4
* Vala
Expand Down Expand Up @@ -126,3 +126,11 @@ Licence : GPL v3 or later
(c) Jonathan Hudson 2021-2023

Inspired by other fine tools such as **kooha**, **peek** and **green-recorder**; I appreciate the other developer's pain with the ever moving targets of Gnome, Wayland, Pipewire and XDG Portal, particularly `kooha`'s guidance on the workings of GStreamer has been extremely useful.

### Bug reports

Please provide the `stderr` information (run wayfarer from a terminal).
Bug reports should provide:

* Operating system and version
* Details of window manger / desktop environment
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('wayfarer', 'vala', 'c', version : '1.2.1')
project('wayfarer', 'vala', 'c', version : '1.2.2')

# For now, as some replacements are not well defined.

Expand Down
2 changes: 1 addition & 1 deletion src/encoders.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Encoders {
{"x264enc",
{{"profile", "baseline"}},
{{"qp-max", 17},
{"speed-preset", "super-fast"},
{"speed-preset", "superfast"},
{"threads", Utils.preferred_threads()}},
},
{"opusenc", {}, {}},
Expand Down
2 changes: 2 additions & 0 deletions src/gst-recording.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class MediaRecorder : GLib.Object {
private State state;
private Pipeline pipeline;
public signal void report_gst_error(string s);
public signal void stream_ended();

public MediaRecorder() {
state = State.NONE;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class MediaRecorder : GLib.Object {
pipeline.set_state (Gst.State.NULL);
b.remove_watch();
bus = null;
stream_ended();
return false;
default:
break;
Expand Down
16 changes: 11 additions & 5 deletions src/recman.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ScreenCap : Object {
public Options options;

public signal void report_gst_error(string s);
public signal void stream_ended();

STATE astate = STATE.None;

Expand All @@ -45,6 +46,10 @@ public class ScreenCap : Object {
mediarec.report_gst_error.connect((s) => {
report_gst_error(s);
});
mediarec.stream_ended.connect (() => {
stderr.printf("End of stream!!!\n");
stream_ended();
});
}

public bool capture(GenericArray<PortalManager.SourceInfo?>sources, out string fname) {
Expand Down Expand Up @@ -202,17 +207,18 @@ public class ScreenCap : Object {
return at;
}

public void post_process(bool forced = false) {
stderr.printf("*DBG* Post state %s forced=%s\n", astate.to_string(), forced.to_string());
public void post_process() {
if (astate != STATE.None) {
stderr.printf("*DBG* Post state %s\n", astate.to_string());
mediarec.stop_recording();
if (true) {
mediarec.force_quit();
}
}
astate = STATE.None;
}

public void force_stop() {
mediarec.force_quit();
}

public void set_bbox(int x0, int y0, int x1, int y1) {
/**
if(x1 > x0) {
Expand Down
50 changes: 31 additions & 19 deletions src/wayfarer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Wayfarer : Gtk.Application {
private bool ctrlseta;
private bool ctrlsets;
private bool stophide;
private bool forced;

public static bool show_version;

Expand Down Expand Up @@ -273,8 +274,12 @@ public class Wayfarer : Gtk.Application {
window.set_icon_name("wayfarer");

sc = new ScreenCap();
sc.stream_ended.connect(() => {
cleanup_session();
});

startbutton.clicked.connect(() => {
forced = false;
stderr.printf("*DBG* Start with %s %d\n", pw_session.to_string(), fd);
if(pw_session == PWSession.X11 || fd > 0) {
start_recording(validaudio);
Expand All @@ -288,6 +293,9 @@ public class Wayfarer : Gtk.Application {
sc.report_gst_error.connect((s) => {
do_stop_action();
statuslabel.label = s;
if(forced) {
cleanup_session();
}
});

var at = sc.get_audio_sources();
Expand Down Expand Up @@ -347,11 +355,8 @@ public class Wayfarer : Gtk.Application {
pw = new PortalManager(conf.restore_token);
pw.closed.connect(() => {
stderr.printf("Portal cancelled / closed remotely [%d]\n", fd);
if(fd > 0) {
Posix.close(fd);
fd = -1;
do_stop_action(true);
}
forced = true;
do_stop_action();
});

pw.completed.connect((result) => {
Expand Down Expand Up @@ -573,7 +578,7 @@ public class Wayfarer : Gtk.Application {
startbutton.set_name((act) ? "record" : "GtkButton");
}

private void do_stop_action(bool forced = false) {
private void do_stop_action() {
if(timerid > 0) {
Source.remove(timerid);
timerid = 0;
Expand All @@ -585,22 +590,29 @@ public class Wayfarer : Gtk.Application {
nt.close_last();
stopwindow.hide();
window.show();
sc.post_process(forced);
if (forced) {
} else {
if(pw_session == PWSession.WAYLAND && pw_result == PortalManager.Result.OK) {
stderr.printf("*DBG* pw.close\n");
pw.close();
}
}
stderr.printf("*DBG* close FD %d\n", fd);
Posix.close(fd);
fd = -1;
//startbutton.sensitive = false;
sc.post_process();
}

private void cleanup_session() {
if(pw_session == PWSession.WAYLAND && pw_result == PortalManager.Result.OK) {
stderr.printf("*DBG* pw.close\n");
pw.close();
}
if(fd != -1) {
stderr.printf("*DBG* close FD %d\n", fd);
Posix.close(fd);
fd = -1;
}
have_area = 0;
set_start_active(false);
update_status_label();
}

if(forced && sc.options.mediatype == "mp4") {
stderr.printf("delete %s on forced close\n", filename);
statuslabel.label = "mp4 file deleted on forced close";
Posix.unlink(filename);
}
}

private void clean_up() {
conf.media_type = mediasel.active_id;
Expand Down