implement native deleteSession method, fixes #1066

This commit is contained in:
Taner Sener
2024-11-18 01:31:25 +00:00
parent 8fdb3671f3
commit 9e6b83c737
5 changed files with 56 additions and 2 deletions
@@ -117,7 +117,7 @@ public class FFmpegKitConfig {
/* Session history variables */
private static int sessionHistorySize;
private static final Map<Long, Session> sessionHistoryMap;
private static final List<Session> sessionHistoryList;
private static final ArrayList<Session> sessionHistoryList;
private static final Object sessionHistoryLock;
private static int asyncConcurrencyLimit;
@@ -165,7 +165,7 @@ public class FFmpegKitConfig {
return (this.size() > sessionHistorySize);
}
};
sessionHistoryList = new LinkedList<>();
sessionHistoryList = new ArrayList<>();
sessionHistoryLock = new Object();
globalLogCallback = null;
@@ -1180,6 +1180,20 @@ public class FFmpegKitConfig {
}
}
/**
* Deletes the session specified with <code>sessionId</code> from the session history.
*
* @param sessionId session identifier
*/
public static void deleteSession(final long sessionId) {
synchronized (sessionHistoryLock) {
Session removedSession = sessionHistoryMap.remove(sessionId);
if (removedSession != null) {
sessionHistoryList.remove(removedSession);
}
}
}
/**
* Returns the last session created from the session history.
*
+8
View File
@@ -407,6 +407,14 @@ typedef NS_ENUM(NSUInteger, Signal) {
*/
+ (id<Session>)getSession:(long)sessionId;
/**
* Deletes the session specified with <code>sessionId</code> from the session
* history.
*
* @param sessionId session identifier
*/
+ (void)deleteSession:(long)sessionId;
/**
* Returns the last session created from the session history.
*
+12
View File
@@ -1353,6 +1353,18 @@ int executeFFprobe(long sessionId, NSArray *arguments) {
return session;
}
+ (void)deleteSession:(long)sessionId {
[sessionHistoryLock lock];
id<Session> session = [sessionHistoryMap objectForKey:[NSNumber numberWithLong:sessionId]];
if (session != nil) {
[sessionHistoryMap removeObjectForKey:[NSNumber numberWithLong:sessionId]];
[sessionHistoryList removeObject:session];
}
[sessionHistoryLock unlock];
}
+ (id<Session>)getLastSession {
[sessionHistoryLock lock];
+12
View File
@@ -1371,6 +1371,18 @@ ffmpegkit::FFmpegKitConfig::getSession(const long sessionId) {
}
}
void ffmpegkit::FFmpegKitConfig::deleteSession(const long sessionId) {
std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
lock.lock();
sessionHistoryMap.erase(sessionId);
auto it = std::remove_if(sessionHistoryList.begin(), sessionHistoryList.end(),
[sessionId](std::shared_ptr<ffmpegkit::Session> session) {
return session->getSessionId() == sessionId;
});
sessionHistoryList.erase(it, sessionHistoryList.end());
}
std::shared_ptr<ffmpegkit::Session>
ffmpegkit::FFmpegKitConfig::getLastSession() {
std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
+8
View File
@@ -371,6 +371,14 @@ class FFmpegKitConfig {
*/
static std::shared_ptr<ffmpegkit::Session> getSession(const long sessionId);
/**
* Deletes the session specified with <code>sessionId</code> from the session
* history.
*
* @param sessionId session identifier
*/
static void deleteSession(const long sessionId);
/**
* Returns the last session created from the session history.
*