AEAudioThreadEndpoint Class Reference

Audio thread message endpoint. More...

#import <AEAudioThreadEndpoint.h>

Inherits NSObject.

Instance Methods

(instancetype _Nullable) - initWithHandler:
 Default initializer.
 
(instancetype _Nullable) - initWithHandler:bufferCapacity:
 Initializer with custom buffer capacity.
 
(void) - AEAudioThreadEndpointPoll
 Poll for messages.
 
(BOOL) - sendBytes:length:
 Send a message to the audio thread endpoint.
 
(void *_Nullable) - createMessageWithLength:
 Prepare a new message.
 
(void) - dispatchMessage
 Dispatch a message created with createMessageWithLength:
 
(void) - beginMessageGroup
 Begins a group of messages to be performed consecutively.
 
(void) - endMessageGroup
 Ends a consecutive group of messages.
 

Detailed Description

Audio thread message endpoint.

This class implements a mechanism to poll for messages from the main thread upon the audio thread. Initialize an instance and begin calling AEAudioThreadEndpointPoll from your render loop. Then use sendBytes:length: from the main thread to send a message to the audio thread.

Use this utility to perform synchronization across the audio and main threads.

You can also use the AEMainThreadEndpoint class to perform messaging in the reverse direction.

Method Documentation

- (instancetype _Nullable) initWithHandler: (AEAudioThreadEndpointHandler _Nonnull)  handler

Default initializer.

Parameters
handlerThe handler block to use for incoming messages
- (instancetype _Nullable) initWithHandler: (AEAudioThreadEndpointHandler _Nonnull)  handler
bufferCapacity: (size_t)  bufferCapacity 

Initializer with custom buffer capacity.

Parameters
handlerThe handler block to use for incoming messages
bufferCapacityThe buffer capacity, in bytes (default is 8192 bytes). Note that due to the underlying implementation, actual capacity may be larger.
- (void) AEAudioThreadEndpointPoll (__unsafe_unretained AEAudioThreadEndpoint *_Nonnull)  endpoint

Poll for messages.

Call this regularly from your render loop on the audio thread to check for incoming messages.

Parameters
endpointThe endpoint instance
- (BOOL) sendBytes: (const void *_Nullable)  bytes
length: (size_t)  length 

Send a message to the audio thread endpoint.

Use this on the main thread to send messages to the endpoint instance. It will be received and handled on the audio thread at the next poll interval.

Parameters
bytesMessage data (or NULL) to copy
lengthLength of message data
Returns
YES if message sent successfully, NO if there was insufficient buffer space
- (void * _Nullable) createMessageWithLength: (size_t)  length

Prepare a new message.

Use this method to gain access to a writable message buffer of the given length, to assemble the message in multiple parts. Then call dispatchMessage to dispatch.

Parameters
lengthLength of message data
Returns
A pointer to message bytes ready for writing, or NULL if there was insufficient buffer space
- (void) dispatchMessage

Dispatch a message created with createMessageWithLength:

- (void) beginMessageGroup

Begins a group of messages to be performed consecutively.

Messages sent using sendBytes:length: between calls to this method and endMessageGroup will be performed consecutively on the main thread during a single poll interval.

- (void) endMessageGroup

Ends a consecutive group of messages.


The documentation for this class was generated from the following file: