mirror of
https://github.com/arthenica/ffmpeg-kit.git
synced 2026-05-07 20:22:27 +00:00
implement native deleteSession method, fixes #1066
This commit is contained in:
+16
-2
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user