00001 00002 package protocol; 00003 00004 /** 00005 * VoicePDU - The PDU that carries voice payload. 00006 * 00007 * @author Mikica B Kocic 00008 */ 00009 public class VoicePDU extends ProtocolDataUnit 00010 { 00011 /** 00012 * Voice PDU Subclass: 16-bit linear little-endian 00013 */ 00014 public final static int LIN16 = 0x01; 00015 00016 /** 00017 * Voice PDU Subclass: G.711 a-Law 00018 */ 00019 public final static int ALAW = 0x02; 00020 00021 /** 00022 * Voice PDU Subclass: G.711 u-Law 00023 */ 00024 public final static int ULAW = 0x03; 00025 00026 /** 00027 * The constructor for outbound Voice PDUs. 00028 */ 00029 public VoicePDU( CallContext c, int subClass ) 00030 { 00031 super( c ); 00032 this.pduType = ProtocolDataUnit.VOICE; 00033 this.pduSubclass = subClass; 00034 } 00035 00036 /** 00037 * The constructor for inbound Voice PDUs. 00038 */ 00039 public VoicePDU( CallContext c, byte[] pduOctets ) 00040 { 00041 super( c, pduOctets ); 00042 } 00043 00044 /** 00045 * Logs this frame. 00046 */ 00047 protected void log( String prefix ) 00048 { 00049 super.log( prefix + " voice frame" ); 00050 } 00051 00052 /** 00053 * Handles arrived PDUs: writes those to audio buffer. 00054 */ 00055 @Override 00056 void onArrivedPDU () 00057 { 00058 dump( "Inbound Voice" ); 00059 00060 int audioSampleSize = this.call.getAudioSampleSize (); 00061 00062 byte[] audioSample = new byte[ audioSampleSize ]; 00063 payload.get( audioSample ); 00064 00065 long ts = this.getTimestamp (); 00066 00067 if ( this.call != null ) { 00068 this.call.onReceivedVoicePDU( ts, audioSample ); 00069 } 00070 } 00071 }