Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Oct 30, 2024
2 parents 4704036 + c516da0 commit 2c79821
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.cagnulein.android_remote;

import static org.cagnulein.android_remote.wrappers.SurfaceControl.createDisplay;

import android.graphics.Rect;
import android.hardware.display.VirtualDisplay;
import android.media.MediaCodec;
Expand Down Expand Up @@ -73,12 +75,18 @@ private static void setSize(MediaFormat format, int width, int height) {
}

private static void setDisplaySurface(IBinder display, Surface surface, Rect deviceRect, Rect displayRect) {
Ln.d("setDisplaySurface 1");
SurfaceControl.openTransaction();
try {
Ln.d("setDisplaySurface 2");
SurfaceControl.setDisplaySurface(display, surface);
Ln.d("setDisplaySurface 3");
SurfaceControl.setDisplayProjection(display, 0, deviceRect, displayRect);
Ln.d("setDisplaySurface 4");
SurfaceControl.setDisplayLayerStack(display, 0);
Ln.d("setDisplaySurface 5");
} finally {
Ln.d("setDisplaySurface 6");
SurfaceControl.closeTransaction();
}
}
Expand Down Expand Up @@ -124,18 +132,24 @@ public void streamScreen(Device device, OutputStream outputStream) throws IOExce
virtualDisplay = null;
}

/*try {
display = createDisplay();
setDisplaySurface(display, surface, deviceRect, videoRect);
Ln.d("Display: using SurfaceControl API");
} catch (Exception surfaceControlException )*/ {
{
try {
virtualDisplay = DisplayManager.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), 0, surface);
Ln.d("Display: using DisplayManager API");
} catch (Exception displayManagerException) {
//Ln.e("Could not create display using SurfaceControl", surfaceControlException);
Ln.e("Could not create display using DisplayManager", displayManagerException);
throw new AssertionError("Could not create display");
try {
boolean secure = Build.VERSION.SDK_INT < Build.VERSION_CODES.R || (Build.VERSION.SDK_INT == Build.VERSION_CODES.R && !"S".equals(
Build.VERSION.CODENAME));
Ln.d("Creating display...");
display = createDisplay("scrcpy", secure);
Ln.d("Display created " + display.toString());
setDisplaySurface(display, surface, deviceRect, videoRect);
Ln.d("Display: using SurfaceControl API");
} catch (Exception surfaceControlException) {
Ln.e("Could not create display using SurfaceControl", surfaceControlException);
Ln.e("Could not create display using DisplayManager", displayManagerException);
throw new AssertionError("Could not create display");
}
}
}
codec.start();
Expand Down

0 comments on commit 2c79821

Please sign in to comment.