replace execute callback with session specific complete callbacks, fixes #197

This commit is contained in:
Taner Sener 2021-12-23 23:10:13 +00:00
parent 6d1493d08d
commit 38d88e0c12
38 changed files with 1277 additions and 774 deletions

View File

@ -28,8 +28,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
/**
* Abstract session implementation which includes common features shared by <code>FFmpeg</code>
* and <code>FFprobe</code> sessions.
* Abstract session implementation which includes common features shared by <code>FFmpeg</code>,
* <code>FFprobe</code> and <code>MediaInformation</code> sessions.
*/
public abstract class AbstractSession implements Session {
@ -49,12 +49,7 @@ public abstract class AbstractSession implements Session {
protected final long sessionId;
/**
* Session specific execute callback function.
*/
protected final ExecuteCallback executeCallback;
/**
* Session specific log callback function.
* Session specific log callback.
*/
protected final LogCallback logCallback;
@ -117,16 +112,13 @@ public abstract class AbstractSession implements Session {
* Creates a new abstract session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param logCallback session specific log callback function
* @param logCallback session specific log callback
* @param logRedirectionStrategy session specific log redirection strategy
*/
public AbstractSession(final String[] arguments,
final ExecuteCallback executeCallback,
final LogCallback logCallback,
final LogRedirectionStrategy logRedirectionStrategy) {
this.sessionId = sessionIdGenerator.getAndIncrement();
this.executeCallback = executeCallback;
this.logCallback = logCallback;
this.createTime = new Date();
this.startTime = null;
@ -143,11 +135,6 @@ public abstract class AbstractSession implements Session {
FFmpegKitConfig.addSession(this);
}
@Override
public ExecuteCallback getExecuteCallback() {
return executeCallback;
}
@Override
public LogCallback getLogCallback() {
return logCallback;

View File

@ -26,33 +26,33 @@ import com.arthenica.smartexception.java.Exceptions;
*/
public class AsyncFFmpegExecuteTask implements Runnable {
private final FFmpegSession ffmpegSession;
private final ExecuteCallback executeCallback;
private final FFmpegSessionCompleteCallback completeCallback;
public AsyncFFmpegExecuteTask(final FFmpegSession ffmpegSession) {
this.ffmpegSession = ffmpegSession;
this.executeCallback = ffmpegSession.getExecuteCallback();
this.completeCallback = ffmpegSession.getCompleteCallback();
}
@Override
public void run() {
FFmpegKitConfig.ffmpegExecute(ffmpegSession);
if (executeCallback != null) {
if (completeCallback != null) {
try {
// NOTIFY SESSION CALLBACK DEFINED
executeCallback.apply(ffmpegSession);
completeCallback.apply(ffmpegSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session complete callback.%s", Exceptions.getStackTraceString(e)));
}
}
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
final FFmpegSessionCompleteCallback globalFFmpegSessionCompleteCallback = FFmpegKitConfig.getFFmpegSessionCompleteCallback();
if (globalFFmpegSessionCompleteCallback != null) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalExecuteCallbackFunction.apply(ffmpegSession);
globalFFmpegSessionCompleteCallback.apply(ffmpegSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global complete callback.%s", Exceptions.getStackTraceString(e)));
}
}
}

View File

@ -26,33 +26,33 @@ import com.arthenica.smartexception.java.Exceptions;
*/
public class AsyncFFprobeExecuteTask implements Runnable {
private final FFprobeSession ffprobeSession;
private final ExecuteCallback executeCallback;
private final FFprobeSessionCompleteCallback completeCallback;
public AsyncFFprobeExecuteTask(final FFprobeSession ffprobeSession) {
this.ffprobeSession = ffprobeSession;
this.executeCallback = ffprobeSession.getExecuteCallback();
this.completeCallback = ffprobeSession.getCompleteCallback();
}
@Override
public void run() {
FFmpegKitConfig.ffprobeExecute(ffprobeSession);
if (executeCallback != null) {
if (completeCallback != null) {
try {
// NOTIFY SESSION CALLBACK DEFINED
executeCallback.apply(ffprobeSession);
completeCallback.apply(ffprobeSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session complete callback.%s", Exceptions.getStackTraceString(e)));
}
}
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
final FFprobeSessionCompleteCallback globalFFprobeSessionCompleteCallback = FFmpegKitConfig.getFFprobeSessionCompleteCallback();
if (globalFFprobeSessionCompleteCallback != null) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalExecuteCallbackFunction.apply(ffprobeSession);
globalFFprobeSessionCompleteCallback.apply(ffprobeSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global complete callback.%s", Exceptions.getStackTraceString(e)));
}
}
}

View File

@ -26,7 +26,7 @@ import com.arthenica.smartexception.java.Exceptions;
*/
public class AsyncGetMediaInformationTask implements Runnable {
private final MediaInformationSession mediaInformationSession;
private final ExecuteCallback executeCallback;
private final MediaInformationSessionCompleteCallback completeCallback;
private final Integer waitTimeout;
public AsyncGetMediaInformationTask(final MediaInformationSession mediaInformationSession) {
@ -35,7 +35,7 @@ public class AsyncGetMediaInformationTask implements Runnable {
public AsyncGetMediaInformationTask(final MediaInformationSession mediaInformationSession, final Integer waitTimeout) {
this.mediaInformationSession = mediaInformationSession;
this.executeCallback = mediaInformationSession.getExecuteCallback();
this.completeCallback = mediaInformationSession.getCompleteCallback();
this.waitTimeout = waitTimeout;
}
@ -43,22 +43,22 @@ public class AsyncGetMediaInformationTask implements Runnable {
public void run() {
FFmpegKitConfig.getMediaInformationExecute(mediaInformationSession, waitTimeout);
if (executeCallback != null) {
if (completeCallback != null) {
try {
// NOTIFY SESSION CALLBACK DEFINED
executeCallback.apply(mediaInformationSession);
completeCallback.apply(mediaInformationSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session complete callback.%s", Exceptions.getStackTraceString(e)));
}
}
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
final MediaInformationSessionCompleteCallback globalMediaInformationSessionCompleteCallback = FFmpegKitConfig.getMediaInformationSessionCompleteCallback();
if (globalMediaInformationSessionCompleteCallback != null) {
try {
// NOTIFY GLOBAL CALLBACK DEFINEDs
globalExecuteCallbackFunction.apply(mediaInformationSession);
globalMediaInformationSessionCompleteCallback.apply(mediaInformationSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global complete callback.%s", Exceptions.getStackTraceString(e)));
}
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2018-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
package com.arthenica.ffmpegkit;
/**
* <p>Callback function invoked when an asynchronous session ends running.
* <p>Session has either {@link SessionState#COMPLETED} or {@link SessionState#FAILED} state when
* the callback is invoked.
* <p>If it has {@link SessionState#COMPLETED} state, <code>ReturnCode</code> should be checked to
* see the execution result.
* <p>If <code>getState</code> returns {@link SessionState#FAILED} then
* <code>getFailStackTrace</code> should be used to get the failure reason.
* <pre>
* switch (session.getState()) {
* case COMPLETED: {
* ReturnCode returnCode = session.getReturnCode();
* } break;
* case FAILED: {
* String failStackTrace = session.getFailStackTrace();
* } break;
* }
* </pre>
*/
@FunctionalInterface
public interface ExecuteCallback {
/**
* <p>Called when an asynchronous session ends running.
*
* @param session session
*/
void apply(final Session session);
}

View File

@ -23,16 +23,16 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* <p>Main class to run <code>FFmpeg</code> commands. Supports executing commands both synchronously and
* asynchronously.
* <p>Main class to run <code>FFmpeg</code> commands. Supports executing commands both
* synchronously and asynchronously.
* <pre>
* FFmpegSession session = FFmpegKit.execute("-i file1.mp4 -c:v libxvid file1.avi");
*
* FFmpegSession asyncSession = FFmpegKit.executeAsync("-i file1.mp4 -c:v libxvid file1.avi", executeCallback);
* FFmpegSession asyncSession = FFmpegKit.executeAsync("-i file1.mp4 -c:v libxvid file1.avi", completeCallback);
* </pre>
* <p>Provides overloaded <code>execute</code> methods to define session specific callbacks.
* <pre>
* FFmpegSession asyncSession = FFmpegKit.executeAsync("-i file1.mp4 -c:v libxvid file1.avi", executeCallback, logCallback, statisticsCallback);
* FFmpegSession asyncSession = FFmpegKit.executeAsync("-i file1.mp4 -c:v libxvid file1.avi", completeCallback, logCallback, statisticsCallback);
* </pre>
*/
public class FFmpegKit {
@ -65,16 +65,17 @@ public class FFmpegKit {
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param arguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback) {
final FFmpegSession session = new FFmpegSession(arguments, executeCallback);
final FFmpegSessionCompleteCallback completeCallback) {
final FFmpegSession session = new FFmpegSession(arguments, completeCallback);
FFmpegKitConfig.asyncFFmpegExecute(session);
@ -84,20 +85,21 @@ public class FFmpegKit {
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback) {
final FFmpegSession session = new FFmpegSession(arguments, executeCallback, logCallback, statisticsCallback);
final FFmpegSession session = new FFmpegSession(arguments, completeCallback, logCallback, statisticsCallback);
FFmpegKitConfig.asyncFFmpegExecute(session);
@ -107,18 +109,19 @@ public class FFmpegKit {
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param executorService executor service that will be used to run this asynchronous operation
* @param arguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final ExecutorService executorService) {
final FFmpegSession session = new FFmpegSession(arguments, executeCallback);
final FFmpegSession session = new FFmpegSession(arguments, completeCallback);
FFmpegKitConfig.asyncFFmpegExecute(session, executorService);
@ -128,22 +131,24 @@ public class FFmpegKit {
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param executorService executor service that will be used to run this asynchronous operation
* @param executorService executor service that will be used to run this asynchronous
* operation
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final ExecutorService executorService) {
final FFmpegSession session = new FFmpegSession(arguments, executeCallback, logCallback, statisticsCallback);
final FFmpegSession session = new FFmpegSession(arguments, completeCallback, logCallback, statisticsCallback);
FFmpegKitConfig.asyncFFmpegExecute(session, executorService);
@ -163,57 +168,63 @@ public class FFmpegKit {
}
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to
* split the command into arguments. You can use single or double quote characters to specify
* arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeAsync(final String command,
final ExecuteCallback executeCallback) {
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback);
final FFmpegSessionCompleteCallback completeCallback) {
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback);
}
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to
* split the command into arguments. You can use single or double quote characters to specify
* arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeAsync(final String command,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback) {
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback);
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
}
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to
* split the command into arguments. You can use single or double quote characters to specify
* arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param executorService executor service that will be used to run this asynchronous operation
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeAsync(final String command,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final ExecutorService executorService) {
final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), executeCallback);
final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), completeCallback);
FFmpegKitConfig.asyncFFmpegExecute(session, executorService);
@ -221,25 +232,27 @@ public class FFmpegKit {
}
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to
* split the command into arguments. You can use single or double quote characters to specify
* arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
public static FFmpegSession executeAsync(final String command,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final ExecutorService executorService) {
final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback);
final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
FFmpegKitConfig.asyncFFmpegExecute(session, executorService);
@ -249,7 +262,7 @@ public class FFmpegKit {
/**
* <p>Cancels all running sessions.
*
* <p>This function does not wait for termination to complete and returns immediately.
* <p>This method does not wait for termination to complete and returns immediately.
*/
public static void cancel() {
@ -264,7 +277,7 @@ public class FFmpegKit {
/**
* <p>Cancels the session specified with <code>sessionId</code>.
*
* <p>This function does not wait for termination to complete and returns immediately.
* <p>This method does not wait for termination to complete and returns immediately.
*
* @param sessionId id of the session that will be cancelled
*/

View File

@ -120,9 +120,11 @@ public class FFmpegKitConfig {
private static ExecutorService asyncExecutorService;
/* Global callbacks */
private static LogCallback globalLogCallbackFunction;
private static StatisticsCallback globalStatisticsCallbackFunction;
private static ExecuteCallback globalExecuteCallbackFunction;
private static LogCallback globalLogCallback;
private static StatisticsCallback globalStatisticsCallback;
private static FFmpegSessionCompleteCallback globalFFmpegSessionCompleteCallback;
private static FFprobeSessionCompleteCallback globalFFprobeSessionCompleteCallback;
private static MediaInformationSessionCompleteCallback globalMediaInformationSessionCompleteCallback;
private static final SparseArray<SAFProtocolUrl> safIdMap;
private static final SparseArray<SAFProtocolUrl> safFileDescriptorMap;
private static LogRedirectionStrategy globalLogRedirectionStrategy;
@ -163,9 +165,11 @@ public class FFmpegKitConfig {
sessionHistoryList = new LinkedList<>();
sessionHistoryLock = new Object();
globalLogCallbackFunction = null;
globalStatisticsCallbackFunction = null;
globalExecuteCallbackFunction = null;
globalLogCallback = null;
globalStatisticsCallback = null;
globalFFmpegSessionCompleteCallback = null;
globalFFprobeSessionCompleteCallback = null;
globalMediaInformationSessionCompleteCallback = null;
safIdMap = new SparseArray<>();
safFileDescriptorMap = new SparseArray<>();
@ -239,12 +243,12 @@ public class FFmpegKitConfig {
// NOTIFY SESSION CALLBACK DEFINED
session.getLogCallback().apply(log);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session LogCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session log callback.%s", Exceptions.getStackTraceString(e)));
}
}
}
final LogCallback globalLogCallbackFunction = FFmpegKitConfig.globalLogCallbackFunction;
final LogCallback globalLogCallbackFunction = FFmpegKitConfig.globalLogCallback;
if (globalLogCallbackFunction != null) {
globalCallbackDefined = true;
@ -252,7 +256,7 @@ public class FFmpegKitConfig {
// NOTIFY GLOBAL CALLBACK DEFINED
globalLogCallbackFunction.apply(log);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global LogCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global log callback.%s", Exceptions.getStackTraceString(e)));
}
}
@ -345,18 +349,18 @@ public class FFmpegKitConfig {
// NOTIFY SESSION CALLBACK IF DEFINED
ffmpegSession.getStatisticsCallback().apply(statistics);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session StatisticsCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session statistics callback.%s", Exceptions.getStackTraceString(e)));
}
}
}
final StatisticsCallback globalStatisticsCallbackFunction = FFmpegKitConfig.globalStatisticsCallbackFunction;
final StatisticsCallback globalStatisticsCallbackFunction = FFmpegKitConfig.globalStatisticsCallback;
if (globalStatisticsCallbackFunction != null) {
try {
// NOTIFY GLOBAL CALLBACK IF DEFINED
globalStatisticsCallbackFunction.apply(statistics);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global StatisticsCallback block.%s", Exceptions.getStackTraceString(e)));
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global statistics callback.%s", Exceptions.getStackTraceString(e)));
}
}
}
@ -704,8 +708,9 @@ public class FFmpegKitConfig {
/**
* <p>Starts an asynchronous FFmpeg execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param ffmpegSession FFmpeg session which includes command options/arguments
*/
@ -718,8 +723,9 @@ public class FFmpegKitConfig {
/**
* <p>Starts an asynchronous FFmpeg execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFmpegSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param ffmpegSession FFmpeg session which includes command options/arguments
* @param executorService executor service that will be used to run this asynchronous operation
@ -733,8 +739,9 @@ public class FFmpegKitConfig {
/**
* <p>Starts an asynchronous FFprobe execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param ffprobeSession FFprobe session which includes command options/arguments
*/
@ -747,8 +754,9 @@ public class FFmpegKitConfig {
/**
* <p>Starts an asynchronous FFprobe execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param ffprobeSession FFprobe session which includes command options/arguments
* @param executorService executor service that will be used to run this asynchronous operation
@ -762,10 +770,12 @@ public class FFmpegKitConfig {
/**
* <p>Starts an asynchronous FFprobe execution for the given media information session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param mediaInformationSession media information session which includes command options/arguments
* @param mediaInformationSession media information session which includes command
* options/arguments
* @param waitTimeout max time to wait until media information is transmitted
*/
public static void asyncGetMediaInformationExecute(final MediaInformationSession mediaInformationSession, final int waitTimeout) {
@ -777,11 +787,14 @@ public class FFmpegKitConfig {
/**
* <p>Starts an asynchronous FFprobe execution for the given media information session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param mediaInformationSession media information session which includes command options/arguments
* @param executorService executor service that will be used to run this asynchronous operation
* @param mediaInformationSession media information session which includes command
* options/arguments
* @param executorService executor service that will be used to run this asynchronous
* operation
* @param waitTimeout max time to wait until media information is transmitted
*/
public static void asyncGetMediaInformationExecute(final MediaInformationSession mediaInformationSession, final ExecutorService executorService, final int waitTimeout) {
@ -822,42 +835,82 @@ public class FFmpegKitConfig {
}
/**
* <p>Sets a global callback function to redirect FFmpeg/FFprobe logs.
* <p>Sets a global callback to redirect FFmpeg/FFprobe logs.
*
* @param logCallback log callback function or null to disable a previously defined
* callback
* @param logCallback log callback or null to disable a previously defined callback
*/
public static void enableLogCallback(final LogCallback logCallback) {
globalLogCallbackFunction = logCallback;
globalLogCallback = logCallback;
}
/**
* <p>Sets a global callback function to redirect FFmpeg statistics.
* <p>Sets a global callback to redirect FFmpeg statistics.
*
* @param statisticsCallback statistics callback function or null to disable a previously
* @param statisticsCallback statistics callback or null to disable a previously
* defined callback
*/
public static void enableStatisticsCallback(final StatisticsCallback statisticsCallback) {
globalStatisticsCallbackFunction = statisticsCallback;
globalStatisticsCallback = statisticsCallback;
}
/**
* <p>Sets a global callback function to receive execution results.
* <p>Sets a global FFmpegSessionCompleteCallback to receive execution results for FFmpeg
* sessions.
*
* @param executeCallback execute callback function or null to disable a previously
* defined callback
* @param ffmpegSessionCompleteCallback complete callback or null to disable a
* previously defined callback
*/
public static void enableExecuteCallback(final ExecuteCallback executeCallback) {
globalExecuteCallbackFunction = executeCallback;
public static void enableFFmpegSessionCompleteCallback(final FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback) {
globalFFmpegSessionCompleteCallback = ffmpegSessionCompleteCallback;
}
/**
* <p>Returns the global execute callback function.
* <p>Returns the global FFmpegSessionCompleteCallback set.
*
* @return global execute callback function
* @return global FFmpegSessionCompleteCallback or null if it is not set
*/
static ExecuteCallback getExecuteCallback() {
return globalExecuteCallbackFunction;
public static FFmpegSessionCompleteCallback getFFmpegSessionCompleteCallback() {
return globalFFmpegSessionCompleteCallback;
}
/**
* <p>Sets a global FFprobeSessionCompleteCallback to receive execution results for FFprobe
* sessions.
*
* @param ffprobeSessionCompleteCallback complete callback or null to disable a
* previously defined callback
*/
public static void enableFFprobeSessionCompleteCallback(final FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback) {
globalFFprobeSessionCompleteCallback = ffprobeSessionCompleteCallback;
}
/**
* <p>Returns the global FFprobeSessionCompleteCallback set.
*
* @return global FFprobeSessionCompleteCallback or null if it is not set
*/
public static FFprobeSessionCompleteCallback getFFprobeSessionCompleteCallback() {
return globalFFprobeSessionCompleteCallback;
}
/**
* <p>Sets a global MediaInformationSessionCompleteCallback to receive execution results for
* MediaInformation sessions.
*
* @param mediaInformationSessionCompleteCallback complete callback or null to disable
* a previously defined callback
*/
public static void enableMediaInformationSessionCompleteCallback(final MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback) {
globalMediaInformationSessionCompleteCallback = mediaInformationSessionCompleteCallback;
}
/**
* <p>Returns the global MediaInformationSessionCompleteCallback set.
*
* @return global MediaInformationSessionCompleteCallback or null if it is not set
*/
public static MediaInformationSessionCompleteCallback getMediaInformationSessionCompleteCallback() {
return globalMediaInformationSessionCompleteCallback;
}
/**
@ -1135,7 +1188,7 @@ public class FFmpegKitConfig {
*
* @return all FFmpeg sessions in the session history
*/
static List<FFmpegSession> getFFmpegSessions() {
public static List<FFmpegSession> getFFmpegSessions() {
final LinkedList<FFmpegSession> list = new LinkedList<>();
synchronized (sessionHistoryLock) {
@ -1154,7 +1207,7 @@ public class FFmpegKitConfig {
*
* @return all FFprobe sessions in the session history
*/
static List<FFprobeSession> getFFprobeSessions() {
public static List<FFprobeSession> getFFprobeSessions() {
final LinkedList<FFprobeSession> list = new LinkedList<>();
synchronized (sessionHistoryLock) {
@ -1168,6 +1221,25 @@ public class FFmpegKitConfig {
return list;
}
/**
* <p>Returns all MediaInformation sessions in the session history.
*
* @return all MediaInformation sessions in the session history
*/
public static List<MediaInformationSession> getMediaInformationSessions() {
final LinkedList<MediaInformationSession> list = new LinkedList<>();
synchronized (sessionHistoryLock) {
for (Session session : sessionHistoryList) {
if (session.isMediaInformation()) {
list.add((MediaInformationSession) session);
}
}
}
return list;
}
/**
* <p>Returns sessions that have the given state.
*
@ -1357,7 +1429,7 @@ public class FFmpegKitConfig {
native static int nativeFFprobeExecute(final long sessionId, final String[] arguments);
/**
* <p>Cancels an ongoing FFmpeg operation natively. This function does not wait for termination
* <p>Cancels an ongoing FFmpeg operation natively. This method does not wait for termination
* to complete and returns immediately.
*
* @param sessionId id of the session

View File

@ -28,10 +28,15 @@ import java.util.List;
public class FFmpegSession extends AbstractSession implements Session {
/**
* Session specific statistics callback function.
* Session specific statistics callback.
*/
private final StatisticsCallback statisticsCallback;
/**
* Session specific complete callback.
*/
private final FFmpegSessionCompleteCallback completeCallback;
/**
* Statistics entries received for this session.
*/
@ -54,44 +59,45 @@ public class FFmpegSession extends AbstractSession implements Session {
/**
* Builds a new FFmpeg session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param arguments command arguments
* @param completeCallback session specific complete callback
*/
public FFmpegSession(final String[] arguments, final ExecuteCallback executeCallback) {
this(arguments, executeCallback, null, null);
public FFmpegSession(final String[] arguments, final FFmpegSessionCompleteCallback completeCallback) {
this(arguments, completeCallback, null, null);
}
/**
* Builds a new FFmpeg session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param logCallback session specific log callback function
* @param statisticsCallback session specific statistics callback function
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
* @param statisticsCallback session specific statistics callback
*/
public FFmpegSession(final String[] arguments,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback) {
this(arguments, executeCallback, logCallback, statisticsCallback, FFmpegKitConfig.getLogRedirectionStrategy());
this(arguments, completeCallback, logCallback, statisticsCallback, FFmpegKitConfig.getLogRedirectionStrategy());
}
/**
* Builds a new FFmpeg session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param logCallback session specific log callback function
* @param statisticsCallback session specific statistics callback function
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
* @param statisticsCallback session specific statistics callback
* @param logRedirectionStrategy session specific log redirection strategy
*/
public FFmpegSession(final String[] arguments,
final ExecuteCallback executeCallback,
final FFmpegSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final StatisticsCallback statisticsCallback,
final LogRedirectionStrategy logRedirectionStrategy) {
super(arguments, executeCallback, logCallback, logRedirectionStrategy);
super(arguments, logCallback, logRedirectionStrategy);
this.completeCallback = completeCallback;
this.statisticsCallback = statisticsCallback;
this.statistics = new LinkedList<>();
@ -99,14 +105,23 @@ public class FFmpegSession extends AbstractSession implements Session {
}
/**
* Returns the session specific statistics callback function.
* Returns the session specific statistics callback.
*
* @return session specific statistics callback function
* @return session specific statistics callback
*/
public StatisticsCallback getStatisticsCallback() {
return statisticsCallback;
}
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
public FFmpegSessionCompleteCallback getCompleteCallback() {
return completeCallback;
}
/**
* Returns all statistics entries generated for this session. If there are asynchronous
* messages that are not delivered yet, this method waits for them until the given timeout.
@ -165,10 +180,8 @@ public class FFmpegSession extends AbstractSession implements Session {
}
/**
* Adds a new statistics entry for this session.
*
* It is invoked internally by <code>FFmpegKit</code> library methods. Must not be used by user
* applications.
* Adds a new statistics entry for this session. It is invoked internally by
* <code>FFmpegKit</code> library methods. Must not be used by user applications.
*
* @param statistics statistics entry
*/
@ -188,6 +201,11 @@ public class FFmpegSession extends AbstractSession implements Session {
return false;
}
@Override
public boolean isMediaInformation() {
return false;
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder();

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
package com.arthenica.ffmpegkit;
/**
* <p>Callback function that is invoked when an asynchronous <code>FFmpeg</code> session has ended.
*/
@FunctionalInterface
public interface FFmpegSessionCompleteCallback {
/**
* <p>Called when an FFmpeg session has ended.
*
* @param session FFmpeg session
*/
void apply(final FFmpegSession session);
}

View File

@ -23,16 +23,16 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* <p>Main class to run <code>FFprobe</code> commands. Supports executing commands both synchronously and
* asynchronously.
* <p>Main class to run <code>FFprobe</code> commands. Supports executing commands both
* synchronously and asynchronously.
* <pre>
* FFprobeSession session = FFprobeKit.execute("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4");
*
* FFprobeSession asyncSession = FFprobeKit.executeAsync("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4", executeCallback);
* FFprobeSession asyncSession = FFprobeKit.executeAsync("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4", completeCallback);
* </pre>
* <p>Provides overloaded <code>execute</code> methods to define session specific callbacks.
* <pre>
* FFprobeSession session = FFprobeKit.executeAsync("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4", executeCallback, logCallback);
* FFprobeSession session = FFprobeKit.executeAsync("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4", completeCallback, logCallback);
* </pre>
* <p>It can extract media information for a file or a url, using {@link #getMediaInformation(String)} method.
* <pre>
@ -79,16 +79,17 @@ public class FFprobeKit {
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback) {
final FFprobeSession session = new FFprobeSession(arguments, executeCallback);
final FFprobeSessionCompleteCallback completeCallback) {
final FFprobeSession session = new FFprobeSession(arguments, completeCallback);
FFmpegKitConfig.asyncFFprobeExecute(session);
@ -98,18 +99,19 @@ public class FFprobeKit {
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final LogCallback logCallback) {
final FFprobeSession session = new FFprobeSession(arguments, executeCallback, logCallback);
final FFprobeSession session = new FFprobeSession(arguments, completeCallback, logCallback);
FFmpegKitConfig.asyncFFprobeExecute(session);
@ -119,18 +121,19 @@ public class FFprobeKit {
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param executorService executor service that will be used to run this asynchronous operation
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final ExecutorService executorService) {
final FFprobeSession session = new FFprobeSession(arguments, executeCallback);
final FFprobeSession session = new FFprobeSession(arguments, completeCallback);
FFmpegKitConfig.asyncFFprobeExecute(session, executorService);
@ -140,20 +143,21 @@ public class FFprobeKit {
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param executorService executor service that will be used to run this asynchronous operation
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeWithArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final ExecutorService executorService) {
final FFprobeSession session = new FFprobeSession(arguments, executeCallback, logCallback);
final FFprobeSession session = new FFprobeSession(arguments, completeCallback, logCallback);
FFmpegKitConfig.asyncFFprobeExecute(session, executorService);
@ -173,55 +177,61 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used
* to split the command into arguments. You can use single or double quote characters to
* specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeAsync(final String command,
final ExecuteCallback executeCallback) {
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback);
final FFprobeSessionCompleteCallback completeCallback) {
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback);
}
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used
* to split the command into arguments. You can use single or double quote characters to
* specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFprobe command
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param command FFprobe command
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeAsync(final String command,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final LogCallback logCallback) {
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback);
return executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
}
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used
* to split the command into arguments. You can use single or double quote characters to
* specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param executorService executor service that will be used to run this asynchronous operation
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeAsync(final String command,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final ExecutorService executorService) {
final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), executeCallback);
final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), completeCallback);
FFmpegKitConfig.asyncFFprobeExecute(session, executorService);
@ -229,23 +239,25 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used
* to split the command into arguments. You can use single or double quote characters to
* specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an {@link FFprobeSessionCompleteCallback} if you want to be notified about the
* result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param logCallback callback that will receive logs
* @param executorService executor service that will be used to run this asynchronous operation
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param executorService executor service that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
public static FFprobeSession executeAsync(final String command,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final ExecutorService executorService) {
final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback);
final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
FFmpegKitConfig.asyncFFprobeExecute(session, executorService);
@ -283,18 +295,20 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
* <p>Starts an asynchronous FFprobe execution to extract the media information for the
* specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be called when the execution is completed
* @param path path or uri of a media file
* @param completeCallback callback that will be called when the execution has completed
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback) {
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), executeCallback);
final MediaInformationSessionCompleteCallback completeCallback) {
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), completeCallback);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT);
@ -302,22 +316,24 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
* <p>Starts an asynchronous FFprobe execution to extract the media information for the
* specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @param path path or uri of a media file
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback,
final MediaInformationSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final int waitTimeout) {
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), executeCallback, logCallback);
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), completeCallback, logCallback);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);
@ -325,20 +341,22 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
* <p>Starts an asynchronous FFprobe execution to extract the media information for the
* specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be called when the execution is completed
* @param executorService executor service that will be used to run this asynchronous operation
* @param path path or uri of a media file
* @param completeCallback callback that will be called when the execution has completed
* @param executorService executor service that will be used to run this asynchronous operation
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback,
final MediaInformationSessionCompleteCallback completeCallback,
final ExecutorService executorService) {
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), executeCallback);
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), completeCallback);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, executorService, AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT);
@ -346,24 +364,26 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
* <p>Starts an asynchronous FFprobe execution to extract the media information for the
* specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param executorService executor service that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @param path path or uri of a media file
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param executorService executor service that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationAsync(final String path,
final ExecuteCallback executeCallback,
final MediaInformationSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final ExecutorService executorService,
final int waitTimeout) {
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), executeCallback, logCallback);
final MediaInformationSession session = new MediaInformationSession(defaultGetMediaInformationCommandArguments(path), completeCallback, logCallback);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, executorService, waitTimeout);
@ -385,44 +405,49 @@ public class FFprobeKit {
}
/**
* <p>Starts an asynchronous FFprobe execution to extract media information using a command. The command passed to
* this method must generate the output in JSON format in order to successfully extract media information from it.
* <p>Starts an asynchronous FFprobe execution to extract media information using a command.
* The command passed to this method must generate the output in JSON format in order to
* successfully extract media information from it.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param command FFprobe command that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @param command FFprobe command that prints media information for a file in JSON
* format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
public static MediaInformationSession getMediaInformationFromCommandAsync(final String command,
final ExecuteCallback executeCallback,
final MediaInformationSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final int waitTimeout) {
return getMediaInformationFromCommandArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, waitTimeout);
return getMediaInformationFromCommandArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, waitTimeout);
}
/**
* <p>Starts an asynchronous FFprobe execution to extract media information using command arguments. The command
* passed to this method must generate the output in JSON format in order to successfully extract media information
* from it.
* <p>Starts an asynchronous FFprobe execution to extract media information using command
* arguments. The command passed to this method must generate the output in JSON format in
* order to successfully extract media information from it.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* {@link ExecuteCallback} if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use a {@link MediaInformationSessionCompleteCallback} if you want to be notified
* about the result.
*
* @param arguments FFprobe command arguments that print media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @param arguments FFprobe command arguments that print media information for a file in
* JSON format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
private static MediaInformationSession getMediaInformationFromCommandArgumentsAsync(final String[] arguments,
final ExecuteCallback executeCallback,
final MediaInformationSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final int waitTimeout) {
final MediaInformationSession session = new MediaInformationSession(arguments, executeCallback, logCallback);
final MediaInformationSession session = new MediaInformationSession(arguments, completeCallback, logCallback);
FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);
@ -434,8 +459,17 @@ public class FFprobeKit {
*
* @return all FFprobe sessions in the session history
*/
public static List<FFprobeSession> listSessions() {
public static List<FFprobeSession> listFFprobeSessions() {
return FFmpegKitConfig.getFFprobeSessions();
}
/**
* <p>Lists all MediaInformation sessions in the session history.
*
* @return all MediaInformation sessions in the session history
*/
public static List<MediaInformationSession> listMediaInformationSessions() {
return FFmpegKitConfig.getMediaInformationSessions();
}
}

View File

@ -24,6 +24,11 @@ package com.arthenica.ffmpegkit;
*/
public class FFprobeSession extends AbstractSession implements Session {
/**
* Session specific complete callback.
*/
private final FFprobeSessionCompleteCallback completeCallback;
/**
* Builds a new FFprobe session.
*
@ -36,39 +41,50 @@ public class FFprobeSession extends AbstractSession implements Session {
/**
* Builds a new FFprobe session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param arguments command arguments
* @param completeCallback session specific complete callback
*/
public FFprobeSession(final String[] arguments, final ExecuteCallback executeCallback) {
this(arguments, executeCallback, null);
public FFprobeSession(final String[] arguments, final FFprobeSessionCompleteCallback completeCallback) {
this(arguments, completeCallback, null);
}
/**
* Builds a new FFprobe session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param logCallback session specific log callback function
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
*/
public FFprobeSession(final String[] arguments,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final LogCallback logCallback) {
this(arguments, executeCallback, logCallback, FFmpegKitConfig.getLogRedirectionStrategy());
this(arguments, completeCallback, logCallback, FFmpegKitConfig.getLogRedirectionStrategy());
}
/**
* Builds a new FFprobe session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param logCallback session specific log callback function
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
* @param logRedirectionStrategy session specific log redirection strategy
*/
public FFprobeSession(final String[] arguments,
final ExecuteCallback executeCallback,
final FFprobeSessionCompleteCallback completeCallback,
final LogCallback logCallback,
final LogRedirectionStrategy logRedirectionStrategy) {
super(arguments, executeCallback, logCallback, logRedirectionStrategy);
super(arguments, logCallback, logRedirectionStrategy);
this.completeCallback = completeCallback;
}
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
public FFprobeSessionCompleteCallback getCompleteCallback() {
return completeCallback;
}
@Override
@ -81,6 +97,11 @@ public class FFprobeSession extends AbstractSession implements Session {
return true;
}
@Override
public boolean isMediaInformation() {
return false;
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder();

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
package com.arthenica.ffmpegkit;
/**
* <p>Callback function that is invoked when an asynchronous <code>FFprobe</code> session has ended.
*/
@FunctionalInterface
public interface FFprobeSessionCompleteCallback {
/**
* <p>Called when an FFprobe session has ended.
*
* @param session FFprobe session
*/
void apply(final FFprobeSession session);
}

View File

@ -23,13 +23,18 @@ package com.arthenica.ffmpegkit;
* <p>A custom FFprobe session, which produces a <code>MediaInformation</code> object using the
* FFprobe output.
*/
public class MediaInformationSession extends FFprobeSession implements Session {
public class MediaInformationSession extends AbstractSession implements Session {
/**
* Media information extracted in the session.
*/
private MediaInformation mediaInformation;
/**
* Session specific complete callback.
*/
private final MediaInformationSessionCompleteCallback completeCallback;
/**
* Creates a new media information session.
*
@ -42,22 +47,24 @@ public class MediaInformationSession extends FFprobeSession implements Session {
/**
* Creates a new media information session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param arguments command arguments
* @param completeCallback session specific complete callback
*/
public MediaInformationSession(final String[] arguments, final ExecuteCallback executeCallback) {
this(arguments, executeCallback, null);
public MediaInformationSession(final String[] arguments, final MediaInformationSessionCompleteCallback completeCallback) {
this(arguments, completeCallback, null);
}
/**
* Creates a new media information session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback function
* @param logCallback session specific log callback function
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
*/
public MediaInformationSession(final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback) {
super(arguments, executeCallback, logCallback, LogRedirectionStrategy.NEVER_PRINT_LOGS);
public MediaInformationSession(final String[] arguments, final MediaInformationSessionCompleteCallback completeCallback, final LogCallback logCallback) {
super(arguments, logCallback, LogRedirectionStrategy.NEVER_PRINT_LOGS);
this.completeCallback = completeCallback;
}
/**
@ -79,6 +86,30 @@ public class MediaInformationSession extends FFprobeSession implements Session {
this.mediaInformation = mediaInformation;
}
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
public MediaInformationSessionCompleteCallback getCompleteCallback() {
return completeCallback;
}
@Override
public boolean isFFmpeg() {
return false;
}
@Override
public boolean isFFprobe() {
return false;
}
@Override
public boolean isMediaInformation() {
return true;
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder();

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
package com.arthenica.ffmpegkit;
/**
* <p>Callback function that is invoked when an asynchronous <code>MediaInformation</code> session
* has ended.
*/
@FunctionalInterface
public interface MediaInformationSessionCompleteCallback {
/**
* <p>Called when a media information session has ended.
*
* @param session media information session
*/
void apply(final MediaInformationSession session);
}

View File

@ -29,16 +29,9 @@ import java.util.concurrent.Future;
public interface Session {
/**
* Returns the session specific execute callback function.
* Returns the session specific log callback.
*
* @return session specific execute callback function
*/
ExecuteCallback getExecuteCallback();
/**
* Returns the session specific log callback function.
*
* @return session specific log callback function
* @return session specific log callback
*/
LogCallback getLogCallback();
@ -198,7 +191,7 @@ public interface Session {
/**
* Adds a new log entry for this session.
*
* <p>
* It is invoked internally by <code>FFmpegKit</code> library methods. Must not be used by user
* applications.
*
@ -227,6 +220,13 @@ public interface Session {
*/
boolean isFFprobe();
/**
* Returns whether it is a <code>MediaInformation</code> session or not.
*
* @return true if it is a <code>MediaInformation</code> session, false otherwise
*/
boolean isMediaInformation();
/**
* Cancels running the session.
*/

View File

@ -32,8 +32,8 @@ public class FFmpegSessionTest {
public void constructorTest() {
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS);
// 1. getExecuteCallback
Assert.assertNull(ffmpegSession.getExecuteCallback());
// 1. getCompleteCallback
Assert.assertNull(ffmpegSession.getCompleteCallback());
// 2. getLogCallback
Assert.assertNull(ffmpegSession.getLogCallback());
@ -93,17 +93,17 @@ public class FFmpegSessionTest {
@Test
public void constructorTest2() {
ExecuteCallback executeCallback = new ExecuteCallback() {
FFmpegSessionCompleteCallback completeCallback = new FFmpegSessionCompleteCallback() {
@Override
public void apply(Session session) {
public void apply(FFmpegSession session) {
}
};
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, executeCallback);
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, completeCallback);
// 1. getExecuteCallback
Assert.assertEquals(ffmpegSession.getExecuteCallback(), executeCallback);
// 1. getCompleteCallback
Assert.assertEquals(ffmpegSession.getCompleteCallback(), completeCallback);
// 2. getLogCallback
Assert.assertNull(ffmpegSession.getLogCallback());
@ -163,10 +163,10 @@ public class FFmpegSessionTest {
@Test
public void constructorTest3() {
ExecuteCallback executeCallback = new ExecuteCallback() {
FFmpegSessionCompleteCallback completeCallback = new FFmpegSessionCompleteCallback() {
@Override
public void apply(Session session) {
public void apply(FFmpegSession session) {
}
};
@ -184,10 +184,10 @@ public class FFmpegSessionTest {
}
};
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, executeCallback, logCallback, statisticsCallback);
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, completeCallback, logCallback, statisticsCallback);
// 1. getExecuteCallback
Assert.assertEquals(ffmpegSession.getExecuteCallback(), executeCallback);
// 1. getCompleteCallback
Assert.assertEquals(ffmpegSession.getCompleteCallback(), completeCallback);
// 2. getLogCallback
Assert.assertEquals(ffmpegSession.getLogCallback(), logCallback);

View File

@ -32,8 +32,8 @@ public class FFprobeSessionTest {
public void constructorTest() {
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS);
// 1. getExecuteCallback
Assert.assertNull(ffprobeSession.getExecuteCallback());
// 1. getCompleteCallback
Assert.assertNull(ffprobeSession.getCompleteCallback());
// 2. getLogCallback
Assert.assertNull(ffprobeSession.getLogCallback());
@ -90,17 +90,17 @@ public class FFprobeSessionTest {
@Test
public void constructorTest2() {
ExecuteCallback executeCallback = new ExecuteCallback() {
FFprobeSessionCompleteCallback completeCallback = new FFprobeSessionCompleteCallback() {
@Override
public void apply(Session session) {
public void apply(FFprobeSession session) {
}
};
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, executeCallback);
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, completeCallback);
// 1. getExecuteCallback
Assert.assertEquals(ffprobeSession.getExecuteCallback(), executeCallback);
// 1. getCompleteCallback
Assert.assertEquals(ffprobeSession.getCompleteCallback(), completeCallback);
// 2. getLogCallback
Assert.assertNull(ffprobeSession.getLogCallback());
@ -157,10 +157,10 @@ public class FFprobeSessionTest {
@Test
public void constructorTest3() {
ExecuteCallback executeCallback = new ExecuteCallback() {
FFprobeSessionCompleteCallback completeCallback = new FFprobeSessionCompleteCallback() {
@Override
public void apply(Session session) {
public void apply(FFprobeSession session) {
}
};
@ -171,10 +171,10 @@ public class FFprobeSessionTest {
}
};
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, executeCallback, logCallback);
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, completeCallback, logCallback);
// 1. getExecuteCallback
Assert.assertEquals(ffprobeSession.getExecuteCallback(), executeCallback);
// 1. getCompleteCallback
Assert.assertEquals(ffprobeSession.getCompleteCallback(), completeCallback);
// 2. getLogCallback
Assert.assertEquals(ffprobeSession.getLogCallback(), logCallback);

View File

@ -29,8 +29,8 @@
extern int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit;
/**
* Abstract session implementation which includes common features shared by <code>FFmpeg</code>
* and <code>FFprobe</code> sessions.
* Abstract session implementation which includes common features shared by <code>FFmpeg</code>,
* <code>FFprobe</code> and <code>MediaInformation</code> sessions.
*/
@interface AbstractSession : NSObject<Session>
@ -38,11 +38,10 @@ extern int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit;
* Creates a new abstract session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param logCallback session specific log callback
* @param logRedirectionStrategy session specific log redirection strategy
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy;
- (instancetype)init:(NSArray*)arguments withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy;
/**
* Waits for all asynchronous messages to be transmitted until the given timeout.

View File

@ -19,7 +19,6 @@
#import "AbstractSession.h"
#import "AtomicLong.h"
#import "ExecuteCallback.h"
#import "FFmpegKit.h"
#import "FFmpegKitConfig.h"
#import "LogCallback.h"
@ -33,7 +32,6 @@ extern void addSessionToSessionHistory(id<Session> session);
@implementation AbstractSession {
long _sessionId;
ExecuteCallback _executeCallback;
LogCallback _logCallback;
NSDate* _createTime;
NSDate* _startTime;
@ -51,11 +49,10 @@ extern void addSessionToSessionHistory(id<Session> session);
sessionIdGenerator = [[AtomicLong alloc] initWithValue:1];
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
- (instancetype)init:(NSArray*)arguments withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
self = [super init];
if (self) {
_sessionId = [sessionIdGenerator getAndIncrement];
_executeCallback = executeCallback;
_logCallback = logCallback;
_createTime = [NSDate date];
_startTime = nil;
@ -74,10 +71,6 @@ extern void addSessionToSessionHistory(id<Session> session);
return self;
}
- (ExecuteCallback)getExecuteCallback {
return _executeCallback;
}
- (LogCallback)getLogCallback {
return _logCallback;
}
@ -230,6 +223,11 @@ extern void addSessionToSessionHistory(id<Session> session);
return false;
}
- (BOOL)isMediaInformation {
// IMPLEMENTED IN SUBCLASSES
return false;
}
- (void)cancel {
if (_state == SessionStateRunning) {
[FFmpegKit cancel:_sessionId];

View File

@ -23,7 +23,6 @@
#import <string.h>
#import <stdlib.h>
#import <Foundation/Foundation.h>
#import "ExecuteCallback.h"
#import "LogCallback.h"
#import "FFmpegSession.h"
#import "StatisticsCallback.h"
@ -34,11 +33,11 @@
* <pre>
* FFmpegSession *session = [FFmpegKit execute:@"-i file1.mp4 -c:v libxvid file1.avi"];
*
* FFmpegSession *asyncSession = [FFmpegKit executeAsync:@"-i file1.mp4 -c:v libxvid file1.avi" withExecuteCallback:executeCallback];
* FFmpegSession *asyncSession = [FFmpegKit executeAsync:@"-i file1.mp4 -c:v libxvid file1.avi" withCompleteCallback:completeCallback];
* </pre>
* <p>Provides overloaded <code>execute</code> methods to define session specific callbacks.
* <pre>
* FFmpegSession *asyncSession = [FFmpegKit executeAsync:@"-i file1.mp4 -c:v libxvid file1.avi" withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
* FFmpegSession *asyncSession = [FFmpegKit executeAsync:@"-i file1.mp4 -c:v libxvid file1.avi" withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
* </pre>
*/
@interface FFmpegKit : NSObject
@ -54,56 +53,56 @@
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param arguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback;
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback;
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param arguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback;
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback;
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param arguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param arguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Synchronously executes FFmpeg command provided. Space character is used to split command
@ -120,70 +119,70 @@
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback;
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback;
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback;
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback;
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Starts an asynchronous FFmpeg execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFmpeg session created for this execution
*/
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Cancels all running sessions.
*
* <p>This function does not wait for termination to complete and returns immediately.
* <p>This method does not wait for termination to complete and returns immediately.
*/
+ (void)cancel;
/**
* <p>Cancels the session specified with <code>sessionId</code>.
*
* <p>This function does not wait for termination to complete and returns immediately.
* <p>This method does not wait for termination to complete and returns immediately.
*
* @param sessionId id of the session that will be cancelled
*/

View File

@ -40,26 +40,26 @@
return session;
}
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withExecuteCallback:executeCallback];
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFmpegExecute:session];
return session;
}
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
[FFmpegKitConfig asyncFFmpegExecute:session];
return session;
}
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withExecuteCallback:executeCallback];
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFmpegExecute:session onDispatchQueue:queue];
return session;
}
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
+ (FFmpegSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
[FFmpegKitConfig asyncFFmpegExecute:session onDispatchQueue:queue];
return session;
}
@ -70,26 +70,26 @@
return session;
}
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFmpegExecute:session];
return session;
}
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
[FFmpegKitConfig asyncFFmpegExecute:session];
return session;
}
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFmpegExecute:session onDispatchQueue:queue];
return session;
}
+ (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
+ (FFmpegSession*)executeAsync:(NSString*)command withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue {
FFmpegSession* session = [[FFmpegSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback];
[FFmpegKitConfig asyncFFmpegExecute:session onDispatchQueue:queue];
return session;
}

View File

@ -24,7 +24,6 @@
#import <pthread.h>
#import <unistd.h>
#import <Foundation/Foundation.h>
#import "ExecuteCallback.h"
#import "FFmpegSession.h"
#import "FFprobeSession.h"
#import "LogCallback.h"
@ -191,8 +190,8 @@ typedef NS_ENUM(NSUInteger, Signal) {
/**
* <p>Starts an asynchronous FFmpeg execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param ffmpegSession FFmpeg session which includes command options/arguments
*/
@ -201,8 +200,8 @@ typedef NS_ENUM(NSUInteger, Signal) {
/**
* <p>Starts an asynchronous FFmpeg execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param ffmpegSession FFmpeg session which includes command options/arguments
* @param queue dispatch queue that will be used to run this asynchronous operation
@ -212,8 +211,8 @@ typedef NS_ENUM(NSUInteger, Signal) {
/**
* <p>Starts an asynchronous FFprobe execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param ffprobeSession FFprobe session which includes command options/arguments
*/
@ -222,8 +221,8 @@ typedef NS_ENUM(NSUInteger, Signal) {
/**
* <p>Starts an asynchronous FFprobe execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param ffprobeSession FFprobe session which includes command options/arguments
* @param queue dispatch queue that will be used to run this asynchronous operation
@ -233,8 +232,8 @@ typedef NS_ENUM(NSUInteger, Signal) {
/**
* <p>Starts an asynchronous FFprobe execution for the given media information session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param mediaInformationSession media information session which includes command options/arguments
* @param waitTimeout max time to wait until media information is transmitted
@ -244,8 +243,8 @@ typedef NS_ENUM(NSUInteger, Signal) {
/**
* <p>Starts an asynchronous FFprobe execution for the given media information session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param mediaInformationSession media information session which includes command options/arguments
* @param queue dispatch queue that will be used to run this asynchronous operation
@ -268,18 +267,47 @@ typedef NS_ENUM(NSUInteger, Signal) {
+ (void)enableStatisticsCallback:(StatisticsCallback)statisticsCallback;
/**
* <p>Sets a global execute callback to receive execution results.
* <p>Sets a global FFmpegSessionCompleteCallback to receive execution results for FFmpeg sessions.
*
* @param executeCallback execute callback or nil to disable a previously execute callback
* @param ffmpegSessionCompleteCallback complete callback or nil to disable a previously defined callback
*/
+ (void)enableExecuteCallback:(ExecuteCallback)executeCallback;
+ (void)enableFFmpegSessionCompleteCallback:(FFmpegSessionCompleteCallback)ffmpegSessionCompleteCallback;
/**
* <p>Returns the global execute callback.
* <p>Returns the global FFmpegSessionCompleteCallback set.
*
* @return global execute callback
* @return global FFmpegSessionCompleteCallback or nil if it is not set
*/
+ (ExecuteCallback)getExecuteCallback;
+ (FFmpegSessionCompleteCallback)getFFmpegSessionCompleteCallback;
/**
* <p>Sets a global FFprobeSessionCompleteCallback to receive execution results for FFprobe sessions.
*
* @param ffprobeSessionCompleteCallback complete callback or nil to disable a previously defined callback
*/
+ (void)enableFFprobeSessionCompleteCallback:(FFprobeSessionCompleteCallback)ffprobeSessionCompleteCallback;
/**
* <p>Returns the global FFprobeSessionCompleteCallback set.
*
* @return global FFprobeSessionCompleteCallback or nil if it is not set
*/
+ (FFprobeSessionCompleteCallback)getFFprobeSessionCompleteCallback;
/**
* <p>Sets a global MediaInformationSessionCompleteCallback to receive execution results for MediaInformation sessions.
*
* @param mediaInformationSessionCompleteCallback complete callback or nil to disable a previously defined
* callback
*/
+ (void)enableMediaInformationSessionCompleteCallback:(MediaInformationSessionCompleteCallback)mediaInformationSessionCompleteCallback;
/**
* <p>Returns the global MediaInformationSessionCompleteCallback set.
*
* @return global MediaInformationSessionCompleteCallback or nil if it is not set
*/
+ (MediaInformationSessionCompleteCallback)getMediaInformationSessionCompleteCallback;
/**
* Returns the current log level.
@ -367,6 +395,13 @@ typedef NS_ENUM(NSUInteger, Signal) {
*/
+ (NSArray*)getFFprobeSessions;
/**
* <p>Returns all MediaInformation sessions in the session history.
*
* @return all MediaInformation sessions in the session history
*/
+ (NSArray*)getMediaInformationSessions;
/**
* <p>Returns sessions that have the given state.
*

View File

@ -67,8 +67,10 @@ static LogCallback logCallback;
/** Holds callback defined to redirect statistics */
static StatisticsCallback statisticsCallback;
/** Holds callback defined to redirect asynchronous execution results */
static ExecuteCallback executeCallback;
/** Holds complete callbacks defined to redirect asynchronous execution results */
static FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback;
static FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback;
static MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback;
static LogRedirectionStrategy globalLogRedirectionStrategy;
@ -507,7 +509,7 @@ void process_log(long sessionId, int levelValue, AVBPrint* logMessage) {
sessionLogCallback(log);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session LogCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside session log callback. %@", [exception callStackSymbols]);
}
}
}
@ -521,7 +523,7 @@ void process_log(long sessionId, int levelValue, AVBPrint* logMessage) {
globalLogCallback(log);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside global LogCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside global log callback. %@", [exception callStackSymbols]);
}
}
@ -580,7 +582,7 @@ void process_statistics(long sessionId, int videoFrameNumber, float videoFps, fl
sessionStatisticsCallback(statistics);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session StatisticsCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside session statistics callback. %@", [exception callStackSymbols]);
}
}
}
@ -591,7 +593,7 @@ void process_statistics(long sessionId, int videoFrameNumber, float videoFps, fl
globalStatisticsCallback(statistics);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside global StatisticsCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside global statistics callback. %@", [exception callStackSymbols]);
}
}
}
@ -751,7 +753,9 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
logCallback = nil;
statisticsCallback = nil;
executeCallback = nil;
ffmpegSessionCompleteCallback = nil;
ffprobeSessionCompleteCallback = nil;
mediaInformationSessionCompleteCallback = nil;
globalLogRedirectionStrategy = LogRedirectionStrategyPrintLogsWhenNoCallbacksDefined;
@ -1008,25 +1012,25 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
dispatch_async(queue, ^{
[FFmpegKitConfig ffmpegExecute:ffmpegSession];
ExecuteCallback sessionExecuteCallback = [ffmpegSession getExecuteCallback];
if (sessionExecuteCallback != nil) {
FFmpegSessionCompleteCallback completeCallback = [ffmpegSession getCompleteCallback];
if (completeCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
sessionExecuteCallback(ffmpegSession);
completeCallback(ffmpegSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside session complete callback. %@", [exception callStackSymbols]);
}
}
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
FFmpegSessionCompleteCallback globalFFmpegSessionCompleteCallback = [FFmpegKitConfig getFFmpegSessionCompleteCallback];
if (globalFFmpegSessionCompleteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
globalExecuteCallback(ffmpegSession);
globalFFmpegSessionCompleteCallback(ffmpegSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside global complete callback. %@", [exception callStackSymbols]);
}
}
});
@ -1040,25 +1044,25 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
dispatch_async(queue, ^{
[FFmpegKitConfig ffprobeExecute:ffprobeSession];
ExecuteCallback sessionExecuteCallback = [ffprobeSession getExecuteCallback];
if (sessionExecuteCallback != nil) {
FFprobeSessionCompleteCallback completeCallback = [ffprobeSession getCompleteCallback];
if (completeCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
sessionExecuteCallback(ffprobeSession);
completeCallback(ffprobeSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside session complete callback. %@", [exception callStackSymbols]);
}
}
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
FFprobeSessionCompleteCallback globalFFprobeSessionCompleteCallback = [FFmpegKitConfig getFFprobeSessionCompleteCallback];
if (globalFFprobeSessionCompleteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
globalExecuteCallback(ffprobeSession);
globalFFprobeSessionCompleteCallback(ffprobeSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside global complete callback. %@", [exception callStackSymbols]);
}
}
});
@ -1072,25 +1076,25 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
dispatch_async(queue, ^{
[FFmpegKitConfig getMediaInformationExecute:mediaInformationSession withTimeout:waitTimeout];
ExecuteCallback sessionExecuteCallback = [mediaInformationSession getExecuteCallback];
if (sessionExecuteCallback != nil) {
MediaInformationSessionCompleteCallback completeCallback = [mediaInformationSession getCompleteCallback];
if (completeCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
sessionExecuteCallback(mediaInformationSession);
completeCallback(mediaInformationSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside session complete callback. %@", [exception callStackSymbols]);
}
}
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
MediaInformationSessionCompleteCallback globalMediaInformationSessionCompleteCallback = [FFmpegKitConfig getMediaInformationSessionCompleteCallback];
if (globalMediaInformationSessionCompleteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
globalExecuteCallback(mediaInformationSession);
globalMediaInformationSessionCompleteCallback(mediaInformationSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
NSLog(@"Exception thrown inside global complete callback. %@", [exception callStackSymbols]);
}
}
});
@ -1104,12 +1108,28 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
statisticsCallback = callback;
}
+ (void)enableExecuteCallback:(ExecuteCallback)callback {
executeCallback = callback;
+ (void)enableFFmpegSessionCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback {
ffmpegSessionCompleteCallback = completeCallback;
}
+ (ExecuteCallback)getExecuteCallback {
return executeCallback;
+ (FFmpegSessionCompleteCallback)getFFmpegSessionCompleteCallback {
return ffmpegSessionCompleteCallback;
}
+ (void)enableFFprobeSessionCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback {
ffprobeSessionCompleteCallback = completeCallback;
}
+ (FFprobeSessionCompleteCallback)getFFprobeSessionCompleteCallback {
return ffprobeSessionCompleteCallback;
}
+ (void)enableMediaInformationSessionCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback {
mediaInformationSessionCompleteCallback = completeCallback;
}
+ (MediaInformationSessionCompleteCallback)getMediaInformationSessionCompleteCallback {
return mediaInformationSessionCompleteCallback;
}
+ (int)getLogLevel {
@ -1243,6 +1263,23 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
return ffprobeSessions;
}
+ (NSArray*)getMediaInformationSessions {
NSMutableArray* mediaInformationSessions = [[NSMutableArray alloc] init];
[sessionHistoryLock lock];
for(int i = 0; i < [sessionHistoryList count]; i++) {
id<Session> session = [sessionHistoryList objectAtIndex:i];
if ([session isMediaInformation]) {
[mediaInformationSessions addObject:session];
}
}
[sessionHistoryLock unlock];
return mediaInformationSessions;
}
+ (NSArray*)getSessionsByState:(SessionState)state {
NSMutableArray* sessions = [[NSMutableArray alloc] init];

View File

@ -23,6 +23,7 @@
#import <Foundation/Foundation.h>
#import "AbstractSession.h"
#import "StatisticsCallback.h"
#import "FFmpegSessionCompleteCallback.h"
/**
* <p>An FFmpeg session.
@ -39,31 +40,31 @@
/**
* Builds a new FFmpeg session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param arguments command arguments
* @param completeCallback session specific complete callback
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback;
/**
* Builds a new FFmpeg session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param logCallback session specific log callback
* @param statisticsCallback session specific statistics callback
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
* @param statisticsCallback session specific statistics callback
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback;
/**
* Builds a new FFmpeg session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param logCallback session specific log callback
* @param statisticsCallback session specific statistics callback
* @param logRedirectionStrategy session specific log redirection strategy
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
* @param statisticsCallback session specific statistics callback
* @param logRedirectionStrategy session specific log redirection strategy
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy;
/**
* Returns the session specific statistics callback.
@ -72,6 +73,13 @@
*/
- (StatisticsCallback)getStatisticsCallback;
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
- (FFmpegSessionCompleteCallback)getCompleteCallback;
/**
* Returns all statistics entries generated for this session. If there are asynchronous
* messages that are not delivered yet, this method waits for them until the given timeout.
@ -108,10 +116,8 @@
- (Statistics*)getLastReceivedStatistics;
/**
* Adds a new statistics entry for this session.
*
* It is invoked internally by <code>FFmpegKit</code> library methods. Must not be used by user
* applications.
* Adds a new statistics entry for this session. It is invoked internally by <code>FFmpegKit</code> library methods.
* Must not be used by user applications.
*
* @param statistics statistics entry
*/

View File

@ -17,7 +17,6 @@
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
#import "ExecuteCallback.h"
#import "FFmpegSession.h"
#import "FFmpegKitConfig.h"
#import "LogCallback.h"
@ -25,6 +24,7 @@
@implementation FFmpegSession {
StatisticsCallback _statisticsCallback;
FFmpegSessionCompleteCallback _completeCallback;
NSMutableArray* _statistics;
NSRecursiveLock* _statisticsLock;
}
@ -35,10 +35,11 @@
- (instancetype)init:(NSArray*)arguments {
self = [super init:arguments withExecuteCallback:nil withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
self = [super init:arguments withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
if (self) {
_statisticsCallback = nil;
_completeCallback = nil;
_statistics = [[NSMutableArray alloc] init];
_statisticsLock = [[NSRecursiveLock alloc] init];
}
@ -46,12 +47,13 @@
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
self = [super init:arguments withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
if (self) {
_statisticsCallback = nil;
_completeCallback = completeCallback;
_statistics = [[NSMutableArray alloc] init];
_statisticsLock = [[NSRecursiveLock alloc] init];
}
@ -59,12 +61,13 @@
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
self = [super init:arguments withLogCallback:logCallback withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
if (self) {
_statisticsCallback = statisticsCallback;
_completeCallback = completeCallback;
_statistics = [[NSMutableArray alloc] init];
_statisticsLock = [[NSRecursiveLock alloc] init];
}
@ -72,12 +75,13 @@
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:logRedirectionStrategy];
self = [super init:arguments withLogCallback:logCallback withLogRedirectionStrategy:logRedirectionStrategy];
if (self) {
_statisticsCallback = statisticsCallback;
_completeCallback = completeCallback;
_statistics = [[NSMutableArray alloc] init];
_statisticsLock = [[NSRecursiveLock alloc] init];
}
@ -89,6 +93,10 @@
return _statisticsCallback;
}
- (FFmpegSessionCompleteCallback)getCompleteCallback {
return _completeCallback;
}
- (NSArray*)getAllStatisticsWithTimeout:(int)waitTimeout {
[self waitForAsynchronousMessagesInTransmit:waitTimeout];
@ -137,5 +145,9 @@
return false;
}
- (BOOL)isMediaInformation {
return false;
}
@end

View File

@ -17,13 +17,13 @@
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FFMPEG_KIT_EXECUTE_CALLBACK_H
#define FFMPEG_KIT_EXECUTE_CALLBACK_H
#ifndef FFMPEG_KIT_FFMPEG_SESSION_COMPLETE_CALLBACK_H
#define FFMPEG_KIT_FFMPEG_SESSION_COMPLETE_CALLBACK_H
@protocol Session;
@class FFmpegSession;
/**
* <p>Callback invoked when an asynchronous session ends running.
* <p>Callback function that is invoked when an asynchronous <code>FFmpeg</code> session has ended.
* <p>Session has either SessionStateCompleted or SessionStateFailed state when
* the callback is invoked.
* <p>If it has SessionStateCompleted state, <code>ReturnCode</code> should be checked to
@ -43,8 +43,8 @@
*
* @param session session of the completed execution
*/
typedef void (^ExecuteCallback)(id<Session> session);
typedef void (^FFmpegSessionCompleteCallback)(FFmpegSession* session);
#import "Session.h"
#import "FFmpegSession.h"
#endif // FFMPEG_KIT_EXECUTE_CALLBACK_H
#endif // FFMPEG_KIT_FFMPEG_SESSION_COMPLETE_CALLBACK_H

View File

@ -32,11 +32,11 @@
* <pre>
* FFprobeSession *session = [FFprobeKit execute:@"-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4"];
*
* FFprobeSession *asyncSession = [FFprobeKit executeAsync:@"-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4" withExecuteCallback:executeCallback];
* FFprobeSession *asyncSession = [FFprobeKit executeAsync:@"-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4" withCompleteCallback:completeCallback];
* </pre>
* <p>Provides overloaded <code>execute</code> methods to define session specific callbacks.
* <pre>
* FFprobeSession *session = [FFprobeKit executeAsync:@"-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4" withExecuteCallback:executeCallback withLogCallback:logCallback];
* FFprobeSession *session = [FFprobeKit executeAsync:@"-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4" withCompleteCallback:completeCallback withLogCallback:logCallback];
* </pre>
* <p>It can extract media information for a file or a url, using getMediaInformation method.
* <pre>
@ -56,54 +56,54 @@
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback;
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback;
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback;
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback;
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* <p>Note that this method returns immediately and does not wait the execution to complete.
* You must use an FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param arguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param arguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Synchronously executes FFprobe command provided. Space character is used to split command
@ -120,56 +120,56 @@
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback;
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback;
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param command FFprobe command
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback;
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback;
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param command FFprobe command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return FFprobe session created for this execution
*/
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Extracts media information for the file specified with path.
@ -192,55 +192,55 @@
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be called when the execution is completed
* @param path path or uri of a media file
* @param completeCallback callback that will be called when the execution has completed
* @return media information session created for this execution
*/
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback;
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback;
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @param path path or uri of a media file
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withTimeout:(int)waitTimeout;
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withTimeout:(int)waitTimeout;
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be called when the execution is completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param path path or uri of a media file
* @param completeCallback callback that will be called when the execution has completed
* @param queue dispatch queue that will be used to run this asynchronous operation
* @return media information session created for this execution
*/
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue;
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue;
/**
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @param path path or uri of a media file
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout;
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout;
/**
* <p>Extracts media information using the command provided asynchronously.
@ -255,16 +255,16 @@
* this method must generate the output in JSON format in order to successfully extract media information from it.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @param command FFprobe command that prints media information for a file in JSON format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
+ (MediaInformationSession*)getMediaInformationFromCommandAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout;
+ (MediaInformationSession*)getMediaInformationFromCommandAsync:(NSString*)command withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout;
/**
* <p>Starts an asynchronous FFprobe execution to extract media information using command arguments. The command
@ -272,23 +272,30 @@
* from it.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @param command FFprobe command that prints media information for a file in JSON format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param queue dispatch queue that will be used to run this asynchronous operation
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
+ (MediaInformationSession*)getMediaInformationFromCommandArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout;
+ (MediaInformationSession*)getMediaInformationFromCommandArgumentsAsync:(NSArray*)arguments withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout;
/**
* <p>Lists all FFprobe sessions in the session history.
*
* @return all FFprobe sessions in the session history
*/
+ (NSArray*)listSessions;
+ (NSArray*)listFFprobeSessions;
/**
* <p>Lists all MediaInformation sessions in the session history.
*
* @return all MediaInformation sessions in the session history
*/
+ (NSArray*)listMediaInformationSessions;
@end

View File

@ -38,26 +38,26 @@
return session;
}
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withExecuteCallback:executeCallback];
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFprobeExecute:session];
return session;
}
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback];
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncFFprobeExecute:session];
return session;
}
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withExecuteCallback:executeCallback];
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFprobeExecute:session onDispatchQueue:queue];
return session;
}
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback];
+ (FFprobeSession*)executeWithArgumentsAsync:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncFFprobeExecute:session onDispatchQueue:queue];
return session;
}
@ -68,26 +68,26 @@
return session;
}
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFprobeExecute:session];
return session;
}
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncFFprobeExecute:session];
return session;
}
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback];
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncFFprobeExecute:session onDispatchQueue:queue];
return session;
}
+ (FFprobeSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
+ (FFprobeSession*)executeAsync:(NSString*)command withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue {
FFprobeSession* session = [[FFprobeSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncFFprobeExecute:session onDispatchQueue:queue];
return session;
}
@ -106,30 +106,30 @@
return session;
}
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback {
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback {
NSArray* arguments = [FFprobeKit defaultGetMediaInformationCommandArguments:path];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withExecuteCallback:executeCallback];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncGetMediaInformationExecute:session withTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit];
return session;
}
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withTimeout:(int)waitTimeout {
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withTimeout:(int)waitTimeout {
NSArray* arguments = [FFprobeKit defaultGetMediaInformationCommandArguments:path];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncGetMediaInformationExecute:session withTimeout:waitTimeout];
return session;
}
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback onDispatchQueue:(dispatch_queue_t)queue {
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback onDispatchQueue:(dispatch_queue_t)queue {
NSArray* arguments = [FFprobeKit defaultGetMediaInformationCommandArguments:path];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withExecuteCallback:executeCallback];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncGetMediaInformationExecute:session onDispatchQueue:queue withTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit];
return session;
}
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
+ (MediaInformationSession*)getMediaInformationAsync:(NSString*)path withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
NSArray* arguments = [FFprobeKit defaultGetMediaInformationCommandArguments:path];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withExecuteCallback:executeCallback];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:completeCallback];
[FFmpegKitConfig asyncGetMediaInformationExecute:session onDispatchQueue:queue withTimeout:waitTimeout];
return session;
}
@ -140,20 +140,24 @@
return session;
}
+ (MediaInformationSession*)getMediaInformationFromCommandAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
MediaInformationSession* session = [[MediaInformationSession alloc] init:[FFmpegKitConfig parseArguments:command] withExecuteCallback:executeCallback withLogCallback:logCallback];
+ (MediaInformationSession*)getMediaInformationFromCommandAsync:(NSString*)command withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
MediaInformationSession* session = [[MediaInformationSession alloc] init:[FFmpegKitConfig parseArguments:command] withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncGetMediaInformationExecute:session onDispatchQueue:queue withTimeout:waitTimeout];
return session;
}
+ (MediaInformationSession*)getMediaInformationFromCommandArgumentsAsync:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback];
+ (MediaInformationSession*)getMediaInformationFromCommandArgumentsAsync:(NSArray*)arguments withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback];
[FFmpegKitConfig asyncGetMediaInformationExecute:session onDispatchQueue:queue withTimeout:waitTimeout];
return session;
}
+ (NSArray*)listSessions {
+ (NSArray*)listFFprobeSessions {
return [FFmpegKitConfig getFFprobeSessions];
}
+ (NSArray*)listMediaInformationSessions {
return [FFmpegKitConfig getMediaInformationSessions];
}
@end

View File

@ -22,6 +22,7 @@
#import <Foundation/Foundation.h>
#import "AbstractSession.h"
#import "FFprobeSessionCompleteCallback.h"
/**
* <p>An FFprobe session.
@ -38,29 +39,36 @@
/**
* Builds a new FFprobe session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param arguments command arguments
* @param completeCallback session specific complete callback
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback;
/**
* Builds a new FFprobe session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param logCallback session specific log callback
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback;
/**
* Builds a new FFprobe session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param logCallback session specific log callback
* @param logRedirectionStrategy session specific log redirection strategy
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
* @param logRedirectionStrategy session specific log redirection strategy
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy;
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
- (FFprobeSessionCompleteCallback)getCompleteCallback;
@end

View File

@ -17,45 +17,66 @@
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
#import "ExecuteCallback.h"
#import "FFprobeSession.h"
#import "FFmpegKitConfig.h"
#import "LogCallback.h"
@implementation FFprobeSession
- (instancetype)init:(NSArray*)arguments {
self = [super init:arguments withExecuteCallback:nil withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
return self;
@implementation FFprobeSession {
FFprobeSessionCompleteCallback _completeCallback;
}
+ (void)initialize {
// EMPTY INITIALIZE
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback {
- (instancetype)init:(NSArray*)arguments {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
self = [super init:arguments withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
if (self) {
_completeCallback = nil;
}
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
self = [super init:arguments withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
if (self) {
_completeCallback = completeCallback;
}
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:logRedirectionStrategy];
self = [super init:arguments withLogCallback:logCallback withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
if (self) {
_completeCallback = completeCallback;
}
return self;
}
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFprobeSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
self = [super init:arguments withLogCallback:logCallback withLogRedirectionStrategy:logRedirectionStrategy];
if (self) {
_completeCallback = completeCallback;
}
return self;
}
- (FFprobeSessionCompleteCallback)getCompleteCallback {
return _completeCallback;
}
- (BOOL)isFFmpeg {
return false;
}
@ -64,5 +85,9 @@
return true;
}
- (BOOL)isMediaInformation {
return false;
}
@end

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2020-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FFMPEG_KIT_FFPROBE_SESSION_COMPLETE_CALLBACK_H
#define FFMPEG_KIT_FFPROBE_SESSION_COMPLETE_CALLBACK_H
@class FFprobeSession;
/**
* <p>Callback function that is invoked when an asynchronous <code>FFprobe</code> session has ended.
* <p>Session has either SessionStateCompleted or SessionStateFailed state when
* the callback is invoked.
* <p>If it has SessionStateCompleted state, <code>ReturnCode</code> should be checked to
* see the execution result.
* <p>If <code>getState</code> returns SessionStateFailed then
* <code>getFailStackTrace</code> should be used to get the failure reason.
* <pre>
* switch ([session getState]) {
* case SessionStateCompleted:
* ReturnCode *returnCode = [session getReturnCode];
* break;
* case SessionStateFailed:
* NSString *failStackTrace = [session getFailStackTrace];
* break;
* }
* </pre>
*
* @param session session of the completed execution
*/
typedef void (^FFprobeSessionCompleteCallback)(FFprobeSession* session);
#import "FFprobeSession.h"
#endif // FFMPEG_KIT_FFPROBE_SESSION_COMPLETE_CALLBACK_H

View File

@ -37,28 +37,30 @@ include_HEADERS = \
ArchDetect.h \
AtomicLong.h \
Chapter.h \
ExecuteCallback.h \
FFmpegKit.h \
FFmpegKitConfig.h \
FFmpegSession.h \
FFprobeKit.h \
FFprobeSession.h \
Level.h \
Log.h \
LogCallback.h \
LogRedirectionStrategy.h \
MediaInformation.h \
MediaInformationJsonParser.h \
MediaInformationSession.h \
Packages.h \
ReturnCode.h \
Session.h \
SessionState.h \
Statistics.h \
StatisticsCallback.h \
StreamInformation.h \
ffmpegkit_exception.h \
fftools_cmdutils.h \
FFmpegSessionCompleteCallback.h \
FFprobeKit.h \
FFprobeSession.h \
FFprobeSessionCompleteCallback.h \
Level.h \
Log.h \
LogCallback.h \
LogRedirectionStrategy.h \
MediaInformation.h \
MediaInformationJsonParser.h \
MediaInformationSession.h \
MediaInformationSessionCompleteCallback.h \
Packages.h \
ReturnCode.h \
Session.h \
SessionState.h \
Statistics.h \
StatisticsCallback.h \
StreamInformation.h \
ffmpegkit_exception.h \
fftools_cmdutils.h \
fftools_ffmpeg.h
libffmpegkit_la_CFLAGS = $(CFLAGS)

View File

@ -414,28 +414,30 @@ include_HEADERS = \
ArchDetect.h \
AtomicLong.h \
Chapter.h \
ExecuteCallback.h \
FFmpegKit.h \
FFmpegKitConfig.h \
FFmpegSession.h \
FFprobeKit.h \
FFprobeSession.h \
Level.h \
Log.h \
LogCallback.h \
LogRedirectionStrategy.h \
MediaInformation.h \
MediaInformationJsonParser.h \
MediaInformationSession.h \
Packages.h \
ReturnCode.h \
Session.h \
SessionState.h \
Statistics.h \
StatisticsCallback.h \
StreamInformation.h \
ffmpegkit_exception.h \
fftools_cmdutils.h \
FFmpegSessionCompleteCallback.h \
FFprobeKit.h \
FFprobeSession.h \
FFprobeSessionCompleteCallback.h \
Level.h \
Log.h \
LogCallback.h \
LogRedirectionStrategy.h \
MediaInformation.h \
MediaInformationJsonParser.h \
MediaInformationSession.h \
MediaInformationSessionCompleteCallback.h \
Packages.h \
ReturnCode.h \
Session.h \
SessionState.h \
Statistics.h \
StatisticsCallback.h \
StreamInformation.h \
ffmpegkit_exception.h \
fftools_cmdutils.h \
fftools_ffmpeg.h
libffmpegkit_la_CFLAGS = $(CFLAGS)

View File

@ -21,14 +21,15 @@
#define FFMPEG_KIT_MEDIA_INFORMATION_SESSION_H
#import <Foundation/Foundation.h>
#import "FFprobeSession.h"
#import "AbstractSession.h"
#import "MediaInformation.h"
#import "MediaInformationSessionCompleteCallback.h"
/**
* <p>A custom FFprobe session, which produces a <code>MediaInformation</code> object using the
* FFprobe output.
*/
@interface MediaInformationSession : FFprobeSession
@interface MediaInformationSession : AbstractSession
/**
* Creates a new media information session.
@ -40,19 +41,19 @@
/**
* Creates a new media information session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param arguments command arguments
* @param completeCallback session specific complete callback
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback;
/**
* Creates a new media information session.
*
* @param arguments command arguments
* @param executeCallback session specific execute callback
* @param logCallback session specific log callback
* @param arguments command arguments
* @param completeCallback session specific complete callback
* @param logCallback session specific log callback
*/
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback;
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback;
/**
* Returns the media information extracted in this session.
@ -69,6 +70,13 @@
*/
- (void)setMediaInformation:(MediaInformation*)mediaInformation;
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
- (MediaInformationSessionCompleteCallback)getCompleteCallback;
@end
#endif // FFMPEG_KIT_MEDIA_INFORMATION_SESSION_H

View File

@ -17,13 +17,13 @@
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
#import "ExecuteCallback.h"
#import "MediaInformationSession.h"
#import "LogCallback.h"
#import "MediaInformation.h"
#import "MediaInformationSession.h"
@implementation MediaInformationSession {
MediaInformation* _mediaInformation;
MediaInformationSessionCompleteCallback _completeCallback;
}
+ (void)initialize {
@ -32,21 +32,33 @@
- (instancetype)init:(NSArray*)arguments {
self = [super init:arguments withExecuteCallback:nil withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
self = [super init:arguments withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
if (self) {
_completeCallback = nil;
}
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
self = [super init:arguments withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
if (self) {
_completeCallback = completeCallback;
}
return self;
}
- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback {
- (instancetype)init:(NSArray*)arguments withCompleteCallback:(MediaInformationSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback {
self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
self = [super init:arguments withLogCallback:logCallback withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
if (self) {
_completeCallback = completeCallback;
}
return self;
}
@ -59,5 +71,21 @@
_mediaInformation = mediaInformation;
}
- (MediaInformationSessionCompleteCallback)getCompleteCallback {
return _completeCallback;
}
- (BOOL)isFFmpeg {
return false;
}
- (BOOL)isFFprobe {
return false;
}
- (BOOL)isMediaInformation {
return true;
}
@end

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2020-2021 Taner Sener
*
* This file is part of FFmpegKit.
*
* FFmpegKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FFmpegKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FFMPEG_KIT_MEDIA_INFORMATION_SESSION_COMPLETE_CALLBACK_H
#define FFMPEG_KIT_MEDIA_INFORMATION_SESSION_COMPLETE_CALLBACK_H
@class MediaInformationSession;
/**
* <p>Callback function that is invoked when an asynchronous <code>MediaInformation</code> session
* has ended.
* <p>Session has either SessionStateCompleted or SessionStateFailed state when
* the callback is invoked.
* <p>If it has SessionStateCompleted state, <code>ReturnCode</code> should be checked to
* see the execution result.
* <p>If <code>getState</code> returns SessionStateFailed then
* <code>getFailStackTrace</code> should be used to get the failure reason.
* <pre>
* switch ([session getState]) {
* case SessionStateCompleted:
* ReturnCode *returnCode = [session getReturnCode];
* break;
* case SessionStateFailed:
* NSString *failStackTrace = [session getFailStackTrace];
* break;
* }
* </pre>
*
* @param session session of the completed execution
*/
typedef void (^MediaInformationSessionCompleteCallback)(MediaInformationSession* session);
#import "MediaInformationSession.h"
#endif // FFMPEG_KIT_MEDIA_INFORMATION_SESSION_COMPLETE_CALLBACK_H

View File

@ -21,7 +21,6 @@
#define FFMPEG_KIT_SESSION_H
#import <Foundation/Foundation.h>
#import "ExecuteCallback.h"
#import "Log.h"
#import "LogCallback.h"
#import "LogRedirectionStrategy.h"
@ -35,13 +34,6 @@
@required
/**
* Returns the session specific execute callback.
*
* @return session specific execute callback
*/
- (ExecuteCallback)getExecuteCallback;
/**
* Returns the session specific log callback.
*
@ -171,7 +163,7 @@
* that end with SessionStateCompleted state. If a session is not started, still running or failed then
* this method returns nil.
*
* @return the return code for this session if the session is completed, nil if session is
* @return the return code for this session if the session has completed, nil if session is
* not started, still running or failed
*/
- (ReturnCode*)getReturnCode;
@ -246,6 +238,13 @@
*/
- (BOOL)isFFprobe;
/**
* Returns whether it is a <code>MediaInformation</code> session or not.
*
* @return true if it is a <code>MediaInformation</code> session, false otherwise
*/
- (BOOL)isMediaInformation;
/**
* Cancels running the session.
*/

View File

@ -841,12 +841,13 @@ framework module ffmpegkit {
header "ArchDetect.h"
header "AtomicLong.h"
header "Chapter.h"
header "ExecuteCallback.h"
header "FFmpegKit.h"
header "FFmpegKitConfig.h"
header "FFmpegSession.h"
header "FFmpegSessionCompleteCallback.h"
header "FFprobeKit.h"
header "FFprobeSession.h"
header "FFprobeSessionCompleteCallback.h"
header "Level.h"
header "Log.h"
header "LogCallback.h"
@ -854,6 +855,7 @@ framework module ffmpegkit {
header "MediaInformation.h"
header "MediaInformationJsonParser.h"
header "MediaInformationSession.h"
header "MediaInformationSessionCompleteCallback.h"
header "Packages.h"
header "ReturnCode.h"
header "Session.h"