count and reset errors

pull/209/head
xufuji456 3 years ago
parent 87d4817725
commit 609c0c5855
  1. 22
      app/src/main/cpp/ffmpeg_cmd.c

@ -3,20 +3,22 @@
#include "ffmpeg_jni_define.h"
#define FFMPEG_TAG "FFmpegCmd"
#define INPUT_SIZE (4 * 1024)
#define ALOGI(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_INFO, TAG, FORMAT, ##__VA_ARGS__);
#define ALOGE(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_ERROR, TAG, FORMAT, ##__VA_ARGS__);
#define ALOGW(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_WARN, TAG, FORMAT, ##__VA_ARGS__);
int err_count;
JNIEnv *ff_env;
jclass ff_class;
jmethodID ff_method;
jmethodID msg_method;
void log_callback(void*, int, const char*, va_list);
void log_callback(void *, int, const char *, va_list);
void init(JNIEnv *env) {
ff_env = env;
err_count = 0;
ff_class = (*env)->FindClass(env, "com/frank/ffmpeg/FFmpegCmd");
ff_method = (*env)->GetStaticMethodID(env, ff_class, "onProgressCallback", "(III)V");
msg_method = (*env)->GetStaticMethodID(env, ff_class, "onMsgCallback", "(Ljava/lang/String;)V");
@ -36,7 +38,7 @@ FFMPEG_FUNC(jint, handle, jobjectArray commands) {
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);
argv[i] = malloc(INPUT_SIZE);
strcpy(argv[i], temp);
(*env)->ReleaseStringUTFChars(env, jstr, temp);
}
@ -54,9 +56,9 @@ FFMPEG_FUNC(void, cancelTaskJni, jint cancel) {
cancel_task(cancel);
}
void msg_callback(const char* format, va_list args) {
void msg_callback(const char *format, va_list args) {
if (ff_env && msg_method) {
char *ff_msg = (char*) malloc(sizeof(char) * 1024);
char *ff_msg = (char *) malloc(sizeof(char) * INPUT_SIZE);
vsprintf(ff_msg, format, args);
jstring jstr = (*ff_env)->NewStringUTF(ff_env, ff_msg);
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, msg_method, jstr);
@ -64,11 +66,8 @@ void msg_callback(const char* format, va_list args) {
}
}
void log_callback(void* ptr, int level, const char* format, va_list args) {
void log_callback(void *ptr, int level, const char *format, va_list args) {
switch (level) {
case AV_LOG_WARNING:
ALOGW(FFMPEG_TAG, format, args);
break;
case AV_LOG_INFO:
ALOGI(FFMPEG_TAG, format, args);
if (format && strncmp("silence", format, 7) == 0) {
@ -77,7 +76,10 @@ void log_callback(void* ptr, int level, const char* format, va_list args) {
break;
case AV_LOG_ERROR:
ALOGE(FFMPEG_TAG, format, args);
msg_callback(format, args);
if (err_count < 10) {
err_count++;
msg_callback(format, args);
}
break;
default:
break;

Loading…
Cancel
Save