cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
890
Views
0
Helpful
2
Replies

NO SOUND

mouradkaroui
Beginner
Beginner

Hi,

I'm new with JTAPI and i need to place a call betwenn my computer "2100" and a cisco phone "2010", i did that (the cisco phone display "call from 2100") , but the problem is where i pick up i can't hear anything.

please i really really need help, i can't find any solution and i'm loosing a lot of time

thank you

and here's my code :

THE MAKECALL CLASS :

import java.net.*;

import javax.telephony.*;

import javax.telephony.events.*;

import com.cisco.cti.util.Condition;

import com.cisco.jtapi.extensions.*;

import java.util.concurrent.TimeUnit;

import javax.media.*;

import javax.telephony.callcontrol.*;

import javax.telephony.callcontrol.events.*;

import javax.telephony.media.MediaCallObserver;

import javax.telephony.media.events.MediaTermConnDtmfEv;

public class MakeCalll  {

final int PORT_NUMBER = 1234;

DatagramSocket socket =new DatagramSocket();

   public MakeCalll(String[] args) throws Exception {

            CListener listener = new CListener();

            final Condition          inService = new Condition();

String hostname = "10.10.10.1";

String login = "mourad";

String passwd = "mourad";

String src = "2100";

String dst = "2010";

                     /* start up JTAPI */

JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);

                     /* connect to the provider */

String providerString = hostname;

providerString += ";login=" + login;

providerString += ";passwd=" + passwd;

Provider provider =  peer.getProvider(providerString);

                  provider.addObserver(listener);

/* wait for it to come into service */

inService.set();

inService.waitTrue();

/* get an object for the calling terminal */

Address srcAddr = (CiscoAddress) provider.getAddress("src");

               Terminal srcTerm = srcAddr.getTerminals()[0];

if (srcAddr==null)

                throw new Exception("Address not found");

            System.out.println("Address: "+srcAddr.toString()+", class: "+srcAddr.getClass().getName());

dstAddr.addObserver(listener);

/*register terminal*/

                    System.out.println("register terminal");

     CiscoMediaTerminal terminal =  (CiscoMediaTerminal) srcAddr.getTerminals()[0];

      if (terminal==null)

                throw new Exception("Terminal not found");

            System.out.println("Found terminal: "+terminal.toString());

      CiscoMediaCapability[] caps =

                    new CiscoMediaCapability[]{CiscoMediaCapability.G711_64K_30_MILLISECONDS};

      terminal.register(InetAddress.getLocalHost(), 1234, caps);

     Address address = terminal.getAddresses()[0];

     if (address==null)

                throw new Exception("Address not found");

            System.out.println("Address: "+address.toString());

  terminal.addObserver(listener);

                srcAddr.addCallObserver(listener);

   

                   srcAddr.addCallObserver(new CallObserver() {

public void callChangedEvent (CallEv [] eventList) {

                /* ignored */

      }

    });

               Call  call =  (CiscoCall) provider.createCall();

                 

                 System.out.println("make the call");

                call.connect(srcTerm, srcAddr, dst);

             terminal.addObserver(new TerminalObserver(){

                 public void terminalChangedEvent(TermEv[] termevs){

                 }

             });

}

