| FFmpegKit Android API 4.5

ffprobekit.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020-2021 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <pthread.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23
24#include "config.h"
25#include "libavcodec/jni.h"
26#include "libavutil/bprint.h"
27#include "ffmpegkit.h"
28
30 int ffprobe_execute(int argc, char **argv);
31
32 extern int configuredLogLevel;
33 extern __thread volatile long globalSessionId;
34 extern void addSession(long sessionId);
35 extern void removeSession(long sessionId);
36 extern void resetMessagesInTransmit(long sessionId);
37
47JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute(JNIEnv *env, jclass object, jlong id, jobjectArray stringArray) {
48 jstring *tempArray = NULL;
49 int argumentCount = 1;
50 char **argv = NULL;
51
52 // SETS DEFAULT LOG LEVEL BEFORE STARTING A NEW RUN
53 av_log_set_level(configuredLogLevel);
54
55 if (stringArray) {
56 int programArgumentCount = (*env)->GetArrayLength(env, stringArray);
57 argumentCount = programArgumentCount + 1;
58
59 tempArray = (jstring *) av_malloc(sizeof(jstring) * programArgumentCount);
60 }
61
62 /* PRESERVE USAGE FORMAT
63 *
64 * ffprobe <arguments>
65 */
66 argv = (char **)av_malloc(sizeof(char*) * (argumentCount));
67 argv[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1));
68 strcpy(argv[0], LIB_NAME);
69
70 // PREPARE ARRAY ELEMENTS
71 if (stringArray) {
72 for (int i = 0; i < (argumentCount - 1); i++) {
73 tempArray[i] = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i);
74 if (tempArray[i] != NULL) {
75 argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0);
76 }
77 }
78 }
79
80 // REGISTER THE ID BEFORE STARTING THE SESSION
81 globalSessionId = (long) id;
82 addSession((long) id);
83
84 resetMessagesInTransmit(globalSessionId);
85
86 // RUN
87 int returnCode = ffprobe_execute(argumentCount, argv);
88
89 // ALWAYS REMOVE THE ID FROM THE MAP
90 removeSession((long) id);
91
92 // CLEANUP
93 if (tempArray) {
94 for (int i = 0; i < (argumentCount - 1); i++) {
95 (*env)->ReleaseStringUTFChars(env, tempArray[i], argv[i + 1]);
96 }
97
98 av_free(tempArray);
99 }
100 av_free(argv[0]);
101 av_free(argv);
102
103 return returnCode;
104}
ffmpegkit.h
LIB_NAME
#define LIB_NAME
Definition: ffmpegkit.h:33
Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute(JNIEnv *env, jclass object, jlong id, jobjectArray stringArray)
Definition: ffprobekit.c:47
ffprobe_execute
int ffprobe_execute(int argc, char **argv)
Definition: fftools_ffprobe.c:3717
removeSession
void removeSession(long sessionId)
Definition: ffmpegkit.c:399
addSession
void addSession(long sessionId)
Definition: ffmpegkit.c:358
resetMessagesInTransmit
void resetMessagesInTransmit(long sessionId)
Definition: ffmpegkit.c:431
configuredLogLevel
int configuredLogLevel
Definition: ffmpegkit.c:109
globalSessionId
__thread volatile long globalSessionId
Definition: ffmpegkit.c:106