From cba3e76f7a3c68e670ce5e48478caa5414dd1203 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 12 Oct 2023 11:58:49 +0200 Subject: [PATCH] expose hascongestion precent used --- .../com/pedro/library/base/Camera1Base.java | 2 + .../com/pedro/library/base/Camera2Base.java | 2 + .../com/pedro/library/base/DisplayBase.java | 2 + .../com/pedro/library/base/FromFileBase.java | 2 + .../com/pedro/library/base/OnlyAudioBase.java | 2 + .../java/com/pedro/library/base/StreamBase.kt | 1 + .../library/multiple/MultiRtpCamera1.java | 13 +++++ .../library/multiple/MultiRtpCamera2.java | 13 +++++ .../library/multiple/MultiRtpDisplay.java | 13 +++++ .../library/multiple/MultiRtpOnlyAudio.java | 13 +++++ .../com/pedro/library/rtmp/RtmpCamera1.java | 5 ++ .../com/pedro/library/rtmp/RtmpCamera2.java | 5 ++ .../com/pedro/library/rtmp/RtmpDisplay.java | 5 ++ .../com/pedro/library/rtmp/RtmpFromFile.java | 5 ++ .../com/pedro/library/rtmp/RtmpOnlyAudio.java | 5 ++ .../java/com/pedro/library/rtmp/RtmpStream.kt | 2 + .../com/pedro/library/rtsp/RtspCamera1.java | 5 ++ .../com/pedro/library/rtsp/RtspCamera2.java | 5 ++ .../com/pedro/library/rtsp/RtspDisplay.java | 5 ++ .../com/pedro/library/rtsp/RtspFromFile.java | 5 ++ .../com/pedro/library/rtsp/RtspOnlyAudio.java | 5 ++ .../java/com/pedro/library/rtsp/RtspStream.kt | 2 + .../com/pedro/library/srt/SrtCamera1.java | 5 ++ .../com/pedro/library/srt/SrtCamera2.java | 5 ++ .../com/pedro/library/srt/SrtDisplay.java | 5 ++ .../com/pedro/library/srt/SrtFromFile.java | 5 ++ .../com/pedro/library/srt/SrtOnlyAudio.java | 53 ++++++++++--------- .../java/com/pedro/library/srt/SrtStream.kt | 2 + .../java/com/pedro/rtmp/rtmp/RtmpClient.kt | 6 ++- .../java/com/pedro/rtmp/rtmp/RtmpSender.kt | 6 ++- .../java/com/pedro/rtsp/rtsp/RtspClient.kt | 6 ++- .../java/com/pedro/rtsp/rtsp/RtspSender.kt | 6 ++- .../main/java/com/pedro/srt/srt/SrtClient.kt | 6 ++- .../main/java/com/pedro/srt/srt/SrtSender.kt | 6 ++- 34 files changed, 192 insertions(+), 36 deletions(-) diff --git a/library/src/main/java/com/pedro/library/base/Camera1Base.java b/library/src/main/java/com/pedro/library/base/Camera1Base.java index 09b1716e2..68d558d80 100644 --- a/library/src/main/java/com/pedro/library/base/Camera1Base.java +++ b/library/src/main/java/com/pedro/library/base/Camera1Base.java @@ -807,6 +807,8 @@ public boolean reTry(long delay, String reason) { //cache control public abstract boolean hasCongestion(); + public abstract boolean hasCongestion(float percentUsed); + public abstract void resizeCache(int newSize) throws RuntimeException; public abstract int getCacheSize(); diff --git a/library/src/main/java/com/pedro/library/base/Camera2Base.java b/library/src/main/java/com/pedro/library/base/Camera2Base.java index e7ac521e9..14f7415ad 100644 --- a/library/src/main/java/com/pedro/library/base/Camera2Base.java +++ b/library/src/main/java/com/pedro/library/base/Camera2Base.java @@ -752,6 +752,8 @@ public boolean reTry(long delay, String reason) { //cache control public abstract boolean hasCongestion(); + public abstract boolean hasCongestion(float percentUsed); + public abstract void resizeCache(int newSize) throws RuntimeException; public abstract int getCacheSize(); diff --git a/library/src/main/java/com/pedro/library/base/DisplayBase.java b/library/src/main/java/com/pedro/library/base/DisplayBase.java index bcf3ef381..c4bf31bea 100644 --- a/library/src/main/java/com/pedro/library/base/DisplayBase.java +++ b/library/src/main/java/com/pedro/library/base/DisplayBase.java @@ -485,6 +485,8 @@ public boolean reTry(long delay, String reason) { //cache control public abstract boolean hasCongestion(); + public abstract boolean hasCongestion(float percentUsed); + public abstract void resizeCache(int newSize) throws RuntimeException; public abstract int getCacheSize(); diff --git a/library/src/main/java/com/pedro/library/base/FromFileBase.java b/library/src/main/java/com/pedro/library/base/FromFileBase.java index 49aa6a6bf..fff866712 100644 --- a/library/src/main/java/com/pedro/library/base/FromFileBase.java +++ b/library/src/main/java/com/pedro/library/base/FromFileBase.java @@ -448,6 +448,8 @@ public boolean reTry(long delay, String reason) { //cache control public abstract boolean hasCongestion(); + public abstract boolean hasCongestion(float percentUsed); + public abstract void resizeCache(int newSize) throws RuntimeException; public abstract int getCacheSize(); diff --git a/library/src/main/java/com/pedro/library/base/OnlyAudioBase.java b/library/src/main/java/com/pedro/library/base/OnlyAudioBase.java index ab6ad259e..eba813dc1 100644 --- a/library/src/main/java/com/pedro/library/base/OnlyAudioBase.java +++ b/library/src/main/java/com/pedro/library/base/OnlyAudioBase.java @@ -293,6 +293,8 @@ public boolean reTry(long delay, String reason) { //cache control public abstract boolean hasCongestion(); + public abstract boolean hasCongestion(float percentUsed); + public abstract void resizeCache(int newSize) throws RuntimeException; public abstract int getCacheSize(); diff --git a/library/src/main/java/com/pedro/library/base/StreamBase.kt b/library/src/main/java/com/pedro/library/base/StreamBase.kt index e238ca64e..408944ab6 100644 --- a/library/src/main/java/com/pedro/library/base/StreamBase.kt +++ b/library/src/main/java/com/pedro/library/base/StreamBase.kt @@ -557,6 +557,7 @@ abstract class StreamBase( protected abstract fun reConnect(delay: Long, backupUrl: String?) abstract fun setReTries(reTries: Int) abstract fun hasCongestion(): Boolean + abstract fun hasCongestion(percentUsed: Float = 20f): Boolean abstract fun setLogs(enabled: Boolean) abstract fun setCheckServerAlive(enabled: Boolean) @Throws(RuntimeException::class) diff --git a/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera1.java b/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera1.java index fa8cbbd60..c2c786b06 100644 --- a/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera1.java +++ b/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera1.java @@ -439,11 +439,24 @@ public boolean hasCongestion(RtpType rtpType, int index) { } } + public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) { + if (rtpType == RtpType.RTMP) { + return rtmpClients[index].hasCongestion(percentUsed); + } else { + return rtspClients[index].hasCongestion(percentUsed); + } + } + @Override public boolean hasCongestion() { return false; } + @Override + public boolean hasCongestion(float percentUsed) { + return false; + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { for (RtmpClient rtmpClient: rtmpClients) { diff --git a/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera2.java b/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera2.java index 954d74a8f..ee6f5d670 100644 --- a/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera2.java +++ b/library/src/main/java/com/pedro/library/multiple/MultiRtpCamera2.java @@ -439,11 +439,24 @@ public boolean hasCongestion(RtpType rtpType, int index) { } } + public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) { + if (rtpType == RtpType.RTMP) { + return rtmpClients[index].hasCongestion(percentUsed); + } else { + return rtspClients[index].hasCongestion(percentUsed); + } + } + @Override public boolean hasCongestion() { return false; } + @Override + public boolean hasCongestion(float percentUsed) { + return false; + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { for (RtmpClient rtmpClient: rtmpClients) { diff --git a/library/src/main/java/com/pedro/library/multiple/MultiRtpDisplay.java b/library/src/main/java/com/pedro/library/multiple/MultiRtpDisplay.java index 4405d0ee2..450e0525b 100644 --- a/library/src/main/java/com/pedro/library/multiple/MultiRtpDisplay.java +++ b/library/src/main/java/com/pedro/library/multiple/MultiRtpDisplay.java @@ -254,11 +254,24 @@ public boolean hasCongestion(RtpType rtpType, int index) { } } + public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) { + if (rtpType == RtpType.RTMP) { + return rtmpClients[index].hasCongestion(percentUsed); + } else { + return rtspClients[index].hasCongestion(percentUsed); + } + } + @Override public boolean hasCongestion() { return false; } + @Override + public boolean hasCongestion(float percentUsed) { + return false; + } + public void resizeCache(RtpType rtpType, int index, int newSize) { if (rtpType == RtpType.RTMP) { rtmpClients[index].resizeCache(newSize); diff --git a/library/src/main/java/com/pedro/library/multiple/MultiRtpOnlyAudio.java b/library/src/main/java/com/pedro/library/multiple/MultiRtpOnlyAudio.java index 1e3311db6..3c2cd4d08 100644 --- a/library/src/main/java/com/pedro/library/multiple/MultiRtpOnlyAudio.java +++ b/library/src/main/java/com/pedro/library/multiple/MultiRtpOnlyAudio.java @@ -361,11 +361,24 @@ public boolean hasCongestion(RtpType rtpType, int index) { } } + public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) { + if (rtpType == RtpType.RTMP) { + return rtmpClients[index].hasCongestion(percentUsed); + } else { + return rtspClients[index].hasCongestion(percentUsed); + } + } + @Override public boolean hasCongestion() { return false; } + @Override + public boolean hasCongestion(float percentUsed) { + return false; + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { for (RtmpClient rtmpClient: rtmpClients) { diff --git a/library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java b/library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java index ed207861d..c10fad354 100644 --- a/library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java +++ b/library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java @@ -215,6 +215,11 @@ public boolean hasCongestion() { return rtmpClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtmpClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtmpClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java b/library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java index 8bcaf570b..0a64a0802 100644 --- a/library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java +++ b/library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java @@ -224,6 +224,11 @@ public boolean hasCongestion() { return rtmpClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtmpClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtmpClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java b/library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java index fcb67fdc9..2c3aaddbb 100644 --- a/library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java +++ b/library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java @@ -187,6 +187,11 @@ public boolean hasCongestion() { return rtmpClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtmpClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtmpClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtmp/RtmpFromFile.java b/library/src/main/java/com/pedro/library/rtmp/RtmpFromFile.java index 36e5b6e4e..0d92b26b9 100644 --- a/library/src/main/java/com/pedro/library/rtmp/RtmpFromFile.java +++ b/library/src/main/java/com/pedro/library/rtmp/RtmpFromFile.java @@ -210,6 +210,11 @@ public boolean hasCongestion() { return rtmpClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtmpClient.hasCongestion(percentUsed); + } + @Override protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) { rtmpClient.setVideoInfo(sps, pps, vps); diff --git a/library/src/main/java/com/pedro/library/rtmp/RtmpOnlyAudio.java b/library/src/main/java/com/pedro/library/rtmp/RtmpOnlyAudio.java index 1978bdb40..d4417ec5e 100644 --- a/library/src/main/java/com/pedro/library/rtmp/RtmpOnlyAudio.java +++ b/library/src/main/java/com/pedro/library/rtmp/RtmpOnlyAudio.java @@ -159,6 +159,11 @@ public boolean hasCongestion() { return rtmpClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtmpClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtmpClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtmp/RtmpStream.kt b/library/src/main/java/com/pedro/library/rtmp/RtmpStream.kt index 2d44f44ec..0235e9df6 100644 --- a/library/src/main/java/com/pedro/library/rtmp/RtmpStream.kt +++ b/library/src/main/java/com/pedro/library/rtmp/RtmpStream.kt @@ -115,6 +115,8 @@ class RtmpStream(context: Context, connectCheckerRtmp: ConnectCheckerRtmp, video override fun hasCongestion(): Boolean = rtmpClient.hasCongestion() + override fun hasCongestion(percentUsed: Float): Boolean = rtmpClient.hasCongestion(percentUsed) + override fun setLogs(enabled: Boolean) { rtmpClient.setLogs(enabled) } diff --git a/library/src/main/java/com/pedro/library/rtsp/RtspCamera1.java b/library/src/main/java/com/pedro/library/rtsp/RtspCamera1.java index af1fdaeaa..479abd475 100644 --- a/library/src/main/java/com/pedro/library/rtsp/RtspCamera1.java +++ b/library/src/main/java/com/pedro/library/rtsp/RtspCamera1.java @@ -181,6 +181,11 @@ public boolean hasCongestion() { return rtspClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtspClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtspClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtsp/RtspCamera2.java b/library/src/main/java/com/pedro/library/rtsp/RtspCamera2.java index 19859ff73..0e6eeee3c 100644 --- a/library/src/main/java/com/pedro/library/rtsp/RtspCamera2.java +++ b/library/src/main/java/com/pedro/library/rtsp/RtspCamera2.java @@ -190,6 +190,11 @@ public boolean hasCongestion() { return rtspClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtspClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtspClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtsp/RtspDisplay.java b/library/src/main/java/com/pedro/library/rtsp/RtspDisplay.java index 5534e349b..128066124 100644 --- a/library/src/main/java/com/pedro/library/rtsp/RtspDisplay.java +++ b/library/src/main/java/com/pedro/library/rtsp/RtspDisplay.java @@ -153,6 +153,11 @@ public boolean hasCongestion() { return rtspClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtspClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtspClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtsp/RtspFromFile.java b/library/src/main/java/com/pedro/library/rtsp/RtspFromFile.java index d52ed0043..07839e24b 100644 --- a/library/src/main/java/com/pedro/library/rtsp/RtspFromFile.java +++ b/library/src/main/java/com/pedro/library/rtsp/RtspFromFile.java @@ -177,6 +177,11 @@ public boolean hasCongestion() { return rtspClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtspClient.hasCongestion(percentUsed); + } + @Override protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) { rtspClient.setVideoInfo(sps, pps, vps); diff --git a/library/src/main/java/com/pedro/library/rtsp/RtspOnlyAudio.java b/library/src/main/java/com/pedro/library/rtsp/RtspOnlyAudio.java index 06fc3ea5a..26483b889 100644 --- a/library/src/main/java/com/pedro/library/rtsp/RtspOnlyAudio.java +++ b/library/src/main/java/com/pedro/library/rtsp/RtspOnlyAudio.java @@ -142,6 +142,11 @@ public boolean hasCongestion() { return rtspClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtspClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtspClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/rtsp/RtspStream.kt b/library/src/main/java/com/pedro/library/rtsp/RtspStream.kt index 5aef08fd7..234b064bd 100644 --- a/library/src/main/java/com/pedro/library/rtsp/RtspStream.kt +++ b/library/src/main/java/com/pedro/library/rtsp/RtspStream.kt @@ -83,6 +83,8 @@ class RtspStream(context: Context, connectCheckerRtsp: ConnectCheckerRtsp, video } override fun hasCongestion(): Boolean = rtspClient.hasCongestion() + + override fun hasCongestion(percentUsed: Float): Boolean = rtspClient.hasCongestion(percentUsed) override fun setLogs(enabled: Boolean) { rtspClient.setLogs(enabled) diff --git a/library/src/main/java/com/pedro/library/srt/SrtCamera1.java b/library/src/main/java/com/pedro/library/srt/SrtCamera1.java index e71be3cf6..d8fd24f77 100644 --- a/library/src/main/java/com/pedro/library/srt/SrtCamera1.java +++ b/library/src/main/java/com/pedro/library/srt/SrtCamera1.java @@ -172,6 +172,11 @@ public boolean hasCongestion() { return srtClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return srtClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { srtClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/srt/SrtCamera2.java b/library/src/main/java/com/pedro/library/srt/SrtCamera2.java index 11a2fa8d0..cd5034cbe 100644 --- a/library/src/main/java/com/pedro/library/srt/SrtCamera2.java +++ b/library/src/main/java/com/pedro/library/srt/SrtCamera2.java @@ -181,6 +181,11 @@ public boolean hasCongestion() { return srtClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return srtClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { srtClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/srt/SrtDisplay.java b/library/src/main/java/com/pedro/library/srt/SrtDisplay.java index 517f958d4..8e08ed1f4 100644 --- a/library/src/main/java/com/pedro/library/srt/SrtDisplay.java +++ b/library/src/main/java/com/pedro/library/srt/SrtDisplay.java @@ -144,6 +144,11 @@ public boolean hasCongestion() { return rtmpClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return rtmpClient.hasCongestion(percentUsed); + } + @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { rtmpClient.sendAudio(aacBuffer, info); diff --git a/library/src/main/java/com/pedro/library/srt/SrtFromFile.java b/library/src/main/java/com/pedro/library/srt/SrtFromFile.java index ce9207269..f80b967da 100644 --- a/library/src/main/java/com/pedro/library/srt/SrtFromFile.java +++ b/library/src/main/java/com/pedro/library/srt/SrtFromFile.java @@ -167,6 +167,11 @@ public boolean hasCongestion() { return srtClient.hasCongestion(); } + @Override + public boolean hasCongestion(float percentUsed) { + return srtClient.hasCongestion(percentUsed); + } + @Override protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) { srtClient.setVideoInfo(sps, pps, vps); diff --git a/library/src/main/java/com/pedro/library/srt/SrtOnlyAudio.java b/library/src/main/java/com/pedro/library/srt/SrtOnlyAudio.java index 0d04dd717..79d477374 100644 --- a/library/src/main/java/com/pedro/library/srt/SrtOnlyAudio.java +++ b/library/src/main/java/com/pedro/library/srt/SrtOnlyAudio.java @@ -34,116 +34,121 @@ */ public class SrtOnlyAudio extends OnlyAudioBase { - private final SrtClient rtmpClient; + private final SrtClient srtClient; public SrtOnlyAudio(ConnectCheckerSrt connectChecker) { super(); - rtmpClient = new SrtClient(connectChecker); - rtmpClient.setOnlyAudio(true); + srtClient = new SrtClient(connectChecker); + srtClient.setOnlyAudio(true); } @Override public void resizeCache(int newSize) throws RuntimeException { - rtmpClient.resizeCache(newSize); + srtClient.resizeCache(newSize); } @Override public int getCacheSize() { - return rtmpClient.getCacheSize(); + return srtClient.getCacheSize(); } @Override public long getSentAudioFrames() { - return rtmpClient.getSentAudioFrames(); + return srtClient.getSentAudioFrames(); } @Override public long getSentVideoFrames() { - return rtmpClient.getSentVideoFrames(); + return srtClient.getSentVideoFrames(); } @Override public long getDroppedAudioFrames() { - return rtmpClient.getDroppedAudioFrames(); + return srtClient.getDroppedAudioFrames(); } @Override public long getDroppedVideoFrames() { - return rtmpClient.getDroppedVideoFrames(); + return srtClient.getDroppedVideoFrames(); } @Override public void resetSentAudioFrames() { - rtmpClient.resetSentAudioFrames(); + srtClient.resetSentAudioFrames(); } @Override public void resetSentVideoFrames() { - rtmpClient.resetSentVideoFrames(); + srtClient.resetSentVideoFrames(); } @Override public void resetDroppedAudioFrames() { - rtmpClient.resetDroppedAudioFrames(); + srtClient.resetDroppedAudioFrames(); } @Override public void resetDroppedVideoFrames() { - rtmpClient.resetDroppedVideoFrames(); + srtClient.resetDroppedVideoFrames(); } @Override public void setAuthorization(String user, String password) { - rtmpClient.setAuthorization(user, password); + srtClient.setAuthorization(user, password); } @Override protected void prepareAudioRtp(boolean isStereo, int sampleRate) { - rtmpClient.setAudioInfo(sampleRate, isStereo); + srtClient.setAudioInfo(sampleRate, isStereo); } @Override protected void startStreamRtp(String url) { - rtmpClient.connect(url); + srtClient.connect(url); } @Override protected void stopStreamRtp() { - rtmpClient.disconnect(); + srtClient.disconnect(); } @Override public void setReTries(int reTries) { - rtmpClient.setReTries(reTries); + srtClient.setReTries(reTries); } @Override protected boolean shouldRetry(String reason) { - return rtmpClient.shouldRetry(reason); + return srtClient.shouldRetry(reason); } @Override public void reConnect(long delay, @Nullable String backupUrl) { - rtmpClient.reConnect(delay, backupUrl); + srtClient.reConnect(delay, backupUrl); } @Override public boolean hasCongestion() { - return rtmpClient.hasCongestion(); + return srtClient.hasCongestion(); + } + + @Override + public boolean hasCongestion(float percentUsed) { + return srtClient.hasCongestion(percentUsed); } @Override protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) { - rtmpClient.sendAudio(aacBuffer, info); + srtClient.sendAudio(aacBuffer, info); } @Override public void setLogs(boolean enable) { - rtmpClient.setLogs(enable); + srtClient.setLogs(enable); } @Override public void setCheckServerAlive(boolean enable) { - rtmpClient.setCheckServerAlive(enable); + srtClient.setCheckServerAlive(enable); } } diff --git a/library/src/main/java/com/pedro/library/srt/SrtStream.kt b/library/src/main/java/com/pedro/library/srt/SrtStream.kt index 0e5b2e455..e137f7d0e 100644 --- a/library/src/main/java/com/pedro/library/srt/SrtStream.kt +++ b/library/src/main/java/com/pedro/library/srt/SrtStream.kt @@ -91,6 +91,8 @@ class SrtStream(context: Context, connectCheckerRtmp: ConnectCheckerSrt, videoSo override fun hasCongestion(): Boolean = srtClient.hasCongestion() + override fun hasCongestion(percentUsed: Float): Boolean = srtClient.hasCongestion(percentUsed) + override fun setLogs(enabled: Boolean) { srtClient.setLogs(enabled) } diff --git a/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt b/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt index 6634341fa..e45af75a9 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt @@ -540,8 +540,10 @@ class RtmpClient(private val connectCheckerRtmp: ConnectCheckerRtmp) { } } - fun hasCongestion(): Boolean { - return rtmpSender.hasCongestion() + @JvmOverloads + @Throws(IllegalArgumentException::class) + fun hasCongestion(percentUsed: Float = 20f): Boolean { + return rtmpSender.hasCongestion(percentUsed) } fun resetSentAudioFrames() { diff --git a/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt b/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt index 3696f8984..f668c4f64 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt @@ -185,11 +185,13 @@ class RtmpSender( queue.clear() } - fun hasCongestion(): Boolean { + @Throws(IllegalArgumentException::class) + fun hasCongestion(percentUsed: Float = 20f): Boolean { + if (percentUsed < 0 || percentUsed > 100) throw IllegalArgumentException("the value must be in range 0 to 100") val size = queue.size.toFloat() val remaining = queue.remainingCapacity().toFloat() val capacity = size + remaining - return size >= capacity * 0.2f //more than 20% queue used. You could have congestion + return size >= capacity * (percentUsed / 100f) } fun resizeCache(newSize: Int) { diff --git a/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.kt b/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.kt index 489878d5f..094eaac4c 100644 --- a/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.kt +++ b/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.kt @@ -423,8 +423,10 @@ class RtspClient(private val connectCheckerRtsp: ConnectCheckerRtsp) { } } - fun hasCongestion(): Boolean { - return rtspSender.hasCongestion() + @JvmOverloads + @Throws(IllegalArgumentException::class) + fun hasCongestion(percentUsed: Float = 20f): Boolean { + return rtspSender.hasCongestion(percentUsed) } @JvmOverloads diff --git a/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspSender.kt b/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspSender.kt index 96ce6891f..eb66795da 100644 --- a/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspSender.kt +++ b/rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspSender.kt @@ -187,11 +187,13 @@ class RtspSender(private val connectCheckerRtsp: ConnectCheckerRtsp) { queue.clear() } - fun hasCongestion(): Boolean { + @Throws(IllegalArgumentException::class) + fun hasCongestion(percentUsed: Float = 20f): Boolean { + if (percentUsed < 0 || percentUsed > 100) throw IllegalArgumentException("the value must be in range 0 to 100") val size = queue.size.toFloat() val remaining = queue.remainingCapacity().toFloat() val capacity = size + remaining - return size >= capacity * 0.2f //more than 20% queue used. You could have congestion + return size >= capacity * (percentUsed / 100f) } fun resizeCache(newSize: Int) { diff --git a/srt/src/main/java/com/pedro/srt/srt/SrtClient.kt b/srt/src/main/java/com/pedro/srt/srt/SrtClient.kt index 6c5e94fa2..8bcf88892 100644 --- a/srt/src/main/java/com/pedro/srt/srt/SrtClient.kt +++ b/srt/src/main/java/com/pedro/srt/srt/SrtClient.kt @@ -358,8 +358,10 @@ class SrtClient(private val connectCheckerSrt: ConnectCheckerSrt) { } } - fun hasCongestion(): Boolean { - return srtSender.hasCongestion() + @JvmOverloads + @Throws(IllegalArgumentException::class) + fun hasCongestion(percentUsed: Float = 20f): Boolean { + return srtSender.hasCongestion(percentUsed) } fun resetSentAudioFrames() { diff --git a/srt/src/main/java/com/pedro/srt/srt/SrtSender.kt b/srt/src/main/java/com/pedro/srt/srt/SrtSender.kt index 9b5b165d5..33a38e6f4 100644 --- a/srt/src/main/java/com/pedro/srt/srt/SrtSender.kt +++ b/srt/src/main/java/com/pedro/srt/srt/SrtSender.kt @@ -219,11 +219,13 @@ class SrtSender( queue.clear() } - fun hasCongestion(): Boolean { + @Throws(IllegalArgumentException::class) + fun hasCongestion(percentUsed: Float = 20f): Boolean { + if (percentUsed < 0 || percentUsed > 100) throw IllegalArgumentException("the value must be in range 0 to 100") val size = queue.size.toFloat() val remaining = queue.remainingCapacity().toFloat() val capacity = size + remaining - return size >= capacity * 0.2f //more than 20% queue used. You could have congestion + return size >= capacity * (percentUsed / 100f) } fun resizeCache(newSize: Int) {