Skip to content
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
8 changes: 4 additions & 4 deletions PARITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ Status of each Windows feature on Linux. This file describes the tree it ships w
| Feature | Linux | Files |
|---|---|---|
| Record a region to MP4 | working on X11. Tray **Record video** and `opensnip --record`. | `linux/App.cs`, `linux/RecordingSession.cs`, `linux/FramePump.cs` |
| Wayland recording | missing. The portal ScreenCast API is not wired. The app reports that recording needs an X11 session. | `linux/App.cs` |
| Wayland recording | partial. ScreenCast portal and GStreamer PipeWire plugin feed cropped frames to ffmpeg; share the selected monitor. Restore tokens persist when supported. Pause, mute, audio and countdown use the existing pipeline. Requires GStreamer tools, PipeWire, video conversion/crop/rate plugins. Monitor geometry must be identifiable; mixed-DPI layouts may be rejected. | `linux/PortalScreenCast.cs`, `linux/FramePump.cs`, `linux/RecordingSession.cs`, `linux/App.cs` |
| Record the window under the cursor | working on X11. | `linux/OverlayWindow.cs` |
| One monitor, even dimensions, 16 px minimum | working | `linux/RecordGeometry.cs` |
| 3-2-1 countdown | working | `linux/RecordingChrome.cs` |
| Red outline | working | `linux/RecordingChrome.cs` |
| Red outline | working on X11; Wayland uses Xwayland outlines when available. | `linux/RecordingChrome.cs` |
| Pause, microphone mute, stop, discard | working | `linux/RecordingChrome.cs`, `linux/RecordingSession.cs` |
| Outline and bar left out of the video | working on X11. Those rectangles are rebuilt from the wallpaper pixmap and the windows underneath. | `linux/X11FrameSource.cs` |
| Outline and bar left out of the video | working on X11. Those rectangles are rebuilt from the wallpaper pixmap and the windows underneath. Wayland cannot exclude the outline or controls; controls may appear for full-monitor recordings. | `linux/X11FrameSource.cs` |
| System audio | partial. PulseAudio or PipeWire monitor source through `pactl` and `ffmpeg`. Video only when `pactl` or a monitor source is missing. | `linux/AudioDevices.cs`, `linux/FfmpegPlan.cs` |
| Microphone, off until enabled | partial. Same `pactl` dependency. Mute keeps a silent stream so paused segments stay compatible. | `linux/AudioDevices.cs` |
| Hardware H.264 | partial. Software libx264 (CRF 18 high, 28 standard). VAAPI and NVENC are not selected. | `linux/FfmpegPlan.cs` |
| 30 or 60 fps | working | `linux/FfmpegPlan.cs`, `linux/SettingsWindow.cs` |
| Mouse cursor in the video | working. XFixes cursor image. | `linux/X11FrameSource.cs` |
| Mouse cursor in the video | working on X11 (XFixes); Wayland requests an embedded cursor when the portal supports it. | `linux/X11FrameSource.cs`, `linux/PortalScreenCast.cs` |
| Copy the MP4 | partial. `text/uri-list` through `xclip` or `wl-copy`. | `linux/ClipboardService.cs`, `linux/FileUri.cs` |
| Preview still that plays on click | working. Play badge; click opens the file. The preview stays at least 8 seconds. | `linux/ThumbnailWindow.cs`, `linux/App.cs` |
| Drag the video preview out | missing | `linux/ThumbnailWindow.cs` |
Expand Down
18 changes: 14 additions & 4 deletions linux/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@ public async void StartRecording()
await ShowErrorAsync("Screen recording needs ffmpeg.");
return;
}
if (PlatformInfo.IsWayland || !PlatformInfo.HasDisplay)
if (!PlatformInfo.IsWayland && !PlatformInfo.HasDisplay)
{
await ShowErrorAsync("Screen recording needs an X11 session.");
await ShowErrorAsync("Screen recording needs a desktop session.");
return;
}

PortalScreenCast portal = null;
_busy = true;
try
{
Expand All @@ -414,7 +415,9 @@ public async void StartRecording()
var region = await OverlayWindow.SelectAsync(frame, Settings, WindowsFor(frame), record: true);
if (region is not { } selected) return;

var monitors = X11Monitors.Query();
var layouts = OverlaySession.ReadLayouts(frame);
IReadOnlyList<PixelRect> monitors = PlatformInfo.IsWayland
? layouts.Select(m => m.Bounds).ToArray() : X11Monitors.Query();
if (monitors.Count == 0)
monitors = new[] { new PixelRect(0, 0, frame.Width, frame.Height) };
if (!RecordGeometry.TryNormalize(selected, monitors, out var area))
Expand All @@ -423,10 +426,16 @@ public async void StartRecording()
return;
}

