Android sip AudioCall中的rtp数据包为空

Android sip AudioCall中的rtp数据包为空,android,sip,rtp,phone-call,Android,Sip,Rtp,Phone Call,我正在用Android的本机库开发一款软电话(Android.net.sip和Android.net.rtp) 我的RTP数据包有问题。数据包正在发送,但它们是空的,则不接收音频 似乎SIP通信正在正确进行,因为邀请、铃声、尝试、再见。。。其他数据包正在发送,正常 import java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketExce

我正在用Android的本机库开发一款软电话(
Android.net.sip
Android.net.rtp

我的RTP数据包有问题。数据包正在发送,但它们是空的,则不接收音频

似乎SIP通信正在正确进行,因为邀请、铃声、尝试、再见。。。其他数据包正在发送,正常

import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.ParseException;
import java.util.Enumeration;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import es.app.packet.MainActivity;
import es.app.packet.R;
import es.app.packet.utils.Constants;
import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.rtp.AudioCodec;
import android.net.rtp.AudioGroup;
import android.net.rtp.RtpStream;
import android.net.rtp.AudioStream;
import android.net.sip.SipAudioCall;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipRegistrationListener;
import android.util.Log;
import android.widget.Toast;

public class SipUtil {

SharedPreferences prefs;

MainActivity mActivity;

//Para SIP
public String sipAddress = null;
public SipManager manager = null;
public SipProfile me = null;
public SipAudioCall mCall = null;

Toast toast;

String username;
String domain;
int conPort;
String password;

static SipUtil mSip;

AudioStream audioStream;
AudioGroup audioGroup;
AudioManager audio;
RtpStream rtpStream;

public SipUtil (MainActivity activity)
{
    manager = null;
    me = null;
    mCall = null;
    this.mActivity = activity;
    prefs = mActivity.getSharedPreferences(Constants.SHARE_PREFERENCES, Context.MODE_PRIVATE);
    mSip=this;

}

public void initializeManager() {
    if(manager == null) {
      manager = SipManager.newInstance(mActivity);
    }

    initializeLocalProfile();
}

public void initializeLocalProfile() {
    if (manager == null) {
        return;
    }

    if (me != null) {
        closeLocalProfile();
    }

    username = prefs.getString("user", "");
    domain = prefs.getString("domain", "XXX.XXX.XXX.XXX"); 
    conPort = prefs.getInt("conPort", 5060);
    password = prefs.getString("pass", "");

    try {
        SipProfile.Builder builder = new SipProfile.Builder(username, domain);
        builder.setPassword(password);
        me = builder.build();

        Intent i = new Intent();
        i.setAction("app.INCOMING_CALL");
        PendingIntent pi = PendingIntent.getBroadcast(mActivity, 0, i, Intent.FILL_IN_DATA);
        manager.open(me, pi, null);

        manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
                public void onRegistering(String localProfileUri) {
                    toast.setText(R.string.conectando);
                    toast.show();
                    Log.d("/SipUtil", "Conectando");
                }

                public void onRegistrationDone(String localProfileUri, long expiryTime) {
                    Log.d("/SipUtil", "Conectado!!");
                    toast.setText(R.string.conectado);
                    toast.show();
                }

                public void onRegistrationFailed(String localProfileUri, int errorCode,
                        String errorMessage) {
                    Log.d("/SipUtil", "Error Autenticacion: " + errorMessage);
                    toast.setText(R.string.error_autenticacion);
                    toast.show();
                }
            });
    } catch (ParseException pe) {
        toast.setText(R.string.error_conexion_SIP);
        toast.show();
    } catch (SipException se) {
        toast.setText(R.string.error_conexion_SIP);
        toast.show();
    }
}

public void destroySipUtil()
{
    if (mCall != null) {
        mCall.close();
    }

    closeLocalProfile();
}

public void closeLocalProfile() {
    if (manager == null) {
        return;
    }
    try {
        if (me != null) {
            manager.close(me.getUriString());
        }
    } catch (Exception ee) {
        Log.d("/onDestroy", "Failed to close local profile.", ee);
    }
}

public void initiateCall(String destino) 
{
    this.sipAddress = "sip:"+destino+"@"+domain;
    llamar();
}

