Skip to content

Commit

Permalink
add clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Oct 12, 2023
1 parent cba3e76 commit da08b06
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) {
}
}

public void clearCache(RtpType rtpType, int index) {
if (rtpType == RtpType.RTMP) {
rtmpClients[index].clearCache();
} else {
rtspClients[index].clearCache();
}
}

@Override
public boolean hasCongestion() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) {
}
}

public void clearCache(RtpType rtpType, int index) {
if (rtpType == RtpType.RTMP) {
rtmpClients[index].clearCache();
} else {
rtspClients[index].clearCache();
}
}

@Override
public boolean hasCongestion() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) {
}
}

public void clearCache(RtpType rtpType, int index) {
if (rtpType == RtpType.RTMP) {
rtmpClients[index].clearCache();
} else {
rtspClients[index].clearCache();
}
}

@Override
public boolean hasCongestion() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ public boolean hasCongestion(RtpType rtpType, int index, int percentUsed) {
}
}

public void clearCache(RtpType rtpType, int index) {
if (rtpType == RtpType.RTMP) {
rtmpClients[index].clearCache();
} else {
rtspClients[index].clearCache();
}
}

@Override
public boolean hasCongestion() {
return false;
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtmp/RtmpCamera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public boolean hasCongestion(float percentUsed) {
return rtmpClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtmpClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtmpClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtmp/RtmpCamera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ public boolean hasCongestion(float percentUsed) {
return rtmpClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtmpClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtmpClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtmp/RtmpDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public boolean hasCongestion() {
return rtmpClient.hasCongestion();
}

public void clearCache() {
rtmpClient.clearCache();
}

@Override
public boolean hasCongestion(float percentUsed) {
return rtmpClient.hasCongestion(percentUsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public boolean hasCongestion(float percentUsed) {
return rtmpClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtmpClient.clearCache();
}

@Override
protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) {
rtmpClient.setVideoInfo(sps, pps, vps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ public boolean hasCongestion(float percentUsed) {
return rtmpClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtmpClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtmpClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtmp/RtmpStream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class RtmpStream(context: Context, connectCheckerRtmp: ConnectCheckerRtmp, video

override fun hasCongestion(percentUsed: Float): Boolean = rtmpClient.hasCongestion(percentUsed)

fun clearCache() {
rtmpClient.clearCache()
}

override fun setLogs(enabled: Boolean) {
rtmpClient.setLogs(enabled)
}
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtsp/RtspCamera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public boolean hasCongestion(float percentUsed) {
return rtspClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtspClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtspClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtsp/RtspCamera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public boolean hasCongestion(float percentUsed) {
return rtspClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtspClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtspClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtsp/RtspDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public boolean hasCongestion(float percentUsed) {
return rtspClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtspClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtspClient.sendAudio(aacBuffer, info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public boolean hasCongestion(float percentUsed) {
return rtspClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtspClient.clearCache();
}

@Override
protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) {
rtspClient.setVideoInfo(sps, pps, vps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public boolean hasCongestion(float percentUsed) {
return rtspClient.hasCongestion(percentUsed);
}

public void clearCache() {
rtspClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtspClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/rtsp/RtspStream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class RtspStream(context: Context, connectCheckerRtsp: ConnectCheckerRtsp, video

override fun hasCongestion(percentUsed: Float): Boolean = rtspClient.hasCongestion(percentUsed)

fun clearCache() {
rtspClient.clearCache()
}

override fun setLogs(enabled: Boolean) {
rtspClient.setLogs(enabled)
}
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/srt/SrtCamera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public boolean hasCongestion(float percentUsed) {
return srtClient.hasCongestion(percentUsed);
}

public void clearCache() {
srtClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
srtClient.sendAudio(aacBuffer, info);
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/srt/SrtCamera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public boolean hasCongestion(float percentUsed) {
return srtClient.hasCongestion(percentUsed);
}

public void clearCache() {
srtClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
srtClient.sendAudio(aacBuffer, info);
Expand Down
58 changes: 31 additions & 27 deletions library/src/main/java/com/pedro/library/srt/SrtDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,137 +40,141 @@
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class SrtDisplay extends DisplayBase {

private final SrtClient rtmpClient;
private final SrtClient srtClient;

public SrtDisplay(Context context, boolean useOpengl, ConnectCheckerSrt connectChecker) {
super(context, useOpengl);
rtmpClient = new SrtClient(connectChecker);
srtClient = new SrtClient(connectChecker);
}

public void setVideoCodec(VideoCodec videoCodec) {
recordController.setVideoMime(
videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
videoEncoder.setType(videoCodec == VideoCodec.H265 ? CodecUtil.H265_MIME : CodecUtil.H264_MIME);
rtmpClient.setVideoCodec(videoCodec);
srtClient.setVideoCodec(videoCodec);
}

@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 rtmpClient.hasCongestion(percentUsed);
return srtClient.hasCongestion(percentUsed);
}

public void clearCache() {
srtClient.clearCache();
}

@Override
protected void getAacDataRtp(ByteBuffer aacBuffer, MediaCodec.BufferInfo info) {
rtmpClient.sendAudio(aacBuffer, info);
srtClient.sendAudio(aacBuffer, info);
}

@Override
protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) {
rtmpClient.setVideoInfo(sps, pps, vps);
srtClient.setVideoInfo(sps, pps, vps);
}

@Override
protected void getH264DataRtp(ByteBuffer h264Buffer, MediaCodec.BufferInfo info) {
rtmpClient.sendVideo(h264Buffer, info);
srtClient.sendVideo(h264Buffer, 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);
}
}
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/srt/SrtFromFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public boolean hasCongestion(float percentUsed) {
return srtClient.hasCongestion(percentUsed);
}

public void clearCache() {
srtClient.clearCache();
}

@Override
protected void onSpsPpsVpsRtp(ByteBuffer sps, ByteBuffer pps, ByteBuffer vps) {
srtClient.setVideoInfo(sps, pps, vps);
Expand Down
Loading

0 comments on commit da08b06

Please sign in to comment.