protocol
Class CallContext

java.lang.Object
  extended by protocol.CallContext

public class CallContext
extends java.lang.Object

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.

Author:
Mikica B Kocic

Field Summary
(package private)  AudioInterface audioInterface
          The audio interface used to play/record for our voice PDUs
private  boolean callEstablished
          The flag that indicates that the call is established
private  int destinationCallNumber
          Represents the Destination Call Number in the PDU header
private  int inSeqNo
          The inbound stream sequence number
private  int outSeqNo
          The outbound stream sequence number
private  boolean receivedFirstVoicePDU
          Used by onReceivedVoicePDU() to stop ringing
private  RemotePeer remotePeer
          The remote peer; owner of the call
private  int sourceCallNumber
          Represents the Source Call Number in the PDU header
private  long startTimestamp
          The start time-stamp of the call
 
Constructor Summary
CallContext(RemotePeer remotePeer, AudioInterface audioInterface)
          The outbound constructor for Call.
 
Method Summary
 ProtocolDataUnit addIn(ProtocolDataUnit pdu)
          Passed a newly arrived PDU.
 void audioWrite(byte[] bs, long timestamp)
          Writes audio data to the speaker.
 void cleanUp()
          Cleans up and detaches call from peer
 int getAudioSampleSize()
          Returns the audio interface sample size (used to determine size of the VoicePDU).
 int getDestinationCallNumber()
          Returns the remote call number.
 int getInSeqNo()
          Returns the inbound stream sequence number.
 int getOutSeqNo()
          Returns the outbound stream sequence number, oSeqno.
 int getOutSeqNoInc()
          Generates a new outbound stream sequence number.
 int getSourceCallNumber()
          Returns the local call number.
 long getStartTimestamp()
          Returns the start time-stamp of the call.
 int getTimestamp()
          Returns the timestamp of this call.
 boolean isEstablished()
          Returns if this call has been callAnswered.
 void onReceivedVoicePDU(long timestamp, byte[] audioSample)
          Notifies us that a Voice PDU has been received.
 void resetClock()
          Resets the clock.
 void send(OctetBuffer pdu)
          Sends a PDU to our peer.
 void setCallEstablished(boolean established)
          Sets if this call is established.
 void setDestinationCallNumber(int callNo)
          Sets the remote call number as a character.
 void setInSeqNo(int next)
          Sets the inbound stream sequence number.
 void setSourceCallNumber(int callNo)
          Sets the local call number as a character.
private  void startAudioRecording()
          Starts sending our audio interface recording.
 void stopAudioRecording()
          Stops sending audio
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceCallNumber

private int sourceCallNumber
Represents the Source Call Number in the PDU header


destinationCallNumber

private int destinationCallNumber
Represents the Destination Call Number in the PDU header


outSeqNo

private int outSeqNo
The outbound stream sequence number


inSeqNo

private int inSeqNo
The inbound stream sequence number


startTimestamp

private long startTimestamp
The start time-stamp of the call


remotePeer

private RemotePeer remotePeer
The remote peer; owner of the call


audioInterface

AudioInterface audioInterface
The audio interface used to play/record for our voice PDUs


callEstablished

private boolean callEstablished
The flag that indicates that the call is established


receivedFirstVoicePDU

private boolean receivedFirstVoicePDU
Used by onReceivedVoicePDU() to stop ringing

Constructor Detail

CallContext

public CallContext(RemotePeer remotePeer,
                   AudioInterface audioInterface)
The outbound constructor for Call. We know nothing except where to send it.

Method Detail

getOutSeqNoInc

public int getOutSeqNoInc()
Generates a new outbound stream sequence number.


getOutSeqNo

public int getOutSeqNo()
Returns the outbound stream sequence number, oSeqno.


getInSeqNo

public int getInSeqNo()
Returns the inbound stream sequence number.


setInSeqNo

public void setInSeqNo(int next)
Sets the inbound stream sequence number.


send

public void send(OctetBuffer pdu)
Sends a PDU to our peer.

Parameters:
pdu - The PDU (in bytes)

getTimestamp

public int getTimestamp()
Returns the timestamp of this call. This is the number of milliseconds since the call started.


startAudioRecording

private void startAudioRecording()
Starts sending our audio interface recording. This method creates a new VoicePduSender object to do that.


stopAudioRecording

public void stopAudioRecording()
Stops sending audio


setCallEstablished

public void 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.


isEstablished

public boolean isEstablished()
Returns if this call has been callAnswered.


audioWrite

public void audioWrite(byte[] bs,
                       long timestamp)
                throws java.io.IOException
Writes audio data to the speaker.

Parameters:
bs - The incoming audio payload
timestamp - The time-stamp
Throws:
java.io.IOException - Description of Exception

onReceivedVoicePDU

public void onReceivedVoicePDU(long timestamp,
                               byte[] audioSample)
Notifies us that a Voice PDU has been received.


setSourceCallNumber

public void setSourceCallNumber(int callNo)
Sets the local call number as a character.


getSourceCallNumber

public int 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'.


setDestinationCallNumber

public void setDestinationCallNumber(int callNo)
Sets the remote call number as a character. This bit of information comes in with received accept call.


getDestinationCallNumber

public int 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'.


resetClock

public void resetClock()
Resets the clock. This method sets the start timestamp of a new call.


getStartTimestamp

public long getStartTimestamp()
Returns the start time-stamp of the call.


addIn

public ProtocolDataUnit 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).


cleanUp

public void cleanUp()
Cleans up and detaches call from peer


getAudioSampleSize

public int getAudioSampleSize()
Returns the audio interface sample size (used to determine size of the VoicePDU).