mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 11:33:06 +00:00
Add support for sending proper packet loss statistics for server-side bandwidth scaling
This commit is contained in:
parent
04941212cd
commit
0c8c108bd1
@ -8,4 +8,6 @@ public interface ConnectionStatusListener {
|
|||||||
public void connectionSinkTooSlow(int firstLostFrame, int lastLostFrame);
|
public void connectionSinkTooSlow(int firstLostFrame, int lastLostFrame);
|
||||||
|
|
||||||
public void connectionReceivedFrame(int frameIndex);
|
public void connectionReceivedFrame(int frameIndex);
|
||||||
|
|
||||||
|
public void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ public class VideoDepacketizer {
|
|||||||
private int currentlyDecoding = DecodeUnit.TYPE_UNKNOWN;
|
private int currentlyDecoding = DecodeUnit.TYPE_UNKNOWN;
|
||||||
|
|
||||||
// Sequencing state
|
// Sequencing state
|
||||||
|
private int lastPacketInStream = 0;
|
||||||
private int nextFrameNumber = 1;
|
private int nextFrameNumber = 1;
|
||||||
private int nextPacketNumber;
|
private int nextPacketNumber;
|
||||||
private int startFrameNumber = 1;
|
private int startFrameNumber = 1;
|
||||||
@ -287,6 +288,13 @@ public class VideoDepacketizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int streamPacketIndex = packet.getStreamPacketIndex();
|
||||||
|
if (streamPacketIndex != (int)(lastPacketInStream + 1)) {
|
||||||
|
// Packets were lost so report this to the server
|
||||||
|
controlListener.connectionLostPackets(lastPacketInStream, streamPacketIndex);
|
||||||
|
}
|
||||||
|
lastPacketInStream = streamPacketIndex;
|
||||||
|
|
||||||
nextPacketNumber++;
|
nextPacketNumber++;
|
||||||
|
|
||||||
// Remove extra padding
|
// Remove extra padding
|
||||||
|
@ -13,6 +13,7 @@ public class VideoPacket {
|
|||||||
private int totalPackets;
|
private int totalPackets;
|
||||||
private int payloadLength;
|
private int payloadLength;
|
||||||
private int flags;
|
private int flags;
|
||||||
|
private int streamPacketIndex;
|
||||||
|
|
||||||
public static final int FLAG_EOF = 0x2;
|
public static final int FLAG_EOF = 0x2;
|
||||||
public static final int FLAG_SOF = 0x4;
|
public static final int FLAG_SOF = 0x4;
|
||||||
@ -29,6 +30,7 @@ public class VideoPacket {
|
|||||||
totalPackets = bb.getInt();
|
totalPackets = bb.getInt();
|
||||||
flags = bb.getInt();
|
flags = bb.getInt();
|
||||||
payloadLength = bb.getInt();
|
payloadLength = bb.getInt();
|
||||||
|
streamPacketIndex = bb.getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFlags()
|
public int getFlags()
|
||||||
@ -56,6 +58,11 @@ public class VideoPacket {
|
|||||||
return totalPackets;
|
return totalPackets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStreamPacketIndex()
|
||||||
|
{
|
||||||
|
return streamPacketIndex;
|
||||||
|
}
|
||||||
|
|
||||||
public ByteBufferDescriptor getNewPayloadDescriptor()
|
public ByteBufferDescriptor getNewPayloadDescriptor()
|
||||||
{
|
{
|
||||||
return new ByteBufferDescriptor(buffer.data, buffer.offset+56, buffer.length-56);
|
return new ByteBufferDescriptor(buffer.data, buffer.offset+56, buffer.length-56);
|
||||||
|
@ -37,7 +37,10 @@ public class ControlStream implements ConnectionStatusListener {
|
|||||||
public static final short PTYPE_FRAME_STATS = 0x1417;
|
public static final short PTYPE_FRAME_STATS = 0x1417;
|
||||||
public static final short PPAYLEN_FRAME_STATS = 64;
|
public static final short PPAYLEN_FRAME_STATS = 64;
|
||||||
|
|
||||||
|
public static final int LOSS_REPORT_INTERVAL_MS = 50;
|
||||||
|
|
||||||
private int currentFrame;
|
private int currentFrame;
|
||||||
|
private int lossCountSinceLastReport;
|
||||||
|
|
||||||
private NvConnectionListener listener;
|
private NvConnectionListener listener;
|
||||||
private InetAddress host;
|
private InetAddress host;
|
||||||
@ -91,11 +94,10 @@ public class ControlStream implements ConnectionStatusListener {
|
|||||||
{
|
{
|
||||||
ByteBuffer bb = ByteBuffer.allocate(PPAYLEN_LOSS_STATS).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer bb = ByteBuffer.allocate(PPAYLEN_LOSS_STATS).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
|
||||||
bb.putInt(0);
|
bb.putInt(lossCountSinceLastReport); // Packet loss count
|
||||||
bb.putInt(30);
|
bb.putInt(LOSS_REPORT_INTERVAL_MS); // Time since last report in milliseconds
|
||||||
bb.putInt(1000);
|
bb.putInt(1000);
|
||||||
bb.putInt(currentFrame);
|
bb.putLong(currentFrame); // Last successfully received frame
|
||||||
bb.putInt(0);
|
|
||||||
|
|
||||||
sendPacket(new NvCtlPacket(PTYPE_LOSS_STATS, PPAYLEN_LOSS_STATS, bb.array()));
|
sendPacket(new NvCtlPacket(PTYPE_LOSS_STATS, PPAYLEN_LOSS_STATS, bb.array()));
|
||||||
}
|
}
|
||||||
@ -147,13 +149,14 @@ public class ControlStream implements ConnectionStatusListener {
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
sendLossStats();
|
sendLossStats();
|
||||||
|
lossCountSinceLastReport = 0;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
listener.connectionTerminated(e);
|
listener.connectionTerminated(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(LOSS_REPORT_INTERVAL_MS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
listener.connectionTerminated(e);
|
listener.connectionTerminated(e);
|
||||||
return;
|
return;
|
||||||
@ -419,4 +422,9 @@ public class ControlStream implements ConnectionStatusListener {
|
|||||||
public void connectionReceivedFrame(int frameIndex) {
|
public void connectionReceivedFrame(int frameIndex) {
|
||||||
currentFrame = frameIndex;
|
currentFrame = frameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket) {
|
||||||
|
// Update the loss count for the next loss report
|
||||||
|
lossCountSinceLastReport += (nextReceivedPacket - lastReceivedPacket) - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user