diff options
author | Andrew Comminos <andrew@morlunk.com> | 2015-04-27 06:21:43 +0300 |
---|---|---|
committer | Andrew Comminos <andrew@morlunk.com> | 2015-04-27 06:21:43 +0300 |
commit | a5ba7a7e1181afc6475a215ddd9e49a08ff55cd9 (patch) | |
tree | 2dfeedb584634f49bb9520be1279378e8ce6d428 /src/main/java/com/morlunk/jumble | |
parent | 24f6e3d2c5662f38982b92e8148ed8088bd61e79 (diff) |
Implemented TalkState AIDL model.
Diffstat (limited to 'src/main/java/com/morlunk/jumble')
10 files changed, 95 insertions, 46 deletions
diff --git a/src/main/java/com/morlunk/jumble/JumbleService.java b/src/main/java/com/morlunk/jumble/JumbleService.java index a98425d..10af4a8 100644 --- a/src/main/java/com/morlunk/jumble/JumbleService.java +++ b/src/main/java/com/morlunk/jumble/JumbleService.java @@ -40,6 +40,7 @@ import com.morlunk.jumble.model.IChannel; import com.morlunk.jumble.model.IUser; import com.morlunk.jumble.model.Message; import com.morlunk.jumble.model.Server; +import com.morlunk.jumble.model.TalkState; import com.morlunk.jumble.model.User; import com.morlunk.jumble.net.JumbleConnection; import com.morlunk.jumble.util.JumbleException; @@ -183,7 +184,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon } @Override - public void onTalkStateChange(final User.TalkState state) { + public void onTalkStateChange(final TalkState state) { mHandler.post(new Runnable() { @Override public void run() { diff --git a/src/main/java/com/morlunk/jumble/audio/AudioInput.java b/src/main/java/com/morlunk/jumble/audio/AudioInput.java index b6e1ad7..91a7215 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioInput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioInput.java @@ -21,20 +21,10 @@ import android.media.AudioFormat; import android.media.AudioRecord; import android.util.Log; -import com.googlecode.javacpp.IntPointer; -import com.googlecode.javacpp.Loader; import com.morlunk.jumble.Constants; -import com.morlunk.jumble.audio.encoder.IEncoder; -import com.morlunk.jumble.audio.encoder.CELT11Encoder; -import com.morlunk.jumble.audio.encoder.CELT7Encoder; -import com.morlunk.jumble.audio.encoder.OpusEncoder; -import com.morlunk.jumble.audio.javacpp.Opus; -import com.morlunk.jumble.audio.javacpp.Speex; import com.morlunk.jumble.exception.AudioInitializationException; import com.morlunk.jumble.exception.NativeAudioException; -import com.morlunk.jumble.model.User; -import com.morlunk.jumble.net.JumbleUDPMessageType; -import com.morlunk.jumble.net.PacketBuffer; +import com.morlunk.jumble.model.TalkState; import com.morlunk.jumble.protocol.AudioHandler; /** @@ -197,7 +187,7 @@ public class AudioInput implements Runnable { return; if(mTransmitMode == Constants.TRANSMIT_CONTINUOUS || mTransmitMode == Constants.TRANSMIT_PUSH_TO_TALK) - mListener.onTalkStateChange(User.TalkState.TALKING); + mListener.onTalkStateChange(TalkState.TALKING); final short[] mAudioBuffer = new short[mFrameSize]; // We loop when the 'recording' instance var is true instead of checking audio record state because we want to always cleanly shutdown. @@ -232,8 +222,8 @@ public class AudioInput implements Runnable { talking |= (System.nanoTime() - vadLastDetectedTime) < SPEECH_DETECT_THRESHOLD; if(talking ^ vadLastDetected) // Update the service with the new talking state if we detected voice. - mListener.onTalkStateChange(talking ? User.TalkState.TALKING : - User.TalkState.PASSIVE); + mListener.onTalkStateChange(talking ? TalkState.TALKING : + TalkState.PASSIVE); vadLastDetected = talking; } @@ -247,13 +237,13 @@ public class AudioInput implements Runnable { mAudioRecord.stop(); - mListener.onTalkStateChange(User.TalkState.PASSIVE); + mListener.onTalkStateChange(TalkState.PASSIVE); Log.i(Constants.TAG, "AudioInput: stopped"); } public interface AudioInputListener { - public void onTalkStateChange(User.TalkState state); + public void onTalkStateChange(TalkState state); public void onAudioInputReceived(short[] frame, int frameSize); } } diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java index 5cd02d9..22d9bac 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java @@ -28,6 +28,7 @@ import android.util.Log; import com.morlunk.jumble.Constants; import com.morlunk.jumble.exception.AudioInitializationException; import com.morlunk.jumble.exception.NativeAudioException; +import com.morlunk.jumble.model.TalkState; import com.morlunk.jumble.model.User; import com.morlunk.jumble.net.JumbleUDPMessageType; import com.morlunk.jumble.net.PacketBuffer; @@ -252,7 +253,7 @@ public class AudioOutput implements Runnable, AudioOutputSpeech.TalkStateListene } @Override - public void onTalkStateUpdated(int session, User.TalkState state) { + public void onTalkStateUpdated(int session, TalkState state) { final User user = mListener.getUser(session); if(user != null && user.getTalkState() != state) { user.setTalkState(state); diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java index 8d336f9..175bb72 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java @@ -23,6 +23,7 @@ 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.exception.NativeAudioException; +import com.morlunk.jumble.model.TalkState; import com.morlunk.jumble.model.User; import com.morlunk.jumble.net.JumbleUDPMessageType; import com.morlunk.jumble.net.PacketBuffer; @@ -42,7 +43,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class AudioOutputSpeech implements Callable<AudioOutputSpeech.Result> { interface TalkStateListener { - public void onTalkStateUpdated(int session, User.TalkState state); + public void onTalkStateUpdated(int session, TalkState state); } private IDecoder mDecoder; @@ -303,19 +304,19 @@ public class AudioOutputSpeech implements Callable<AudioOutputSpeech.Result> { if(!nextAlive) ucFlags = 0xFF; - User.TalkState talkState; + TalkState talkState; switch (ucFlags) { case 0: - talkState = User.TalkState.TALKING; + talkState = TalkState.TALKING; break; case 1: - talkState = User.TalkState.SHOUTING; + talkState = TalkState.SHOUTING; break; case 0xFF: - talkState = User.TalkState.PASSIVE; + talkState = TalkState.PASSIVE; break; default: - talkState = User.TalkState.WHISPERING; + talkState = TalkState.WHISPERING; break; } diff --git a/src/main/java/com/morlunk/jumble/model/Message.java b/src/main/java/com/morlunk/jumble/model/Message.java index 8aa97c4..17270da 100644 --- a/src/main/java/com/morlunk/jumble/model/Message.java +++ b/src/main/java/com/morlunk/jumble/model/Message.java @@ -118,4 +118,14 @@ public class Message extends IMessage.Stub { result = 31 * result + (int) (mReceivedTime ^ (mReceivedTime >>> 32)); return result; } + + /** + * The type of message this object represents. + * @deprecated + */ + public enum Type { + INFO, + WARNING, + TEXT_MESSAGE + } } diff --git a/src/main/java/com/morlunk/jumble/model/TalkState.java b/src/main/java/com/morlunk/jumble/model/TalkState.java new file mode 100644 index 0000000..c87391d --- /dev/null +++ b/src/main/java/com/morlunk/jumble/model/TalkState.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 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.model; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * User talk state. + * Created by andrew on 19/04/15. + */ +public enum TalkState implements Parcelable { + TALKING, + SHOUTING, + PASSIVE, + WHISPERING; + + public static Creator<TalkState> CREATOR = new Creator<TalkState>() { + @Override + public TalkState createFromParcel(Parcel source) { + return TalkState.values()[source.readInt()]; + } + + @Override + public TalkState[] newArray(int size) { + return new TalkState[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(ordinal()); + } +} diff --git a/src/main/java/com/morlunk/jumble/model/User.java b/src/main/java/com/morlunk/jumble/model/User.java index 6a5e950..f34e261 100644 --- a/src/main/java/com/morlunk/jumble/model/User.java +++ b/src/main/java/com/morlunk/jumble/model/User.java @@ -17,21 +17,10 @@ package com.morlunk.jumble.model; -import android.graphics.Bitmap; -import android.os.Parcel; -import android.os.Parcelable; - import com.google.protobuf.ByteString; public class User extends IUser.Stub implements Comparable<User> { - public static enum TalkState { - TALKING, - SHOUTING, - PASSIVE, - WHISPERING - } - private int mSession; private int mId = -1; private String mName; @@ -211,8 +200,8 @@ public class User extends IUser.Stub implements Comparable<User> { mLocalIgnored = localIgnored; } - public int getTalkState() { - return mTalkState.ordinal(); // FIXME: ordinals are bad + public TalkState getTalkState() { + return mTalkState; } public void setTalkState(TalkState mTalkState) { diff --git a/src/main/java/com/morlunk/jumble/protocol/AudioHandler.java b/src/main/java/com/morlunk/jumble/protocol/AudioHandler.java index cd0592a..0aa2718 100644 --- a/src/main/java/com/morlunk/jumble/protocol/AudioHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/AudioHandler.java @@ -38,7 +38,7 @@ import com.morlunk.jumble.audio.encoder.ResamplingEncoder; import com.morlunk.jumble.exception.AudioException; import com.morlunk.jumble.exception.AudioInitializationException; import com.morlunk.jumble.exception.NativeAudioException; -import com.morlunk.jumble.model.Message; +import com.morlunk.jumble.model.TalkState; import com.morlunk.jumble.model.User; import com.morlunk.jumble.net.JumbleConnection; import com.morlunk.jumble.net.JumbleUDPMessageType; @@ -499,9 +499,9 @@ public class AudioHandler extends JumbleNetworkListener implements AudioInput.Au } @Override - public void onTalkStateChange(User.TalkState state) { + public void onTalkStateChange(TalkState state) { synchronized (mEncoderLock) { - if (mEncoder != null && state == User.TalkState.PASSIVE) { + if (mEncoder != null && state == TalkState.PASSIVE) { try { mEncoder.terminate(); if (mEncoder.isReady()) { @@ -559,7 +559,7 @@ public class AudioHandler extends JumbleNetworkListener implements AudioInput.Au public interface AudioEncodeListener { public void onAudioEncoded(byte[] data, int length); - public void onTalkStateChange(User.TalkState state); + public void onTalkStateChange(TalkState state); } /** diff --git a/src/main/java/com/morlunk/jumble/protocol/ModelHandler.java b/src/main/java/com/morlunk/jumble/protocol/ModelHandler.java index 7baeef2..b696763 100644 --- a/src/main/java/com/morlunk/jumble/protocol/ModelHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/ModelHandler.java @@ -286,7 +286,7 @@ public class ModelHandler extends JumbleTCPMessageListener.Stub { if(msg.hasSelfDeaf()) user.setSelfDeafened(msg.getSelfDeaf()); - if(self != null && user.getSession() != self.getSession() && (user.getChannelId() == self.getChannelId())) { + if(self != null && user.getSession() != self.getSession() && user.getChannel().equals(self.getChannel())) { if(user.isSelfMuted() && user.isSelfDeafened()) mLogger.log(Message.Type.INFO, mContext.getString(R.string.chat_notify_now_muted_deafened, MessageFormatter.highlightString(user.getName()))); else if(user.isSelfMuted()) @@ -450,8 +450,8 @@ public class ModelHandler extends JumbleTCPMessageListener.Stub { else mLogger.log(Message.Type.INFO, mContext.getString(R.string.chat_notify_disconnected, MessageFormatter.highlightString(user.getName()))); - Channel channel = mChannels.get(user.getChannelId()); - channel.removeUser(user.getSession()); + Channel channel = user.getChannel(); + channel.removeUser(user); changeSubchannelUsers(channel, -1); try { diff --git a/src/main/java/com/morlunk/jumble/util/JumbleLogger.java b/src/main/java/com/morlunk/jumble/util/JumbleLogger.java index 5570241..72b261c 100644 --- a/src/main/java/com/morlunk/jumble/util/JumbleLogger.java +++ b/src/main/java/com/morlunk/jumble/util/JumbleLogger.java @@ -20,9 +20,12 @@ package com.morlunk.jumble.util; import com.morlunk.jumble.model.Message; /** + * An interface for reporting user-readable information. * Created by andrew on 12/07/14. */ public interface JumbleLogger { - public void log(String message); - public void log(Message message); + void logInfo(String message); + void logWarning(String message); + void logError(String message); + void log(Message.Type type, String message); } |