diff --git a/run b/run new file mode 100755 index 0000000..b9c3d45 --- /dev/null +++ b/run @@ -0,0 +1,23 @@ +#!/bin/bash +# WF 2017-05-21 +jar=target/androidscreencast-0.0.11s-SNAPSHOT-executable.jar +if [ ! -f $jar ] +then + mvn package +fi +adb=`which adb` +if [ $? -ne 0 ] +then + echo "adb not on path " + echo "you might want to check your app.properties" + grep adb app.properties + exit 1 +fi +grep $adb app.properties +if [ $? -ne 0 ] +then + mv app.properties app.org + echo "adb=$adb" > app.properties + grep -v adb app.org >> app.properties +fi +java -jar $jar diff --git a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java index 1f452f2..4a12906 100644 --- a/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java +++ b/src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java @@ -37,6 +37,9 @@ public final class ScreenCaptureRunnable implements Runnable { private ScreenCaptureListener listener = null; private long currentAdbCommandTimeout; private boolean isStopped = false; + private double fps; + private long starttime; + private int frames; @Inject public ScreenCaptureRunnable(final IDevice device, @Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) { @@ -50,10 +53,14 @@ public ScreenCaptureRunnable(final IDevice device, @Named(ADB_COMMAND_TIMEOUT_KE public void run() { log().info("Starting screen capturing."); while (!isStopped) { + // prepare timing calculation + starttime=System.nanoTime(); + frames=0; try { final RawImage screenshot = getScreenshot(); if (screenshot != null) { display(screenshot); + calcfps(); } else { log().info("Failed to get device screenshot."); } @@ -68,6 +75,23 @@ public void run() { log().info("Stopping screen capturing."); } + /** + * calculate the frames per second + */ + private void calcfps() { + frames++; + long time = System.nanoTime(); + long millis = (time-starttime)/1000000; + fps=(1000.0*frames)/millis; + LOGGER.info(String.format("%4.2f fps %4d msecs/frame",fps,millis/frames)); + } + + /** + * get a screen shot from the device via adb + * @return a raw image + * @throws InterruptedException + * @throws ClosedByInterruptException + */ private RawImage getScreenshot() throws InterruptedException, ClosedByInterruptException { RawImage rawImage = null; try { @@ -90,6 +114,10 @@ private RawImage getScreenshot() throws InterruptedException, ClosedByInterruptE return rawImage; } + /** + * display the given rawImage + * @param rawImage + */ private void display(final RawImage rawImage) { final RawImage imageToProcess = landscape ? rawImage.getRotated() : rawImage; final BufferedImage image = ImageUtils.convertImage(imageToProcess); diff --git a/src/test/java/com/github/xsavikx/androidscreencast/TestMain.java b/src/test/java/com/github/xsavikx/androidscreencast/TestMain.java new file mode 100644 index 0000000..4690188 --- /dev/null +++ b/src/test/java/com/github/xsavikx/androidscreencast/TestMain.java @@ -0,0 +1,18 @@ +package com.github.xsavikx.androidscreencast; + +import org.junit.Test; + +/** + * test running main program + * @author wf + * + */ +public class TestMain { + + @Test + public void testMain() { + String args[]={}; + Main.main(args); + } + +}