MusicKit  0.0.0
Public Member Functions | Static Public Member Functions | Protected Attributes
SndAudioBufferQueue Class Reference

Abstraction of the producer / consumer buffer queue operation found inside the SndStreamClients, which have both an input and output SndAudioBufferQueue. Provides thread safe buffer exchange and blocking operations. More...

#import <SndAudioBufferQueue.h>

List of all members.

Public Member Functions

(id) - initQueueWithLength:
 Initializes queue for operation with a total of pending+processed buffers.
(SndAudioBuffer *) - popNextPendingBuffer
 Returns the next buffer that is yet to be processed.
(SndAudioBuffer *) - popNextProcessedBuffer
 Returns the next buffer that has already been processed.
(id) - addPendingBuffer:
 Adds buffer to the pending queue.
(id) - addProcessedBuffer:
 Adds a buffer to the processed queue.
(void) - cancelProcessedBuffers
 Moves all processed buffers onto the pending queue.
(int) - pendingBuffersCount
(int) - processedBuffersCount
(id) - freeBuffers
 Frees the SndAudioBuffers within the queues.
(BOOL) - prepareQueueAsType:withBufferPrototype:
 Primes the SndAudioBufferQueue for streaming.
(int) - bufferCount
 Returns the total number of buffers being shuffled about betwixt pending and processed queues.
(id) - initQueueWithLength:
 Initializes queue for operation with a total of pending+processed buffers.
(SndAudioBuffer *) - popNextPendingBuffer
 Returns the next buffer that is yet to be processed.
(SndAudioBuffer *) - popNextProcessedBuffer
 Returns the next buffer that has already been processed.
(id) - addPendingBuffer:
 Adds buffer to the pending queue.
(id) - addProcessedBuffer:
 Adds a buffer to the processed queue.
(void) - cancelProcessedBuffers
 Moves all processed buffers onto the pending queue.
(int) - pendingBuffersCount
(int) - processedBuffersCount
(id) - freeBuffers
 Frees the SndAudioBuffers within the queues.
(BOOL) - prepareQueueAsType:withBufferPrototype:
 Primes the SndAudioBufferQueue for streaming.
(int) - bufferCount
 Returns the total number of buffers being shuffled about betwixt pending and processed queues.

Static Public Member Functions

(id) + audioBufferQueueWithLength:
 Factory method.
(id) + audioBufferQueueWithLength:
 Factory method.

Protected Attributes

NSMutableArray * pendingBuffers
NSMutableArray * processedBuffers
NSConditionLock * pendingBuffersLock
NSConditionLock * processedBuffersLock
unsigned int numBuffers
unsigned int maximumPendingBuffers
unsigned int maximumProcessedBuffers

Detailed Description

Abstraction of the producer / consumer buffer queue operation found inside the SndStreamClients, which have both an input and output SndAudioBufferQueue. Provides thread safe buffer exchange and blocking operations.


Member Function Documentation

- (id) addPendingBuffer: (SndAudioBuffer *)  audioBuffer

Adds buffer to the pending queue.

Parameters:
audioBufferBuffer to be added
Returns:
Returns self.
- (id) addPendingBuffer: (SndAudioBuffer *)  audioBuffer

Adds buffer to the pending queue.

Parameters:
audioBufferBuffer to be added
Returns:
Returns self.
- (id) addProcessedBuffer: (SndAudioBuffer *)  audioBuffer

Adds a buffer to the processed queue.

Parameters:
audioBufferBuffer to be added
Returns:
Returns self.
- (id) addProcessedBuffer: (SndAudioBuffer *)  audioBuffer

Adds a buffer to the processed queue.

Parameters:
audioBufferBuffer to be added
Returns:
Returns self.
+ (id) audioBufferQueueWithLength: (int)  numberOfBuffers

Factory method.

Parameters:
numberOfBuffersBuffer queue length.

Creates a fresh new SndAudioBufferQueue, sets the eventual number of buffers to numberOfBuffers.

Returns:
An autoreleased SndAudioBufferQueue instance.
+ (id) audioBufferQueueWithLength: (int)  numberOfBuffers

Factory method.

Parameters:
numberOfBuffersBuffer queue length.

Creates a fresh new SndAudioBufferQueue, sets the eventual number of buffers to numberOfBuffers.

Returns:
An autoreleased SndAudioBufferQueue instance.
- (int) bufferCount

Returns the total number of buffers being shuffled about betwixt pending and processed queues.

Returns:
Number of buffers in queues
- (int) bufferCount

Returns the total number of buffers being shuffled about betwixt pending and processed queues.

Returns:
Number of buffers in queues
- (id) freeBuffers

Frees the SndAudioBuffers within the queues.

Returns:
Returns self
- (id) freeBuffers

