]> sjero.net Git - linphone/blob - LinphoneCoreFactoryImpl.java
Drawable hdpi and mdpi + rotation issue fixed + memory leak fixed
[linphone] / 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 import java.io.InputStream;
24
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                 if (!hasNeonInCpuFeatures()) {
48                         boolean noNeonLibrariesLoaded = loadOptionalLibrary("avcodecnoneon");
49                         if (!noNeonLibrariesLoaded) {
50                                 loadOptionalLibrary("avcodec");
51                         }
52                 } else {
53                         loadOptionalLibrary("avcodec");
54                 }
55  
56                 // OPENSSL (cryptography)
57                 // lin prefix avoids collision with libs in /system/lib
58                 loadOptionalLibrary("lincrypto");
59                 loadOptionalLibrary("linssl");
60
61                 // Secure RTP and key negotiation
62                 loadOptionalLibrary("srtp");
63                 loadOptionalLibrary("zrtpcpp"); // GPLv3+
64
65                 // Tunnel
66                 loadOptionalLibrary("tunnelclient");
67                 
68                 // g729 A implementation
69                 loadOptionalLibrary("bcg729");
70
71                 //Main library
72                 if (!hasNeonInCpuFeatures()) {
73                         try {
74                                 if (!isArmv7()) {
75                                         System.loadLibrary("linphonearmv5"); 
76                                 } else {
77                                         System.loadLibrary("linphonenoneon"); 
78                                 }
79                                 Log.w("linphone", "No-neon liblinphone loaded");
80                         } catch (UnsatisfiedLinkError ule) {
81                                 Log.w("linphone", "Failed to load no-neon liblinphone, loading neon liblinphone");
82                                 System.loadLibrary("linphone"); 
83                         }
84                 } else {
85                         System.loadLibrary("linphone"); 
86                 }
87
88                 Version.dumpCapabilities();
89         }
90         @Override
91         public LinphoneAuthInfo createAuthInfo(String username, String password,
92                         String realm) {
93                 return new LinphoneAuthInfoImpl(username,password,realm);
94         }
95
96         @Override
97         public LinphoneAddress createLinphoneAddress(String username,
98                         String domain, String displayName) {
99                 return new LinphoneAddressImpl(username,domain,displayName);
100         }
101
102         @Override
103         public LinphoneAddress createLinphoneAddress(String identity) {
104                 return new LinphoneAddressImpl(identity);
105         }
106
107         @Override
108         public LinphoneCore createLinphoneCore(LinphoneCoreListener listener,
109                         String userConfig, String factoryConfig, Object userdata)
110                         throws LinphoneCoreException {
111                 try {
112                         return new LinphoneCoreImpl(listener,new File(userConfig),new File(factoryConfig),userdata);
113                 } catch (IOException e) {
114                         throw new LinphoneCoreException("Cannot create LinphoneCore",e);
115                 }
116         }
117
118         @Override
119         public LinphoneCore createLinphoneCore(LinphoneCoreListener listener) throws LinphoneCoreException {
120                 try {
121                         return new LinphoneCoreImpl(listener);
122                 } catch (IOException e) {
123                         throw new LinphoneCoreException("Cannot create LinphoneCore",e);
124                 }
125         }
126
127         @Override
128         public LinphoneProxyConfig createProxyConfig(String identity, String proxy,
129                         String route, boolean enableRegister) throws LinphoneCoreException {
130                 return new LinphoneProxyConfigImpl(identity,proxy,route,enableRegister);
131         }
132
133         @Override
134         public native void setDebugMode(boolean enable);
135
136         @Override
137         public void setLogHandler(LinphoneLogHandler handler) {
138                 //not implemented on Android
139                 
140         }
141
142         @Override
143         public LinphoneFriend createLinphoneFriend(String friendUri) {
144                 return new LinphoneFriendImpl(friendUri);
145         }
146
147         @Override
148         public LinphoneFriend createLinphoneFriend() {
149                 return createLinphoneFriend(null);
150         }
151
152         public static boolean hasNeonInCpuFeatures()
153         {
154                 ProcessBuilder cmd;
155                 boolean result = false;
156                 
157                 try {
158                         String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
159                         cmd = new ProcessBuilder(args);
160         
161                    Process process = cmd.start();
162                    InputStream in = process.getInputStream();
163                    byte[] re = new byte[1024];
164                    while(in.read(re) != -1){
165                            String line = new String(re);
166                            if (line.contains("Features")) {
167                                    result = line.contains("neon");
168                                    break;
169                            }
170                    }
171                    in.close();
172                 } catch(IOException ex){
173                         ex.printStackTrace();
174                 }
175                 return result;
176         }
177         
178         public static boolean isArmv7()
179         {
180                 return System.getProperty("os.arch").contains("armv7");
181         }
182 }