Skip to content

Commit

Permalink
Merge pull request #6620 from ant-media/improve-rtmp-overflow-check
Browse files Browse the repository at this point in the history
Improve rtmp overflow check because it causes a test fail in enterprise
  • Loading branch information
mekya authored Aug 28, 2024
2 parents 141e1a2 + 127c9a5 commit bb51116
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/main/java/io/antmedia/muxer/MuxAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1074,19 +1074,19 @@ public long correctPacketDtsOverflow(long packetDts) {
*/


if (lastDTS > packetDts) {
if (lastDTS > packetDts && packetDts >= 0) {

if (lastDTS > (packetDts + (long) overflowCount * Integer.MAX_VALUE)) {
//It should be a huge difference such as starting from 0 after Integer.MAX_VALUE between lastDTS and packetDts for the overflow.
//We just check that it's bigger than the half of the Integer.MAX_VALUE
if ((lastDTS - packetDts) > (Integer.MAX_VALUE/2)) {
logger.info("Increasing the overflow count for stream:{} because incoming packetDts:{} is lower than the lastDts:{}", streamId, packetDts, lastDTS);
overflowCount++;
}

packetDts = packetDts + (long) overflowCount * Integer.MAX_VALUE;
}

lastDTS = packetDts;

return packetDts;

return packetDts + (long) overflowCount * Integer.MAX_VALUE;
}

/**
Expand Down
47 changes: 24 additions & 23 deletions src/test/java/io/antmedia/test/MuxerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5610,74 +5610,75 @@ public void testRtmpDtsOverflow() {

muxAdaptor.writeStreamPacket(videoPacket1);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(1, overFlowCount);
assertEquals(0, overFlowCount);
long lastVideoDts = muxAdaptor.getLastDTS();
assertEquals(lastVideoDts, videoPacket1.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);

muxAdaptor.writeStreamPacket(audioPacket2);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(1, overFlowCount);
assertEquals(0, overFlowCount);
lastAudioDts = muxAdaptor.getLastDTS();
assertEquals(lastAudioDts, audioPacket2.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);

muxAdaptor.writeStreamPacket(videoPacket2);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(1, overFlowCount);
assertEquals(0, overFlowCount);
lastVideoDts = muxAdaptor.getLastDTS();
assertEquals(lastVideoDts, videoPacket2.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);


verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, audioPacket2.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE );
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, videoPacket2.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE, 0, 0, false, 0, videoPacket2.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, audioPacket2.getTimestamp() );
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, videoPacket2.getTimestamp(), 0, 0, false, 0, videoPacket2.getTimestamp() );

muxAdaptor.writeStreamPacket(audioPacket3);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(1, overFlowCount);
assertEquals(0, overFlowCount);
lastAudioDts = muxAdaptor.getLastDTS();
assertEquals(lastAudioDts, audioPacket3.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);

muxAdaptor.writeStreamPacket(videoPacket3);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(1, overFlowCount);
assertEquals(0, overFlowCount);
lastVideoDts = muxAdaptor.getLastDTS();
assertEquals(lastVideoDts, videoPacket3.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);

verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, audioPacket3.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, audioPacket3.getTimestamp());

directByteBufferVideo.position(0);
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, videoPacket3.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE, 0, 0, false, 0,
videoPacket3.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, videoPacket3.getTimestamp(), 0, 0, false, 0,
videoPacket3.getTimestamp());

muxAdaptor.writeStreamPacket(audioPacket4);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(2, overFlowCount);
assertEquals(0, overFlowCount);
lastAudioDts = muxAdaptor.getLastDTS();
assertEquals(lastAudioDts, audioPacket4.getTimestamp()+(long) overFlowCount * Integer.MAX_VALUE);
assertEquals(lastAudioDts, audioPacket4.getTimestamp());

muxAdaptor.writeStreamPacket(videoPacket4);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(2, overFlowCount);
assertEquals(0, overFlowCount);
lastVideoDts = muxAdaptor.getLastDTS();
assertEquals(lastVideoDts, videoPacket4.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
assertEquals(lastVideoDts, videoPacket4.getTimestamp());

verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, audioPacket4.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, videoPacket4.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE, 0, 0, false, 0,
videoPacket4.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, audioPacket4.getTimestamp());
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, videoPacket4.getTimestamp(), 0, 0, false, 0,
videoPacket4.getTimestamp() );

muxAdaptor.writeStreamPacket(audioPacketOverflowed);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(3, overFlowCount);
assertEquals(1, overFlowCount);
lastAudioDts = muxAdaptor.getLastDTS();
assertEquals(lastAudioDts, audioPacketOverflowed.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
assertEquals(lastAudioDts, audioPacketOverflowed.getTimestamp());

muxAdaptor.writeStreamPacket(videoPacketOverflowed);
overFlowCount = muxAdaptor.getOverflowCount();
assertEquals(3, overFlowCount);
assertEquals(1, overFlowCount);
lastVideoDts = muxAdaptor.getLastDTS();
assertEquals(lastVideoDts, videoPacketOverflowed.getTimestamp() + (long) overFlowCount * Integer.MAX_VALUE);
assertEquals(lastVideoDts, videoPacketOverflowed.getTimestamp());

verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, lastAudioDts);
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, lastVideoDts, 0, 0, false, 0, lastVideoDts);
verify(hlsMuxer,times(1)).writeAudioBuffer(directByteBuffer,1, lastAudioDts + (long) overFlowCount * Integer.MAX_VALUE);
verify(hlsMuxer,times(1)).writeVideoBuffer(directByteBufferVideo, lastVideoDts + (long) overFlowCount * Integer.MAX_VALUE,
0, 0, false, 0, lastVideoDts + (long) overFlowCount * Integer.MAX_VALUE);
}

}
Binary file removed test_hevc.flv
Binary file not shown.

0 comments on commit bb51116

Please sign in to comment.