Remove starting app stage from under the lock

This commit is contained in:
Cameron Gutman 2017-05-21 14:42:09 -07:00
parent 636c20d67b
commit 8f3eecd980

View File

@ -214,7 +214,13 @@ public class NvConnection {
return true;
}
private void establishConnection() {
public void start(final AudioRenderer audioRenderer, final VideoDecoderRenderer videoDecoderRenderer, final NvConnectionListener connectionListener)
{
new Thread(new Runnable() {
public void run() {
context.connListener = connectionListener;
context.videoCapabilities = videoDecoderRenderer.getCapabilities();
String appName = context.streamConfig.getApp().getAppName();
try {
@ -239,6 +245,10 @@ public class NvConnection {
ByteBuffer ib = ByteBuffer.allocate(16);
ib.putInt(context.riKeyId);
// Moonlight-core is not thread-safe with respect to connection start and stop, so
// we must not invoke that functionality in parallel.
synchronized (MoonBridge.class) {
MoonBridge.setupBridge(videoDecoderRenderer, audioRenderer, connectionListener);
MoonBridge.startConnection(context.serverAddress.getHostAddress(),
context.serverAppVersion, context.serverGfeVersion,
context.negotiatedWidth, context.negotiatedHeight,
@ -247,20 +257,6 @@ public class NvConnection {
context.streamConfig.getHevcSupported(), context.riKey.getEncoded(), ib.array(),
context.videoCapabilities);
}
public void start(final AudioRenderer audioRenderer, final VideoDecoderRenderer videoDecoderRenderer, final NvConnectionListener connectionListener)
{
new Thread(new Runnable() {
public void run() {
// Moonlight-core is not thread-safe with respect to connection start and stop, so
// we must not invoke that functionality in parallel.
synchronized (MoonBridge.class) {
MoonBridge.setupBridge(videoDecoderRenderer, audioRenderer, connectionListener);
context.connListener = connectionListener;
context.videoCapabilities = videoDecoderRenderer.getCapabilities();
establishConnection();
}
}
}).start();
}