CallContext deals with all the packets that are part of a specific call. More...
Public Member Functions | |
CallContext (RemotePeer remotePeer, AudioInterface audioInterface) | |
The outbound constructor for Call. | |
synchronized int | getOutSeqNoInc () |
Generates a new outbound stream sequence number. | |
synchronized int | getOutSeqNo () |
Returns the outbound stream sequence number, oSeqno. | |
int | getInSeqNo () |
Returns the inbound stream sequence number. | |
void | setInSeqNo (int next) |
Sets the inbound stream sequence number. | |
void | send (OctetBuffer pdu) |
Sends a PDU to our peer. | |
int | getTimestamp () |
Returns the timestamp of this call. | |
void | stopAudioRecording () |
Stops sending audio. | |
void | setCallEstablished (boolean established) |
Sets if this call is established. | |
boolean | isEstablished () |
Returns if this call has been callAnswered. | |
void | audioWrite (byte[] bs, long timestamp) throws IOException |
Writes audio data to the speaker. | |
void | onReceivedVoicePDU (long timestamp, byte[] audioSample) |
Notifies us that a Voice PDU has been received. | |
void | setSourceCallNumber (int callNo) |
Sets the local call number as a character. | |
int | getSourceCallNumber () |
Returns the local call number. | |
void | setDestinationCallNumber (int callNo) |
Sets the remote call number as a character. | |
int | getDestinationCallNumber () |
Returns the remote call number. | |
void | resetClock () |
Resets the clock. | |
long | getStartTimestamp () |
Returns the start time-stamp of the call. | |
synchronized ProtocolDataUnit | addIn (ProtocolDataUnit pdu) |
Passed a newly arrived PDU. | |
void | cleanUp () |
Cleans up and detaches call from peer. | |
int | getAudioSampleSize () |
Returns the audio interface sample size (used to determine size of the VoicePDU). | |
Package Attributes | |
AudioInterface | audioInterface = null |
The audio interface used to play/record for our voice PDUs. | |
Private Member Functions | |
void | startAudioRecording () |
Starts sending our audio interface recording. | |
Private Attributes | |
int | sourceCallNumber = 1 |
Represents the Source Call Number in the PDU header. | |
int | destinationCallNumber = 0 |
Represents the Destination Call Number in the PDU header. | |
int | outSeqNo = 0 |
The outbound stream sequence number. | |
int | inSeqNo = 0 |
The inbound stream sequence number. | |
long | startTimestamp = 0 |
The start time-stamp of the call. | |
RemotePeer | remotePeer = null |
The remote peer; owner of the call. | |
boolean | callEstablished = false |
The flag that indicates that the call is established. | |
boolean | receivedFirstVoicePDU = false |
Used by onReceivedVoicePDU() to stop ringing. |
CallContext deals with all the packets that are part of a specific call.
The thing to remember is that a received message contains fields with the senders viewpoint so source is the far end and dest is us. in the reply the oposite is true: source is us and dest is them.
Definition at line 21 of file CallContext.java.
protocol.CallContext.CallContext | ( | RemotePeer | remotePeer, |
AudioInterface | audioInterface | ||
) |
The outbound constructor for Call.
We know nothing except where to send it.
Definition at line 53 of file CallContext.java.
References protocol.RemotePeer.addNewCall(), protocol.CallContext.audioInterface, and protocol.CallContext.remotePeer.
{ this.audioInterface = audioInterface; synchronized( remotePeer ) { this.remotePeer = remotePeer; this.remotePeer.addNewCall( this ); } }
synchronized ProtocolDataUnit protocol.CallContext.addIn | ( | ProtocolDataUnit | pdu ) |
Passed a newly arrived PDU.
If the PDU is the next one we are expecting, then put it in the buffer and adjust our expectations. Return it, so it can be acted upon. If it isn't the next expected then ignore it and return null (Warn).
Definition at line 270 of file CallContext.java.
References protocol.CallContext.getInSeqNo(), protocol.ProtocolDataUnit.outSeqNo, and protocol.CallContext.setInSeqNo().
{ ProtocolDataUnit ret = null; int where = pdu.outSeqNo; int expected = this.getInSeqNo (); if ( expected == where ) { setInSeqNo( ++where ); ret = pdu; } return ret; }
void protocol.CallContext.audioWrite | ( | byte[] | bs, |
long | timestamp | ||
) | throws IOException |
Writes audio data to the speaker.
bs | The incoming audio payload |
timestamp | The time-stamp |
IOException | Description of Exception |
Definition at line 177 of file CallContext.java.
References protocol.CallContext.audioInterface, and audio.AudioInterface.writeBuffered().
Referenced by protocol.CallContext.onReceivedVoicePDU().
{ if ( this.audioInterface != null ) { this.audioInterface.writeBuffered( bs, timestamp ); } }
void protocol.CallContext.cleanUp | ( | ) |
Cleans up and detaches call from peer.
Definition at line 285 of file CallContext.java.
References protocol.CallContext.audioInterface, protocol.CallContext.remotePeer, audio.AudioInterface.setAudioSender(), audio.AudioInterface.stopPlay(), and audio.AudioInterface.stopRecording().
Referenced by protocol.RemotePeer.cleanUp().
{ if ( this.audioInterface != null ) { this.audioInterface.setAudioSender( null ); this.audioInterface.stopPlay (); this.audioInterface.stopRecording (); } this.remotePeer = null; }
int protocol.CallContext.getAudioSampleSize | ( | ) |
Returns the audio interface sample size (used to determine size of the VoicePDU).
Definition at line 300 of file CallContext.java.
References protocol.CallContext.audioInterface, and audio.AudioInterface.getSampleSize().
Referenced by protocol.VoicePDU.onArrivedPDU().
{ if ( this.audioInterface != null ) { return this.audioInterface.getSampleSize (); } return 0; }
int protocol.CallContext.getDestinationCallNumber | ( | ) |
Returns the remote call number.
Together with the local call number, they uniquely identify the call between two parties.
On an outgoing call this represents 'Destination Call Number', and on an inbound call this represents 'Source Call Number'.
Definition at line 243 of file CallContext.java.
References protocol.CallContext.destinationCallNumber.
Referenced by protocol.ProtocolDataUnit.ProtocolDataUnit().
{ return this.destinationCallNumber & 0x7FFF; }
int protocol.CallContext.getInSeqNo | ( | ) |
Returns the inbound stream sequence number.
Definition at line 83 of file CallContext.java.
References protocol.CallContext.inSeqNo.
Referenced by protocol.CallContext.addIn(), and protocol.ProtocolDataUnit.sendPayload().
{ return this.inSeqNo; }
synchronized int protocol.CallContext.getOutSeqNo | ( | ) |
Returns the outbound stream sequence number, oSeqno.
Definition at line 75 of file CallContext.java.
References protocol.CallContext.outSeqNo.
{ return this.outSeqNo; }
synchronized int protocol.CallContext.getOutSeqNoInc | ( | ) |
Generates a new outbound stream sequence number.
Definition at line 67 of file CallContext.java.
References protocol.CallContext.outSeqNo.
Referenced by protocol.ProtocolDataUnit.sendPayload().
{ return ( this.outSeqNo++ ) & 0xFF; }
int protocol.CallContext.getSourceCallNumber | ( | ) |
Returns the local call number.
Together with the remote call number, they uniquely identify the call between two parties.
On an outgoing call this represents 'Source Call Number', and on an incoming call this represents 'Destination Call Number'.
Definition at line 222 of file CallContext.java.
References protocol.CallContext.sourceCallNumber.
Referenced by protocol.ProtocolDataUnit.ProtocolDataUnit().
{ return this.sourceCallNumber & 0x7FFF; }
long protocol.CallContext.getStartTimestamp | ( | ) |
Returns the start time-stamp of the call.
Definition at line 259 of file CallContext.java.
References protocol.CallContext.startTimestamp.
{ return this.startTimestamp; }
int protocol.CallContext.getTimestamp | ( | ) |
Returns the timestamp of this call.
This is the number of milliseconds since the call started.
Definition at line 112 of file CallContext.java.
References protocol.CallContext.startTimestamp.
Referenced by protocol.ProtocolDataUnit.log(), protocol.ProtocolDataUnit.ProtocolDataUnit(), and protocol.VoicePDUSender.VoicePDUSender().
{ long now = System.currentTimeMillis (); return (int) ( now - this.startTimestamp ); }
boolean protocol.CallContext.isEstablished | ( | ) |
Returns if this call has been callAnswered.
Definition at line 165 of file CallContext.java.
References protocol.CallContext.callEstablished.
{ return this.callEstablished; }
void protocol.CallContext.onReceivedVoicePDU | ( | long | timestamp, |
byte[] | audioSample | ||
) |
Notifies us that a Voice PDU has been received.
Definition at line 188 of file CallContext.java.
References protocol.CallContext.audioInterface, protocol.CallContext.audioWrite(), protocol.CallContext.receivedFirstVoicePDU, and audio.AudioInterface.stopRinging().
Referenced by protocol.VoicePDU.onArrivedPDU().
{ if ( ( this.audioInterface != null ) && ( ! this.receivedFirstVoicePDU ) ) { /* Stop ringing audio interface */ this.receivedFirstVoicePDU = true; this.audioInterface.stopRinging (); } /* write samples to audio interface */ try { audioWrite( audioSample, timestamp ); } catch( IOException e ) { Log.exception( Log.WARN, e ); } }
void protocol.CallContext.resetClock | ( | ) |
Resets the clock.
This method sets the start timestamp of a new call.
Definition at line 251 of file CallContext.java.
References protocol.CallContext.startTimestamp.
Referenced by protocol.RemotePeer.startReceiver().
{ this.startTimestamp = System.currentTimeMillis (); }
void protocol.CallContext.send | ( | OctetBuffer | pdu ) |
Sends a PDU to our peer.
pdu | The PDU (in bytes) |
Definition at line 101 of file CallContext.java.
References protocol.CallContext.remotePeer, and protocol.RemotePeer.send().
Referenced by protocol.ProtocolDataUnit.sendPayload().
{ if ( this.remotePeer != null ) { this.remotePeer.send( pdu ); } }
void protocol.CallContext.setCallEstablished | ( | boolean | established ) |
Sets if this call is established.
This can either be when we receive a ANSWER PDU from our peer to an outbound call, or when we answer an incoming call ourselves.
Definition at line 151 of file CallContext.java.
References protocol.CallContext.audioInterface, protocol.CallContext.callEstablished, protocol.CallContext.startAudioRecording(), and audio.AudioInterface.stopRinging().
Referenced by CryptoPhoneApp.acceptIncomingCall(), and CryptoPhoneApp.deferredOnAccept().
{ if ( ! this.callEstablished && established ) { this.audioInterface.stopRinging (); startAudioRecording (); } this.callEstablished = established; }
void protocol.CallContext.setDestinationCallNumber | ( | int | callNo ) |
Sets the remote call number as a character.
This bit of information comes in with received accept call.
Definition at line 231 of file CallContext.java.
References protocol.CallContext.destinationCallNumber.
Referenced by protocol.RemotePeer.addNewCall().
{ this.destinationCallNumber = callNo; }
void protocol.CallContext.setInSeqNo | ( | int | next ) |
Sets the inbound stream sequence number.
Definition at line 91 of file CallContext.java.
References protocol.CallContext.inSeqNo.
Referenced by protocol.CallContext.addIn().
{ this.inSeqNo = next % 256; }
void protocol.CallContext.setSourceCallNumber | ( | int | callNo ) |
Sets the local call number as a character.
Definition at line 210 of file CallContext.java.
References protocol.CallContext.sourceCallNumber.
Referenced by protocol.RemotePeer.addNewCall().
{ this.sourceCallNumber = callNo; }
void protocol.CallContext.startAudioRecording | ( | ) | [private] |
Starts sending our audio interface recording.
This method creates a new VoicePduSender object to do that.
Definition at line 122 of file CallContext.java.
References protocol.CallContext.audioInterface, audio.AudioInterface.setAudioSender(), and audio.AudioInterface.startRecording().
Referenced by protocol.CallContext.setCallEstablished().
{ if ( this.audioInterface == null ) { return; } VoicePDUSender voicePduSender = new VoicePDUSender( this.audioInterface, this ); this.audioInterface.setAudioSender( voicePduSender ); this.audioInterface.startRecording (); }
void protocol.CallContext.stopAudioRecording | ( | ) |
Stops sending audio.
Definition at line 137 of file CallContext.java.
References protocol.CallContext.audioInterface, and audio.AudioInterface.stopRecording().
{ if ( this.audioInterface == null ) { return; } this.audioInterface.stopRecording (); }
AudioInterface protocol.CallContext.audioInterface = null [package] |
The audio interface used to play/record for our voice PDUs.
Definition at line 42 of file CallContext.java.
Referenced by protocol.CallContext.audioWrite(), protocol.CallContext.CallContext(), protocol.CallContext.cleanUp(), protocol.CallContext.getAudioSampleSize(), protocol.CallContext.onReceivedVoicePDU(), protocol.CallContext.setCallEstablished(), protocol.CallContext.startAudioRecording(), and protocol.CallContext.stopAudioRecording().
boolean protocol.CallContext.callEstablished = false [private] |
The flag that indicates that the call is established.
Definition at line 45 of file CallContext.java.
Referenced by protocol.CallContext.isEstablished(), and protocol.CallContext.setCallEstablished().
int protocol.CallContext.destinationCallNumber = 0 [private] |
Represents the Destination Call Number in the PDU header.
Definition at line 27 of file CallContext.java.
Referenced by protocol.CallContext.getDestinationCallNumber(), and protocol.CallContext.setDestinationCallNumber().
int protocol.CallContext.inSeqNo = 0 [private] |
The inbound stream sequence number.
Definition at line 33 of file CallContext.java.
Referenced by protocol.CallContext.getInSeqNo(), and protocol.CallContext.setInSeqNo().
int protocol.CallContext.outSeqNo = 0 [private] |
The outbound stream sequence number.
Definition at line 30 of file CallContext.java.
Referenced by protocol.CallContext.getOutSeqNo(), and protocol.CallContext.getOutSeqNoInc().
boolean protocol.CallContext.receivedFirstVoicePDU = false [private] |
Used by onReceivedVoicePDU() to stop ringing.
Definition at line 48 of file CallContext.java.
Referenced by protocol.CallContext.onReceivedVoicePDU().
RemotePeer protocol.CallContext.remotePeer = null [private] |
The remote peer; owner of the call.
Definition at line 39 of file CallContext.java.
Referenced by protocol.CallContext.CallContext(), protocol.CallContext.cleanUp(), and protocol.CallContext.send().
int protocol.CallContext.sourceCallNumber = 1 [private] |
Represents the Source Call Number in the PDU header.
Definition at line 24 of file CallContext.java.
Referenced by protocol.CallContext.getSourceCallNumber(), and protocol.CallContext.setSourceCallNumber().
long protocol.CallContext.startTimestamp = 0 [private] |
The start time-stamp of the call.
Definition at line 36 of file CallContext.java.
Referenced by protocol.CallContext.getStartTimestamp(), protocol.CallContext.getTimestamp(), and protocol.CallContext.resetClock().