diff options
Diffstat (limited to 'app/src')
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/Mirror.java | 7 | ||||
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/MuxRecorder.java | 45 | ||||
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/Session.java | 5 |
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() { |