]> sjero.net Git - linphone/blob - java/impl/org/linphone/core/LinphoneCoreFactoryImpl.java
Renamed android libraries to avoid confusion
[linphone] / java / impl / org / linphone / core / LinphoneCoreFactoryImpl.java
1 /*
2 LinphoneCoreFactoryImpl.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 import java.io.File;
22 import java.io.IOException;
23
24 import org.linphone.mediastream.CpuUtils;
25 import org.linphone.mediastream.Version;
26
27 import android.util.Log;
28
29 public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
30
31         private static boolean loadOptionalLibrary(String s) {
32                 try {
33                         System.loadLibrary(s);
34                         return true;
35                 } catch (Throwable e) {
36                         Log.w("Unable to load optional library lib", s);
37                 }
38                 return false;
39         }
40
41         static {
42                 // FFMPEG (audio/video)
43                 loadOptionalLibrary("avutil");
44                 loadOptionalLibrary("swscale");
45                 loadOptionalLibrary("avcore");
46
47                 System.loadLibrary("neon");
48                 
49                 if (!hasNeonInCpuFeatures()) {
50                         boolean noNeonLibrariesLoaded = loadOptionalLibrary("avcodecnoneon");
51                         if (!noNeonLibrariesLoaded) {
52                                 loadOptionalLibrary("avcodec");
53                         }
54                 } else {
55                         loadOptionalLibrary("avcodec");
56                 }
57  
58                 // OPENSSL (cryptography)
59                 // lin prefix avoids collision with libs in /system/lib
60                 loadOptionalLibrary("lincrypto");
61                 loadOptionalLibrary("linssl");
62
63                 // Secure RTP and key negotiation
64                 loadOptionalLibrary("srtp");
65                 loadOptionalLibrary("zrtpcpp"); // GPLv3+
66
67                 // Tunnel
68                 loadOptionalLibrary("tunnelclient");
69                 
70                 // g729 A implementation
71                 loadOptionalLibrary("bcg729");
72
73                 //Main library
74                 if (isArmv7()) {
75                         if (hasNeonInCpuFeatures()) {
76                                 Log.d("linphone", "armv7 liblinphone loaded");
77                                 System.loadLibrary("linphonearmv7"); 
78                         } else {
79                                 Log.w("linphone", "No-neon armv7 liblinphone loaded");
80                                 System.loadLibrary("linphonearmv7noneon"); 
81                         }
82                 } else if (Version.isX86()) {
83                         Log.d("linphone", "No-neon x86 liblinphone loaded");
84                         System.loadLibrary("linphonex86noneon"); 
85                 } else {
86                         Log.d("linphone", "No-neon armv5 liblinphone loaded");
87                         System.loadLibrary("linphonearmv5noneon"); 
88                 }
89
90                 Version.dumpCapabilities();
91         }
92         @Override
93         public LinphoneAuthInfo createAuthInfo(String username, String password,
94                         String realm) {
95                 return new LinphoneAuthInfoImpl(username,password,realm);
96         }
97
98         @Override
99         public LinphoneAddress createLinphoneAddress(String username,
100                         String domain, String displayName) {
101                 return new LinphoneAddressImpl(username,domain,displayName);
102         }
103
104         @Override
105         public LinphoneAddress createLinphoneAddress(String identity) {
106                 return new LinphoneAddressImpl(identity);
107         }
108         
109         @Override
110         public LpConfig createLpConfig(String file) {
111                 return new LpConfigImpl(file);
112         }
113
114         @Override
115         public LinphoneCore createLinphoneCore(LinphoneCoreListener listener,
116                         String userConfig, String factoryConfig, Object userdata)
117                         throws LinphoneCoreException {
118                 try {
119                         return new LinphoneCoreImpl(listener,new File(userConfig),new File(factoryConfig),userdata);
120                 } catch (IOException e) {
121                         throw new LinphoneCoreException("Cannot create LinphoneCore",e);
122                 }
123         }
124
125         @Override
126         public LinphoneCore createLinphoneCore(LinphoneCoreListener listener) throws LinphoneCoreException {
127                 try {
128                         return new LinphoneCoreImpl(listener);
129                 } catch (IOException e) {
130                         throw new LinphoneCoreException("Cannot create LinphoneCore",e);
131                 }
132         }
133
134         @Override
135         public LinphoneProxyConfig createProxyConfig(String identity, String proxy,
136                         String route, boolean enableRegister) throws LinphoneCoreException {
137                 return new LinphoneProxyConfigImpl(identity,proxy,route,enableRegister);
138         }
139
140         @Override
141         public native void setDebugMode(boolean enable, String tag);
142
143         @Override
144         public void setLogHandler(LinphoneLogHandler handler) {
145                 //not implemented on Android
146                 
147         }
148
149         @Override
150         public LinphoneFriend createLinphoneFriend(String friendUri) {
151                 return new LinphoneFriendImpl(friendUri);
152         }
153
154         @Override
155         public LinphoneFriend createLinphoneFriend() {
156                 return createLinphoneFriend(null);
157         }
158
159         public static boolean hasNeonInCpuFeatures()
160         {
161                 CpuUtils cpu = new CpuUtils();
162                 return cpu.isCpuNeon();
163         }
164         
165         public static boolean isArmv7()
166         {
167                 return System.getProperty("os.arch").contains("armv7");
168         }
169
170         @Override
171         public LinphoneAuthInfo createAuthInfo(String username, String userid,
172                         String passwd, String ha1, String realm) {
173                 return new LinphoneAuthInfoImpl(username,userid,passwd,ha1,realm);
174         }
175 }