use less async calls to process logs and statistics

pull/295/head
Taner Sener 4 years ago
parent aed46e9bd7
commit 0b45c3e101
  1. 176
      flutter/flutter/lib/src/ffmpeg_kit_flutter_initializer.dart

@ -98,117 +98,109 @@ class FFmpegKitInitializer {
return; return;
} }
FFmpegKitConfig.getSession(sessionId).then((Session? session) { activeLogRedirectionStrategy =
activeLogRedirectionStrategy = FFmpegKitFactory.getLogRedirectionStrategy(sessionId) ??
session?.getLogRedirectionStrategy() ?? activeLogRedirectionStrategy; activeLogRedirectionStrategy;
final LogCallback? logCallback = session?.getLogCallback(); final LogCallback? logCallback = FFmpegKitFactory.getLogCallback(sessionId);
if (logCallback != null) { if (logCallback != null) {
sessionCallbackDefined = true; sessionCallbackDefined = true;
try { try {
// NOTIFY SESSION CALLBACK DEFINED // NOTIFY SESSION CALLBACK DEFINED
logCallback(log); logCallback(log);
} on Exception catch (e, stack) { } on Exception catch (e, stack) {
print("Exception thrown inside session LogCallback block. $e"); print("Exception thrown inside session LogCallback block. $e");
print(stack); print(stack);
}
} }
}
final globalLogCallbackFunction = FFmpegKitFactory.getGlobalLogCallback(); final globalLogCallbackFunction = FFmpegKitFactory.getGlobalLogCallback();
if (globalLogCallbackFunction != null) { if (globalLogCallbackFunction != null) {
globalCallbackDefined = true; globalCallbackDefined = true;
try { try {
// NOTIFY GLOBAL CALLBACK DEFINED // NOTIFY GLOBAL CALLBACK DEFINED
globalLogCallbackFunction(log); globalLogCallbackFunction(log);
} on Exception catch (e, stack) { } on Exception catch (e, stack) {
print("Exception thrown inside global LogCallback block. $e"); print("Exception thrown inside global LogCallback block. $e");
print(stack); print(stack);
}
} }
}
// EXECUTE THE LOG STRATEGY // EXECUTE THE LOG STRATEGY
switch (activeLogRedirectionStrategy) { switch (activeLogRedirectionStrategy) {
case LogRedirectionStrategy.neverPrintLogs: case LogRedirectionStrategy.neverPrintLogs:
{ {
return;
}
case LogRedirectionStrategy.printLogsWhenGlobalCallbackNotDefined:
{
if (globalCallbackDefined) {
return; return;
} }
case LogRedirectionStrategy.printLogsWhenGlobalCallbackNotDefined: }
{ break;
if (globalCallbackDefined) { case LogRedirectionStrategy.printLogsWhenSessionCallbackNotDefined:
return; {
} if (sessionCallbackDefined) {
} return;
break;
case LogRedirectionStrategy.printLogsWhenSessionCallbackNotDefined:
{
if (sessionCallbackDefined) {
return;
}
} }
break; }
case LogRedirectionStrategy.printLogsWhenNoCallbacksDefined: break;
{ case LogRedirectionStrategy.printLogsWhenNoCallbacksDefined:
if (globalCallbackDefined || sessionCallbackDefined) { {
return; if (globalCallbackDefined || sessionCallbackDefined) {
} return;
} }
break; }
case LogRedirectionStrategy.alwaysPrintLogs: break;
{} case LogRedirectionStrategy.alwaysPrintLogs:
break; {}
} break;
}
// PRINT LOGS // PRINT LOGS
switch (level) { switch (level) {
case Level.avLogQuiet: case Level.avLogQuiet:
{ {
// PRINT NO OUTPUT // PRINT NO OUTPUT
} }
break; break;
default: default:
{ {
stdout.write(text); stdout.write(text);
} }
} }
});
} }
void _processStatisticsCallbackEvent(Map<dynamic, dynamic> event) { void _processStatisticsCallbackEvent(Map<dynamic, dynamic> event) {
final Statistics statistics = FFmpegKitFactory.mapToStatistics(event); final Statistics statistics = FFmpegKitFactory.mapToStatistics(event);
final int sessionId = event["sessionId"]; final int sessionId = event["sessionId"];
FFmpegKitConfig.getSession(sessionId).then((Session? session) { final StatisticsCallback? statisticsCallback =
if (session != null && session.isFFmpeg()) { FFmpegKitFactory.getStatisticsCallback(sessionId);
final FFmpegSession ffmpegSession = session as FFmpegSession; if (statisticsCallback != null) {
final StatisticsCallback? statisticsCallback = try {
ffmpegSession.getStatisticsCallback(); // NOTIFY SESSION CALLBACK DEFINED
statisticsCallback(statistics);
if (statisticsCallback != null) { } on Exception catch (e, stack) {
try { print("Exception thrown inside session StatisticsCallback block. $e");
// NOTIFY SESSION CALLBACK DEFINED print(stack);
statisticsCallback(statistics);
} on Exception catch (e, stack) {
print(
"Exception thrown inside session StatisticsCallback block. $e");
print(stack);
}
}
} }
}
final globalStatisticsCallbackFunction = final globalStatisticsCallbackFunction =
FFmpegKitFactory.getGlobalStatisticsCallback(); FFmpegKitFactory.getGlobalStatisticsCallback();
if (globalStatisticsCallbackFunction != null) { if (globalStatisticsCallbackFunction != null) {
try { try {
// NOTIFY GLOBAL CALLBACK DEFINED // NOTIFY GLOBAL CALLBACK DEFINED
globalStatisticsCallbackFunction(statistics); globalStatisticsCallbackFunction(statistics);
} on Exception catch (e, stack) { } on Exception catch (e, stack) {
print("Exception thrown inside global StatisticsCallback block. $e"); print("Exception thrown inside global StatisticsCallback block. $e");
print(stack); print(stack);
}
} }
}); }
} }
void _processExecuteCallbackEvent(Map<dynamic, dynamic> event) { void _processExecuteCallbackEvent(Map<dynamic, dynamic> event) {

Loading…
Cancel
Save