aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLena <lena@omega>2026-07-01 00:00:00 +0000
committerLena <lena@omega>2026-07-01 00:00:00 +0000
commit3cc5eff7d8d4b9a33633b99e2a82d3df8cdfd4d6 (patch)
treee5dce6fe0a90360db98950ba773fc2c3d1e92510
parent431a0e36f42ef3c44de4fd46f304ad2b38e4b3cd (diff)
downloadscrcpy-android-3cc5eff7d8d4b9a33633b99e2a82d3df8cdfd4d6.tar.gz
app: report whether a recording was actually written
MuxRecorder had a Listener interface that nothing implemented; every callback fired into a no-op. Delete it. stop() now returns whether a keyframe ever landed and the muxer ran, so Mirror can stop claiming "recording saved" when no file was written.
-rw-r--r--app/src/main/java/invalid/lena/scrcpy/Mirror.java7
-rw-r--r--app/src/main/java/invalid/lena/scrcpy/MuxRecorder.java45
-rw-r--r--app/src/main/java/invalid/lena/scrcpy/Session.java5
3 files changed, 21 insertions, 36 deletions
diff --git a/app/src/main/java/invalid/lena/scrcpy/Mirror.java b/app/src/main/java/invalid/lena/scrcpy/Mirror.java
index f6e249d..2c361da 100644
--- a/app/src/main/java/invalid/lena/scrcpy/Mirror.java
+++ b/app/src/main/java/invalid/lena/scrcpy/Mirror.java
@@ -260,8 +260,11 @@ public final class Mirror extends Activity {
private void toggleRecord() {
if (session == null) return;
if (session.isRecording()) {
- session.stopRecording();
- Toast.makeText(this, "recording saved", Toast.LENGTH_SHORT).show();
+ // stopRecording is false when no keyframe ever landed (still
+ // ARMED) - no file was written, so don't claim one was saved.
+ boolean saved = session.stopRecording();
+ Toast.makeText(this, saved ? "recording saved" : "recording discarded (no video)",
+ Toast.LENGTH_SHORT).show();
} else {
File dir = getExternalFilesDir(null);
if (dir == null) {
diff --git a/app/src/main/java/invalid/lena/scrcpy/MuxRecorder.java b/app/src/main/java/invalid/lena/scrcpy/MuxRecorder.java
index 457272e..d06551e 100644
--- a/app/src/main/java/invalid/lena/scrcpy/MuxRecorder.java
+++ b/app/src/main/java/invalid/lena/scrcpy/MuxRecorder.java
@@ -26,19 +26,9 @@ import java.nio.ByteBuffer;
// illegal). User can re-arm; a fresh output gets the new dimensions.
public final class MuxRecorder implements VideoRecorder {
- public interface Listener {
- // Fires on the recorder thread; main use is updating the UI's
- // record button label once writing actually begins (we may be
- // ARMED for many frames before a keyframe lands).
- default void onStarted(File out) {}
- default void onStopped(File out, long bytes) {}
- default void onError(Throwable t) {}
- }
-
private enum State { IDLE, ARMED, RECORDING, ERROR }
private final Object lock = new Object();
- private final Listener listener;
private State state = State.IDLE;
private int fourcc, w, h;
@@ -51,12 +41,6 @@ public final class MuxRecorder implements VideoRecorder {
private long firstPtsUs = -1;
private long lastPtsUs = -1;
- public MuxRecorder() { this(null); }
-
- public MuxRecorder(Listener listener) {
- this.listener = listener != null ? listener : new Listener() {};
- }
-
// Externally-driven controls.
public void arm(File out) {
@@ -74,21 +58,22 @@ public final class MuxRecorder implements VideoRecorder {
Log.i("rec: armed -> %s", out);
}
- public void stop() {
- File out;
+ // Returns true if a recording was actually written (a keyframe landed
+ // and the muxer ran); false if we were still ARMED, so the caller can
+ // tell the user the truth instead of claiming a file was saved.
+ public boolean stop() {
long bytes;
- boolean reportStopped;
+ boolean wrote;
synchronized (lock) {
- if (state == State.IDLE) return;
- reportStopped = (state == State.RECORDING);
+ if (state == State.IDLE) return false;
+ wrote = (state == State.RECORDING);
closeMuxerLocked();
- out = outFile;
bytes = bytesWritten;
state = State.IDLE;
outFile = null;
}
Log.i("rec: stopped (%d bytes)", bytes);
- if (reportStopped) listener.onStopped(out, bytes);
+ return wrote;
}
public boolean isActive() {
@@ -102,17 +87,15 @@ public final class MuxRecorder implements VideoRecorder {
@Override
public void onMeta(int fcc, int width, int height) {
synchronized (lock) {
- // Resize during recording → close, surface as an error so
- // the UI can re-arm. addTrack after start is illegal; we
- // don't try to splice tracks together.
+ // Resize during recording → close the file. addTrack after
+ // start is illegal; we don't try to splice tracks together.
+ // The user can re-arm; a fresh output gets the new dimensions.
if (state == State.RECORDING && (fcc != fourcc || width != w || height != h)) {
- Log.w("rec: resize/codec change during recording - closing");
- File out = outFile;
- long bytes = bytesWritten;
+ Log.w("rec: resize/codec change during recording - closing (%d bytes)",
+ bytesWritten);
closeMuxerLocked();
state = State.IDLE;
outFile = null;
- listener.onStopped(out, bytes);
}
fourcc = fcc; w = width; h = height;
}
@@ -142,7 +125,6 @@ public final class MuxRecorder implements VideoRecorder {
}
writeSampleLocked(data, ptsUs, true);
state = State.RECORDING;
- listener.onStarted(outFile);
return;
case RECORDING:
writeSampleLocked(data, ptsUs, isKeyframe);
@@ -177,7 +159,6 @@ public final class MuxRecorder implements VideoRecorder {
try { if (muxer != null) muxer.release(); } catch (Exception ignored) {}
muxer = null;
trackIdx = -1;
- listener.onError(e);
return false;
}
}
diff --git a/app/src/main/java/invalid/lena/scrcpy/Session.java b/app/src/main/java/invalid/lena/scrcpy/Session.java
index 019ce80..774fdc1 100644
--- a/app/src/main/java/invalid/lena/scrcpy/Session.java
+++ b/app/src/main/java/invalid/lena/scrcpy/Session.java
@@ -138,9 +138,10 @@ public final class Session {
r.arm(out);
}
- public void stopRecording() {
+ // Returns true if a file was actually written (see MuxRecorder.stop).
+ public boolean stopRecording() {
MuxRecorder r = recorder;
- if (r != null) r.stop();
+ return r != null && r.stop();
}
public boolean isRecording() {