call session callbacks first rather than global callbacks on native platforms

This commit is contained in:
Taner Sener 2021-11-08 00:33:53 +00:00
parent fc747666c5
commit 1cb36ea365
4 changed files with 109 additions and 34 deletions

View File

@ -19,6 +19,8 @@
package com.arthenica.ffmpegkit;
import com.arthenica.smartexception.java.Exceptions;
/**
* <p>Executes an FFmpeg session asynchronously.
*/
@ -35,13 +37,23 @@ public class AsyncFFmpegExecuteTask implements Runnable {
public void run() {
FFmpegKitConfig.ffmpegExecute(ffmpegSession);
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
globalExecuteCallbackFunction.apply(ffmpegSession);
if (executeCallback != null) {
try {
// NOTIFY SESSION CALLBACK DEFINED
executeCallback.apply(ffmpegSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
}
}
if (executeCallback != null) {
executeCallback.apply(ffmpegSession);
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalExecuteCallbackFunction.apply(ffmpegSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
}
}
}
}

View File

@ -19,6 +19,8 @@
package com.arthenica.ffmpegkit;
import com.arthenica.smartexception.java.Exceptions;
/**
* <p>Executes an FFprobe session asynchronously.
*/
@ -35,13 +37,23 @@ public class AsyncFFprobeExecuteTask implements Runnable {
public void run() {
FFmpegKitConfig.ffprobeExecute(ffprobeSession);
if (executeCallback != null) {
try {
// NOTIFY SESSION CALLBACK DEFINED
executeCallback.apply(ffprobeSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
}
}
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalExecuteCallbackFunction.apply(ffprobeSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
}
if (executeCallback != null) {
executeCallback.apply(ffprobeSession);
}
}

View File

@ -19,6 +19,8 @@
package com.arthenica.ffmpegkit;
import com.arthenica.smartexception.java.Exceptions;
/**
* <p>Executes a MediaInformation session asynchronously.
*/
@ -41,13 +43,23 @@ public class AsyncGetMediaInformationTask implements Runnable {
public void run() {
FFmpegKitConfig.getMediaInformationExecute(mediaInformationSession, waitTimeout);
if (executeCallback != null) {
try {
// NOTIFY SESSION CALLBACK DEFINED
executeCallback.apply(mediaInformationSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside session ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
}
}
final ExecuteCallback globalExecuteCallbackFunction = FFmpegKitConfig.getExecuteCallback();
if (globalExecuteCallbackFunction != null) {
try {
// NOTIFY GLOBAL CALLBACK DEFINEDs
globalExecuteCallbackFunction.apply(mediaInformationSession);
} catch (final Exception e) {
android.util.Log.e(FFmpegKitConfig.TAG, String.format("Exception thrown inside global ExecuteCallback block.%s", Exceptions.getStackTraceString(e)));
}
if (executeCallback != null) {
executeCallback.apply(mediaInformationSession);
}
}

View File

@ -990,7 +990,7 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
int returnCodeValue = executeFFprobe([mediaInformationSession getSessionId], [mediaInformationSession getArguments]);
ReturnCode* returnCode = [[ReturnCode alloc] init:returnCodeValue];
[mediaInformationSession complete:returnCode];
if ([returnCode isSuccess]) {
if ([returnCode isValueSuccess]) {
MediaInformation* mediaInformation = [MediaInformationJsonParser from:[mediaInformationSession getAllLogsAsStringWithTimeout:waitTimeout]];
[mediaInformationSession setMediaInformation:mediaInformation];
}
@ -1007,15 +1007,28 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
+ (void)asyncFFmpegExecute:(FFmpegSession*)ffmpegSession onDispatchQueue:(dispatch_queue_t)queue {
dispatch_async(queue, ^{
[FFmpegKitConfig ffmpegExecute:ffmpegSession];
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
globalExecuteCallback(ffmpegSession);
}
ExecuteCallback sessionExecuteCallback = [ffmpegSession getExecuteCallback];
if (sessionExecuteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
sessionExecuteCallback(ffmpegSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
}
}
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
globalExecuteCallback(ffmpegSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
}
}
});
}
@ -1026,15 +1039,28 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
+ (void)asyncFFprobeExecute:(FFprobeSession*)ffprobeSession onDispatchQueue:(dispatch_queue_t)queue {
dispatch_async(queue, ^{
[FFmpegKitConfig ffprobeExecute:ffprobeSession];
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
globalExecuteCallback(ffprobeSession);
}
ExecuteCallback sessionExecuteCallback = [ffprobeSession getExecuteCallback];
if (sessionExecuteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
sessionExecuteCallback(ffprobeSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
}
}
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
globalExecuteCallback(ffprobeSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
}
}
});
}
@ -1045,15 +1071,28 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
+ (void)asyncGetMediaInformationExecute:(MediaInformationSession*)mediaInformationSession onDispatchQueue:(dispatch_queue_t)queue withTimeout:(int)waitTimeout {
dispatch_async(queue, ^{
[FFmpegKitConfig getMediaInformationExecute:mediaInformationSession withTimeout:waitTimeout];
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
globalExecuteCallback(mediaInformationSession);
}
ExecuteCallback sessionExecuteCallback = [mediaInformationSession getExecuteCallback];
if (sessionExecuteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
sessionExecuteCallback(mediaInformationSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
}
}
ExecuteCallback globalExecuteCallback = [FFmpegKitConfig getExecuteCallback];
if (globalExecuteCallback != nil) {
@try {
// NOTIFY SESSION CALLBACK DEFINED
globalExecuteCallback(mediaInformationSession);
}
@catch(NSException* exception) {
NSLog(@"Exception thrown inside session ExecuteCallback block. %@", [exception callStackSymbols]);
}
}
});
}