当拨出电话转发到其他地方时,PJSUA2 android中没有音频

时间:2016-10-07 09:33:24

标签: android sip pjsip pjsua2

我遇到了问题。 我是PJSIP的新手。我在android中使用PJSUA2开发了一个SIP客户端。现在一切正常,除非我正在拨打一个正在转发到其他地方的电话,然后我从两端都没有收到任何音频。 知道我做错了什么吗?

这是正在处理电话的地方

public class MyCall extends Call{

public static AudioMedia audioMedia;
public static AudDevManager mgr;
public Endpoint ep;

public MyCall(Account acc, int call_id,Endpoint ep)
{
   // call_id=
    super(acc,call_id);
    this.ep=ep;
}

// Notification when call's state has changed.
@Override
public void onCallState(OnCallStateParam prm) {
    System.out.println("Message : "+prm.getE().getBody().getRxMsg().getRdata().getWholeMsg());
}

//test
@Override
public void onCallTransferRequest (OnCallTransferRequestParam prm)
{
    System.out.println("Hello transferring");
}

@Override
public pjsip_redirect_op onCallRedirected (OnCallRedirectedParam prm)
{
    System.out.println("Redirecting.......wait");
    return null;
}

// Notification when call's media state has changed.
@Override
public void onCallMediaState(OnCallMediaStateParam prm){

    CallInfo info;
    //Call currentCall=CurrentCall.call;
    Call currentCall=this;

    try {
        info = getInfo();


        for (int i = 0; i < info.getMedia().size(); i++) {

            Media media = getMedia(i);
            CallMediaInfo mediaInfo = info.getMedia().get(i);


            if (mediaInfo.getType() == pjmedia_type.PJMEDIA_TYPE_AUDIO && media != null && mediaInfo.getStatus() == pjsua_call_media_status.PJSUA_CALL_MEDIA_ACTIVE){

            audioMedia = AudioMedia.typecastFromMedia(media);
            audioMedia.adjustRxLevel(1.5f);
            audioMedia.adjustTxLevel((float) 1.5);


            try {
                    System.out.println("Audio should start now");

                //making a handler for ui thread to show the thread
                Handler mainHandler = new Handler(CallActivity.ca.getMainLooper());

                Runnable myRunnable = new Runnable() {
                    @Override
                    public void run() {
                        CallActivity.tv.setText("Call Started");
                    } // This is your code
                };

                mainHandler.post(myRunnable);

                mgr = ep.audDevManager();


                audioMedia.startTransmit(mgr.getPlaybackDevMedia());
                mgr.getCaptureDevMedia().startTransmit(audioMedia);

                } catch (Exception exc) {
                    System.out.println("Exception in audio related : "+exc);
                }
            }
        }


    } catch (Exception e) {
        System.out.println("Exception caught while getting call info."+ e.toString());
        return;
    }

}

}

这是配置完成的地方

public void test()
{
    //stored phoneno and pwd

            SharedPreferences sp = getSharedPreferences("skytel_skysip", Context.MODE_PRIVATE);
            String uname = sp.getString("e164", "");
            String pwd = sp.getString("pwd", "");

            Globals.uname=uname;
            Globals.pwd=pwd;

            //------------------------------------------------------------
            try {
                // Create endpoint
             ep = new Endpoint();
             ep.libCreate();
             // Initialize endpoint
             EpConfig epConfig = new EpConfig();
             ep.libInit(epConfig);
             // Create SIP transport. Error handling sample is shown
             System.out.println("Configuration started");

             TransportConfig sipTpConfig = new TransportConfig();
             sipTpConfig.setPort(5061);
             ep.transportCreate(pjsip_transport_type_e.PJSIP_TRANSPORT_UDP, sipTpConfig);


                //printing the list of codecs
             /*for(int i=0;i<ep.codecEnum().size();i++)
                System.out.println("Codec Name : "+ep.codecEnum().get(i).getCodecId()+"\n");*/

             // Start the library
             ep.libStart();

             EpOperation.setEp(ep);

             System.out.println("Configuration ended");
             System.out.println("Username : "+uname);
             System.out.println("Password : "+pwd);

             AccountConfig acfg = new AccountConfig();
             acfg.setIdUri("sip:" + uname + "@xx.xxx.xxx.xx");

             acfg.getRegConfig().setRegistrarUri("sip:xx.xxx.xxx.xx");

             AuthCredInfo cred = new AuthCredInfo("digest", "*", uname, 0, pwd);
             acfg.getSipConfig().getAuthCreds().add(cred);
             // Create the account
             MyAccount acc = new MyAccount();
             acc.create(acfg);

             EpOperation.setAccountConfig(acfg);
             // Here we don't have anything else to do..
             while(Globals.flag==0) {
                 System.out.println("Flag : "+Globals.flag);
                 Thread.sleep(5000);
             }
             Globals.flag=0;

             Call call = new MyCall(acc, 1,ep);

             //override event handlers
             CurrentCall.call = call;


            } catch (Exception e) {
                System.out.println("This is exception : " + e);
                return;
            }
}

按钮单击

callbtn.setOnClickListener(new View.OnClickListener() {

     @Override
     public void onClick(View view) {
         //number
         String num = number.getText().toString();

         callbtn.setText("Registering.Wait...");
         Toast.makeText(ma, "Configuring.Please Wait...", Toast.LENGTH_LONG).show();
         //stored phoneno and pwd
         SharedPreferences sp = getSharedPreferences("skytel_skysip", Context.MODE_PRIVATE);
         String uname = sp.getString("e164", "");
         String pwd = sp.getString("pwd", "");

         Globals.uname=uname;
         Globals.pwd=pwd;

         //------------------------------------------------------------
         try {

             Intent i=new Intent(view.getContext(),CallActivity.class);
             startActivityForResult(i,0);

             test();
             CallOpParam prm = new CallOpParam(true);
             CurrentCall.call.makeCall("sip:" + num + "@80.241.208.191", prm);
             //CurrentCall.call.makeCall("sip:" + num + "@80.241.208.11", prm);
             System.out.println("Call made");

             callbtn.setText("CALL");


         } catch (Exception e) {
             System.out.println("This is exception : " + e);
             return;
         }
     }   });

0 个答案:

没有答案