implement native deleteSession method, fixes #1066

development
Taner Sener 7 months ago
parent 8fdb3671f3
commit 9e6b83c737
  1. 18
      android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegKitConfig.java
  2. 8
      apple/src/FFmpegKitConfig.h
  3. 12
      apple/src/FFmpegKitConfig.m
  4. 12
      linux/src/FFmpegKitConfig.cpp
  5. 8
      linux/src/FFmpegKitConfig.h

@ -117,7 +117,7 @@ public class FFmpegKitConfig {
/* Session history variables */ /* Session history variables */
private static int sessionHistorySize; private static int sessionHistorySize;
private static final Map<Long, Session> sessionHistoryMap; 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 final Object sessionHistoryLock;
private static int asyncConcurrencyLimit; private static int asyncConcurrencyLimit;
@ -165,7 +165,7 @@ public class FFmpegKitConfig {
return (this.size() > sessionHistorySize); return (this.size() > sessionHistorySize);
} }
}; };
sessionHistoryList = new LinkedList<>(); sessionHistoryList = new ArrayList<>();
sessionHistoryLock = new Object(); sessionHistoryLock = new Object();
globalLogCallback = null; 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. * Returns the last session created from the session history.
* *

@ -407,6 +407,14 @@ typedef NS_ENUM(NSUInteger, Signal) {
*/ */
+ (id<Session>)getSession:(long)sessionId; + (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. * Returns the last session created from the session history.
* *

@ -1353,6 +1353,18 @@ int executeFFprobe(long sessionId, NSArray *arguments) {
return session; 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 { + (id<Session>)getLastSession {
[sessionHistoryLock lock]; [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> std::shared_ptr<ffmpegkit::Session>
ffmpegkit::FFmpegKitConfig::getLastSession() { ffmpegkit::FFmpegKitConfig::getLastSession() {
std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock); 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); 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. * Returns the last session created from the session history.
* *

Loading…
Cancel
Save