change ffprobe_cmd.c to cpp

pull/166/head
xufuji456 4 years ago
parent 5fad821835
commit 618702389c
  1. 2
      app/CMakeLists.txt
  2. 2
      app/src/main/cpp/audio_player.c
  3. 8
      app/src/main/cpp/ffmpeg_jni_define.h
  4. 33
      app/src/main/cpp/ffprobe_cmd.c
  5. 42
      app/src/main/cpp/ffprobe_cmd.cpp

@ -33,7 +33,7 @@ add_library( # Sets the name of the library.
src/main/cpp/media_player.cpp
src/main/cpp/video_filter.c
src/main/cpp/fast_start.c
src/main/cpp/ffprobe_cmd.c
src/main/cpp/ffprobe_cmd.cpp
)
add_library( ffmpeg

@ -35,7 +35,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr) {
//get the audio stream index in the stream array
int i = 0, audio_stream_idx = -1;
for (; i < pFormatCtx->nb_streams; i++) {
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
audio_stream_idx = i;
break;
}

@ -18,6 +18,14 @@
JNIEXPORT RETURN_TYPE JNICALL Java_com_frank_ffmpeg_FFmpegCmd_ ## FUNC_NAME \
(JNIEnv *env, jclass thiz, ##__VA_ARGS__)\
#define FFPROBE_FUNC(RETURN_TYPE, FUNC_NAME, ...) \
extern "C" { \
JNIEXPORT RETURN_TYPE JNICALL Java_com_frank_ffmpeg_FFmpegCmd_ ## FUNC_NAME \
(JNIEnv *env, jclass thiz, ##__VA_ARGS__);\
}\
JNIEXPORT RETURN_TYPE JNICALL Java_com_frank_ffmpeg_FFmpegCmd_ ## FUNC_NAME \
(JNIEnv *env, jclass thiz, ##__VA_ARGS__)\
#define VIDEO_PLAYER_FUNC(RETURN_TYPE, FUNC_NAME, ...) \
JNIEXPORT RETURN_TYPE JNICALL Java_com_frank_ffmpeg_VideoPlayer_ ## FUNC_NAME \
(JNIEnv *env, jobject thiz, ##__VA_ARGS__)\

@ -1,33 +0,0 @@
//
// Created by frank on 2020-01-06.
//
#include <jni.h>
#include <string.h>
#include <malloc.h>
#include <ffmpeg_jni_define.h>
#include <ffmpeg/ffprobe.h>
FFMPEG_FUNC(jstring, handleProbe, jobjectArray commands) {
int argc = (*env)->GetArrayLength(env, commands);
char **argv = (char **) malloc(argc * sizeof(char *));
int i;
for (i = 0; i < argc; i++) {
jstring jstr = (jstring) (*env)->GetObjectArrayElement(env, commands, i);
char *temp = (char *) (*env)->GetStringUTFChars(env, jstr, 0);
argv[i] = malloc(1024);
strcpy(argv[i], temp);
(*env)->ReleaseStringUTFChars(env, jstr, temp);
}
//execute ffprobe command
char *result = ffprobe_run(argc, argv);
//release memory
for (i = 0; i < argc; i++) {
free(argv[i]);
}
free(argv);
return (*env)->NewStringUTF(env, result);
}

@ -0,0 +1,42 @@
//
// Created by frank on 2020-01-06.
//
#include <jni.h>
#include <string.h>
#include <malloc.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "ffmpeg_jni_define.h"
#include "ffmpeg/ffprobe.h"
#ifdef __cplusplus
}
#endif
FFPROBE_FUNC(jstring, handleProbe, jobjectArray commands) {
int argc = env->GetArrayLength(commands);
char **argv = (char **) malloc(argc * sizeof(char *));
int i;
for (i = 0; i < argc; i++) {
jstring jstr = (jstring) env->GetObjectArrayElement( commands, i);
char *temp = (char *) env->GetStringUTFChars(jstr, 0);
argv[i] = static_cast<char *>(malloc(1024));
strcpy(argv[i], temp);
env->ReleaseStringUTFChars(jstr, temp);
}
//execute ffprobe command
char *result = ffprobe_run(argc, argv);
//release memory
for (i = 0; i < argc; i++) {
free(argv[i]);
}
free(argv);
return env->NewStringUTF(result);
}
Loading…
Cancel
Save