mirror of
https://github.com/arthenica/ffmpeg-kit.git
synced 2026-06-06 20:27:34 +00:00
implement execute methods for react-native
This commit is contained in:
+68
-5
@@ -121,14 +121,14 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
|
||||
|
||||
private final AtomicBoolean logsEnabled;
|
||||
private final AtomicBoolean statisticsEnabled;
|
||||
private final ExecutorService asyncWriteToPipeExecutorService;
|
||||
private final ExecutorService asyncExecutorService;
|
||||
|
||||
public FFmpegKitReactNativeModule(@Nullable ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
|
||||
this.logsEnabled = new AtomicBoolean(false);
|
||||
this.statisticsEnabled = new AtomicBoolean(false);
|
||||
this.asyncWriteToPipeExecutorService = Executors.newFixedThreadPool(asyncWriteToPipeConcurrencyLimit);
|
||||
this.asyncExecutorService = Executors.newFixedThreadPool(asyncWriteToPipeConcurrencyLimit);
|
||||
|
||||
if (reactContext != null) {
|
||||
reactContext.addLifecycleEventListener(this);
|
||||
@@ -161,7 +161,7 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
|
||||
|
||||
@Override
|
||||
public void onHostDestroy() {
|
||||
this.asyncWriteToPipeExecutorService.shutdown();
|
||||
this.asyncExecutorService.shutdown();
|
||||
}
|
||||
|
||||
protected void registerGlobalCallbacks(final ReactApplicationContext reactContext) {
|
||||
@@ -573,6 +573,69 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void ffmpegSessionExecute(final Double sessionId, final Promise promise) {
|
||||
if (sessionId != null) {
|
||||
Session session = FFmpegKitConfig.getSession(sessionId.longValue());
|
||||
if (session == null) {
|
||||
promise.reject("SESSION_NOT_FOUND", "Session not found.");
|
||||
} else {
|
||||
if (session instanceof FFmpegSession) {
|
||||
final FFmpegSessionExecuteTask ffmpegSessionExecuteTask = new FFmpegSessionExecuteTask((FFmpegSession) session, promise);
|
||||
asyncExecutorService.submit(ffmpegSessionExecuteTask);
|
||||
} else {
|
||||
promise.reject("NOT_FFMPEG_SESSION", "A session is found but it does not have the correct type.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
promise.reject("INVALID_SESSION", "Invalid session id.");
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void ffprobeSessionExecute(final Double sessionId, final Promise promise) {
|
||||
if (sessionId != null) {
|
||||
Session session = FFmpegKitConfig.getSession(sessionId.longValue());
|
||||
if (session == null) {
|
||||
promise.reject("SESSION_NOT_FOUND", "Session not found.");
|
||||
} else {
|
||||
if (session instanceof FFprobeSession) {
|
||||
final FFprobeSessionExecuteTask ffprobeSessionExecuteTask = new FFprobeSessionExecuteTask((FFprobeSession) session, promise);
|
||||
asyncExecutorService.submit(ffprobeSessionExecuteTask);
|
||||
} else {
|
||||
promise.reject("NOT_FFPROBE_SESSION", "A session is found but it does not have the correct type.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
promise.reject("INVALID_SESSION", "Invalid session id.");
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void mediaInformationSessionExecute(final Double sessionId, final Double waitTimeout, final Promise promise) {
|
||||
if (sessionId != null) {
|
||||
Session session = FFmpegKitConfig.getSession(sessionId.longValue());
|
||||
if (session == null) {
|
||||
promise.reject("SESSION_NOT_FOUND", "Session not found.");
|
||||
} else {
|
||||
if (session instanceof MediaInformationSession) {
|
||||
final int timeout;
|
||||
if (isValidPositiveNumber(waitTimeout)) {
|
||||
timeout = waitTimeout.intValue();
|
||||
} else {
|
||||
timeout = AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT;
|
||||
}
|
||||
final MediaInformationSessionExecuteTask mediaInformationSessionExecuteTask = new MediaInformationSessionExecuteTask((MediaInformationSession) session, timeout, promise);
|
||||
asyncExecutorService.submit(mediaInformationSessionExecuteTask);
|
||||
} 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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void asyncFFmpegSessionExecute(final Double sessionId, final Promise promise) {
|
||||
if (sessionId != null) {
|
||||
@@ -743,8 +806,8 @@ public class FFmpegKitReactNativeModule extends ReactContextBaseJavaModule imple
|
||||
|
||||
@ReactMethod
|
||||
public void writeToPipe(final String inputPath, final String namedPipePath, final Promise promise) {
|
||||
final AsyncWriteToPipeTask asyncTask = new AsyncWriteToPipeTask(inputPath, namedPipePath, promise);
|
||||
asyncWriteToPipeExecutorService.submit(asyncTask);
|
||||
final WriteToPipeTask asyncTask = new WriteToPipeTask(inputPath, namedPipePath, promise);
|
||||
asyncExecutorService.submit(asyncTask);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
|
||||
+40
@@ -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 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.reactnative;
|
||||
|
||||
import com.arthenica.ffmpegkit.FFmpegKitConfig;
|
||||
import com.arthenica.ffmpegkit.FFmpegSession;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
|
||||
public class FFmpegSessionExecuteTask implements Runnable {
|
||||
private final FFmpegSession ffmpegSession;
|
||||
private final Promise promise;
|
||||
|
||||
public FFmpegSessionExecuteTask(final FFmpegSession ffmpegSession, final Promise promise) {
|
||||
this.ffmpegSession = ffmpegSession;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
FFmpegKitConfig.ffmpegExecute(ffmpegSession);
|
||||
promise.resolve(null);
|
||||
}
|
||||
}
|
||||
+40
@@ -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 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.reactnative;
|
||||
|
||||
import com.arthenica.ffmpegkit.FFmpegKitConfig;
|
||||
import com.arthenica.ffmpegkit.FFprobeSession;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
|
||||
public class FFprobeSessionExecuteTask implements Runnable {
|
||||
private final FFprobeSession ffprobeSession;
|
||||
private final Promise promise;
|
||||
|
||||
public FFprobeSessionExecuteTask(final FFprobeSession ffprobeSession, final Promise promise) {
|
||||
this.ffprobeSession = ffprobeSession;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
FFmpegKitConfig.ffprobeExecute(ffprobeSession);
|
||||
promise.resolve(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.reactnative;
|
||||
|
||||
import com.arthenica.ffmpegkit.FFmpegKitConfig;
|
||||
import com.arthenica.ffmpegkit.MediaInformationSession;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
|
||||
public class MediaInformationSessionExecuteTask implements Runnable {
|
||||
private final MediaInformationSession mediaInformationSession;
|
||||
private final int timeout;
|
||||
private final Promise promise;
|
||||
|
||||
public MediaInformationSessionExecuteTask(final MediaInformationSession mediaInformationSession, final int timeout, final Promise promise) {
|
||||
this.mediaInformationSession = mediaInformationSession;
|
||||
this.timeout = timeout;
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
FFmpegKitConfig.getMediaInformationExecute(mediaInformationSession, timeout);
|
||||
promise.resolve(null);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -27,12 +27,12 @@ import com.facebook.react.bridge.Promise;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AsyncWriteToPipeTask implements Runnable {
|
||||
public class WriteToPipeTask implements Runnable {
|
||||
private final String inputPath;
|
||||
private final String namedPipePath;
|
||||
private final Promise promise;
|
||||
|
||||
public AsyncWriteToPipeTask(final String inputPath, final String namedPipePath, final Promise promise) {
|
||||
public WriteToPipeTask(final String inputPath, final String namedPipePath, final Promise promise) {
|
||||
this.inputPath = inputPath;
|
||||
this.namedPipePath = namedPipePath;
|
||||
this.promise = promise;
|
||||
Reference in New Issue
Block a user