summaryrefslogtreecommitdiffstats
path: root/voip/java/android/net/sip/SipAudioCall.java
blob: abdc9d75ade6047954f52d88352616095b2277a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.sip;

import android.net.rtp.AudioGroup;
import android.net.rtp.AudioStream;
import android.os.Message;

import javax.sip.SipException;

/**
 * Interface for making audio calls over SIP.
 * @hide
 */
public interface SipAudioCall {
    /** Listener class for all event callbacks. */
    public interface Listener {
        /**
         * Called when the call object is ready to make another call.
         *
         * @param call the call object that is ready to make another call
         */
        void onReadyToCall(SipAudioCall call);

        /**
         * Called when a request is sent out to initiate a new call.
         *
         * @param call the call object that carries out the audio call
         */
        void onCalling(SipAudioCall call);

        /**
         * Called when a new call comes in.
         *
         * @param call the call object that carries out the audio call
         * @param caller the SIP profile of the caller
         */
        void onRinging(SipAudioCall call, SipProfile caller);

        /**
         * Called when a RINGING response is received for the INVITE request sent
         *
         * @param call the call object that carries out the audio call
         */
        void onRingingBack(SipAudioCall call);

        /**
         * Called when the session is established.
         *
         * @param call the call object that carries out the audio call
         */
        void onCallEstablished(SipAudioCall call);

        /**
         * Called when the session is terminated.
         *
         * @param call the call object that carries out the audio call
         */
        void onCallEnded(SipAudioCall call);

        /**
         * Called when the peer is busy during session initialization.
         *
         * @param call the call object that carries out the audio call
         */
        void onCallBusy(SipAudioCall call);

        /**
         * Called when the call is on hold.
         *
         * @param call the call object that carries out the audio call
         */
        void onCallHeld(SipAudioCall call);

        /**
         * Called when an error occurs.
         *
         * @param call the call object that carries out the audio call
         * @param errorMessage error message
         */
        void onError(SipAudioCall call, String errorMessage);
    }

    /**
     * The adapter class for {@link SipAudioCall#Listener}. The default
     * implementation of all callback methods is no-op.
     */
    public class Adapter implements Listener {
        protected void onChanged(SipAudioCall call) {
        }
        public void onReadyToCall(SipAudioCall call) {
            onChanged(call);
        }
        public void onCalling(SipAudioCall call) {
            onChanged(call);
        }
        public void onRinging(SipAudioCall call, SipProfile caller) {
            onChanged(call);
        }
        public void onRingingBack(SipAudioCall call) {
            onChanged(call);
        }
        public void onCallEstablished(SipAudioCall call) {
            onChanged(call);
        }
        public void onCallEnded(SipAudioCall call) {
            onChanged(call);
        }
        public void onCallBusy(SipAudioCall call) {
            onChanged(call);
        }
        public void onCallHeld(SipAudioCall call) {
            onChanged(call);
        }
        public void onError(SipAudioCall call, String errorMessage) {
            onChanged(call);
        }
    }

    /**
     * Sets the listener to listen to the audio call events. The method calls
     * {@link #setListener(Listener, false)}.
     *
     * @param listener to listen to the audio call events of this object
     * @see #setListener(Listener, boolean)
     */
    void setListener(Listener listener);

    /**
     * Sets the listener to listen to the audio call events. A
     * {@link SipAudioCall} can only hold one listener at a time. Subsequent
     * calls to this method override the previous listener.
     *
     * @param listener to listen to the audio call events of this object
     * @param callbackImmediately set to true if the caller wants to be called
     *      back immediately on the current state
     */
    void setListener(Listener listener, boolean callbackImmediately);

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

    /**
     * Initiates an audio call to the specified profile.
     *
     * @param callee the SIP profile to make the call to
     * @param sipManager the {@link SipManager} object to help make call with
     */
    void makeCall(SipProfile callee, SipManager sipManager) throws SipException;

    /**
     * Attaches an incoming call to this call object.
     *
     * @param session the session that receives the incoming call
     * @param sdp the session description of the incoming call
     */
    void attachCall(ISipSession session, SdpSessionDescription sdp)
            throws SipException;

    /** Ends a call. */
    void endCall() throws SipException;

    /**
     * Puts a call on hold.  When succeeds,
     * {@link #Listener#onCallHeld(SipAudioCall)} is called.
     */
    void holdCall() throws SipException;

    /** Answers a call. */
    void answerCall() throws SipException;

    /**
     * Continues a call that's on hold. When succeeds,
     * {@link #Listener#onCallEstablished(SipAudioCall)} is called.
     */
    void continueCall() throws SipException;

    /** Puts the device to in-call mode. */
    void setInCallMode();

    /** Puts the device to speaker mode. */
    void setSpeakerMode();

    /** Toggles mute. */
    void toggleMute();

    /**
     * Checks if the call is on hold.
     *
     * @return true if the call is on hold
     */
    boolean isOnHold();

    /**
     * Checks if the call is muted.
     *
     * @return true if the call is muted
     */
    boolean isMuted();

    /**
     * Sends a DTMF code.
     *
     * @param code the DTMF code to send
     */
    void sendDtmf(int code);

    /**
     * Sends a DTMF code.
     *
     * @param code the DTMF code to send
     * @param result the result message to send when done
     */
    void sendDtmf(int code, Message result);

    /**
     * Gets the {@link AudioStream} object used in this call. The object
     * represents the RTP stream that carries the audio data to and from the
     * peer. The object may not be created before the call is established. And
     * it is undefined after the call ends or the {@link #close} method is
     * called.
     *
     * @return the {@link AudioStream} object or null if the RTP stream has not
     *      yet been set up
     */
    AudioStream getAudioStream();

    /**
     * Gets the {@link AudioGroup} object which the {@link AudioStream} object
     * joins. The group object may not exist before the call is established.
     * Also, the {@code AudioStream} may change its group during a call (e.g.,
     * after the call is held/un-held). Finally, the {@code AudioGroup} object
     * returned by this method is undefined after the call ends or the
     * {@link #close} method is called.
     *
     * @return the {@link AudioGroup} object or null if the RTP stream has not
     *      yet been set up
     * @see #getAudioStream
     */
    AudioGroup getAudioGroup();

    /**
     * Checks if the call is established.
     *
     * @return true if the call is established
     */
    boolean isInCall();

    /**
     * Gets the local SIP profile.
     *
     * @return the local SIP profile
     */
    SipProfile getLocalProfile();

    /**
     * Gets the peer's SIP profile.
     *
     * @return the peer's SIP profile
     */
    SipProfile getPeerProfile();

    /**
     * Gets the state of the {@link ISipSession} that carries this call.
     *
     * @return the session state
     */
    SipSessionState getState();

    /**
     * Gets the {@link ISipSession} that carries this call.
     *
     * @return the session object that carries this call
     */
    ISipSession getSipSession();

    /**
     * Enables/disables the ring-back tone.
     *
     * @param enabled true to enable; false to disable
     */
    void setRingbackToneEnabled(boolean enabled);

    /**
     * Enables/disables the ring tone.
     *
     * @param enabled true to enable; false to disable
     */
    void setRingtoneEnabled(boolean enabled);
}