如何使用JAIN SIP库接受传入的音频SIP呼叫?

时间:2018-08-06 15:35:25

标签: android sip jain-sip

这是我第一次使用JAIN SIP进行创建。我已经使用JAIN SIP创建了Android SIP客户端。我能够收到来电通知并接收它,但无法使音频流正常工作。我想问题可能出在为音频流定义会话描述协议(SDP)的方式上。

下面是我的acceptCall方法:

public void acceptCall() throws IllegalStateException {
    soundManager.setupAudioStream();
    Request request = incomingRequest.getRequest();
    remoteIP = SDPBuilder.getRemoteIP(incomingRequest.getRequest());
    try {
        Response response = messageFactory.createResponse(Response.OK, request);
        response.addHeader(localContactHeader);
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "sdp");
        response.setContent(getSDPData().getBytes(), contentTypeHeader);
        SipResponder responder = new SipResponder(sipProvider, incomingRequest, currentServerTransaction);
        responder.execute(response);
    } catch (Exception e) {
        if (BuildConfig.DEBUG) e.printStackTrace();
        direction = CallDirection.NONE;
        notifySessionFailed("couldn't establish call");
    }
}

这是我的返回SDP数据的方法:

private String getSDPData()
{

    return "v=0\r\n"
            + "o=4855 13760799956958020 13760799956958020"
            + " IN IP4 " + localIP + "\r\n"
            + "s=mysession session\r\n"
            + "c=IN IP4 "
            + localIP + "\r\n" + "t=0 0\r\n"
            + "m=audio " + String.valueOf(port)
            + " RTP/AVP 0 4 18\r\n"
            + "a=rtpmap:0 PCMU/8000\r\n"
            + "a=rtpmap:4 G723/8000\r\n"
            + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
}

最后我的SIP响应程序类:

public class SipResponder extends AsyncTask<Response, String, ServerTransaction> {
private static final String TAG = "BACKGROUND";
private SipProvider sipProvider;
private RequestEvent requestEvent;
private ServerTransaction transaction;

public SipResponder(SipProvider provider, RequestEvent event, ServerTransaction transaction) {
    sipProvider = provider;
    requestEvent = event;
    this.transaction = transaction;
}

@Override
protected ServerTransaction doInBackground(Response... responses) {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

    Request request = requestEvent.getRequest();
    Response response = responses[0];

    try {
        if (transaction == null)
            transaction = requestEvent.getServerTransaction();
        if (transaction == null) {
            transaction = sipProvider.getNewServerTransaction(request);
        }
        transaction.sendResponse(response);

        return transaction;
    } catch (TransactionAlreadyExistsException e) {
        Log.e(TAG, "that race condition. UGH");
        e.printStackTrace();
        return null;
    } catch (Exception e) {
        Log.e(TAG, "the response failed. UGH");
        e.printStackTrace();
        return null;
    }
}}

这已经有一段时间了。请帮助。

0 个答案:

没有答案