public void colgar() {
    try {
        mCall.endCall();
        if(audioGroup != null) 
            audioGroup.clear();
        Log.d("/SipUtil", "Llamada finalizada en colgar");
    } catch (SipException e) {
        Log.d("/SipUtil", "Llamada MAL finalizada en colgar");
    }

}

private void llamar()
{
    try 
    {
        SipAudioCall.Listener listener = new SipAudioCall.Listener() {

            @Override
            public void onCallEstablished(SipAudioCall call) 
            {
                Log.d("/SipUtil", "onCallEstablished");
                mCall = call;

                try 
                {
                    byte ip[] = null;
                    try {
                        for (Enumeration<NetworkInterface> en = NetworkInterface
                                .getNetworkInterfaces(); en
                                .hasMoreElements();) {
                            NetworkInterface intf = en.nextElement();
                            for (Enumeration<InetAddress> enumIpAddr = intf
                                    .getInetAddresses(); enumIpAddr
                                    .hasMoreElements();) {
                                InetAddress inetAddress = enumIpAddr
                                        .nextElement();
                                if (!inetAddress.isLoopbackAddress()) {
                                    ip = inetAddress.getAddress();
                                }
                            }
                        }
                    } catch (SocketException ex) {
                        Log.i("SocketException ", ex.toString());
                    }

                    audio =  (AudioManager) mActivity.getSystemService(Context.AUDIO_SERVICE);
                    audio.setMode(AudioManager.MODE_IN_CALL);

                    audioGroup = new AudioGroup();
                    audioGroup.setMode(AudioGroup.MODE_NORMAL);

                    audioStream = new AudioStream(InetAddress.getByAddress(ip));
                    audioStream.setCodec(AudioCodec.GSM);
                    audioStream.setMode(RtpStream.MODE_NORMAL);

                    audioStream.associate(InetAddress.getByName(mCall.getPeerProfile().getSipDomain()), 
                            11234);

                    audioStream.join(audioGroup);

                    mCall.startAudio();
                    if (mCall.isMuted()) 
                    {
                        mCall.toggleMute();
                    }

                    Log.d("/SipUtil", "HABLANDO... "+mCall.getPeerProfile().getSipDomain());
                    Log.d("/SipUtil", "Codec");
                    } catch (SocketException e) {
                        toast.setText(R.string.error_codec);
                        Log.d("/SipUtil", "Error Codec");
                    } catch (IOException e) {
                        toast.setText(R.string.error_codec);
                        toast.show();
                        Log.d("/SipUtil", "Error Codec");
                    }

                }

                @Override
                public void onCallEnded(SipAudioCall call) {
                    mCall = call;
                    Log.d("/SipUtil", "onCallEnded");
                    try {
                        mCall.endCall();
                        colgar();
                        Log.d("/SipUtil", "Llamada finalizada");
                    } catch (SipException e) {
                            Log.d("/SipUtil", "Llamada MAL finalizada");
                    }
                }

                public void onChanged (SipAudioCall call){
                    Log.d("/SipUtil", "onChanged");
                    mCall = call;
                }

          };

          String origen = "sip:"+username+":"+password+"@"+domain;
          mCall = manager.makeAudioCall(origen, sipAddress, listener, 0); 

         }
         catch (Exception e) {
             Log.i("/InitiateCall", "Error intentando cerrar manager.", e);
             if (me != null) {
                 try {
                     manager.close(me.getUriString());
                 } catch (Exception ee) {
                     Log.i("/InitiateCall",
                             "Error when trying to close manager.", ee);
                 }
             }
             if (mCall != null) {
                 mCall.close();
             }
         }
    }
}
import java.io.IOException;
导入java.net.InetAddress;
导入java.net.NetworkInterface;
导入java.net.SocketException;
导入java.text.ParseException;
导入java.util.Enumeration;
导入android.media.AudioManager;
导入android.media.MediaPlayer;
导入android.media.SoundPool;
导入es.app.packet.main活动;
导入es.app.packet.R;
导入es.app.packet.utils.Constants;
导入android.annotation.SuppressLint;
导入android.app.pendingent;
导入android.content.Context;
导入android.content.Intent;
导入android.content.SharedReferences;
导入android.net.rtp.AudioCodec;
导入android.net.rtp.AudioGroup;
导入android.net.rtp.RtpStream;
导入android.net.rtp.AudioStream;
导入android.net.sip.SipAudioCall;
导入android.net.sip.SipException;
导入android.net.sip.SipManager;
导入android.net.sip.SipProfile;
导入android.net.sip.SipRegistrationListener;
导入android.util.Log;
导入android.widget.Toast;
公共类SipUtil{
共享引用优先权;
主要活动能力;
//帕拉西普
公共字符串sipAddress=null;
公共SipManager=null;
公共SipProfile me=null;
公共SipAudioCall mCall=null;
吐司;
字符串用户名;
字符串域;
国际康波特;
字符串密码;
静态SipUtil-mSip;
音频流;
听力组;听力组;
音频管理器音频;
rtp流rtp流;
公共SipUtil(主要活动)
{
manager=null;
me=null;
mCall=null;
这个。活动=活动;
prefs=mActivity.getSharedReferences(Constants.SHARE\u首选项,Context.MODE\u PRIVATE);
mSip=这个;
}
公共无效初始值设定项管理器(){
if(manager==null){
manager=SipManager.newInstance(mActivity);
}
初始化ELOCALPROFILE();
}
public void initializeLocalProfile(){
if(manager==null){
返回;
}
如果(me!=null){
closeLocalProfile();
}
username=prefs.getString(“用户”,“用户”);
domain=prefs.getString(“domain”、“XXX.XXX.XXX.XXX”);
conPort=prefs.getInt(“conPort”,5060);
password=prefs.getString(“pass”、“”);
试一试{
SipProfile.Builder=新的SipProfile.Builder(用户名,域);
builder.setPassword(密码);
me=builder.build();
意图i=新意图();
i、 设置动作(“应用程序来电”);
PendingEvent pi=PendingEvent.getBroadcast(mActivity,0,i,Intent.FILL_IN_数据);
manager.open(me、pi、null);
manager.setRegistrationListener(me.getUriString(),新SipRegistrationListener()){
注册时的公共void(字符串localProfileUri){
toast.setText(R.string.conectando);
toast.show();
Log.d(“/SipUtil”,“Conectando”);
}
public void onRegistrationDone(字符串localProfileUri,长过期时间){
Log.d(“/SipUtil”,“Conectado!!”);
toast.setText(R.string.conectado);
toast.show();
}
public void onRegistrationFailed(字符串localProfileUri,int errorCode,
字符串错误消息){
Log.d(“/SipUtil”,“Error autentication:”+errorMessage);
toast.setText(R.string.error\u autentication);
toast.show();
}
});
}捕获(解析异常pe){
toast.setText(R.string.error\u conexion\u SIP);
toast.show();
}捕获(SIPSE){
toast.setText(R.string.error\u conexion\u SIP);
toast.show();
}
}
public void destructionsiputil()
{
如果(mCall!=null){
mCall.close();
}
closeLocalProfile();
}
public void closeLocalProfile(){
if(manager==null){
返回;
}
试一试{
如果(me!=null){
manager.close(me.getUriString());
}
}捕获(异常ee){
Log.d(“/ondestory”,“无法关闭本地配置文件”,ee);
}
}
public void initiateCall(字符串destino)
{
this.sipAddress=“sip:”+destino+“@”+域;
llamar();
}
公开无效colgar(){
试一试{
mCall.endCall();
如果(音频组!=null)
audioGroup.clear();
Log.d(“/SipUtil”,“Llamada finalizada en colgar”);
}捕获(SIPE例外){
Log.d(“/SipUtil”,“Llamada MAL”和“lamada en colgar”);
}
}
私人图书馆
{
尝试
{
SipAudioCall.Listener侦听器=新的SipAudioCall.Listener(){
@凌驾
一旦建立公共无效(SipAudioCall)
{
Log.d(“/SipUtil”,“一旦建立”);
mCall=呼叫;
尝试
{
字节ip[]=null;
试一试{
对于(枚举en=网络接口
.getNetworkInterfaces();en
.hasMoreElements();){
NetworkInterface intf=en.nextElement();
对于(枚举枚举enumIpAddr=intf
.getInetAddresses();EnumIPAddress
.hasMoreElements();){
InetAddress InetAddress=EnumipAddress
.nextElement();
如果(!inetAddress.isLoopbackAddress()){
ip=inetAddress.getAddress();
}
}
}