Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fps calculation #42

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions run
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.");
}
Expand All @@ -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 {
Expand All @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/github/xsavikx/androidscreencast/TestMain.java
Original file line number Diff line number Diff line change
@@ -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);
}

}