From 17b4a70acb28ceeb1a18f80c1258c4b893613d81 Mon Sep 17 00:00:00 2001 From: Sajid Ali Date: Mon, 13 Dec 2021 15:07:57 +0500 Subject: [PATCH] Added an option to provide custom session id --- android/ffmpeg-kit-android-lib/build.gradle | 6 +- .../arthenica/ffmpegkit/AbstractSession.java | 12 ++- .../com/arthenica/ffmpegkit/FFmpegKit.java | 70 +++++++++++---- .../arthenica/ffmpegkit/FFmpegSession.java | 31 +++++-- .../com/arthenica/ffmpegkit/FFprobeKit.java | 85 +++++++++++++------ .../arthenica/ffmpegkit/FFprobeSession.java | 27 ++++-- .../ffmpegkit/MediaInformationSession.java | 19 +++-- .../ffmpegkit/FFmpegSessionTest.java | 12 ++- .../ffmpegkit/FFprobeSessionTest.java | 12 ++- 9 files changed, 199 insertions(+), 75 deletions(-) diff --git a/android/ffmpeg-kit-android-lib/build.gradle b/android/ffmpeg-kit-android-lib/build.gradle index be18375..a0d146f 100644 --- a/android/ffmpeg-kit-android-lib/build.gradle +++ b/android/ffmpeg-kit-android-lib/build.gradle @@ -5,10 +5,10 @@ android { ndkVersion "23.0.7599858" defaultConfig { - minSdkVersion 24 + minSdkVersion 16 targetSdkVersion 30 - versionCode 240450 - versionName "4.5" + versionCode 160450 + versionName "4.5.LTS" project.archivesBaseName = "ffmpeg-kit" consumerProguardFiles 'proguard-rules.pro' } diff --git a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/AbstractSession.java b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/AbstractSession.java index 9e799af..fe43af1 100644 --- a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/AbstractSession.java +++ b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/AbstractSession.java @@ -33,6 +33,8 @@ import java.util.concurrent.atomic.AtomicLong; */ public abstract class AbstractSession implements Session { + public static final long AUTO_GENERATED_ID = -1; + /** * Generates unique ids for sessions. */ @@ -116,16 +118,22 @@ public abstract class AbstractSession implements Session { /** * Creates a new abstract session. * + * @param sessionId provide your own session id or -1 to generate session id * @param arguments command arguments * @param executeCallback session specific execute callback function * @param logCallback session specific log callback function * @param logRedirectionStrategy session specific log redirection strategy */ - public AbstractSession(final String[] arguments, + public AbstractSession(final long sessionId, + final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final LogRedirectionStrategy logRedirectionStrategy) { - this.sessionId = sessionIdGenerator.getAndIncrement(); + if(sessionId > 0){ + this.sessionId = sessionId; + } else { + this.sessionId = sessionIdGenerator.getAndIncrement(); + } this.executeCallback = executeCallback; this.logCallback = logCallback; this.createTime = new Date(); diff --git a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegKit.java b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegKit.java index 150e723..047730d 100644 --- a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegKit.java +++ b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegKit.java @@ -19,7 +19,6 @@ package com.arthenica.ffmpegkit; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; @@ -63,19 +62,36 @@ public class FFmpegKit { return session; } + /** + *

Synchronously executes FFmpeg with arguments provided. + * + * @param sessionId Provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} + * @param arguments FFmpeg command options/arguments as string array + * @return FFmpeg session created for this execution + */ + public static FFmpegSession execute(final long sessionId, final String[] arguments) { + final FFmpegSession session = new FFmpegSession(sessionId, arguments); + + FFmpegKitConfig.ffmpegExecute(session); + + return session; + } + /** *

Starts an asynchronous FFmpeg execution with arguments provided. * *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId Provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @param arguments FFmpeg command options/arguments as string array * @param executeCallback callback that will be called when the execution is completed * @return FFmpeg session created for this execution */ - public static FFmpegSession executeAsync(final String[] arguments, + public static FFmpegSession executeAsync(final long sessionId, + final String[] arguments, final ExecuteCallback executeCallback) { - final FFmpegSession session = new FFmpegSession(arguments, executeCallback); + final FFmpegSession session = new FFmpegSession(sessionId, arguments, executeCallback); FFmpegKitConfig.asyncFFmpegExecute(session); @@ -88,17 +104,18 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId Provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @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 * @return FFmpeg session created for this execution */ - public static FFmpegSession executeAsync(final String[] arguments, + public static FFmpegSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback) { - final FFmpegSession session = new FFmpegSession(arguments, executeCallback, logCallback, statisticsCallback); + final FFmpegSession session = new FFmpegSession(sessionId, arguments, executeCallback, logCallback, statisticsCallback); FFmpegKitConfig.asyncFFmpegExecute(session); @@ -111,15 +128,16 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId Provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @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 * @return FFmpeg session created for this execution */ - public static FFmpegSession executeAsync(final String[] arguments, + public static FFmpegSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final ExecutorService executorService) { - final FFmpegSession session = new FFmpegSession(arguments, executeCallback); + final FFmpegSession session = new FFmpegSession(sessionId, arguments, executeCallback); FFmpegKitConfig.asyncFFmpegExecute(session, executorService); @@ -132,6 +150,7 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId Provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @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 @@ -139,12 +158,12 @@ public class FFmpegKit { * @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[] arguments, + public static FFmpegSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback, final ExecutorService executorService) { - final FFmpegSession session = new FFmpegSession(arguments, executeCallback, logCallback, statisticsCallback); + final FFmpegSession session = new FFmpegSession(sessionId, arguments, executeCallback, logCallback, statisticsCallback); FFmpegKitConfig.asyncFFmpegExecute(session, executorService); @@ -163,6 +182,19 @@ public class FFmpegKit { return execute(FFmpegKitConfig.parseArguments(command)); } + /** + *

Synchronously executes FFmpeg command provided. Space character is used to split command + * into arguments. You can use single or double quote characters to specify arguments inside + * your command. + * + * @param sessionId provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} + * @param command FFmpeg command + * @return FFmpeg session created for this execution + */ + public static FFmpegSession execute(final long sessionId, final String command) { + return execute(sessionId, FFmpegKitConfig.parseArguments(command)); + } + /** *

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. @@ -170,13 +202,14 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @param command FFmpeg command * @param executeCallback callback that will be called when the execution is completed * @return FFmpeg session created for this execution */ - public static FFmpegSession executeAsync(final String command, + public static FFmpegSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback) { - return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback); + return executeAsync(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback); } /** @@ -186,17 +219,18 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @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 * @return FFmpeg session created for this execution */ - public static FFmpegSession executeAsync(final String command, + public static FFmpegSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback) { - return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback); + return executeAsync(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback); } /** @@ -206,15 +240,16 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @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 * @return FFmpeg session created for this execution */ - public static FFmpegSession executeAsync(final String command, + public static FFmpegSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, final ExecutorService executorService) { - final FFmpegSession session = new FFmpegSession(FFmpegKitConfig.parseArguments(command), executeCallback); + final FFmpegSession session = new FFmpegSession(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback); FFmpegKitConfig.asyncFFmpegExecute(session, executorService); @@ -228,6 +263,7 @@ public class FFmpegKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFmpegSession#AUTO_GENERATED_ID} * @param command FFmpeg command * @param executeCallback callback that will be called when the execution is completed * @param logCallback callback that will receive logs @@ -235,12 +271,12 @@ public class FFmpegKit { * @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, + public static FFmpegSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, 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(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback); FFmpegKitConfig.asyncFFmpegExecute(session, executorService); diff --git a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegSession.java b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegSession.java index 28e7ada..867c93f 100644 --- a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegSession.java +++ b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFmpegSession.java @@ -48,49 +48,64 @@ public class FFmpegSession extends AbstractSession implements Session { * @param arguments command arguments */ public FFmpegSession(final String[] arguments) { - this(arguments, null); + this(-1, arguments); } /** - * Builds a new FFmpeg session. + * Builds a new FFmpeg session with provide session id. + * + * @param sessionId provide session id + * @param arguments command arguments + */ + public FFmpegSession(final long sessionId, final String[] arguments) { + this(sessionId, arguments, null); + } + + /** + * Builds a new FFmpeg session with provided session id. * + * @param sessionId provide session id * @param arguments command arguments * @param executeCallback session specific execute callback function */ - public FFmpegSession(final String[] arguments, final ExecuteCallback executeCallback) { - this(arguments, executeCallback, null, null); + public FFmpegSession(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback) { + this(sessionId, arguments, executeCallback, null, null); } /** * Builds a new FFmpeg session. * + * @param sessionId provide session id * @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 */ - public FFmpegSession(final String[] arguments, + public FFmpegSession(final long sessionId, + final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback) { - this(arguments, executeCallback, logCallback, statisticsCallback, FFmpegKitConfig.getLogRedirectionStrategy()); + this(sessionId, arguments, executeCallback, logCallback, statisticsCallback, FFmpegKitConfig.getLogRedirectionStrategy()); } /** * Builds a new FFmpeg session. * + * @param sessionId provide session id * @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 logRedirectionStrategy session specific log redirection strategy */ - public FFmpegSession(final String[] arguments, + public FFmpegSession(final long sessionId, + final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final StatisticsCallback statisticsCallback, final LogRedirectionStrategy logRedirectionStrategy) { - super(arguments, executeCallback, logCallback, logRedirectionStrategy); + super(sessionId, arguments, executeCallback, logCallback, logRedirectionStrategy); this.statisticsCallback = statisticsCallback; diff --git a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeKit.java b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeKit.java index 3db4611..0d17336 100644 --- a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeKit.java +++ b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeKit.java @@ -66,19 +66,35 @@ public class FFprobeKit { return session; } + /** + *

Synchronously executes FFprobe with arguments provided. + * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} + * @param arguments FFprobe command options/arguments as string array + * @return FFprobe session created for this execution + */ + public static FFprobeSession execute(final long sessionId, final String[] arguments) { + final FFprobeSession session = new FFprobeSession(sessionId, arguments); + + FFmpegKitConfig.ffprobeExecute(session); + + return session; + } + /** *

Starts an asynchronous FFprobe execution with arguments provided. * *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @param arguments FFprobe command options/arguments as string array * @param executeCallback callback that will be called when the execution is completed * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String[] arguments, + public static FFprobeSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback) { - final FFprobeSession session = new FFprobeSession(arguments, executeCallback); + final FFprobeSession session = new FFprobeSession(sessionId, arguments, executeCallback); FFmpegKitConfig.asyncFFprobeExecute(session); @@ -91,15 +107,16 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String[] arguments, + public static FFprobeSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback) { - final FFprobeSession session = new FFprobeSession(arguments, executeCallback, logCallback); + final FFprobeSession session = new FFprobeSession(sessionId, arguments, executeCallback, logCallback); FFmpegKitConfig.asyncFFprobeExecute(session); @@ -112,15 +129,16 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String[] arguments, + public static FFprobeSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final ExecutorService executorService) { - final FFprobeSession session = new FFprobeSession(arguments, executeCallback); + final FFprobeSession session = new FFprobeSession(sessionId, arguments, executeCallback); FFmpegKitConfig.asyncFFprobeExecute(session, executorService); @@ -133,17 +151,18 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String[] arguments, + public static FFprobeSession executeAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final ExecutorService executorService) { - final FFprobeSession session = new FFprobeSession(arguments, executeCallback, logCallback); + final FFprobeSession session = new FFprobeSession(sessionId, arguments, executeCallback, logCallback); FFmpegKitConfig.asyncFFprobeExecute(session, executorService); @@ -169,13 +188,14 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @param command FFprobe command * @param executeCallback callback that will be called when the execution is completed * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String command, + public static FFprobeSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback) { - return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback); + return executeAsync(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback); } /** @@ -185,15 +205,16 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @param command FFprobe command * @param executeCallback callback that will be notified when execution is completed * @param logCallback callback that will receive logs * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String command, + public static FFprobeSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, final LogCallback logCallback) { - return executeAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback); + return executeAsync(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback, logCallback); } /** @@ -203,15 +224,16 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String command, + public static FFprobeSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, final ExecutorService executorService) { - final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), executeCallback); + final FFprobeSession session = new FFprobeSession(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback); FFmpegKitConfig.asyncFFprobeExecute(session, executorService); @@ -225,17 +247,18 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return FFprobe session created for this execution */ - public static FFprobeSession executeAsync(final String command, + public static FFprobeSession executeAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, final LogCallback logCallback, final ExecutorService executorService) { - final FFprobeSession session = new FFprobeSession(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback); + final FFprobeSession session = new FFprobeSession(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback, logCallback); FFmpegKitConfig.asyncFFprobeExecute(session, executorService); @@ -278,13 +301,14 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @param path path or uri of a media file * @param executeCallback callback that will be called when the execution is completed * @return media information session created for this execution */ - public static MediaInformationSession getMediaInformationAsync(final String path, + public static MediaInformationSession getMediaInformationAsync(final long sessionId, final String path, final ExecuteCallback executeCallback) { - final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback); + final MediaInformationSession session = new MediaInformationSession(sessionId, new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback); FFmpegKitConfig.asyncGetMediaInformationExecute(session, AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT); @@ -297,17 +321,18 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return media information session created for this execution */ - public static MediaInformationSession getMediaInformationAsync(final String path, + public static MediaInformationSession getMediaInformationAsync(final long sessionId, final String path, final ExecuteCallback executeCallback, final LogCallback logCallback, final int waitTimeout) { - final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, logCallback); + final MediaInformationSession session = new MediaInformationSession(sessionId, new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, logCallback); FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout); @@ -320,15 +345,16 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return media information session created for this execution */ - public static MediaInformationSession getMediaInformationAsync(final String path, + public static MediaInformationSession getMediaInformationAsync(final long sessionId, final String path, final ExecuteCallback executeCallback, final ExecutorService executorService) { - final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback); + final MediaInformationSession session = new MediaInformationSession(sessionId, new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback); FFmpegKitConfig.asyncGetMediaInformationExecute(session, executorService, AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT); @@ -341,6 +367,7 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 @@ -348,12 +375,12 @@ public class FFprobeKit { * @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, + public static MediaInformationSession getMediaInformationAsync(final long sessionId, final String path, final ExecuteCallback executeCallback, final LogCallback logCallback, final ExecutorService executorService, final int waitTimeout) { - final MediaInformationSession session = new MediaInformationSession(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, logCallback); + final MediaInformationSession session = new MediaInformationSession(sessionId, new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}, executeCallback, logCallback); FFmpegKitConfig.asyncGetMediaInformationExecute(session, executorService, waitTimeout); @@ -381,17 +408,18 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return media information session created for this execution */ - public static MediaInformationSession getMediaInformationFromCommandAsync(final String command, + public static MediaInformationSession getMediaInformationFromCommandAsync(final long sessionId, final String command, final ExecuteCallback executeCallback, final LogCallback logCallback, final int waitTimeout) { - return getMediaInformationFromCommandArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, waitTimeout); + return getMediaInformationFromCommandArgumentsAsync(sessionId, FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, waitTimeout); } /** @@ -402,17 +430,18 @@ public class FFprobeKit { *

Note that this method returns immediately and does not wait the execution to complete. You must use an * {@jlink ExecuteCallback} if you want to be notified about the result. * + * @param sessionId provide session id or {@link FFprobeSession#AUTO_GENERATED_ID} * @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 * @return media information session created for this execution */ - private static MediaInformationSession getMediaInformationFromCommandArgumentsAsync(final String[] arguments, + private static MediaInformationSession getMediaInformationFromCommandArgumentsAsync(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final int waitTimeout) { - final MediaInformationSession session = new MediaInformationSession(arguments, executeCallback, logCallback); + final MediaInformationSession session = new MediaInformationSession(sessionId, arguments, executeCallback, logCallback); FFmpegKitConfig.getMediaInformationExecute(session, waitTimeout); diff --git a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeSession.java b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeSession.java index 43fe477..3d94fad 100644 --- a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeSession.java +++ b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/FFprobeSession.java @@ -30,7 +30,16 @@ public class FFprobeSession extends AbstractSession implements Session { * @param arguments command arguments */ public FFprobeSession(final String[] arguments) { - this(arguments, null); + this(-1, arguments); + } + + /** + * Builds a new FFprobe session. + * + * @param arguments command arguments + */ + public FFprobeSession(final long sessionId, final String[] arguments) { + this(sessionId, arguments, null); } /** @@ -39,36 +48,38 @@ public class FFprobeSession extends AbstractSession implements Session { * @param arguments command arguments * @param executeCallback session specific execute callback function */ - public FFprobeSession(final String[] arguments, final ExecuteCallback executeCallback) { - this(arguments, executeCallback, null); + public FFprobeSession(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback) { + this(sessionId, arguments, executeCallback, null); } /** - * Builds a new FFprobe session. + * Builds a new FFprobe session with provided session id. * + * @param sessionId provide session id or {@link #AUTO_GENERATED_ID} * @param arguments command arguments * @param executeCallback session specific execute callback function * @param logCallback session specific log callback function */ - public FFprobeSession(final String[] arguments, + public FFprobeSession(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback) { - this(arguments, executeCallback, logCallback, FFmpegKitConfig.getLogRedirectionStrategy()); + this(sessionId, arguments, executeCallback, logCallback, FFmpegKitConfig.getLogRedirectionStrategy()); } /** * Builds a new FFprobe session. * + * @param sessionId provide session id or {@link #AUTO_GENERATED_ID} * @param arguments command arguments * @param executeCallback session specific execute callback function * @param logCallback session specific log callback function * @param logRedirectionStrategy session specific log redirection strategy */ - public FFprobeSession(final String[] arguments, + public FFprobeSession(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback, final LogRedirectionStrategy logRedirectionStrategy) { - super(arguments, executeCallback, logCallback, logRedirectionStrategy); + super(sessionId, arguments, executeCallback, logCallback, logRedirectionStrategy); } @Override diff --git a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/MediaInformationSession.java b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/MediaInformationSession.java index 004e1dd..3041fe6 100644 --- a/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/MediaInformationSession.java +++ b/android/ffmpeg-kit-android-lib/src/main/java/com/arthenica/ffmpegkit/MediaInformationSession.java @@ -36,7 +36,16 @@ public class MediaInformationSession extends FFprobeSession implements Session { * @param arguments command arguments */ public MediaInformationSession(final String[] arguments) { - this(arguments, null); + this(-1, arguments); + } + + /** + * Creates a new media information session. + * + * @param arguments command arguments + */ + public MediaInformationSession(final long sessionId, final String[] arguments) { + this(sessionId, arguments, null); } /** @@ -45,8 +54,8 @@ public class MediaInformationSession extends FFprobeSession implements Session { * @param arguments command arguments * @param executeCallback session specific execute callback function */ - public MediaInformationSession(final String[] arguments, final ExecuteCallback executeCallback) { - this(arguments, executeCallback, null); + public MediaInformationSession(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback) { + this(sessionId, arguments, executeCallback, null); } /** @@ -56,8 +65,8 @@ public class MediaInformationSession extends FFprobeSession implements Session { * @param executeCallback session specific execute callback function * @param logCallback session specific log callback function */ - public MediaInformationSession(final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback) { - super(arguments, executeCallback, logCallback, LogRedirectionStrategy.NEVER_PRINT_LOGS); + public MediaInformationSession(final long sessionId, final String[] arguments, final ExecuteCallback executeCallback, final LogCallback logCallback) { + super(sessionId, arguments, executeCallback, logCallback, LogRedirectionStrategy.NEVER_PRINT_LOGS); } /** diff --git a/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFmpegSessionTest.java b/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFmpegSessionTest.java index b387225..13f9b02 100644 --- a/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFmpegSessionTest.java +++ b/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFmpegSessionTest.java @@ -27,6 +27,7 @@ import java.util.List; public class FFmpegSessionTest { private static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"}; + private static final long TEST_SESSION_ID = 120; @Test public void constructorTest() { @@ -100,7 +101,7 @@ public class FFmpegSessionTest { } }; - FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, executeCallback); + FFmpegSession ffmpegSession = new FFmpegSession(FFmpegSession.AUTO_GENERATED_ID, TEST_ARGUMENTS, executeCallback); // 1. getExecuteCallback Assert.assertEquals(ffmpegSession.getExecuteCallback(), executeCallback); @@ -184,7 +185,7 @@ public class FFmpegSessionTest { } }; - FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, executeCallback, logCallback, statisticsCallback); + FFmpegSession ffmpegSession = new FFmpegSession(FFmpegSession.AUTO_GENERATED_ID, TEST_ARGUMENTS, executeCallback, logCallback, statisticsCallback); // 1. getExecuteCallback Assert.assertEquals(ffmpegSession.getExecuteCallback(), executeCallback); @@ -245,6 +246,13 @@ public class FFmpegSessionTest { Assert.assertNull(ffmpegSession.getFuture()); } + @Test + public void providedSessionIdTest() { + FFmpegSession providedSession = new FFmpegSession(TEST_SESSION_ID, TEST_ARGUMENTS); + + Assert.assertEquals(TEST_SESSION_ID, providedSession.sessionId); + } + @Test public void getSessionIdTest() { FFmpegSession ffmpegSession1 = new FFmpegSession(TEST_ARGUMENTS); diff --git a/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFprobeSessionTest.java b/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFprobeSessionTest.java index 634e901..2e09187 100644 --- a/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFprobeSessionTest.java +++ b/android/ffmpeg-kit-android-lib/src/test/java/com/arthenica/ffmpegkit/FFprobeSessionTest.java @@ -27,6 +27,7 @@ import java.util.List; public class FFprobeSessionTest { private static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"}; + private static final long TEST_SESSION_ID = 120; @Test public void constructorTest() { @@ -97,7 +98,7 @@ public class FFprobeSessionTest { } }; - FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, executeCallback); + FFprobeSession ffprobeSession = new FFprobeSession(FFprobeSession.AUTO_GENERATED_ID, TEST_ARGUMENTS, executeCallback); // 1. getExecuteCallback Assert.assertEquals(ffprobeSession.getExecuteCallback(), executeCallback); @@ -171,7 +172,7 @@ public class FFprobeSessionTest { } }; - FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, executeCallback, logCallback); + FFprobeSession ffprobeSession = new FFprobeSession(FFprobeSession.AUTO_GENERATED_ID, TEST_ARGUMENTS, executeCallback, logCallback); // 1. getExecuteCallback Assert.assertEquals(ffprobeSession.getExecuteCallback(), executeCallback); @@ -229,6 +230,13 @@ public class FFprobeSessionTest { Assert.assertNull(ffprobeSession.getFuture()); } + @Test + public void providedSessionIdTest() { + FFprobeSession providedSession = new FFprobeSession(TEST_SESSION_ID, TEST_ARGUMENTS); + + Assert.assertEquals(TEST_SESSION_ID, providedSession.sessionId); + } + @Test public void getSessionIdTest() { FFprobeSession ffprobeSession1 = new FFprobeSession(TEST_ARGUMENTS);