parent
2fceb5f5ed
commit
4680721cef
@ -0,0 +1,183 @@ |
||||
/* |
||||
* Copyright (c) 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; |
||||
|
||||
import android.os.Build; |
||||
|
||||
import com.arthenica.smartexception.java.Exceptions; |
||||
|
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Collections; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p>Responsible of loading native libraries. |
||||
*/ |
||||
public class NativeLoader { |
||||
|
||||
static final String[] FFMPEG_LIBRARIES = {"avutil", "swscale", "swresample", "avcodec", "avformat", "avfilter", "avdevice"}; |
||||
|
||||
static boolean isTestModeDisabled() { |
||||
return (System.getProperty("enable.ffmpeg.kit.test.mode") == null); |
||||
} |
||||
|
||||
private static void loadLibrary(final String libraryName) { |
||||
if (isTestModeDisabled()) { |
||||
System.loadLibrary(libraryName); |
||||
} |
||||
} |
||||
|
||||
private static List<String> loadExternalLibraries() { |
||||
if (isTestModeDisabled()) { |
||||
return Packages.getExternalLibraries(); |
||||
} else { |
||||
return Collections.emptyList(); |
||||
} |
||||
} |
||||
|
||||
private static String loadNativeAbi() { |
||||
if (isTestModeDisabled()) { |
||||
return AbiDetect.getNativeAbi(); |
||||
} else { |
||||
return Abi.ABI_X86_64.getName(); |
||||
} |
||||
} |
||||
|
||||
static String loadAbi() { |
||||
if (isTestModeDisabled()) { |
||||
return AbiDetect.getAbi(); |
||||
} else { |
||||
return Abi.ABI_X86_64.getName(); |
||||
} |
||||
} |
||||
|
||||
static String loadPackageName() { |
||||
if (isTestModeDisabled()) { |
||||
return Packages.getPackageName(); |
||||
} else { |
||||
return "test"; |
||||
} |
||||
} |
||||
|
||||
static String loadVersion() { |
||||
final String version = "4.4"; |
||||
|
||||
if (isTestModeDisabled()) { |
||||
return FFmpegKitConfig.getVersion(); |
||||
} else if (loadIsLTSBuild()) { |
||||
return String.format("%s-lts", version); |
||||
} else { |
||||
return version; |
||||
} |
||||
} |
||||
|
||||
static boolean loadIsLTSBuild() { |
||||
if (isTestModeDisabled()) { |
||||
return AbiDetect.isNativeLTSBuild(); |
||||
} else { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
static int loadLogLevel() { |
||||
if (isTestModeDisabled()) { |
||||
return FFmpegKitConfig.getNativeLogLevel(); |
||||
} else { |
||||
return Level.AV_LOG_DEBUG.getValue(); |
||||
} |
||||
} |
||||
|
||||
static String loadBuildDate() { |
||||
if (isTestModeDisabled()) { |
||||
return FFmpegKitConfig.getBuildDate(); |
||||
} else { |
||||
return new SimpleDateFormat("yyyyMMdd").format(new Date()); |
||||
} |
||||
} |
||||
|
||||
static void enableRedirection() { |
||||
if (isTestModeDisabled()) { |
||||
FFmpegKitConfig.enableRedirection(); |
||||
} |
||||
} |
||||
|
||||
static void loadFFmpegKitAbiDetect() { |
||||
loadLibrary("ffmpegkit_abidetect"); |
||||
} |
||||
|
||||
static boolean loadFFmpeg() { |
||||
boolean nativeFFmpegLoaded = false; |
||||
boolean nativeFFmpegTriedAndFailed = false; |
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
||||
|
||||
/* LOADING LINKED LIBRARIES MANUALLY ON API < 21 */ |
||||
final List<String> externalLibrariesEnabled = loadExternalLibraries(); |
||||
if (externalLibrariesEnabled.contains("tesseract") || externalLibrariesEnabled.contains("x265") || externalLibrariesEnabled.contains("snappy") || externalLibrariesEnabled.contains("openh264") || externalLibrariesEnabled.contains("rubberband")) { |
||||
loadLibrary("c++_shared"); |
||||
} |
||||
|
||||
if (AbiDetect.ARM_V7A.equals(loadNativeAbi())) { |
||||
try { |
||||
for (String ffmpegLibrary : FFMPEG_LIBRARIES) { |
||||
loadLibrary(ffmpegLibrary + "_neon"); |
||||
} |
||||
nativeFFmpegLoaded = true; |
||||
} catch (final UnsatisfiedLinkError e) { |
||||
android.util.Log.i(FFmpegKitConfig.TAG, String.format("NEON supported armeabi-v7a ffmpeg library not found. Loading default armeabi-v7a library.%s", Exceptions.getStackTraceString(e))); |
||||
nativeFFmpegTriedAndFailed = true; |
||||
} |
||||
} |
||||
|
||||
if (!nativeFFmpegLoaded) { |
||||
for (String ffmpegLibrary : FFMPEG_LIBRARIES) { |
||||
loadLibrary(ffmpegLibrary); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nativeFFmpegTriedAndFailed; |
||||
} |
||||
|
||||
static void loadFFmpegKit(final boolean nativeFFmpegTriedAndFailed) { |
||||
boolean nativeFFmpegKitLoaded = false; |
||||
|
||||
if (!nativeFFmpegTriedAndFailed && AbiDetect.ARM_V7A.equals(loadNativeAbi())) { |
||||
try { |
||||
|
||||
/* |
||||
* THE TRY TO LOAD ARM-V7A-NEON FIRST. IF NOT LOAD DEFAULT ARM-V7A |
||||
*/ |
||||
|
||||
loadLibrary("ffmpegkit_armv7a_neon"); |
||||
nativeFFmpegKitLoaded = true; |
||||
AbiDetect.setArmV7aNeonLoaded(); |
||||
} catch (final UnsatisfiedLinkError e) { |
||||
android.util.Log.i(FFmpegKitConfig.TAG, String.format("NEON supported armeabi-v7a ffmpegkit library not found. Loading default armeabi-v7a library.%s", Exceptions.getStackTraceString(e))); |
||||
} |
||||
} |
||||
|
||||
if (!nativeFFmpegKitLoaded) { |
||||
loadLibrary("ffmpegkit"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,44 +0,0 @@ |
||||
/* |
||||
* Copyright (c) 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; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class AbstractSessionTest { |
||||
|
||||
private static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"}; |
||||
|
||||
@Test |
||||
public void getLogsAsStringTest() { |
||||
final FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, null, null, null, LogRedirectionStrategy.ALWAYS_PRINT_LOGS); |
||||
|
||||
String logMessage1 = "i am log one"; |
||||
String logMessage2 = "i am log two"; |
||||
|
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage1)); |
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage2)); |
||||
|
||||
String logsAsString = ffprobeSession.getLogsAsString(); |
||||
|
||||
Assert.assertEquals(logMessage1 + logMessage2, logsAsString); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,350 @@ |
||||
/* |
||||
* Copyright (c) 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; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class FFmpegSessionTest { |
||||
|
||||
static { |
||||
System.setProperty("enable.ffmpeg.kit.test.mode", "true"); |
||||
} |
||||
|
||||
private static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"}; |
||||
|
||||
@Test |
||||
public void constructorTest() { |
||||
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
// 1. getExecuteCallback
|
||||
Assert.assertNull(ffmpegSession.getExecuteCallback()); |
||||
|
||||
// 2. getLogCallback
|
||||
Assert.assertNull(ffmpegSession.getLogCallback()); |
||||
|
||||
// 3. getStatisticsCallback
|
||||
Assert.assertNull(ffmpegSession.getStatisticsCallback()); |
||||
|
||||
// 4. getSessionId
|
||||
Assert.assertTrue(ffmpegSession.getSessionId() > 0); |
||||
|
||||
// 5. getCreateTime
|
||||
Assert.assertTrue(ffmpegSession.getCreateTime().getTime() <= System.currentTimeMillis()); |
||||
|
||||
// 6. getStartTime
|
||||
Assert.assertNull(ffmpegSession.getStartTime()); |
||||
|
||||
// 7. getEndTime
|
||||
Assert.assertNull(ffmpegSession.getEndTime()); |
||||
|
||||
// 8. getDuration
|
||||
Assert.assertEquals(0, ffmpegSession.getDuration()); |
||||
|
||||
// 9. getArguments
|
||||
Assert.assertArrayEquals(TEST_ARGUMENTS, ffmpegSession.getArguments()); |
||||
|
||||
// 10. getCommand
|
||||
StringBuilder commandBuilder = new StringBuilder(); |
||||
for (int i = 0; i < TEST_ARGUMENTS.length; i++) { |
||||
if (i > 0) { |
||||
commandBuilder.append(" "); |
||||
} |
||||
commandBuilder.append(TEST_ARGUMENTS[i]); |
||||
} |
||||
Assert.assertEquals(commandBuilder.toString(), ffmpegSession.getCommand()); |
||||
|
||||
// 11. getLogs
|
||||
Assert.assertEquals(0, ffmpegSession.getLogs().size()); |
||||
|
||||
// 12. getLogsAsString
|
||||
Assert.assertEquals("", ffmpegSession.getLogsAsString()); |
||||
|
||||
// 13. getState
|
||||
Assert.assertEquals(SessionState.CREATED, ffmpegSession.getState()); |
||||
|
||||
// 14. getState
|
||||
Assert.assertNull(ffmpegSession.getReturnCode()); |
||||
|
||||
// 15. getFailStackTrace
|
||||
Assert.assertNull(ffmpegSession.getFailStackTrace()); |
||||
|
||||
// 16. getLogRedirectionStrategy
|
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffmpegSession.getLogRedirectionStrategy()); |
||||
|
||||
// 17. getFuture
|
||||
Assert.assertNull(ffmpegSession.getFuture()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorTest2() { |
||||
ExecuteCallback executeCallback = new ExecuteCallback() { |
||||
|
||||
@Override |
||||
public void apply(Session session) { |
||||
} |
||||
}; |
||||
|
||||
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, executeCallback); |
||||
|
||||
// 1. getExecuteCallback
|
||||
Assert.assertEquals(ffmpegSession.getExecuteCallback(), executeCallback); |
||||
|
||||
// 2. getLogCallback
|
||||
Assert.assertNull(ffmpegSession.getLogCallback()); |
||||
|
||||
// 3. getStatisticsCallback
|
||||
Assert.assertNull(ffmpegSession.getStatisticsCallback()); |
||||
|
||||
// 4. getSessionId
|
||||
Assert.assertTrue(ffmpegSession.getSessionId() > 0); |
||||
|
||||
// 5. getCreateTime
|
||||
Assert.assertTrue(ffmpegSession.getCreateTime().getTime() <= System.currentTimeMillis()); |
||||
|
||||
// 6. getStartTime
|
||||
Assert.assertNull(ffmpegSession.getStartTime()); |
||||
|
||||
// 7. getEndTime
|
||||
Assert.assertNull(ffmpegSession.getEndTime()); |
||||
|
||||
// 8. getDuration
|
||||
Assert.assertEquals(0, ffmpegSession.getDuration()); |
||||
|
||||
// 9. getArguments
|
||||
Assert.assertArrayEquals(TEST_ARGUMENTS, ffmpegSession.getArguments()); |
||||
|
||||
// 10. getCommand
|
||||
StringBuilder commandBuilder = new StringBuilder(); |
||||
for (int i = 0; i < TEST_ARGUMENTS.length; i++) { |
||||
if (i > 0) { |
||||
commandBuilder.append(" "); |
||||
} |
||||
commandBuilder.append(TEST_ARGUMENTS[i]); |
||||
} |
||||
Assert.assertEquals(commandBuilder.toString(), ffmpegSession.getCommand()); |
||||
|
||||
// 11. getLogs
|
||||
Assert.assertEquals(0, ffmpegSession.getLogs().size()); |
||||
|
||||
// 12. getLogsAsString
|
||||
Assert.assertEquals("", ffmpegSession.getLogsAsString()); |
||||
|
||||
// 13. getState
|
||||
Assert.assertEquals(SessionState.CREATED, ffmpegSession.getState()); |
||||
|
||||
// 14. getState
|
||||
Assert.assertNull(ffmpegSession.getReturnCode()); |
||||
|
||||
// 15. getFailStackTrace
|
||||
Assert.assertNull(ffmpegSession.getFailStackTrace()); |
||||
|
||||
// 16. getLogRedirectionStrategy
|
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffmpegSession.getLogRedirectionStrategy()); |
||||
|
||||
// 17. getFuture
|
||||
Assert.assertNull(ffmpegSession.getFuture()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorTest3() { |
||||
ExecuteCallback executeCallback = new ExecuteCallback() { |
||||
|
||||
@Override |
||||
public void apply(Session session) { |
||||
} |
||||
}; |
||||
|
||||
LogCallback logCallback = new LogCallback() { |
||||
@Override |
||||
public void apply(Log log) { |
||||
|
||||
} |
||||
}; |
||||
|
||||
StatisticsCallback statisticsCallback = new StatisticsCallback() { |
||||
@Override |
||||
public void apply(Statistics statistics) { |
||||
|
||||
} |
||||
}; |
||||
|
||||
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS, executeCallback, logCallback, statisticsCallback); |
||||
|
||||
// 1. getExecuteCallback
|
||||
Assert.assertEquals(ffmpegSession.getExecuteCallback(), executeCallback); |
||||
|
||||
// 2. getLogCallback
|
||||
Assert.assertEquals(ffmpegSession.getLogCallback(), logCallback); |
||||
|
||||
// 3. getStatisticsCallback
|
||||
Assert.assertEquals(ffmpegSession.getStatisticsCallback(), statisticsCallback); |
||||
|
||||
// 4. getSessionId
|
||||
Assert.assertTrue(ffmpegSession.getSessionId() > 0); |
||||
|
||||
// 5. getCreateTime
|
||||
Assert.assertTrue(ffmpegSession.getCreateTime().getTime() <= System.currentTimeMillis()); |
||||
|
||||
// 6. getStartTime
|
||||
Assert.assertNull(ffmpegSession.getStartTime()); |
||||
|
||||
// 7. getEndTime
|
||||
Assert.assertNull(ffmpegSession.getEndTime()); |
||||
|
||||
// 8. getDuration
|
||||
Assert.assertEquals(0, ffmpegSession.getDuration()); |
||||
|
||||
// 9. getArguments
|
||||
Assert.assertArrayEquals(TEST_ARGUMENTS, ffmpegSession.getArguments()); |
||||
|
||||
// 10. getCommand
|
||||
StringBuilder commandBuilder = new StringBuilder(); |
||||
for (int i = 0; i < TEST_ARGUMENTS.length; i++) { |
||||
if (i > 0) { |
||||
commandBuilder.append(" "); |
||||
} |
||||
commandBuilder.append(TEST_ARGUMENTS[i]); |
||||
} |
||||
Assert.assertEquals(commandBuilder.toString(), ffmpegSession.getCommand()); |
||||
|
||||
// 11. getLogs
|
||||
Assert.assertEquals(0, ffmpegSession.getLogs().size()); |
||||
|
||||
// 12. getLogsAsString
|
||||
Assert.assertEquals("", ffmpegSession.getLogsAsString()); |
||||
|
||||
// 13. getState
|
||||
Assert.assertEquals(SessionState.CREATED, ffmpegSession.getState()); |
||||
|
||||
// 14. getState
|
||||
Assert.assertNull(ffmpegSession.getReturnCode()); |
||||
|
||||
// 15. getFailStackTrace
|
||||
Assert.assertNull(ffmpegSession.getFailStackTrace()); |
||||
|
||||
// 16. getLogRedirectionStrategy
|
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffmpegSession.getLogRedirectionStrategy()); |
||||
|
||||
// 17. getFuture
|
||||
Assert.assertNull(ffmpegSession.getFuture()); |
||||
} |
||||
|
||||
@Test |
||||
public void getSessionIdTest() { |
||||
FFmpegSession ffmpegSession1 = new FFmpegSession(TEST_ARGUMENTS); |
||||
FFmpegSession ffmpegSession2 = new FFmpegSession(TEST_ARGUMENTS); |
||||
FFmpegSession ffmpegSession3 = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
Assert.assertTrue(ffmpegSession3.getSessionId() > ffmpegSession2.getSessionId()); |
||||
Assert.assertTrue(ffmpegSession3.getSessionId() > ffmpegSession1.getSessionId()); |
||||
Assert.assertTrue(ffmpegSession2.getSessionId() > ffmpegSession1.getSessionId()); |
||||
|
||||
Assert.assertTrue(ffmpegSession1.getSessionId() > 0); |
||||
Assert.assertTrue(ffmpegSession2.getSessionId() > 0); |
||||
Assert.assertTrue(ffmpegSession3.getSessionId() > 0); |
||||
} |
||||
|
||||
@Test |
||||
public void getLogs() { |
||||
final FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
String logMessage1 = "i am log one"; |
||||
String logMessage2 = "i am log two"; |
||||
String logMessage3 = "i am log three"; |
||||
|
||||
ffmpegSession.addLog(new Log(ffmpegSession.getSessionId(), Level.AV_LOG_INFO, logMessage1)); |
||||
ffmpegSession.addLog(new Log(ffmpegSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage2)); |
||||
ffmpegSession.addLog(new Log(ffmpegSession.getSessionId(), Level.AV_LOG_TRACE, logMessage3)); |
||||
|
||||
List<Log> logs = ffmpegSession.getLogs(); |
||||
|
||||
Assert.assertEquals(3, logs.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getLogsAsStringTest() { |
||||
final FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
String logMessage1 = "i am log one"; |
||||
String logMessage2 = "i am log two"; |
||||
|
||||
ffmpegSession.addLog(new Log(ffmpegSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage1)); |
||||
ffmpegSession.addLog(new Log(ffmpegSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage2)); |
||||
|
||||
String logsAsString = ffmpegSession.getLogsAsString(); |
||||
|
||||
Assert.assertEquals(logMessage1 + logMessage2, logsAsString); |
||||
} |
||||
|
||||
@Test |
||||
public void getLogRedirectionStrategy() { |
||||
FFmpegKitConfig.setLogRedirectionStrategy(LogRedirectionStrategy.NEVER_PRINT_LOGS); |
||||
|
||||
final FFmpegSession ffmpegSession1 = new FFmpegSession(TEST_ARGUMENTS); |
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffmpegSession1.getLogRedirectionStrategy()); |
||||
|
||||
FFmpegKitConfig.setLogRedirectionStrategy(LogRedirectionStrategy.PRINT_LOGS_WHEN_SESSION_CALLBACK_NOT_DEFINED); |
||||
|
||||
final FFmpegSession ffmpegSession2 = new FFmpegSession(TEST_ARGUMENTS); |
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffmpegSession2.getLogRedirectionStrategy()); |
||||
} |
||||
|
||||
@Test |
||||
public void startRunningTest() { |
||||
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
ffmpegSession.startRunning(); |
||||
|
||||
Assert.assertEquals(SessionState.RUNNING, ffmpegSession.getState()); |
||||
Assert.assertTrue(ffmpegSession.getStartTime().getTime() <= System.currentTimeMillis()); |
||||
Assert.assertTrue(ffmpegSession.getCreateTime().getTime() <= ffmpegSession.getStartTime().getTime()); |
||||
} |
||||
|
||||
@Test |
||||
public void completeTest() { |
||||
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
ffmpegSession.startRunning(); |
||||
ffmpegSession.complete(new ReturnCode(100)); |
||||
|
||||
Assert.assertEquals(SessionState.COMPLETED, ffmpegSession.getState()); |
||||
Assert.assertEquals(100, ffmpegSession.getReturnCode().getValue()); |
||||
Assert.assertTrue(ffmpegSession.getStartTime().getTime() <= ffmpegSession.getEndTime().getTime()); |
||||
Assert.assertTrue(ffmpegSession.getDuration() >= 0); |
||||
} |
||||
|
||||
@Test |
||||
public void failTest() { |
||||
FFmpegSession ffmpegSession = new FFmpegSession(TEST_ARGUMENTS); |
||||
|
||||
ffmpegSession.startRunning(); |
||||
ffmpegSession.fail(new Exception("")); |
||||
|
||||
Assert.assertEquals(SessionState.FAILED, ffmpegSession.getState()); |
||||
Assert.assertNull(ffmpegSession.getReturnCode()); |
||||
Assert.assertTrue(ffmpegSession.getStartTime().getTime() <= ffmpegSession.getEndTime().getTime()); |
||||
Assert.assertTrue(ffmpegSession.getDuration() >= 0); |
||||
Assert.assertNotNull(ffmpegSession.getFailStackTrace()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,334 @@ |
||||
/* |
||||
* Copyright (c) 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; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class FFprobeSessionTest { |
||||
|
||||
static { |
||||
System.setProperty("enable.ffmpeg.kit.test.mode", "true"); |
||||
} |
||||
|
||||
private static final String[] TEST_ARGUMENTS = new String[]{"argument1", "argument2"}; |
||||
|
||||
@Test |
||||
public void constructorTest() { |
||||
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
// 1. getExecuteCallback
|
||||
Assert.assertNull(ffprobeSession.getExecuteCallback()); |
||||
|
||||
// 2. getLogCallback
|
||||
Assert.assertNull(ffprobeSession.getLogCallback()); |
||||
|
||||
// 3. getSessionId
|
||||
Assert.assertTrue(ffprobeSession.getSessionId() > 0); |
||||
|
||||
// 4. getCreateTime
|
||||
Assert.assertTrue(ffprobeSession.getCreateTime().getTime() <= System.currentTimeMillis()); |
||||
|
||||
// 5. getStartTime
|
||||
Assert.assertNull(ffprobeSession.getStartTime()); |
||||
|
||||
// 6. getEndTime
|
||||
Assert.assertNull(ffprobeSession.getEndTime()); |
||||
|
||||
// 7. getDuration
|
||||
Assert.assertEquals(0, ffprobeSession.getDuration()); |
||||
|
||||
// 8. getArguments
|
||||
Assert.assertArrayEquals(TEST_ARGUMENTS, ffprobeSession.getArguments()); |
||||
|
||||
// 9. getCommand
|
||||
StringBuilder commandBuilder = new StringBuilder(); |
||||
for (int i = 0; i < TEST_ARGUMENTS.length; i++) { |
||||
if (i > 0) { |
||||
commandBuilder.append(" "); |
||||
} |
||||
commandBuilder.append(TEST_ARGUMENTS[i]); |
||||
} |
||||
Assert.assertEquals(commandBuilder.toString(), ffprobeSession.getCommand()); |
||||
|
||||
// 10. getLogs
|
||||
Assert.assertEquals(0, ffprobeSession.getLogs().size()); |
||||
|
||||
// 11. getLogsAsString
|
||||
Assert.assertEquals("", ffprobeSession.getLogsAsString()); |
||||
|
||||
// 12. getState
|
||||
Assert.assertEquals(SessionState.CREATED, ffprobeSession.getState()); |
||||
|
||||
// 13. getState
|
||||
Assert.assertNull(ffprobeSession.getReturnCode()); |
||||
|
||||
// 14. getFailStackTrace
|
||||
Assert.assertNull(ffprobeSession.getFailStackTrace()); |
||||
|
||||
// 15. getLogRedirectionStrategy
|
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffprobeSession.getLogRedirectionStrategy()); |
||||
|
||||
// 16. getFuture
|
||||
Assert.assertNull(ffprobeSession.getFuture()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorTest2() { |
||||
ExecuteCallback executeCallback = new ExecuteCallback() { |
||||
|
||||
@Override |
||||
public void apply(Session session) { |
||||
} |
||||
}; |
||||
|
||||
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, executeCallback); |
||||
|
||||
// 1. getExecuteCallback
|
||||
Assert.assertEquals(ffprobeSession.getExecuteCallback(), executeCallback); |
||||
|
||||
// 2. getLogCallback
|
||||
Assert.assertNull(ffprobeSession.getLogCallback()); |
||||
|
||||
// 3. getSessionId
|
||||
Assert.assertTrue(ffprobeSession.getSessionId() > 0); |
||||
|
||||
// 4. getCreateTime
|
||||
Assert.assertTrue(ffprobeSession.getCreateTime().getTime() <= System.currentTimeMillis()); |
||||
|
||||
// 5. getStartTime
|
||||
Assert.assertNull(ffprobeSession.getStartTime()); |
||||
|
||||
// 6. getEndTime
|
||||
Assert.assertNull(ffprobeSession.getEndTime()); |
||||
|
||||
// 7. getDuration
|
||||
Assert.assertEquals(0, ffprobeSession.getDuration()); |
||||
|
||||
// 8. getArguments
|
||||
Assert.assertArrayEquals(TEST_ARGUMENTS, ffprobeSession.getArguments()); |
||||
|
||||
// 9. getCommand
|
||||
StringBuilder commandBuilder = new StringBuilder(); |
||||
for (int i = 0; i < TEST_ARGUMENTS.length; i++) { |
||||
if (i > 0) { |
||||
commandBuilder.append(" "); |
||||
} |
||||
commandBuilder.append(TEST_ARGUMENTS[i]); |
||||
} |
||||
Assert.assertEquals(commandBuilder.toString(), ffprobeSession.getCommand()); |
||||
|
||||
// 10. getLogs
|
||||
Assert.assertEquals(0, ffprobeSession.getLogs().size()); |
||||
|
||||
// 11. getLogsAsString
|
||||
Assert.assertEquals("", ffprobeSession.getLogsAsString()); |
||||
|
||||
// 12. getState
|
||||
Assert.assertEquals(SessionState.CREATED, ffprobeSession.getState()); |
||||
|
||||
// 13. getState
|
||||
Assert.assertNull(ffprobeSession.getReturnCode()); |
||||
|
||||
// 14. getFailStackTrace
|
||||
Assert.assertNull(ffprobeSession.getFailStackTrace()); |
||||
|
||||
// 15. getLogRedirectionStrategy
|
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffprobeSession.getLogRedirectionStrategy()); |
||||
|
||||
// 16. getFuture
|
||||
Assert.assertNull(ffprobeSession.getFuture()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorTest3() { |
||||
ExecuteCallback executeCallback = new ExecuteCallback() { |
||||
|
||||
@Override |
||||
public void apply(Session session) { |
||||
} |
||||
}; |
||||
|
||||
LogCallback logCallback = new LogCallback() { |
||||
@Override |
||||
public void apply(Log log) { |
||||
|
||||
} |
||||
}; |
||||
|
||||
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS, executeCallback, logCallback); |
||||
|
||||
// 1. getExecuteCallback
|
||||
Assert.assertEquals(ffprobeSession.getExecuteCallback(), executeCallback); |
||||
|
||||
// 2. getLogCallback
|
||||
Assert.assertEquals(ffprobeSession.getLogCallback(), logCallback); |
||||
|
||||
// 3. getSessionId
|
||||
Assert.assertTrue(ffprobeSession.getSessionId() > 0); |
||||
|
||||
// 4. getCreateTime
|
||||
Assert.assertTrue(ffprobeSession.getCreateTime().getTime() <= System.currentTimeMillis()); |
||||
|
||||
// 5. getStartTime
|
||||
Assert.assertNull(ffprobeSession.getStartTime()); |
||||
|
||||
// 6. getEndTime
|
||||
Assert.assertNull(ffprobeSession.getEndTime()); |
||||
|
||||
// 7. getDuration
|
||||
Assert.assertEquals(0, ffprobeSession.getDuration()); |
||||
|
||||
// 8. getArguments
|
||||
Assert.assertArrayEquals(TEST_ARGUMENTS, ffprobeSession.getArguments()); |
||||
|
||||
// 9. getCommand
|
||||
StringBuilder commandBuilder = new StringBuilder(); |
||||
for (int i = 0; i < TEST_ARGUMENTS.length; i++) { |
||||
if (i > 0) { |
||||
commandBuilder.append(" "); |
||||
} |
||||
commandBuilder.append(TEST_ARGUMENTS[i]); |
||||
} |
||||
Assert.assertEquals(commandBuilder.toString(), ffprobeSession.getCommand()); |
||||
|
||||
// 10. getLogs
|
||||
Assert.assertEquals(0, ffprobeSession.getLogs().size()); |
||||
|
||||
// 11. getLogsAsString
|
||||
Assert.assertEquals("", ffprobeSession.getLogsAsString()); |
||||
|
||||
// 12. getState
|
||||
Assert.assertEquals(SessionState.CREATED, ffprobeSession.getState()); |
||||
|
||||
// 13. getState
|
||||
Assert.assertNull(ffprobeSession.getReturnCode()); |
||||
|
||||
// 14. getFailStackTrace
|
||||
Assert.assertNull(ffprobeSession.getFailStackTrace()); |
||||
|
||||
// 15. getLogRedirectionStrategy
|
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffprobeSession.getLogRedirectionStrategy()); |
||||
|
||||
// 16. getFuture
|
||||
Assert.assertNull(ffprobeSession.getFuture()); |
||||
} |
||||
|
||||
@Test |
||||
public void getSessionIdTest() { |
||||
FFprobeSession ffprobeSession1 = new FFprobeSession(TEST_ARGUMENTS); |
||||
FFprobeSession ffprobeSession2 = new FFprobeSession(TEST_ARGUMENTS); |
||||
FFprobeSession ffprobeSession3 = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
Assert.assertTrue(ffprobeSession3.getSessionId() > ffprobeSession2.getSessionId()); |
||||
Assert.assertTrue(ffprobeSession3.getSessionId() > ffprobeSession1.getSessionId()); |
||||
Assert.assertTrue(ffprobeSession2.getSessionId() > ffprobeSession1.getSessionId()); |
||||
|
||||
Assert.assertTrue(ffprobeSession1.getSessionId() > 0); |
||||
Assert.assertTrue(ffprobeSession2.getSessionId() > 0); |
||||
Assert.assertTrue(ffprobeSession3.getSessionId() > 0); |
||||
} |
||||
|
||||
@Test |
||||
public void getLogs() { |
||||
final FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
String logMessage1 = "i am log one"; |
||||
String logMessage2 = "i am log two"; |
||||
String logMessage3 = "i am log three"; |
||||
|
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_INFO, logMessage1)); |
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage2)); |
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_TRACE, logMessage3)); |
||||
|
||||
List<Log> logs = ffprobeSession.getLogs(); |
||||
|
||||
Assert.assertEquals(3, logs.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getLogsAsStringTest() { |
||||
final FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
String logMessage1 = "i am log one"; |
||||
String logMessage2 = "i am log two"; |
||||
|
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage1)); |
||||
ffprobeSession.addLog(new Log(ffprobeSession.getSessionId(), Level.AV_LOG_DEBUG, logMessage2)); |
||||
|
||||
String logsAsString = ffprobeSession.getLogsAsString(); |
||||
|
||||
Assert.assertEquals(logMessage1 + logMessage2, logsAsString); |
||||
} |
||||
|
||||
@Test |
||||
public void getLogRedirectionStrategy() { |
||||
FFmpegKitConfig.setLogRedirectionStrategy(LogRedirectionStrategy.NEVER_PRINT_LOGS); |
||||
|
||||
final FFprobeSession ffprobeSession1 = new FFprobeSession(TEST_ARGUMENTS); |
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffprobeSession1.getLogRedirectionStrategy()); |
||||
|
||||
FFmpegKitConfig.setLogRedirectionStrategy(LogRedirectionStrategy.PRINT_LOGS_WHEN_SESSION_CALLBACK_NOT_DEFINED); |
||||
|
||||
final FFprobeSession ffprobeSession2 = new FFprobeSession(TEST_ARGUMENTS); |
||||
Assert.assertEquals(FFmpegKitConfig.getLogRedirectionStrategy(), ffprobeSession2.getLogRedirectionStrategy()); |
||||
} |
||||
|
||||
@Test |
||||
public void startRunningTest() { |
||||
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
ffprobeSession.startRunning(); |
||||
|
||||
Assert.assertEquals(SessionState.RUNNING, ffprobeSession.getState()); |
||||
Assert.assertTrue(ffprobeSession.getStartTime().getTime() <= System.currentTimeMillis()); |
||||
Assert.assertTrue(ffprobeSession.getCreateTime().getTime() <= ffprobeSession.getStartTime().getTime()); |
||||
} |
||||
|
||||
@Test |
||||
public void completeTest() { |
||||
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
ffprobeSession.startRunning(); |
||||
ffprobeSession.complete(new ReturnCode(100)); |
||||
|
||||
Assert.assertEquals(SessionState.COMPLETED, ffprobeSession.getState()); |
||||
Assert.assertEquals(100, ffprobeSession.getReturnCode().getValue()); |
||||
Assert.assertTrue(ffprobeSession.getStartTime().getTime() <= ffprobeSession.getEndTime().getTime()); |
||||
Assert.assertTrue(ffprobeSession.getDuration() >= 0); |
||||
} |
||||
|
||||
@Test |
||||
public void failTest() { |
||||
FFprobeSession ffprobeSession = new FFprobeSession(TEST_ARGUMENTS); |
||||
|
||||
ffprobeSession.startRunning(); |
||||
ffprobeSession.fail(new Exception("")); |
||||
|
||||
Assert.assertEquals(SessionState.FAILED, ffprobeSession.getState()); |
||||
Assert.assertNull(ffprobeSession.getReturnCode()); |
||||
Assert.assertTrue(ffprobeSession.getStartTime().getTime() <= ffprobeSession.getEndTime().getTime()); |
||||
Assert.assertTrue(ffprobeSession.getDuration() >= 0); |
||||
Assert.assertNotNull(ffprobeSession.getFailStackTrace()); |
||||
} |
||||
|
||||
} |
||||
@ -1,4 +1,2 @@ |
||||
include ':ffmpeg-kit-android-lib' |
||||
include ':ffmpeg-kit' |
||||
project(':ffmpeg-kit').projectDir = new File('..') |
||||
rootProject.name = 'ffmpeg-kit-android' |
||||
|
||||
@ -0,0 +1,56 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_ABSTRACT_SESSION_H |
||||
#define FFMPEG_KIT_ABSTRACT_SESSION_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
#import "Session.h" |
||||
|
||||
/**
|
||||
* Defines how long default "getAll" methods wait, in milliseconds. |
||||
*/ |
||||
extern int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit; |
||||
|
||||
/**
|
||||
* Abstract session implementation which includes common features shared by <code>FFmpeg</code> |
||||
* and <code>FFprobe</code> sessions. |
||||
*/ |
||||
@interface AbstractSession : NSObject<Session> |
||||
|
||||
/**
|
||||
* Creates a new abstract session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
* @param logDelegate session specific log delegate |
||||
* @param logRedirectionStrategy session specific log redirection strategy |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy; |
||||
|
||||
/**
|
||||
* Waits for all asynchronous messages to be transmitted until the given timeout. |
||||
* |
||||
* @param timeout wait timeout in milliseconds |
||||
*/ |
||||
- (void)waitForAsynchronousMessagesInTransmit:(int)timeout; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_ABSTRACT_SESSION_H
|
||||
@ -0,0 +1,235 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "AbstractSession.h" |
||||
#import "AtomicLong.h" |
||||
#import "ExecuteDelegate.h" |
||||
#import "FFmpegKit.h" |
||||
#import "FFmpegKitConfig.h" |
||||
#import "LogDelegate.h" |
||||
#import "ReturnCode.h" |
||||
|
||||
int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit = 5000; |
||||
|
||||
static AtomicLong *sessionIdGenerator = nil; |
||||
|
||||
@implementation AbstractSession { |
||||
long _sessionId; |
||||
id<ExecuteDelegate> _executeDelegate; |
||||
id<LogDelegate> _logDelegate; |
||||
NSDate* _createTime; |
||||
NSDate* _startTime; |
||||
NSDate* _endTime; |
||||
NSArray* _arguments; |
||||
NSMutableArray* _logs; |
||||
NSRecursiveLock* _logsLock; |
||||
SessionState _state; |
||||
ReturnCode* _returnCode; |
||||
NSString* _failStackTrace; |
||||
LogRedirectionStrategy _logRedirectionStrategy; |
||||
} |
||||
|
||||
+ (void)initialize { |
||||
sessionIdGenerator = [[AtomicLong alloc] initWithValue:1]; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy { |
||||
self = [super init]; |
||||
if (self) { |
||||
_sessionId = [sessionIdGenerator incrementAndGet]; |
||||
_executeDelegate = executeDelegate; |
||||
_logDelegate = logDelegate; |
||||
_createTime = [NSDate date]; |
||||
_startTime = nil; |
||||
_endTime = nil; |
||||
_arguments = arguments; |
||||
_logs = [[NSMutableArray alloc] init]; |
||||
_logsLock = [[NSRecursiveLock alloc] init]; |
||||
_state = SessionStateCreated; |
||||
_returnCode = nil; |
||||
_failStackTrace = nil; |
||||
_logRedirectionStrategy = logRedirectionStrategy; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (id<ExecuteDelegate>)getExecuteDelegate { |
||||
return _executeDelegate; |
||||
} |
||||
|
||||
- (id<LogDelegate>)getLogDelegate { |
||||
return _logDelegate; |
||||
} |
||||
|
||||
- (long)getSessionId { |
||||
return _sessionId; |
||||
} |
||||
|
||||
- (NSDate*)getCreateTime { |
||||
return _createTime; |
||||
} |
||||
|
||||
- (NSDate*)getStartTime { |
||||
return _startTime; |
||||
} |
||||
|
||||
- (NSDate*)getEndTime { |
||||
return _endTime; |
||||
} |
||||
|
||||
- (long)getDuration { |
||||
NSDate* startTime = _startTime; |
||||
NSDate* endTime = _endTime; |
||||
if (startTime != nil && endTime != nil) { |
||||
return [[NSNumber numberWithDouble:([endTime timeIntervalSinceDate:startTime]*1000)] longValue]; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
- (NSArray*)getArguments { |
||||
return _arguments; |
||||
} |
||||
|
||||
- (NSString*)getCommand { |
||||
return [FFmpegKit argumentsToString:_arguments]; |
||||
} |
||||
|
||||
- (void)waitForAsynchronousMessagesInTransmit:(int)timeout { |
||||
NSDate* expireDate = [[NSDate date] dateByAddingTimeInterval:((double)timeout)/1000]; |
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
||||
|
||||
while ([self thereAreAsynchronousMessagesInTransmit] && ([[NSDate date] timeIntervalSinceDate:expireDate] < 0)) { |
||||
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC)); |
||||
} |
||||
} |
||||
|
||||
- (NSArray*)getAllLogsWithTimeout:(int)waitTimeout { |
||||
[self waitForAsynchronousMessagesInTransmit:waitTimeout]; |
||||
|
||||
if ([self thereAreAsynchronousMessagesInTransmit]) { |
||||
NSLog(@"getAllLogsWithTimeout was called to return all logs but there are still logs being transmitted for session id %ld.", _sessionId); |
||||
} |
||||
|
||||
return [self getLogs]; |
||||
} |
||||
|
||||
- (NSArray*)getAllLogs { |
||||
return [self getAllLogsWithTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit]; |
||||
} |
||||
|
||||
- (NSArray*)getLogs { |
||||
[_logsLock lock]; |
||||
NSArray* logsCopy = [_logs copy]; |
||||
[_logsLock unlock]; |
||||
|
||||
return logsCopy; |
||||
} |
||||
|
||||
- (NSString*)getAllLogsAsStringWithTimeout:(int)waitTimeout { |
||||
[self waitForAsynchronousMessagesInTransmit:waitTimeout]; |
||||
|
||||
if ([self thereAreAsynchronousMessagesInTransmit]) { |
||||
NSLog(@"getAllLogsAsStringWithTimeout was called to return all logs but there are still logs being transmitted for session id %ld.", _sessionId); |
||||
} |
||||
|
||||
return [self getAllLogsAsString]; |
||||
} |
||||
|
||||
- (NSString*)getAllLogsAsString { |
||||
return [self getAllLogsAsStringWithTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit]; |
||||
} |
||||
|
||||
- (NSString*)getLogsAsString { |
||||
NSMutableString* concatenatedString = [[NSMutableString alloc] init]; |
||||
|
||||
[_logsLock lock]; |
||||
for (int i=0; i < [_logs count]; i++) { |
||||
[concatenatedString appendString:[[_logs objectAtIndex:i] getMessage]]; |
||||
} |
||||
[_logsLock unlock]; |
||||
|
||||
return concatenatedString; |
||||
} |
||||
|
||||
- (NSString*)getOutput { |
||||
return [self getAllLogsAsString]; |
||||
} |
||||
|
||||
- (SessionState)getState { |
||||
return _state; |
||||
} |
||||
|
||||
- (ReturnCode*)getReturnCode { |
||||
return _returnCode; |
||||
} |
||||
|
||||
- (NSString*)getFailStackTrace { |
||||
return _failStackTrace; |
||||
} |
||||
|
||||
- (LogRedirectionStrategy)getLogRedirectionStrategy { |
||||
return _logRedirectionStrategy; |
||||
} |
||||
|
||||
- (BOOL)thereAreAsynchronousMessagesInTransmit { |
||||
return ([FFmpegKitConfig messagesInTransmit:_sessionId] != 0); |
||||
} |
||||
|
||||
- (void)addLog:(Log*)log { |
||||
[_logsLock lock]; |
||||
[_logs addObject:log]; |
||||
[_logsLock unlock]; |
||||
} |
||||
|
||||
- (void)startRunning { |
||||
_state = SessionStateRunning; |
||||
_startTime = [NSDate date]; |
||||
} |
||||
|
||||
- (void)complete:(ReturnCode*)returnCode { |
||||
_returnCode = returnCode; |
||||
_state = SessionStateCompleted; |
||||
_endTime = [NSDate date]; |
||||
} |
||||
|
||||
- (void)fail:(NSException*)exception { |
||||
_failStackTrace = [NSString stringWithFormat:@"%@", [exception callStackSymbols]]; |
||||
_state = SessionStateFailed; |
||||
_endTime = [NSDate date]; |
||||
} |
||||
|
||||
- (BOOL)isFFmpeg { |
||||
// IMPLEMENTED IN SUBCLASSES |
||||
return false; |
||||
} |
||||
|
||||
- (BOOL)isFFprobe { |
||||
// IMPLEMENTED IN SUBCLASSES |
||||
return false; |
||||
} |
||||
|
||||
- (void)cancel { |
||||
if (_state == SessionStateRunning) { |
||||
[FFmpegKit cancel:_sessionId]; |
||||
} |
||||
} |
||||
|
||||
@end |
||||
@ -1,35 +0,0 @@ |
||||
/*
|
||||
* 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/>.
|
||||
*/ |
||||
|
||||
#include <Foundation/Foundation.h> |
||||
|
||||
/**
|
||||
* Represents an ongoing FFmpeg execution. |
||||
*/ |
||||
@interface FFmpegExecution : NSObject |
||||
|
||||
- (instancetype)initWithExecutionId:(long)newExecutionId andArguments:(NSArray*)arguments; |
||||
|
||||
- (NSDate*)getStartTime; |
||||
|
||||
- (long)getExecutionId; |
||||
|
||||
- (NSString*)getCommand; |
||||
|
||||
@end |
||||
@ -1,52 +0,0 @@ |
||||
/* |
||||
* 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/>. |
||||
*/ |
||||
|
||||
#include "FFmpegExecution.h" |
||||
#include "FFmpegKit.h" |
||||
|
||||
@implementation FFmpegExecution { |
||||
NSDate* startTime; |
||||
long executionId; |
||||
NSString* command; |
||||
} |
||||
|
||||
- (instancetype)initWithExecutionId:(long)newExecutionId andArguments:(NSArray*)arguments { |
||||
self = [super init]; |
||||
if (self) { |
||||
startTime = [NSDate date]; |
||||
executionId = newExecutionId; |
||||
command = [FFmpegKit argumentsToString:arguments]; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (NSDate*)getStartTime { |
||||
return startTime; |
||||
} |
||||
|
||||
- (long)getExecutionId { |
||||
return executionId; |
||||
} |
||||
|
||||
- (NSString*)getCommand { |
||||
return command; |
||||
} |
||||
|
||||
@end |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,119 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_FFMPEG_SESSION_H |
||||
#define FFMPEG_KIT_FFMPEG_SESSION_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
#import "AbstractSession.h" |
||||
#import "StatisticsDelegate.h" |
||||
|
||||
/**
|
||||
* <p>An FFmpeg session. |
||||
*/ |
||||
@interface FFmpegSession : AbstractSession |
||||
|
||||
/**
|
||||
* Builds a new FFmpeg session. |
||||
* |
||||
* @param arguments command arguments |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments; |
||||
|
||||
/**
|
||||
* Builds a new FFmpeg session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate; |
||||
|
||||
/**
|
||||
* Builds a new FFmpeg session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
* @param logDelegate session specific log delegate |
||||
* @param statisticsDelegate session specific statistics delegate |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withStatisticsDelegate:(id<StatisticsDelegate>)statisticsDelegate; |
||||
|
||||
/**
|
||||
* Builds a new FFmpeg session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
* @param logDelegate session specific log delegate |
||||
* @param statisticsDelegate session specific statistics delegate |
||||
* @param logRedirectionStrategy session specific log redirection strategy |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withStatisticsDelegate:(id<StatisticsDelegate>)statisticsDelegate withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy; |
||||
|
||||
/**
|
||||
* Returns the session specific statistics delegate. |
||||
* |
||||
* @return session specific statistics delegate |
||||
*/ |
||||
- (id<StatisticsDelegate>)getStatisticsDelegate; |
||||
|
||||
/**
|
||||
* 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. |
||||
* |
||||
* @param waitTimeout wait timeout for asynchronous messages in milliseconds |
||||
* @return list of statistics entries generated for this session |
||||
*/ |
||||
- (NSArray*)getAllStatisticsWithTimeout:(int)waitTimeout; |
||||
|
||||
/**
|
||||
* Returns all statistics entries generated for this session. If there are asynchronous |
||||
* messages that are not delivered yet, this method waits for them until |
||||
* AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit expires. |
||||
* |
||||
* @return list of statistics entries generated for this session |
||||
*/ |
||||
- (NSArray*)getAllStatistics; |
||||
|
||||
/**
|
||||
* Returns all statistics entries delivered for this session. Note that if there are |
||||
* asynchronous messages that are not delivered yet, this method will not wait for |
||||
* them and will return immediately. |
||||
* |
||||
* @return list of statistics entries received for this session |
||||
*/ |
||||
- (NSArray*)getStatistics; |
||||
|
||||
/**
|
||||
* Returns the last received statistics entry. |
||||
* |
||||
* @return the last received statistics entry or nil if there are not any statistics entries |
||||
* received |
||||
*/ |
||||
- (Statistics*)getLastReceivedStatistics; |
||||
|
||||
/**
|
||||
* Adds a new statistics entry for this session. |
||||
* |
||||
* @param statistics statistics entry |
||||
*/ |
||||
- (void)addStatistics:(Statistics*)statistics; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_FFMPEG_SESSION_H
|
||||
@ -0,0 +1,137 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "ExecuteDelegate.h" |
||||
#import "FFmpegSession.h" |
||||
#import "FFmpegKitConfig.h" |
||||
#import "LogDelegate.h" |
||||
#import "StatisticsDelegate.h" |
||||
|
||||
@implementation FFmpegSession { |
||||
id<StatisticsDelegate> _statisticsDelegate; |
||||
NSMutableArray* _statistics; |
||||
NSRecursiveLock* _statisticsLock; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:nil withLogDelegate:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]]; |
||||
|
||||
if (self) { |
||||
_statisticsDelegate = nil; |
||||
_statistics = [[NSMutableArray alloc] init]; |
||||
_statisticsLock = [[NSRecursiveLock alloc] init]; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]]; |
||||
|
||||
if (self) { |
||||
_statisticsDelegate = nil; |
||||
_statistics = [[NSMutableArray alloc] init]; |
||||
_statisticsLock = [[NSRecursiveLock alloc] init]; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withStatisticsDelegate:(id<StatisticsDelegate>)statisticsDelegate { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:logDelegate withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]]; |
||||
|
||||
if (self) { |
||||
_statisticsDelegate = statisticsDelegate; |
||||
_statistics = [[NSMutableArray alloc] init]; |
||||
_statisticsLock = [[NSRecursiveLock alloc] init]; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withStatisticsDelegate:(id<StatisticsDelegate>)statisticsDelegate withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:logDelegate withLogRedirectionStrategy:logRedirectionStrategy]; |
||||
|
||||
if (self) { |
||||
_statisticsDelegate = statisticsDelegate; |
||||
_statistics = [[NSMutableArray alloc] init]; |
||||
_statisticsLock = [[NSRecursiveLock alloc] init]; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (id<StatisticsDelegate>)getStatisticsDelegate { |
||||
return _statisticsDelegate; |
||||
} |
||||
|
||||
- (NSArray*)getAllStatisticsWithTimeout:(int)waitTimeout { |
||||
[self waitForAsynchronousMessagesInTransmit:waitTimeout]; |
||||
|
||||
if ([self thereAreAsynchronousMessagesInTransmit]) { |
||||
NSLog(@"getAllStatisticsWithTimeout was called to return all statistics but there are still statistics being transmitted for session id %ld.", [self getSessionId]); |
||||
} |
||||
|
||||
return [self getStatistics]; |
||||
} |
||||
|
||||
- (NSArray*)getAllStatistics { |
||||
return [self getAllStatisticsWithTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit]; |
||||
} |
||||
|
||||
- (NSArray*)getStatistics { |
||||
[_statisticsLock lock]; |
||||
NSArray* statisticsCopy = [_statistics copy]; |
||||
[_statisticsLock unlock]; |
||||
|
||||
return statisticsCopy; |
||||
} |
||||
|
||||
- (Statistics*)getLastReceivedStatistics { |
||||
Statistics* lastStatistics = nil; |
||||
|
||||
[_statisticsLock lock]; |
||||
if ([_statistics count] > 0) { |
||||
lastStatistics = [_statistics objectAtIndex:0]; |
||||
} |
||||
[_statisticsLock unlock]; |
||||
|
||||
return lastStatistics; |
||||
} |
||||
|
||||
- (void)addStatistics:(Statistics*)statistics { |
||||
[_statisticsLock lock]; |
||||
[_statistics addObject:statistics]; |
||||
[_statisticsLock unlock]; |
||||
} |
||||
|
||||
- (BOOL)isFFmpeg { |
||||
return true; |
||||
} |
||||
|
||||
- (BOOL)isFFprobe { |
||||
return false; |
||||
} |
||||
|
||||
@end |
||||
|
||||
@ -0,0 +1,67 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_FFPROBE_SESSION_H |
||||
#define FFMPEG_KIT_FFPROBE_SESSION_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
#import "AbstractSession.h" |
||||
|
||||
/**
|
||||
* <p>An FFprobe session. |
||||
*/ |
||||
@interface FFprobeSession : AbstractSession |
||||
|
||||
/**
|
||||
* Builds a new FFprobe session. |
||||
* |
||||
* @param arguments command arguments |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments; |
||||
|
||||
/**
|
||||
* Builds a new FFprobe session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate; |
||||
|
||||
/**
|
||||
* Builds a new FFprobe session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
* @param logDelegate session specific log delegate |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate; |
||||
|
||||
/**
|
||||
* Builds a new FFprobe session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
* @param logDelegate session specific log delegate |
||||
* @param logRedirectionStrategy session specific log redirection strategy |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_FFPROBE_SESSION_H
|
||||
@ -0,0 +1,64 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "ExecuteDelegate.h" |
||||
#import "FFprobeSession.h" |
||||
#import "FFmpegKitConfig.h" |
||||
#import "LogDelegate.h" |
||||
|
||||
@implementation FFprobeSession |
||||
|
||||
- (instancetype)init:(NSArray*)arguments { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:nil withLogDelegate:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:logDelegate withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:logDelegate withLogRedirectionStrategy:logRedirectionStrategy]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (BOOL)isFFmpeg { |
||||
return false; |
||||
} |
||||
|
||||
- (BOOL)isFFprobe { |
||||
return true; |
||||
} |
||||
|
||||
@end |
||||
|
||||
@ -0,0 +1,85 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_LEVEL_H |
||||
#define FFMPEG_KIT_LEVEL_H |
||||
|
||||
/**
|
||||
* <p>Enumeration type for log levels. |
||||
*/ |
||||
typedef NS_ENUM(NSUInteger, Level) { |
||||
|
||||
/**
|
||||
* This log level is defined by FFmpegKit. It is used to specify logs printed to stderr by |
||||
* FFmpeg. Logs that has this level are not filtered and always redirected. |
||||
*/ |
||||
LevelAVLogStdErr = -16, |
||||
|
||||
/**
|
||||
* Print no output. |
||||
*/ |
||||
LevelAVLogQuiet = -8, |
||||
|
||||
/**
|
||||
* Something went really wrong and we will crash now. |
||||
*/ |
||||
LevelAVLogPanic = 0, |
||||
|
||||
/**
|
||||
* Something went wrong and recovery is not possible. |
||||
* For example, no header was found for a format which depends |
||||
* on headers or an illegal combination of parameters is used. |
||||
*/ |
||||
LevelAVLogFatal = 8, |
||||
|
||||
/**
|
||||
* Something went wrong and cannot losslessly be recovered. |
||||
* However, not all future data is affected. |
||||
*/ |
||||
LevelAVLogError = 16, |
||||
|
||||
/**
|
||||
* Something somehow does not look correct. This may or may not |
||||
* lead to problems. An example would be the use of '-vstrict -2'. |
||||
*/ |
||||
LevelAVLogWarning = 24, |
||||
|
||||
/**
|
||||
* Standard information. |
||||
*/ |
||||
LevelAVLogInfo = 32, |
||||
|
||||
/**
|
||||
* Detailed information. |
||||
*/ |
||||
LevelAVLogVerbose = 40, |
||||
|
||||
/**
|
||||
* Stuff which is only useful for libav* developers. |
||||
*/ |
||||
LevelAVLogDebug = 48, |
||||
|
||||
/**
|
||||
* Extremely verbose debugging, useful for libav* development. |
||||
*/ |
||||
LevelAVLogTrace = 56 |
||||
|
||||
}; |
||||
|
||||
#endif // FFMPEG_KIT_LEVEL_H
|
||||
@ -0,0 +1,40 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_LOG_H |
||||
#define FFMPEG_KIT_LOG_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
|
||||
/**
|
||||
* <p>Log entry for an <code>FFmpegKit</code> session. |
||||
*/ |
||||
@interface Log : NSObject |
||||
|
||||
- (instancetype)init:(long)sessionId :(int)level :(NSString*)message; |
||||
|
||||
- (long)getSessionId; |
||||
|
||||
- (int)getLevel; |
||||
|
||||
- (NSString*)getMessage; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_LOG_H
|
||||
@ -0,0 +1,51 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "Log.h" |
||||
|
||||
@implementation Log { |
||||
long _sessionId; |
||||
int _level; |
||||
NSString *_message; |
||||
} |
||||
|
||||
- (instancetype)init:(long)sessionId :(int)level :(NSString*)message { |
||||
self = [super init]; |
||||
if (self) { |
||||
_sessionId = sessionId; |
||||
_level = level; |
||||
_message = message; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (long)getSessionId { |
||||
return _sessionId; |
||||
} |
||||
|
||||
- (int)getLevel { |
||||
return _level; |
||||
} |
||||
|
||||
- (NSString*)getMessage { |
||||
return _message; |
||||
} |
||||
|
||||
@end |
||||
@ -0,0 +1,31 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_LOG_REDIRECTION_STRATEGY_H |
||||
#define FFMPEG_KIT_LOG_REDIRECTION_STRATEGY_H |
||||
|
||||
typedef NS_ENUM(NSUInteger, LogRedirectionStrategy) { |
||||
LogRedirectionStrategyAlwaysPrintLogs, |
||||
LogRedirectionStrategyPrintLogsWhenNoDelegatesDefined, |
||||
LogRedirectionStrategyPrintLogsWhenGlobalDelegateNotDefined, |
||||
LogRedirectionStrategyPrintLogsWhenSessionDelegateNotDefined, |
||||
LogRedirectionStrategyNeverPrintLogs |
||||
}; |
||||
|
||||
#endif // FFMPEG_KIT_LOG_REDIRECTION_STRATEGY_H
|
||||
@ -0,0 +1,74 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_MEDIA_INFORMATION_SESSION_H |
||||
#define FFMPEG_KIT_MEDIA_INFORMATION_SESSION_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
#import "FFprobeSession.h" |
||||
#import "MediaInformation.h" |
||||
|
||||
/**
|
||||
* <p>A custom FFprobe session, which produces a <code>MediaInformation</code> object using the |
||||
* FFprobe output. |
||||
*/ |
||||
@interface MediaInformationSession : FFprobeSession |
||||
|
||||
/**
|
||||
* Creates a new media information session. |
||||
* |
||||
* @param arguments command arguments |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments; |
||||
|
||||
/**
|
||||
* Creates a new media information session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate; |
||||
|
||||
/**
|
||||
* Creates a new media information session. |
||||
* |
||||
* @param arguments command arguments |
||||
* @param executeDelegate session specific execute delegate |
||||
* @param logDelegate session specific log delegate |
||||
*/ |
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate; |
||||
|
||||
/**
|
||||
* Returns the media information extracted in this session. |
||||
* |
||||
* @return media information extracted or nil if the command failed or the output can not be |
||||
* parsed |
||||
*/ |
||||
- (MediaInformation*)getMediaInformation; |
||||
|
||||
/**
|
||||
* Sets the media information extracted in this session. |
||||
* |
||||
* @param mediaInformation media information extracted |
||||
*/ |
||||
- (void)setMediaInformation:(MediaInformation*)mediaInformation; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_MEDIA_INFORMATION_SESSION_H
|
||||
@ -0,0 +1,59 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "ExecuteDelegate.h" |
||||
#import "LogDelegate.h" |
||||
#import "MediaInformation.h" |
||||
#import "MediaInformationSession.h" |
||||
|
||||
@implementation MediaInformationSession { |
||||
MediaInformation* _mediaInformation; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:nil withLogDelegate:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (instancetype)init:(NSArray*)arguments withExecuteDelegate:(id<ExecuteDelegate>)executeDelegate withLogDelegate:(id<LogDelegate>)logDelegate { |
||||
|
||||
self = [super init:arguments withExecuteDelegate:executeDelegate withLogDelegate:logDelegate withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs]; |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (MediaInformation*)getMediaInformation { |
||||
return _mediaInformation; |
||||
} |
||||
|
||||
- (void)setMediaInformation:(MediaInformation*)mediaInformation { |
||||
_mediaInformation = mediaInformation; |
||||
} |
||||
|
||||
@end |
||||
|
||||
@ -0,0 +1,46 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_PACKAGES_H |
||||
#define FFMPEG_KIT_PACKAGES_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
|
||||
/**
|
||||
* <p>Helper class to extract binary package information. |
||||
*/ |
||||
@interface Packages : NSObject |
||||
|
||||
/**
|
||||
* Returns the FFmpegKit binary package name. |
||||
* |
||||
* @return predicted FFmpegKit binary package name |
||||
*/ |
||||
+ (NSString*)getPackageName; |
||||
|
||||
/**
|
||||
* Returns enabled external libraries by FFmpeg. |
||||
* |
||||
* @return enabled external libraries |
||||
*/ |
||||
+ (NSArray*)getExternalLibraries; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_PACKAGES_H
|
||||
@ -0,0 +1,263 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "config.h" |
||||
#import "libavutil/ffversion.h" |
||||
#import "FFmpegKitConfig.h" |
||||
#import "Packages.h" |
||||
|
||||
static NSMutableArray *supportedExternalLibraries; |
||||
|
||||
@implementation Packages |
||||
|
||||
+ (void)initialize { |
||||
supportedExternalLibraries = [[NSMutableArray alloc] init]; |
||||
[supportedExternalLibraries addObject:@"dav1d"]; |
||||
[supportedExternalLibraries addObject:@"fontconfig"]; |
||||
[supportedExternalLibraries addObject:@"freetype"]; |
||||
[supportedExternalLibraries addObject:@"fribidi"]; |
||||
[supportedExternalLibraries addObject:@"gmp"]; |
||||
[supportedExternalLibraries addObject:@"gnutls"]; |
||||
[supportedExternalLibraries addObject:@"kvazaar"]; |
||||
[supportedExternalLibraries addObject:@"mp3lame"]; |
||||
[supportedExternalLibraries addObject:@"libaom"]; |
||||
[supportedExternalLibraries addObject:@"libass"]; |
||||
[supportedExternalLibraries addObject:@"iconv"]; |
||||
[supportedExternalLibraries addObject:@"libilbc"]; |
||||
[supportedExternalLibraries addObject:@"libtheora"]; |
||||
[supportedExternalLibraries addObject:@"libvidstab"]; |
||||
[supportedExternalLibraries addObject:@"libvorbis"]; |
||||
[supportedExternalLibraries addObject:@"libvpx"]; |
||||
[supportedExternalLibraries addObject:@"libwebp"]; |
||||
[supportedExternalLibraries addObject:@"libxml2"]; |
||||
[supportedExternalLibraries addObject:@"opencore-amr"]; |
||||
[supportedExternalLibraries addObject:@"openh264"]; |
||||
[supportedExternalLibraries addObject:@"opus"]; |
||||
[supportedExternalLibraries addObject:@"rubberband"]; |
||||
[supportedExternalLibraries addObject:@"sdl2"]; |
||||
[supportedExternalLibraries addObject:@"shine"]; |
||||
[supportedExternalLibraries addObject:@"snappy"]; |
||||
[supportedExternalLibraries addObject:@"soxr"]; |
||||
[supportedExternalLibraries addObject:@"speex"]; |
||||
[supportedExternalLibraries addObject:@"tesseract"]; |
||||
[supportedExternalLibraries addObject:@"twolame"]; |
||||
[supportedExternalLibraries addObject:@"x264"]; |
||||
[supportedExternalLibraries addObject:@"x265"]; |
||||
[supportedExternalLibraries addObject:@"xvid"]; |
||||
} |
||||
|
||||
+ (NSString*)getBuildConf { |
||||
return [NSString stringWithUTF8String:FFMPEG_CONFIGURATION]; |
||||
} |
||||
|
||||
+ (NSString*)getPackageName { |
||||
NSArray *enabledLibraryArray = [Packages getExternalLibraries]; |
||||
Boolean speex = [enabledLibraryArray containsObject:@"speex"]; |
||||
Boolean fribidi = [enabledLibraryArray containsObject:@"fribidi"]; |
||||
Boolean gnutls = [enabledLibraryArray containsObject:@"gnutls"]; |
||||
Boolean xvid = [enabledLibraryArray containsObject:@"xvid"]; |
||||
|
||||
Boolean min = false; |
||||
Boolean minGpl = false; |
||||
Boolean https = false; |
||||
Boolean httpsGpl = false; |
||||
Boolean audio = false; |
||||
Boolean video = false; |
||||
Boolean full = false; |
||||
Boolean fullGpl = false; |
||||
|
||||
if (speex && fribidi) { |
||||
if (xvid) { |
||||
fullGpl = true; |
||||
} else { |
||||
full = true; |
||||
} |
||||
} else if (speex) { |
||||
audio = true; |
||||
} else if (fribidi) { |
||||
video = true; |
||||
} else if (xvid) { |
||||
if (gnutls) { |
||||
httpsGpl = true; |
||||
} else { |
||||
minGpl = true; |
||||
} |
||||
} else { |
||||
if (gnutls) { |
||||
https = true; |
||||
} else { |
||||
min = true; |
||||
} |
||||
} |
||||
|
||||
if (fullGpl) { |
||||
if ([enabledLibraryArray containsObject:@"dav1d"] && |
||||
[enabledLibraryArray containsObject:@"fontconfig"] && |
||||
[enabledLibraryArray containsObject:@"freetype"] && |
||||
[enabledLibraryArray containsObject:@"fribidi"] && |
||||
[enabledLibraryArray containsObject:@"gmp"] && |
||||
[enabledLibraryArray containsObject:@"gnutls"] && |
||||
[enabledLibraryArray containsObject:@"kvazaar"] && |
||||
[enabledLibraryArray containsObject:@"mp3lame"] && |
||||
[enabledLibraryArray containsObject:@"libass"] && |
||||
[enabledLibraryArray containsObject:@"iconv"] && |
||||
[enabledLibraryArray containsObject:@"libilbc"] && |
||||
[enabledLibraryArray containsObject:@"libtheora"] && |
||||
[enabledLibraryArray containsObject:@"libvidstab"] && |
||||
[enabledLibraryArray containsObject:@"libvorbis"] && |
||||
[enabledLibraryArray containsObject:@"libvpx"] && |
||||
[enabledLibraryArray containsObject:@"libwebp"] && |
||||
[enabledLibraryArray containsObject:@"libxml2"] && |
||||
[enabledLibraryArray containsObject:@"opencore-amr"] && |
||||
[enabledLibraryArray containsObject:@"opus"] && |
||||
[enabledLibraryArray containsObject:@"shine"] && |
||||
[enabledLibraryArray containsObject:@"snappy"] && |
||||
[enabledLibraryArray containsObject:@"soxr"] && |
||||
[enabledLibraryArray containsObject:@"speex"] && |
||||
[enabledLibraryArray containsObject:@"twolame"] && |
||||
[enabledLibraryArray containsObject:@"x264"] && |
||||
[enabledLibraryArray containsObject:@"x265"] && |
||||
[enabledLibraryArray containsObject:@"xvid"]) { |
||||
return @"full-gpl"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
if (full) { |
||||
if ([enabledLibraryArray containsObject:@"dav1d"] && |
||||
[enabledLibraryArray containsObject:@"fontconfig"] && |
||||
[enabledLibraryArray containsObject:@"freetype"] && |
||||
[enabledLibraryArray containsObject:@"fribidi"] && |
||||
[enabledLibraryArray containsObject:@"gmp"] && |
||||
[enabledLibraryArray containsObject:@"gnutls"] && |
||||
[enabledLibraryArray containsObject:@"kvazaar"] && |
||||
[enabledLibraryArray containsObject:@"mp3lame"] && |
||||
[enabledLibraryArray containsObject:@"libass"] && |
||||
[enabledLibraryArray containsObject:@"iconv"] && |
||||
[enabledLibraryArray containsObject:@"libilbc"] && |
||||
[enabledLibraryArray containsObject:@"libtheora"] && |
||||
[enabledLibraryArray containsObject:@"libvorbis"] && |
||||
[enabledLibraryArray containsObject:@"libvpx"] && |
||||
[enabledLibraryArray containsObject:@"libwebp"] && |
||||
[enabledLibraryArray containsObject:@"libxml2"] && |
||||
[enabledLibraryArray containsObject:@"opencore-amr"] && |
||||
[enabledLibraryArray containsObject:@"opus"] && |
||||
[enabledLibraryArray containsObject:@"shine"] && |
||||
[enabledLibraryArray containsObject:@"snappy"] && |
||||
[enabledLibraryArray containsObject:@"soxr"] && |
||||
[enabledLibraryArray containsObject:@"speex"] && |
||||
[enabledLibraryArray containsObject:@"twolame"]) { |
||||
return @"full"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
if (video) { |
||||
if ([enabledLibraryArray containsObject:@"dav1d"] && |
||||
[enabledLibraryArray containsObject:@"fontconfig"] && |
||||
[enabledLibraryArray containsObject:@"freetype"] && |
||||
[enabledLibraryArray containsObject:@"fribidi"] && |
||||
[enabledLibraryArray containsObject:@"kvazaar"] && |
||||
[enabledLibraryArray containsObject:@"libass"] && |
||||
[enabledLibraryArray containsObject:@"iconv"] && |
||||
[enabledLibraryArray containsObject:@"libtheora"] && |
||||
[enabledLibraryArray containsObject:@"libvpx"] && |
||||
[enabledLibraryArray containsObject:@"libwebp"] && |
||||
[enabledLibraryArray containsObject:@"snappy"]) { |
||||
return @"video"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
if (audio) { |
||||
if ([enabledLibraryArray containsObject:@"mp3lame"] && |
||||
[enabledLibraryArray containsObject:@"libilbc"] && |
||||
[enabledLibraryArray containsObject:@"libvorbis"] && |
||||
[enabledLibraryArray containsObject:@"opencore-amr"] && |
||||
[enabledLibraryArray containsObject:@"opus"] && |
||||
[enabledLibraryArray containsObject:@"shine"] && |
||||
[enabledLibraryArray containsObject:@"soxr"] && |
||||
[enabledLibraryArray containsObject:@"speex"] && |
||||
[enabledLibraryArray containsObject:@"twolame"]) { |
||||
return @"audio"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
if (httpsGpl) { |
||||
if ([enabledLibraryArray containsObject:@"gmp"] && |
||||
[enabledLibraryArray containsObject:@"gnutls"] && |
||||
[enabledLibraryArray containsObject:@"libvidstab"] && |
||||
[enabledLibraryArray containsObject:@"x264"] && |
||||
[enabledLibraryArray containsObject:@"x265"] && |
||||
[enabledLibraryArray containsObject:@"xvid"]) { |
||||
return @"https-gpl"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
if (https) { |
||||
if ([enabledLibraryArray containsObject:@"gmp"] && |
||||
[enabledLibraryArray containsObject:@"gnutls"]) { |
||||
return @"https"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
if (minGpl) { |
||||
if ([enabledLibraryArray containsObject:@"libvidstab"] && |
||||
[enabledLibraryArray containsObject:@"x264"] && |
||||
[enabledLibraryArray containsObject:@"x265"] && |
||||
[enabledLibraryArray containsObject:@"xvid"]) { |
||||
return @"min-gpl"; |
||||
} else { |
||||
return @"custom"; |
||||
} |
||||
} |
||||
|
||||
return @"min"; |
||||
} |
||||
|
||||
+ (NSArray*)getExternalLibraries { |
||||
NSString *buildConfiguration = [Packages getBuildConf]; |
||||
NSMutableArray *enabledLibraryArray = [[NSMutableArray alloc] init]; |
||||
|
||||
for (int i=0; i < [supportedExternalLibraries count]; i++) { |
||||
NSString *supportedExternalLibrary = [supportedExternalLibraries objectAtIndex:i]; |
||||
|
||||
NSString *libraryName1 = [NSString stringWithFormat:@"enable-%@", supportedExternalLibrary]; |
||||
NSString *libraryName2 = [NSString stringWithFormat:@"enable-lib%@", supportedExternalLibrary]; |
||||
|
||||
if ([buildConfiguration rangeOfString:libraryName1].location != NSNotFound || [buildConfiguration rangeOfString:libraryName2].location != NSNotFound) { |
||||
[enabledLibraryArray addObject:supportedExternalLibrary]; |
||||
} |
||||
} |
||||
|
||||
[enabledLibraryArray sortUsingSelector:@selector(compare:)]; |
||||
|
||||
return enabledLibraryArray; |
||||
} |
||||
|
||||
@end |
||||
@ -0,0 +1,44 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_RETURN_CODE_H |
||||
#define FFMPEG_KIT_RETURN_CODE_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
|
||||
typedef NS_ENUM(NSUInteger, ReturnCodeEnum) { |
||||
ReturnCodeSuccess = 0, |
||||
ReturnCodeCancel = 255 |
||||
}; |
||||
|
||||
@interface ReturnCode : NSObject |
||||
|
||||
- (instancetype)init:(int)value; |
||||
|
||||
- (int)getValue; |
||||
|
||||
- (BOOL)isSuccess; |
||||
|
||||
- (BOOL)isError; |
||||
|
||||
- (BOOL)isCancel; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_RETURN_CODE_H
|
||||
@ -0,0 +1,51 @@ |
||||
/* |
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "ReturnCode.h" |
||||
|
||||
@implementation ReturnCode { |
||||
int _value; |
||||
} |
||||
|
||||
- (instancetype)init:(int)value { |
||||
self = [super init]; |
||||
if (self) { |
||||
_value = value; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (int)getValue { |
||||
return _value; |
||||
} |
||||
|
||||
- (BOOL)isSuccess { |
||||
return (_value == ReturnCodeSuccess); |
||||
} |
||||
|
||||
- (BOOL)isError { |
||||
return ((_value != ReturnCodeSuccess) && (_value != ReturnCodeCancel)); |
||||
} |
||||
|
||||
- (BOOL)isCancel { |
||||
return (_value == ReturnCodeCancel); |
||||
} |
||||
|
||||
@end |
||||
@ -0,0 +1,255 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_SESSION_H |
||||
#define FFMPEG_KIT_SESSION_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
#import "ExecuteDelegate.h" |
||||
#import "Log.h" |
||||
#import "LogDelegate.h" |
||||
#import "LogRedirectionStrategy.h" |
||||
#import "ReturnCode.h" |
||||
#import "SessionState.h" |
||||
|
||||
@protocol ExecuteDelegate; |
||||
|
||||
/**
|
||||
* <p>Common interface for all <code>FFmpegKit</code> sessions. |
||||
*/ |
||||
@protocol Session |
||||
|
||||
@required |
||||
|
||||
/**
|
||||
* Returns the session specific execute delegate. |
||||
* |
||||
* @return session specific execute delegate |
||||
*/ |
||||
- (id<ExecuteDelegate>)getExecuteDelegate; |
||||
|
||||
/**
|
||||
* Returns the session specific log delegate. |
||||
* |
||||
* @return session specific log delegate |
||||
*/ |
||||
- (id<LogDelegate>)getLogDelegate; |
||||
|
||||
/**
|
||||
* Returns the session identifier. |
||||
* |
||||
* @return session identifier |
||||
*/ |
||||
- (long)getSessionId; |
||||
|
||||
/**
|
||||
* Returns session create time. |
||||
* |
||||
* @return session create time |
||||
*/ |
||||
- (NSDate*)getCreateTime; |
||||
|
||||
/**
|
||||
* Returns session start time. |
||||
* |
||||
* @return session start time |
||||
*/ |
||||
- (NSDate*)getStartTime; |
||||
|
||||
/**
|
||||
* Returns session end time. |
||||
* |
||||
* @return session end time |
||||
*/ |
||||
- (NSDate*)getEndTime; |
||||
|
||||
/**
|
||||
* Returns the time taken to execute this session. |
||||
* |
||||
* @return time taken to execute this session in milliseconds or zero (0) if the session is |
||||
* not over yet |
||||
*/ |
||||
- (long)getDuration; |
||||
|
||||
/**
|
||||
* Returns command arguments as an array. |
||||
* |
||||
* @return command arguments as an array |
||||
*/ |
||||
- (NSArray*)getArguments; |
||||
|
||||
/**
|
||||
* Returns command arguments as a concatenated string. |
||||
* |
||||
* @return command arguments as a concatenated string |
||||
*/ |
||||
- (NSString*)getCommand; |
||||
|
||||
/**
|
||||
* Returns all log entries generated for this session. If there are asynchronous |
||||
* messages that are not delivered yet, this method waits for them until the given timeout. |
||||
* |
||||
* @param waitTimeout wait timeout for asynchronous messages in milliseconds |
||||
* @return list of log entries generated for this session |
||||
*/ |
||||
- (NSArray*)getAllLogsWithTimeout:(int)waitTimeout; |
||||
|
||||
/**
|
||||
* Returns all log entries generated for this session. If there are asynchronous |
||||
* messages that are not delivered yet, this method waits for them. |
||||
* |
||||
* @return list of log entries generated for this session |
||||
*/ |
||||
- (NSArray*)getAllLogs; |
||||
|
||||
/**
|
||||
* Returns all log entries delivered for this session. Note that if there are asynchronous |
||||
* messages that are not delivered yet, this method will not wait for them and will return |
||||
* immediately. |
||||
* |
||||
* @return list of log entries received for this session |
||||
*/ |
||||
- (NSArray*)getLogs; |
||||
|
||||
/**
|
||||
* Returns all log entries generated for this session as a concatenated string. If there are |
||||
* asynchronous messages that are not delivered yet, this method waits for them until |
||||
* the given timeout. |
||||
* |
||||
* @param waitTimeout wait timeout for asynchronous messages in milliseconds |
||||
* @return all log entries generated for this session as a concatenated string |
||||
*/ |
||||
- (NSString*)getAllLogsAsStringWithTimeout:(int)waitTimeout; |
||||
|
||||
/**
|
||||
* Returns all log entries generated for this session as a concatenated string. If there are |
||||
* asynchronous messages that are not delivered yet, this method waits for them. |
||||
* |
||||
* @return all log entries generated for this session as a concatenated string |
||||
*/ |
||||
- (NSString*)getAllLogsAsString; |
||||
|
||||
/**
|
||||
* Returns all log entries delivered for this session as a concatenated string. Note that if |
||||
* there are asynchronous messages that are not delivered yet, this method will not wait |
||||
* for them and will return immediately. |
||||
* |
||||
* @return list of log entries received for this session |
||||
*/ |
||||
- (NSString*)getLogsAsString; |
||||
|
||||
/**
|
||||
* Returns the log output generated while running the session. |
||||
* |
||||
* @return log output generated |
||||
*/ |
||||
- (NSString*)getOutput; |
||||
|
||||
/**
|
||||
* Returns the state of the session. |
||||
* |
||||
* @return state of the session |
||||
*/ |
||||
- (SessionState)getState; |
||||
|
||||
/**
|
||||
* Returns the return code for this session. Note that return code is only set for sessions |
||||
* 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 |
||||
* not started, still running or failed |
||||
*/ |
||||
- (ReturnCode*)getReturnCode; |
||||
|
||||
/**
|
||||
* Returns the stack trace of the exception received while executing this session. |
||||
* <p> |
||||
* The stack trace is only set for sessions that end with SessionStateFailed state. For sessions that has |
||||
* SessionStateCompleted state this method returns nil. |
||||
* |
||||
* @return stack trace of the exception received while executing this session, nil if session |
||||
* is not started, still running or completed |
||||
*/ |
||||
- (NSString*)getFailStackTrace; |
||||
|
||||
/**
|
||||
* Returns session specific log redirection strategy. |
||||
* |
||||
* @return session specific log redirection strategy |
||||
*/ |
||||
- (LogRedirectionStrategy)getLogRedirectionStrategy; |
||||
|
||||
/**
|
||||
* Returns whether there are still asynchronous messages being transmitted for this |
||||
* session or not. |
||||
* |
||||
* @return true if there are still asynchronous messages being transmitted, false |
||||
* otherwise |
||||
*/ |
||||
- (BOOL)thereAreAsynchronousMessagesInTransmit; |
||||
|
||||
/**
|
||||
* Adds a new log entry for this session. |
||||
* |
||||
* @param log log entry |
||||
*/ |
||||
- (void)addLog:(Log*)log; |
||||
|
||||
/**
|
||||
* Starts running the session. |
||||
*/ |
||||
- (void)startRunning; |
||||
|
||||
/**
|
||||
* Completes running the session with the provided return code. |
||||
* |
||||
* @param returnCode return code of the execution |
||||
*/ |
||||
- (void)complete:(ReturnCode*)returnCode; |
||||
|
||||
/**
|
||||
* Ends running the session with a failure. |
||||
* |
||||
* @param exception execution received |
||||
*/ |
||||
- (void)fail:(NSException*)exception; |
||||
|
||||
/**
|
||||
* Returns whether it is an <code>FFmpeg</code> session or not. |
||||
* |
||||
* @return true if it is an <code>FFmpeg</code> session, false otherwise |
||||
*/ |
||||
- (BOOL)isFFmpeg; |
||||
|
||||
/**
|
||||
* Returns whether it is an <code>FFprobe</code> session or not. |
||||
* |
||||
* @return true if it is an <code>FFprobe</code> session, false otherwise |
||||
*/ |
||||
- (BOOL)isFFprobe; |
||||
|
||||
/**
|
||||
* Cancels running the session. |
||||
*/ |
||||
- (void)cancel; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_SESSION_H
|
||||
@ -0,0 +1,30 @@ |
||||
/*
|
||||
* Copyright (c) 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 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_SESSION_STATE_H |
||||
#define FFMPEG_KIT_SESSION_STATE_H |
||||
|
||||
typedef NS_ENUM(NSUInteger, SessionState) { |
||||
SessionStateCreated, |
||||
SessionStateRunning, |
||||
SessionStateFailed, |
||||
SessionStateCompleted |
||||
}; |
||||
|
||||
#endif // FFMPEG_KIT_SESSION_STATE_H
|
||||
Loading…
Reference in new issue