if (PlatformInfo.IsWayland)
{
portal = await PortalScreenCast.OpenAsync(Settings.RecordCursor);
portal.SetRegion(area, layouts);
}
var audio = await Task.Run(AudioDevices.Discover);
string system = Settings.RecordSystemAudio ? audio.SystemSource : null;
string mic = Settings.RecordMicrophone ? audio.ResolveMicrophone(Settings.MicrophoneDevice) : null;
var session = new RecordingSession(area, Settings, system, mic);
var session = new RecordingSession(area, Settings, system, mic, portal);
portal = null;
session.Saved += (path, preview) => Dispatcher.UIThread.Post(() => _ = OnRecordingSavedAsync(session, path, preview));
session.Failed += message => Dispatcher.UIThread.Post(() =>
{
Expand Down Expand Up @@ -461,6 +470,7 @@ public async void StartRecording()
}
finally
{
portal?.Dispose();
_busy = false;
QuitIfIdle();
}
Expand Down
2 changes: 1 addition & 1 deletion linux/DBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OpenSnip;

sealed record PortalResponse(string Path, uint Code, Dictionary<string, VariantValue> Results);

static class DBus
static partial class DBus
{
static string SessionAddress
{
Expand Down
45 changes: 39 additions & 6 deletions linux/FramePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ sealed class FramePump : IDisposable
{
readonly PixelRect _area;
readonly EncodeSpec _spec;
readonly PortalScreenCast _portal;
Process _capture;
readonly Func<long[]> _exclude;
readonly object _gate = new();
readonly StringBuilder _stderr = new();
Expand All @@ -25,9 +27,10 @@ sealed class FramePump : IDisposable
volatile bool _failed;
bool _disposed;

public FramePump(PixelRect area, EncodeSpec spec, Func<long[]> exclude)
public FramePump(PixelRect area, EncodeSpec spec, Func<long[]> exclude, PortalScreenCast portal = null)
{
_area = area;
_portal = portal;
_spec = spec;
_exclude = exclude;
}
Expand All @@ -40,8 +43,11 @@ public void Start()
_run = true;
_thread = new Thread(Run) { IsBackground = true, Name = "OpenSnip recording" };
_thread.Start();
if (!_started.Wait(8000))
throw new InvalidOperationException(_error ?? "ffmpeg did not start.");
if (!_started.Wait(_portal == null ? 8000 : 15000))
{
Stop();
throw new InvalidOperationException(_error ?? "Screen capture did not start.");
}
if (_failed)
throw new InvalidOperationException(string.IsNullOrWhiteSpace(_error) ? "ffmpeg did not start." : _error);
}
Expand All @@ -60,6 +66,7 @@ public CapturedFrame CopyLatest()
public void Stop()
{
_run = false;
try { if (_capture != null && !_capture.HasExited) _capture.Kill(entireProcessTree: true); } catch { }
if (_thread != null && !_thread.Join(6000))
{
try { _process?.Kill(entireProcessTree: true); } catch { }
Expand All @@ -75,14 +82,25 @@ public void Dispose()
try { Stop(); } catch { }
_started.Dispose();
try { _process?.Dispose(); } catch { }
try { _capture?.Dispose(); } catch { }
}

void Run()
{
X11FrameSource source = null;
try
{
source = new X11FrameSource(_area.X, _area.Y, _area.Width, _area.Height);
if (_portal == null) source = new X11FrameSource(_area.X, _area.Y, _area.Width, _area.Height);
else
{
_capture = _portal.StartFrames(_spec.Framerate);
_capture.ErrorDataReceived += (_, e) =>
{
if (e.Data == null) return;
lock (_stderr) { if (_stderr.Length > 8000) _stderr.Clear(); _stderr.AppendLine(e.Data); }
};
_capture.BeginErrorReadLine();
}
var psi = new ProcessStartInfo("ffmpeg")
{
UseShellExecute = false,
Expand Down Expand Up @@ -115,7 +133,7 @@ void Run()
}

var buffer = new byte[_area.Width * _area.Height * 4];
_started.Set();
if (_portal == null) _started.Set();
long interval = Stopwatch.Frequency / Math.Max(1, _spec.Framerate);
long next = Stopwatch.GetTimestamp();
while (_run)
Expand All @@ -136,7 +154,21 @@ void Run()
try { exclude = _exclude?.Invoke() ?? exclude; }
catch { exclude = Array.Empty<long>(); }

if (!source.Grab(buffer, exclude, _spec.Cursor))
if (_portal != null)
{
try
{
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(10));
_capture.StandardOutput.BaseStream.ReadExactlyAsync(buffer, timeout.Token).AsTask().GetAwaiter().GetResult();
_started.Set();
}
catch
{
if (_run) Fail(Stderr("Wayland screen capture stopped or timed out."));
break;
}
}
else if (!source.Grab(buffer, exclude, _spec.Cursor))
{
Fail("Screen capture failed.");
break;
Expand Down Expand Up @@ -168,6 +200,7 @@ void Run()
try { _input?.Close(); } catch { }
_started.Set();
try { source?.Dispose(); } catch { }
try { if (_capture != null && !_capture.HasExited) _capture.Kill(entireProcessTree: true); } catch { }
}
}

Expand Down
Loading
Loading