diff options
author | Andrew Comminos <andrewcomminos@gmail.com> | 2014-07-08 11:21:14 +0400 |
---|---|---|
committer | Andrew Comminos <andrewcomminos@gmail.com> | 2014-07-08 11:21:14 +0400 |
commit | b19f5043eb6dc2725f1899daec907fce09569b24 (patch) | |
tree | 60b85e6a194ced2d81c8704ff06508ce8617af61 | |
parent | bc35443a9cfb680a45290219cd874f7fa9a5b777 (diff) |
Tighten assertions and minor reformat.
5 files changed, 105 insertions, 105 deletions
diff --git a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java index 284ec44..103f09e 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java @@ -31,7 +31,6 @@ import com.morlunk.jumble.exception.NativeAudioException; */ @Platform(library="celt11", cinclude={"<celt.h>","<celt_types.h>"}) public class CELT11 { - public static final int CELT_GET_BITSTREAM_VERSION = 2000; public static final int CELT_SET_BITRATE_REQUEST = 6; public static final int CELT_SET_PREDICTION_REQUEST = 4; @@ -40,6 +39,22 @@ public class CELT11 { Loader.load(); } + public static native @NoDeallocator Pointer celt_mode_create(int sampleRate, int frameSize, IntPointer error); + public static native int celt_mode_info(@Cast("const CELTMode*") Pointer mode, int request, IntPointer value); + public static native void celt_mode_destroy(@Cast("CELTMode*") Pointer mode); + + public static native @NoDeallocator Pointer celt_decoder_create(int sampleRate, int channels, IntPointer error); + public static native int celt_decode(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, short[] pcm, int frameSize); + public static native int celt_decode_float(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, float[] pcm, int frameSize); + public static native int celt_decoder_ctl(@Cast("CELTDecoder*") Pointer st, int request, Pointer val); + public static native void celt_decoder_destroy(@Cast("CELTDecoder*") Pointer st); + + public static native @NoDeallocator Pointer celt_encoder_create(int sampleRate, int channels, IntPointer error); + public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, Pointer val); + public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, int val); + public static native int celt_encode(@Cast("CELTEncoder*") Pointer state, @Cast("const short*") short[] pcm, int frameSize, @Cast("unsigned char*") byte[] compressed, int maxCompressedBytes); + public static native void celt_encoder_destroy(@Cast("CELTEncoder*") Pointer state); + public static class CELT11Encoder implements IEncoder { private Pointer mState; @@ -101,20 +116,4 @@ public class CELT11 { celt_decoder_destroy(mState); } } - - public static native @NoDeallocator Pointer celt_mode_create(int sampleRate, int frameSize, IntPointer error); - public static native int celt_mode_info(@Cast("const CELTMode*") Pointer mode, int request, IntPointer value); - public static native void celt_mode_destroy(@Cast("CELTMode*") Pointer mode); - - public static native @NoDeallocator Pointer celt_decoder_create(int sampleRate, int channels, IntPointer error); - public static native int celt_decode(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, short[] pcm, int frameSize); - public static native int celt_decode_float(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, float[] pcm, int frameSize); - public static native int celt_decoder_ctl(@Cast("CELTDecoder*") Pointer st, int request, Pointer val); - public static native void celt_decoder_destroy(@Cast("CELTDecoder*") Pointer st); - - public static native @NoDeallocator Pointer celt_encoder_create(int sampleRate, int channels, IntPointer error); - public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, Pointer val); - public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, int val); - public static native int celt_encode(@Cast("CELTEncoder*") Pointer state, @Cast("const short*") short[] pcm, int frameSize, @Cast("unsigned char*") byte[] compressed, int maxCompressedBytes); - public static native void celt_encoder_destroy(@Cast("CELTEncoder*") Pointer state); }
\ No newline at end of file diff --git a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java index 81df8ec..da5e8ca 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java @@ -31,13 +31,28 @@ import com.morlunk.jumble.exception.NativeAudioException; */ @Platform(library="celt7", cinclude={"<celt.h>","<celt_types.h>"}) public class CELT7 { - public static final int CELT_GET_BITSTREAM_VERSION = 2000; static { Loader.load(); } + public static native @NoDeallocator Pointer celt_mode_create(int sampleRate, int frameSize, IntPointer error); + public static native int celt_mode_info(@Cast("const CELTMode*") Pointer mode, int request, IntPointer value); + public static native void celt_mode_destroy(@Cast("CELTMode*") Pointer mode); + + public static native @NoDeallocator Pointer celt_decoder_create(@Cast("CELTMode*") Pointer mode, int channels, IntPointer error); + public static native int celt_decode(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, short[] pcm); + public static native int celt_decode_float(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, float[] pcm); + public static native int celt_decoder_ctl(@Cast("CELTDecoder*") Pointer st, int request, Pointer val); + public static native void celt_decoder_destroy(@Cast("CELTDecoder*") Pointer st); + + public static native @NoDeallocator Pointer celt_encoder_create(@Cast("const CELTMode *") Pointer mode, int channels, IntPointer error); + public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, Pointer val); + public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, int val); + public static native int celt_encode(@Cast("CELTEncoder *") Pointer state, @Cast("const short *") short[] pcm, @Cast("short *") short[] optionalSynthesis, @Cast("unsigned char *") byte[] compressed, int nbCompressedBytes); + public static native void celt_encoder_destroy(@Cast("CELTEncoder *") Pointer state); + public static class CELT7Encoder implements IEncoder { private Pointer mMode; @@ -104,20 +119,4 @@ public class CELT7 { celt_mode_destroy(mMode); } } - - public static native @NoDeallocator Pointer celt_mode_create(int sampleRate, int frameSize, IntPointer error); - public static native int celt_mode_info(@Cast("const CELTMode*") Pointer mode, int request, IntPointer value); - public static native void celt_mode_destroy(@Cast("CELTMode*") Pointer mode); - - public static native @NoDeallocator Pointer celt_decoder_create(@Cast("CELTMode*") Pointer mode, int channels, IntPointer error); - public static native int celt_decode(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, short[] pcm); - public static native int celt_decode_float(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, float[] pcm); - public static native int celt_decoder_ctl(@Cast("CELTDecoder*") Pointer st, int request, Pointer val); - public static native void celt_decoder_destroy(@Cast("CELTDecoder*") Pointer st); - - public static native @NoDeallocator Pointer celt_encoder_create(@Cast("const CELTMode *") Pointer mode, int channels, IntPointer error); - public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, Pointer val); - public static native int celt_encoder_ctl(@Cast("CELTEncoder*")Pointer state, int request, int val); - public static native int celt_encode(@Cast("CELTEncoder *") Pointer state, @Cast("const short *") short[] pcm, @Cast("short *") short[] optionalSynthesis, @Cast("unsigned char *") byte[] compressed, int nbCompressedBytes); - public static native void celt_encoder_destroy(@Cast("CELTEncoder *") Pointer state); } diff --git a/src/main/java/com/morlunk/jumble/audio/javacpp/Opus.java b/src/main/java/com/morlunk/jumble/audio/javacpp/Opus.java index ce6424e..57d0f22 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/Opus.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/Opus.java @@ -33,13 +33,36 @@ import com.morlunk.jumble.exception.NativeAudioException; @Platform(library= "opus", link= "opus", cinclude={"<opus.h>","<opus_types.h>"}) public class Opus { - public static final int OPUS_APPLICATION_VOIP = 2048; public static final int OPUS_SET_BITRATE_REQUEST = 4002; public static final int OPUS_GET_BITRATE_REQUEST = 4003; public static final int OPUS_SET_VBR_REQUEST = 4006; + public static native int opus_decoder_get_size(int channels); + public static native @NoDeallocator Pointer opus_decoder_create(int fs, int channels, IntPointer error); + public static native int opus_decoder_init(@Cast("OpusDecoder*") Pointer st, int fs, int channels); + public static native int opus_decode(@Cast("OpusDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, short[] out, int frameSize, int decodeFec); + public static native int opus_decode_float(@Cast("OpusDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, float[] out, int frameSize, int decodeFec); + //public static native int opus_decoder_ctl(@Cast("OpusDecoder*") Pointer st, int request); + public static native void opus_decoder_destroy(@Cast("OpusDecoder*") Pointer st); + //public static native int opus_packet_parse(@Cast("const unsigned char*") BytePointer data, int len, ... + public static native int opus_packet_get_bandwidth(@Cast("const unsigned char*") BytePointer data); + public static native int opus_packet_get_samples_per_frame(@Cast("const unsigned char*") BytePointer data, int fs); + public static native int opus_packet_get_nb_channels(@Cast("const unsigned char*") BytePointer data); + public static native int opus_packet_get_nb_frames(@Cast("const unsigned char*") BytePointer packet, int len); + public static native int opus_packet_get_nb_samples(@Cast("const unsigned char*") BytePointer packet, int len, int fs); + + + public static native int opus_encoder_get_size(int channels); + public static native @NoDeallocator Pointer opus_encoder_create(int fs, int channels, int application, IntPointer error); + public static native int opus_encoder_init(@Cast("OpusEncoder*") Pointer st, int fs, int channels, int application); + public static native int opus_encode(@Cast("OpusEncoder*") Pointer st, @Cast("const short*") short[] pcm, int frameSize, @Cast("unsigned char*") byte[] data, int maxDataBytes); + public static native int opus_encode_float(@Cast("OpusEncoder*") Pointer st, @Cast("const float*") float[] pcm, int frameSize, @Cast("unsigned char*") byte[] data, int maxDataBytes); + public static native void opus_encoder_destroy(@Cast("OpusEncoder*") Pointer st); + public static native int opus_encoder_ctl(@Cast("OpusEncoder*") Pointer st, int request, Pointer value); + public static native int opus_encoder_ctl(@Cast("OpusEncoder*") Pointer st, int request, @Cast("opus_int32") int value); + static { Loader.load(); } @@ -109,28 +132,4 @@ public class Opus { opus_decoder_destroy(mState); } } - - public static native int opus_decoder_get_size(int channels); - public static native @NoDeallocator Pointer opus_decoder_create(int fs, int channels, IntPointer error); - public static native int opus_decoder_init(@Cast("OpusDecoder*") Pointer st, int fs, int channels); - public static native int opus_decode(@Cast("OpusDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, short[] out, int frameSize, int decodeFec); - public static native int opus_decode_float(@Cast("OpusDecoder*") Pointer st, @Cast("const unsigned char*") byte[] data, int len, float[] out, int frameSize, int decodeFec); - //public static native int opus_decoder_ctl(@Cast("OpusDecoder*") Pointer st, int request); - public static native void opus_decoder_destroy(@Cast("OpusDecoder*") Pointer st); - //public static native int opus_packet_parse(@Cast("const unsigned char*") BytePointer data, int len, ... - public static native int opus_packet_get_bandwidth(@Cast("const unsigned char*") BytePointer data); - public static native int opus_packet_get_samples_per_frame(@Cast("const unsigned char*") BytePointer data, int fs); - public static native int opus_packet_get_nb_channels(@Cast("const unsigned char*") BytePointer data); - public static native int opus_packet_get_nb_frames(@Cast("const unsigned char*") BytePointer packet, int len); - public static native int opus_packet_get_nb_samples(@Cast("const unsigned char*") BytePointer packet, int len, int fs); - - - public static native int opus_encoder_get_size(int channels); - public static native @NoDeallocator Pointer opus_encoder_create(int fs, int channels, int application, IntPointer error); - public static native int opus_encoder_init(@Cast("OpusEncoder*") Pointer st, int fs, int channels, int application); - public static native int opus_encode(@Cast("OpusEncoder*") Pointer st, @Cast("const short*") short[] pcm, int frameSize, @Cast("unsigned char*") byte[] data, int maxDataBytes); - public static native int opus_encode_float(@Cast("OpusEncoder*") Pointer st, @Cast("const float*") float[] pcm, int frameSize, @Cast("unsigned char*") byte[] data, int maxDataBytes); - public static native void opus_encoder_destroy(@Cast("OpusEncoder*") Pointer st); - public static native int opus_encoder_ctl(@Cast("OpusEncoder*") Pointer st, int request, Pointer value); - public static native int opus_encoder_ctl(@Cast("OpusEncoder*") Pointer st, int request, @Cast("opus_int32") int value); } diff --git a/src/main/java/com/morlunk/jumble/audio/javacpp/Speex.java b/src/main/java/com/morlunk/jumble/audio/javacpp/Speex.java index 7a2e60c..a5c7a3a 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/Speex.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/Speex.java @@ -221,6 +221,49 @@ public class Speex { Loader.load(); } + // Resampler + private static native Pointer speex_resampler_init(int channels, int inSampleRate, int outSampleRate, int quality, IntPointer error); + private static native int speex_resampler_process_int(@Cast("SpeexResamplerState*") Pointer state, int channelIndex, @Cast("short*") short[] in, @Cast("unsigned int*") int[] inLen, @Cast("short*") short[] out, @Cast("unsigned int*") int[] outLen); + private static native void speex_resampler_destroy(@Cast("SpeexResamplerState*") Pointer state); + + // Jitter buffer + private static native Pointer jitter_buffer_init(int tick); + private static native void jitter_buffer_reset(@Cast("JitterBuffer*") Pointer jitterBuffer); + private static native void jitter_buffer_destroy(@Cast("JitterBuffer*") Pointer jitterBuffer); + private static native void jitter_buffer_put(@Cast("JitterBuffer*") Pointer jitterBuffer, JitterBufferPacket packet); + private static native int jitter_buffer_get(@Cast("JitterBuffer*") Pointer jitterBuffer, JitterBufferPacket packet, int frameSize, IntPointer startOffset); + private static native int jitter_buffer_get_pointer_timestamp(@Cast("JitterBuffer*") Pointer jitterBuffer); + private static native void jitter_buffer_tick(@Cast("JitterBuffer*") Pointer jitterBuffer); + private static native int jitter_buffer_ctl(@Cast("JitterBuffer*") Pointer jitterBuffer, int request, @Cast("void *") Pointer pointer); + private static native int jitter_buffer_update_delay(@Cast("JitterBuffer*") Pointer jitterBuffer, JitterBufferPacket packet, IntPointer startOffset); + + // Preprocessor + private static native Pointer speex_preprocess_state_init(int frameSize, int samplingRate); + private static native void speex_preprocess_state_destroy(@Cast("SpeexPreprocessState*") Pointer state); + private static native int speex_preprocess_run(@Cast("SpeexPreprocessState*") Pointer state, short x[]); + private static native int speex_preprocess(@Cast("SpeexPreprocessState*") Pointer state, short[] x, int[] echo); + private static native void speex_preprocess_estimate_update(@Cast("SpeexPreprocessState*") Pointer state, short[] x); + private static native int speex_preprocess_ctl(@Cast("SpeexPreprocessState*") Pointer state, int request, Pointer ptr); + + // Bits + private static native void speex_bits_init(@Cast("SpeexBits*") SpeexBits bits); + private static native void speex_bits_read_from(@Cast("SpeexBits*") SpeexBits bits, @Cast("const char*") byte[] data, int size); + private static native void speex_bits_destroy(@Cast("SpeexBits*") SpeexBits bits); + + // Modes + public static native @Cast("const void*") Pointer speex_lib_get_mode(int mode); + + // Decoder + public static native Pointer speex_decoder_init(@Cast("const SpeexMode*") Pointer mode); + public static native void speex_decoder_ctl(Pointer state, int request, Pointer value); + public static native int speex_decode(Pointer state, @Cast("SpeexBits*") SpeexBits bits, float[] out); + public static native void speex_decoder_destroy(Pointer state); + + // Encoder + public static native Pointer speex_encoder_init(@Cast("const SpeexMode*") Pointer mode); + public static native void speex_encoder_ctl(Pointer state, int request, Pointer value); + public static native void speex_encoder_destroy(Pointer state); + @Name("_JitterBufferPacket") public static class JitterBufferPacket extends Pointer { @@ -449,48 +492,4 @@ public class Speex { speex_bits_destroy(mBits); } } - - // Resampler - private static native Pointer speex_resampler_init(int channels, int inSampleRate, int outSampleRate, int quality, IntPointer error); - private static native int speex_resampler_process_int(@Cast("SpeexResamplerState*") Pointer state, int channelIndex, @Cast("short*") short[] in, @Cast("unsigned int*") int[] inLen, @Cast("short*") short[] out, @Cast("unsigned int*") int[] outLen); - private static native void speex_resampler_destroy(@Cast("SpeexResamplerState*") Pointer state); - - // Jitter buffer - private static native Pointer jitter_buffer_init(int tick); - private static native void jitter_buffer_reset(@Cast("JitterBuffer*") Pointer jitterBuffer); - private static native void jitter_buffer_destroy(@Cast("JitterBuffer*") Pointer jitterBuffer); - private static native void jitter_buffer_put(@Cast("JitterBuffer*") Pointer jitterBuffer, JitterBufferPacket packet); - private static native int jitter_buffer_get(@Cast("JitterBuffer*") Pointer jitterBuffer, JitterBufferPacket packet, int frameSize, IntPointer startOffset); - private static native int jitter_buffer_get_pointer_timestamp(@Cast("JitterBuffer*") Pointer jitterBuffer); - private static native void jitter_buffer_tick(@Cast("JitterBuffer*") Pointer jitterBuffer); - private static native int jitter_buffer_ctl(@Cast("JitterBuffer*") Pointer jitterBuffer, int request, @Cast("void *") Pointer pointer); - private static native int jitter_buffer_update_delay(@Cast("JitterBuffer*") Pointer jitterBuffer, JitterBufferPacket packet, IntPointer startOffset); - - // Preprocessor - private static native Pointer speex_preprocess_state_init(int frameSize, int samplingRate); - private static native void speex_preprocess_state_destroy(@Cast("SpeexPreprocessState*") Pointer state); - private static native int speex_preprocess_run(@Cast("SpeexPreprocessState*") Pointer state, short x[]); - private static native int speex_preprocess(@Cast("SpeexPreprocessState*") Pointer state, short[] x, int[] echo); - private static native void speex_preprocess_estimate_update(@Cast("SpeexPreprocessState*") Pointer state, short[] x); - private static native int speex_preprocess_ctl(@Cast("SpeexPreprocessState*") Pointer state, int request, Pointer ptr); - - // Bits - private static native void speex_bits_init(@Cast("SpeexBits*") SpeexBits bits); - private static native void speex_bits_read_from(@Cast("SpeexBits*") SpeexBits bits, @Cast("const char*") byte[] data, int size); - private static native void speex_bits_destroy(@Cast("SpeexBits*") SpeexBits bits); - - // Modes - public static native @Cast("const void*") Pointer speex_lib_get_mode(int mode); - - // Decoder - public static native Pointer speex_decoder_init(@Cast("const SpeexMode*") Pointer mode); - public static native void speex_decoder_ctl(Pointer state, int request, Pointer value); - public static native int speex_decode(Pointer state, @Cast("SpeexBits*") SpeexBits bits, float[] out); - public static native void speex_decoder_destroy(Pointer state); - - // Encoder - public static native Pointer speex_encoder_init(@Cast("const SpeexMode*") Pointer mode); - public static native void speex_encoder_ctl(Pointer state, int request, Pointer value); - public static native void speex_encoder_destroy(Pointer state); - } diff --git a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java index 1997e97..a1b817c 100644 --- a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java +++ b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java @@ -477,8 +477,12 @@ public class JumbleConnection implements JumbleTCP.TCPConnectionListener, Jumble * @param force Whether to avoid tunneling this data over TCP. */ public void sendUDPMessage(final byte[] data, final int length, final boolean force) { - if(!mConnected) return; - if(mServerVersion == 0x10202) applyLegacyCodecWorkaround(data); + if (!mConnected) return; + if (length > data.length) { + throw new IllegalArgumentException("Requested length " + length + " is longer than " + + "available data length " + data.length + "!"); + } + if (mServerVersion == 0x10202) applyLegacyCodecWorkaround(data); if (!force && (mForceTCP || !mUsingUDP)) mTCP.sendMessage(data, length, JumbleTCPMessageType.UDPTunnel); else if (!mForceTCP) |