MobileFFmpeg Android API  4.4
mobileffprobe.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Taner Sener
3  *
4  * This file is part of MobileFFmpeg.
5  *
6  * MobileFFmpeg 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  * MobileFFmpeg 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 MobileFFmpeg. 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 "mobileffmpeg.h"
28 
30 int ffprobe_execute(int argc, char **argv);
31 
34 
43 JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Config_nativeFFprobeExecute(JNIEnv *env, jclass object, jobjectArray stringArray) {
44  jstring *tempArray = NULL;
45  int argumentCount = 1;
46  char **argv = NULL;
47 
48  if (stringArray != NULL) {
49  int programArgumentCount = (*env)->GetArrayLength(env, stringArray);
50  argumentCount = programArgumentCount + 1;
51 
52  tempArray = (jstring *) av_malloc(sizeof(jstring) * programArgumentCount);
53  }
54 
55  /* PRESERVE USAGE FORMAT
56  *
57  * ffprobe <arguments>
58  */
59  argv = (char **)av_malloc(sizeof(char*) * (argumentCount));
60  argv[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1));
61  strcpy(argv[0], LIB_NAME);
62 
63  // PREPARE
64  if (stringArray != NULL) {
65  for (int i = 0; i < (argumentCount - 1); i++) {
66  tempArray[i] = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i);
67  if (tempArray[i] != NULL) {
68  argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0);
69  }
70  }
71  }
72 
73  // LAST COMMAND OUTPUT SHOULD BE CLEARED BEFORE STARTING A NEW EXECUTION
75 
76  // RUN
77  int retCode = ffprobe_execute(argumentCount, argv);
78 
79  // CLEANUP
80  if (tempArray != NULL) {
81  for (int i = 0; i < (argumentCount - 1); i++) {
82  (*env)->ReleaseStringUTFChars(env, tempArray[i], argv[i + 1]);
83  }
84 
85  av_free(tempArray);
86  }
87  av_free(argv[0]);
88  av_free(argv);
89 
90  return retCode;
91 }
ffprobe_execute
int ffprobe_execute(int argc, char **argv)
Definition: fftools_ffprobe.c:3585
clearLastCommandOutput
void clearLastCommandOutput()
Definition: mobileffmpeg.c:276
mobileffmpeg.h
LIB_NAME
#define LIB_NAME
Definition: mobileffmpeg.h:33
Java_com_arthenica_mobileffmpeg_Config_nativeFFprobeExecute
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Config_nativeFFprobeExecute(JNIEnv *env, jclass object, jobjectArray stringArray)
Definition: mobileffprobe.c:43