Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,39 @@ describe("LinuxNativeCaptureSession", () => {
expect(helper.stdinWrites).not.toContain("resume\n");
});

it("closes the cursor pause range when the helper stops while paused, before stop() (#1637)", async () => {
const now = vi.spyOn(Date, "now").mockReturnValue(900);
const session = newSession();
await startReady(session);

emitCaptureStarted(1_000);
emitCursorSample(1_100);
await flushStdout();

now.mockReturnValue(1_200);
session.pause();
emitCursorSample(1_300);
await flushStdout();

now.mockReturnValue(1_500);
helper.emitEvent({
event: "capture-stopped",
timestampMs: 1_500,
path: "/tmp/recording.mp4",
durationMs: 200,
frames: 6,
dropped: 0,
});
await flushStdout();

now.mockReturnValue(1_600);
const stopping = session.stop();
helper.emit("exit", 0, null);
const result = await stopping;

expect(result.cursor.samples.map((sample) => sample.timeMs)).toEqual([100]);
});

/**
* A non-fatal `error` event after the first frame does not end the capture;
* a later wait is still satisfied.
Expand Down
20 changes: 12 additions & 8 deletions electron/native-bridge/capture/linuxNativeCaptureSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,16 @@ export class LinuxNativeCaptureSession {
this.cursorPauseStartedAtMs = null;
}

/**
* The cursor telemetry of a finished take, without its paused stretches. A take can
* end while paused, and the helper can end it before `stop()` runs: the open pause
* closes here, where every stopped snapshot is built.
*/
private stoppedCursorData(endMs?: number) {
this.completeCursorPauseRange(endMs);
return compactCursorTelemetryPauseRanges(this.cursor.toRecordingData(), this.cursorPauseRanges);
}

get isPaused() {
return this.paused;
}
Expand Down Expand Up @@ -535,10 +545,7 @@ export class LinuxNativeCaptureSession {
durationMs: Math.round(salvage.durationSec * 1000),
frames: salvage.videoSamples,
droppedFrames: 0,
cursor: compactCursorTelemetryPauseRanges(
this.cursor.toRecordingData(),
this.cursorPauseRanges,
),
cursor: this.stoppedCursorData(),
...(this.sourceKind ? { sourceKind: this.sourceKind } : {}),
...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}),
...(this.audioLost ? { audioLost: true as const } : {}),
Expand Down Expand Up @@ -696,10 +703,7 @@ export class LinuxNativeCaptureSession {
durationMs: payload.durationMs,
frames: payload.frames,
droppedFrames: payload.dropped,
cursor: compactCursorTelemetryPauseRanges(
this.cursor.toRecordingData(),
this.cursorPauseRanges,
),
cursor: this.stoppedCursorData(payload.timestampMs),
...(this.sourceKind ? { sourceKind: this.sourceKind } : {}),
...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}),
...(this.audioLost ? { audioLost: true as const } : {}),
Expand Down
Loading