fix ios ffprobe implementation

This commit is contained in:
Taner Sener 2021-09-15 21:26:32 +01:00
parent e3ea69a58e
commit 28612fce75
6 changed files with 45 additions and 45 deletions

View File

@ -103,7 +103,7 @@ volatile int handleSIGXCPU = 1;
volatile int handleSIGPIPE = 1;
/** Holds the id of the current session */
__thread volatile long sessionId = 0;
__thread volatile long globalSessionId = 0;
/** Holds the default log level */
int configuredLogLevel = AV_LOG_INFO;
@ -275,7 +275,7 @@ void logCallbackDataAdd(int level, AVBPrint *data) {
// CREATE DATA STRUCT FIRST
struct CallbackData *newData = (struct CallbackData*)av_malloc(sizeof(struct CallbackData));
newData->type = LogType;
newData->sessionId = sessionId;
newData->sessionId = globalSessionId;
newData->logLevel = level;
av_bprint_init(&newData->logData, 0, AV_BPRINT_SIZE_UNLIMITED);
av_bprintf(&newData->logData, "%s", data->str);
@ -303,7 +303,7 @@ void logCallbackDataAdd(int level, AVBPrint *data) {
monitorNotify();
atomic_fetch_add(&sessionInTransitMessageCountMap[sessionId % SESSION_MAP_SIZE], 1);
atomic_fetch_add(&sessionInTransitMessageCountMap[globalSessionId % SESSION_MAP_SIZE], 1);
}
/**
@ -314,7 +314,7 @@ void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_
// CREATE DATA STRUCT FIRST
struct CallbackData *newData = (struct CallbackData*)av_malloc(sizeof(struct CallbackData));
newData->type = StatisticsType;
newData->sessionId = sessionId;
newData->sessionId = globalSessionId;
newData->statisticsFrameNumber = frameNumber;
newData->statisticsFps = fps;
newData->statisticsQuality = quality;
@ -347,7 +347,7 @@ void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_
monitorNotify();
atomic_fetch_add(&sessionInTransitMessageCountMap[sessionId % SESSION_MAP_SIZE], 1);
atomic_fetch_add(&sessionInTransitMessageCountMap[globalSessionId % SESSION_MAP_SIZE], 1);
}
/**
@ -787,10 +787,10 @@ JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpeg
}
// REGISTER THE ID BEFORE STARTING THE SESSION
sessionId = (long) id;
globalSessionId = (long) id;
addSession((long) id);
resetMessagesInTransmit(sessionId);
resetMessagesInTransmit(globalSessionId);
// RUN
int returnCode = ffmpeg_execute(argumentCount, argv);

View File

@ -30,10 +30,10 @@
int ffprobe_execute(int argc, char **argv);
extern int configuredLogLevel;
extern __thread volatile long sessionId;
extern void addSession(long id);
extern void removeSession(long id);
extern void resetMessagesInTransmit(long id);
extern __thread volatile long globalSessionId;
extern void addSession(long sessionId);
extern void removeSession(long sessionId);
extern void resetMessagesInTransmit(long sessionId);
/**
* Synchronously executes FFprobe natively with arguments provided.
@ -78,10 +78,10 @@ JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprob
}
// REGISTER THE ID BEFORE STARTING THE SESSION
sessionId = (long) id;
globalSessionId = (long) id;
addSession((long) id);
resetMessagesInTransmit(sessionId);
resetMessagesInTransmit(globalSessionId);
// RUN
int returnCode = ffprobe_execute(argumentCount, argv);

View File

@ -260,9 +260,9 @@ extern volatile int handleSIGTERM;
extern volatile int handleSIGXCPU;
extern volatile int handleSIGPIPE;
extern __thread volatile long sessionId;
extern void cancelSession(long id);
extern int cancelRequested(long id);
extern __thread volatile long globalSessionId;
extern void cancelSession(long sessionId);
extern int cancelRequested(long sessionId);
/* sub2video hack:
Convert subtitles to video with alpha to insert them in filter graphs.
@ -772,7 +772,7 @@ static void ffmpeg_cleanup(int ret)
if (received_sigterm) {
av_log(NULL, AV_LOG_INFO, "Exiting normally, received signal %d.\n",
(int) received_sigterm);
} else if (cancelRequested(sessionId)) {
} else if (cancelRequested(globalSessionId)) {
av_log(NULL, AV_LOG_INFO, "Exiting normally, received cancel request.\n");
} else if (ret && atomic_load(&transcode_init_done)) {
av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
@ -2438,7 +2438,7 @@ static int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
if (ifilter->filter) {
/* THIS VALIDATION IS REQUIRED TO COMPLETE CANCELLATION */
if (!received_sigterm && !cancelRequested(sessionId)) {
if (!received_sigterm && !cancelRequested(globalSessionId)) {
ret = av_buffersrc_close(ifilter->filter, pts, AV_BUFFERSRC_FLAG_PUSH);
}
if (ret < 0)
@ -4989,7 +4989,7 @@ static int transcode(void)
goto fail;
#endif
while (!received_sigterm && !cancelRequested(sessionId)) {
while (!received_sigterm && !cancelRequested(globalSessionId)) {
int64_t cur_time= av_gettime_relative();
/* if 'q' pressed, exits */
@ -5728,10 +5728,10 @@ int ffmpeg_execute(int argc, char **argv)
if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
exit_program(69);
exit_program((received_nb_signals || cancelRequested(sessionId))? 255 : main_ffmpeg_return_code);
exit_program((received_nb_signals || cancelRequested(globalSessionId))? 255 : main_ffmpeg_return_code);
} else {
main_ffmpeg_return_code = (received_nb_signals || cancelRequested(sessionId)) ? 255 : longjmp_value;
main_ffmpeg_return_code = (received_nb_signals || cancelRequested(globalSessionId)) ? 255 : longjmp_value;
}
return main_ffmpeg_return_code;

View File

@ -85,7 +85,7 @@ volatile int handleSIGXCPU = 1;
volatile int handleSIGPIPE = 1;
/** Holds the id of the current execution */
__thread volatile long _sessionId = 0;
__thread volatile long globalSessionId = 0;
/** Holds the default log level */
int configuredLogLevel = LevelAVLogInfo;
@ -254,7 +254,7 @@ void callbackNotify() {
* @param logData log data
*/
void logCallbackDataAdd(int level, NSString *logData) {
CallbackData* callbackData = [[CallbackData alloc] init:_sessionId logLevel:level data:logData];
CallbackData* callbackData = [[CallbackData alloc] init:globalSessionId logLevel:level data:logData];
[lock lock];
[callbackDataArray addObject:callbackData];
@ -262,14 +262,14 @@ void logCallbackDataAdd(int level, NSString *logData) {
callbackNotify();
atomic_fetch_add(&sessionInTransitMessageCountMap[_sessionId % SESSION_MAP_SIZE], 1);
atomic_fetch_add(&sessionInTransitMessageCountMap[globalSessionId % SESSION_MAP_SIZE], 1);
}
/**
* 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) {
CallbackData *callbackData = [[CallbackData alloc] init:_sessionId videoFrameNumber:frameNumber fps:fps quality:quality size:size time:time bitrate:bitrate speed:speed];
CallbackData *callbackData = [[CallbackData alloc] init:globalSessionId videoFrameNumber:frameNumber fps:fps quality:quality size:size time:time bitrate:bitrate speed:speed];
[lock lock];
[callbackDataArray addObject:callbackData];
@ -277,7 +277,7 @@ void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_
callbackNotify();
atomic_fetch_add(&sessionInTransitMessageCountMap[_sessionId % SESSION_MAP_SIZE], 1);
atomic_fetch_add(&sessionInTransitMessageCountMap[globalSessionId % SESSION_MAP_SIZE], 1);
}
/**
@ -581,7 +581,7 @@ int executeFFmpeg(long sessionId, NSArray* arguments) {
}
// REGISTER THE ID BEFORE STARTING THE SESSION
_sessionId = sessionId;
globalSessionId = sessionId;
registerSessionId(sessionId);
resetMessagesInTransmit(sessionId);
@ -621,7 +621,7 @@ int executeFFprobe(long sessionId, NSArray* arguments) {
}
// REGISTER THE ID BEFORE STARTING THE SESSION
_sessionId = sessionId;
globalSessionId = sessionId;
registerSessionId(sessionId);
resetMessagesInTransmit(sessionId);

View File

@ -257,9 +257,9 @@ extern volatile int handleSIGTERM;
extern volatile int handleSIGXCPU;
extern volatile int handleSIGPIPE;
extern __thread volatile long sessionId;
extern void cancelSession(long id);
extern int cancelRequested(long id);
extern __thread volatile long globalSessionId;
extern void cancelSession(long sessionId);
extern int cancelRequested(long sessionId);
/* sub2video hack:
Convert subtitles to video with alpha to insert them in filter graphs.
@ -769,7 +769,7 @@ static void ffmpeg_cleanup(int ret)
if (received_sigterm) {
av_log(NULL, AV_LOG_INFO, "Exiting normally, received signal %d.\n",
(int) received_sigterm);
} else if (cancelRequested(sessionId)) {
} else if (cancelRequested(globalSessionId)) {
av_log(NULL, AV_LOG_INFO, "Exiting normally, received cancel request.\n");
} else if (ret && atomic_load(&transcode_init_done)) {
av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
@ -2435,7 +2435,7 @@ static int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
if (ifilter->filter) {
/* THIS VALIDATION IS REQUIRED TO COMPLETE CANCELLATION */
if (!received_sigterm && !cancelRequested(sessionId)) {
if (!received_sigterm && !cancelRequested(globalSessionId)) {
ret = av_buffersrc_close(ifilter->filter, pts, AV_BUFFERSRC_FLAG_PUSH);
}
if (ret < 0)
@ -4986,7 +4986,7 @@ static int transcode(void)
goto fail;
#endif
while (!received_sigterm && !cancelRequested(sessionId)) {
while (!received_sigterm && !cancelRequested(globalSessionId)) {
int64_t cur_time= av_gettime_relative();
/* if 'q' pressed, exits */
@ -5725,10 +5725,10 @@ int ffmpeg_execute(int argc, char **argv)
if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
exit_program(69);
exit_program((received_nb_signals || cancelRequested(sessionId))? 255 : main_ffmpeg_return_code);
exit_program((received_nb_signals || cancelRequested(globalSessionId))? 255 : main_ffmpeg_return_code);
} else {
main_ffmpeg_return_code = (received_nb_signals || cancelRequested(sessionId)) ? 255 : longjmp_value;
main_ffmpeg_return_code = (received_nb_signals || cancelRequested(globalSessionId)) ? 255 : longjmp_value;
}
return main_ffmpeg_return_code;

View File

@ -40,6 +40,7 @@
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/display.h"
#include "libavutil/hash.h"
#include "libavutil/hdr_dynamic_metadata.h"
@ -1688,9 +1689,9 @@ static void xml_print_section_header(WriterContext *wctx)
wctx->section[wctx->level-1] : NULL;
if (wctx->level == 0) {
const char *qual = " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
"xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
"xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
const char *qual = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
"xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
av_log(NULL, AV_LOG_STDERR, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
av_log(NULL, AV_LOG_STDERR, "<%sffprobe%s>\n",
@ -2032,7 +2033,7 @@ static void print_pkt_side_data(WriterContext *w,
print_int("dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
} else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
print_int("type", *t);
print_int("service_type", *t);
} else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
print_int("id", *sd->data);
} else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
@ -2248,8 +2249,8 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
else print_str_opt("media_type", "unknown");
print_int("stream_index", stream->index);
print_int("key_frame", frame->key_frame);
print_ts ("pkt_pts", frame->pts);
print_time("pkt_pts_time", frame->pts, &stream->time_base);
print_ts ("pts", frame->pts);
print_time("pts_time", frame->pts, &stream->time_base);
print_ts ("pkt_dts", frame->pkt_dts);
print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
@ -3081,7 +3082,6 @@ static void close_input_file(InputFile *ifile)
/* close decoder for each stream */
for (i = 0; i < ifile->nb_streams; i++)
if (ifile->streams[i].st->codecpar->codec_id != AV_CODEC_ID_NONE)
avcodec_free_context(&ifile->streams[i].dec_ctx);
av_freep(&ifile->streams);
@ -3747,6 +3747,7 @@ int ffprobe_execute(int argc, char **argv)
{ "report", 0, { .func_arg = opt_report }, "generate a report" },
{ "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" },
{ "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" },
{ "cpucount", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpucount }, "force specific cpu count", "count" },
{ "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" },
#if CONFIG_AVDEVICE
@ -3830,7 +3831,6 @@ int ffprobe_execute(int argc, char **argv)
ffprobe_options = options;
parse_loglevel(argc, argv, options);
avformat_network_init();
init_opts();
#if CONFIG_AVDEVICE
avdevice_register_all();
#endif