Update Limelight Common to support new version of GFE 2.1.1

This commit is contained in:
Iwan Timmer
2014-08-03 13:23:25 +02:00
parent 7b166b5587
commit 59faa3926d
7 changed files with 35 additions and 48 deletions
+4 -33
View File
@@ -15,7 +15,6 @@ import com.limelight.nvstream.http.NvHTTP;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -68,7 +67,7 @@ public class Limelight implements NvConnectionListener {
} }
} }
conn = new NvConnection(host, this, streamConfig, PlatformBinding.getCryptoProvider()); conn = new NvConnection(host, "Pi", this, streamConfig, PlatformBinding.getCryptoProvider());
GamepadMapping mapping = null; GamepadMapping mapping = null;
if (mappingFile!=null) { if (mappingFile!=null) {
@@ -102,7 +101,7 @@ public class Limelight implements NvConnectionListener {
* Creates a connection to the host and starts up the stream. * Creates a connection to the host and starts up the stream.
*/ */
private void startUpFake(StreamConfiguration streamConfig, String videoFile) { private void startUpFake(StreamConfiguration streamConfig, String videoFile) {
conn = new NvConnection(host, this, streamConfig, PlatformBinding.getCryptoProvider()); conn = new NvConnection(host, "Pi", this, streamConfig, PlatformBinding.getCryptoProvider());
conn.start(PlatformBinding.getDeviceName(), null, conn.start(PlatformBinding.getDeviceName(), null,
VideoDecoderRenderer.FLAG_PREFER_QUALITY, VideoDecoderRenderer.FLAG_PREFER_QUALITY,
new FakeAudioRenderer(), new FakeAudioRenderer(),
@@ -113,24 +112,11 @@ public class Limelight implements NvConnectionListener {
* Pair the device with the host * Pair the device with the host
*/ */
private void pair() { private void pair() {
String macAddress;
try {
macAddress = NvConnection.getMacAddressString();
} catch (SocketException e) {
e.printStackTrace();
return;
}
if (macAddress == null) {
displayError("Pair", "Couldn't find a MAC address");
return;
}
NvHTTP httpConn; NvHTTP httpConn;
try { try {
httpConn = new NvHTTP(InetAddress.getByName(host), httpConn = new NvHTTP(InetAddress.getByName(host),
macAddress, PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider()); "Pi", PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider());
try { try {
if (httpConn.getPairState() == PairingManager.PairState.PAIRED) { if (httpConn.getPairState() == PairingManager.PairState.PAIRED) {
displayError("pair", "Already paired"); displayError("pair", "Already paired");
@@ -171,7 +157,6 @@ public class Limelight implements NvConnectionListener {
int height = 720; int height = 720;
int refresh = 60; int refresh = 60;
int bitrate = 10000; int bitrate = 10000;
int packetSize = 1024;
boolean parse = true; boolean parse = true;
boolean fake = false; boolean fake = false;
boolean tests = true; boolean tests = true;
@@ -256,19 +241,6 @@ public class Limelight implements NvConnectionListener {
System.out.println("Syntax error: bitrate expected after -bitrate"); System.out.println("Syntax error: bitrate expected after -bitrate");
System.exit(3); System.exit(3);
} }
} else if (args[i].equals("-packetsize")) {
if (i + 1 < args.length) {
try {
packetSize = Integer.parseInt(args[i+1]);
} catch (NumberFormatException e) {
System.out.println("Syntax error: packetsize must be a number");
System.exit(3);
}
i++;
} else {
System.out.println("Syntax error: packetsize expected after -packetsize");
System.exit(3);
}
} else if (args[i].equals("-fake")) { } else if (args[i].equals("-fake")) {
fake = true; fake = true;
} else if (args[i].equals("-out")) { } else if (args[i].equals("-out")) {
@@ -310,7 +282,6 @@ public class Limelight implements NvConnectionListener {
System.out.println("\t-30fps\t\tUse 30fps"); System.out.println("\t-30fps\t\tUse 30fps");
System.out.println("\t-60fps\t\tUse 60fps [default]"); System.out.println("\t-60fps\t\tUse 60fps [default]");
System.out.println("\t-bitrate <bitrate>\t\tSpecify the bitrate in Kbps"); System.out.println("\t-bitrate <bitrate>\t\tSpecify the bitrate in Kbps");
System.out.println("\t-packetsize <size>\t\tSpecify the packetsize in bytes");
System.out.println("\t-input <device>\tUse <device> as input. Can be used multiple times"); System.out.println("\t-input <device>\tUse <device> as input. Can be used multiple times");
System.out.println("\t\t\t[default uses all devices in /dev/input]"); System.out.println("\t\t\t[default uses all devices in /dev/input]");
System.out.println("\t-mapping <file>\tUse <file> as gamepad mapping configuration file"); System.out.println("\t-mapping <file>\tUse <file> as gamepad mapping configuration file");
@@ -324,7 +295,7 @@ public class Limelight implements NvConnectionListener {
//Set debugging level //Set debugging level
Logger.getLogger(LimeLog.class.getName()).setLevel(debug); Logger.getLogger(LimeLog.class.getName()).setLevel(debug);
StreamConfiguration streamConfig = new StreamConfiguration(width, height, refresh, bitrate, packetSize); StreamConfiguration streamConfig = new StreamConfiguration("Steam", width, height, refresh, bitrate);
Limelight limelight = new Limelight(host); Limelight limelight = new Limelight(host);
if (!pair) if (!pair)
@@ -16,10 +16,8 @@ public class AlsaAudioRenderer implements AudioRenderer {
} }
@Override @Override
public void streamInitialized(int channelCount, int sampleRate) { public boolean streamInitialized(int channelCount, int sampleRate) {
int ret = AlsaAudio.init(channelCount, sampleRate, device); return AlsaAudio.init(channelCount, sampleRate, device) == 0;
if (ret != 0)
throw new IllegalStateException("Alsa renderer initialization failure: "+ret);
} }
@Override @Override
@@ -12,9 +12,10 @@ public class FakeAudioRenderer implements AudioRenderer {
private long last; private long last;
@Override @Override
public void streamInitialized(int channelCount, int sampleRate) { public boolean streamInitialized(int channelCount, int sampleRate) {
System.out.println("Fake " + channelCount + " channel " + sampleRate + " samplerate audio output"); System.out.println("Fake " + channelCount + " channel " + sampleRate + " samplerate audio output");
last = System.currentTimeMillis(); last = System.currentTimeMillis();
return true;
} }
@Override @Override
@@ -17,8 +17,12 @@ public abstract class AbstractVideoRenderer implements VideoDecoderRenderer {
private int dataSize; private int dataSize;
private long last; private long last;
private long endToEndLatency;
private long decodeLatency;
private long packets;
@Override @Override
public void start(final VideoDepacketizer depacketizer) { public boolean start(final VideoDepacketizer depacketizer) {
last = System.currentTimeMillis(); last = System.currentTimeMillis();
thread = new Thread(new Runnable() { thread = new Thread(new Runnable() {
@Override @Override
@@ -26,14 +30,17 @@ public abstract class AbstractVideoRenderer implements VideoDecoderRenderer {
while (running) { while (running) {
try { try {
DecodeUnit decodeUnit = depacketizer.takeNextDecodeUnit(); DecodeUnit decodeUnit = depacketizer.takeNextDecodeUnit();
long latency = System.currentTimeMillis()-decodeUnit.getReceiveTimestamp();
endToEndLatency += latency;
dataSize += decodeUnit.getDataLength(); dataSize += decodeUnit.getDataLength();
decodeUnit(decodeUnit); decodeUnit(decodeUnit);
if (System.currentTimeMillis()>last+2000) { if (System.currentTimeMillis()>last+2000) {
int bitrate = (dataSize/2)/1024; int bitrate = (dataSize/2)/1024;
long latency = System.currentTimeMillis()-decodeUnit.getReceiveTimestamp(); latency = System.currentTimeMillis()-decodeUnit.getReceiveTimestamp();
System.out.println("Video " + bitrate + "kB/s " + latency + "ms"); decodeLatency += latency;
System.out.println("Video " + bitrate + "kB/s " + latency);
dataSize = 0; dataSize = 0;
last = System.currentTimeMillis(); last = System.currentTimeMillis();
} }
@@ -43,6 +50,7 @@ public abstract class AbstractVideoRenderer implements VideoDecoderRenderer {
}); });
running = true; running = true;
thread.start(); thread.start();
return true;
} }
@Override @Override
@@ -62,5 +70,15 @@ public abstract class AbstractVideoRenderer implements VideoDecoderRenderer {
public int getCapabilities() { public int getCapabilities() {
return 0; return 0;
} }
@Override
public int getAverageEndToEndLatency() {
return (int) (endToEndLatency / packets);
}
@Override
public int getAverageDecoderLatency() {
return (int) (decodeLatency / packets);
}
} }
@@ -26,8 +26,9 @@ public class FakeVideoRenderer extends AbstractVideoRenderer {
} }
@Override @Override
public void setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) { public boolean setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) {
System.out.println("Fake " + width + "x" + height + " " + redrawRate + "fps video output"); System.out.println("Fake " + width + "x" + height + " " + redrawRate + "fps video output");
return true;
} }
@Override @Override
@@ -14,10 +14,8 @@ public class OmxDecoderRenderer extends AbstractVideoRenderer {
private final static byte[] BITSTREAM_RESTRICTIONS = new byte[] {(byte) 0xF1, (byte) 0x83, 0x2A, 0x00}; private final static byte[] BITSTREAM_RESTRICTIONS = new byte[] {(byte) 0xF1, (byte) 0x83, 0x2A, 0x00};
@Override @Override
public void setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) { public boolean setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) {
int err = OmxDecoder.init(); return OmxDecoder.init() == 0;
if (err != 0)
throw new IllegalStateException("AVC decoder initialization failure: "+err);
} }
@Override @Override
@@ -132,5 +130,5 @@ public class OmxDecoderRenderer extends AbstractVideoRenderer {
source.offset = offset; source.offset = offset;
source.length = length; source.length = length;
} }
} }