mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Fix some ANRs and force-close errors when connection failures occur.
This commit is contained in:
parent
4d80373f25
commit
83ad55e436
@ -64,8 +64,13 @@ public class NvAudioStream {
|
|||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
//session.endSession();
|
|
||||||
track.release();
|
if (session != null) {
|
||||||
|
//session.endSession();
|
||||||
|
}
|
||||||
|
if (track != null) {
|
||||||
|
track.release();
|
||||||
|
}
|
||||||
|
|
||||||
threads.clear();
|
threads.clear();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ public class NvVideoStream {
|
|||||||
|
|
||||||
private RTPSession session;
|
private RTPSession session;
|
||||||
private DatagramSocket rtp, rtcp;
|
private DatagramSocket rtp, rtcp;
|
||||||
|
private Socket firstFrameSocket;
|
||||||
|
|
||||||
|
|
||||||
private LinkedList<Thread> threads = new LinkedList<Thread>();
|
private LinkedList<Thread> threads = new LinkedList<Thread>();
|
||||||
|
|
||||||
@ -63,6 +65,11 @@ public class NvVideoStream {
|
|||||||
if (rtcp != null) {
|
if (rtcp != null) {
|
||||||
rtcp.close();
|
rtcp.close();
|
||||||
}
|
}
|
||||||
|
if (firstFrameSocket != null) {
|
||||||
|
try {
|
||||||
|
firstFrameSocket.close();
|
||||||
|
} catch (IOException e) {}
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for threads to terminate
|
// Wait for threads to terminate
|
||||||
for (Thread t : threads) {
|
for (Thread t : threads) {
|
||||||
@ -71,8 +78,12 @@ public class NvVideoStream {
|
|||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
//session.endSession();
|
if (session != null) {
|
||||||
videoDecoder.release();
|
//session.endSession();
|
||||||
|
}
|
||||||
|
if (videoDecoder != null) {
|
||||||
|
videoDecoder.release();
|
||||||
|
}
|
||||||
|
|
||||||
threads.clear();
|
threads.clear();
|
||||||
}
|
}
|
||||||
@ -85,27 +96,30 @@ public class NvVideoStream {
|
|||||||
private void readFirstFrame(String host) throws IOException
|
private void readFirstFrame(String host) throws IOException
|
||||||
{
|
{
|
||||||
byte[] firstFrame = depacketizer.allocatePacketBuffer();
|
byte[] firstFrame = depacketizer.allocatePacketBuffer();
|
||||||
Socket s = new Socket(host, FIRST_FRAME_PORT);
|
|
||||||
|
|
||||||
System.out.println("VID: Waiting for first frame");
|
System.out.println("VID: Waiting for first frame");
|
||||||
InputStream firstFrameStream = s.getInputStream();
|
firstFrameSocket = new Socket(host, FIRST_FRAME_PORT);
|
||||||
|
|
||||||
int offset = 0;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
int bytesRead = firstFrameStream.read(firstFrame, offset, firstFrame.length-offset);
|
|
||||||
|
|
||||||
if (bytesRead == -1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
offset += bytesRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
System.out.println("VID: First frame read ("+offset+" bytes)");
|
|
||||||
|
|
||||||
depacketizer.addInputData(new AvVideoPacket(new AvByteBufferDescriptor(firstFrame, 0, offset)));
|
try {
|
||||||
|
InputStream firstFrameStream = firstFrameSocket.getInputStream();
|
||||||
|
|
||||||
|
int offset = 0;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int bytesRead = firstFrameStream.read(firstFrame, offset, firstFrame.length-offset);
|
||||||
|
|
||||||
|
if (bytesRead == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
offset += bytesRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("VID: First frame read ("+offset+" bytes)");
|
||||||
|
depacketizer.addInputData(new AvVideoPacket(new AvByteBufferDescriptor(firstFrame, 0, offset)));
|
||||||
|
} finally {
|
||||||
|
firstFrameSocket.close();
|
||||||
|
firstFrameSocket = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupRtpSession(String host) throws SocketException
|
public void setupRtpSession(String host) throws SocketException
|
||||||
@ -161,7 +175,6 @@ public class NvVideoStream {
|
|||||||
try {
|
try {
|
||||||
readFirstFrame(host);
|
readFirstFrame(host);
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
e2.printStackTrace();
|
|
||||||
abort();
|
abort();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user