Package com.vivoka.vsdk.audio
Class ProducerModule
java.lang.Object
com.vivoka.vsdk.audio.ProducerModule
- Direct Known Subclasses:
AudioRecorder,BufferForwarder,BufferModule,BufferModuleOut,BufferStreamer,Channel,File
Abstract class representing a producer module in the audio processing pipeline.
This class provides methods for managing subscribers, handling errors, and dispatching audio buffers.
It defines the lifecycle of a producer module including opening, running, starting, pausing, resuming,
stopping, and closing operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum representing the state of the producer module. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCloses the producer module.protected voiddispatchAudio(int channelCount, int sampleRate, byte[] audioData, boolean last) Dispatches audio data to the subscribers.protected voiddispatchBuffer(Buffer buffer, boolean last) Dispatches audio data to the subscribers.Gets the last error message associated with the producer module.getState()Gets the current state of the producer module.booleanisBusy()Checks if the producer module is currently busy.booleanisClosed()Checks if the producer module is currently closed and ready tostart()orrun()a new pipeline operation.booleanisIdle()Checks if the producer module is currently idle.booleanisOpened()Checks if the producer module is currently opened.booleanisPaused()Checks if the producer module is currently paused.booleanChecks if the producer module is currently running.booleanChecks if the producer module is currently started.protected voidopenImpl()Opens the producer module.protected voidPauses the producer module.protected voidResumes the producer module.protected voidrunImpl()Runs the producer module in a blocking manner.protected voidsetLastError(String error) protected voidsetState(ProducerModule.State state) voidsetStateChanedCallback(androidx.core.util.Consumer<ProducerModule.State> onStateChanged) protected voidStarts the producer module in a non-blocking manner.protected voidstopImpl()Stops the producer module.subscribeFirst(IAudioCallback audioCallback) Subscribes an audio callback to the producer module.subscribeLast(IAudioCallback audioCallback) Subscribes an audio callback to the end of the subscriber list.voidunsubscribe(int position) Unsubscribes an audio callback from the producer module.
-
Constructor Details
-
ProducerModule
public ProducerModule()Constructor for the ProducerModule class. Initializes the producer module with an empty list of subscribers.
-
-
Method Details
-
subscribeFirst
Subscribes an audio callback to the producer module. The callback will be notified when audio data is available.- Parameters:
audioCallback- The audio callback to subscribe.- Returns:
- An iterator representing the position of the subscriber.
- Throws:
Exception- If the audioCallback is null.
-
subscribeLast
Subscribes an audio callback to the end of the subscriber list. The callback will be notified when audio data is available.- Parameters:
audioCallback- The audio callback to subscribe.- Returns:
- An iterator representing the position of the subscriber.
- Throws:
Exception- If the audioCallback is null.
-
unsubscribe
Unsubscribes an audio callback from the producer module. The callback will no longer be notified when audio data is available.- Parameters:
position- The position of the subscriber to unsubscribe.- Throws:
Exception- If the position is negative or out of bounds.
-
getLastError
Gets the last error message associated with the producer module. This can be used to retrieve error information after an operation fails.- Returns:
- The last error message, or null if no error has occurred.
-
setLastError
- Throws:
Exception
-
getState
Gets the current state of the producer module. This can be used to check if the module is opened, running, started, paused, idle, or closed.- Returns:
- The current state of the producer module.
-
setState
-
setStateChanedCallback
public void setStateChanedCallback(androidx.core.util.Consumer<ProducerModule.State> onStateChanged) -
isOpened
public boolean isOpened()Checks if the producer module is currently opened. This indicates that the module is ready to start processing audio data.- Returns:
- True if the producer module is opened, false otherwise.
-
isRunning
public boolean isRunning()Checks if the producer module is currently running. This indicates that the module is actively processing audio data in synchronous mode.- Returns:
- True if the producer module is running, false otherwise.
-
isStarted
public boolean isStarted()Checks if the producer module is currently started. This indicates that the module is actively processing audio data in asynchronous mode.- Returns:
- True if the producer module is started, false otherwise.
-
isPaused
public boolean isPaused()Checks if the producer module is currently paused. This indicates that the module has been paused and can be resumed later.- Returns:
- True if the producer module is paused, false otherwise.
-
isIdle
public boolean isIdle()Checks if the producer module is currently idle. This indicates that the module has completed its work and thestop()was not called.- Returns:
- True if the producer module is idle, false otherwise.
-
isClosed
public boolean isClosed()Checks if the producer module is currently closed and ready tostart()orrun()a new pipeline operation.- Returns:
- True if the producer module is closed, false otherwise.
-
isBusy
public boolean isBusy()Checks if the producer module is currently busy. This indicates that the module is either running or started.- Returns:
- True if the producer module is busy, false otherwise.
-
openImpl
Opens the producer module. This method prepares the module for processing audio data. This method is called by the pipeline before starting or running the producer.- Throws:
Exception- If the producer is already opened or an error occurs during opening.
-
runImpl
Runs the producer module in a blocking manner. The producer state must beOPENED. When calling run pipeline, this method will be called after theopenmethod. The state remains RUNNING until the end and then becomes OPENED.- Throws:
Exception- If the producer is not opened or an error occurs during running.
-
startImpl
Starts the producer module in a non-blocking manner. The producer state must beOPENED. When calling start pipeline, this method will be called after theopenmethod. startImpl() should initiate the producer and return immediately without waiting for processing to complete and update the state to STARTED when it is done.- Throws:
Exception- If an error occurs during starting.
-
pauseImpl
Pauses the producer module. The producer state must beSTARTED. When calling pause pipeline, this method will be called. It should initiate the pausing process and return immediately without waiting for it to complete. It should make sure that the state is updated to PAUSED when it is done.- Throws:
Exception- If an error occurs during pausing.
-
resumeImpl
Resumes the producer module. The producer state must bePAUSED. When the producer is resumed, the child class needs to update the state to STARTED. When calling resume pipeline, this method will be called. It should initiate the resuming process and return immediately without waiting for it to complete. It should make sure that the state is updated to OPENED when it is done.- Throws:
Exception- If an error occurs during resuming.
-
stopImpl
Stops the producer module. The producer state must beSTARTED. When calling stop pipeline, this method will be called. It should initiate the stopping process and return immediately without waiting for it to complete. It should make sure that the state is updated to OPENED when it is done.- Throws:
Exception- If an error occurs during stopping.
-
closeImpl
Closes the producer module. The producer state must beOPENEDorIDLE. When calling stop pipeline, this method will be called after thecloseImplmethod. When calling run pipeline, this method will be called after therunImplmethod. If the closeImpl is asynchronous, the closeImpl should wait until the producer is OPENED.- Throws:
Exception- If an error occurs during closing.
-
dispatchAudio
protected void dispatchAudio(int channelCount, int sampleRate, byte[] audioData, boolean last) throws Exception Dispatches audio data to the subscribers.- Parameters:
channelCount- The number of channels.sampleRate- The sample rate.audioData- The audio data.last- Whether this is the last audio data.- Throws:
Exception- If an error occurs during dispatching.
-
dispatchBuffer
Dispatches audio data to the subscribers.- Parameters:
buffer- The audio buffer.last- Whether this is the last audio data.- Throws:
Exception- If an error occurs during dispatching.
-