Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afa583e6 authored by Hung-ying Tyan's avatar Hung-ying Tyan
Browse files

SipAudioCall: expose startAudio()

so that apps can start audio when time is right.

Change-Id: I7ae96689d3a8006b34097533bc2434bc3814b82a
parent ecd43cca
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -626,6 +626,7 @@ public class SipPhone extends SipPhoneBase {
                    if (newState == Call.State.INCOMING) {
                        setState(mOwner.getState()); // INCOMING or WAITING
                    } else {
                        if (newState == Call.State.ACTIVE) call.startAudio();
                        setState(newState);
                    }
                    mOwner.onConnectionStateChanged(SipConnection.this);
+7 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public interface SipAudioCall {
    void setListener(Listener listener, boolean callbackImmediately);

    /**
     * Closes this object. The object is not usable after being closed.
     * Closes this object. This object is not usable after being closed.
     */
    void close();

@@ -171,6 +171,12 @@ public interface SipAudioCall {
    void makeCall(SipProfile callee, SipManager sipManager, int timeout)
            throws SipException;

    /**
     * Starts the audio for the established call. This method should be called
     * after {@link Listener#onCallEstablished} is called.
     */
    void startAudio();

    /**
     * Attaches an incoming call to this call object.
     *
+65 −60
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.util.Log;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -239,24 +240,18 @@ public class SipAudioCallImpl extends SipSessionAdapter
        }
    }

    private synchronized void establishCall(String sessionDescription) {
    @Override
    public void onCallEstablished(ISipSession session,
            String sessionDescription) {
        stopRingbackTone();
        stopRinging();
        try {
            SdpSessionDescription sd =
                    new SdpSessionDescription(sessionDescription);
            Log.d(TAG, "sip call established: " + sd);
            startCall(sd);
            mInCall = true;
            mPeerSd = new SdpSessionDescription(sessionDescription);
            Log.d(TAG, "sip call established: " + mPeerSd);
        } catch (SdpException e) {
            Log.e(TAG, "createSessionDescription()", e);
        }
    }

    @Override
    public void onCallEstablished(ISipSession session,
            String sessionDescription) {
        establishCall(sessionDescription);
        Listener listener = mListener;
        if (listener != null) {
            try {
@@ -609,10 +604,23 @@ public class SipAudioCallImpl extends SipSessionAdapter
        return copies;
    }

    private void startCall(SdpSessionDescription peerSd) {
    public void startAudio() {
        try {
            startAudioInternal();
        } catch (UnknownHostException e) {
            onError(mSipSession, SipErrorCode.PEER_NOT_REACHABLE.toString(),
                    e.getMessage());
        } catch (Throwable e) {
            onError(mSipSession, SipErrorCode.CLIENT_ERROR.toString(),
                    e.getMessage());
        }
    }

    private synchronized void startAudioInternal() throws UnknownHostException {
        stopCall(DONT_RELEASE_SOCKET);
        mInCall = true;
        SdpSessionDescription peerSd = mPeerSd;
        if (isWifiOn()) grabWifiHighPerfLock();
        mPeerSd = peerSd;
        String peerMediaAddress = peerSd.getPeerMediaAddress(AUDIO);
        // TODO: handle multiple media fields
        int peerMediaPort = peerSd.getPeerMediaPort(AUDIO);
@@ -621,7 +629,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
        int localPort = getLocalMediaPort();
        int sampleRate = 8000;
        int frameSize = sampleRate / 50; // 160
        try {

        // TODO: get sample rate from sdp
        mCodec = getCodec(peerSd);

@@ -671,9 +679,6 @@ public class SipAudioCallImpl extends SipSessionAdapter
                audioGroup.setMode(AudioGroup.MODE_NORMAL);
            }
        }
        } catch (Exception e) {
            Log.e(TAG, "call()", e);
        }
    }

    private void stopCall(boolean releaseSocket) {