Skip to content

Commit 440c7fe

Browse files
committed
fix: clear screen on camera switch and quad mode transition
- Add clearVideo() - draws black on main TextureView via lockCanvas - Add clearQuadViews() - draws black on all 4 quad TextureViews - Call clearVideo() in saveSettings() before reconnect on camera switch - Call clearVideo() in stopQuad() before restarting single stream - Call clearVideo() in onResume() non-quad path before startListener - Call clearQuadViews() in startQuad() before creating new QuadCells - Call clearQuadViews() in onResume() quad path before re-creating cells
1 parent 39673df commit 440c7fe

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

‎android/app/src/main/java/com/openipc/decoder/Decoder.java‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import android.widget.TextView;
6161
import android.widget.Toast;
6262
import android.graphics.Bitmap;
63+
import android.graphics.Canvas;
6364
import android.provider.MediaStore;
6465

6566
import java.io.BufferedInputStream;
@@ -548,6 +549,9 @@ private void startQuad() {
548549
mSurface.setVisibility(View.GONE);
549550
quadContainer.setVisibility(View.VISIBLE);
550551

552+
// clear stale quad frames
553+
clearQuadViews();
554+
551555
// collect first 4 cameras with quad enabled
552556
quadCells = new QuadCell[4];
553557
int count = 0;
@@ -581,6 +585,9 @@ private void stopQuad() {
581585
quadContainer.setVisibility(View.GONE);
582586
mSurface.setVisibility(View.VISIBLE);
583587

588+
// clear stale frame before reconnect
589+
clearVideo();
590+
584591
// restart single-stream playback
585592
if (!listener) {
586593
listener = true;
@@ -602,6 +609,7 @@ private void saveSettings() {
602609
applyActiveCamera();
603610
activeStream = false;
604611
closeSockets();
612+
clearVideo();
605613
}
606614

607615
/** Close all active network sockets to unblock I/O threads. */
@@ -830,7 +838,29 @@ private void focusChange(View item) {
830838
});
831839
}
832840

833-
/** Converts dp units to pixels using cached display density. */
841+
/** Clear the video view by drawing black so no stale frame lingers. */
842+
private void clearVideo() {
843+
if (mSurface == null || !mSurface.isAvailable()) return;
844+
Canvas canvas = mSurface.lockCanvas();
845+
if (canvas != null) {
846+
canvas.drawColor(Color.BLACK);
847+
mSurface.unlockCanvasAndPost(canvas);
848+
}
849+
}
850+
851+
/** Clear all quad views so stale frames are erased before restart. */
852+
private void clearQuadViews() {
853+
for (int i = 0; i < 4; i++) {
854+
TextureView t = quadViews[i];
855+
if (t == null || !t.isAvailable()) continue;
856+
Canvas c = t.lockCanvas();
857+
if (c != null) {
858+
c.drawColor(Color.BLACK);
859+
t.unlockCanvasAndPost(c);
860+
}
861+
}
862+
}
863+
834864
private int dp(float dp) {
835865
return (int) (dp * mDensity + 0.5f);
836866
}
@@ -2021,6 +2051,8 @@ protected void onResume() {
20212051
}
20222052
quadCells = null;
20232053
}
2054+
// clear stale quad frames
2055+
clearQuadViews();
20242056
quadCells = new QuadCell[4];
20252057
int count = 0;
20262058
for (int i = 0; i < CAM_COUNT && count < 4; i++) {
@@ -2041,6 +2073,8 @@ protected void onResume() {
20412073
}
20422074
quadCells = null;
20432075
}
2076+
// clear stale frame before reconnect
2077+
clearVideo();
20442078
if (!listener) {
20452079
listener = true;
20462080
startListener();

0 commit comments

Comments
 (0)