Skip to content

Commit

Permalink
fix execute() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed Jan 1, 2022
1 parent 8448f29 commit eaa0b91
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,32 @@ public void getMediaInformationSessions(final Promise promise) {
promise.resolve(toSessionArray(FFprobeKit.listMediaInformationSessions()));
}

// MediaInformationSession

@ReactMethod
public void getMediaInformation(final Double sessionId, final Promise promise) {
if (sessionId != null) {
final Session session = FFmpegKitConfig.getSession(sessionId.longValue());
if (session == null) {
promise.reject("SESSION_NOT_FOUND", "Session not found.");
} else {
if (session.isMediaInformation()) {
final MediaInformationSession mediaInformationSession = (MediaInformationSession) session;
final MediaInformation mediaInformation = mediaInformationSession.getMediaInformation();
if (mediaInformation != null) {
promise.resolve(toMap(mediaInformation));
} else {
promise.resolve(null);
}
} else {
promise.reject("NOT_MEDIA_INFORMATION_SESSION", "A session is found but it does not have the correct type.");
}
}
} else {
promise.reject("INVALID_SESSION", "Invalid session id.");
}
}

// Packages

@ReactMethod
Expand Down
16 changes: 16 additions & 0 deletions react-native/ios/FFmpegKitReactNativeModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,22 @@ - (void)registerGlobalCallbacks {
resolve([FFmpegKitReactNativeModule toSessionArray:[FFprobeKit listMediaInformationSessions]]);
}

// MediaInformationSession

RCT_EXPORT_METHOD(getMediaInformation:(int)sessionId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
AbstractSession* session = (AbstractSession*)[FFmpegKitConfig getSession:sessionId];
if (session == nil) {
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
} else {
if ([session isMediaInformation]) {
MediaInformationSession *mediaInformationSession = (MediaInformationSession*)session;
resolve([FFmpegKitReactNativeModule toMediaInformationDictionary:[mediaInformationSession getMediaInformation]]);
} else {
reject(@"NOT_MEDIA_INFORMATION_SESSION", @"A session is found but it does not have the correct type.", nil);
}
}
}

// Packages

RCT_EXPORT_METHOD(getPackageName:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
Expand Down
14 changes: 7 additions & 7 deletions react-native/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ declare module 'ffmpeg-kit-react-native' {

export class FFmpegKit {

static execute(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static execute(command: string): Promise<FFmpegSession>;

static executeWithArguments(commandArguments: string[], completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
static executeWithArguments(commandArguments: string[]): Promise<FFmpegSession>;

static executeAsync(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;

Expand Down Expand Up @@ -236,19 +236,19 @@ declare module 'ffmpeg-kit-react-native' {

export class FFprobeKit {

static execute(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static execute(command: string): Promise<FFprobeSession>;

static executeWithArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
static executeWithArguments(commandArguments: string[]): Promise<FFprobeSession>;

static executeAsync(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;

static executeWithArgumentsAsync(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;

static getMediaInformation(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformation(path: string, waitTimeout?: number): Promise<MediaInformationSession>;

static getMediaInformationFromCommand(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommand(command: string, waitTimeout?: number): Promise<MediaInformationSession>;

static getMediaInformationFromCommandArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
static getMediaInformationFromCommandArguments(commandArguments: string[], waitTimeout?: number): Promise<MediaInformationSession>;

static getMediaInformationAsync(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;

Expand Down
56 changes: 25 additions & 31 deletions react-native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,26 +709,20 @@ export class FFmpegKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* @param command FFmpeg command
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async execute(command, completeCallback, logCallback, statisticsCallback) {
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
static async execute(command) {
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command));
}

/**
* <p>Synchronously executes FFmpeg with arguments provided.
*
* @param commandArguments FFmpeg command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @param statisticsCallback callback that will receive statistics
* @return FFmpeg session created for this execution
*/
static async executeWithArguments(commandArguments, completeCallback, logCallback, statisticsCallback) {
let session = await FFmpegSession.create(commandArguments, completeCallback, logCallback, statisticsCallback);
static async executeWithArguments(commandArguments) {
let session = await FFmpegSession.create(commandArguments, undefined, undefined, undefined);

await FFmpegKitConfig.ffmpegExecute(session);

Expand Down Expand Up @@ -1614,7 +1608,7 @@ class FFmpegKitFactory {
}

static getVersion() {
return "4.5";
return "4.5.1";
}

static getLogRedirectionStrategy(sessionId) {
Expand Down Expand Up @@ -2055,24 +2049,20 @@ export class FFprobeKit {
* into arguments. You can use single or double quote characters to specify arguments inside your command.
*
* @param command FFprobe command
* @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, completeCallback, logCallback) {
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
static async execute(command) {
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command));
}

/**
* <p>Synchronously executes FFprobe with arguments provided.
*
* @param commandArguments FFprobe command options/arguments as string array
* @param completeCallback callback that will be called when the execution has completed
* @param logCallback callback that will receive logs
* @return FFprobe session created for this execution
*/
static async executeWithArguments(commandArguments, completeCallback, logCallback) {
let session = await FFprobeSession.create(commandArguments, completeCallback, logCallback);
static async executeWithArguments(commandArguments) {
let session = await FFprobeSession.create(commandArguments, undefined, undefined);

await FFmpegKitConfig.ffprobeExecute(session);

Expand Down Expand Up @@ -2118,28 +2108,24 @@ export class FFprobeKit {
* <p>Extracts media information for the file specified with path.
*
* @param path path or uri of a media file
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformation(path, completeCallback, logCallback, waitTimeout) {
static async getMediaInformation(path, waitTimeout) {
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout);
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, waitTimeout);
}

/**
* <p>Extracts media information using the command provided. The command passed to
* 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 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, completeCallback, logCallback, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, waitTimeout);
static async getMediaInformationFromCommand(command, waitTimeout) {
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), waitTimeout);
}

/**
Expand All @@ -2148,16 +2134,19 @@ export class FFprobeKit {
* from it.
*
* @param commandArguments FFprobe command arguments that prints media information for a file in JSON format
* @param completeCallback callback that will be notified when execution has completed
* @param logCallback callback that will receive logs
* @param waitTimeout max time to wait until media information is transmitted
* @return media information session created for this execution
*/
static async getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, completeCallback, logCallback);
static async getMediaInformationFromCommandArguments(commandArguments, waitTimeout) {
let session = await MediaInformationSession.create(commandArguments, undefined, undefined);

await FFmpegKitConfig.getMediaInformationExecute(session, waitTimeout);

const mediaInformation = await FFmpegKitReactNativeModule.getMediaInformation(session.getSessionId());
if (mediaInformation !== undefined && mediaInformation !== null) {
session.setMediaInformation(new MediaInformation(mediaInformation));
}

return session;
}

Expand Down Expand Up @@ -2214,6 +2203,11 @@ export class FFprobeKit {

await FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);

const mediaInformation = await FFmpegKitReactNativeModule.getMediaInformation(session.getSessionId());
if (mediaInformation !== undefined && mediaInformation !== null) {
session.setMediaInformation(new MediaInformation(mediaInformation));
}

return session;
}

Expand Down

0 comments on commit eaa0b91

Please sign in to comment.