Skip to content

Commit

Permalink
IPC connection now uses two message channels to deal with threading
Browse files Browse the repository at this point in the history
  • Loading branch information
sgretscher committed Feb 12, 2024
1 parent 33eef73 commit c718222
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
11 changes: 9 additions & 2 deletions TestHost/CompanionAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ constexpr auto kIPCDestroyEffectMethodID { ARA::IPC::MethodID::createWithNonARAM
constexpr auto kIPCTerminateMethodID { ARA::IPC::MethodID::createWithNonARAMethodID<-6> () };


constexpr auto mainChannelIDSuffix { ".main" };
constexpr auto otherChannelIDSuffix { ".other" };


#if defined (__GNUC__)
_Pragma ("GCC diagnostic push")
_Pragma ("GCC diagnostic ignored \"-Wunused-template\"")
Expand Down Expand Up @@ -552,7 +556,8 @@ class IPCPlugInEntry : public PlugInEntry, private RemoteLauncher, public ARA::I
: PlugInEntry { std::move (description) },
RemoteLauncher { launchArgs, channelID },
ARA::IPC::ProxyPlugIn { this },
Connection { this, IPCMessageChannel::createConnectedToID (channelID, this) }
Connection { this, IPCMessageChannel::createConnectedToID (channelID + mainChannelIDSuffix, this),
IPCMessageChannel::createConnectedToID (channelID + otherChannelIDSuffix, this) }
{
validateAndSetFactory (getFactoryFunction (toIPCRef (getConnection ())));
}
Expand Down Expand Up @@ -678,7 +683,9 @@ class ProxyHost : public ARA::IPC::ProxyHost, public Connection
public:
ProxyHost (const std::string& channelID)
: ARA::IPC::ProxyHost { this },
Connection { this, IPCMessageChannel::createPublishingID (channelID, this) }
Connection { this, IPCMessageChannel::createPublishingID (channelID + mainChannelIDSuffix, this),
IPCMessageChannel::createPublishingID (channelID + otherChannelIDSuffix, this)
}
{}

void handleReceivedMessage (const ARA::IPC::MessageID messageID,
Expand Down
38 changes: 25 additions & 13 deletions TestPlugIn/AudioUnit_v3/Framework/TestAUv3AudioUnit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ @implementation TestAUv3ARAIPCMessageChannel {

@synthesize callHostBlock = _callHostBlock;

- (instancetype)init {
- (instancetype)initAsMainThreadChannel:(BOOL) isMainThreadChannel {
self = [super init];

if (self == nil) { return nil; }

_callHostBlock = nil;
_messageChannelRef = ARA::IPC::ARAIPCAUProxyHostInitializeMessageChannel(self);
_messageChannelRef = ARA::IPC::ARAIPCAUProxyHostInitializeMessageChannel(self, isMainThreadChannel);

return self;
}
Expand Down Expand Up @@ -261,33 +261,45 @@ and modify the (outputData->mBuffers[x].mData) pointers to point to this owned m

#if ARA_AUDIOUNITV3_IPC_IS_AVAILABLE

NSObject<AUMessageChannel> * __strong _sharedFactoryMessageChannel API_AVAILABLE(macos(13.0)) = nil;
NSObject<AUMessageChannel> * __strong _mainMessageChannel API_AVAILABLE(macos(13.0)) = nil;
NSObject<AUMessageChannel> * __strong _otherMessageChannel API_AVAILABLE(macos(13.0)) = nil;

__attribute__((destructor))
void destroy_sharedFactoryMessageChannel() {
void destroy_sharedMessageChannels() {
if (@available(macOS 13.0, *))
{
if (_sharedFactoryMessageChannel)
{
if (_mainMessageChannel || _otherMessageChannel)
ARA::IPC::ARAIPCAUProxyHostUninitialize();
_sharedFactoryMessageChannel = nil;
}
_mainMessageChannel = nil;
_otherMessageChannel = nil;
}
}

// \todo the return value should be _Nullable!
- (id<AUMessageChannel> _Nonnull)messageChannelFor:(NSString * _Nonnull)channelName {
if (@available(macOS 13.0, *))
{
if ([channelName isEqualTo:ARA_AUDIOUNIT_FACTORY_CUSTOM_MESSAGES_UTI])
if ([channelName isEqualTo:ARA_AUDIOUNIT_MAIN_THREAD_MESSAGES_UTI])
{
if (!_mainMessageChannel)
{
if (!_otherMessageChannel)
ARA::IPC::ARAIPCProxyHostAddFactory(ARATestDocumentController::getARAFactory());
_mainMessageChannel = [[TestAUv3ARAIPCMessageChannel alloc] initAsMainThreadChannel:YES];
}

return _mainMessageChannel;
}
if ([channelName isEqualTo:ARA_AUDIOUNIT_OTHER_THREADS_MESSAGES_UTI])
{
if (!_sharedFactoryMessageChannel)
if (!_otherMessageChannel)
{
ARA::IPC::ARAIPCProxyHostAddFactory(ARATestDocumentController::getARAFactory());
_sharedFactoryMessageChannel = [TestAUv3ARAIPCMessageChannel new];
if (!_mainMessageChannel)
ARA::IPC::ARAIPCProxyHostAddFactory(ARATestDocumentController::getARAFactory());
_otherMessageChannel = [[TestAUv3ARAIPCMessageChannel alloc] initAsMainThreadChannel:NO];
}

return _sharedFactoryMessageChannel;
return _otherMessageChannel;
}
}
return nil;
Expand Down

0 comments on commit c718222

Please sign in to comment.