]> sjero.net Git - linphone/blob - java/impl/org/linphone/core/LinphoneCallImpl.java
add jni and java accessors for realtime late and loss rates
[linphone] / java / impl / org / linphone / core / LinphoneCallImpl.java
1 /*
2 LinphoneCallImpl.java
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19 package org.linphone.core;
20
21
22 class LinphoneCallImpl implements LinphoneCall {
23  
24         protected final long nativePtr;
25         boolean ownPtr = false;
26         private LinphoneCallStats audioStats;
27         private LinphoneCallStats videoStats;
28
29         native private void finalize(long nativePtr);
30         native private long  getCallLog(long nativePtr);
31         private native boolean isIncoming(long nativePtr);
32         native private long getRemoteAddress(long nativePtr);
33         native private int getState(long nativePtr);
34         private native long getCurrentParamsCopy(long nativePtr);
35         private native long getRemoteParams(long nativePtr);
36         private native void enableCamera(long nativePtr, boolean enabled);
37         private native boolean cameraEnabled(long nativePtr);
38         private native void enableEchoCancellation(long nativePtr,boolean enable);
39         private native boolean isEchoCancellationEnabled(long nativePtr) ;
40         private native void enableEchoLimiter(long nativePtr,boolean enable);
41         private native boolean isEchoLimiterEnabled(long nativePtr);
42         private native Object getReplacedCall(long nativePtr);
43         private native int getDuration(long nativePtr);
44         private native float getCurrentQuality(long nativePtr);
45         private native float getAverageQuality(long nativePtr);
46         
47         /*
48          * This method must always be called from JNI, nothing else.
49          */
50         private LinphoneCallImpl(long aNativePtr)  {
51                 nativePtr = aNativePtr;
52         }
53         protected void finalize() throws Throwable {
54                 finalize(nativePtr);
55         }
56         public LinphoneCallLog getCallLog() {
57                 long lNativePtr = getCallLog(nativePtr);
58                 if (lNativePtr!=0) {
59                         return new LinphoneCallLogImpl(lNativePtr); 
60                 } else {
61                         return null;
62                 }
63         }
64         public void setAudioStats(LinphoneCallStats stats) {
65                 audioStats = stats;
66         }
67         public void setVideoStats(LinphoneCallStats stats) {
68                 videoStats = stats;
69         }
70         public LinphoneCallStats getAudioStats() {
71                 if (audioStats!=null) ((LinphoneCallStatsImpl)audioStats).updateRealTimeStats(this);
72                 return audioStats;
73         }
74         public LinphoneCallStats getVideoStats() {
75                 if (videoStats!=null) ((LinphoneCallStatsImpl)videoStats).updateRealTimeStats(this);
76                 return videoStats;
77         }
78         public CallDirection getDirection() {
79                 return isIncoming(nativePtr)?CallDirection.Incoming:CallDirection.Outgoing;
80         }
81         public LinphoneAddress getRemoteAddress() {
82                 long lNativePtr = getRemoteAddress(nativePtr);
83                 if (lNativePtr!=0) {
84                         return new LinphoneAddressImpl(lNativePtr); 
85                 } else {
86                         return null;
87                 }
88         }
89         public State getState() {
90                 return LinphoneCall.State.fromInt(getState(nativePtr));
91         }
92         public LinphoneCallParams getCurrentParamsCopy() {
93                 return new LinphoneCallParamsImpl(getCurrentParamsCopy(nativePtr));
94         }
95         public LinphoneCallParams getRemoteParams() {
96                 long remoteParamsPtr = getRemoteParams(nativePtr);
97                 if (remoteParamsPtr == 0) {
98                         return null;
99                 }
100                 return new LinphoneCallParamsImpl(remoteParamsPtr);
101         }
102         public void enableCamera(boolean enabled) {
103                 enableCamera(nativePtr, enabled);
104         }
105         public boolean cameraEnabled() {
106                 return cameraEnabled(nativePtr);
107         }
108
109         @Override
110         public boolean equals(Object call) {
111                 if (this == call) return true;
112                 if (call == null) return false;
113                 if (!(call instanceof LinphoneCallImpl)) return false;
114                 return nativePtr == ((LinphoneCallImpl)call).nativePtr;
115         }
116
117         @Override
118         public int hashCode() {
119                 int result = 17;
120                 result = 31 * result + (int) (nativePtr ^ (nativePtr >>> 32));
121                 return result;
122         }
123         public void enableEchoCancellation(boolean enable) {
124                 enableEchoCancellation(nativePtr,enable);
125                 
126         }
127         public boolean isEchoCancellationEnabled() {
128                 return isEchoCancellationEnabled(nativePtr);
129         }
130         public void enableEchoLimiter(boolean enable) {
131                 enableEchoLimiter(nativePtr,enable);
132         }
133         public boolean isEchoLimiterEnabled() {
134                 return isEchoLimiterEnabled(nativePtr);
135         }
136         public LinphoneCall getReplacedCall(){
137                 return (LinphoneCall)getReplacedCall(nativePtr);
138         }
139
140         public int getDuration() {
141                 return getDuration(nativePtr);
142         }
143         public float getAverageQuality() {
144                 return getAverageQuality(nativePtr);
145         }
146         public float getCurrentQuality() {
147                 return getCurrentQuality(nativePtr);
148         }
149
150         private native String getAuthenticationToken(long nativePtr);
151         public String getAuthenticationToken(){
152                 return getAuthenticationToken(nativePtr);
153         }
154
155         private native boolean isAuthenticationTokenVerified(long nativePtr);
156         public boolean isAuthenticationTokenVerified(){
157                 return isAuthenticationTokenVerified(nativePtr);
158         }
159
160         private native void setAuthenticationTokenVerified(long nativePtr, boolean verified);
161         public void setAuthenticationTokenVerified(boolean verified){
162                 setAuthenticationTokenVerified(nativePtr, verified);
163         }
164
165         public boolean isInConference() {
166                 LinphoneCallParamsImpl params = new LinphoneCallParamsImpl(getCurrentParamsCopy(nativePtr));
167                 return params.localConferenceMode();
168         }
169
170         @Override
171         public String toString() {
172                 return "Call " + nativePtr;
173         }
174
175         private native float getPlayVolume(long nativePtr);
176         public float getPlayVolume() {
177                 return getPlayVolume(nativePtr);
178         }
179
180         private native String getRemoteUserAgent(long nativePtr);
181         public String getRemoteUserAgent() {
182                 return getRemoteUserAgent(nativePtr);
183         }
184
185         private native String getRemoteContact(long nativePtr);
186         public String getRemoteContact() {
187                 return getRemoteContact(nativePtr);
188         }
189         
190         private native void takeSnapshot(long nativePtr, String path);
191         public void takeSnapshot(String path) {
192                 takeSnapshot(nativePtr, path);
193         }
194
195         private native void zoomVideo(long nativePtr, float factor, float cx, float cy);
196         public void zoomVideo(float factor, float cx, float cy) {
197                 zoomVideo(nativePtr, factor, cx, cy);
198         }
199         
200         private native void startRecording(long nativePtr);
201         @Override
202         public void startRecording() {
203                 startRecording(nativePtr);
204         }
205         private native void stopRecording(long nativePtr);
206         @Override
207         public void stopRecording() {
208                 stopRecording(nativePtr);
209         }
210 }