]> sjero.net Git - linphone/blob - LinphoneCoreFactoryImpl.java
replace vectores by arrays in linphone core api
[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 void loadOptionalLibrary(String s) {
32                 try {
33                         System.loadLibrary(s);
34                 } catch (Throwable e) {
35                         Log.w("Unable to load optional library lib", s);
36                 }
37         }
38
39         static {
40                 // FFMPEG (audio/video)
41                 if (!hasNeonInCpuFeatures()) {
42                         loadOptionalLibrary("avutilnoneon");
43                         loadOptionalLibrary("swscalenoneon");
44                         loadOptionalLibrary("avcorenoneon");
45                         loadOptionalLibrary("avcodecnoneon");
46                 } else {
47                         loadOptionalLibrary("avutil");
48                         loadOptionalLibrary("swscale");
49                         loadOptionalLibrary("avcore");
50                         loadOptionalLibrary("avcodec");
51                 }
52  
53                 // OPENSSL (cryptography)
54                 // lin prefix avoids collision with libs in /system/lib
55                 loadOptionalLibrary("lincrypto");
56                 loadOptionalLibrary("linssl");
57
58                 // Secure RTP and key negotiation
59                 loadOptionalLibrary("srtp");
60                 loadOptionalLibrary("zrtpcpp"); // GPLv3+
61
62                 // Tunnel
63                 loadOptionalLibrary("tunnelclient");
64                 
65                 // g729 A implementation
66                 loadOptionalLibrary("bcg729");
67
68                 //Main library
69                 if (!hasNeonInCpuFeatures()) {
70                         System.loadLibrary("linphonenoneon"); 
71                         Log.w("linphone", "No-neon liblinphone loaded");
72                 } else {
73                         System.loadLibrary("linphone"); 
74                 }
75
76                 Version.dumpCapabilities();
77         }
78         @Override
79         public LinphoneAuthInfo createAuthInfo(String username, String password,
80                         String realm) {
81                 return new LinphoneAuthInfoImpl(username,password,realm);
82         }
83
84         @Override
85         public LinphoneAddress createLinphoneAddress(String username,
86                         String domain, String displayName) {
87                 return new LinphoneAddressImpl(username,domain,displayName);
88         }
89
90         @Override
91         public LinphoneAddress createLinphoneAddress(String identity) {
92                 return new LinphoneAddressImpl(identity);
93         }
94
95         @Override
96         public LinphoneCore createLinphoneCore(LinphoneCoreListener listener,
97                         String userConfig, String factoryConfig, Object userdata)
98                         throws LinphoneCoreException {
99                 try {
100                         return new LinphoneCoreImpl(listener,new File(userConfig),new File(factoryConfig),userdata);
101                 } catch (IOException e) {
102                         throw new LinphoneCoreException("Cannot create LinphoneCore",e);
103                 }
104         }
105
106         @Override
107         public LinphoneCore createLinphoneCore(LinphoneCoreListener listener) throws LinphoneCoreException {
108                 try {
109                         return new LinphoneCoreImpl(listener);
110                 } catch (IOException e) {
111                         throw new LinphoneCoreException("Cannot create LinphoneCore",e);
112                 }
113         }
114
115         @Override
116         public LinphoneProxyConfig createProxyConfig(String identity, String proxy,
117                         String route, boolean enableRegister) throws LinphoneCoreException {
118                 return new LinphoneProxyConfigImpl(identity,proxy,route,enableRegister);
119         }
120
121         @Override
122         public native void setDebugMode(boolean enable);
123
124         @Override
125         public void setLogHandler(LinphoneLogHandler handler) {
126                 //not implemented on Android
127                 
128         }
129
130         @Override
131         public LinphoneFriend createLinphoneFriend(String friendUri) {
132                 return new LinphoneFriendImpl(friendUri);
133         }
134
135         @Override
136         public LinphoneFriend createLinphoneFriend() {
137                 return createLinphoneFriend(null);
138         }
139
140         public static boolean hasNeonInCpuFeatures()
141         {
142                 ProcessBuilder cmd;
143                 boolean result = false;
144                 
145                 try {
146                         String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
147                         cmd = new ProcessBuilder(args);
148         
149                    Process process = cmd.start();
150                    InputStream in = process.getInputStream();
151                    byte[] re = new byte[1024];
152                    while(in.read(re) != -1){
153                            String line = new String(re);
154                            if (line.contains("Features")) {
155                                    result = line.contains("neon");
156                                    break;
157                            }
158                    }
159                    in.close();
160                 } catch(IOException ex){
161                         ex.printStackTrace();
162                 }
163                 return result;
164         }
165 }