mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Reference count packets in the RTP queue so they don't get overwritten while queued
This commit is contained in:
parent
8a465edad9
commit
df59c99f80
@ -67,4 +67,22 @@ public class RtpPacket implements RtpPacketFields {
|
||||
{
|
||||
bb.reinitialize(buffer.data, buffer.offset+headerSize, buffer.length-headerSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int referencePacket() {
|
||||
// There's no circular buffer for audio packets so this is a no-op
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int dereferencePacket() {
|
||||
// There's no circular buffer for audio packets so this is a no-op
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRefCount() {
|
||||
// There's no circular buffer for audio packets so this is a no-op
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,10 @@ public interface RtpPacketFields {
|
||||
public byte getPacketType();
|
||||
|
||||
public short getRtpSequenceNumber();
|
||||
|
||||
public int referencePacket();
|
||||
|
||||
public int dereferencePacket();
|
||||
|
||||
public int getRefCount();
|
||||
}
|
||||
|
@ -68,6 +68,9 @@ public class RtpReorderQueue {
|
||||
oldestQueuedEntry = entry;
|
||||
}
|
||||
|
||||
// Add a reference to the packet while it's in the queue
|
||||
packet.referencePacket();
|
||||
|
||||
if (head) {
|
||||
queue.addFirst(entry);
|
||||
}
|
||||
@ -111,6 +114,11 @@ public class RtpReorderQueue {
|
||||
return lowestSeqEntry;
|
||||
}
|
||||
|
||||
private void removeEntry(RtpQueueEntry entry) {
|
||||
queue.remove(entry);
|
||||
entry.packet.dereferencePacket();
|
||||
}
|
||||
|
||||
private RtpQueueEntry validateQueueConstraints() {
|
||||
if (queue.isEmpty()) {
|
||||
return null;
|
||||
@ -121,14 +129,14 @@ public class RtpReorderQueue {
|
||||
// Check that the queue's time constraint is satisfied
|
||||
if (TimeHelper.getMonotonicMillis() - oldestQueuedTime > maxQueueTime) {
|
||||
LimeLog.info("Discarding RTP packet queued for too long: "+(TimeHelper.getMonotonicMillis() - oldestQueuedTime));
|
||||
queue.remove(oldestQueuedEntry);
|
||||
removeEntry(oldestQueuedEntry);
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
// Check that the queue's size constraint is satisfied
|
||||
if (queue.size() == maxSize) {
|
||||
LimeLog.info("Discarding RTP packet after queue overgrowth");
|
||||
queue.remove(oldestQueuedEntry);
|
||||
removeEntry(oldestQueuedEntry);
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
@ -203,6 +211,8 @@ public class RtpReorderQueue {
|
||||
}
|
||||
}
|
||||
|
||||
// This function returns a referenced packet. The caller must dereference
|
||||
// the packet when it is finished.
|
||||
public RtpPacketFields getQueuedPacket() {
|
||||
RtpQueueEntry queuedEntry = null;
|
||||
|
||||
|
@ -219,6 +219,7 @@ public class AudioStream {
|
||||
if (queueStatus == RtpReorderQueue.RtpQueueStatus.QUEUED_PACKETS_READY) {
|
||||
while ((queuedPacket = (RtpPacket) rtpQueue.getQueuedPacket()) != null) {
|
||||
depacketizer.decodeInputData(queuedPacket);
|
||||
queuedPacket.dereferencePacket();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class VideoPacket implements RtpPacketFields {
|
||||
return rtpSequenceNumber;
|
||||
}
|
||||
|
||||
int referencePacket() {
|
||||
public int referencePacket() {
|
||||
if (useAtomicRefCount) {
|
||||
return duAtomicRefCount.incrementAndGet();
|
||||
}
|
||||
@ -124,7 +124,7 @@ public class VideoPacket implements RtpPacketFields {
|
||||
}
|
||||
}
|
||||
|
||||
int dereferencePacket() {
|
||||
public int dereferencePacket() {
|
||||
if (useAtomicRefCount) {
|
||||
return duAtomicRefCount.decrementAndGet();
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class VideoPacket implements RtpPacketFields {
|
||||
}
|
||||
}
|
||||
|
||||
int getRefCount() {
|
||||
public int getRefCount() {
|
||||
if (useAtomicRefCount) {
|
||||
return duAtomicRefCount.get();
|
||||
}
|
||||
|
@ -222,6 +222,7 @@ public class VideoStream {
|
||||
// The packet queue now has packets ready
|
||||
while ((queuedPacket = (VideoPacket) rtpQueue.getQueuedPacket()) != null) {
|
||||
depacketizer.addInputData(queuedPacket);
|
||||
queuedPacket.dereferencePacket();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user