add sessions to history on creation
This commit is contained in:
parent
78c4da02e8
commit
d4f51ca5c0
|
@ -139,6 +139,8 @@ public abstract class AbstractSession implements Session {
|
|||
this.returnCode = null;
|
||||
this.failStackTrace = null;
|
||||
this.logRedirectionStrategy = logRedirectionStrategy;
|
||||
|
||||
FFmpegKitConfig.addSession(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -604,7 +604,6 @@ public class FFmpegKitConfig {
|
|||
* @param ffmpegSession FFmpeg session which includes command options/arguments
|
||||
*/
|
||||
public static void ffmpegExecute(final FFmpegSession ffmpegSession) {
|
||||
addSession(ffmpegSession);
|
||||
ffmpegSession.startRunning();
|
||||
|
||||
try {
|
||||
|
@ -622,7 +621,6 @@ public class FFmpegKitConfig {
|
|||
* @param ffprobeSession FFprobe session which includes command options/arguments
|
||||
*/
|
||||
public static void ffprobeExecute(final FFprobeSession ffprobeSession) {
|
||||
addSession(ffprobeSession);
|
||||
ffprobeSession.startRunning();
|
||||
|
||||
try {
|
||||
|
@ -641,7 +639,6 @@ public class FFmpegKitConfig {
|
|||
* @param waitTimeout max time to wait until media information is transmitted
|
||||
*/
|
||||
public static void getMediaInformationExecute(final MediaInformationSession mediaInformationSession, final int waitTimeout) {
|
||||
addSession(mediaInformationSession);
|
||||
mediaInformationSession.startRunning();
|
||||
|
||||
try {
|
||||
|
@ -664,8 +661,6 @@ public class FFmpegKitConfig {
|
|||
* @param ffmpegSession FFmpeg session which includes command options/arguments
|
||||
*/
|
||||
public static void asyncFFmpegExecute(final FFmpegSession ffmpegSession) {
|
||||
addSession(ffmpegSession);
|
||||
|
||||
AsyncFFmpegExecuteTask asyncFFmpegExecuteTask = new AsyncFFmpegExecuteTask(ffmpegSession);
|
||||
Future<?> future = asyncExecutorService.submit(asyncFFmpegExecuteTask);
|
||||
ffmpegSession.setFuture(future);
|
||||
|
@ -678,8 +673,6 @@ public class FFmpegKitConfig {
|
|||
* @param executorService executor service that will be used to run this asynchronous operation
|
||||
*/
|
||||
public static void asyncFFmpegExecute(final FFmpegSession ffmpegSession, final ExecutorService executorService) {
|
||||
addSession(ffmpegSession);
|
||||
|
||||
AsyncFFmpegExecuteTask asyncFFmpegExecuteTask = new AsyncFFmpegExecuteTask(ffmpegSession);
|
||||
Future<?> future = executorService.submit(asyncFFmpegExecuteTask);
|
||||
ffmpegSession.setFuture(future);
|
||||
|
@ -691,8 +684,6 @@ public class FFmpegKitConfig {
|
|||
* @param ffprobeSession FFprobe session which includes command options/arguments
|
||||
*/
|
||||
public static void asyncFFprobeExecute(final FFprobeSession ffprobeSession) {
|
||||
addSession(ffprobeSession);
|
||||
|
||||
AsyncFFprobeExecuteTask asyncFFmpegExecuteTask = new AsyncFFprobeExecuteTask(ffprobeSession);
|
||||
Future<?> future = asyncExecutorService.submit(asyncFFmpegExecuteTask);
|
||||
ffprobeSession.setFuture(future);
|
||||
|
@ -705,8 +696,6 @@ public class FFmpegKitConfig {
|
|||
* @param executorService executor service that will be used to run this asynchronous operation
|
||||
*/
|
||||
public static void asyncFFprobeExecute(final FFprobeSession ffprobeSession, final ExecutorService executorService) {
|
||||
addSession(ffprobeSession);
|
||||
|
||||
AsyncFFprobeExecuteTask asyncFFmpegExecuteTask = new AsyncFFprobeExecuteTask(ffprobeSession);
|
||||
Future<?> future = executorService.submit(asyncFFmpegExecuteTask);
|
||||
ffprobeSession.setFuture(future);
|
||||
|
@ -719,8 +708,6 @@ public class FFmpegKitConfig {
|
|||
* @param waitTimeout max time to wait until media information is transmitted
|
||||
*/
|
||||
public static void asyncGetMediaInformationExecute(final MediaInformationSession mediaInformationSession, final int waitTimeout) {
|
||||
addSession(mediaInformationSession);
|
||||
|
||||
AsyncGetMediaInformationTask asyncGetMediaInformationTask = new AsyncGetMediaInformationTask(mediaInformationSession, waitTimeout);
|
||||
Future<?> future = asyncExecutorService.submit(asyncGetMediaInformationTask);
|
||||
mediaInformationSession.setFuture(future);
|
||||
|
@ -734,8 +721,6 @@ public class FFmpegKitConfig {
|
|||
* @param waitTimeout max time to wait until media information is transmitted
|
||||
*/
|
||||
public static void asyncGetMediaInformationExecute(final MediaInformationSession mediaInformationSession, final ExecutorService executorService, final int waitTimeout) {
|
||||
addSession(mediaInformationSession);
|
||||
|
||||
AsyncGetMediaInformationTask asyncGetMediaInformationTask = new AsyncGetMediaInformationTask(mediaInformationSession, waitTimeout);
|
||||
Future<?> future = executorService.submit(asyncGetMediaInformationTask);
|
||||
mediaInformationSession.setFuture(future);
|
||||
|
|
|
@ -29,6 +29,8 @@ int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit = 5000;
|
|||
|
||||
static AtomicLong *sessionIdGenerator = nil;
|
||||
|
||||
extern void addSessionToSessionHistory(id<Session> session);
|
||||
|
||||
@implementation AbstractSession {
|
||||
long _sessionId;
|
||||
ExecuteCallback _executeCallback;
|
||||
|
@ -65,6 +67,8 @@ static AtomicLong *sessionIdGenerator = nil;
|
|||
_returnCode = nil;
|
||||
_failStackTrace = nil;
|
||||
_logRedirectionStrategy = logRedirectionStrategy;
|
||||
|
||||
addSessionToSessionHistory(self);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
|
@ -101,6 +101,31 @@ typedef NS_ENUM(NSUInteger, CallbackType) {
|
|||
StatisticsType
|
||||
};
|
||||
|
||||
void addSessionToSessionHistory(id<Session> session) {
|
||||
NSNumber* sessionIdNumber = [NSNumber numberWithLong:[session getSessionId]];
|
||||
|
||||
[sessionHistoryLock lock];
|
||||
|
||||
/*
|
||||
* ASYNC SESSIONS CALL THIS METHOD TWICE
|
||||
* THIS CHECK PREVENTS ADDING THE SAME SESSION TWICE
|
||||
*/
|
||||
if ([sessionHistoryMap objectForKey:sessionIdNumber] == nil) {
|
||||
[sessionHistoryMap setObject:session forKey:sessionIdNumber];
|
||||
[sessionHistoryList addObject:session];
|
||||
if ([sessionHistoryList count] > sessionHistorySize) {
|
||||
id<Session> first = [sessionHistoryList firstObject];
|
||||
if (first != nil) {
|
||||
NSNumber* key = [NSNumber numberWithLong:[first getSessionId]];
|
||||
[sessionHistoryList removeObject:key];
|
||||
[sessionHistoryMap removeObjectForKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[sessionHistoryLock unlock];
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback data class.
|
||||
*/
|
||||
|
@ -278,11 +303,11 @@ CallbackData *callbackDataRemove() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds a session id to the session map.
|
||||
* Registers a session id to the session map.
|
||||
*
|
||||
* @param sessionId session id
|
||||
*/
|
||||
void addSession(long sessionId) {
|
||||
void registerSessionId(long sessionId) {
|
||||
atomic_store(&sessionMap[sessionId % SESSION_MAP_SIZE], 1);
|
||||
}
|
||||
|
||||
|
@ -557,8 +582,8 @@ int executeFFmpeg(long sessionId, NSArray* arguments) {
|
|||
|
||||
// REGISTER THE ID BEFORE STARTING THE SESSION
|
||||
_sessionId = sessionId;
|
||||
addSession(sessionId);
|
||||
|
||||
registerSessionId(sessionId);
|
||||
|
||||
resetMessagesInTransmit(sessionId);
|
||||
|
||||
// RUN
|
||||
|
@ -597,7 +622,7 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
|
||||
// REGISTER THE ID BEFORE STARTING THE SESSION
|
||||
_sessionId = sessionId;
|
||||
addSession(sessionId);
|
||||
registerSessionId(sessionId);
|
||||
|
||||
resetMessagesInTransmit(sessionId);
|
||||
|
||||
|
@ -846,7 +871,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
|
||||
+ (void)ffmpegExecute:(FFmpegSession*)ffmpegSession {
|
||||
[FFmpegKitConfig addSession:ffmpegSession];
|
||||
[ffmpegSession startRunning];
|
||||
|
||||
@try {
|
||||
|
@ -859,7 +883,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
|
||||
+ (void)ffprobeExecute:(FFprobeSession*)ffprobeSession {
|
||||
[FFmpegKitConfig addSession:ffprobeSession];
|
||||
[ffprobeSession startRunning];
|
||||
|
||||
@try {
|
||||
|
@ -872,7 +895,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
|
||||
+ (void)getMediaInformationExecute:(MediaInformationSession*)mediaInformationSession withTimeout:(int)waitTimeout {
|
||||
[FFmpegKitConfig addSession:mediaInformationSession];
|
||||
[mediaInformationSession startRunning];
|
||||
|
||||
@try {
|
||||
|
@ -894,8 +916,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
|
||||
+ (void)asyncFFmpegExecute:(FFmpegSession*)ffmpegSession onDispatchQueue:(dispatch_queue_t)queue {
|
||||
[FFmpegKitConfig addSession:ffmpegSession];
|
||||
|
||||
dispatch_async(queue, ^{
|
||||
[FFmpegKitConfig ffmpegExecute:ffmpegSession];
|
||||
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
|
||||
|
@ -915,8 +935,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
|
||||
+ (void)asyncFFprobeExecute:(FFprobeSession*)ffprobeSession onDispatchQueue:(dispatch_queue_t)queue {
|
||||
[FFmpegKitConfig addSession:ffprobeSession];
|
||||
|
||||
dispatch_async(queue, ^{
|
||||
[FFmpegKitConfig ffprobeExecute:ffprobeSession];
|
||||
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
|
||||
|
@ -936,8 +954,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
|
||||
+ (void)asyncGetMediaInformationExecute:(MediaInformationSession*)mediaInformationSession onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
|
||||
[FFmpegKitConfig addSession:mediaInformationSession];
|
||||
|
||||
dispatch_async(queue, ^{
|
||||
[FFmpegKitConfig getMediaInformationExecute:mediaInformationSession withTimeout:waitTimeout];
|
||||
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
|
||||
|
@ -1008,31 +1024,6 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
|
|||
}
|
||||
}
|
||||
|
||||
+ (void)addSession:(id<Session>)session {
|
||||
NSNumber* sessionIdNumber = [NSNumber numberWithLong:[session getSessionId]];
|
||||
|
||||
[sessionHistoryLock lock];
|
||||
|
||||
/*
|
||||
* ASYNC SESSIONS CALL THIS METHOD TWICE
|
||||
* THIS CHECK PREVENTS ADDING THE SAME SESSION TWICE
|
||||
*/
|
||||
if ([sessionHistoryMap objectForKey:sessionIdNumber] == nil) {
|
||||
[sessionHistoryMap setObject:session forKey:sessionIdNumber];
|
||||
[sessionHistoryList addObject:session];
|
||||
if ([sessionHistoryList count] > sessionHistorySize) {
|
||||
id<Session> first = [sessionHistoryList firstObject];
|
||||
if (first != nil) {
|
||||
NSNumber* key = [NSNumber numberWithLong:[first getSessionId]];
|
||||
[sessionHistoryList removeObject:key];
|
||||
[sessionHistoryMap removeObjectForKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[sessionHistoryLock unlock];
|
||||
}
|
||||
|
||||
+ (id<Session>)getSession:(long)sessionId {
|
||||
[sessionHistoryLock lock];
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user