Class Opus
- java.lang.Object
-
- org.jitsi.impl.neomedia.codec.audio.opus.Opus
-
public class Opus extends Object
Defines the API of the native opus library to be utilized by the libjitsi library.- Author:
- Boris Grozev, Lyubomir Marinov
-
-
Field Summary
Fields Modifier and Type Field Description static intBANDWIDTH_FULLBANDOpus fullband constantstatic intBANDWIDTH_MEDIUMBANDOpus mediumband constantstatic intBANDWIDTH_NARROWBANDOpus narrowband constantstatic intBANDWIDTH_SUPERWIDEBANDOpus superwideband constantstatic intBANDWIDTH_WIDEBANDOpus wideband constantstatic intINVALID_PACKETOpus constant for an invalid packetstatic intMAX_PACKETThe maximum size of a packet we can create.static intOPUS_AUTOConstant used to set various settings to "automatic"static intOPUS_OKConstant usually indicating that no error occurred
-
Constructor Summary
Constructors Constructor Description Opus()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertOpusIsFunctional()Asserts that the Opus class and the JNI library which supports it are functional.static intdecode(long decoder, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputFrameSize, int decodeFEC)Decodes an opus packet from input into output.static longdecoder_create(int Fs, int channels)Creates an OpusDecoder structure, returns a pointer to it or 0 on error.static voiddecoder_destroy(long decoder)Destroys an OpusDecoder, freeing it's resources.static intdecoder_get_nb_samples(long decoder, byte[] packet, int offset, int length)Returns the number of samples in an opus packetstatic intdecoder_get_size(int channels)Returns the size in bytes required for an OpusDecoder structure.static intencode(long encoder, byte[] input, int inputOffset, int inputFrameSize, byte[] output, int outputOffset, int outputLength)Encodes the input from input into an opus packet in output.static longencoder_create(int Fs, int channels)Creates an OpusEncoder structure, returns a pointer to it casted to long.static voidencoder_destroy(long encoder)Destroys an OpusEncoder, freeing it's resources.static intencoder_get_bandwidth(long encoder)Wrapper around the native opus_encoder_ctl function.static intencoder_get_bitrate(long encoder)Wrapper around the native opus_encoder_ctl function.static intencoder_get_complexity(long encoder)static intencoder_get_dtx(long encoder)Wrapper around the native opus_encoder_ctl function.static intencoder_get_inband_fec(long encoder)Wrapper around the native opus_encoder_ctl function.static intencoder_get_size(int channels)Returns the size in bytes required for an OpusEncoder structure.static intencoder_get_vbr(long encoder)Wrapper around the native opus_encoder_ctl function.static intencoder_get_vbr_constraint(long encoder)Wrapper around the native opus_encoder_ctl function.static intencoder_set_bandwidth(long encoder, int bandwidth)Wrapper around the native opus_encoder_ctl function.static intencoder_set_bitrate(long encoder, int bitrate)Wrapper around the native opus_encoder_ctl function.static intencoder_set_complexity(long encoder, int complexity)Wrapper around the native opus_encoder_ctl function.static intencoder_set_dtx(long encoder, int dtx)Wrapper around the native opus_encoder_ctl function.static intencoder_set_force_channels(long encoder, int forcechannels)Wrapper around the native opus_encoder_ctl function.static intencoder_set_inband_fec(long encoder, int inbandFEC)Wrapper around the native opus_encoder_ctl function.static intencoder_set_max_bandwidth(long encoder, int maxBandwidth)Wrapper around the native opus_encoder_ctl function.static intencoder_set_packet_loss_perc(long encoder, int packetLossPerc)Wrapper around the native opus_encoder_ctl function.static intencoder_set_vbr(long encoder, int vbr)Wrapper around the native opus_encoder_ctl function.static intencoder_set_vbr_constraint(long encoder, int use_cvbr)Wrapper around the native opus_encoder_ctl function.static intpacket_get_bandwidth(byte[] data, int offset)Returns the audio bandwidth of an Opus packet, one of BANDWIDTH_FULLBAND, BANDWIDTH_MEDIUMBAND, BANDWIDTH_NARROWBAND, BANDWIDTH_SUPERWIDEBAND or BANDWIDTH_WIDEBAND, or INVALID_PACKET on error.static intpacket_get_nb_channels(byte[] data, int offset)Returns the number of channels encoded in an Opus packet.static intpacket_get_nb_frames(byte[] packet, int offset, int length)Returns the number of frames in an Opus packet.
-
-
-
Field Detail
-
BANDWIDTH_FULLBAND
public static final int BANDWIDTH_FULLBAND
Opus fullband constant- See Also:
- Constant Field Values
-
BANDWIDTH_MEDIUMBAND
public static final int BANDWIDTH_MEDIUMBAND
Opus mediumband constant- See Also:
- Constant Field Values
-
BANDWIDTH_NARROWBAND
public static final int BANDWIDTH_NARROWBAND
Opus narrowband constant- See Also:
- Constant Field Values
-
BANDWIDTH_SUPERWIDEBAND
public static final int BANDWIDTH_SUPERWIDEBAND
Opus superwideband constant- See Also:
- Constant Field Values
-
BANDWIDTH_WIDEBAND
public static final int BANDWIDTH_WIDEBAND
Opus wideband constant- See Also:
- Constant Field Values
-
INVALID_PACKET
public static final int INVALID_PACKET
Opus constant for an invalid packet- See Also:
- Constant Field Values
-
MAX_PACKET
public static final int MAX_PACKET
The maximum size of a packet we can create. Since we're only creating packets with a single frame, that's a 1 byte TOC + the maximum frame size. See http://tools.ietf.org/html/rfc6716#section-3.2- See Also:
- Constant Field Values
-
OPUS_AUTO
public static final int OPUS_AUTO
Constant used to set various settings to "automatic"- See Also:
- Constant Field Values
-
OPUS_OK
public static final int OPUS_OK
Constant usually indicating that no error occurred- See Also:
- Constant Field Values
-
-
Method Detail
-
assertOpusIsFunctional
public static void assertOpusIsFunctional()
Asserts that the Opus class and the JNI library which supports it are functional. The method is to be invoked early (e.g. static/class initializers) by classes which require it (i.e. they depend on it and they cannot function without it).
-
decode
public static int decode(long decoder, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputFrameSize, int decodeFEC)Decodes an opus packet from input into output.- Parameters:
decoder- the OpusDecoder state to perform the decodinginput- an array of bytes which represents the input payload to decode. If null, indicates packet loss.inputOffset- the offset in input at which the payload to be decoded beginsinputLength- the length in bytes in input beginning at inputOffset of the payload to be decodedoutput- an array of bytes into which the decoded signal is to be outputoutputOffset- the offset in output at which the output of the decoded signal is to beginoutputFrameSize- the number of samples per channel output beginning at outputOffset of the maximum space available for output of the decoded signaldecodeFEC- 0 to decode the packet normally, 1 to decode the FEC data in the packet- Returns:
- the number of decoded samples written into output (beginning at outputOffset)
-
decoder_create
public static long decoder_create(int Fs, int channels)Creates an OpusDecoder structure, returns a pointer to it or 0 on error.- Parameters:
Fs- Sample rate to decode tochannels- number of channels to decode to(1/2)- Returns:
- A pointer to the OpusDecoder structure created, 0 on error.
-
decoder_destroy
public static void decoder_destroy(long decoder)
Destroys an OpusDecoder, freeing it's resources.- Parameters:
decoder- Address of the structure (as returned from decoder_create)
-
decoder_get_nb_samples
public static int decoder_get_nb_samples(long decoder, byte[] packet, int offset, int length)Returns the number of samples in an opus packet- Parameters:
decoder- The decoder to use.packet- Array holding the packet.offset- Offset into packet where the actual packet begins.length- Length of the packet.- Returns:
- the number of samples in packet .
-
decoder_get_size
public static int decoder_get_size(int channels)
Returns the size in bytes required for an OpusDecoder structure.- Parameters:
channels- number of channels (1/2)- Returns:
- the size in bytes required for an OpusDecoder structure.
-
encode
public static int encode(long encoder, byte[] input, int inputOffset, int inputFrameSize, byte[] output, int outputOffset, int outputLength)Encodes the input from input into an opus packet in output.- Parameters:
encoder- The encoder to use.input- Array containing PCM encoded input.inputOffset- Offset to use into the input arrayinputFrameSize- The number of samples per channel in input.output- Array where the encoded packet will be stored.outputOffset- Offset to use into the output arrayoutputLength- The number of available bytes in output.- Returns:
- The number of bytes written in output, or a negative on error.
-
encoder_create
public static long encoder_create(int Fs, int channels)Creates an OpusEncoder structure, returns a pointer to it casted to long. The native function's application parameter is always set to OPUS_APPLICATION_VOIP.- Parameters:
Fs- Sample rate of the input PCMchannels- number of channels in the input (1/2)- Returns:
- A pointer to the OpusEncoder structure created, 0 on error
-
encoder_destroy
public static void encoder_destroy(long encoder)
Destroys an OpusEncoder, freeing it's resources.- Parameters:
encoder- Address of the structure (as returned from encoder_create)
-
encoder_get_bandwidth
public static int encoder_get_bandwidth(long encoder)
Wrapper around the native opus_encoder_ctl function. Returns the current encoder audio bandwidth .- Parameters:
encoder- The encoder to use- Returns:
- the current encoder audio bandwidth
-
encoder_get_bitrate
public static int encoder_get_bitrate(long encoder)
Wrapper around the native opus_encoder_ctl function. Returns the current encoder bitrate.- Parameters:
encoder- The encoder to use- Returns:
- The current encoder bitrate.
-
encoder_get_complexity
public static int encoder_get_complexity(long encoder)
-
encoder_get_dtx
public static int encoder_get_dtx(long encoder)
Wrapper around the native opus_encoder_ctl function. Returns the current DTX setting of the encoder.- Parameters:
encoder- The encoder to use- Returns:
- the current DTX setting of the encoder.
-
encoder_get_inband_fec
public static int encoder_get_inband_fec(long encoder)
Wrapper around the native opus_encoder_ctl function. Returns the current inband FEC encoder setting.- Parameters:
encoder- The encoder to use- Returns:
- the current inband FEC encoder setting.
-
encoder_get_size
public static int encoder_get_size(int channels)
Returns the size in bytes required for an OpusEncoder structure.- Parameters:
channels- number of channels (1/2)- Returns:
- the size in bytes required for an OpusEncoder structure.
-
encoder_get_vbr
public static int encoder_get_vbr(long encoder)
Wrapper around the native opus_encoder_ctl function. Returns the current encoder VBR setting- Parameters:
encoder- The encoder to use- Returns:
- The current encoder VBR setting.
-
encoder_get_vbr_constraint
public static int encoder_get_vbr_constraint(long encoder)
Wrapper around the native opus_encoder_ctl function. Returns the current VBR constraint encoder setting.- Parameters:
encoder- The encoder to use- Returns:
- the current VBR constraint encoder setting.
-
encoder_set_bandwidth
public static int encoder_set_bandwidth(long encoder, int bandwidth)Wrapper around the native opus_encoder_ctl function. Sets the encoder audio bandwidth.- Parameters:
encoder- The encoder to usebandwidth- The bandwidth to set, should be one of BANDWIDTH_FULLBAND, BANDWIDTH_MEDIUMBAND, BANDWIDTH_NARROWBAND, BANDWIDTH_SUPERWIDEBAND or BANDWIDTH_WIDEBAND.- Returns:
- OPUS_OK on success
-
encoder_set_bitrate
public static int encoder_set_bitrate(long encoder, int bitrate)Wrapper around the native opus_encoder_ctl function. Sets the encoder bitrate- Parameters:
encoder- The encoder to usebitrate- The bitrate to set- Returns:
- OPUS_OK on success
-
encoder_set_complexity
public static int encoder_set_complexity(long encoder, int complexity)Wrapper around the native opus_encoder_ctl function. Sets the encoder complexity setting.- Parameters:
encoder- The encoder to usecomplexity- The complexity level, from 1 to 10- Returns:
- OPUS_OK on success
-
encoder_set_dtx
public static int encoder_set_dtx(long encoder, int dtx)Wrapper around the native opus_encoder_ctl function. Sets the DTX setting of the encoder.- Parameters:
encoder- The encoder to usedtx- 0 to turn DTX off, non-zero to turn it on- Returns:
- OPUS_OK on success
-
encoder_set_force_channels
public static int encoder_set_force_channels(long encoder, int forcechannels)Wrapper around the native opus_encoder_ctl function. Sets the force channels setting of the encoder.- Parameters:
encoder- The encoder to useforcechannels- Number of channels- Returns:
- OPUS_OK on success
-
encoder_set_inband_fec
public static int encoder_set_inband_fec(long encoder, int inbandFEC)Wrapper around the native opus_encoder_ctl function. Sets the encoder FEC setting.- Parameters:
encoder- The encoder to useinbandFEC- 0 to turn FEC off, non-zero to turn it on.- Returns:
- OPUS_OK on success
-
encoder_set_max_bandwidth
public static int encoder_set_max_bandwidth(long encoder, int maxBandwidth)Wrapper around the native opus_encoder_ctl function. Sets the maximum audio bandwidth to be used by the encoder.- Parameters:
encoder- The encoder to usemaxBandwidth- The maximum bandwidth to use, should be one of BANDWIDTH_FULLBAND, BANDWIDTH_MEDIUMBAND, BANDWIDTH_NARROWBAND, BANDWIDTH_SUPERWIDEBAND or BANDWIDTH_WIDEBAND- Returns:
- OPUS_OK on success.
-
encoder_set_packet_loss_perc
public static int encoder_set_packet_loss_perc(long encoder, int packetLossPerc)Wrapper around the native opus_encoder_ctl function. Sets the encoder's expected packet loss percentage.- Parameters:
encoder- The encoder to use- Returns:
- OPUS_OK on success.
-
encoder_set_vbr
public static int encoder_set_vbr(long encoder, int vbr)Wrapper around the native opus_encoder_ctl function. Sets the encoder VBR setting- Parameters:
encoder- The encoder to usevbr- 0 to turn VBR off, non-zero to turn it on.- Returns:
- OPUS_OK on success
-
encoder_set_vbr_constraint
public static int encoder_set_vbr_constraint(long encoder, int use_cvbr)Wrapper around the native opus_encoder_ctl function. Sets the encoder VBR constraint setting- Parameters:
encoder- The encoder to useuse_cvbr- 0 to turn VBR constraint off, non-zero to turn it on.- Returns:
- OPUS_OK on success
-
packet_get_bandwidth
public static int packet_get_bandwidth(byte[] data, int offset)Returns the audio bandwidth of an Opus packet, one of BANDWIDTH_FULLBAND, BANDWIDTH_MEDIUMBAND, BANDWIDTH_NARROWBAND, BANDWIDTH_SUPERWIDEBAND or BANDWIDTH_WIDEBAND, or INVALID_PACKET on error.- Parameters:
data- Array holding the packet.offset- Offset into packet where the actual packet begins.- Returns:
- one of BANDWIDTH_FULLBAND, BANDWIDTH_MEDIUMBAND, BANDWIDTH_NARROWBAND, BANDWIDTH_SUPERWIDEBAND, BANDWIDTH_WIDEBAND, or INVALID_PACKET on error.
-
packet_get_nb_channels
public static int packet_get_nb_channels(byte[] data, int offset)Returns the number of channels encoded in an Opus packet.- Parameters:
data- Array holding the packet.offset- Offset into packet where the actual packet begins.- Returns:
- the number of channels encoded in data.
-
packet_get_nb_frames
public static int packet_get_nb_frames(byte[] packet, int offset, int length)Returns the number of frames in an Opus packet.- Parameters:
packet- Array holding the packet.offset- Offset into packet where the actual packet begins.length- Length of the packet.- Returns:
- the number of frames in packet.
-
-