Package com.vivoka.vsdk.audio
Class Pipeline
java.lang.Object
com.vivoka.vsdk.audio.Pipeline
Represents an audio processing pipeline.
The pipeline consists of:
- a single
producermodule, - zero or more
modifiermodules, and - zero or more
consumermodules.
The pipeline manages the flow of audio buffers from the producer through the modifiers to the consumers, and can operate in either synchronous or asynchronous mode.
Supported operations include:
start()pause()resume()stop()
Note that not all operations are supported by every producer implementation. For example, some producers may not support pausing or resuming once started.
The pipeline also provides methods to add or remove modifiers and consumers at specific positions, ensuring proper error handling and state management for the producer module.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoideraseConsumer(Iterator<IConsumerModule> iterator) Removes a consumer module from the consumer list using the provided iterator.voideraseModifier(Iterator<IModifierModule> iterator) Removes a modifier module from the modifier list using the provided iterator.static List<WeakReference<Pipeline>> Returns a list of all currently active pipelines.insertConsumer(int position, IConsumerModule consumerModule) Inserts a consumer module at the specified position in the consumer list.insertModifier(int position, IModifierModule modifierModule) Inserts a modifier module at the specified position in the modifier list.booleanisActive()Checks if the pipeline is currently active in synchronous or asynchronous mode.voidpause()Pauses the audio processing pipeline if it is currently running in asynchronous mode.pushBackConsumer(IConsumerModule consumerModule) Adds a consumer module to the end of the consumer list.pushBackModifier(IModifierModule modifierModule) Adds a modifier module to the end of the modifier list.pushFrontConsumer(IConsumerModule consumerModule) Adds a consumer module to the end of the consumer list.pushFrontModifier(IModifierModule modifierModule) Adds a modifier module to the end of the modifier list.voidresume()Resumes the audio processing pipeline if it is currently paused in asynchronous mode.voidrun()Runs the audio processing pipeline in a synchronous manner.voidsetProducer(ProducerModule producer) Sets the producer module for the pipeline.voidstart()Starts the audio processing pipeline in asynchronous mode.voidstop()Stops the audio processing pipeline if it is currently running in asynchronous mode.voidUnsubscribes the pipeline from the current producer, if any.
-
Constructor Details
-
Pipeline
public Pipeline()Creates a new audio processing pipeline.
-
-
Method Details
-
run
Runs the audio processing pipeline in a synchronous manner. This method will block until the processing is complete. It will throw an Exception if any error occurs during the processing. This method will call open(), run(), and close() methods of the producer. Note that pause() and resume() operations are not supported in this mode.- Throws:
Exception- If any error occurs during the processing.
-
start
Starts the audio processing pipeline in asynchronous mode. This method will return immediately and the processing will occur in a separate thread. It will throw an Exception if any error occurs during the start operation. This method will call open() and start() methods of the producer. Note that pause() and resume() operations are supported in this mode if the producer allows it.- Throws:
Exception- If any error occurs during the start operation.
-
pause
Pauses the audio processing pipeline if it is currently running in asynchronous mode.- Throws:
Exception- Throw an Exception if the producer does not support pausing or if any error occurs during the pause operation.
-
resume
Resumes the audio processing pipeline if it is currently paused in asynchronous mode.- Throws:
Exception- Throw an Exception if the producer does not support resuming or if any error occurs during the resume operation.
-
stop
Stops the audio processing pipeline if it is currently running in asynchronous mode.- Throws:
Exception- Throw an Exception if any error occurs during the stop operation.
-
isActive
public boolean isActive()Checks if the pipeline is currently active in synchronous or asynchronous mode.- Returns:
- True if the pipeline is active, false otherwise.
-
setProducer
Sets the producer module for the pipeline. If a producer is already set, it will be unsubscribed and closed before setting the new one. The pipeline will subscribe to the new producer to receive audio buffers and dispatch them.- Parameters:
producer- The producer module to set.- Throws:
Exception- If any error occurs while unsubscribing the previous producer or subscribing the new producer.
-
pushBackModifier
Adds a modifier module to the end of the modifier list. The modifier will be applied to audio buffers after all previously added modifiers.- Parameters:
modifierModule- The modifier module to add.- Returns:
- An iterator pointing to the added modifier module.
- Throws:
Exception- If any error occurs while adding the modifier module.
-
pushBackConsumer
Adds a consumer module to the end of the consumer list. The consumer will be called after all previously added consumers.- Parameters:
consumerModule- The consumer module to add.- Returns:
- An iterator pointing to the added consumer module.
- Throws:
Exception- If any error occurs while adding the consumer module.
-
pushFrontModifier
Adds a modifier module to the end of the modifier list. The modifier will be applied to audio buffers before all previously added modifiers.- Parameters:
modifierModule- The modifier module to add.- Returns:
- An iterator pointing to the added modifier module.
- Throws:
Exception- If any error occurs while adding the modifier module.
-
pushFrontConsumer
Adds a consumer module to the end of the consumer list. The consumer will be called before all previously added consumers.- Parameters:
consumerModule- The consumer module to add.- Returns:
- An iterator pointing to the added consumer module.
- Throws:
Exception- If any error occurs while adding the consumer module.
-
insertModifier
public Iterator<IModifierModule> insertModifier(int position, IModifierModule modifierModule) throws Exception Inserts a modifier module at the specified position in the modifier list. The position must be between 0 and the current size of the modifier list (inclusive).- Parameters:
position- The position at which to insert the modifier module.modifierModule- The modifier module to insert.- Returns:
- An iterator pointing to the inserted modifier module.
- Throws:
Exception- If the position is out of bounds.
-
insertConsumer
public Iterator<IConsumerModule> insertConsumer(int position, IConsumerModule consumerModule) throws Exception Inserts a consumer module at the specified position in the consumer list. The position must be between 0 and the current size of the consumer list (inclusive).- Parameters:
position- The position at which to insert the consumer module.consumerModule- The consumer module to insert.- Returns:
- An iterator pointing to the inserted consumer module.
- Throws:
Exception- If the position is out of bounds.
-
eraseModifier
Removes a modifier module from the modifier list using the provided iterator.- Parameters:
iterator- The iterator pointing to the modifier module to remove.- Throws:
Exception- If the iterator is invalid or out of bounds.
-
eraseConsumer
Removes a consumer module from the consumer list using the provided iterator.- Parameters:
iterator- The iterator pointing to the consumer module to remove.- Throws:
Exception- If the iterator is invalid or out of bounds.
-
unsubscribeFromProducer
Unsubscribes the pipeline from the current producer, if any. This will also close the producer if it is not already closed.- Throws:
Exception- If any error occurs while unsubscribing or closing the producer.
-
clearModifiers
public void clearModifiers() -
clearConsumers
public void clearConsumers() -
getActivePipelines
Returns a list of all currently active pipelines.- Returns:
- A list of all currently active pipelines.
-