• R/O
  • SSH
  • HTTPS

iax24j: コミット


コミットメタ情報

リビジョン58 (tree)
日時2013-11-20 22:58:49
作者cbs01360

ログメッセージ

Bug fixed

変更サマリ

差分

--- branches/android/iax24j/src/iax/client/audio/Player.java (revision 57)
+++ branches/android/iax24j/src/iax/client/audio/Player.java (revision 58)
@@ -16,7 +16,6 @@
1616 */
1717 public final static int JITTER_BUFFER = 1;
1818
19-
2019 /**
2120 * Constructor. Initializes the player.
2221 * @throws PlayerException
--- branches/android/iax24j/src/iax/client/protocol/connection/Connection.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/connection/Connection.java (revision 58)
@@ -23,6 +23,6 @@
2323 * Sends a packet udp from an array of bytes
2424 * @param data the data to send
2525 */
26- public abstract void send(byte data[]);
26+ public abstract void send(byte data[]) throws Exception;
2727
2828 }
\ No newline at end of file
--- branches/android/iax24j/src/iax/client/protocol/connection/J2SEConnection.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/connection/J2SEConnection.java (revision 58)
@@ -65,7 +65,7 @@
6565 // Wait until receiving the data of a packet
6666 socket.receive( packet );
6767 recv(packet);
68- } catch (IOException e) {
68+ } catch (Exception e) {
6969 e.printStackTrace();
7070 }
7171 }
@@ -85,13 +85,13 @@
8585 /* (non-Javadoc)
8686 * @see iax.protocol.connection.IConnection#send(byte[])
8787 */
88- public void send(byte data[]) {
89- try {
88+ public void send(byte data[]) throws Exception {
89+// try {
9090 DatagramPacket packet = new DatagramPacket(data, data.length, hostIAddr, port);
9191 socket.send(packet);
92- } catch (Exception e) {
93- e.printStackTrace();
94- }
92+// } catch (Exception e) {
93+// e.printStackTrace();
94+// }
9595 }
9696
9797 }
\ No newline at end of file
--- branches/android/iax24j/src/iax/client/protocol/frame/ProtocolControlFrame.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/frame/ProtocolControlFrame.java (revision 58)
@@ -498,6 +498,21 @@
498498 }
499499
500500 /**
501+ * Gets a msgcount subclass
502+ * @return the cause code as an integer.
503+ * @throws FrameException
504+ */
505+ public int getMsgCount() throws FrameException {
506+ try {
507+ byte data[] = (byte[])infoElements.get(new Integer(InfoElement.MSGCOUNT));
508+ ByteBuffer byteBuffer = new ByteBuffer(data);
509+ return byteBuffer.get16bits();
510+ } catch (Exception e) {
511+ throw new FrameException(e);
512+ }
513+ }
514+
515+ /**
501516 * Gets the user name.
502517 * @return The user name as string.
503518 * @throws FrameException
--- branches/android/iax24j/src/iax/client/protocol/call/state/Linked.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/call/state/Linked.java (revision 58)
@@ -112,6 +112,8 @@
112112 ProtocolControlFrame protocolControlFrame = (ProtocolControlFrame) frame;
113113 switch (protocolControlFrame.getSubclass()) {
114114 case ProtocolControlFrame.ACCEPT_SC:
115+ protocolControlFrame.setCapability(call.getAudioFactory().getCodec());
116+ protocolControlFrame.setFormat(call.getAudioFactory().getCodec());
115117 call.sendFullFrameAndWaitForAck(protocolControlFrame);
116118 break;
117119 default:
--- branches/android/iax24j/src/iax/client/protocol/call/state/CallState.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/call/state/CallState.java (revision 58)
@@ -27,11 +27,13 @@
2727 CallCommandRecvFacade.ack(call, protocolControlFrame);
2828 break;
2929 case ProtocolControlFrame.HANGUP_SC:
30+// System.out.println("%%%%%%%%%%%%% CakkState#handleRecvFrame HANGUP_SC %%%%%%%%%%%%%%%%%%%%%%%");
3031 CallCommandRecvFacade.hangup(call, protocolControlFrame);
3132 call.setState(Initial.getInstance());
3233 call.endCall();
3334 break;
3435 case ProtocolControlFrame.INVAL_SC:
36+// System.out.println("%%%%%%%%%%%%% CakkState#handleRecvFrame INVAL_SC %%%%%%%%%%%%%%%%%%%%%%%");
3537 call.setState(Initial.getInstance());
3638 call.endCall();
3739 break;
--- branches/android/iax24j/src/iax/client/protocol/call/Call.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/call/Call.java (revision 58)
@@ -15,6 +15,7 @@
1515 import iax.client.protocol.frame.ProtocolControlFrame;
1616 import iax.client.protocol.peer.Peer;
1717 import iax.client.protocol.peer.PeerException;
18+import iax.client.protocol.peer.state.Unregistered;
1819
1920 import java.util.Iterator;
2021 import java.util.Timer;
@@ -31,7 +32,7 @@
3132 * Interval in milliseconds that the miniframe's timestamp is reset
3233 */
3334 public static final int TIMESTAMP_MINIFRAME_RESET = 65536;
34-
35+
3536 // Maximum size of a sequence number
3637 private final int SEQNO_MAXSIZE = 256;
3738 // ***** PING DESACTIVATED *****
@@ -41,9 +42,7 @@
4142 private final int RETRY_MAXCOUNT = 10;
4243 //Peer's retry refresh in seconds
4344 private final int RETRY_REFRESH = 1;
44-
45- private final int MAX_FAILURE = 5;
46-
45+ private final int MAX_CONTINUAL_FAILURE = 0;
4746 // HashMap with the frames that are waiting for an ack
4847 private ConcurrentHashMap<Long, FullFrame> framesWaitingAck;
4948 // HashMap with the frames that are waiting for a specific reply
@@ -89,8 +88,7 @@
8988
9089 private boolean callTokenReceived = false;
9190
92- private int failureCount = 0;
93-
91+ private int continualFailureCount = 0;
9492 /**
9593 * Constructor. Initialize the player and the recorder
9694 * @param peer the peer that handles this call
@@ -298,6 +296,7 @@
298296 * Ends a call. For that stops the player and the recorder, and notifies the peer that this call is finished
299297 */
300298 public void endCall() {
299+// System.out.println("%%%%%%%%%%%%%%%%% Call#endCall called %%%%%%%%%%%%%%%%%%%%%%%%%");
301300 // ***** PING DESACTIVATED *****
302301 // pingTimer.cancel();
303302 retryTimer.cancel();
@@ -430,6 +429,7 @@
430429 */
431430 public synchronized void ackedFrame(long timeStamp) {
432431 framesWaitingAck.remove(new Long(timeStamp));
432+ continualFailureCount = 0;
433433 }
434434
435435 /**
@@ -438,6 +438,7 @@
438438 */
439439 public synchronized void repliedFrame(int id) {
440440 framesWaitingReply.remove(new Integer(id));
441+ continualFailureCount = 0;
441442 }
442443
443444 /**
@@ -468,7 +469,7 @@
468469 peer.sendFrame(fullFrame);
469470 }
470471
471- static int x = 0;
472+// static int x = 0;
472473 /**
473474 * Plays audio from the audio frames received through the player. If the player is stopped, starts it.
474475 * @param timestamp the timestamp of the frame
@@ -475,7 +476,7 @@
475476 * @param data the audio data of the frame
476477 * @param absolute if the timestamp absolute or not
477478 */
478- public void writeAudioIn(long timestamp, byte[] data, boolean absolute) {
479+ public synchronized void writeAudioIn(long timestamp, byte[] data, boolean absolute) {
479480 if (!hold) {
480481 if (!playing) {
481482 player.play();
@@ -501,8 +502,8 @@
501502 retryFullFrame.incRetryCount();
502503 if (retryFullFrame.getRetryCount() < RETRY_MAXCOUNT) {
503504 peer.sendFrame(retryFullFrame);
504- failureCount = 0;
505505 } else{
506+ iterator.remove();
506507 throw new PeerException("Reached retries maximun in the call " + srcCallNo +
507508 " for a full frame of type " + retryFullFrame.getFrameType() + ", subclass " + retryFullFrame.getSubclass());
508509 }
@@ -513,19 +514,24 @@
513514 retryFullFrame.incRetryCount();
514515 if (retryFullFrame.getRetryCount() < RETRY_MAXCOUNT) {
515516 peer.sendFrame(retryFullFrame);
516- failureCount = 0;
517517 } else {
518+ iterator.remove();
518519 throw new PeerException("Reached retries maximun in the call " + srcCallNo +
519520 " for a full frame of type " + retryFullFrame.getFrameType() + ", subclass " + retryFullFrame.getSubclass());
520521 }
521522 }
522523 } catch (PeerException e) {
523- framesWaitingAck.clear();
524- framesWaitingReply.clear();
525- if (failureCount++ >= MAX_FAILURE){
526- endCall(); // ƒRƒƒ“ƒgƒAƒEƒg‚µ‚Ä‚¢‚½
527- }
528- e.printStackTrace(); // ƒRƒƒ“ƒgƒAƒEƒg‚µ‚Ä‚¢‚½
524+// if (continualFailureCount < MAX_CONTINUAL_FAILURE) {
525+// continualFailureCount++;
526+// } else {
527+// System.out.println("%%%%%%%%%%%%%%%%% retryFramesWaiting retry over %%%%%%%%%%%%%%%%%%%%%%%%%");
528+ framesWaitingAck.clear();
529+ framesWaitingReply.clear();
530+ CallCommandSendFacade.hangup(this);
531+ endCall();
532+ peer.setState(Unregistered.getInstance());
533+// }
534+ e.printStackTrace();
529535 }
530536 }
531537
@@ -537,7 +543,6 @@
537543 }
538544
539545 public void listen(final byte[] buffer, int length) {
540- // TODO think about length
541546 CallCommandSendFacade.sendVoice(this, buffer);
542547 }
543548
@@ -549,12 +554,10 @@
549554 return dtmfCode;
550555 }
551556
552-
553557 public AudioFactory getAudioFactory() {
554558 return audioFactory;
555559 }
556560
557-
558561 public void setAudioFactory(AudioFactory audioFactory) {
559562 this.audioFactory = audioFactory;
560563 }
@@ -575,14 +578,12 @@
575578 this.recorder = recorder;
576579 }
577580
578-
579581 public boolean isCallTokenReceived() {
580582 return callTokenReceived;
581583 }
582584
583-
584585 public void setCallTokenReceived(boolean callTokenReceived) {
585586 this.callTokenReceived = callTokenReceived;
586587 }
587-
588+
588589 }
\ No newline at end of file
--- branches/android/iax24j/src/iax/client/protocol/call/command/send/Accept.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/call/command/send/Accept.java (revision 58)
@@ -1,7 +1,6 @@
11 package iax.client.protocol.call.command.send;
22
33 import iax.client.protocol.call.Call;
4-import iax.client.protocol.frame.FrameException;
54 import iax.client.protocol.frame.ProtocolControlFrame;
65
76 /**
@@ -27,7 +26,7 @@
2726 }
2827
2928 public void run() {
30- ProtocolControlFrame acceptFrame = new ProtocolControlFrame(call.getSrcCallNo(),
29+ call.handleSendFrame(new ProtocolControlFrame(call.getSrcCallNo(),
3130 false,
3231 call.getDestCallNo(),
3332 recvCallFrame.getTimestamp(),
@@ -34,21 +33,6 @@
3433 recvCallFrame.getOseqno(),
3534 recvCallFrame.getIseqno(),
3635 false,
37- ProtocolControlFrame.ACCEPT_SC);
38- try {
39- acceptFrame.setCapability(call.getAudioFactory().getCodec());
40- acceptFrame.setFormat(call.getAudioFactory().getCodec());
41- call.handleSendFrame(acceptFrame);
42- } catch (FrameException e) {
43- e.printStackTrace();
44- }
45-// call.handleSendFrame(new ProtocolControlFrame(call.getSrcCallNo(),
46-// false,
47-// call.getDestCallNo(),
48-// recvCallFrame.getTimestamp(),
49-// recvCallFrame.getOseqno(),
50-// recvCallFrame.getIseqno(),
51-// false,
52-// ProtocolControlFrame.ACCEPT_SC));
36+ ProtocolControlFrame.ACCEPT_SC));
5337 }
5438 }
--- branches/android/iax24j/src/iax/client/protocol/peer/state/Waiting.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/peer/state/Waiting.java (revision 58)
@@ -36,7 +36,10 @@
3636 PeerCommandRecvFacade.regack(peer, protocolControlFrame);
3737 if (peer.isProcessingExit())
3838 peer.setState(Unregistered.getInstance());
39- else peer.setState(Registered.getInstance());
39+ else {
40+ peer.setMsgCount(protocolControlFrame.getMsgCount());
41+ peer.setState(Registered.getInstance());
42+ }
4043 break;
4144 case ProtocolControlFrame.REGAUTH_SC:
4245 if (peer.isProcessingExit())
--- branches/android/iax24j/src/iax/client/protocol/peer/Peer.java (revision 57)
+++ branches/android/iax24j/src/iax/client/protocol/peer/Peer.java (revision 58)
@@ -39,7 +39,9 @@
3939 //Peer's retry refresh in seconds
4040 private final int RETRY_REFRESH = 1;
4141 //Peer's retry max
42- private final int RETRY_MAXCOUNT = 10;
42+ private final int RETRY_MAXCOUNT = 5;
43+
44+// private final int MAX_CONTINUAL_FAILURE = 2;
4345
4446 //Registration user name.
4547 private String userName;
@@ -64,7 +66,7 @@
6466 //Source timestamp for full frames from the first full frame sent by this call
6567 private long srcTimestamp;
6668 //Register timer task
67- private Timer registerTimer;
69+ private Timer registerTimer = null;
6870 //Retry timer task to retry frames not committed whit a specific frame or an ack frame
6971 private Timer retryTimer;
7072 //Flag for determining if the peer is processing the exit
@@ -71,8 +73,16 @@
7173 private boolean processingExit;
7274 //Max calls
7375 // private int maxCalls;
76+// private int continualFailureCount = 0;
7477
78+ private int regRefresh = 5;
79+
80+ // How many messages waiting
81+ private int msgCount = 0;
82+
7583 private AudioFactory audioFactory;
84+
85+ private boolean reconnectFlag = false;
7686
7787 /**
7888 * Constructor. Initializes the peer with the given values.Using NullAudioFactory class and J2SEConnection class
@@ -141,17 +151,23 @@
141151 }
142152 };
143153 retryTimer.schedule(retryTimerTask, RETRY_REFRESH*1000, RETRY_REFRESH*1000);
144- this.registerTimer = new Timer();
145- if (register) {
146- TimerTask registerTimerTask = new TimerTask() {
147- public void run() {
148- register();
149- }
150- };
151- registerTimer.schedule(registerTimerTask, 0, REGISTER_REFRESH*1000);
152- }
154+ setRegisterSchedule();
153155 }
154156
157+ private void setRegisterSchedule() {
158+ if (registerTimer != null){
159+ registerTimer.cancel();
160+ }
161+ registerTimer = new Timer();
162+ TimerTask registerTimerTask = new TimerTask() {
163+ public void run() {
164+ register();
165+ }
166+ };
167+// System.out.println("VVVVVVVVVVVVVVVVVVVV setRegisterSchedule regRefresh = " + regRefresh + " VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV");
168+ registerTimer.schedule(registerTimerTask, 0, regRefresh * 1000);
169+ }
170+
155171 /**
156172 * Gets peer user name.
157173 * @return String with user name.
@@ -192,6 +208,8 @@
192208 public long getTimestamp() {
193209 long now = System.currentTimeMillis();
194210 return now-srcTimestamp;
211+// srcTimestamp += 20;
212+// return srcTimestamp;
195213 }
196214
197215 /**
@@ -208,12 +226,19 @@
208226 */
209227 public void setState(PeerState state) {
210228 this.state = state;
211- if (state instanceof Registered)
229+ if (state instanceof Registered) {
212230 peerListener.registered();
213- else if (state instanceof Waiting)
231+ if (regRefresh != REGISTER_REFRESH) {
232+ regRefresh = REGISTER_REFRESH;
233+ setRegisterSchedule();
234+ }
235+ } else if (state instanceof Waiting) {
214236 peerListener.waiting();
215- else if (state instanceof Unregistered)
237+ } else if (state instanceof Unregistered) {
216238 peerListener.unregistered();
239+ regRefresh = 5;
240+ setRegisterSchedule();
241+ }
217242 }
218243
219244
@@ -231,6 +256,7 @@
231256 */
232257 public synchronized void ackedFrame(long timeStamp) {
233258 framesWaitingAck.remove(new Long(timeStamp));
259+// continualFailureCount = 0;
234260 }
235261
236262 /**
@@ -239,6 +265,7 @@
239265 */
240266 public synchronized void repliedFrame(int id) {
241267 framesWaitingReply.remove(new Integer(id));
268+// continualFailureCount = 0;
242269 }
243270
244271 /**
@@ -246,6 +273,7 @@
246273 */
247274 public void register() {
248275 srcTimestamp = System.currentTimeMillis();
276+// srcTimestamp = 0;
249277 PeerCommandSendFacade.regreq(this);
250278 }
251279
@@ -358,6 +386,10 @@
358386 try {
359387 connection.send(frame.serialize());
360388 } catch (Exception e) {
389+ if (call != null) {
390+ call.endCall();
391+ }
392+ setState(Unregistered.getInstance());
361393 e.printStackTrace();
362394 }
363395 }
@@ -411,6 +443,7 @@
411443 * @param call The call to end.
412444 */
413445 public void endCall(Call call) {
446+// System.out.println("%%%%%%%%%%%%%%%%% Peer#endCall called %%%%%%%%%%%%%%%%%%%%%%%%%");
414447 peerListener.hungup(call.getCalledNumber());
415448 this.call = null;
416449 }
@@ -421,8 +454,7 @@
421454 * @return The new call.
422455 * @throws PeerException
423456 */
424- //public synchronized Call newCall(String calledNumber) throws PeerException {
425- public Call newCall(String calledNumber) throws PeerException {
457+ public synchronized Call newCall(String calledNumber) throws PeerException {
426458 if (call == null && peerListener.isEnabled()) {
427459 Call newCall = null;
428460 try {
@@ -483,8 +515,15 @@
483515 retryFullFrame.incRetryCount();
484516 if (retryFullFrame.getRetryCount() < RETRY_MAXCOUNT) {
485517 sendFrame(retryFullFrame);
486- } else throw new PeerException("Reached retries maximun in the peer for full frame of type " +
487- retryFullFrame.getFrameType() + ", subclass " + retryFullFrame.getSubclass());
518+ } else {
519+ iterator.remove();
520+ if (retryFullFrame.getFrameType() == 6
521+ && retryFullFrame.getSubclass() == 13){
522+ reconnectFlag = true;
523+ }
524+ throw new PeerException("Reached retries maximun in the peer for full frame of type " +
525+ retryFullFrame.getFrameType() + ", subclass " + retryFullFrame.getSubclass());
526+ }
488527 }
489528 iterator = framesWaitingReply.values().iterator();
490529 while (iterator.hasNext()) {
@@ -492,15 +531,39 @@
492531 retryFullFrame.incRetryCount();
493532 if (retryFullFrame.getRetryCount() < RETRY_MAXCOUNT) {
494533 sendFrame(retryFullFrame);
495- } else throw new PeerException("Reached retries maximun in the peer for full frame of type " +
534+ } else {
535+ iterator.remove();
536+ if (retryFullFrame.getFrameType() == 6
537+ && retryFullFrame.getSubclass() == 13){
538+ reconnectFlag = true;
539+ }
540+ throw new PeerException("Reached retries maximun in the peer for full frame of type " +
496541 retryFullFrame.getFrameType() + ", subclass " + retryFullFrame.getSubclass());
542+ }
497543 }
498544 } catch (PeerException e) {
499545 framesWaitingAck.clear();
500546 framesWaitingReply.clear();
501- setState(Unregistered.getInstance());
547+ setState(Unregistered.getInstance());
502548 e.printStackTrace();
503549 }
504550 }
551+
552+ /**
553+ * @return the msgCount
554+ */
555+ public int getMsgCount() {
556+ return msgCount;
557+ }
558+
559+ /**
560+ * @param msgCount the msgCount to set
561+ */
562+ public void setMsgCount(int msgCount) {
563+ this.msgCount = msgCount;
564+ }
505565
566+ public boolean isReconnect() {
567+ return reconnectFlag;
568+ }
506569 }
\ No newline at end of file
旧リポジトリブラウザで表示