public class WASAPISystem extends AudioSystem
AudioSystem.DataFlow
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_BUFFER_DURATION
The default duration of audio data in milliseconds to be read from
WASAPIStream in an invocation of
WASAPIStream.read(Buffer) or to be processed by
WASAPIRenderer in an invocation of
WASAPIRenderer.process(Buffer) . |
static long |
DEFAULT_DEVICE_PERIOD
The default interval in milliseconds between periodic processing passes
by the audio engine.
|
FEATURE_AGC, FEATURE_DENOISE, FEATURE_ECHO_CANCELLATION, FEATURE_NOTIFY_AND_PLAYBACK_DEVICES, LOCATOR_PROTOCOL_AUDIORECORD, LOCATOR_PROTOCOL_AUDIOSILENCE, LOCATOR_PROTOCOL_JAVASOUND, LOCATOR_PROTOCOL_MACCOREAUDIO, LOCATOR_PROTOCOL_OPENSLES, LOCATOR_PROTOCOL_PORTAUDIO, LOCATOR_PROTOCOL_PULSEAUDIO, LOCATOR_PROTOCOL_WASAPI, PNAME_DENOISE, PNAME_ECHOCANCEL
FEATURE_REINITIALIZE, LOCATOR_PROTOCOL_ANDROIDCAMERA, LOCATOR_PROTOCOL_CIVIL, LOCATOR_PROTOCOL_DIRECTSHOW, LOCATOR_PROTOCOL_IMGSTREAMING, LOCATOR_PROTOCOL_MEDIARECORDER, LOCATOR_PROTOCOL_QUICKTIME, LOCATOR_PROTOCOL_VIDEO4LINUX2, PROP_DEVICES
Constructor and Description |
---|
WASAPISystem()
Initializes a new WASAPISystem instance.
|
Modifier and Type | Method and Description |
---|---|
static int |
CoInitializeEx()
Invokes the Windows API function CoInitializeEx (by way of
WASAPI.CoInitializeEx(long, int) ) with arguments suitable to the
operation of WASAPIRenderer, WASAPIStream and
WASAPISystem. |
protected void |
doInitialize()
Invoked by
DeviceSystem.initialize() to perform the very logic of the
initialization of this DeviceSystem. |
protected void |
finalize() |
java.util.List<javax.media.format.AudioFormat> |
getAECSupportedFormats()
Gets the List of AudioFormats supported by the voice
capture DMO that supports/implements the acoustic echo cancellation (AEC)
feature.
|
static javax.media.format.AudioFormat[] |
getFormatsToInitializeIAudioClient(javax.media.format.AudioFormat format)
Gets an array of alternative AudioFormats based on
format with which an attempt is to be made to initialize a new
IAudioClient instance.
|
long |
getIMMDevice(java.lang.String id)
Gets an audio endpoint device that is identified by a specific endpoint
ID string.
|
int |
getIMMDeviceDataFlow(long iMMDevice)
Gets the data flow of a specific IMMDevice in the form of an
EDataFlow value.
|
int |
getIMMDeviceIndex(java.lang.String id,
int dataFlow)
Gets the zero-based index within the IMMDeviceCollection
interface of an audio endpoint device specified by an endpoint ID string.
|
protected java.lang.String |
getRendererClassName()
Gets the name of the class which implements the Renderer
interface to render media on a playback or notification device associated
with this DeviceSystem.
|
static int |
getSampleSizeInBytes(javax.media.format.AudioFormat format)
Gets the size in bytes of an audio sample of a specific
AudioFormat.
|
long |
initializeAEC()
Initializes a new IMediaObject instance which represents a Voice
Capture DSP implementing acoustic echo cancellation (AEC).
|
long |
initializeIAudioClient(javax.media.MediaLocator locator,
AudioSystem.DataFlow dataFlow,
int streamFlags,
long eventHandle,
long hnsBufferDuration,
javax.media.format.AudioFormat[] formats)
Initializes a new IAudioClient instance for an audio endpoint
device identified by a specific MediaLocator.
|
protected void |
postInitialize()
Invoked as part of the execution of
DeviceSystem.initialize() after the
execution of DeviceSystem.doInitialize() regardless of whether the latter
completed successfully. |
protected void |
preInitialize()
Invoked as part of the execution of
DeviceSystem.initialize() before the
execution of DeviceSystem.doInitialize() . |
java.lang.String |
toString()
Returns a human-readable representation of this DeviceSystem.
|
static void |
WAVEFORMATEX_fill(long waveformatex,
javax.media.format.AudioFormat audioFormat)
Sets the fields of a specific WAVEFORMATEX instance from a
specific AudioFormat instance so that the two of them are
equivalent in terms of the formats of audio data that they describe.
|
createRenderer, createRenderer, getAudioInputStream, getAudioSystem, getAudioSystems, getDevice, getDevices, getFormat, getPropertyName, getSelectedDevice, isAutomaticGainControl, isDenoise, isEchoCancel, postInitializeSpecificDevices, propertyChange, setAutomaticGainControl, setCaptureDevices, setDenoise, setDevice, setEchoCancel, setPlaybackDevices
filterDeviceListByLocatorProtocol, getDeviceSystems, getFeatures, getFormat, getLocatorProtocol, getMediaType, initialize, initializeDeviceSystems, initializeDeviceSystems, invokeDeviceSystemInitialize, invokeDeviceSystemInitialize
addPropertyChangeListener, firePropertyChange, getPropertyChangeSource, removePropertyChangeListener
public static final long DEFAULT_BUFFER_DURATION
WASAPIStream.read(Buffer)
or to be processed by
WASAPIRenderer in an invocation of
WASAPIRenderer.process(Buffer)
.public static final long DEFAULT_DEVICE_PERIOD
WASAPISystem() throws java.lang.Exception
java.lang.Exception
- if anything goes wrong while initializing the new
WASAPISystem instancepublic static int CoInitializeEx() throws HResultException
WASAPI.CoInitializeEx(long, int)
) with arguments suitable to the
operation of WASAPIRenderer, WASAPIStream and
WASAPISystem.
Generally, the WASAPI integration is designed with COINIT_MULTITHREADED in mind. However, it may turn out that it works with COINIT_APARTMENTTHREADED as well.
HResultException
- if the invocation of the method
WASAPI.CoInitializeEx throws such an exceptionpublic static javax.media.format.AudioFormat[] getFormatsToInitializeIAudioClient(javax.media.format.AudioFormat format)
format
- the AudioFormat on which the alternative
AudioFormats are to be basedpublic static int getSampleSizeInBytes(javax.media.format.AudioFormat format)
format
- the AudioFormat to get the size in bytes of an
audio sample ofpublic static void WAVEFORMATEX_fill(long waveformatex, javax.media.format.AudioFormat audioFormat)
waveformatex
- the WAVEFORMATEX instance to set the fields
of from the specified audioFormataudioFormat
- the AudioFormat instance to set the fields of
the specified waveformatex fromprotected void doInitialize() throws java.lang.Exception
DeviceSystem.initialize()
to perform the very logic of the
initialization of this DeviceSystem. This instance has been
prepared for initialization by an earlier call to
DeviceSystem.preInitialize()
and the initialization will be completed with a
subsequent call to DeviceSystem.postInitialize()
.doInitialize
in class DeviceSystem
java.lang.Exception
- if an error occurs during the initialization of this
instance. The initialization of this instance will be completed with a
subsequent call to postInitialize() regardless of any
Exception thrown by doInitialize().protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public java.util.List<javax.media.format.AudioFormat> getAECSupportedFormats()
If an AudioFormat instance contained in the returned List is one of the formats of a CaptureDeviceInfo2 or the supportedFormats of a FormatControl associated with a WASAPI CaptureDevice/DataSource or SourceStream, it signals that the AudioFormat in question has been included in that formats or supportedFormats only because it is supported by the voice capture DMO supporting/implementing the acoustic echo cancellation (AEC) feature.
public long getIMMDevice(java.lang.String id) throws HResultException
id
- the endpoint ID string which identifies the audio endpoint
device to be retrievedHResultException
- if an error occurs while retrieving the audio
endpoint device that is identified by the specified endpoint ID string in
a native WASAPI function which returns an HRESULT valuepublic int getIMMDeviceDataFlow(long iMMDevice) throws HResultException
iMMDevice
- the IMMDevice to get the data flow ofHResultException
- if an error occurs while retrieving the data
flow of the specified iMMDevice in a native WASAPI function
which returns an HRESULT valuepublic int getIMMDeviceIndex(java.lang.String id, int dataFlow) throws HResultException
id
- the endpoint ID string which specifies the audio endpoint
device whose zero-based index within the IMMDeviceCollection
interface is to be retrievedHResultException
- if an error occurs while determining the
zero-based index within the IMMDeviceCollection interface of the
audio endpoint device identified by the specified endpoint ID string in a
native WASAPI function which returns an HRESULT valueprotected java.lang.String getRendererClassName()
#createRenderer(boolean)
.getRendererClassName
in class DeviceSystem
public long initializeAEC() throws java.lang.Exception
java.lang.Exception
- if initializing the new instance failspublic long initializeIAudioClient(javax.media.MediaLocator locator, AudioSystem.DataFlow dataFlow, int streamFlags, long eventHandle, long hnsBufferDuration, javax.media.format.AudioFormat[] formats) throws HResultException
WASAPIRenderer
and WASAPIStream
.locator
- a MediaLocator which identifies the audio
endpoint device to initialize a new IAudioClient instance fordataFlow
- the flow of media data to be supported by the audio
endpoint device identified by the specified locatorstreamFlags
- eventHandle
- hnsBufferDuration
- the base of the duration in milliseconds of the
buffer that the audio application will share with the audio engine. If
Format.NOT_SPECIFIED
, the method uses the default interval
between periodic passes by the audio engine.formats
- an array of alternative AudioFormats with which
initialization of a new IAudioClient instance is to be
attempted. The first element of the formats array which is
supported by the new IAudioClient instance is used to initialize
it and any preceding elements are set to null to signify that
they are not supported and to make it possible to retrieve the
AudioFormat with which the new IAudioClient instance
has been initialized.HResultException
- if an error occurs while initializing a new
IAudioClient for the audio endpoint device identified by the
specified locator in a native WASAPI function which returns an
HRESULT valueprotected void postInitialize() throws java.lang.Exception
DeviceSystem.initialize()
after the
execution of DeviceSystem.doInitialize()
regardless of whether the latter
completed successfully. The implementation of DeviceSystem fires
a new PropertyChangeEvent to notify that the value of the
property DeviceSystem.PROP_DEVICES
of this instance may have changed i.e.
that the list of devices detected by this instance may have changed.
Because AudioSystem may support playback and notification audio
devices apart from capture audio devices, fires more specific
PropertyChangeEvents than DeviceSystempostInitialize
in class AudioSystem
java.lang.Exception
protected void preInitialize() throws java.lang.Exception
DeviceSystem.initialize()
before the
execution of DeviceSystem.doInitialize()
. The implementation of
DeviceSystem removes from FMJ's CaptureDeviceManager
the CaptureDeviceInfos whose MediaLocator has the same
protocol as DeviceSystem.getLocatorProtocol()
of this instance.
Removes any capture, playback and notification devices previously
detected by this AudioSystem and prepares it for the execution
of its DeviceSystem.doInitialize()
implementation (which detects
all devices to be provided by this instance).preInitialize
in class AudioSystem
java.lang.Exception
public java.lang.String toString()
toString
in class DeviceSystem
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.