Class Pipeline

java.lang.Object
com.vivoka.vsdk.audio.Pipeline

public class Pipeline extends Object
Represents an audio processing pipeline.

The pipeline consists of:

  • a single producer module,
  • zero or more modifier modules, and
  • zero or more consumer modules.

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 Details

    • Pipeline

      public Pipeline()
      Creates a new audio processing pipeline.
  • Method Details

    • run

      public void run() throws Exception
      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

      public void start() throws Exception
      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

      public void pause() throws Exception
      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

      public void resume() throws Exception
      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

      public void stop() throws Exception
      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

      public void setProducer(ProducerModule producer) throws Exception
      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

      public Iterator<IModifierModule> pushBackModifier(IModifierModule modifierModule) throws Exception
      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

      public Iterator<IConsumerModule> pushBackConsumer(IConsumerModule consumerModule) throws Exception
      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

      public Iterator<IModifierModule> pushFrontModifier(IModifierModule modifierModule) throws Exception
      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

      public Iterator<IConsumerModule> pushFrontConsumer(IConsumerModule consumerModule) throws Exception
      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

      public void eraseModifier(Iterator<IModifierModule> iterator) throws Exception
      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

      public void eraseConsumer(Iterator<IConsumerModule> iterator) throws Exception
      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

      public void unsubscribeFromProducer() throws Exception
      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

      public static List<WeakReference<Pipeline>> getActivePipelines()
      Returns a list of all currently active pipelines.
      Returns:
      A list of all currently active pipelines.