Compare commits

...

14 Commits

Author SHA1 Message Date
Cameron Gutman 79f888fe47 Update common 2014-08-09 03:41:03 -07:00
Cameron Gutman 9393bf7f79 Fix a regression in video scaling after the CPU decoding fix 2014-08-06 22:33:41 -07:00
Cameron Gutman 1b1d4399a9 Bump version and update common 2014-08-06 17:24:21 -07:00
Cameron Gutman b2ad259a7c Also add bitstream restrictions to Qualcomm devices to hopefully address the GS3 issue 2014-08-06 17:22:41 -07:00
Cameron Gutman ac5c264090 Only close spinner dialogs corresponding to the current activity 2014-08-06 15:05:26 -07:00
Cameron Gutman fcfdd4e323 Add missing Cursor.close() calls to fix a crash reported on Ouya 2014-08-06 15:01:18 -07:00
Cameron Gutman ea65bb2c0a Remove the extra app list update when the activity is first started 2014-08-06 14:30:19 -07:00
Cameron Gutman b340055588 If the activity is being finished, don't dismiss the dialog. This is already handled in the closeDialogs() function. 2014-08-06 14:26:13 -07:00
Cameron Gutman 2918039b6f Fix a bug where we'd add a null entry to the computer list 2014-08-05 23:44:04 -07:00
Cameron Gutman e8fd1f262a Update common jar 2014-08-05 23:19:37 -07:00
Cameron Gutman 8887401644 Fix surface sizing with scaling disabled on the CPU decoder 2014-08-05 23:16:02 -07:00
Cameron Gutman f892db6ee8 Fix ANR when switching from the PC view to the app view 2014-08-05 22:30:11 -07:00
Cameron Gutman 829532c572 Some devices don't properly get interrupted while waiting for an input buffer, so wait 100 ms then check the interrupt flag 2014-08-05 21:29:21 -07:00
Cameron Gutman 875eb1e773 Update common and version 2014-07-31 15:23:31 -07:00
9 changed files with 190 additions and 117 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.limelight" package="com.limelight"
android:versionCode="28" android:versionCode="30"
android:versionName="2.5.2" > android:versionName="2.5.3" >
<uses-sdk <uses-sdk
android:minSdkVersion="16" android:minSdkVersion="16"
Binary file not shown.
+1 -1
View File
@@ -91,13 +91,13 @@ public class AppView extends Activity {
} }
}); });
registerForContextMenu(appList); registerForContextMenu(appList);
updateAppList();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
SpinnerDialog.closeDialogs(this);
Dialog.closeDialogs(); Dialog.closeDialogs();
} }
+10 -9
View File
@@ -165,13 +165,6 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
sv.setOnGenericMotionListener(this); sv.setOnGenericMotionListener(this);
sv.setOnTouchListener(this); sv.setOnTouchListener(this);
SurfaceHolder sh = sv.getHolder();
if (stretchToFit) {
// Set the surface to the size of the video
sh.setFixedSize(width, height);
}
// Warn the user if they're on a metered connection // Warn the user if they're on a metered connection
checkDataConnection(); checkDataConnection();
@@ -191,7 +184,15 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
PlatformBinding.getCryptoProvider(this)); PlatformBinding.getCryptoProvider(this));
keybTranslator = new KeyboardTranslator(conn); keybTranslator = new KeyboardTranslator(conn);
controllerHandler = new ControllerHandler(conn); controllerHandler = new ControllerHandler(conn);
decoderRenderer = new ConfigurableDecoderRenderer(); decoderRenderer = new ConfigurableDecoderRenderer();
decoderRenderer.initializeWithFlags(drFlags);
SurfaceHolder sh = sv.getHolder();
if (stretchToFit || !decoderRenderer.isHardwareAccelerated()) {
// Set the surface to the size of the video
sh.setFixedSize(width, height);
}
// The connection will be started when the surface gets created // The connection will be started when the surface gets created
sh.addCallback(this); sh.addCallback(this);
@@ -254,7 +255,7 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
SpinnerDialog.closeDialogs(); SpinnerDialog.closeDialogs(this);
Dialog.closeDialogs(); Dialog.closeDialogs();
displayedFailureDialog = true; displayedFailureDialog = true;
@@ -610,7 +611,7 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
// Resize the surface to match the aspect ratio of the video // Resize the surface to match the aspect ratio of the video
// This must be done after the surface is created. // This must be done after the surface is created.
if (!stretchToFit) { if (!stretchToFit && decoderRenderer.isHardwareAccelerated()) {
resizeSurfaceWithAspectRatio((SurfaceView) findViewById(R.id.surfaceView), width, height); resizeSurfaceWithAspectRatio((SurfaceView) findViewById(R.id.surfaceView), width, height);
} }
@@ -16,15 +16,28 @@ public class ConfigurableDecoderRenderer implements VideoDecoderRenderer {
@Override @Override
public boolean setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) { public boolean setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) {
if (decoderRenderer == null) {
throw new IllegalStateException("ConfigurableDecoderRenderer not initialized");
}
return decoderRenderer.setup(width, height, redrawRate, renderTarget, drFlags);
}
public void initializeWithFlags(int drFlags) {
if ((drFlags & VideoDecoderRenderer.FLAG_FORCE_HARDWARE_DECODING) != 0 || if ((drFlags & VideoDecoderRenderer.FLAG_FORCE_HARDWARE_DECODING) != 0 ||
((drFlags & VideoDecoderRenderer.FLAG_FORCE_SOFTWARE_DECODING) == 0 && ((drFlags & VideoDecoderRenderer.FLAG_FORCE_SOFTWARE_DECODING) == 0 &&
MediaCodecDecoderRenderer.findSafeDecoder() != null)) { MediaCodecDecoderRenderer.findSafeDecoder() != null)) {
decoderRenderer = new MediaCodecDecoderRenderer(); decoderRenderer = new MediaCodecDecoderRenderer();
} }
else { else {
decoderRenderer = new AndroidCpuDecoderRenderer(); decoderRenderer = new AndroidCpuDecoderRenderer();
} }
return decoderRenderer.setup(width, height, redrawRate, renderTarget, drFlags); }
public boolean isHardwareAccelerated() {
if (decoderRenderer == null) {
throw new IllegalStateException("ConfigurableDecoderRenderer not initialized");
}
return (decoderRenderer instanceof MediaCodecDecoderRenderer);
} }
@Override @Override
@@ -48,6 +48,7 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
static { static {
spsFixupBitsreamFixupDecoderPrefixes = new LinkedList<String>(); spsFixupBitsreamFixupDecoderPrefixes = new LinkedList<String>();
spsFixupBitsreamFixupDecoderPrefixes.add("omx.nvidia"); spsFixupBitsreamFixupDecoderPrefixes.add("omx.nvidia");
spsFixupBitsreamFixupDecoderPrefixes.add("omx.qcom");
spsFixupNumRefFixupDecoderPrefixes = new LinkedList<String>(); spsFixupNumRefFixupDecoderPrefixes = new LinkedList<String>();
spsFixupNumRefFixupDecoderPrefixes.add("omx.TI"); spsFixupNumRefFixupDecoderPrefixes.add("omx.TI");
@@ -177,8 +178,14 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
{ {
du = depacketizer.pollNextDecodeUnit(); du = depacketizer.pollNextDecodeUnit();
if (du != null) { if (du != null) {
submitDecodeUnit(du); if (!submitDecodeUnit(du)) {
depacketizer.freeDecodeUnit(du); // Thread was interrupted
depacketizer.freeDecodeUnit(du);
return;
}
else {
depacketizer.freeDecodeUnit(du);
}
} }
int outIndex = videoDecoder.dequeueOutputBuffer(info, 0); int outIndex = videoDecoder.dequeueOutputBuffer(info, 0);
@@ -250,106 +257,112 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
} }
private boolean submitDecodeUnit(DecodeUnit decodeUnit) { private boolean submitDecodeUnit(DecodeUnit decodeUnit) {
int inputIndex = videoDecoder.dequeueInputBuffer(-1); int inputIndex;
if (inputIndex >= 0)
{
ByteBuffer buf = videoDecoderInputBuffers[inputIndex];
long currentTime = System.currentTimeMillis(); do {
long delta = currentTime-decodeUnit.getReceiveTimestamp(); if (Thread.interrupted()) {
if (delta >= 0 && delta < 300) { return false;
totalTimeMs += currentTime-decodeUnit.getReceiveTimestamp();
totalFrames++;
} }
// Clear old input data inputIndex = videoDecoder.dequeueInputBuffer(100000);
buf.clear(); } while (inputIndex < 0);
int codecFlags = 0; ByteBuffer buf = videoDecoderInputBuffers[inputIndex];
int decodeUnitFlags = decodeUnit.getFlags();
if ((decodeUnitFlags & DecodeUnit.DU_FLAG_CODEC_CONFIG) != 0) {
codecFlags |= MediaCodec.BUFFER_FLAG_CODEC_CONFIG;
}
if ((decodeUnitFlags & DecodeUnit.DU_FLAG_SYNC_FRAME) != 0) {
codecFlags |= MediaCodec.BUFFER_FLAG_SYNC_FRAME;
}
if ((decodeUnitFlags & DecodeUnit.DU_FLAG_CODEC_CONFIG) != 0 && long currentTime = System.currentTimeMillis();
(needsSpsBitstreamFixup || needsSpsNumRefFixup)) { long delta = currentTime-decodeUnit.getReceiveTimestamp();
ByteBufferDescriptor header = decodeUnit.getBufferList().get(0); if (delta >= 0 && delta < 300) {
if (header.data[header.offset+4] == 0x67) { totalTimeMs += currentTime-decodeUnit.getReceiveTimestamp();
byte last = header.data[header.length+header.offset-1]; totalFrames++;
}
// TI OMAP4 requires a reference frame count of 1 to decode successfully // Clear old input data
if (needsSpsNumRefFixup) { buf.clear();
LimeLog.info("Fixing up num ref frames");
this.replace(header, 80, 9, new byte[] {0x40}, 3);
}
// The SPS that comes in the current H264 bytestream doesn't set bitstream_restriction_flag int codecFlags = 0;
// or max_dec_frame_buffering which increases decoding latency on Tegra. int decodeUnitFlags = decodeUnit.getFlags();
// We manually modify the SPS here to speed-up decoding if the decoder was flagged as needing it. if ((decodeUnitFlags & DecodeUnit.DU_FLAG_CODEC_CONFIG) != 0) {
int spsLength; codecFlags |= MediaCodec.BUFFER_FLAG_CODEC_CONFIG;
if (needsSpsBitstreamFixup) { }
if (!needsSpsNumRefFixup) { if ((decodeUnitFlags & DecodeUnit.DU_FLAG_SYNC_FRAME) != 0) {
switch (header.length) { codecFlags |= MediaCodec.BUFFER_FLAG_SYNC_FRAME;
case 26: }
LimeLog.info("Adding bitstream restrictions to SPS (26)");
buf.put(header.data, header.offset, 24); if ((decodeUnitFlags & DecodeUnit.DU_FLAG_CODEC_CONFIG) != 0 &&
buf.put((byte) 0x11); (needsSpsBitstreamFixup || needsSpsNumRefFixup)) {
buf.put((byte) 0xe3); ByteBufferDescriptor header = decodeUnit.getBufferList().get(0);
buf.put((byte) 0x06); if (header.data[header.offset+4] == 0x67) {
buf.put((byte) 0x50); byte last = header.data[header.length+header.offset-1];
spsLength = header.length + 2;
break; // TI OMAP4 requires a reference frame count of 1 to decode successfully
case 27: if (needsSpsNumRefFixup) {
LimeLog.info("Adding bitstream restrictions to SPS (27)"); LimeLog.info("Fixing up num ref frames");
buf.put(header.data, header.offset, 25); this.replace(header, 80, 9, new byte[] {0x40}, 3);
buf.put((byte) 0x04); }
buf.put((byte) 0x78);
buf.put((byte) 0xc1); // The SPS that comes in the current H264 bytestream doesn't set bitstream_restriction_flag
buf.put((byte) 0x94); // or max_dec_frame_buffering which increases decoding latency on Tegra.
spsLength = header.length + 2; // We manually modify the SPS here to speed-up decoding if the decoder was flagged as needing it.
break; int spsLength;
default: if (needsSpsBitstreamFixup) {
LimeLog.warning("Unknown SPS of length "+header.length); if (!needsSpsNumRefFixup) {
buf.put(header.data, header.offset, header.length); switch (header.length) {
spsLength = header.length; case 26:
break; LimeLog.info("Adding bitstream restrictions to SPS (26)");
} buf.put(header.data, header.offset, 24);
} buf.put((byte) 0x11);
else { buf.put((byte) 0xe3);
// Set bitstream restrictions to only buffer single frame buf.put((byte) 0x06);
// (starts 9 bits before stop bit and 6 bits earlier because of the shortening above) buf.put((byte) 0x50);
this.replace(header, header.length*8+Integer.numberOfLeadingZeros(last & - last)%8-9-6, 2, BITSTREAM_RESTRICTIONS, 3*8); spsLength = header.length + 2;
break;
case 27:
LimeLog.info("Adding bitstream restrictions to SPS (27)");
buf.put(header.data, header.offset, 25);
buf.put((byte) 0x04);
buf.put((byte) 0x78);
buf.put((byte) 0xc1);
buf.put((byte) 0x94);
spsLength = header.length + 2;
break;
default:
LimeLog.warning("Unknown SPS of length "+header.length);
buf.put(header.data, header.offset, header.length); buf.put(header.data, header.offset, header.length);
spsLength = header.length; spsLength = header.length;
break;
} }
} }
else { else {
// Set bitstream restrictions to only buffer single frame
// (starts 9 bits before stop bit and 6 bits earlier because of the shortening above)
this.replace(header, header.length*8+Integer.numberOfLeadingZeros(last & - last)%8-9-6, 2, BITSTREAM_RESTRICTIONS, 3*8);
buf.put(header.data, header.offset, header.length); buf.put(header.data, header.offset, header.length);
spsLength = header.length; spsLength = header.length;
} }
videoDecoder.queueInputBuffer(inputIndex,
0, spsLength,
currentTime * 1000, codecFlags);
return true;
} }
} else {
buf.put(header.data, header.offset, header.length);
spsLength = header.length;
}
// Copy data from our buffer list into the input buffer videoDecoder.queueInputBuffer(inputIndex,
for (ByteBufferDescriptor desc : decodeUnit.getBufferList()) 0, spsLength,
{ currentTime * 1000, codecFlags);
buf.put(desc.data, desc.offset, desc.length); return true;
} }
videoDecoder.queueInputBuffer(inputIndex,
0, decodeUnit.getDataLength(),
currentTime * 1000, codecFlags);
} }
// Copy data from our buffer list into the input buffer
for (ByteBufferDescriptor desc : decodeUnit.getBufferList())
{
buf.put(desc.data, desc.offset, desc.length);
}
videoDecoder.queueInputBuffer(inputIndex,
0, decodeUnit.getDataLength(),
currentTime * 1000, codecFlags);
return true; return true;
} }
@@ -109,6 +109,8 @@ public class ComputerDatabaseManager {
computerList.add(details); computerList.add(details);
} }
c.close();
return computerList; return computerList;
} }
@@ -117,6 +119,7 @@ public class ComputerDatabaseManager {
ComputerDetails details = new ComputerDetails(); ComputerDetails details = new ComputerDetails();
if (!c.moveToFirst()) { if (!c.moveToFirst()) {
// No matching computer // No matching computer
c.close();
return null; return null;
} }
@@ -146,6 +149,8 @@ public class ComputerDatabaseManager {
details.macAddress = c.getString(4); details.macAddress = c.getString(4);
c.close();
// If a field is corrupt or missing, delete the database entry // If a field is corrupt or missing, delete the database entry
if (details.uuid == null || details.localIp == null || details.remoteIp == null || if (details.uuid == null || details.localIp == null || details.remoteIp == null ||
details.macAddress == null) { details.macAddress == null) {
@@ -12,6 +12,7 @@ import java.util.TimerTask;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import com.limelight.LimeLog; import com.limelight.LimeLog;
import com.limelight.binding.PlatformBinding; import com.limelight.binding.PlatformBinding;
@@ -39,6 +40,8 @@ public class ComputerManagerService extends Service {
private ComputerManagerBinder binder = new ComputerManagerBinder(); private ComputerManagerBinder binder = new ComputerManagerBinder();
private ComputerDatabaseManager dbManager; private ComputerDatabaseManager dbManager;
private AtomicInteger dbRefCount = new AtomicInteger(0);
private IdentityManager idManager; private IdentityManager idManager;
private ThreadPoolExecutor pollingPool; private ThreadPoolExecutor pollingPool;
private Timer pollingTimer; private Timer pollingTimer;
@@ -173,15 +176,41 @@ public class ComputerManagerService extends Service {
} }
public void removeComputer(String name) { public void removeComputer(String name) {
if (!getLocalDatabaseReference()) {
return;
}
// Remove it from the database // Remove it from the database
dbManager.deleteComputer(name); dbManager.deleteComputer(name);
releaseLocalDatabaseReference();
}
private boolean getLocalDatabaseReference() {
if (dbRefCount.get() == 0) {
return false;
}
dbRefCount.incrementAndGet();
return true;
}
private void releaseLocalDatabaseReference() {
if (dbRefCount.decrementAndGet() == 0) {
dbManager.close();
}
} }
private TimerTask getTimerTask() { private TimerTask getTimerTask() {
return new TimerTask() { return new TimerTask() {
@Override @Override
public void run() { public void run() {
if (!getLocalDatabaseReference()) {
return;
}
List<ComputerDetails> computerList = dbManager.getAllComputers(); List<ComputerDetails> computerList = dbManager.getAllComputers();
releaseLocalDatabaseReference();
for (ComputerDetails computer : computerList) { for (ComputerDetails computer : computerList) {
pollingPool.execute(getPollingRunnable(computer)); pollingPool.execute(getPollingRunnable(computer));
} }
@@ -356,6 +385,10 @@ public class ComputerManagerService extends Service {
public void run() { public void run() {
boolean newPc = (details.name == null); boolean newPc = (details.name == null);
if (!getLocalDatabaseReference()) {
return;
}
// Poll the machine // Poll the machine
if (!doPollMachine(details)) { if (!doPollMachine(details)) {
details.state = ComputerDetails.State.OFFLINE; details.state = ComputerDetails.State.OFFLINE;
@@ -369,6 +402,7 @@ public class ComputerManagerService extends Service {
// removed after this was issued // removed after this was issued
if (dbManager.getComputerByName(details.name) == null) { if (dbManager.getComputerByName(details.name) == null) {
// It's gone // It's gone
releaseLocalDatabaseReference();
return; return;
} }
} }
@@ -376,10 +410,12 @@ public class ComputerManagerService extends Service {
dbManager.updateComputer(details); dbManager.updateComputer(details);
} }
// Update anyone listening // Don't call the listener if this is a failed lookup of a new PC
if (listener != null) { if ((!newPc || details.state == ComputerDetails.State.ONLINE) && listener != null) {
listener.notifyComputerUpdated(details); listener.notifyComputerUpdated(details);
} }
releaseLocalDatabaseReference();
} }
}; };
} }
@@ -400,6 +436,7 @@ public class ComputerManagerService extends Service {
// Initialize the DB // Initialize the DB
dbManager = new ComputerDatabaseManager(this); dbManager = new ComputerDatabaseManager(this);
dbRefCount.set(1);
} }
@Override @Override
@@ -411,12 +448,11 @@ public class ComputerManagerService extends Service {
// Stop the thread pool // Stop the thread pool
pollingPool.shutdownNow(); pollingPool.shutdownNow();
try {
pollingPool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {}
// Close the DB // FIXME: Should await termination here but we have timeout issues in HttpURLConnection
dbManager.close();
// Remove the initial DB reference
releaseLocalDatabaseReference();
} }
@Override @Override
+15 -10
View File
@@ -1,6 +1,7 @@
package com.limelight.utils; package com.limelight.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
@@ -31,16 +32,19 @@ public class SpinnerDialog implements Runnable,OnCancelListener {
return spinner; return spinner;
} }
public static void closeDialogs() public static void closeDialogs(Activity activity)
{ {
synchronized (rundownDialogs) { synchronized (rundownDialogs) {
for (SpinnerDialog d : rundownDialogs) { Iterator<SpinnerDialog> i = rundownDialogs.iterator();
if (d.progress.isShowing()) { while (i.hasNext()) {
d.progress.dismiss(); SpinnerDialog dialog = i.next();
if (dialog.activity == activity) {
i.remove();
if (dialog.progress.isShowing()) {
dialog.progress.dismiss();
}
} }
} }
rundownDialogs.clear();
} }
} }
@@ -63,12 +67,13 @@ public class SpinnerDialog implements Runnable,OnCancelListener {
@Override @Override
public void run() { public void run() {
// If we're dying, don't bother doing anything
if (activity.isFinishing()) {
return;
}
if (progress == null) if (progress == null)
{ {
// If we're dying, don't bother creating a dialog
if (activity.isFinishing())
return;
progress = new ProgressDialog(activity); progress = new ProgressDialog(activity);
progress.setTitle(title); progress.setTitle(title);