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

This commit is contained in:
Taner Sener 2021-12-25 12:30:33 +00:00
parent ea9f267ce6
commit adfce89fc1
4 changed files with 461 additions and 190 deletions

View File

@ -111,7 +111,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
// EVENTS
public static final String EVENT_LOG_CALLBACK_EVENT = "FFmpegKitLogCallbackEvent";
public static final String EVENT_STATISTICS_CALLBACK_EVENT = "FFmpegKitStatisticsCallbackEvent";
public static final String EVENT_EXECUTE_CALLBACK_EVENT = "FFmpegKitExecuteCallbackEvent";
public static final String EVENT_COMPLETE_CALLBACK_EVENT = "FFmpegKitCompleteCallbackEvent";
// REQUEST CODES
public static final int READABLE_REQUEST_CODE = 10000;
@ -165,9 +165,19 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
}
protected void registerGlobalCallbacks(final ReactApplicationContext reactContext) {
FFmpegKitConfig.enableExecuteCallback(session -> {
FFmpegKitConfig.enableFFmpegSessionCompleteCallback(session -> {
final DeviceEventManagerModule.RCTDeviceEventEmitter jsModule = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
jsModule.emit(EVENT_EXECUTE_CALLBACK_EVENT, toMap(session));
jsModule.emit(EVENT_COMPLETE_CALLBACK_EVENT, toMap(session));
});
FFmpegKitConfig.enableFFprobeSessionCompleteCallback(session -> {
final DeviceEventManagerModule.RCTDeviceEventEmitter jsModule = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
jsModule.emit(EVENT_COMPLETE_CALLBACK_EVENT, toMap(session));
});
FFmpegKitConfig.enableMediaInformationSessionCompleteCallback(session -> {
final DeviceEventManagerModule.RCTDeviceEventEmitter jsModule = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
jsModule.emit(EVENT_COMPLETE_CALLBACK_EVENT, toMap(session));
});
FFmpegKitConfig.enableLogCallback(log -> {
@ -359,7 +369,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof FFmpegSession) {
if (session.isFFmpeg()) {
final int timeout;
if (isValidPositiveNumber(waitTimeout)) {
timeout = waitTimeout.intValue();
@ -384,7 +394,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof FFmpegSession) {
if (session.isFFmpeg()) {
final List<Statistics> statistics = ((FFmpegSession) session).getStatistics();
promise.resolve(toStatisticsArray(statistics));
} else {
@ -580,7 +590,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof FFmpegSession) {
if (session.isFFmpeg()) {
final FFmpegSessionExecuteTask ffmpegSessionExecuteTask = new FFmpegSessionExecuteTask((FFmpegSession) session, promise);
asyncExecutorService.submit(ffmpegSessionExecuteTask);
} else {
@ -599,7 +609,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof FFprobeSession) {
if (session.isFFprobe()) {
final FFprobeSessionExecuteTask ffprobeSessionExecuteTask = new FFprobeSessionExecuteTask((FFprobeSession) session, promise);
asyncExecutorService.submit(ffprobeSessionExecuteTask);
} else {
@ -618,7 +628,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof MediaInformationSession) {
if (session.isMediaInformation()) {
final int timeout;
if (isValidPositiveNumber(waitTimeout)) {
timeout = waitTimeout.intValue();
@ -643,7 +653,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof FFmpegSession) {
if (session.isFFmpeg()) {
FFmpegKitConfig.asyncFFmpegExecute((FFmpegSession) session);
promise.resolve(null);
} else {
@ -662,7 +672,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof FFprobeSession) {
if (session.isFFprobe()) {
FFmpegKitConfig.asyncFFprobeExecute((FFprobeSession) session);
promise.resolve(null);
} else {
@ -681,7 +691,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session instanceof MediaInformationSession) {
if (session.isMediaInformation()) {
final int timeout;
if (isValidPositiveNumber(waitTimeout)) {
timeout = waitTimeout.intValue();
@ -932,7 +942,12 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
@ReactMethod
public void getFFprobeSessions(final Promise promise) {
promise.resolve(toSessionArray(FFprobeKit.listSessions()));
promise.resolve(toSessionArray(FFprobeKit.listFFprobeSessions()));
}
@ReactMethod
public void getMediaInformationSessions(final Promise promise) {
promise.resolve(toSessionArray(FFprobeKit.listMediaInformationSessions()));
}
// Packages
@ -980,7 +995,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
sessionMap.putString(KEY_SESSION_COMMAND, session.getCommand());
if (session.isFFprobe()) {
if (session instanceof MediaInformationSession) {
if (session.isMediaInformation()) {
final MediaInformationSession mediaInformationSession = (MediaInformationSession) session;
final MediaInformation mediaInformation = mediaInformationSession.getMediaInformation();
if (mediaInformation != null) {

View File

@ -61,7 +61,7 @@ static int const SESSION_TYPE_MEDIA_INFORMATION = 3;
// EVENTS
static NSString *const EVENT_LOG_CALLBACK_EVENT = @"FFmpegKitLogCallbackEvent";
static NSString *const EVENT_STATISTICS_CALLBACK_EVENT = @"FFmpegKitStatisticsCallbackEvent";
static NSString *const EVENT_EXECUTE_CALLBACK_EVENT = @"FFmpegKitExecuteCallbackEvent";
static NSString *const EVENT_COMPLETE_CALLBACK_EVENT = @"FFmpegKitCompleteCallbackEvent";
extern int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit;
@ -91,15 +91,25 @@ RCT_EXPORT_MODULE(FFmpegKitReactNativeModule);
[array addObject:EVENT_LOG_CALLBACK_EVENT];
[array addObject:EVENT_STATISTICS_CALLBACK_EVENT];
[array addObject:EVENT_EXECUTE_CALLBACK_EVENT];
[array addObject:EVENT_COMPLETE_CALLBACK_EVENT];
return array;
}
- (void)registerGlobalCallbacks {
[FFmpegKitConfig enableExecuteCallback:^(id<Session> session){
[FFmpegKitConfig enableFFmpegSessionCompleteCallback:^(FFmpegSession* session){
NSDictionary *dictionary = [FFmpegKitReactNativeModule toSessionDictionary:session];
[self sendEventWithName:EVENT_EXECUTE_CALLBACK_EVENT body:dictionary];
[self sendEventWithName:EVENT_COMPLETE_CALLBACK_EVENT body:dictionary];
}];
[FFmpegKitConfig enableFFprobeSessionCompleteCallback:^(FFprobeSession* session){
NSDictionary *dictionary = [FFmpegKitReactNativeModule toSessionDictionary:session];
[self sendEventWithName:EVENT_COMPLETE_CALLBACK_EVENT body:dictionary];
}];
[FFmpegKitConfig enableMediaInformationSessionCompleteCallback:^(MediaInformationSession* session){
NSDictionary *dictionary = [FFmpegKitReactNativeModule toSessionDictionary:session];
[self sendEventWithName:EVENT_COMPLETE_CALLBACK_EVENT body:dictionary];
}];
[FFmpegKitConfig enableLogCallback: ^(Log* log){
@ -234,7 +244,7 @@ RCT_EXPORT_METHOD(getArch:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRe
// FFmpegSession
RCT_EXPORT_METHOD(ffmpegSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withExecuteCallback:nil withLogCallback:nil withStatisticsCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
FFmpegSession* session = [[FFmpegSession alloc] init:arguments withCompleteCallback:nil withLogCallback:nil withStatisticsCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
resolve([FFmpegKitReactNativeModule toSessionDictionary:session]);
}
@ -243,7 +253,7 @@ RCT_EXPORT_METHOD(ffmpegSessionGetAllStatistics:(int)sessionId withTimeout:(int)
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[FFmpegSession class]]) {
if ([session isFFmpeg]) {
int timeout;
if ([FFmpegKitReactNativeModule isValidPositiveNumber:waitTimeout]) {
timeout = waitTimeout;
@ -263,7 +273,7 @@ RCT_EXPORT_METHOD(ffmpegSessionGetStatistics:(int)sessionId resolver:(RCTPromise
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[FFmpegSession class]]) {
if ([session isFFmpeg]) {
NSArray* statistics = [(FFmpegSession*)session getStatistics];
resolve([FFmpegKitReactNativeModule toStatisticsArray:statistics]);
} else {
@ -275,14 +285,14 @@ RCT_EXPORT_METHOD(ffmpegSessionGetStatistics:(int)sessionId resolver:(RCTPromise
// FFprobeSession
RCT_EXPORT_METHOD(ffprobeSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withExecuteCallback:nil withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
FFprobeSession* session = [[FFprobeSession alloc] init:arguments withCompleteCallback:nil withLogCallback:nil withLogRedirectionStrategy:LogRedirectionStrategyNeverPrintLogs];
resolve([FFmpegKitReactNativeModule toSessionDictionary:session]);
}
// MediaInformationSession
RCT_EXPORT_METHOD(mediaInformationSession:(NSArray*)arguments resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withExecuteCallback:nil withLogCallback:nil];
MediaInformationSession* session = [[MediaInformationSession alloc] init:arguments withCompleteCallback:nil withLogCallback:nil];
resolve([FFmpegKitReactNativeModule toSessionDictionary:session]);
}
@ -409,7 +419,7 @@ RCT_EXPORT_METHOD(ffmpegSessionExecute:(int)sessionId resolver:(RCTPromiseResolv
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[FFmpegSession class]]) {
if ([session isFFmpeg]) {
dispatch_async(asyncDispatchQueue, ^{
[FFmpegKitConfig ffmpegExecute:(FFmpegSession*)session];
resolve(nil);
@ -425,7 +435,7 @@ RCT_EXPORT_METHOD(ffprobeSessionExecute:(int)sessionId resolver:(RCTPromiseResol
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[FFprobeSession class]]) {
if ([session isFFprobe]) {
dispatch_async(asyncDispatchQueue, ^{
[FFmpegKitConfig ffprobeExecute:(FFprobeSession*)session];
resolve(nil);
@ -441,7 +451,7 @@ RCT_EXPORT_METHOD(mediaInformationSessionExecute:(int)sessionId withTimeout:(int
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[MediaInformationSession class]]) {
if ([session isMediaInformation]) {
int timeout;
if ([FFmpegKitReactNativeModule isValidPositiveNumber:waitTimeout]) {
timeout = waitTimeout;
@ -462,7 +472,7 @@ RCT_EXPORT_METHOD(asyncFFmpegSessionExecute:(int)sessionId resolver:(RCTPromiseR
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[FFmpegSession class]]) {
if ([session isFFmpeg]) {
[FFmpegKitConfig asyncFFmpegExecute:(FFmpegSession*)session];
resolve(nil);
} else {
@ -476,7 +486,7 @@ RCT_EXPORT_METHOD(asyncFFprobeSessionExecute:(int)sessionId resolver:(RCTPromise
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[FFprobeSession class]]) {
if ([session isFFprobe]) {
[FFmpegKitConfig asyncFFprobeExecute:(FFprobeSession*)session];
resolve(nil);
} else {
@ -490,7 +500,7 @@ RCT_EXPORT_METHOD(asyncMediaInformationSessionExecute:(int)sessionId withTimeout
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMemberOfClass:[MediaInformationSession class]]) {
if ([session isMediaInformation]) {
int timeout;
if ([FFmpegKitReactNativeModule isValidPositiveNumber:waitTimeout]) {
timeout = waitTimeout;
@ -652,7 +662,11 @@ RCT_EXPORT_METHOD(getFFmpegSessions:(RCTPromiseResolveBlock)resolve rejecter:(RC
// FFprobeKit
RCT_EXPORT_METHOD(getFFprobeSessions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
resolve([FFmpegKitReactNativeModule toSessionArray:[FFprobeKit listSessions]]);
resolve([FFmpegKitReactNativeModule toSessionArray:[FFprobeKit listFFprobeSessions]]);
}
RCT_EXPORT_METHOD(getMediaInformationSessions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
resolve([FFmpegKitReactNativeModule toSessionArray:[FFprobeKit listMediaInformationSessions]]);
}
// Packages
@ -695,7 +709,7 @@ RCT_EXPORT_METHOD(getExternalLibraries:(RCTPromiseResolveBlock)resolve rejecter:
dictionary[KEY_SESSION_COMMAND] = [session getCommand];
if ([session isFFprobe]) {
if ([(AbstractSession*)session isMemberOfClass:[MediaInformationSession class]]) {
if ([session isMediaInformation]) {
MediaInformationSession *mediaInformationSession = (MediaInformationSession*)session;
dictionary[KEY_SESSION_MEDIA_INFORMATION] = [FFmpegKitReactNativeModule toMediaInformationDictionary:[mediaInformationSession getMediaInformation]];
dictionary[KEY_SESSION_TYPE] = [NSNumber numberWithInt:SESSION_TYPE_MEDIA_INFORMATION];

View File

@ -16,8 +16,6 @@ declare module 'ffmpeg-kit-react-native' {
static createMediaInformationSessionFromMap(sessionMap: { [key: string]: any }): MediaInformationSession;
getExecuteCallback(): ExecuteCallback;
getLogCallback(): LogCallback;
getSessionId(): number;
@ -58,6 +56,8 @@ declare module 'ffmpeg-kit-react-native' {
isFFprobe(): boolean;
isMediaInformation(): boolean;
cancel(): Promise<void>;
}
@ -68,17 +68,19 @@ declare module 'ffmpeg-kit-react-native' {
}
export type ExecuteCallback = (session: Session) => void;
export type FFmpegSessionCompleteCallback = (session: FFmpegSession) => void;
export type FFprobeSessionCompleteCallback = (session: FFprobeSession) => void;
export type MediaInformationSessionCompleteCallback = (session: MediaInformationSession) => void;
export class FFmpegKit {
static execute(command: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static execute(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeWithArguments(commandArguments: string[], executeCallback?: ExecuteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeWithArguments(commandArguments: string[], completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeAsync(command: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeAsync(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeWithArgumentsAsync(commandArguments: string[], executeCallback?: ExecuteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeWithArgumentsAsync(commandArguments: string[], completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static cancel(sessionId?: number): Promise<void>;
@ -132,7 +134,17 @@ declare module 'ffmpeg-kit-react-native' {
static enableStatisticsCallback(statisticsCallback: StatisticsCallback): void;
static enableExecuteCallback(executeCallback: ExecuteCallback): void;
static enableFFmpegSessionCompleteCallback(completeCallback: FFmpegSessionCompleteCallback): void;
static getFFmpegSessionCompleteCallback(): FFmpegSessionCompleteCallback;
static enableFFprobeSessionCompleteCallback(completeCallback: FFprobeSessionCompleteCallback): void;
static getFFprobeSessionCompleteCallback(): FFprobeSessionCompleteCallback;
static enableMediaInformationSessionCompleteCallback(completeCallback: MediaInformationSessionCompleteCallback): void;
static getMediaInformationSessionCompleteCallback(): MediaInformationSessionCompleteCallback;
static getLogLevel(): Level;
@ -152,6 +164,12 @@ declare module 'ffmpeg-kit-react-native' {
static clearSessions(): Promise<void>;
static getFFmpegSessions(): Promise<FFmpegSession[]>;
static getFFprobeSessions(): Promise<FFprobeSession[]>;
static getMediaInformationSessions(): Promise<MediaInformationSession[]>;
static getSessionsByState(state): Promise<Session[]>;
static getLogRedirectionStrategy(): LogRedirectionStrategy;
@ -192,12 +210,14 @@ declare module 'ffmpeg-kit-react-native' {
constructor();
static create(argumentsArray: Array<string>, executeCallback?: ExecuteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>;
static create(argumentsArray: Array<string>, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFmpegSession>;
static fromMap(sessionMap: { [key: string]: any }): FFmpegSession;
getStatisticsCallback(): StatisticsCallback;
getCompleteCallback(): FFmpegSessionCompleteCallback;
getAllStatistics(waitTimeout?: number): Promise<Array<Statistics>>;
getStatistics(): Promise<Array<Statistics>>;
@ -208,31 +228,35 @@ declare module 'ffmpeg-kit-react-native' {
isFFprobe(): boolean;
isMediaInformation(): boolean;
}
export class FFprobeKit {
static execute(command: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static execute(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArguments(commandArguments: string[], executeCallback?: ExecuteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeAsync(command: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeAsync(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArgumentsAsync(commandArguments: string[], executeCallback?: ExecuteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArgumentsAsync(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static getMediaInformation(path: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformation(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommand(command: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommand(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArguments(commandArguments: string[], executeCallback?: ExecuteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationAsync(path: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationAsync(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandAsync(command: string, executeCallback?: ExecuteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandAsync(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArgumentsAsync(commandArguments: string[], executeCallback?: ExecuteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArgumentsAsync(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static listSessions(): Promise<FFprobeSession[]>;
static listFFprobeSessions(): Promise<FFprobeSession[]>;
static listMediaInformationSessions(): Promise<MediaInformationSession[]>;
}
@ -240,14 +264,18 @@ declare module 'ffmpeg-kit-react-native' {
constructor();
static create(argumentsArray: Array<string>, executeCallback?: ExecuteCallback, logCallback?: LogCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFprobeSession>;
static create(argumentsArray: Array<string>, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, logRedirectionStrategy?: LogRedirectionStrategy): Promise<FFprobeSession>;
static fromMap(sessionMap: { [key: string]: any }): FFprobeSession;
getCompleteCallback(): FFprobeSessionCompleteCallback;
isFFmpeg(): boolean;
isFFprobe(): boolean;
isMediaInformation(): boolean;
}
export class Level {
@ -341,11 +369,11 @@ declare module 'ffmpeg-kit-react-native' {
}
export class MediaInformationSession extends FFprobeSession {
export class MediaInformationSession extends AbstractSession implements Session {
constructor();
static create(argumentsArray: Array<string>, executeCallback?: ExecuteCallback, logCallback?: LogCallback): Promise<MediaInformationSession>;
static create(argumentsArray: Array<string>, completeCallback?: MediaInformationSessionCompleteCallback, logCallback?: LogCallback): Promise<MediaInformationSession>;
static fromMap(sessionMap: { [key: string]: any }): MediaInformationSession;
@ -353,6 +381,14 @@ declare module 'ffmpeg-kit-react-native' {
setMediaInformation(mediaInformation: MediaInformation): void;
getCompleteCallback(): MediaInformationSessionCompleteCallback;
isFFmpeg(): boolean;
isFFprobe(): boolean;
isMediaInformation(): boolean;
}
export class Packages {
@ -387,8 +423,6 @@ declare module 'ffmpeg-kit-react-native' {
export interface Session {
getExecuteCallback(): ExecuteCallback;
getLogCallback(): LogCallback;
getSessionId(): number;
@ -429,6 +463,8 @@ declare module 'ffmpeg-kit-react-native' {
isFFprobe(): boolean;
isMediaInformation(): boolean;
cancel(): Promise<void>;
}

View File

@ -2,14 +2,16 @@ import {NativeEventEmitter, NativeModules} from 'react-native';
const {FFmpegKitReactNativeModule} = NativeModules;
const executeCallbackMap = new Map()
const ffmpegSessionCompleteCallbackMap = new Map()
const ffprobeSessionCompleteCallbackMap = new Map()
const mediaInformationSessionCompleteCallbackMap = new Map()
const logCallbackMap = new Map()
const statisticsCallbackMap = new Map()
const logRedirectionStrategyMap = new Map()
const eventLogCallbackEvent = "FFmpegKitLogCallbackEvent";
const eventStatisticsCallbackEvent = "FFmpegKitStatisticsCallbackEvent";
const eventExecuteCallbackEvent = "FFmpegKitExecuteCallbackEvent";
const eventCompleteCallbackEvent = "FFmpegKitCompleteCallbackEvent";
export const LogRedirectionStrategy = {
ALWAYS_PRINT_LOGS: 0,
@ -59,17 +61,9 @@ class FFmpegKitReactNativeEventEmitter extends NativeEventEmitter {
export class Session {
/**
* Returns the session specific execute callback function.
* Returns the session specific log callback.
*
* @return session specific execute callback function
*/
getExecuteCallback() {
}
/**
* Returns the session specific log callback function.
*
* @return session specific log callback function
* @return session specific log callback
*/
getLogCallback() {
}
@ -245,6 +239,14 @@ export class Session {
isFFprobe() {
}
/**
* Returns whether it is a <code>MediaInformation</code> session or not.
*
* @return true if it is a <code>MediaInformation</code> session, false otherwise
*/
isMediaInformation() {
}
/**
* Cancels running the session.
*/
@ -254,8 +256,8 @@ export class Session {
}
/**
* Abstract session implementation which includes common features shared by <code>FFmpeg</code>
* and <code>FFprobe</code> sessions.
* Abstract session implementation which includes common features shared by <code>FFmpeg</code>,
* <code>FFprobe</code> and <code>MediaInformation</code> sessions.
*/
export class AbstractSession extends Session {
@ -445,18 +447,9 @@ export class AbstractSession extends Session {
}
/**
* Returns the session specific execute callback function.
* Returns the session specific log callback.
*
* @return session specific execute callback function
*/
getExecuteCallback() {
return FFmpegKitFactory.getExecuteCallback(this.getSessionId())
}
/**
* Returns the session specific log callback function.
*
* @return session specific log callback function
* @return session specific log callback
*/
getLogCallback() {
return FFmpegKitFactory.getLogCallback(this.getSessionId())
@ -666,6 +659,15 @@ export class AbstractSession extends Session {
return false;
}
/**
* Returns whether it is a <code>MediaInformation</code> session or not.
*
* @return true if it is a <code>MediaInformation</code> session, false otherwise
*/
isMediaInformation() {
return false;
}
/**
* Cancels running the session.
*/
@ -707,26 +709,26 @@ export class FFmpegKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async execute(command, executeCallback, logCallback, statisticsCallback) {
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback);
static async execute(command, completeCallback, logCallback, statisticsCallback) {
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
}
/**
* <p>Synchronously executes FFmpeg with arguments provided.
*
* @param commandArguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async executeWithArguments(commandArguments, executeCallback, logCallback, statisticsCallback) {
let session = await FFmpegSession.create(commandArguments, executeCallback, logCallback, statisticsCallback);
static async executeWithArguments(commandArguments, completeCallback, logCallback, statisticsCallback) {
let session = await FFmpegSession.create(commandArguments, completeCallback, logCallback, statisticsCallback);
await FFmpegKitConfig.ffmpegExecute(session);
@ -738,32 +740,32 @@ export class FFmpegKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFmpeg command
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async executeAsync(command, executeCallback, logCallback, statisticsCallback) {
return FFmpegKit.executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, statisticsCallback);
static async executeAsync(command, completeCallback, logCallback, statisticsCallback) {
return FFmpegKit.executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
}
/**
* <p>Starts an asynchronous FFmpeg execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param commandArguments FFmpeg command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async executeWithArgumentsAsync(commandArguments, executeCallback, logCallback, statisticsCallback) {
let session = await FFmpegSession.create(commandArguments, executeCallback, logCallback, statisticsCallback);
static async executeWithArgumentsAsync(commandArguments, completeCallback, logCallback, statisticsCallback) {
let session = await FFmpegSession.create(commandArguments, completeCallback, logCallback, statisticsCallback);
await FFmpegKitConfig.asyncFFmpegExecute(session);
@ -773,7 +775,7 @@ export class FFmpegKit {
/**
* <p>Cancels the session specified with <code>sessionId</code>.
*
* <p>This function does not wait for termination to complete and returns immediately.
* <p>This method does not wait for termination to complete and returns immediately.
*
* @param sessionId id of the session that will be cancelled
*/
@ -1019,7 +1021,7 @@ export class FFmpegKitConfig {
* <p>Starts an asynchronous FFmpeg execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFmpegSessionCompleteCallback if you want to be notified about the result.
*
* @param ffmpegSession FFmpeg session which includes command options/arguments
*/
@ -1033,7 +1035,7 @@ export class FFmpegKitConfig {
* <p>Starts an asynchronous FFprobe execution for the given session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param ffprobeSession FFprobe session which includes command options/arguments
*/
@ -1047,7 +1049,7 @@ export class FFmpegKitConfig {
* <p>Starts an asynchronous FFprobe execution for the given media information session.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param mediaInformationSession media information session which includes command options/arguments
* @param waitTimeout max time to wait until media information is transmitted
@ -1059,9 +1061,9 @@ export class FFmpegKitConfig {
}
/**
* <p>Sets a global callback function to redirect FFmpeg/FFprobe logs.
* <p>Sets a global callback to redirect FFmpeg/FFprobe logs.
*
* @param logCallback log callback function or undefined to disable a previously defined
* @param logCallback log callback or undefined to disable a previously defined
* callback
*/
static enableLogCallback(logCallback) {
@ -1069,9 +1071,9 @@ export class FFmpegKitConfig {
}
/**
* <p>Sets a global callback function to redirect FFmpeg statistics.
* <p>Sets a global callback to redirect FFmpeg statistics.
*
* @param statisticsCallback statistics callback function or undefined to disable a previously
* @param statisticsCallback statistics callback or undefined to disable a previously
* defined callback
*/
static enableStatisticsCallback(statisticsCallback) {
@ -1079,13 +1081,58 @@ export class FFmpegKitConfig {
}
/**
* <p>Sets a global callback function to receive execution results.
* <p>Sets a global FFmpegSessionCompleteCallback to receive execution results for FFmpeg sessions.
*
* @param executeCallback execute callback function or undefined to disable a previously
* defined callback
* @param ffmpegSessionCompleteCallback complete callback or undefined to disable a previously defined callback
*/
static enableExecuteCallback(executeCallback) {
FFmpegKitFactory.setGlobalExecuteCallback(executeCallback);
static enableFFmpegSessionCompleteCallback(ffmpegSessionCompleteCallback) {
FFmpegKitFactory.setGlobalFFmpegSessionCompleteCallback(ffmpegSessionCompleteCallback);
}
/**
* <p>Returns the global FFmpegSessionCompleteCallback set.
*
* @return global FFmpegSessionCompleteCallback or undefined if it is not set
*/
static getFFmpegSessionCompleteCallback() {
return FFmpegKitFactory.getGlobalFFmpegSessionCompleteCallback();
}
/**
* <p>Sets a global FFprobeSessionCompleteCallback to receive execution results for FFprobe sessions.
*
* @param ffprobeSessionCompleteCallback complete callback or undefined to disable a previously defined callback
*/
static enableFFprobeSessionCompleteCallback(ffprobeSessionCompleteCallback) {
FFmpegKitFactory.setGlobalFFprobeSessionCompleteCallback(ffprobeSessionCompleteCallback);
}
/**
* <p>Returns the global FFprobeSessionCompleteCallback set.
*
* @return global FFprobeSessionCompleteCallback or undefined if it is not set
*/
static getFFprobeSessionCompleteCallback() {
return FFmpegKitFactory.getGlobalFFprobeSessionCompleteCallback();
}
/**
* <p>Sets a global MediaInformationSessionCompleteCallback to receive execution results for MediaInformation sessions.
*
* @param mediaInformationSessionCompleteCallback complete callback or undefined to disable a previously defined
* callback
*/
static enableMediaInformationSessionCompleteCallback(mediaInformationSessionCompleteCallback) {
FFmpegKitFactory.setGlobalMediaInformationSessionCompleteCallback(mediaInformationSessionCompleteCallback);
}
/**
* <p>Returns the global MediaInformationSessionCompleteCallback set.
*
* @return global MediaInformationSessionCompleteCallback or undefined if it is not set
*/
static getMediaInformationSessionCompleteCallback() {
return FFmpegKitFactory.getGlobalMediaInformationSessionCompleteCallback();
}
/**
@ -1195,6 +1242,42 @@ export class FFmpegKitConfig {
return FFmpegKitReactNativeModule.clearSessions();
}
/**
* <p>Returns all FFmpeg sessions in the session history.
*
* @return all FFmpeg sessions in the session history
*/
static async getFFmpegSessions() {
await FFmpegKitConfig.init();
const sessionArray = await FFmpegKitReactNativeModule.getFFmpegSessions();
return sessionArray.map(FFmpegKitFactory.mapToSession);
}
/**
* <p>Returns all FFprobe sessions in the session history.
*
* @return all FFprobe sessions in the session history
*/
static async getFFprobeSessions() {
await FFmpegKitConfig.init();
const sessionArray = await FFmpegKitReactNativeModule.getFFprobeSessions();
return sessionArray.map(FFmpegKitFactory.mapToSession);
}
/**
* <p>Returns all MediaInformation sessions in the session history.
*
* @return all MediaInformation sessions in the session history
*/
static async getMediaInformationSessions() {
await FFmpegKitConfig.init();
const sessionArray = await FFmpegKitReactNativeModule.getMediaInformationSessions();
return sessionArray.map(FFmpegKitFactory.mapToSession);
}
/**
* <p>Returns sessions that have the given state.
*
@ -1475,9 +1558,11 @@ export class FFmpegKitConfig {
class FFmpegKitFactory {
static #ffmpegSessionCompleteCallback = undefined;
static #ffprobeSessionCompleteCallback = undefined;
static #mediaInformationSessionCompleteCallback = undefined;
static #logCallback = undefined;
static #statisticsCallback = undefined;
static #executeCallback = undefined;
static #activeLogLevel = undefined;
static mapToStatistics(statisticsMap) {
@ -1560,22 +1645,58 @@ class FFmpegKitFactory {
this.#statisticsCallback = statisticsCallback;
}
static getExecuteCallback(sessionId) {
return executeCallbackMap.get(sessionId);
static getFFmpegSessionCompleteCallback(sessionId) {
return ffmpegSessionCompleteCallbackMap.get(sessionId);
}
static setExecuteCallback(sessionId, executeCallback) {
if (executeCallback !== undefined) {
executeCallbackMap.set(sessionId, executeCallback);
static setFFmpegSessionCompleteCallback(sessionId, completeCallback) {
if (completeCallback !== undefined) {
ffmpegSessionCompleteCallbackMap.set(sessionId, completeCallback);
}
}
static getGlobalExecuteCallback() {
return this.#executeCallback;
static getGlobalFFmpegSessionCompleteCallback() {
return this.#ffmpegSessionCompleteCallback;
}
static setGlobalExecuteCallback(executeCallback) {
this.#executeCallback = executeCallback;
static setGlobalFFmpegSessionCompleteCallback(completeCallback) {
this.#ffmpegSessionCompleteCallback = completeCallback;
}
static getFFprobeSessionCompleteCallback(sessionId) {
return ffprobeSessionCompleteCallbackMap.get(sessionId);
}
static setFFprobeSessionCompleteCallback(sessionId, completeCallback) {
if (completeCallback !== undefined) {
ffprobeSessionCompleteCallbackMap.set(sessionId, completeCallback);
}
}
static getGlobalFFprobeSessionCompleteCallback() {
return this.#ffprobeSessionCompleteCallback;
}
static setGlobalFFprobeSessionCompleteCallback(completeCallback) {
this.#ffprobeSessionCompleteCallback = completeCallback;
}
static getMediaInformationSessionCompleteCallback(sessionId) {
return mediaInformationSessionCompleteCallbackMap.get(sessionId);
}
static setMediaInformationSessionCompleteCallback(sessionId, completeCallback) {
if (completeCallback !== undefined) {
mediaInformationSessionCompleteCallbackMap.set(sessionId, completeCallback);
}
}
static getGlobalMediaInformationSessionCompleteCallback() {
return this.#mediaInformationSessionCompleteCallback;
}
static setGlobalMediaInformationSessionCompleteCallback(completeCallback) {
this.#mediaInformationSessionCompleteCallback = completeCallback;
}
static setLogLevel(logLevel) {
@ -1631,7 +1752,7 @@ class FFmpegKitInitializer {
// NOTIFY SESSION CALLBACK DEFINED
activeLogCallback(log);
} catch (err) {
console.log("Exception thrown inside session LogCallback block.", err.stack);
console.log("Exception thrown inside session log callback.", err.stack);
}
}
@ -1643,7 +1764,7 @@ class FFmpegKitInitializer {
// NOTIFY GLOBAL CALLBACK DEFINED
globalLogCallbackFunction(log);
} catch (err) {
console.log("Exception thrown inside global LogCallback block.", err.stack);
console.log("Exception thrown inside global log callback.", err.stack);
}
}
@ -1697,7 +1818,7 @@ class FFmpegKitInitializer {
// NOTIFY SESSION CALLBACK DEFINED
activeStatisticsCallback(statistics);
} catch (err) {
console.log("Exception thrown inside session StatisticsCallback block.", err.stack);
console.log("Exception thrown inside session statistics callback.", err.stack);
}
}
@ -1707,34 +1828,60 @@ class FFmpegKitInitializer {
// NOTIFY GLOBAL CALLBACK DEFINED
globalStatisticsCallbackFunction(statistics);
} catch (err) {
console.log("Exception thrown inside global StatisticsCallback block.", err.stack);
console.log("Exception thrown inside global statistics callback.", err.stack);
}
}
}
static processExecuteCallbackEvent(event) {
let sessionId = event.sessionId;
static processCompleteCallbackEvent(event) {
if (event !== undefined) {
let sessionId = event.sessionId;
FFmpegKitConfig.getSession(sessionId).then(session => {
if (session.getExecuteCallback() !== undefined) {
try {
// NOTIFY SESSION CALLBACK DEFINED
session.getExecuteCallback()(session);
} catch (err) {
console.log("Exception thrown inside session ExecuteCallback block.", err.stack);
}
}
FFmpegKitConfig.getSession(sessionId).then(session => {
if (session !== undefined) {
if (session.getCompleteCallback() !== undefined) {
try {
// NOTIFY SESSION CALLBACK DEFINED
session.getCompleteCallback()(session);
} catch (err) {
console.log("Exception thrown inside session complete callback.", err.stack);
}
}
let globalExecuteCallbackFunction = FFmpegKitFactory.getGlobalExecuteCallback();
if (globalExecuteCallbackFunction !== undefined) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalExecuteCallbackFunction(session);
} catch (err) {
console.log("Exception thrown inside global ExecuteCallback block.", err.stack);
if (session.isFFmpeg()) {
let globalFFmpegSessionCompleteCallback = FFmpegKitFactory.getGlobalFFmpegSessionCompleteCallback();
if (globalFFmpegSessionCompleteCallback !== undefined) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalFFmpegSessionCompleteCallback(session);
} catch (err) {
console.log("Exception thrown inside global complete callback.", err.stack);
}
}
} else if (session.isFFprobe()) {
let globalFFprobeSessionCompleteCallback = FFmpegKitFactory.getGlobalFFprobeSessionCompleteCallback();
if (globalFFprobeSessionCompleteCallback !== undefined) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalFFprobeSessionCompleteCallback(session);
} catch (err) {
console.log("Exception thrown inside global complete callback.", err.stack);
}
}
} else if (session.isMediaInformation()) {
let globalMediaInformationSessionCompleteCallback = FFmpegKitFactory.getGlobalMediaInformationSessionCompleteCallback();
if (globalMediaInformationSessionCompleteCallback !== undefined) {
try {
// NOTIFY GLOBAL CALLBACK DEFINED
globalMediaInformationSessionCompleteCallback(session);
} catch (err) {
console.log("Exception thrown inside global complete callback.", err.stack);
}
}
}
}
}
});
});
}
}
static async initialize() {
@ -1748,7 +1895,7 @@ class FFmpegKitInitializer {
this.#eventEmitter.addListener(eventLogCallbackEvent, FFmpegKitInitializer.processLogCallbackEvent);
this.#eventEmitter.addListener(eventStatisticsCallbackEvent, FFmpegKitInitializer.processStatisticsCallbackEvent);
this.#eventEmitter.addListener(eventExecuteCallbackEvent, FFmpegKitInitializer.processExecuteCallbackEvent);
this.#eventEmitter.addListener(eventCompleteCallbackEvent, FFmpegKitInitializer.processCompleteCallbackEvent);
FFmpegKitFactory.setLogLevel(await FFmpegKitReactNativeModule.getLogLevel());
const version = FFmpegKitFactory.getVersion();
@ -1779,17 +1926,17 @@ export class FFmpegSession extends AbstractSession {
* Creates a new FFmpeg session.
*
* @param argumentsArray FFmpeg command arguments
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @param logRedirectionStrategy defines how logs will be redirected
* @returns FFmpeg session created
*/
static async create(argumentsArray, executeCallback, logCallback, statisticsCallback, logRedirectionStrategy) {
static async create(argumentsArray, completeCallback, logCallback, statisticsCallback, logRedirectionStrategy) {
const session = await AbstractSession.createFFmpegSession(argumentsArray, logRedirectionStrategy);
const sessionId = session.getSessionId();
FFmpegKitFactory.setExecuteCallback(sessionId, executeCallback);
FFmpegKitFactory.setFFmpegSessionCompleteCallback(sessionId, completeCallback);
FFmpegKitFactory.setLogCallback(sessionId, logCallback);
FFmpegKitFactory.setStatisticsCallback(sessionId, statisticsCallback);
@ -1807,14 +1954,23 @@ export class FFmpegSession extends AbstractSession {
}
/**
* Returns the session specific statistics callback function.
* Returns the session specific statistics callback.
*
* @return session specific statistics callback function
* @return session specific statistics callback
*/
getStatisticsCallback() {
return FFmpegKitFactory.getStatisticsCallback(this.getSessionId());
}
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
getCompleteCallback() {
return FFmpegKitFactory.getFFmpegSessionCompleteCallback(this.getSessionId());
}
/**
* 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.
@ -1867,6 +2023,10 @@ export class FFmpegSession extends AbstractSession {
return false;
}
isMediaInformation() {
return false;
}
}
/**
@ -1879,24 +2039,24 @@ export class FFprobeKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async execute(command, executeCallback, logCallback) {
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback);
static async execute(command, completeCallback, logCallback) {
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
}
/**
* <p>Synchronously executes FFprobe with arguments provided.
*
* @param commandArguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async executeWithArguments(commandArguments, executeCallback, logCallback) {
let session = await FFprobeSession.create(commandArguments, executeCallback, logCallback);
static async executeWithArguments(commandArguments, completeCallback, logCallback) {
let session = await FFprobeSession.create(commandArguments, completeCallback, logCallback);
await FFmpegKitConfig.ffprobeExecute(session);
@ -1908,30 +2068,30 @@ export class FFprobeKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async executeAsync(command, executeCallback, logCallback) {
return FFprobeKit.executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback);
static async executeAsync(command, completeCallback, logCallback) {
return FFprobeKit.executeWithArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
}
/**
* <p>Starts an asynchronous FFprobe execution with arguments provided.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* FFprobeSessionCompleteCallback if you want to be notified about the result.
*
* @param commandArguments FFprobe command options/arguments as string array
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async executeWithArgumentsAsync(commandArguments, executeCallback, logCallback) {
let session = await FFprobeSession.create(commandArguments, executeCallback, logCallback);
static async executeWithArgumentsAsync(commandArguments, completeCallback, logCallback) {
let session = await FFprobeSession.create(commandArguments, completeCallback, logCallback);
await FFmpegKitConfig.asyncFFprobeExecute(session);
@ -1942,14 +2102,14 @@ export class FFprobeKit {
* <p>Extracts media information for the file specified with path.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformation(path, executeCallback, logCallback, waitTimeout) {
static async getMediaInformation(path, completeCallback, logCallback, waitTimeout) {
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, executeCallback, logCallback, waitTimeout);
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout);
}
/**
@ -1957,13 +2117,13 @@ export class FFprobeKit {
* this method must generate the output in JSON format in order to successfully extract media information from it.
*
* @param command FFprobe command that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommand(command, executeCallback, logCallback, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, waitTimeout);
static async getMediaInformationFromCommand(command, completeCallback, logCallback, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, waitTimeout);
}
/**
@ -1972,13 +2132,13 @@ export class FFprobeKit {
* from it.
*
* @param commandArguments FFprobe command arguments that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommandArguments(commandArguments, executeCallback, logCallback, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, executeCallback, logCallback);
static async getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, completeCallback, logCallback);
await FFmpegKitConfig.getMediaInformationExecute(session, waitTimeout);
@ -1989,17 +2149,17 @@ export class FFprobeKit {
* <p>Starts an asynchronous FFprobe execution to extract the media information for the specified file.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param path path or uri of a media file
* @param executeCallback callback that will be notified when execution is completed
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationAsync(path, executeCallback, logCallback, waitTimeout) {
static async getMediaInformationAsync(path, completeCallback, logCallback, waitTimeout) {
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
return FFprobeKit.getMediaInformationFromCommandArgumentsAsync(commandArguments, executeCallback, logCallback, waitTimeout);
return FFprobeKit.getMediaInformationFromCommandArgumentsAsync(commandArguments, completeCallback, logCallback, waitTimeout);
}
/**
@ -2007,16 +2167,16 @@ export class FFprobeKit {
* this method must generate the output in JSON format in order to successfully extract media information from it.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param command FFprobe command that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommandAsync(command, executeCallback, logCallback, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArgumentsAsync(FFmpegKitConfig.parseArguments(command), executeCallback, logCallback, waitTimeout);
static async getMediaInformationFromCommandAsync(command, completeCallback, logCallback, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArgumentsAsync(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, waitTimeout);
}
/**
@ -2025,16 +2185,16 @@ export class FFprobeKit {
* from it.
*
* <p>Note that this method returns immediately and does not wait the execution to complete. You must use an
* ExecuteCallback if you want to be notified about the result.
* MediaInformationSessionCompleteCallback if you want to be notified about the result.
*
* @param commandArguments FFprobe command arguments that prints media information for a file in JSON format
* @param executeCallback callback that will be notified when execution is completed
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommandArgumentsAsync(commandArguments, executeCallback, logCallback, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, executeCallback, logCallback);
static async getMediaInformationFromCommandArgumentsAsync(commandArguments, completeCallback, logCallback, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, completeCallback, logCallback);
await FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);
@ -2046,13 +2206,25 @@ export class FFprobeKit {
*
* @return all FFprobe sessions in the session history
*/
static async listSessions() {
static async listFFprobeSessions() {
await FFmpegKitConfig.init();
const sessionArray = await FFmpegKitReactNativeModule.getFFprobeSessions();
return sessionArray.map(FFmpegKitFactory.mapToSession);
}
/**
* <p>Lists all MediaInformation sessions in the session history.
*
* @return all MediaInformation sessions in the session history
*/
static async listMediaInformationSessions() {
await FFmpegKitConfig.init();
const sessionArray = await FFmpegKitReactNativeModule.getMediaInformationSessions();
return sessionArray.map(FFmpegKitFactory.mapToSession);
}
}
/**
@ -2071,16 +2243,16 @@ export class FFprobeSession extends AbstractSession {
* Creates a new FFprobe session.
*
* @param argumentsArray FFprobe command arguments
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param logRedirectionStrategy defines how logs will be redirected
* @returns FFprobe session created
*/
static async create(argumentsArray, executeCallback, logCallback, logRedirectionStrategy) {
static async create(argumentsArray, completeCallback, logCallback, logRedirectionStrategy) {
const session = await AbstractSession.createFFprobeSession(argumentsArray, logRedirectionStrategy);
const sessionId = session.getSessionId();
FFmpegKitFactory.setExecuteCallback(sessionId, executeCallback);
FFmpegKitFactory.setFFprobeSessionCompleteCallback(sessionId, completeCallback);
FFmpegKitFactory.setLogCallback(sessionId, logCallback);
return session;
@ -2096,6 +2268,15 @@ export class FFprobeSession extends AbstractSession {
return AbstractSession.createFFprobeSessionFromMap(sessionMap);
}
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
getCompleteCallback() {
return FFmpegKitFactory.getFFprobeSessionCompleteCallback(this.getSessionId());
}
isFFmpeg() {
return false;
}
@ -2104,6 +2285,10 @@ export class FFprobeSession extends AbstractSession {
return true;
}
isMediaInformation() {
return false;
}
}
/**
@ -2469,7 +2654,7 @@ export class MediaInformationJsonParser {
* <p>A custom FFprobe session, which produces a <code>MediaInformation</code> object using the
* FFprobe output.
*/
export class MediaInformationSession extends FFprobeSession {
export class MediaInformationSession extends AbstractSession {
#mediaInformation;
/**
@ -2483,15 +2668,15 @@ export class MediaInformationSession extends FFprobeSession {
* Creates a new MediaInformationSession session.
*
* @param argumentsArray FFprobe command arguments
* @param executeCallback callback that will be called when the execution is completed
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @returns MediaInformationSession session created
*/
static async create(argumentsArray, executeCallback, logCallback) {
static async create(argumentsArray, completeCallback, logCallback) {
const session = await AbstractSession.createMediaInformationSession(argumentsArray);
const sessionId = session.getSessionId();
FFmpegKitFactory.setExecuteCallback(sessionId, executeCallback);
FFmpegKitFactory.setMediaInformationSessionCompleteCallback(sessionId, completeCallback);
FFmpegKitFactory.setLogCallback(sessionId, logCallback);
return session;
@ -2526,6 +2711,27 @@ export class MediaInformationSession extends FFprobeSession {
this.#mediaInformation = mediaInformation;
}
/**
* Returns the session specific complete callback.
*
* @return session specific complete callback
*/
getCompleteCallback() {
return FFmpegKitFactory.getMediaInformationSessionCompleteCallback(this.getSessionId());
}
isFFmpeg() {
return false;
}
isFFprobe() {
return false;
}
isMediaInformation() {
return true;
}
}
/**