| FFmpegKit Android API 6.0

Loading...
Searching...
No Matches
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 "libavutil/mem.h"
28#include "ffmpegkit.h"
29
31 int ffprobe_execute(int argc, char **argv);
32
33 extern int configuredLogLevel;
34 extern __thread long globalSessionId;
35 extern void addSession(long sessionId);
36 extern void removeSession(long sessionId);
37 extern void resetMessagesInTransmit(long sessionId);
38
48JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute(JNIEnv *env, jclass object, jlong id, jobjectArray stringArray) {
49 jstring *tempArray = NULL;
50 int argumentCount = 1;
51 char **argv = NULL;
52
53 // SETS DEFAULT LOG LEVEL BEFORE STARTING A NEW RUN
54 av_log_set_level(configuredLogLevel);
55
56 if (stringArray) {
57 int programArgumentCount = (*env)->GetArrayLength(env, stringArray);
58 argumentCount = programArgumentCount + 1;
59
60 tempArray = (jstring *) av_malloc(sizeof(jstring) * programArgumentCount);
61 }
62
63 /* PRESERVE USAGE FORMAT
64 *
65 * ffprobe <arguments>
66 */
67 argv = (char **)av_malloc(sizeof(char*) * (argumentCount));
68 argv[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1));
69 strcpy(argv[0], LIB_NAME);
70
71 // PREPARE ARRAY ELEMENTS
72 if (stringArray) {
73 for (int i = 0; i < (argumentCount - 1); i++) {
74 tempArray[i] = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i);
75 if (tempArray[i] != NULL) {
76 argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0);
77 }
78 }
79 }
80
81 // REGISTER THE ID BEFORE STARTING THE SESSION
82 globalSessionId = (long) id;
83 addSession((long) id);
84
85 resetMessagesInTransmit(globalSessionId);
86
87 // RUN
88 int returnCode = ffprobe_execute(argumentCount, argv);
89
90 // ALWAYS REMOVE THE ID FROM THE MAP
91 removeSession((long) id);
92
93 // CLEANUP
94 if (tempArray) {
95 for (int i = 0; i < (argumentCount - 1); i++) {
96 (*env)->ReleaseStringUTFChars(env, tempArray[i], argv[i + 1]);
97 }
98
99 av_free(tempArray);
100 }
101 av_free(argv[0]);
102 av_free(argv);
103
104 return returnCode;
105}
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:48
ffprobe_execute
int ffprobe_execute(int argc, char **argv)
Definition fftools_ffprobe.c:4096
removeSession
void removeSession(long sessionId)
Definition ffmpegkit.c:402
addSession
void addSession(long sessionId)
Definition ffmpegkit.c:361
globalSessionId
__thread long globalSessionId
Definition ffmpegkit.c:109
resetMessagesInTransmit
void resetMessagesInTransmit(long sessionId)
Definition ffmpegkit.c:434
configuredLogLevel
int configuredLogLevel
Definition ffmpegkit.c:112