00001 00002 package protocol; 00003 00004 import java.io.IOException; 00005 00006 import utils.Log; 00007 00008 import audio.AudioInterface; 00009 00010 /** 00011 * Takes captured audio and sends it to the remote peer via UDP channel 00012 * 00013 * @author Mikica B Kocic 00014 */ 00015 public class VoicePDUSender implements AudioInterface.Packetizer 00016 { 00017 private AudioInterface audio; 00018 private CallContext call; 00019 00020 private int voicePduSubclass; 00021 private byte[] audioBuffer; 00022 private long callStartTimestamp; 00023 private long nextDueTimestamp; 00024 private int timestamp; 00025 00026 /** 00027 * Constructor for the VoicePDUSender object 00028 * 00029 * @param audioInterface The audio interface 00030 * @param call The call object 00031 */ 00032 VoicePDUSender( AudioInterface audioInterface, CallContext call ) 00033 { 00034 this.audio = audioInterface; 00035 this.call = call; 00036 00037 this.voicePduSubclass = audioInterface.getVoicePduSubclass (); 00038 this.audioBuffer = new byte[ this.audio.getSampleSize () ]; 00039 00040 this.callStartTimestamp = this.call.getTimestamp (); 00041 this.nextDueTimestamp = this.callStartTimestamp; 00042 } 00043 00044 /** 00045 * Sends audio as payload encapsulated in VoicePDU 00046 */ 00047 public void send () throws IOException 00048 { 00049 this.audio.readWithTimestamp( this.audioBuffer ); 00050 this.timestamp = (int) this.nextDueTimestamp; 00051 00052 VoicePDU vf = new VoicePDU( this.call, this.voicePduSubclass ); 00053 vf.setTimestamp( this.timestamp ); 00054 vf.sendPayload( this.audioBuffer ); 00055 00056 vf.dump( "Outbound Voice" ); 00057 Log.audio( "Sent voice PDU" ); 00058 00059 /* Now work out how long to wait... 00060 */ 00061 this.nextDueTimestamp += 20; 00062 } 00063 00064 }