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
31int ffprobe_execute(int argc, char **argv);
32
33extern int configuredLogLevel;
34extern __thread long globalSessionId;
35extern void addSession(long sessionId);
36extern void removeSession(long sessionId);
37extern 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
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}
#define LIB_NAME
Definition ffmpegkit.h:33
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute(JNIEnv *env, jclass object, jlong id, jobjectArray stringArray)
Definition ffprobekit.c:48
int ffprobe_execute(int argc, char **argv)
void removeSession(long sessionId)
Definition ffmpegkit.c:402
void addSession(long sessionId)
Definition ffmpegkit.c:361
__thread long globalSessionId
Definition ffmpegkit.c:109
void resetMessagesInTransmit(long sessionId)
Definition ffmpegkit.c:434
int configuredLogLevel
Definition ffmpegkit.c:112