Frees the SndAudioBuffers within the queues.

Returns:
Returns self
- (id) initQueueWithLength: (int)  numberOfBuffers

Initializes queue for operation with a total of pending+processed buffers.

Since we add and pop buffers in separate methods, if we try to add before popping, we will need to use one less than the full number of buffers initialized with, such that we never exceed the maximum. For example, if we initialize with 4 buffers, at best we can hold only 3 processed buffers so we can add a pending buffer, before then popping a processed buffer.

Parameters:
numberOfBuffersNumber of buffers.
Returns:
Returns self.
- (id) initQueueWithLength: (int)  numberOfBuffers

Initializes queue for operation with a total of pending+processed buffers.

Since we add and pop buffers in separate methods, if we try to add before popping, we will need to use one less than the full number of buffers initialized with, such that we never exceed the maximum. For example, if we initialize with 4 buffers, at best we can hold only 3 processed buffers so we can add a pending buffer, before then popping a processed buffer.

Parameters:
numberOfBuffersNumber of buffers.
Returns:
Returns self.
Returns:
Number of buffers in the pending queue
Returns:
Number of buffers in the pending queue

Returns the next buffer that is yet to be processed.

In contexts where the queue is used for input and output processing, the returned buffer can be interpreted as:

  • output - The next buffer to be synthesized / produced
  • input - The next input buffer to be processed

Blocks the calling thread until a buffer is present for popping.

Returns:
Returns an autoreleased SndAudioBuffer instance.

Returns the next buffer that is yet to be processed.

In contexts where the queue is used for input and output processing, the returned buffer can be interpreted as:

  • output - The next buffer to be synthesized / produced
  • input - The next input buffer to be processed

Blocks the calling thread until a buffer is present for popping.

Returns:
Returns an autoreleased SndAudioBuffer instance.

Returns the next buffer that has already been processed.

In contexts where the queue is used for input and output processing, the returned buffer can be interpreted as:

  • output - The next buffer to be consumed by the world at large
  • input - The next buffer to be filled with input material

Blocks the calling thread until a buffer is present for popping.

Returns:
Returns an autoreleased SndAudioBuffer instance.

Returns the next buffer that has already been processed.

In contexts where the queue is used for input and output processing, the returned buffer can be interpreted as:

  • output - The next buffer to be consumed by the world at large
  • input - The next buffer to be filled with input material

Blocks the calling thread until a buffer is present for popping.

Returns:
Returns an autoreleased SndAudioBuffer instance.
- (BOOL) prepareQueueAsType: (SndAudioBufferQueueType)  type
withBufferPrototype: (SndAudioBuffer *)  buff 

Primes the SndAudioBufferQueue for streaming.

Parameters:
typeEither audioBufferQueue_typeInput or audioBufferQueue_typeOutput
buffThe format of the SndAudioBuffer buff will be used as a template for the internal queued buffers.

If prepared as an input queue, the buffers are initially placed in the processed queue; otherwise the fresh buffers are placed in the pending queue. The former ensures that any input buffer consumers do not get empty buffers, and the latter allows buffer producers (eg synthesizers) to process several buffers ahead, giving them some processing head room in a multi-threaded environment.

Returns:
Returns self.
- (BOOL) prepareQueueAsType: (SndAudioBufferQueueType)  type
withBufferPrototype: (SndAudioBuffer *)  buff 

Primes the SndAudioBufferQueue for streaming.

Parameters:
typeEither audioBufferQueue_typeInput or audioBufferQueue_typeOutput
buffThe format of the SndAudioBuffer buff will be used as a template for the internal queued buffers.

If prepared as an input queue, the buffers are initially placed in the processed queue; otherwise the fresh buffers are placed in the pending queue. The former ensures that any input buffer consumers do not get empty buffers, and the latter allows buffer producers (eg synthesizers) to process several buffers ahead, giving them some processing head room in a multi-threaded environment.

Returns:
Returns self.
Returns:
Number of buffers in the processed queue
Returns:
Number of buffers in the processed queue

Member Data Documentation

- (unsigned int) maximumPendingBuffers [protected]

Maximum number of buffers ever stored in pending queue

- (unsigned int) maximumProcessedBuffers [protected]

Maximum number of buffers ever stored in process queue

- (unsigned int) numBuffers [protected]

Total number of buffers in the queue, both pending and processed

- (NSMutableArray *) pendingBuffers [protected]

Array of buffers pending processing (to be consumed)

- (NSConditionLock *) pendingBuffersLock [protected]

Lock for thread safety around pending buffers array

- (NSMutableArray *) processedBuffers [protected]

Array of processed buffers (post consumption)

- (NSConditionLock *) processedBuffersLock [protected]

Lock for thread safety around processed buffers array


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