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. | |
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.
- (instancetype _Nullable) initWithHandler: | (AEAudioThreadEndpointHandler _Nonnull) | handler |
Default initializer.
handler | The handler block to use for incoming messages |
- (instancetype _Nullable) initWithHandler: | (AEAudioThreadEndpointHandler _Nonnull) | handler | |
bufferCapacity: | (size_t) | bufferCapacity | |
Initializer with custom buffer capacity.
handler | The handler block to use for incoming messages |
bufferCapacity | The 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.
endpoint | The 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.
bytes | Message data (or NULL) to copy |
length | Length of message data |
- (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.
length | Length of message data |
- (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.