FFmpegKit Android API  4.4
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 sessionId;
34 extern void addSession(long id);
35 extern void removeSession(long id);
36 extern void resetMessagesInTransmit(long id);
37 
47 JNIEXPORT 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  sessionId = (long) id;
82  addSession((long) id);
83 
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 }
#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:47
__thread volatile long sessionId
Definition: ffmpegkit.c:105
void addSession(long id)
Definition: ffmpegkit.c:357
int ffprobe_execute(int argc, char **argv)
void resetMessagesInTransmit(long id)
Definition: ffmpegkit.c:430
int configuredLogLevel
Definition: ffmpegkit.c:108
void removeSession(long id)
Definition: ffmpegkit.c:398