Skip to content

Commit

Permalink
revert to old image serving
Browse files Browse the repository at this point in the history
  • Loading branch information
shamanec committed Nov 28, 2023
1 parent 2cae8d1 commit 30aafd6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
23 changes: 1 addition & 22 deletions app/src/main/java/com/shamanec/stream/LocalWebsocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public LocalWebsocketServer(int port) {

@Override
public void onOpen(WebSocket conn, ClientHandshake handshake) {
conn.send(getDeviceInfo());

}

@Override
Expand All @@ -30,9 +30,6 @@ public void onClose(WebSocket conn, int code, String reason, boolean remote) {

@Override
public void onMessage(WebSocket conn, String message) {
if (message == "info") {
conn.send(getDeviceInfo());
}
}

@Override
Expand All @@ -52,22 +49,4 @@ public void onStart() {
setConnectionLostTimeout(0);
setConnectionLostTimeout(100);
}

private byte[] getDeviceInfo() {
ByteBuffer infoMessage = ByteBuffer.allocate(8);
infoMessage.putInt(ScreenCaptureService.metricsWidth);
infoMessage.putInt(ScreenCaptureService.metricsHeight);

// Message type `1` for information
byte[] messageTypeBytes = ByteBuffer.allocate(4).putInt(1).array();
byte[] infoBytes = infoMessage.array();

byte[] combinedBytes = new byte[messageTypeBytes.length + infoBytes.length];

System.arraycopy(messageTypeBytes, 0, combinedBytes, 0, messageTypeBytes.length);
System.arraycopy(infoBytes, 0, combinedBytes, messageTypeBytes.length, infoBytes.length);

return combinedBytes;
}

}
15 changes: 3 additions & 12 deletions app/src/main/java/com/shamanec/stream/ScreenCaptureService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public class ScreenCaptureService extends Service {
private int mRotation;
private OrientationChangeCallback mOrientationChangeCallback;

public static int metricsWidth;
public static int metricsHeight;

LocalWebsocketServer server;

public ScreenCaptureService() throws IOException {
Expand Down Expand Up @@ -134,16 +131,10 @@ public void run() {

bitmap.recycle();

// Message type `2` for images
byte[] messageTypeBytes = ByteBuffer.allocate(4).putInt(2).array();
byte[] compressedImage = outputStream.toByteArray();

byte[] combinedBytes = new byte[messageTypeBytes.length + compressedImage.length];
System.arraycopy(messageTypeBytes, 0, combinedBytes, 0, messageTypeBytes.length);
System.arraycopy(compressedImage, 0, combinedBytes, messageTypeBytes.length, compressedImage.length);

// Send the compressed image over the WebSocket
server.broadcast(combinedBytes);
server.broadcast(compressedImage);

} catch (InterruptedException e) {
// Handle interruption or exit the loop
Expand Down Expand Up @@ -306,8 +297,8 @@ private void createVirtualDisplay() {
// Set up the width and height for the image reader to be half of the real display metrics
// This significantly increases the FPS even with JPEG quality of 100
// Instead of rescaling bitmaps which reduces quality even further
metricsWidth = metrics.widthPixels;
metricsHeight = metrics.heightPixels;
int metricsWidth = metrics.widthPixels;
int metricsHeight = metrics.heightPixels;

mWidth = metricsWidth / 2;
mHeight = metricsHeight / 2;
Expand Down

0 comments on commit 30aafd6

Please sign in to comment.