2 LinphoneCoreFactoryImpl.java
3 Copyright (C) 2010 Belledonne Communications, Grenoble, France
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.
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.
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.
19 package org.linphone.core;
22 import java.io.IOException;
23 import java.io.InputStream;
25 import org.linphone.mediastream.Version;
27 import android.util.Log;
29 public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
31 private static boolean loadOptionalLibrary(String s) {
33 System.loadLibrary(s);
35 } catch (Throwable e) {
36 Log.w("Unable to load optional library lib", s);
42 // FFMPEG (audio/video)
43 loadOptionalLibrary("avutil");
44 loadOptionalLibrary("swscale");
45 loadOptionalLibrary("avcore");
47 if (!hasNeonInCpuFeatures()) {
48 boolean noNeonLibrariesLoaded = loadOptionalLibrary("avcodecnoneon");
49 if (!noNeonLibrariesLoaded) {
50 loadOptionalLibrary("avcodec");
53 loadOptionalLibrary("avcodec");
56 // OPENSSL (cryptography)
57 // lin prefix avoids collision with libs in /system/lib
58 loadOptionalLibrary("lincrypto");
59 loadOptionalLibrary("linssl");
61 // Secure RTP and key negotiation
62 loadOptionalLibrary("srtp");
63 loadOptionalLibrary("zrtpcpp"); // GPLv3+
66 loadOptionalLibrary("tunnelclient");
68 // g729 A implementation
69 loadOptionalLibrary("bcg729");
72 if (!hasNeonInCpuFeatures()) {
74 if (!isArmv7() && !Version.isX86()) {
75 System.loadLibrary("linphonearmv5");
77 System.loadLibrary("linphonenoneon");
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");
85 System.loadLibrary("linphone");
88 Version.dumpCapabilities();
91 public LinphoneAuthInfo createAuthInfo(String username, String password,
93 return new LinphoneAuthInfoImpl(username,password,realm);
97 public LinphoneAddress createLinphoneAddress(String username,
98 String domain, String displayName) {
99 return new LinphoneAddressImpl(username,domain,displayName);
103 public LinphoneAddress createLinphoneAddress(String identity) {
104 return new LinphoneAddressImpl(identity);
108 public LinphoneCore createLinphoneCore(LinphoneCoreListener listener,
109 String userConfig, String factoryConfig, Object userdata)
110 throws LinphoneCoreException {
112 return new LinphoneCoreImpl(listener,new File(userConfig),new File(factoryConfig),userdata);
113 } catch (IOException e) {
114 throw new LinphoneCoreException("Cannot create LinphoneCore",e);
119 public LinphoneCore createLinphoneCore(LinphoneCoreListener listener) throws LinphoneCoreException {
121 return new LinphoneCoreImpl(listener);
122 } catch (IOException e) {
123 throw new LinphoneCoreException("Cannot create LinphoneCore",e);
128 public LinphoneProxyConfig createProxyConfig(String identity, String proxy,
129 String route, boolean enableRegister) throws LinphoneCoreException {
130 return new LinphoneProxyConfigImpl(identity,proxy,route,enableRegister);
134 public native void setDebugMode(boolean enable, String tag);
137 public void setLogHandler(LinphoneLogHandler handler) {
138 //not implemented on Android
143 public LinphoneFriend createLinphoneFriend(String friendUri) {
144 return new LinphoneFriendImpl(friendUri);
148 public LinphoneFriend createLinphoneFriend() {
149 return createLinphoneFriend(null);
152 public static boolean hasNeonInCpuFeatures()
155 boolean result = false;
158 String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
159 cmd = new ProcessBuilder(args);
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");
172 } catch(IOException ex){
173 ex.printStackTrace();
178 public static boolean isArmv7()
180 return System.getProperty("os.arch").contains("armv7");