From 7e16723cc4cea10bff83b4847e90626524c89155 Mon Sep 17 00:00:00 2001 From: Callum Moffat Date: Tue, 11 Jan 2022 13:42:42 -0500 Subject: [PATCH] Run callbacks on main queue --- .../ios/Classes/FFmpegKitFlutterPlugin.m | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/flutter/flutter/ios/Classes/FFmpegKitFlutterPlugin.m b/flutter/flutter/ios/Classes/FFmpegKitFlutterPlugin.m index c7b5f8a..22381a2 100644 --- a/flutter/flutter/ios/Classes/FFmpegKitFlutterPlugin.m +++ b/flutter/flutter/ios/Classes/FFmpegKitFlutterPlugin.m @@ -112,30 +112,40 @@ extern int const AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit; - (void)registerGlobalCallbacks { [FFmpegKitConfig enableFFmpegSessionCompleteCallback:^(FFmpegSession* session){ NSDictionary *dictionary = [FFmpegKitFlutterPlugin toSessionDictionary:session]; - self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_COMPLETE_CALLBACK_EVENT withDictionary:dictionary]); + dispatch_async(dispatch_get_main_queue(), ^() { + self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_COMPLETE_CALLBACK_EVENT withDictionary:dictionary]); + }); }]; [FFmpegKitConfig enableFFprobeSessionCompleteCallback:^(FFprobeSession* session){ NSDictionary *dictionary = [FFmpegKitFlutterPlugin toSessionDictionary:session]; - self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_COMPLETE_CALLBACK_EVENT withDictionary:dictionary]); + dispatch_async(dispatch_get_main_queue(), ^() { + self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_COMPLETE_CALLBACK_EVENT withDictionary:dictionary]); + }); }]; [FFmpegKitConfig enableMediaInformationSessionCompleteCallback:^(MediaInformationSession* session){ NSDictionary *dictionary = [FFmpegKitFlutterPlugin toSessionDictionary:session]; - self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_COMPLETE_CALLBACK_EVENT withDictionary:dictionary]); + dispatch_async(dispatch_get_main_queue(), ^() { + self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_COMPLETE_CALLBACK_EVENT withDictionary:dictionary]); + }); }]; [FFmpegKitConfig enableLogCallback: ^(Log* log){ if (self->logsEnabled) { NSDictionary *dictionary = [FFmpegKitFlutterPlugin toLogDictionary:log]; - self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_LOG_CALLBACK_EVENT withDictionary:dictionary]); + dispatch_async(dispatch_get_main_queue(), ^() { + self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_LOG_CALLBACK_EVENT withDictionary:dictionary]); + }); } }]; [FFmpegKitConfig enableStatisticsCallback:^(Statistics* statistics){ if (self->statisticsEnabled) { NSDictionary *dictionary = [FFmpegKitFlutterPlugin toStatisticsDictionary:statistics]; - self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_STATISTICS_CALLBACK_EVENT withDictionary:dictionary]); + dispatch_async(dispatch_get_main_queue(), ^() { + self->_eventSink([FFmpegKitFlutterPlugin toStringDictionary:EVENT_STATISTICS_CALLBACK_EVENT withDictionary:dictionary]); + }); } }]; }