diff options
author | Andrew Comminos <andrewcomminos@gmail.com> | 2013-11-25 05:10:52 +0400 |
---|---|---|
committer | Andrew Comminos <andrewcomminos@gmail.com> | 2013-11-25 05:10:52 +0400 |
commit | dcf3fed8885d04109dddb816794864356507607b (patch) | |
tree | 2051de7d9e304ac523c9960ad7f74c5b65d18423 /src | |
parent | fde2187b916986e36322e1843fde82e9df56d4c6 (diff) |
Almost full support for all Mumble codecs. Few changes to messaging.
Diffstat (limited to 'src')
28 files changed, 523 insertions, 310 deletions
diff --git a/src/main/aidl/com/morlunk/jumble/IJumbleObserver.aidl b/src/main/aidl/com/morlunk/jumble/IJumbleObserver.aidl index 874e782..279f01f 100644 --- a/src/main/aidl/com/morlunk/jumble/IJumbleObserver.aidl +++ b/src/main/aidl/com/morlunk/jumble/IJumbleObserver.aidl @@ -41,5 +41,5 @@ interface IJumbleObserver { // Logging & Messaging void onLogInfo(String message); void onLogWarning(String message); - void onMessageReceived(String message); + void onMessageReceived(out User user, String message); } diff --git a/src/main/java/com/morlunk/jumble/Constants.java b/src/main/java/com/morlunk/jumble/Constants.java index b2190ab..7a984e1 100644 --- a/src/main/java/com/morlunk/jumble/Constants.java +++ b/src/main/java/com/morlunk/jumble/Constants.java @@ -55,7 +55,7 @@ public class Constants { public static final int TRANSMIT_CONTINUOUS = 2; public static final int PROTOCOL_VERSION = (PROTOCOL_MAJOR << 16) | (PROTOCOL_MINOR << 8) | PROTOCOL_PATCH; - public static final String PROTOCOL_STRING = PROTOCOL_MAJOR+"."+PROTOCOL_MINOR+"."+PROTOCOL_PATCH; + public static final String PROTOCOL_STRING = PROTOCOL_MAJOR+ "" +PROTOCOL_MINOR+"."+PROTOCOL_PATCH; public static final int DEFAULT_PORT = 64738; public static final String TAG = "Jumble"; diff --git a/src/main/java/com/morlunk/jumble/JumbleService.java b/src/main/java/com/morlunk/jumble/JumbleService.java index 16e867b..03d2348 100644 --- a/src/main/java/com/morlunk/jumble/JumbleService.java +++ b/src/main/java/com/morlunk/jumble/JumbleService.java @@ -18,7 +18,9 @@ package com.morlunk.jumble; import android.app.Service; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; import android.os.IBinder; import android.os.RemoteCallbackList; import android.os.RemoteException; @@ -30,18 +32,18 @@ import com.morlunk.jumble.db.Database; import com.morlunk.jumble.model.Channel; import com.morlunk.jumble.model.Server; import com.morlunk.jumble.model.User; -import com.morlunk.jumble.net.ChannelHandler; +import com.morlunk.jumble.protocol.ChannelHandler; import com.morlunk.jumble.net.JumbleConnection; import com.morlunk.jumble.net.JumbleConnectionException; import com.morlunk.jumble.net.JumbleTCPMessageType; import com.morlunk.jumble.net.JumbleUDPMessageType; -import com.morlunk.jumble.net.TextMessageHandler; -import com.morlunk.jumble.net.UserHandler; +import com.morlunk.jumble.protocol.JumbleMessageListener; +import com.morlunk.jumble.protocol.TextMessageHandler; +import com.morlunk.jumble.protocol.UserHandler; import com.morlunk.jumble.protobuf.Mumble; import com.morlunk.jumble.util.MessageFormatter; import java.security.Security; -import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -75,7 +77,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon public boolean mAutoReconnect; public byte[] mCertificate; public String mCertificatePassword; - public int mDetectionThreshold; + public float mDetectionThreshold; public int mTransmitMode; public boolean mUseOpus; public boolean mForceTcp; @@ -93,7 +95,28 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon private AudioInput.AudioInputListener mAudioInputListener = new AudioInput.AudioInputListener() { @Override public void onFrameEncoded(byte[] data, int length, JumbleUDPMessageType messageType) { - mConnection.sendUDPMessage(data, length, false); + if(isConnected()) + mConnection.sendUDPMessage(data, length, false); + } + + @Override + public void onTalkStateChanged(final boolean talking) { + if(!isConnected()) + return; + + new Handler(getMainLooper()).post(new Runnable() { + @Override + public void run() { + final User currentUser = getUserHandler().getUser(getSession()); + currentUser.setTalkState(talking ? User.TalkState.TALKING : User.TalkState.PASSIVE); + notifyObservers(new ObserverRunnable() { + @Override + public void run(IJumbleObserver observer) throws RemoteException { + observer.onUserTalkStateUpdated(currentUser); + } + }); + } + }); } }; @@ -198,15 +221,6 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon mAudioInput.startRecording(); else mAudioInput.stopRecording(); - - final User currentUser = getSessionUser(); - currentUser.setTalkState(talking ? User.TalkState.TALKING : User.TalkState.PASSIVE); - notifyObservers(new ObserverRunnable() { - @Override - public void run(IJumbleObserver observer) throws RemoteException { - observer.onUserTalkStateUpdated(currentUser); - } - }); } @Override @@ -299,7 +313,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon // Log message to chat User target = getUser(session); String formattedMessage = getString(R.string.chat_message_to, MessageFormatter.highlightString(target.getName()), message); - logMessage(formattedMessage); + logMessage(getSessionUser(), formattedMessage); } @Override @@ -315,7 +329,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon // Log message to chat Channel target = getChannel(channel); String formattedMessage = getString(R.string.chat_message_to, MessageFormatter.highlightString(target.getName()), message); - logMessage(formattedMessage); + logMessage(getSessionUser(), formattedMessage); } @Override @@ -382,7 +396,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon mAutoReconnect = extras.getBoolean(EXTRAS_AUTO_RECONNECT, true); mCertificate = extras.getByteArray(EXTRAS_CERTIFICATE); mCertificatePassword = extras.getString(EXTRAS_CERTIFICATE_PASSWORD); - mDetectionThreshold = extras.getInt(EXTRAS_DETECTION_THRESHOLD, 1400); + mDetectionThreshold = extras.getFloat(EXTRAS_DETECTION_THRESHOLD, 0.5f); mTransmitMode = extras.getInt(EXTRAS_TRANSMIT_MODE, Constants.TRANSMIT_VOICE_ACTIVITY); mUseOpus = extras.getBoolean(EXTRAS_USE_OPUS, true); mUseTor = extras.getBoolean(EXTRAS_USE_TOR, false); @@ -437,24 +451,13 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon mUserHandler = new UserHandler(this); mTextMessageHandler = new TextMessageHandler(this); mAudioOutput = new AudioOutput(this); - mAudioInput = new AudioInput(JumbleUDPMessageType.UDPVoiceOpus, mTransmitMode, mAudioInputListener); - - // Add message handlers for all managers - mConnection.addMessageHandler(mChannelHandler); - mConnection.addMessageHandler(mUserHandler); - mConnection.addMessageHandler(mTextMessageHandler); - mConnection.addMessageHandler(mAudioOutput); - mConnection.addMessageHandler(mAudioInput); + mAudioInput = new AudioInput(this, JumbleUDPMessageType.UDPVoiceOpus, mTransmitMode, mDetectionThreshold, mAudioInputListener); + mConnection.addMessageHandlers(mChannelHandler, mUserHandler, mTextMessageHandler, mAudioOutput, mAudioInput); mConnection.connect(); } public void disconnect() { - mConnection.removeMessageHandler(mChannelHandler); - mConnection.removeMessageHandler(mUserHandler); - mConnection.removeMessageHandler(mTextMessageHandler); - mConnection.removeMessageHandler(mAudioOutput); - mConnection.removeMessageHandler(mAudioInput); mConnection.disconnect(); mConnection = null; } @@ -468,6 +471,8 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon Log.v(Constants.TAG, "Connected"); mAudioOutput.startPlaying(); + if(mTransmitMode == Constants.TRANSMIT_CONTINUOUS || mTransmitMode == Constants.TRANSMIT_VOICE_ACTIVITY) + mAudioInput.startRecording(); if(mServer.getId() != -1) { // Send access tokens @@ -489,6 +494,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon Log.v(Constants.TAG, "Disconnected"); mAudioOutput.stopPlaying(); + mAudioInput.stopRecording(); notifyObservers(new ObserverRunnable() { @Override @@ -580,15 +586,16 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon /** * Logs a text message to the client. + * @param user The user that sent the message. * @param message An HTML message to send to the client. */ - public void logMessage(final String message) { + public void logMessage(final User user, final String message) { final String formatMessage = mChatDateFormat.format(new Date())+message; mLogHistory.add(formatMessage); notifyObservers(new ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { - observer.onMessageReceived(formatMessage); + observer.onMessageReceived(user, formatMessage); } }); } diff --git a/src/main/java/com/morlunk/jumble/audio/Audio.java b/src/main/java/com/morlunk/jumble/audio/Audio.java index 81155d9..f9dcbf5 100644 --- a/src/main/java/com/morlunk/jumble/audio/Audio.java +++ b/src/main/java/com/morlunk/jumble/audio/Audio.java @@ -16,8 +16,6 @@ package com.morlunk.jumble.audio; -import com.morlunk.jumble.net.JumbleMessageHandler; - /** * Created by andrew on 16/07/13. */ diff --git a/src/main/java/com/morlunk/jumble/audio/AudioInput.java b/src/main/java/com/morlunk/jumble/audio/AudioInput.java index d9aaebb..596eb72 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioInput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioInput.java @@ -18,7 +18,6 @@ package com.morlunk.jumble.audio; import android.media.AudioFormat; import android.media.AudioRecord; -import android.media.AudioTrack; import android.media.MediaRecorder; import android.util.Log; @@ -26,41 +25,55 @@ import com.googlecode.javacpp.IntPointer; import com.googlecode.javacpp.Loader; import com.googlecode.javacpp.Pointer; import com.morlunk.jumble.Constants; +import com.morlunk.jumble.JumbleService; +import com.morlunk.jumble.audio.javacpp.CELT11; +import com.morlunk.jumble.audio.javacpp.CELT7; import com.morlunk.jumble.audio.javacpp.Opus; import com.morlunk.jumble.audio.javacpp.Speex; -import com.morlunk.jumble.net.JumbleMessageHandler; +import com.morlunk.jumble.protocol.JumbleMessageListener; import com.morlunk.jumble.net.JumbleUDPMessageType; import com.morlunk.jumble.net.PacketDataStream; import com.morlunk.jumble.protobuf.Mumble; +import com.morlunk.jumble.protocol.ProtocolHandler; import java.util.Arrays; /** * Created by andrew on 23/08/13. */ -public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { +public class AudioInput extends ProtocolHandler implements Runnable { static { Loader.load(Opus.class); // Do this so we can reference IntPointer and the like earlier. } public interface AudioInputListener { + /** + * Called when a frame has finished processing, and is ready to go to the server. + * @param data The encoded audio data. + * @param length The length of the encoded audio data. + * @param messageType The codec of the encoded data. + */ public void onFrameEncoded(byte[] data, int length, JumbleUDPMessageType messageType); + + public void onTalkStateChanged(boolean talking); } - public static final int[] SAMPLE_RATES = { 48000, 44100, 22050, 160000, 11025, 8000 }; - public static final int SPEEX_RESAMPLE_QUALITY = 3; - public static final int OPUS_MAX_BYTES = 512; // Opus specifies 4000 bytes as a recommended value for encoding, but the official mumble project uses 512. + private static final int[] SAMPLE_RATES = { 48000, 44100, 22050, 160000, 11025, 8000 }; + private static final int SPEEX_RESAMPLE_QUALITY = 3; + private static final int OPUS_MAX_BYTES = 512; // Opus specifies 4000 bytes as a recommended value for encoding, but the official mumble project uses 512. - private Pointer mOpusEncoder;; -// private com.morlunk.jumble.audio.celt11.SWIGTYPE_p_CELTEncoder mCELTBetaEncoder; -// private com.morlunk.jumble.audio.celt7.SWIGTYPE_p_CELTMode mCELTAlphaMode; -// private com.morlunk.jumble.audio.celt7.SWIGTYPE_p_CELTEncoder mCELTAlphaEncoder; + private Pointer mOpusEncoder; + private Pointer mCELTBetaEncoder; + private Pointer mCELTAlphaMode; + private Pointer mCELTAlphaEncoder; private Speex.SpeexPreprocessState mPreprocessState; private Speex.SpeexResampler mResampler; private AudioInputListener mListener; private int mTransmitMode = Constants.TRANSMIT_PUSH_TO_TALK; + private float mVADThreshold = 0; + private boolean mVADLastDetected = false; private AudioRecord mAudioRecord; private int mMinBufferSize; @@ -87,9 +100,11 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { * Creates a new audio input manager configured for the specified codec. * @param listener */ - public AudioInput(JumbleUDPMessageType codec, int transmitMode, AudioInputListener listener) { + public AudioInput(JumbleService service, JumbleUDPMessageType codec, int transmitMode, float voiceThreshold, AudioInputListener listener) { + super(service); mListener = listener; mTransmitMode = transmitMode; + mVADThreshold = voiceThreshold; switchCodec(codec); configurePreprocessState(); @@ -137,6 +152,10 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { mPreprocessState.control(Speex.SpeexPreprocessState.SPEEX_PREPROCESS_SET_AGC_TARGET, arg); // TODO AGC max gain, decrement, noise suppress, echo + + // Increase VAD difficulty + arg.put(99); + mPreprocessState.control(Speex.SpeexPreprocessState.SPEEX_PREPROCESS_GET_PROB_START, arg); } /** @@ -160,11 +179,11 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { Opus.opus_encoder_ctl(mOpusEncoder, Opus.OPUS_SET_VBR_REQUEST, vbr); break; case UDPVoiceCELTBeta: -// mCELTBetaEncoder = CELT11.celt_encoder_create(Audio.SAMPLE_RATE, 1, error); + mCELTBetaEncoder = CELT11.celt_encoder_create(Audio.SAMPLE_RATE, mFrameSize, error); break; case UDPVoiceCELTAlpha: -// mCELTAlphaMode = CELT7.celt_mode_create(Audio.SAMPLE_RATE, Audio.FRAME_SIZE, error); -// mCELTAlphaEncoder = CELT7.celt_encoder_create(mCELTAlphaMode, 1, error); + mCELTAlphaMode = CELT7.celt_mode_create(Audio.SAMPLE_RATE, mFrameSize, error); + mCELTAlphaEncoder = CELT7.celt_encoder_create(mCELTAlphaMode, 1, error); break; case UDPVoiceSpeex: // TODO @@ -221,6 +240,7 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { mRecording = true; mBufferedFrames = 0; mFrameCounter = 0; + mVADLastDetected = false; mAudioRecord.startRecording(); @@ -230,8 +250,11 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { final short[] audioData = new short[mFrameSize]; final short[] resampleBuffer = new short[mMicFrameSize]; + if(mTransmitMode == Constants.TRANSMIT_CONTINUOUS || mTransmitMode == Constants.TRANSMIT_PUSH_TO_TALK) + mListener.onTalkStateChanged(true); + // We loop when the 'recording' instance var is true instead of checking audio record state because we want to always cleanly shutdown. - while(mRecording) { + while(mRecording || mBufferedFrames > 0) { // Make sure we clear all buffered frames before stopping. FIXME- second 'or' condition is experimental, untested. int shortsRead = mAudioRecord.read(mResampler != null ? resampleBuffer : audioData, 0, mResampler != null ? mMicFrameSize : mFrameSize); if(shortsRead > 0) { int len; @@ -242,6 +265,9 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { if(mResampler != null) mResampler.resample(resampleBuffer, audioData); + // Run preprocessor on audio data. TODO echo! + mPreprocessState.preprocess(audioData); + boolean talking = true; if(mTransmitMode == Constants.TRANSMIT_VOICE_ACTIVITY) { @@ -249,16 +275,16 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { IntPointer prob = new IntPointer(1); mPreprocessState.control(Speex.SpeexPreprocessState.SPEEX_PREPROCESS_GET_PROB, prob); float speechProbablilty = (float)prob.get() / 100.0f; - // TODO use determined probability - // talking = ...? + talking = speechProbablilty >= mVADThreshold; + + if(talking ^ mVADLastDetected) // Update the service with the new talking state if we detected voice. + mListener.onTalkStateChanged(talking); + mVADLastDetected = talking; } if(!talking) continue; - // Run preprocessor on audio data. TODO echo! - mPreprocessState.preprocess(audioData); - switch (mCodec) { case UDPVoiceOpus: System.arraycopy(audioData, 0, mOpusBuffer, mFrameSize * mBufferedFrames, mFrameSize); @@ -279,8 +305,12 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { } break; case UDPVoiceCELTBeta: + int betaResult = CELT11.celt_encode(mCELTBetaEncoder, audioData, mFrameSize, mEncodedBuffer, OPUS_MAX_BYTES); + encoded = betaResult == 0; break; case UDPVoiceCELTAlpha: + int alphaResult = CELT7.celt_encode(mCELTAlphaEncoder, audioData, null, mEncodedBuffer, OPUS_MAX_BYTES); + encoded = alphaResult == 0; break; case UDPVoiceSpeex: break; @@ -296,6 +326,8 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { mAudioRecord.stop(); + mListener.onTalkStateChanged(false); + synchronized (mRecordLock) { mRecordLock.notify(); } @@ -324,6 +356,8 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { size |= 1 << 13; mPacketDataStream.writeLong(size); mPacketDataStream.append(frame, frame.length); + } else { + } mListener.onFrameEncoded(mPacketBuffer, mPacketDataStream.size(), mCodec); @@ -335,6 +369,12 @@ public class AudioInput extends JumbleMessageHandler.Stub implements Runnable { public void destroy() { if(mOpusEncoder != null) Opus.opus_encoder_destroy(mOpusEncoder); + if(mCELTBetaEncoder != null) + CELT11.celt_encoder_destroy(mCELTBetaEncoder); + if(mCELTAlphaEncoder != null) + CELT7.celt_encoder_destroy(mCELTAlphaEncoder); + if(mCELTAlphaMode != null) + CELT7.celt_mode_destroy(mCELTAlphaMode); if(mPreprocessState != null) mPreprocessState.destroy(); if(mResampler != null) diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java index 304abc5..680e3a0 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java @@ -25,14 +25,14 @@ import android.os.Process; import android.os.RemoteException; import android.util.Log; -import com.googlecode.javacpp.BytePointer; import com.morlunk.jumble.Constants; import com.morlunk.jumble.IJumbleObserver; import com.morlunk.jumble.JumbleService; import com.morlunk.jumble.model.User; -import com.morlunk.jumble.net.JumbleMessageHandler; +import com.morlunk.jumble.protocol.JumbleMessageListener; import com.morlunk.jumble.net.JumbleUDPMessageType; import com.morlunk.jumble.net.PacketDataStream; +import com.morlunk.jumble.protocol.ProtocolHandler; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -43,12 +43,11 @@ import java.util.concurrent.ConcurrentHashMap; /** * Created by andrew on 16/07/13. */ -public class AudioOutput extends JumbleMessageHandler.Stub implements Runnable, AudioOutputSpeech.TalkStateListener { +public class AudioOutput extends ProtocolHandler implements Runnable, AudioOutputSpeech.TalkStateListener { /** Number of nanoseconds until sleeping audio output thread. */ private static final long SLEEP_THRESHOLD = 3000000000L; - private JumbleService mService; private ConcurrentHashMap<Integer, AudioOutputSpeech> mAudioOutputs = new ConcurrentHashMap<Integer, AudioOutputSpeech>(); private AudioTrack mAudioTrack; @@ -58,7 +57,7 @@ public class AudioOutput extends JumbleMessageHandler.Stub implements Runnable, private long mLastPacket; // Time that the last packet was received, in nanoseconds public AudioOutput(JumbleService service) { - mService = service; + super(service); int bufferSize = AudioTrack.getMinBufferSize(Audio.SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) * 2; mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, @@ -157,7 +156,7 @@ public class AudioOutput extends JumbleMessageHandler.Stub implements Runnable, PacketDataStream pds = new PacketDataStream(voiceData, voiceData.length); int session = (int) pds.readLong(); - User user = mService.getUserHandler().getUser(session); + User user = getService().getUserHandler().getUser(session); if(user != null && !user.isLocalMuted()) { // TODO check for whispers here int seq = (int) pds.readLong(); @@ -187,14 +186,14 @@ public class AudioOutput extends JumbleMessageHandler.Stub implements Runnable, @Override public void onTalkStateUpdated(int session, User.TalkState state) { - final User user = mService.getUserHandler().getUser(session); + final User user = getService().getUserHandler().getUser(session); if(user.getTalkState() != state) { user.setTalkState(state); Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { observer.onUserTalkStateUpdated(user); diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java index 5d2c85e..7c93816 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java @@ -29,8 +29,6 @@ import com.morlunk.jumble.model.User; import com.morlunk.jumble.net.JumbleUDPMessageType; import com.morlunk.jumble.net.PacketDataStream; -import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; 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 c5753ed..66dd219 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java @@ -47,4 +47,8 @@ public class CELT11 { public static native int celt_decode_float(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") BytePointer data, int len, FloatPointer 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 frameSize, IntPointer error); + 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 383e4df..dd5b737 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java @@ -47,4 +47,8 @@ public class CELT7 { public static native int celt_decode_float(@Cast("CELTDecoder*") Pointer st, @Cast("const unsigned char*") BytePointer data, int len, FloatPointer 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_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 72d284e..962a2f5 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/Opus.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/Opus.java @@ -30,7 +30,7 @@ import com.googlecode.javacpp.annotation.Platform; * Created by andrew on 18/10/13. */ -@Platform(library="opus", link="opus", cinclude={"<opus.h>","<opus_types.h>"}) +@Platform(library= "opus", link= "opus", cinclude={"<opus.h>","<opus_types.h>"}) public class Opus { public static final int OPUS_APPLICATION_VOIP = 2048; 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 3ba0018..14d702f 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/Speex.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/Speex.java @@ -32,7 +32,7 @@ import com.googlecode.javacpp.annotation.Platform; * JavaCPP interface for Speex JNI. * Created by andrew on 18/10/13. */ -@Platform(library="speex", link="speex", cinclude={"<speex/speex.h>","<speex/speex_types.h>","<speex/speex_jitter.h>", "<speex/speex_preprocess.h>", "<speex/speex_resampler.h>"}) +@Platform(library= "speex", link= "speex", cinclude={"<speex/speex.h>","<speex/speex_types.h>","<speex/speex_jitter.h>", "<speex/speex_preprocess.h>", "<speex/speex_resampler.h>"}) public class Speex { static { diff --git a/src/main/java/com/morlunk/jumble/db/Database.java b/src/main/java/com/morlunk/jumble/db/Database.java index 86bffc4..7e4efdd 100644 --- a/src/main/java/com/morlunk/jumble/db/Database.java +++ b/src/main/java/com/morlunk/jumble/db/Database.java @@ -22,9 +22,6 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -import com.morlunk.jumble.Constants; -import com.morlunk.jumble.model.Server; - import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/morlunk/jumble/model/Channel.java b/src/main/java/com/morlunk/jumble/model/Channel.java index 2350918..5a80918 100644 --- a/src/main/java/com/morlunk/jumble/model/Channel.java +++ b/src/main/java/com/morlunk/jumble/model/Channel.java @@ -20,7 +20,6 @@ import android.os.Parcel; import android.os.Parcelable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public final class Channel implements Parcelable { diff --git a/src/main/java/com/morlunk/jumble/net/CryptState.java b/src/main/java/com/morlunk/jumble/net/CryptState.java index 9271088..aba0295 100644 --- a/src/main/java/com/morlunk/jumble/net/CryptState.java +++ b/src/main/java/com/morlunk/jumble/net/CryptState.java @@ -31,12 +31,12 @@ import javax.crypto.spec.SecretKeySpec; /** * Based off of the official Mumble project's 'CryptState.h' and 'CryptState.cpp' files. - * <p/> + * * This code implements the patented OCB-AES128 cipher mode of operation. * Until recently, this would've posed a problem- Jumble is licensed under Apache v2, and the patent was only licensed for use with GPL software without authorization. * As of January 2013, the author has given a free license for any open source software certified by the OSI (Apache v2 included) * http://www.cs.ucdavis.edu/~rogaway/ocb/license.htm - * <p/> + * * Created by andrew on 24/06/13. */ public class CryptState { @@ -152,10 +152,9 @@ public class CryptState { public void ocbEncrypt(byte[] plain, byte[] encrypted, int plainLength, byte[] nonce, byte[] tag) throws BadPaddingException, IllegalBlockSizeException, ShortBufferException { final byte[] checksum = new byte[AES_BLOCK_SIZE], - delta = new byte[AES_BLOCK_SIZE], tmp = new byte[AES_BLOCK_SIZE], - pad = new byte[AES_BLOCK_SIZE]; - System.arraycopy(mEncryptKey.doFinal(nonce), 0, delta, 0, AES_BLOCK_SIZE); + pad = new byte[AES_BLOCK_SIZE], + delta = mEncryptKey.doFinal(nonce); final ByteBuffer plainBuffer = ByteBuffer.wrap(plain); final ByteBuffer encryptedBuffer = ByteBuffer.wrap(encrypted); @@ -164,8 +163,8 @@ public class CryptState { int len = plainLength; while(len > AES_BLOCK_SIZE) { - plainBuffer.get(plainRegion); - encryptedBuffer.get(encryptedRegion); + plainBuffer.get(plainRegion, 0, AES_BLOCK_SIZE); + encryptedBuffer.get(encryptedRegion, 0, AES_BLOCK_SIZE); CryptSupport.S2(delta); CryptSupport.XOR(tmp, delta, plainRegion); @@ -177,8 +176,9 @@ public class CryptState { CryptSupport.S2(delta); CryptSupport.ZERO(tmp); - tmp[AES_BLOCK_SIZE-1] = (byte) (((len * 8) >> 8) & 0xFF); - tmp[AES_BLOCK_SIZE-1] = (byte) ((len * 8) & 0xFF); + long num = len * 8; + tmp[AES_BLOCK_SIZE-1] = (byte) ((num >> 8) & 0xFF); + tmp[AES_BLOCK_SIZE-1] = (byte) (num & 0xFF); CryptSupport.XOR(tmp, tmp, delta); mEncryptKey.doFinal(tmp, 0, tmp.length, pad); System.arraycopy(plain, plainBuffer.position(), tmp, 0, len); @@ -192,7 +192,7 @@ public class CryptState { mEncryptKey.doFinal(tmp, 0, AES_BLOCK_SIZE, tag); } - public void ocbDecrypt(byte[] encrypted, byte[] plain, int len, byte[] nonce, byte[] tag) throws BadPaddingException, IllegalBlockSizeException, ShortBufferException { + public void ocbDecrypt(byte[] encrypted, byte[] plain, int encryptedLen, byte[] nonce, byte[] tag) throws BadPaddingException, IllegalBlockSizeException, ShortBufferException { final byte[] checksum = new byte[AES_BLOCK_SIZE], delta = new byte[AES_BLOCK_SIZE], tmp = new byte[AES_BLOCK_SIZE], @@ -205,6 +205,7 @@ public class CryptState { final byte[] plainRegion = new byte[AES_BLOCK_SIZE]; final byte[] encryptedRegion = new byte[AES_BLOCK_SIZE]; + int len = encryptedLen; while (len > AES_BLOCK_SIZE) { plainBuffer.get(plainRegion); encryptedBuffer.get(encryptedRegion); @@ -219,7 +220,9 @@ public class CryptState { CryptSupport.S2(delta); CryptSupport.ZERO(tmp); - tmp[AES_BLOCK_SIZE - 1] = (byte) ((len * 8) & 0xFF); + long num = len * 8; + tmp[AES_BLOCK_SIZE - 2] = (byte) ((num >> 8) & 0xFF); + tmp[AES_BLOCK_SIZE - 1] = (byte) (num & 0xFF); CryptSupport.XOR(tmp, tmp, delta); mEncryptKey.doFinal(tmp, 0, AES_BLOCK_SIZE, pad); System.arraycopy(encrypted, encryptedBuffer.position(), tmp, 0, len); @@ -233,11 +236,12 @@ public class CryptState { } - public boolean decrypt(byte[] source, byte[] dst, int cryptedLength) { + public synchronized byte[] decrypt(byte[] source, int cryptedLength) { if (cryptedLength < 4) - return false; + return null; int plainLength = cryptedLength - 4; + final byte[] dst = new byte[plainLength]; byte[] saveiv = new byte[AES_BLOCK_SIZE]; byte ivbyte = source[0]; boolean restore = false; @@ -258,7 +262,7 @@ public class CryptState { if (++mDecryptIV[i] != 0) break; } else { - return false; + return null; } } else { // This is either out of order or a repeat. @@ -296,12 +300,12 @@ public class CryptState { if (++mDecryptIV[i] != 0) break; } else { - return false; + return null; } if (mDecryptHistory[mDecryptIV[0]] == mDecryptIV[1]) { System.arraycopy(saveiv, 0, mDecryptIV, 0, AES_BLOCK_SIZE); - return false; + return null; } } @@ -327,7 +331,7 @@ public class CryptState { if (Arrays.equals(shiftedSource, threeTag)) { System.arraycopy(saveiv, 0, mDecryptIV, 0, AES_BLOCK_SIZE); - return false; + return null; } mDecryptHistory[mDecryptIV[0]] = mDecryptIV[1]; @@ -339,11 +343,12 @@ public class CryptState { mUiLost += lost; mLastGoodStart = System.nanoTime(); - return true; + return dst; } - public void encrypt(byte[] source, byte[] dst, int plainLength) { + public synchronized byte[] encrypt(byte[] source, int plainLength) { final byte[] tag = new byte[AES_BLOCK_SIZE]; + final byte[] dst = new byte[plainLength+4]; // First, increase our IV. for (int i = 0; i < AES_BLOCK_SIZE; i++) @@ -368,5 +373,6 @@ public class CryptState { dst[1] = tag[0]; dst[2] = tag[1]; dst[3] = tag[2]; + return dst; } } diff --git a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java index 902239c..349d82e 100644 --- a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java +++ b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java @@ -28,6 +28,7 @@ import com.google.protobuf.Message; import com.morlunk.jumble.Constants; import com.morlunk.jumble.model.Server; import com.morlunk.jumble.protobuf.Mumble; +import com.morlunk.jumble.protocol.JumbleMessageListener; import javax.net.ssl.SSLSocket; @@ -36,6 +37,7 @@ import java.net.*; import java.nio.ByteBuffer; import java.security.*; import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; @@ -103,12 +105,12 @@ public class JumbleConnection { private int mSession; // Message handlers - private ConcurrentLinkedQueue<JumbleMessageHandler> mHandlers = new ConcurrentLinkedQueue<JumbleMessageHandler>(); + private ConcurrentLinkedQueue<JumbleMessageListener> mHandlers = new ConcurrentLinkedQueue<JumbleMessageListener>(); /** * Handles packets received that are critical to the connection state. */ - private JumbleMessageHandler mConnectionMessageHandler = new JumbleMessageHandler.Stub() { + private JumbleMessageListener mConnectionMessageHandler = new JumbleMessageListener.Stub() { @Override public void messageServerSync(Mumble.ServerSync msg) { @@ -230,15 +232,11 @@ public class JumbleConnection { long t = getElapsed(); if(!mForceTCP) { - byte[] buffer = new byte[16]; - buffer[0] = (byte) (JumbleUDPMessageType.UDPPing.ordinal() << 5); + ByteBuffer buffer = ByteBuffer.allocate(16); + buffer.put((byte) (JumbleUDPMessageType.UDPPing.ordinal() << 5)); + buffer.putLong(t); - byte[] data = new byte[15]; - PacketDataStream dataStream = new PacketDataStream(data, 8); - dataStream.writeLong(t); - System.arraycopy(data, 0, buffer, 1, dataStream.size()); - - sendUDPMessage(buffer, dataStream.size()+1, true); + sendUDPMessage(buffer.array(), 16, true); } Mumble.Ping.Builder pb = Mumble.Ping.newBuilder(); @@ -315,11 +313,16 @@ public class JumbleConnection { return (System.nanoTime()-mStartTimestamp)/1000; } - public void addMessageHandler(JumbleMessageHandler handler) { + public void addMessageHandler(JumbleMessageListener handler) { mHandlers.add(handler); } - public void removeMessageHandler(JumbleMessageHandler handler) { + public void addMessageHandlers(JumbleMessageListener... handlers) { + for(JumbleMessageListener listener : handlers) + mHandlers.add(listener); + } + + public void removeMessageHandler(JumbleMessageListener handler) { mHandlers.remove(handler); } @@ -486,7 +489,7 @@ public class JumbleConnection { try { Message message = getProtobufMessage(data, messageType); - for(JumbleMessageHandler handler : mHandlers) { + for(JumbleMessageListener handler : mHandlers) { broadcastTCPMessage(handler, message, messageType); } } catch (InvalidProtocolBufferException e) { @@ -496,7 +499,7 @@ public class JumbleConnection { private final void handleUDPMessage(byte[] data) { final JumbleUDPMessageType dataType = JumbleUDPMessageType.values()[data[0] >> 5 & 0x7]; - for(JumbleMessageHandler handler : mHandlers) { + for(JumbleMessageListener handler : mHandlers) { broadcastUDPMessage(handler, data, dataType); } } @@ -573,7 +576,7 @@ public class JumbleConnection { * @param msg Protobuf message. * @param messageType The type of the message. */ - public final void broadcastTCPMessage(JumbleMessageHandler handler, Message msg, JumbleTCPMessageType messageType) { + public final void broadcastTCPMessage(JumbleMessageListener handler, Message msg, JumbleTCPMessageType messageType) { switch (messageType) { case Authenticate: handler.messageAuthenticate((Mumble.Authenticate) msg); @@ -666,7 +669,7 @@ public class JumbleConnection { * @param data Raw UDP data of the message. * @param messageType The type of the message. */ - public final void broadcastUDPMessage(JumbleMessageHandler handler, byte[] data, JumbleUDPMessageType messageType) { + public final void broadcastUDPMessage(JumbleMessageListener handler, byte[] data, JumbleUDPMessageType messageType) { switch (messageType) { case UDPPing: handler.messageUDPPing(data); @@ -771,8 +774,6 @@ public class JumbleConnection { } } - mConnected = false; - if(mListener != null) { mMainHandler.post(new Runnable() { @Override @@ -827,11 +828,11 @@ public class JumbleConnection { public void run() { try { mUDPSocket = new DatagramSocket(); - mUDPSocket.connect(mHost, mServer.getPort()); } catch (SocketException e) { mListener.onConnectionWarning("Could not initialize UDP socket! Try forcing a TCP connection."); return; } + mUDPSocket.connect(mHost, mServer.getPort()); DatagramPacket packet = new DatagramPacket(new byte[BUFFER_SIZE], BUFFER_SIZE); @@ -841,8 +842,8 @@ public class JumbleConnection { try { mUDPSocket.receive(packet); // Decrypt UDP packet using OCB-AES128 - final byte[] decryptedData = new byte[packet.getLength()]; - if(!mCryptState.decrypt(packet.getData(), decryptedData, packet.getLength()) && + final byte[] decryptedData = mCryptState.decrypt(packet.getData(), packet.getLength()); + if(decryptedData == null && mCryptState.getLastGoodElapsed() > 5000000 && mCryptState.getLastRequestElapsed() > 5000000) { // If decryption fails, request resync @@ -861,8 +862,7 @@ public class JumbleConnection { public void sendMessage(byte[] data, int length) throws IOException { if(!mCryptState.isValid()) return; - byte[] encryptedData = new byte[length+4]; - mCryptState.encrypt(data, encryptedData, length); + byte[] encryptedData = mCryptState.encrypt(data, length); DatagramPacket packet = new DatagramPacket(encryptedData, encryptedData.length); packet.setAddress(mHost); packet.setPort(mServer.getPort()); diff --git a/src/main/java/com/morlunk/jumble/net/JumbleObserver.java b/src/main/java/com/morlunk/jumble/net/JumbleObserver.java index 865b124..db653eb 100644 --- a/src/main/java/com/morlunk/jumble/net/JumbleObserver.java +++ b/src/main/java/com/morlunk/jumble/net/JumbleObserver.java @@ -98,7 +98,7 @@ public class JumbleObserver extends IJumbleObserver.Stub { } @Override - public void onMessageReceived(String message) throws RemoteException { + public void onMessageReceived(User user, String message) throws RemoteException { } } diff --git a/src/main/java/com/morlunk/jumble/net/ChannelHandler.java b/src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java index 2366d70..d88ffb5 100644 --- a/src/main/java/com/morlunk/jumble/net/ChannelHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.morlunk.jumble.net; +package com.morlunk.jumble.protocol; import android.os.RemoteException; @@ -33,7 +33,7 @@ import java.util.Map; /** * Created by andrew on 18/07/13. */ -public class ChannelHandler extends JumbleMessageHandler.Stub { +public class ChannelHandler extends ProtocolHandler { private Comparator<Integer> mChannelComparator = new Comparator<Integer>() { @Override @@ -46,11 +46,10 @@ public class ChannelHandler extends JumbleMessageHandler.Stub { } }; - private JumbleService mService; private Map<Integer, Channel> mChannels = new HashMap<Integer, Channel>(); public ChannelHandler(JumbleService service) { - mService = service; + super(service); } public Channel getChannel(int id) { @@ -130,7 +129,7 @@ public class ChannelHandler extends JumbleMessageHandler.Stub { } final Channel finalChannel = channel; - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { if(newChannel) @@ -151,7 +150,7 @@ public class ChannelHandler extends JumbleMessageHandler.Stub { parent.removeSubchannel(msg.getChannelId()); changeSubchannelUsers(parent, -channel.getUsers().size()); } - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { observer.onChannelRemoved(channel); @@ -170,8 +169,8 @@ public class ChannelHandler extends JumbleMessageHandler.Stub { if(channel != null) { channel.setPermissions(msg.getPermissions()); if(msg.getChannelId() == 0) // If we're provided permissions for the root channel, we'll apply these as our server permissions. - mService.setPermissions(msg.getPermissions()); - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().setPermissions(msg.getPermissions()); + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { observer.onChannelPermissionsUpdated(channel); diff --git a/src/main/java/com/morlunk/jumble/net/JumbleMessageHandler.java b/src/main/java/com/morlunk/jumble/protocol/JumbleMessageListener.java index 8b1174e..3f39372 100644 --- a/src/main/java/com/morlunk/jumble/net/JumbleMessageHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/JumbleMessageListener.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.morlunk.jumble.net; +package com.morlunk.jumble.protocol; import com.morlunk.jumble.protobuf.Mumble; -public interface JumbleMessageHandler { +public interface JumbleMessageListener { public void messageAuthenticate(Mumble.Authenticate msg); public void messageBanList(Mumble.BanList msg); public void messageReject(Mumble.Reject msg); @@ -55,7 +55,8 @@ public interface JumbleMessageHandler { * Designed to be subclassed at any level of the library, the default implementations do nothing. * Created by andrew on 24/06/13. */ - public static class Stub implements JumbleMessageHandler { + public static class Stub implements JumbleMessageListener { + public void messageAuthenticate(Mumble.Authenticate msg) {} public void messageBanList(Mumble.BanList msg) {} public void messageReject(Mumble.Reject msg) {} diff --git a/src/main/java/com/morlunk/jumble/protocol/ProtocolHandler.java b/src/main/java/com/morlunk/jumble/protocol/ProtocolHandler.java new file mode 100644 index 0000000..43cead3 --- /dev/null +++ b/src/main/java/com/morlunk/jumble/protocol/ProtocolHandler.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2013 Andrew Comminos + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package com.morlunk.jumble.protocol; + +import com.morlunk.jumble.JumbleService; + +/** + * A protocol handler implements a discrete type (or class) of TCP or UDP protobuf messages. + * The purpose of protocol handlers is to divide logic for each type of data received from the + * server (i.e. audio, user state, channels) into their own classes. + * Created by andrew on 21/11/13. + */ +public class ProtocolHandler extends JumbleMessageListener.Stub { + + private JumbleService mService; + + public ProtocolHandler(JumbleService service) { + mService = service; + } + + protected JumbleService getService() { + return mService; + } +} diff --git a/src/main/java/com/morlunk/jumble/net/TextMessageHandler.java b/src/main/java/com/morlunk/jumble/protocol/TextMessageHandler.java index 5b63667..97db785 100644 --- a/src/main/java/com/morlunk/jumble/net/TextMessageHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/TextMessageHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.morlunk.jumble.net; +package com.morlunk.jumble.protocol; import com.morlunk.jumble.JumbleService; import com.morlunk.jumble.model.User; @@ -25,18 +25,16 @@ import com.morlunk.jumble.util.MessageFormatter; * Handles receiving text messages. * Created by andrew on 27/07/13. */ -public class TextMessageHandler extends JumbleMessageHandler.Stub { - - private JumbleService mService; +public class TextMessageHandler extends ProtocolHandler { public TextMessageHandler(JumbleService service) { - mService = service; + super(service); } @Override public void messageTextMessage(Mumble.TextMessage msg) { // TODO format user colors - User sender = mService.getUserHandler().getUser(msg.getActor()); + User sender = getService().getUserHandler().getUser(msg.getActor()); if(sender != null && sender.isLocalIgnored()) return; @@ -50,6 +48,6 @@ public class TextMessageHandler extends JumbleMessageHandler.Stub { else if(msg.getChannelIdCount() > 0) senderTarget = "(Channel) "; - mService.logMessage(String.format("%s%s: %s", senderTarget, senderName, msg.getMessage())); + getService().logMessage(sender, String.format("%s%s: %s", senderTarget, senderName, msg.getMessage())); } } diff --git a/src/main/java/com/morlunk/jumble/net/UserHandler.java b/src/main/java/com/morlunk/jumble/protocol/UserHandler.java index a33de1a..a520451 100644 --- a/src/main/java/com/morlunk/jumble/net/UserHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/UserHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.morlunk.jumble.net; +package com.morlunk.jumble.protocol; import android.os.RemoteException; import android.util.Log; @@ -37,7 +37,7 @@ import java.util.List; /** * Created by andrew on 18/07/13. */ -public class UserHandler extends JumbleMessageHandler.Stub { +public class UserHandler extends ProtocolHandler { /** * Comparator to sort users alphabetically. @@ -51,11 +51,10 @@ public class UserHandler extends JumbleMessageHandler.Stub { } }; - private JumbleService mService; private HashMap<Integer, User> mUsers = new HashMap<Integer, User>(); public UserHandler(JumbleService service) { - mService = service; + super(service); } public User getUser(int id) { @@ -83,7 +82,7 @@ public class UserHandler extends JumbleMessageHandler.Stub { User user = mUsers.get(msg.getSession()); boolean newUser = false; - User self = mUsers.get(mService.getSession()); + User self = mUsers.get(getService().getSession()); if(user == null) { if(msg.hasName()) { @@ -91,7 +90,7 @@ public class UserHandler extends JumbleMessageHandler.Stub { mUsers.put(msg.getSession(), user); newUser = true; // Add user to root channel by default. This works because for some reason, we don't get a channel ID when the user joins into root. - Channel root = mService.getChannelHandler().getChannel(0); + Channel root = getService().getChannelHandler().getChannel(0); user.setChannelId(0); root.addUser(user.getSession()); root.setSubchannelUserCount(root.getSubchannelUserCount()+1); @@ -121,7 +120,7 @@ public class UserHandler extends JumbleMessageHandler.Stub { } if(newUser) - mService.logInfo(mService.getString(R.string.chat_notify_connected, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_connected, MessageFormatter.highlightString(user.getName()))); if(msg.hasSelfDeaf() || msg.hasSelfMute()) { if(msg.hasSelfMute()) @@ -131,11 +130,11 @@ public class UserHandler extends JumbleMessageHandler.Stub { if(self != null && user.getSession() != self.getSession() && (user.getChannelId() == self.getChannelId())) { if(user.isSelfMuted() && user.isSelfDeafened()) - mService.logInfo(mService.getString(R.string.chat_notify_now_muted_deafened, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_now_muted_deafened, MessageFormatter.highlightString(user.getName()))); else if(user.isSelfMuted()) - mService.logInfo(mService.getString(R.string.chat_notify_now_muted, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_now_muted, MessageFormatter.highlightString(user.getName()))); else - mService.logInfo(mService.getString(R.string.chat_notify_now_unmuted, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_now_unmuted, MessageFormatter.highlightString(user.getName()))); } } @@ -145,17 +144,17 @@ public class UserHandler extends JumbleMessageHandler.Stub { if(self != null) { if(user.getSession() == self.getSession()) { if(user.isRecording()) - mService.logInfo(mService.getString(R.string.chat_notify_self_recording_started)); + getService().logInfo(getService().getString(R.string.chat_notify_self_recording_started)); else - mService.logInfo(mService.getString(R.string.chat_notify_self_recording_stopped)); + getService().logInfo(getService().getString(R.string.chat_notify_self_recording_stopped)); } else { - Channel selfChannel = mService.getChannelHandler().getChannel(user.getChannelId()); + Channel selfChannel = getService().getChannelHandler().getChannel(user.getChannelId()); // If in a linked channel OR the same channel as the current user, notify the user about recording if(selfChannel != null && (selfChannel.getLinks().contains(user.getChannelId()) || self.getChannelId() == user.getChannelId())) { if(user.isRecording()) - mService.logInfo(mService.getString(R.string.chat_notify_user_recording_started, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_user_recording_started, MessageFormatter.highlightString(user.getName()))); else - mService.logInfo(mService.getString(R.string.chat_notify_user_recording_stopped, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_user_recording_stopped, MessageFormatter.highlightString(user.getName()))); } } } @@ -172,7 +171,7 @@ public class UserHandler extends JumbleMessageHandler.Stub { /* if(self != null && ((user.getChannelId() == self.getChannelId()) || (actor.getSession() == self.getSession()))) { if(user.getSession() == self.getSession()) { if(msg.hasMute() && msg.hasDeaf() && user.isMuted() && user.isDeafened()) { - mService.logInfo(); + getService().logInfo(); } } }*/ @@ -184,25 +183,25 @@ public class UserHandler extends JumbleMessageHandler.Stub { } if(msg.hasChannelId()) { - final Channel channel = mService.getChannelHandler().getChannel(msg.getChannelId()); + final Channel channel = getService().getChannelHandler().getChannel(msg.getChannelId()); if(channel == null) { Log.e(Constants.TAG, "Invalid channel for user!"); return; // TODO handle better } - final Channel old = mService.getChannelHandler().getChannel(user.getChannelId()); + final Channel old = getService().getChannelHandler().getChannel(user.getChannelId()); user.setChannelId(msg.getChannelId()); if(old != null) { old.removeUser(user.getSession()); - mService.getChannelHandler().changeSubchannelUsers(old, -1); + getService().getChannelHandler().changeSubchannelUsers(old, -1); } channel.addUser(user.getSession()); - mService.getChannelHandler().changeSubchannelUsers(channel, 1); + getService().getChannelHandler().changeSubchannelUsers(channel, 1); sortUsers(channel); if(!newUser) { - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { observer.onUserJoinedChannel(finalUser, channel, old); @@ -230,7 +229,7 @@ public class UserHandler extends JumbleMessageHandler.Stub { final boolean finalNewUser = newUser; - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { if(finalNewUser) @@ -247,18 +246,18 @@ public class UserHandler extends JumbleMessageHandler.Stub { final User actor = getUser(msg.getActor()); final String reason = msg.getReason(); - if(msg.getSession() == mService.getSession()) - mService.logWarning(mService.getString(msg.getBan() ? R.string.chat_notify_kick_ban_self : R.string.chat_notify_kick_self, MessageFormatter.highlightString(actor.getName()), reason)); + if(msg.getSession() == getService().getSession()) + getService().logWarning(getService().getString(msg.getBan() ? R.string.chat_notify_kick_ban_self : R.string.chat_notify_kick_self, MessageFormatter.highlightString(actor.getName()), reason)); else if(actor != null) - mService.logInfo(mService.getString(msg.getBan() ? R.string.chat_notify_kick_ban : R.string.chat_notify_kick, MessageFormatter.highlightString(actor.getName()), reason, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(msg.getBan() ? R.string.chat_notify_kick_ban : R.string.chat_notify_kick, MessageFormatter.highlightString(actor.getName()), reason, MessageFormatter.highlightString(user.getName()))); else - mService.logInfo(mService.getString(R.string.chat_notify_disconnected, MessageFormatter.highlightString(user.getName()))); + getService().logInfo(getService().getString(R.string.chat_notify_disconnected, MessageFormatter.highlightString(user.getName()))); - Channel channel = mService.getChannelHandler().getChannel(user.getChannelId()); + Channel channel = getService().getChannelHandler().getChannel(user.getChannelId()); channel.removeUser(user.getSession()); - mService.getChannelHandler().changeSubchannelUsers(channel, -1); - mService.notifyObservers(new JumbleService.ObserverRunnable() { + getService().getChannelHandler().changeSubchannelUsers(channel, -1); + getService().notifyObservers(new JumbleService.ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { observer.onUserRemoved(user, reason); diff --git a/src/main/jni/celt11.cpp b/src/main/jni/celt11.cpp index dae13a9..506efda 100644 --- a/src/main/jni/celt11.cpp +++ b/src/main/jni/celt11.cpp @@ -1027,17 +1027,17 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mod } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decoder_1ctl(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mode_1info(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - char* ptr2 = arg2 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); ptr2 += position2; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_decoder_ctl((CELTDecoder*)ptr0, arg1, ptr2); + int rvalue = celt_mode_info((const CELTMode*)ptr0, arg1, ptr2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1048,13 +1048,21 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decode } return rarg; } -JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decode(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; + signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); + ptr1 += position1; + short* ptr3 = arg3 == NULL ? NULL : (short*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; + jint rarg = 0; jthrowable exc = NULL; try { - celt_decoder_destroy((CELTDecoder*)ptr0); + int rvalue = celt_decode((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4); + rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1062,18 +1070,43 @@ JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decode if (exc != NULL) { env->Throw(exc); } + return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mode_1info(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); + ptr1 += position1; + float* ptr3 = arg3 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; + jint rarg = 0; + jthrowable exc = NULL; + try { + int rvalue = celt_decode_float((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4); + rarg = (jint)rvalue; + } catch (...) { + exc = JavaCPP_handleException(env, 14); + } + + if (exc != NULL) { + env->Throw(exc); + } + return rarg; +} +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decoder_1ctl(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; + char* ptr2 = arg2 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); ptr2 += position2; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_mode_info((const CELTMode*)ptr0, arg1, ptr2); + int rvalue = celt_decoder_ctl((CELTDecoder*)ptr0, arg1, ptr2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1084,13 +1117,13 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mode_1 } return rarg; } -JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mode_1destroy(JNIEnv* env, jclass cls, jobject arg0) { +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; jthrowable exc = NULL; try { - celt_mode_destroy((CELTMode*)ptr0); + celt_decoder_destroy((CELTDecoder*)ptr0); } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1099,7 +1132,7 @@ JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mode_1 env->Throw(exc); } } -JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jobject arg2) { +JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1encoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jobject arg2) { int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); ptr2 += position2; @@ -1107,7 +1140,7 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1dec void* rptr; jthrowable exc = NULL; try { - rptr = celt_decoder_create(arg0, arg1, ptr2); + rptr = celt_encoder_create(arg0, arg1, ptr2); if (rptr != NULL) { rarg = env->AllocObject(JavaCPP_getClass(env, 1)); env->SetLongField(rarg, JavaCPP_addressFID, ptr_to_jlong(rptr)); @@ -1121,45 +1154,71 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1dec } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decode(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1encode(JNIEnv* env, jclass cls, jobject arg0, jshortArray arg1, jint arg2, jbyteArray arg3, jint arg4) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); - jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); - ptr1 += position1; - short* ptr3 = arg3 == NULL ? NULL : (short*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; + short* ptr1 = arg1 == NULL ? NULL : env->GetShortArrayElements(arg1, NULL); + signed char* ptr3 = arg3 == NULL ? NULL : env->GetByteArrayElements(arg3, NULL); jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_decode((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4); + int rvalue = celt_encode((CELTEncoder*)ptr0, (const short*)ptr1, arg2, (unsigned char*)ptr3, arg4); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } + if (arg1 != NULL) env->ReleaseShortArrayElements(arg1, (jshort*)ptr1, 0); + if (arg3 != NULL) env->ReleaseByteArrayElements(arg3, (jbyte*)ptr3, 0); if (exc != NULL) { env->Throw(exc); } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4) { +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1encoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); - jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); - ptr1 += position1; - float* ptr3 = arg3 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; - jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_decode_float((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4); - rarg = (jint)rvalue; + celt_encoder_destroy((CELTEncoder*)ptr0); + } catch (...) { + exc = JavaCPP_handleException(env, 14); + } + + if (exc != NULL) { + env->Throw(exc); + } +} +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1mode_1destroy(JNIEnv* env, jclass cls, jobject arg0) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; + jthrowable exc = NULL; + try { + celt_mode_destroy((CELTMode*)ptr0); + } catch (...) { + exc = JavaCPP_handleException(env, 14); + } + + if (exc != NULL) { + env->Throw(exc); + } +} +JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT11_celt_1decoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jobject arg2) { + int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); + ptr2 += position2; + jobject rarg = NULL; + void* rptr; + jthrowable exc = NULL; + try { + rptr = celt_decoder_create(arg0, arg1, ptr2); + if (rptr != NULL) { + rarg = env->AllocObject(JavaCPP_getClass(env, 1)); + env->SetLongField(rarg, JavaCPP_addressFID, ptr_to_jlong(rptr)); + } } catch (...) { exc = JavaCPP_handleException(env, 14); } diff --git a/src/main/jni/celt7.cpp b/src/main/jni/celt7.cpp index ef1f102..0f53852 100644 --- a/src/main/jni/celt7.cpp +++ b/src/main/jni/celt7.cpp @@ -1027,17 +1027,17 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder_1ctl(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode_1info(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - char* ptr2 = arg2 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); ptr2 += position2; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_decoder_ctl((CELTDecoder*)ptr0, arg1, ptr2); + int rvalue = celt_mode_info((const CELTMode*)ptr0, arg1, ptr2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1048,13 +1048,21 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder } return rarg; } -JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decode(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; + signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); + ptr1 += position1; + short* ptr3 = arg3 == NULL ? NULL : (short*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; + jint rarg = 0; jthrowable exc = NULL; try { - celt_decoder_destroy((CELTDecoder*)ptr0); + int rvalue = celt_decode((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3); + rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1062,18 +1070,43 @@ JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder if (exc != NULL) { env->Throw(exc); } + return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode_1info(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); + ptr1 += position1; + float* ptr3 = arg3 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; + jint rarg = 0; + jthrowable exc = NULL; + try { + int rvalue = celt_decode_float((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3); + rarg = (jint)rvalue; + } catch (...) { + exc = JavaCPP_handleException(env, 14); + } + + if (exc != NULL) { + env->Throw(exc); + } + return rarg; +} +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder_1ctl(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; + char* ptr2 = arg2 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); ptr2 += position2; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_mode_info((const CELTMode*)ptr0, arg1, ptr2); + int rvalue = celt_decoder_ctl((CELTDecoder*)ptr0, arg1, ptr2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1084,13 +1117,13 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode_1i } return rarg; } -JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode_1destroy(JNIEnv* env, jclass cls, jobject arg0) { +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; jthrowable exc = NULL; try { - celt_mode_destroy((CELTMode*)ptr0); + celt_decoder_destroy((CELTDecoder*)ptr0); } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1099,7 +1132,7 @@ JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode_1d env->Throw(exc); } } -JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder_1create(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { +JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1encoder_1create(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; @@ -1110,8 +1143,8 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1deco void* rptr; jthrowable exc = NULL; try { - rptr = celt_decoder_create((CELTMode*)ptr0, arg1, ptr2); - if (rptr == (CELTMode*)ptr0) { + rptr = celt_encoder_create((const CELTMode *)ptr0, arg1, ptr2); + if (rptr == (const CELTMode *)ptr0) { rarg = arg0; } else if (rptr != NULL) { rarg = env->AllocObject(JavaCPP_getClass(env, 1)); @@ -1126,45 +1159,78 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1deco } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decode(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1encode(JNIEnv* env, jclass cls, jobject arg0, jshortArray arg1, jshortArray arg2, jbyteArray arg3, jint arg4) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); - jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); - ptr1 += position1; - short* ptr3 = arg3 == NULL ? NULL : (short*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; + short* ptr1 = arg1 == NULL ? NULL : env->GetShortArrayElements(arg1, NULL); + short* ptr2 = arg2 == NULL ? NULL : env->GetShortArrayElements(arg2, NULL); + signed char* ptr3 = arg3 == NULL ? NULL : env->GetByteArrayElements(arg3, NULL); jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_decode((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3); + int rvalue = celt_encode((CELTEncoder *)ptr0, (const short *)ptr1, (short *)ptr2, (unsigned char *)ptr3, arg4); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } + if (arg1 != NULL) env->ReleaseShortArrayElements(arg1, (jshort*)ptr1, 0); + if (arg2 != NULL) env->ReleaseShortArrayElements(arg2, (jshort*)ptr2, 0); + if (arg3 != NULL) env->ReleaseByteArrayElements(arg3, (jbyte*)ptr3, 0); if (exc != NULL) { env->Throw(exc); } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3) { +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1encoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); - jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); - ptr1 += position1; - float* ptr3 = arg3 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; - jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = celt_decode_float((CELTDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3); - rarg = (jint)rvalue; + celt_encoder_destroy((CELTEncoder *)ptr0); + } catch (...) { + exc = JavaCPP_handleException(env, 14); + } + + if (exc != NULL) { + env->Throw(exc); + } +} +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1mode_1destroy(JNIEnv* env, jclass cls, jobject arg0) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; + jthrowable exc = NULL; + try { + celt_mode_destroy((CELTMode*)ptr0); + } catch (...) { + exc = JavaCPP_handleException(env, 14); + } + + if (exc != NULL) { + env->Throw(exc); + } +} +JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_CELT7_celt_1decoder_1create(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; + int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); + ptr2 += position2; + jobject rarg = NULL; + void* rptr; + jthrowable exc = NULL; + try { + rptr = celt_decoder_create((CELTMode*)ptr0, arg1, ptr2); + if (rptr == (CELTMode*)ptr0) { + rarg = arg0; + } else if (rptr != NULL) { + rarg = env->AllocObject(JavaCPP_getClass(env, 1)); + env->SetLongField(rarg, JavaCPP_addressFID, ptr_to_jlong(rptr)); + } } catch (...) { exc = JavaCPP_handleException(env, 14); } diff --git a/src/main/jni/opus.cpp b/src/main/jni/opus.cpp index 785020c..9ad5173 100644 --- a/src/main/jni/opus.cpp +++ b/src/main/jni/opus.cpp @@ -1005,20 +1005,14 @@ JNIEXPORT void JNICALL Java_com_googlecode_javacpp_SizeTPointer_allocateArray(JN env->CallNonvirtualVoidMethodA(obj, JavaCPP_getClass(env, 1), JavaCPP_initMID, args); } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4) { - char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1nb_1channels(JNIEnv* env, jclass cls, jobject arg0) { + signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - float* ptr1 = arg1 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); - jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); - ptr1 += position1; - signed char* ptr3 = arg3 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_encode_float((OpusEncoder*)ptr0, (const float*)ptr1, arg2, (unsigned char*)ptr3, arg4); + int rvalue = opus_packet_get_nb_channels((const unsigned char*)ptr0); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1029,13 +1023,15 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encode_1 } return rarg; } -JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { - char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1nb_1frames(JNIEnv* env, jclass cls, jobject arg0, jint arg1) { + signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; + jint rarg = 0; jthrowable exc = NULL; try { - opus_encoder_destroy((OpusEncoder*)ptr0); + int rvalue = opus_packet_get_nb_frames((const unsigned char*)ptr0, arg1); + rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1043,18 +1039,16 @@ JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_ if (exc != NULL) { env->Throw(exc); } + return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1ctl(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { - char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1nb_1samples(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jint arg2) { + signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - char* ptr2 = arg2 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); - jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); - ptr2 += position2; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_encoder_ctl((OpusEncoder*)ptr0, arg1, ptr2); + int rvalue = opus_packet_get_nb_samples((const unsigned char*)ptr0, arg1, arg2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1065,11 +1059,11 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_ } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1get_1size(JNIEnv* env, jclass cls, jint arg0) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1get_1size(JNIEnv* env, jclass cls, jint arg0) { jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_decoder_get_size(arg0); + int rvalue = opus_encoder_get_size(arg0); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1080,15 +1074,15 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_ } return rarg; } -JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jobject arg2) { - int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); - jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); - ptr2 += position2; +JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jint arg2, jobject arg3) { + int* ptr3 = arg3 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; jobject rarg = NULL; void* rptr; jthrowable exc = NULL; try { - rptr = opus_decoder_create(arg0, arg1, ptr2); + rptr = opus_encoder_create(arg0, arg1, arg2, ptr3); if (rptr != NULL) { rarg = env->AllocObject(JavaCPP_getClass(env, 1)); env->SetLongField(rarg, JavaCPP_addressFID, ptr_to_jlong(rptr)); @@ -1102,14 +1096,14 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decod } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1init(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jint arg2) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1init(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jint arg2, jint arg3) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_decoder_init((OpusDecoder*)ptr0, arg1, arg2); + int rvalue = opus_encoder_init((OpusEncoder*)ptr0, arg1, arg2, arg3); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1120,44 +1114,42 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_ } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decode(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4, jint arg5) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encode(JNIEnv* env, jclass cls, jobject arg0, jshortArray arg1, jint arg2, jbyteArray arg3, jint arg4) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); - jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); - ptr1 += position1; - short* ptr3 = arg3 == NULL ? NULL : (short*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; + short* ptr1 = arg1 == NULL ? NULL : env->GetShortArrayElements(arg1, NULL); + signed char* ptr3 = arg3 == NULL ? NULL : env->GetByteArrayElements(arg3, NULL); jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_decode((OpusDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4, arg5); + int rvalue = opus_encode((OpusEncoder*)ptr0, (const short*)ptr1, arg2, (unsigned char*)ptr3, arg4); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } + if (arg1 != NULL) env->ReleaseShortArrayElements(arg1, (jshort*)ptr1, 0); + if (arg3 != NULL) env->ReleaseByteArrayElements(arg3, (jbyte*)ptr3, 0); if (exc != NULL) { env->Throw(exc); } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4, jint arg5) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + float* ptr1 = arg1 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); ptr1 += position1; - float* ptr3 = arg3 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + signed char* ptr3 = arg3 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); ptr3 += position3; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_decode_float((OpusDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4, arg5); + int rvalue = opus_encode_float((OpusEncoder*)ptr0, (const float*)ptr1, arg2, (unsigned char*)ptr3, arg4); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1168,13 +1160,13 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decode_1 } return rarg; } -JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; jthrowable exc = NULL; try { - opus_decoder_destroy((OpusDecoder*)ptr0); + opus_encoder_destroy((OpusEncoder*)ptr0); } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1183,14 +1175,17 @@ JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_ env->Throw(exc); } } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1bandwidth(JNIEnv* env, jclass cls, jobject arg0) { - signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1ctl(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jobject arg2) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; + char* ptr2 = arg2 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); + ptr2 += position2; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_packet_get_bandwidth((const unsigned char*)ptr0); + int rvalue = opus_encoder_ctl((OpusEncoder*)ptr0, arg1, ptr2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1201,14 +1196,11 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1 } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1samples_1per_1frame(JNIEnv* env, jclass cls, jobject arg0, jint arg1) { - signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); - jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); - ptr0 += position0; +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1get_1size(JNIEnv* env, jclass cls, jint arg0) { jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_packet_get_samples_per_frame((const unsigned char*)ptr0, arg1); + int rvalue = opus_decoder_get_size(arg0); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1219,15 +1211,19 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1 } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1nb_1channels(JNIEnv* env, jclass cls, jobject arg0) { - signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); - jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); - ptr0 += position0; - jint rarg = 0; +JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jobject arg2) { + int* ptr2 = arg2 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg2, JavaCPP_addressFID)); + jint position2 = arg2 == NULL ? 0 : env->GetIntField(arg2, JavaCPP_positionFID); + ptr2 += position2; + jobject rarg = NULL; + void* rptr; jthrowable exc = NULL; try { - int rvalue = opus_packet_get_nb_channels((const unsigned char*)ptr0); - rarg = (jint)rvalue; + rptr = opus_decoder_create(arg0, arg1, ptr2); + if (rptr != NULL) { + rarg = env->AllocObject(JavaCPP_getClass(env, 1)); + env->SetLongField(rarg, JavaCPP_addressFID, ptr_to_jlong(rptr)); + } } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1237,14 +1233,14 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1 } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1nb_1frames(JNIEnv* env, jclass cls, jobject arg0, jint arg1) { - signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1init(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jint arg2) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_packet_get_nb_frames((const unsigned char*)ptr0, arg1); + int rvalue = opus_decoder_init((OpusDecoder*)ptr0, arg1, arg2); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1255,14 +1251,20 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1 } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1nb_1samples(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jint arg2) { - signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decode(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4, jint arg5) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; + signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); + ptr1 += position1; + short* ptr3 = arg3 == NULL ? NULL : (short*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_packet_get_nb_samples((const unsigned char*)ptr0, arg1, arg2); + int rvalue = opus_decode((OpusDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4, arg5); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1273,11 +1275,20 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1 } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1get_1size(JNIEnv* env, jclass cls, jint arg0) { +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decode_1float(JNIEnv* env, jclass cls, jobject arg0, jobject arg1, jint arg2, jobject arg3, jint arg4, jint arg5) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; + signed char* ptr1 = arg1 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg1, JavaCPP_addressFID)); + jint position1 = arg1 == NULL ? 0 : env->GetIntField(arg1, JavaCPP_positionFID); + ptr1 += position1; + float* ptr3 = arg3 == NULL ? NULL : (float*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); + jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); + ptr3 += position3; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_encoder_get_size(arg0); + int rvalue = opus_decode_float((OpusDecoder*)ptr0, (const unsigned char*)ptr1, arg2, ptr3, arg4, arg5); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1288,19 +1299,13 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_ } return rarg; } -JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1create(JNIEnv* env, jclass cls, jint arg0, jint arg1, jint arg2, jobject arg3) { - int* ptr3 = arg3 == NULL ? NULL : (int*)jlong_to_ptr(env->GetLongField(arg3, JavaCPP_addressFID)); - jint position3 = arg3 == NULL ? 0 : env->GetIntField(arg3, JavaCPP_positionFID); - ptr3 += position3; - jobject rarg = NULL; - void* rptr; +JNIEXPORT void JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1decoder_1destroy(JNIEnv* env, jclass cls, jobject arg0) { + char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); + jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); + ptr0 += position0; jthrowable exc = NULL; try { - rptr = opus_encoder_create(arg0, arg1, arg2, ptr3); - if (rptr != NULL) { - rarg = env->AllocObject(JavaCPP_getClass(env, 1)); - env->SetLongField(rarg, JavaCPP_addressFID, ptr_to_jlong(rptr)); - } + opus_decoder_destroy((OpusDecoder*)ptr0); } catch (...) { exc = JavaCPP_handleException(env, 14); } @@ -1308,16 +1313,15 @@ JNIEXPORT jobject JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encod if (exc != NULL) { env->Throw(exc); } - return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_1init(JNIEnv* env, jclass cls, jobject arg0, jint arg1, jint arg2, jint arg3) { - char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1bandwidth(JNIEnv* env, jclass cls, jobject arg0) { + signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_encoder_init((OpusEncoder*)ptr0, arg1, arg2, arg3); + int rvalue = opus_packet_get_bandwidth((const unsigned char*)ptr0); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); @@ -1328,23 +1332,19 @@ JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encoder_ } return rarg; } -JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1encode(JNIEnv* env, jclass cls, jobject arg0, jshortArray arg1, jint arg2, jbyteArray arg3, jint arg4) { - char* ptr0 = arg0 == NULL ? NULL : (char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); +JNIEXPORT jint JNICALL Java_com_morlunk_jumble_audio_javacpp_Opus_opus_1packet_1get_1samples_1per_1frame(JNIEnv* env, jclass cls, jobject arg0, jint arg1) { + signed char* ptr0 = arg0 == NULL ? NULL : (signed char*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID)); jint position0 = arg0 == NULL ? 0 : env->GetIntField(arg0, JavaCPP_positionFID); ptr0 += position0; - short* ptr1 = arg1 == NULL ? NULL : env->GetShortArrayElements(arg1, NULL); - signed char* ptr3 = arg3 == NULL ? NULL : env->GetByteArrayElements(arg3, NULL); jint rarg = 0; jthrowable exc = NULL; try { - int rvalue = opus_encode((OpusEncoder*)ptr0, (const short*)ptr1, arg2, (unsigned char*)ptr3, arg4); + int rvalue = opus_packet_get_samples_per_frame((const unsigned char*)ptr0, arg1); rarg = (jint)rvalue; } catch (...) { exc = JavaCPP_handleException(env, 14); } - if (arg1 != NULL) env->ReleaseShortArrayElements(arg1, (jshort*)ptr1, 0); - if (arg3 != NULL) env->ReleaseByteArrayElements(arg3, (jbyte*)ptr3, 0); if (exc != NULL) { env->Throw(exc); } diff --git a/src/main/libs/armeabi/libcelt11.so b/src/main/libs/armeabi/libcelt11.so Binary files differindex ddfc482..9656d51 100755 --- a/src/main/libs/armeabi/libcelt11.so +++ b/src/main/libs/armeabi/libcelt11.so diff --git a/src/main/libs/armeabi/libcelt7.so b/src/main/libs/armeabi/libcelt7.so Binary files differindex f2b6d11..924821e 100755 --- a/src/main/libs/armeabi/libcelt7.so +++ b/src/main/libs/armeabi/libcelt7.so diff --git a/src/main/libs/armeabi/libopus.so b/src/main/libs/armeabi/libopus.so Binary files differindex 5694d09..f2c9d53 100755 --- a/src/main/libs/armeabi/libopus.so +++ b/src/main/libs/armeabi/libopus.so diff --git a/src/main/libs/armeabi/libspeex.so b/src/main/libs/armeabi/libspeex.so Binary files differindex 5d3f7d2..979f422 100755 --- a/src/main/libs/armeabi/libspeex.so +++ b/src/main/libs/armeabi/libspeex.so |