public static void main(String[] args) {

try { 

                      new MakeCalll(args);

            } catch (Exception e) {

       e.printStackTrace();

      } finally {

         System.exit(0);

}

}

    private class CListener implements

            ControllerListener, ProviderObserver, CiscoTerminalObserver, CallControlCallObserver,

            MediaCallObserver, AddressObserver

    {

        private RTPSender conversation;

        private CallControlCall call;

        public void controllerUpdate(ControllerEvent event)

        {

            System.out.println("Controller event: "+event.toString());

        }

        public void providerChangedEvent(ProvEv[] events)

        {

            System.out.println("Provider events: "+eventsToString(events));

        }

        public void terminalChangedEvent(TermEv[] events)

        {

            System.out.println("Terminal events: "+eventsToString(events));

            for (TermEv event: events)

            {

                if (event instanceof CiscoRTPOutputStartedEv)

                {

                    try {

                        CiscoRTPOutputStartedEv rtpOutput = (CiscoRTPOutputStartedEv) event;

                        CiscoRTPOutputProperties props = rtpOutput.getRTPOutputProperties();

                        if (conversation==null){

                            conversation = new RTPSender

                                    (props.getRemoteAddress(), props.getRemotePort(),socket);

                        }

                        conversation.setDaemon(true);

                        conversation.run();

                    } catch (Exception ex) {

                        System.out.println("Error streaming");

                        ex.printStackTrace();

                    }

                }

                if (event instanceof CiscoRTPInputStartedEv)

                {

                    CiscoRTPInputStartedEv rtpInput = (CiscoRTPInputStartedEv) event;

                    System.out.println("streaming audio to url: "+rtpInput.getCiscoRTPHandle());

                }

            }

        }

        public void callChangedEvent(CallEv[] events)

        {

            System.out.println("Address call events: "+eventsToString(events));

            for (CallEv event: events)

                if (event instanceof CallCtlConnOfferedEv)

                {

                    CallCtlConnOfferedEv offEvent = (CallCtlConnOfferedEv)event;

                    CallControlConnection conn = (CallControlConnection) offEvent.getConnection();

                    try {

                        conn.accept();

                        call = (CallControlCall) event.getCall();

                        System.out.println("Connection accepted");

                    } catch (Exception ex) {

                        System.out.println("Error accepting call");

                        ex.printStackTrace();

                    }

                }

                else if (event instanceof TermConnRingingEv)

                {

                    try{

                        ((TermConnRingingEv)event).getTerminalConnection().answer();

                    }catch (Exception e)

                    {

                        System.out.println("Error answer on call");

                        e.printStackTrace();

                    }

                }

                else if (event instanceof CallCtlConnEstablishedEv)

                {

                    if (conversation!=null)

                        conversation.start();

                }

                else if (event instanceof MediaTermConnDtmfEv)

                {

                    System.out.println("DTMF: "+((MediaTermConnDtmfEv)event).getDtmfDigit());

                }

        }

        public void addressChangedEvent(AddrEv[] events)

        {

            System.out.println("Address events: "+eventsToString(events));

        }

        private String eventsToString(Object[] events)

        {

            StringBuilder buf = new StringBuilder();

            for (Object ev: events)

                buf.append(ev.toString()+", ");

            return buf.toString();

        }

    }  

}

AND THE RTPSENDER CLASS:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;

import java.nio.MappedByteBuffer;

import java.nio.channels.FileChannel.MapMode;

import java.util.Random;

public class RTPSender extends Thread implements Runnable {

InetAddress farEndAddr;

int farEndPort;

DatagramSocket sock;

public RTPSender(InetAddress addr, int port, DatagramSocket socket){

farEndAddr = addr;

farEndPort = port;

sock = socket;

}

@Override

public void run() {

            System.out.println("run");

MappedByteBuffer fileContent = null;

             try

{

                         File file = new File ("telsonne.wav");

                        FileInputStream fin = new FileInputStream(file);

                        fileContent = fin.getChannel().map(MapMode.READ_ONLY, 0, file.length());

}catch (FileNotFoundException e) { 

            System.out.println("file not found : " + e.getMessage()); 

        } 

        catch (IOException eio) { 

            System.out.println("io exception " + eio.getMessage()); 

        } 

byte [] buf = new byte[172];

buf[0] = (byte)0x80; //V=2 P(padding)=0 X(extension fields)=0 CC(CSRC count)=0

buf[1] = (byte)0; //M(marker)=0 Payload type = 0 (PCM ULaw)

Random random_generator = new Random();

int sequence_number = random_generator.nextInt(65536);

long timestamp = 1;

int sync_source = random_generator.nextInt();

buf[8] = (byte)(sync_source/16777216);

buf[9] = (byte)((sync_source/65536)%256);

buf[10] = (byte)((sync_source/256)%256);

buf[11] = (byte)(sync_source%256);

                long curTime1 = System.currentTimeMillis();

long curTime2 = System.currentTimeMillis();

                System.out.println(curTime2);

while (true)

try

{      

                        buf[2] = (byte)(sequence_number/256);

buf[3] = (byte)(sequence_number%256);

buf[4] = (byte)(timestamp/16777216);

buf[5] = (byte)((timestamp/65536)%256);

buf[6] = (byte)((timestamp/256)%256);

buf[7] = (byte)(timestamp%256);

DatagramPacket packet = new DatagramPacket(buf, 172, farEndAddr, farEndPort);

                        sock.send(packet);

                        long ms2Sleep = curTime2 + 20 - System.currentTimeMillis();

                        curTime2 += 20;

System.out.println("Current Time:"+curTime2+" to sleep:"+ms2Sleep+" ms...");

if (ms2Sleep > 0)

Thread.sleep(ms2Sleep);

sequence_number = (sequence_number+1)&0xFFFF;

                        timestamp=(timestamp+160)&0xFFFFFFFF;

                        }

catch (Exception e){

System.out.println("Exception:"+e);

return;

}

}

}

2 Replies 2

paolo bevilacqua
Hall of Fame Master Hall of Fame Master
Hall of Fame Master

Wrong forum, try developer.cisco.com.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers