Prevent racing connection start and stop

This commit is contained in:
Cameron Gutman 2017-05-21 11:52:43 -07:00
parent b3a1938c1d
commit 7651ce5e84

View File

@ -63,8 +63,12 @@ public class NvConnection {
} }
public void stop() { public void stop() {
MoonBridge.stopConnection(); // Moonlight-core is not thread-safe with respect to connection start and stop, so
MoonBridge.cleanupBridge(); // we must not invoke that functionality in parallel.
synchronized (MoonBridge.class) {
MoonBridge.stopConnection();
MoonBridge.cleanupBridge();
}
} }
private boolean startApp() throws XmlPullParserException, IOException private boolean startApp() throws XmlPullParserException, IOException
@ -210,6 +214,13 @@ public class NvConnection {
private void establishConnection() { private void establishConnection() {
String appName = context.streamConfig.getApp().getAppName(); String appName = context.streamConfig.getApp().getAppName();
try {
context.serverAddress = InetAddress.getByName(host);
} catch (UnknownHostException e) {
context.connListener.connectionTerminated(-1);
return;
}
context.connListener.stageStarting(appName); context.connListener.stageStarting(appName);
try { try {
@ -234,22 +245,19 @@ public class NvConnection {
context.videoCapabilities); context.videoCapabilities);
} }
public void start(AudioRenderer audioRenderer, VideoDecoderRenderer videoDecoderRenderer, NvConnectionListener connectionListener) public void start(final AudioRenderer audioRenderer, final VideoDecoderRenderer videoDecoderRenderer, final NvConnectionListener connectionListener)
{ {
MoonBridge.setupBridge(videoDecoderRenderer, audioRenderer, connectionListener);
context.connListener = connectionListener;
context.videoCapabilities = videoDecoderRenderer.getCapabilities();
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
try { // Moonlight-core is not thread-safe with respect to connection start and stop, so
context.serverAddress = InetAddress.getByName(host); // we must not invoke that functionality in parallel.
} catch (UnknownHostException e) { synchronized (MoonBridge.class) {
context.connListener.connectionTerminated(-1); MoonBridge.setupBridge(videoDecoderRenderer, audioRenderer, connectionListener);
return; context.connListener = connectionListener;
} context.videoCapabilities = videoDecoderRenderer.getCapabilities();
establishConnection(); establishConnection();
}
} }
}).start(); }).start();
} }