mirror of
https://github.com/arthenica/ffmpeg-kit.git
synced 2026-05-07 20:22:27 +00:00
fix setSessionHistorySize method on native platforms
This commit is contained in:
+18
-7
@@ -1086,6 +1086,22 @@ public class FFmpegKitConfig {
|
||||
throw new IllegalArgumentException("Session history size must not exceed the hard limit!");
|
||||
} else if (sessionHistorySize > 0) {
|
||||
FFmpegKitConfig.sessionHistorySize = sessionHistorySize;
|
||||
deleteExpiredSessions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes expired sessions.
|
||||
*/
|
||||
private static void deleteExpiredSessions() {
|
||||
while (sessionHistoryList.size() > sessionHistorySize) {
|
||||
try {
|
||||
Session expiredSession = sessionHistoryList.remove(0);
|
||||
if (expiredSession != null) {
|
||||
sessionHistoryMap.remove(expiredSession.getSessionId());
|
||||
}
|
||||
} catch (final IndexOutOfBoundsException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1099,18 +1115,13 @@ public class FFmpegKitConfig {
|
||||
|
||||
/*
|
||||
* ASYNC SESSIONS CALL THIS METHOD TWICE
|
||||
* THIS CHECK PREVENTS ADDING THE SAME SESSION TWICE
|
||||
* THIS CHECK PREVENTS ADDING THE SAME SESSION AGAIN
|
||||
*/
|
||||
final boolean sessionAlreadyAdded = sessionHistoryMap.containsKey(session.getSessionId());
|
||||
if (!sessionAlreadyAdded) {
|
||||
sessionHistoryMap.put(session.getSessionId(), session);
|
||||
sessionHistoryList.add(session);
|
||||
if (sessionHistoryList.size() > sessionHistorySize) {
|
||||
try {
|
||||
sessionHistoryList.remove(0);
|
||||
} catch (final IndexOutOfBoundsException ignored) {
|
||||
}
|
||||
}
|
||||
deleteExpiredSessions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -19,6 +19,8 @@
|
||||
|
||||
package com.arthenica.ffmpegkit;
|
||||
|
||||
import static com.arthenica.ffmpegkit.FFmpegSessionTest.TEST_ARGUMENTS;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -167,6 +169,24 @@ public class FFmpegKitConfigTest {
|
||||
Assert.assertEquals("mp4", extension);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSessionHistorySize() {
|
||||
int newSize = 15;
|
||||
FFmpegKitConfig.setSessionHistorySize(newSize);
|
||||
|
||||
for (int i = 1; i <= (newSize + 5); i++) {
|
||||
new FFmpegSession(TEST_ARGUMENTS);
|
||||
Assert.assertTrue(FFmpegKitConfig.getSessions().size() <= newSize);
|
||||
}
|
||||
|
||||
newSize = 3;
|
||||
FFmpegKitConfig.setSessionHistorySize(newSize);
|
||||
for (int i = 1; i <= (newSize + 5); i++) {
|
||||
new FFmpegSession(TEST_ARGUMENTS);
|
||||
Assert.assertTrue(FFmpegKitConfig.getSessions().size() <= newSize);
|
||||
}
|
||||
}
|
||||
|
||||
private String listToPackageName(final List<String> externalLibraryList) {
|
||||
boolean speex = externalLibraryList.contains("speex");
|
||||
boolean fribidi = externalLibraryList.contains("fribidi");
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import java.util.List;
|
||||
|
||||
public class FFmpegSessionTest {
|
||||
|
||||
private static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"};
|
||||
static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"};
|
||||
|
||||
@Test
|
||||
public void constructorTest() {
|
||||
|
||||
Reference in New Issue
Block a user