Package com.twilio.voice
Interface AudioDevice
- All Superinterfaces:
AudioDeviceCapturer
,AudioDeviceRenderer
- All Known Implementing Classes:
DefaultAudioDevice
AudioDevice interface allows developers to inject custom audio device capturer and audio device
renderer of audio by replacing the default device used by the SDK.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
audioDeviceExecuteWorkerBlock
(AudioDeviceContext audioDeviceContext, Runnable runnable) A utility method to execute a runnable on the media engine's worker thread asynchronously.static void
audioDeviceFormatChanged
(AudioDeviceContext audioDeviceContext) This method should be called any time the capturing or rendering format changes.static void
audioDeviceReadRenderData
(AudioDeviceContext audioDeviceContext, ByteBuffer audioSample) This method needs to be called byAudioDeviceRenderer
` to pull renderable audio data from the media engine.static void
audioDeviceWriteCaptureData
(AudioDeviceContext audioDeviceContext, ByteBuffer audioSample) This method needs to be called byAudioDeviceCapturer
implementation to provide captured data to the media engine.Methods inherited from interface com.twilio.voice.AudioDeviceCapturer
getCapturerFormat, onInitCapturer, onStartCapturing, onStopCapturing
Methods inherited from interface com.twilio.voice.AudioDeviceRenderer
getRendererFormat, onInitRenderer, onStartRendering, onStopRendering
-
Method Details
-
audioDeviceFormatChanged
This method should be called any time the capturing or rendering format changes. If both formats change simultaneously its fine to call this method just once. As a result the media engine will read the new audio format, stop capturing and/or rendering by callingAudioDeviceCapturer.onStopCapturing()
and/orAudioDeviceRenderer.onStopRendering()
and then callAudioDeviceCapturer.onStartCapturing(AudioDeviceContext)
and/orAudioDeviceRenderer.onStartRendering(AudioDeviceContext)
.- Parameters:
audioDeviceContext
- The AudioDevice context. You should use the same context provided in `AudioDeviceCapturer.onStartCapturing(AudioDeviceContext)
and/orAudioDeviceRenderer.onStartRendering(AudioDeviceContext)
here.
-
audioDeviceWriteCaptureData
static void audioDeviceWriteCaptureData(@NonNull AudioDeviceContext audioDeviceContext, @NonNull ByteBuffer audioSample) This method needs to be called byAudioDeviceCapturer
implementation to provide captured data to the media engine. WhenAudioDeviceCapturer.onStartCapturing(AudioDeviceContext)
callback is raised, call this method in a loop to provide captured data to media engine.- Parameters:
audioDeviceContext
- The AudioDevice context. You should use the same context provided in `AudioDeviceCapturer.onStartCapturing(AudioDeviceContext)
and/orAudioDeviceRenderer.onStartRendering(AudioDeviceContext)
here.audioSample
- Audio data you wish to deliver.
-
audioDeviceReadRenderData
static void audioDeviceReadRenderData(@NonNull AudioDeviceContext audioDeviceContext, @NonNull ByteBuffer audioSample) This method needs to be called byAudioDeviceRenderer
` to pull renderable audio data from the media engine.- Parameters:
audioDeviceContext
- The context reference. You should use the same context provided inAudioDeviceRenderer.onStartRendering(AudioDeviceContext)
here.audioSample
- A reference to a buffer where the signed 16-bit LPCM audio data will be copied into.
-
audioDeviceExecuteWorkerBlock
static void audioDeviceExecuteWorkerBlock(@NonNull AudioDeviceContext audioDeviceContext, @NonNull Runnable runnable) A utility method to execute a runnable on the media engine's worker thread asynchronously.AudioDevice invokes the callbacks on the media engine's worker thread. If you wish to initialize, start or stop the audio device from your application code, to avoid the thread-safety problems, you should execute code from the media engine's worker thread.
- Parameters:
audioDeviceContext
- The AudioDevice context. You should use the same context provided inAudioDeviceRenderer.onStartRendering(AudioDeviceContext)
orAudioDeviceCapturer.onStartCapturing(AudioDeviceContext)
here.runnable
- A block which will be executed on the media engine's worker thread.
-