mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 03:23:07 +00:00
Remove the depacketizer thread again...
This commit is contained in:
parent
63ee6ef79a
commit
ccc3eeebe8
@ -7,7 +7,6 @@ import java.net.InetAddress;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
|
|
||||||
import com.limelight.nvstream.NvConnectionListener;
|
import com.limelight.nvstream.NvConnectionListener;
|
||||||
import com.limelight.nvstream.av.ByteBufferDescriptor;
|
import com.limelight.nvstream.av.ByteBufferDescriptor;
|
||||||
@ -19,8 +18,6 @@ public class AudioStream {
|
|||||||
|
|
||||||
public static final int RTP_RECV_BUFFER = 64 * 1024;
|
public static final int RTP_RECV_BUFFER = 64 * 1024;
|
||||||
|
|
||||||
private LinkedBlockingQueue<RtpPacket> packets = new LinkedBlockingQueue<RtpPacket>(100);
|
|
||||||
|
|
||||||
private DatagramSocket rtp;
|
private DatagramSocket rtp;
|
||||||
|
|
||||||
private AudioDepacketizer depacketizer;
|
private AudioDepacketizer depacketizer;
|
||||||
@ -77,8 +74,6 @@ public class AudioStream {
|
|||||||
|
|
||||||
startReceiveThread();
|
startReceiveThread();
|
||||||
|
|
||||||
startDepacketizerThread();
|
|
||||||
|
|
||||||
if ((streamListener.getCapabilities() & AudioRenderer.CAPABILITY_DIRECT_SUBMIT) == 0) {
|
if ((streamListener.getCapabilities() & AudioRenderer.CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
startDecoderThread();
|
startDecoderThread();
|
||||||
}
|
}
|
||||||
@ -113,39 +108,13 @@ public class AudioStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDepacketizerThread()
|
|
||||||
{
|
|
||||||
// This thread lessens the work on the receive thread
|
|
||||||
// so it can spend more time waiting for data
|
|
||||||
Thread t = new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (!isInterrupted())
|
|
||||||
{
|
|
||||||
RtpPacket packet;
|
|
||||||
|
|
||||||
try {
|
|
||||||
packet = packets.take();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
connListener.connectionTerminated(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
depacketizer.decodeInputData(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
threads.add(t);
|
|
||||||
t.setName("Audio - Depacketizer");
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startDecoderThread()
|
private void startDecoderThread()
|
||||||
{
|
{
|
||||||
// Decoder thread
|
// Decoder thread
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
while (!isInterrupted())
|
while (!isInterrupted())
|
||||||
{
|
{
|
||||||
ByteBufferDescriptor samples;
|
ByteBufferDescriptor samples;
|
||||||
@ -158,6 +127,7 @@ public class AudioStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
streamListener.playDecodedAudio(samples.data, samples.offset, samples.length);
|
streamListener.playDecodedAudio(samples.data, samples.offset, samples.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -179,17 +149,14 @@ public class AudioStream {
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
rtp.receive(packet);
|
rtp.receive(packet);
|
||||||
|
desc.length = packet.getLength();
|
||||||
|
depacketizer.decodeInputData(new RtpPacket(desc));
|
||||||
|
desc.reinitialize(new byte[1500], 0, 1500);
|
||||||
|
packet.setData(desc.data, desc.offset, desc.length);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
connListener.connectionTerminated(e);
|
connListener.connectionTerminated(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the packet to the depacketizer thread
|
|
||||||
desc.length = packet.getLength();
|
|
||||||
if (packets.offer(new RtpPacket(desc))) {
|
|
||||||
desc.reinitialize(new byte[1500], 0, 1500);
|
|
||||||
packet.setData(desc.data, desc.offset, desc.length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,6 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
|
|
||||||
import com.limelight.nvstream.NvConnectionListener;
|
import com.limelight.nvstream.NvConnectionListener;
|
||||||
import com.limelight.nvstream.StreamConfiguration;
|
import com.limelight.nvstream.StreamConfiguration;
|
||||||
@ -26,8 +25,6 @@ public class VideoStream {
|
|||||||
public static final int FIRST_FRAME_TIMEOUT = 5000;
|
public static final int FIRST_FRAME_TIMEOUT = 5000;
|
||||||
public static final int RTP_RECV_BUFFER = 128 * 1024;
|
public static final int RTP_RECV_BUFFER = 128 * 1024;
|
||||||
|
|
||||||
private LinkedBlockingQueue<RtpPacket> packets = new LinkedBlockingQueue<RtpPacket>(100);
|
|
||||||
|
|
||||||
private InetAddress host;
|
private InetAddress host;
|
||||||
private DatagramSocket rtp;
|
private DatagramSocket rtp;
|
||||||
private Socket firstFrameSocket;
|
private Socket firstFrameSocket;
|
||||||
@ -169,9 +166,6 @@ public class VideoStream {
|
|||||||
// early packets
|
// early packets
|
||||||
startReceiveThread();
|
startReceiveThread();
|
||||||
|
|
||||||
// Start the depacketizer thread to deal with the RTP data
|
|
||||||
startDepacketizerThread();
|
|
||||||
|
|
||||||
// Start a decode thread if we're not doing direct submit
|
// Start a decode thread if we're not doing direct submit
|
||||||
if ((decRend.getCapabilities() & VideoDecoderRenderer.CAPABILITY_DIRECT_SUBMIT) == 0) {
|
if ((decRend.getCapabilities() & VideoDecoderRenderer.CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
startDecoderThread();
|
startDecoderThread();
|
||||||
@ -210,34 +204,6 @@ public class VideoStream {
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDepacketizerThread()
|
|
||||||
{
|
|
||||||
// This thread lessens the work on the receive thread
|
|
||||||
// so it can spend more time waiting for data
|
|
||||||
Thread t = new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (!isInterrupted())
|
|
||||||
{
|
|
||||||
RtpPacket packet;
|
|
||||||
|
|
||||||
try {
|
|
||||||
packet = packets.take();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
listener.connectionTerminated(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// !!! We no longer own the data buffer at this point !!!
|
|
||||||
depacketizer.addInputData(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
threads.add(t);
|
|
||||||
t.setName("Video - Depacketizer");
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startReceiveThread()
|
private void startReceiveThread()
|
||||||
{
|
{
|
||||||
// Receive thread
|
// Receive thread
|
||||||
@ -251,17 +217,15 @@ public class VideoStream {
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
rtp.receive(packet);
|
rtp.receive(packet);
|
||||||
|
desc.length = packet.getLength();
|
||||||
|
depacketizer.addInputData(new RtpPacket(desc));
|
||||||
|
desc.reinitialize(new byte[1500], 0, 1500);
|
||||||
|
packet.setData(desc.data, desc.offset, desc.length);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
listener.connectionTerminated(e);
|
listener.connectionTerminated(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give the packet to the depacketizer thread
|
|
||||||
desc.length = packet.getLength();
|
|
||||||
if (packets.offer(new RtpPacket(desc))) {
|
|
||||||
desc.reinitialize(new byte[1500], 0, 1500);
|
|
||||||
packet.setData(desc.data, desc.offset, desc.length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user