提交 f23762b9 authored 作者: 祁增奎's avatar 祁增奎

Android替换

上级 5e4362bc
...@@ -22,14 +22,14 @@ external libraries enabled. ...@@ -22,14 +22,14 @@ external libraries enabled.
##### 2.1.1 Android Tools ##### 2.1.1 Android Tools
- Android SDK Build Tools - Android SDK Build Tools
- Android NDK r22b or later with LLDB and CMake (See [#292](https://github.com/arthenica/ffmpeg-kit/issues/292) if you want to use NDK r23b) - Android NDK r22b or later with LLDB and CMake (See [#292](https://github.com/arthenica/ffmpeg-kit/issues/292) if you want to use NDK r23b or later)
##### 2.1.2 Packages ##### 2.1.2 Packages
Use your package manager (apt, yum, dnf, brew, etc.) to install the following packages. Use your package manager (apt, yum, dnf, brew, etc.) to install the following packages.
``` ```
autoconf automake libtool pkg-config curl cmake gcc gperf texinfo yasm nasm bison autogen git wget autopoint meson ninja autoconf automake libtool pkg-config curl git doxygen nasm cmake gcc gperf texinfo yasm bison autogen wget autopoint meson ninja ragel groff gtk-doc-tools libtasn1
``` ```
##### 2.1.3 Environment Variables ##### 2.1.3 Environment Variables
...@@ -77,7 +77,7 @@ All libraries created by `android.sh` can be found under the `prebuilt` director ...@@ -77,7 +77,7 @@ All libraries created by `android.sh` can be found under the `prebuilt` director
} }
dependencies { dependencies {
implementation 'com.arthenica:ffmpeg-kit-full:5.1' implementation 'com.arthenica:ffmpeg-kit-full:6.0-2'
} }
``` ```
......
...@@ -38,7 +38,7 @@ PROJECT_NAME = "FFmpegKit Android API" ...@@ -38,7 +38,7 @@ PROJECT_NAME = "FFmpegKit Android API"
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # control system is used.
PROJECT_NUMBER = 5.1 PROJECT_NUMBER = 6.0
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a # for a project that appears at the top of each page and should give viewer a
......
-keep class com.arthenica.ffmpegkit.FFmpegKitConfig { -keep class com.arthenica.ffmpegkit.FFmpegKitConfig {
native <methods>; native <methods>;
void log(long, int, byte[]); void log(long, int, byte[]);
void statistics(long, int, float, float, long , int, double, double); void statistics(long, int, float, float, long , double, double, double);
int safOpen(int); int safOpen(int);
int safClose(int); int safClose(int);
} }
......
...@@ -45,7 +45,7 @@ struct CallbackData { ...@@ -45,7 +45,7 @@ struct CallbackData {
float statisticsFps; // statistics fps float statisticsFps; // statistics fps
float statisticsQuality; // statistics quality float statisticsQuality; // statistics quality
int64_t statisticsSize; // statistics size int64_t statisticsSize; // statistics size
int statisticsTime; // statistics time double statisticsTime; // statistics time
double statisticsBitrate; // statistics bitrate double statisticsBitrate; // statistics bitrate
double statisticsSpeed; // statistics speed double statisticsSpeed; // statistics speed
...@@ -312,7 +312,7 @@ void logCallbackDataAdd(int level, AVBPrint *data) { ...@@ -312,7 +312,7 @@ void logCallbackDataAdd(int level, AVBPrint *data) {
/** /**
* Adds statistics data to the end of callback data list. * Adds statistics data to the end of callback data list.
*/ */
void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_t size, int time, double bitrate, double speed) { void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_t size, double time, double bitrate, double speed) {
// CREATE DATA STRUCT FIRST // CREATE DATA STRUCT FIRST
struct CallbackData *newData = (struct CallbackData*)av_malloc(sizeof(struct CallbackData)); struct CallbackData *newData = (struct CallbackData*)av_malloc(sizeof(struct CallbackData));
...@@ -491,7 +491,7 @@ void ffmpegkit_log_callback_function(void *ptr, int level, const char* format, v ...@@ -491,7 +491,7 @@ void ffmpegkit_log_callback_function(void *ptr, int level, const char* format, v
* @param bitrate output bit rate in kbits/s * @param bitrate output bit rate in kbits/s
* @param speed processing speed = processed duration / operation duration * @param speed processing speed = processed duration / operation duration
*/ */
void ffmpegkit_statistics_callback_function(int frameNumber, float fps, float quality, int64_t size, int time, double bitrate, double speed) { void ffmpegkit_statistics_callback_function(int frameNumber, float fps, float quality, int64_t size, double time, double bitrate, double speed) {
statisticsCallbackDataAdd(frameNumber, fps, quality, size, time, bitrate, speed); statisticsCallbackDataAdd(frameNumber, fps, quality, size, time, bitrate, speed);
} }
...@@ -581,6 +581,30 @@ int saf_close(int fd) { ...@@ -581,6 +581,30 @@ int saf_close(int fd) {
return (*env)->CallStaticIntMethod(env, configClass, safCloseMethod, fd); return (*env)->CallStaticIntMethod(env, configClass, safCloseMethod, fd);
} }
/**
* Used by JNI methods to enable redirection.
*/
static void enableNativeRedirection() {
mutexLock();
if (redirectionEnabled != 0) {
mutexUnlock();
return;
}
redirectionEnabled = 1;
mutexUnlock();
int rc = pthread_create(&callbackThread, 0, callbackThreadFunction, 0);
if (rc != 0) {
LOGE("Failed to create callback thread (rc=%d).\n", rc);
return;
}
av_log_set_callback(ffmpegkit_log_callback_function);
set_report_callback(ffmpegkit_statistics_callback_function);
}
/** /**
* Called when 'ffmpegkit' native library is loaded. * Called when 'ffmpegkit' native library is loaded.
* *
...@@ -620,7 +644,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { ...@@ -620,7 +644,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_FALSE; return JNI_FALSE;
} }
statisticsMethod = (*env)->GetStaticMethodID(env, localConfigClass, "statistics", "(JIFFJIDD)V"); statisticsMethod = (*env)->GetStaticMethodID(env, localConfigClass, "statistics", "(JIFFJDDD)V");
if (statisticsMethod == NULL) { if (statisticsMethod == NULL) {
LOGE("OnLoad thread failed to GetStaticMethodID for %s.\n", "statistics"); LOGE("OnLoad thread failed to GetStaticMethodID for %s.\n", "statistics");
return JNI_FALSE; return JNI_FALSE;
...@@ -665,6 +689,8 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { ...@@ -665,6 +689,8 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
av_set_saf_open(saf_open); av_set_saf_open(saf_open);
av_set_saf_close(saf_close); av_set_saf_close(saf_close);
enableNativeRedirection();
return JNI_VERSION_1_6; return JNI_VERSION_1_6;
} }
...@@ -696,24 +722,7 @@ JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLog ...@@ -696,24 +722,7 @@ JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLog
* @param object reference to the class on which this method is invoked * @param object reference to the class on which this method is invoked
*/ */
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_enableNativeRedirection(JNIEnv *env, jclass object) { JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_enableNativeRedirection(JNIEnv *env, jclass object) {
mutexLock(); enableNativeRedirection();
if (redirectionEnabled != 0) {
mutexUnlock();
return;
}
redirectionEnabled = 1;
mutexUnlock();
int rc = pthread_create(&callbackThread, 0, callbackThreadFunction, 0);
if (rc != 0) {
LOGE("Failed to create callback thread (rc=%d).\n", rc);
return;
}
av_log_set_callback(ffmpegkit_log_callback_function);
set_report_callback(ffmpegkit_statistics_callback_function);
} }
/** /**
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "libavutil/ffversion.h" #include "libavutil/ffversion.h"
/** Library version string */ /** Library version string */
#define FFMPEG_KIT_VERSION "5.1" #define FFMPEG_KIT_VERSION "6.0"
/** Defines tag used for Android logging. */ /** Defines tag used for Android logging. */
#define LIB_NAME "ffmpeg-kit" #define LIB_NAME "ffmpeg-kit"
......
/* /*
* Various utilities for command line tools * Various utilities for command line tools
* Copyright (c) 2000-2003 Fabrice Bellard * Copyright (c) 2000-2003 Fabrice Bellard
* copyright (c) 2018 Taner Sener ( tanersener gmail com ) * Copyright (c) 2018-2022 Taner Sener
* Copyright (c) 2023 ARTHENICA LTD
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
...@@ -25,6 +26,12 @@ ...@@ -25,6 +26,12 @@
* manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied * manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
* by us to develop mobile-ffmpeg and later ffmpeg-kit libraries. * by us to develop mobile-ffmpeg and later ffmpeg-kit libraries.
* *
* ffmpeg-kit changes by ARTHENICA LTD
*
* 07.2023
* --------------------------------------------------------
* - FFmpeg 6.0 changes migrated
*
* mobile-ffmpeg / ffmpeg-kit changes by Taner Sener * mobile-ffmpeg / ffmpeg-kit changes by Taner Sener
* *
* 09.2022 * 09.2022
...@@ -129,11 +136,18 @@ void register_exit(void (*cb)(int ret)) ...@@ -129,11 +136,18 @@ void register_exit(void (*cb)(int ret))
program_exit = cb; program_exit = cb;
} }
void report_and_exit(int ret)
{
av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
exit_program(AVUNERROR(ret));
}
void exit_program(int ret) void exit_program(int ret)
{ {
if (program_exit) if (program_exit)
program_exit(ret); program_exit(ret);
// FFmpegKit
// exit disabled and replaced with longjmp, exit value stored in longjmp_value // exit disabled and replaced with longjmp, exit value stored in longjmp_value
// exit(ret); // exit(ret);
longjmp_value = ret; longjmp_value = ret;
...@@ -696,7 +710,7 @@ static void init_parse_context(OptionParseContext *octx, ...@@ -696,7 +710,7 @@ static void init_parse_context(OptionParseContext *octx,
octx->nb_groups = nb_groups; octx->nb_groups = nb_groups;
octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups)); octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups));
if (!octx->groups) if (!octx->groups)
exit_program(1); report_and_exit(AVERROR(ENOMEM));
for (i = 0; i < octx->nb_groups; i++) for (i = 0; i < octx->nb_groups; i++)
octx->groups[i].group_def = &groups[i]; octx->groups[i].group_def = &groups[i];
...@@ -843,12 +857,7 @@ do { \ ...@@ -843,12 +857,7 @@ do { \
void print_error(const char *filename, int err) void print_error(const char *filename, int err)
{ {
char errbuf[128]; av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, av_err2str(err));
const char *errbuf_ptr = errbuf;
if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
errbuf_ptr = strerror(AVUNERROR(err));
av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
} }
int read_yesno(void) int read_yesno(void)
...@@ -971,7 +980,7 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, ...@@ -971,7 +980,7 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
break; break;
} }
while ((t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX))) { while ((t = av_dict_iterate(opts, t))) {
const AVClass *priv_class; const AVClass *priv_class;
char *p = strchr(t->key, ':'); char *p = strchr(t->key, ':');
...@@ -1009,11 +1018,8 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, ...@@ -1009,11 +1018,8 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
if (!s->nb_streams) if (!s->nb_streams)
return NULL; return NULL;
opts = av_calloc(s->nb_streams, sizeof(*opts)); opts = av_calloc(s->nb_streams, sizeof(*opts));
if (!opts) { if (!opts)
av_log(NULL, AV_LOG_ERROR, report_and_exit(AVERROR(ENOMEM));
"Could not alloc memory for stream options.\n");
exit_program(1);
}
for (i = 0; i < s->nb_streams; i++) for (i = 0; i < s->nb_streams; i++)
opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
s, s->streams[i], NULL); s, s->streams[i], NULL);
...@@ -1028,10 +1034,8 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) ...@@ -1028,10 +1034,8 @@ void *grow_array(void *array, int elem_size, int *size, int new_size)
} }
if (*size < new_size) { if (*size < new_size) {
uint8_t *tmp = av_realloc_array(array, new_size, elem_size); uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
if (!tmp) { if (!tmp)
av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); report_and_exit(AVERROR(ENOMEM));
exit_program(1);
}
memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
*size = new_size; *size = new_size;
return tmp; return tmp;
...@@ -1044,10 +1048,8 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) ...@@ -1044,10 +1048,8 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
void *new_elem; void *new_elem;
if (!(new_elem = av_mallocz(elem_size)) || if (!(new_elem = av_mallocz(elem_size)) ||
av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) { av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); report_and_exit(AVERROR(ENOMEM));
exit_program(1);
}
return new_elem; return new_elem;
} }
......
/* /*
* Various utilities for command line tools * Various utilities for command line tools
* copyright (c) 2003 Fabrice Bellard * copyright (c) 2003 Fabrice Bellard
* copyright (c) 2018 Taner Sener ( tanersener gmail com ) * copyright (c) 2018-2022 Taner Sener
* copyright (c) 2023 ARTHENICA LTD
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
...@@ -25,6 +26,12 @@ ...@@ -25,6 +26,12 @@
* manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied * manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
* by us to develop mobile-ffmpeg and later ffmpeg-kit libraries. * by us to develop mobile-ffmpeg and later ffmpeg-kit libraries.
* *
* ffmpeg-kit changes by ARTHENICA LTD
*
* 07.2023
* --------------------------------------------------------
* - FFmpeg 6.0 changes migrated
*
* mobile-ffmpeg / ffmpeg-kit changes by Taner Sener * mobile-ffmpeg / ffmpeg-kit changes by Taner Sener
* *
* 09.2022 * 09.2022
...@@ -95,6 +102,17 @@ extern __thread int find_stream_info; ...@@ -95,6 +102,17 @@ extern __thread int find_stream_info;
*/ */
void register_exit(void (*cb)(int ret)); void register_exit(void (*cb)(int ret));
/**
* Reports an error corresponding to the provided
* AVERROR code and calls exit_program() with the
* corresponding POSIX error code.
* @note ret must be an AVERROR-value of a POSIX error code
* (i.e. AVERROR(EFOO) and not AVERROR_FOO).
* library functions can return both, so call this only
* with AVERROR(EFOO) of your own.
*/
void report_and_exit(int ret) av_noreturn;
/** /**
* Wraps exit with a program-specific cleanup routine. * Wraps exit with a program-specific cleanup routine.
*/ */
...@@ -232,11 +250,6 @@ void show_help_children(const AVClass *clazz, int flags); ...@@ -232,11 +250,6 @@ void show_help_children(const AVClass *clazz, int flags);
void show_help_default_ffmpeg(const char *opt, const char *arg); void show_help_default_ffmpeg(const char *opt, const char *arg);
void show_help_default_ffprobe(const char *opt, const char *arg); void show_help_default_ffprobe(const char *opt, const char *arg);
/**
* Generic -h handler common to all fftools.
*/
int show_help(void *optctx, const char *opt, const char *arg);
/** /**
* Parse the command line arguments. * Parse the command line arguments.
* *
......
This source diff could not be displayed because it is too large. You can view the blob instead.
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论