Skip to content

Commit

Permalink
implement native deleteSession method, fixes #1066
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed Nov 18, 2024
1 parent 8fdb367 commit 9cf2e80
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ParcelFileDescriptor getParcelFileDescriptor() {
/* 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;
Expand Down Expand Up @@ -165,7 +165,7 @@ protected boolean removeEldestEntry(Map.Entry<Long, Session> eldest) {
return (this.size() > sessionHistorySize);
}
};
sessionHistoryList = new LinkedList<>();
sessionHistoryList = new ArrayList<>();
sessionHistoryLock = new Object();

globalLogCallback = null;
Expand Down Expand Up @@ -1180,6 +1180,20 @@ public static Session getSession(final long sessionId) {
}
}

/**
* 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.
*
Expand Down
8 changes: 8 additions & 0 deletions apple/src/FFmpegKitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions apple/src/FFmpegKitConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,18 @@ + (void)setSessionHistorySize:(int)pSessionHistorySize {
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];

Expand Down
8 changes: 8 additions & 0 deletions linux/src/FFmpegKitConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,14 @@ 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);
sessionHistoryList.erase(std::remove_if(sessionHistoryList.begin(), sessionHistoryList.end(), [](std::shared_ptr<ffmpegkit::Session> session) { return session->getSessionId() == sessionId; }), sessionHistoryList.end());
}

std::shared_ptr<ffmpegkit::Session>
ffmpegkit::FFmpegKitConfig::getLastSession() {
std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
Expand Down
8 changes: 8 additions & 0 deletions linux/src/FFmpegKitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9cf2e80

Please sign in to comment.