1 // Copyright 2017-present 650 Industries. All rights reserved. 2 3 #ifdef __cplusplus 4 5 #import <AVFoundation/AVFoundation.h> 6 7 #import <jsi/jsi.h> 8 9 // TODO: Replace this with <ReactCommon/TurboModuleUtils.h> after we upgrade to RN 0.66 10 #import <EXAV/CallbackWrapper.h> 11 12 namespace jsi = facebook::jsi; 13 using CallInvoker = facebook::react::CallInvoker; 14 15 // TODO: Replace this with just facebook::react namespace after we upgrade to RN 0.66 16 using JsiCallbackWrapper = expo::CallbackWrapper; 17 using LongLivedObjectCollection = expo::LongLivedObjectCollection; 18 19 namespace expo { 20 namespace av { 21 22 // A class managing lifecycle of audio sample buffer callbacks 23 class AudioSampleCallbackWrapper 24 { 25 std::weak_ptr<JsiCallbackWrapper> weakWrapper; 26 public: 27 AudioSampleCallbackWrapper(jsi::Function &&callback, 28 jsi::Runtime &runtime, 29 std::shared_ptr<CallInvoker> jsInvoker); 30 31 ~AudioSampleCallbackWrapper(); 32 33 void call(AudioBuffer* buffer, double timestamp); 34 35 // static members 36 public: 37 // called when JS VM is destroyed to remove all JSI callback objects removeAllCallbacks()38 static void removeAllCallbacks() { 39 callbackCollection->clear(); 40 } 41 42 private: 43 static std::shared_ptr<LongLivedObjectCollection> callbackCollection; 44 }; 45 46 } // namespace av 47 } // namespace expo 48 49 #endif // __cplusplus 50