From a780f0b8d0ccec90d359c0c554f07d5afde9554c Mon Sep 17 00:00:00 2001
From: 562935844@qq.com
Date: 星期二, 28 六月 2022 17:05:31 +0800
Subject: [PATCH] 代码同步

---
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java |  610 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 428 insertions(+), 182 deletions(-)

diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
index c6d339b..2e4a99b 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
@@ -3,26 +3,32 @@
 import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
-import android.view.SurfaceView;
 import android.view.TextureView;
 import android.widget.Toast;
 
 import com.hdl.hdllinphonesdk.activity.HDLLinphoneIntercomActivity;
+import com.hdl.hdllinphonesdk.activity.HDLLinphoneReverseCallActivity;
 import com.hdl.hdllinphonesdk.callback.OnHDLLinphoneCallListener;
 import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack;
 import com.hdl.hdllinphonesdk.core.callback.PhoneCallback;
 import com.hdl.hdllinphonesdk.core.callback.RegistrationCallback;
-import com.hdl.hdllinphonesdk.core.linphone.LinphoneUtils;
 import com.hdl.hdllinphonesdk.core.service.HDLLinphoneService;
 import com.hdl.hdllinphonesdk.utils.HDLLog;
 
+import org.linphone.core.AccountCreator;
 import org.linphone.core.Address;
+import org.linphone.core.AudioDevice;
+import org.linphone.core.AuthInfo;
 import org.linphone.core.Call;
 import org.linphone.core.CallParams;
-import org.linphone.core.CallStats;
 import org.linphone.core.Core;
 import org.linphone.core.CoreException;
+import org.linphone.core.Factory;
 import org.linphone.core.ProxyConfig;
+import org.linphone.core.TransportType;
+
+import java.io.FileOutputStream;
+import java.io.InputStream;
 
 import static java.lang.Thread.sleep;
 
@@ -30,21 +36,46 @@
  * Created by jlchen on 2021/8/4.
  */
 public class HDLLinphoneKit {
-    public static final String KEY_TITLE_NAME = "lpTitleName";
+    /**
+     * 涓版灄鍙瀵硅
+     */
+    public static final String INTER_PHONE_TYPE_FLVI = "FLVI";
+    /**
+     * 澶у崕鍙瀵硅
+     */
+    public static final String INTER_PHONE_TYPE_IMOUVISIAL = "IMOUVISIAL";
+    /**
+     * 钀ょ煶鐚溂
+     */
+    public static final String INTER_PHONE_TYPE_EZVIZ = "EZVIZ";
+    /**
+     * HDL鍙瀵硅
+     */
+    public static final String INTER_PHONE_TYPE_HDL = "HDL";
+    /**
+     * 鍏ㄨ閫氬彲瑙嗗璁�
+     */
+    public static final String INTER_PHONE_TYPE_FREEVIEW = "FREEVIEW";
 
+    public static final String KEY_TITLE_NAME = "lpTitleName";
+    public static final String KEY_SIP_ACCOUNT = "lpSipAccount";
     public static final String HDLLinphoneKitNAME = "HDLLinphoneKit";
     private volatile static HDLLinphoneKit instance;
     private Context viewContext;
     private ServiceWaitThread mServiceWaitThread;
     private String mUsername, mPassword, mServerIP;
-    private TextureView mRenderingView, mPreviewView;
-
+    //    private TextureView mRenderingView, mPreviewView;
     private boolean isAutoJumpCallView;//鏄惁鑷姩璺宠浆鍛煎彨椤甸潰
 
-
     private HDLLinphoneKit() {
+
     }
 
+    /**
+     * getInstance
+     *
+     * @return HDLLinphoneKit
+     */
     public static synchronized HDLLinphoneKit getInstance() {
         if (instance == null) {
             synchronized (HDLLinphoneKit.class) {
@@ -57,33 +88,52 @@
     }
 
     /**
+     * 鑾峰彇 LinphoneCore
+     *
+     * @return Core
+     */
+    public Core getCore() {
+        if (!HDLLinphoneService.isReady()) {
+            CheckIfNeedstartService();
+            return null;
+        } else {
+            return HDLLinphoneService.getCore();
+        }
+    }
+
+    /**
      * 鍒濆鍖朙inphone
+     *
+     * @param context
      */
     public void initLinphone(Context context) {
         viewContext = context.getApplicationContext();
         if (!HDLLinphoneService.isReady()) {
-            startService(context);
-            addCallback(new RegistrationCallback() {
-                @Override
-                public void registrationOk() {
-                    super.registrationOk();
-                    Log.e(HDLLinphoneKitNAME, "registrationOk: ");
-                    callBackRegistrationOk(viewContext);
-
-                }
-
-                @Override
-                public void registrationFailed() {
-                    super.registrationFailed();
-                    Log.e(HDLLinphoneKitNAME, "registrationFailed: ");
-//                    Toast.makeText(LoginActivity.this, "鐧诲綍澶辫触锛�", Toast.LENGTH_SHORT).show();
-                }
-            }, null);
-
+            CheckIfNeedstartService();
         } else {
-
         }
+    }
 
+    /**
+     * startService
+     */
+    private synchronized void CheckIfNeedstartService() {
+        startService(viewContext);
+        addCallback(new RegistrationCallback() {
+            @Override
+            public void registrationOk() {
+                super.registrationOk();
+                HDLLog.e(HDLLinphoneKitNAME, "registrationOk: ");
+                callBackRegistrationOk(viewContext);
+            }
+
+            @Override
+            public void registrationFailed() {
+                super.registrationFailed();
+                HDLLog.e(HDLLinphoneKitNAME, "registrationFailed: ");
+//                    Toast.makeText(LoginActivity.this, "鐧诲綍澶辫触锛�", Toast.LENGTH_SHORT).show();
+            }
+        }, null);
     }
 
     /**
@@ -94,9 +144,16 @@
             @Override
             public void incomingCall(Call linphoneCall) {
                 super.incomingCall(linphoneCall);
+                Log.d("HDLLinphoneKit","------incomingCall------");
+                if (linphoneCall != null) {
+                    String callUsername = linphoneCall.getRemoteAddress().getUsername();
+                    HDLLog.I("鏉ョ數鍙风爜锛�" + callUsername);
+//                    HDLLog.Log("鏉ョ數鍙风爜DisplayName锛�" + linphoneCall.getRemoteAddress().getDisplayName());
+                    if (mOnHDLLinphoneCallListener != null) {
+                        mOnHDLLinphoneCallListener.onIncomingCall(callUsername);
+                    }
+                }
 
-                String callUsername = linphoneCall.getRemoteAddress().getUsername();
-                HDLLog.E("鏉ョ數鍙风爜锛�" + callUsername);
                 if (isAutoJumpCallView) {
                     //鏄惁闇�瑕佽嚜鍔ㄦ墦寮�鍛煎彨椤甸潰
                     gotoHDLLinphoneIntercomActivity();
@@ -106,23 +163,29 @@
             @Override
             public void outgoingInit() {
                 super.outgoingInit();
-
+<<<<<<< HEAD
+                Log.d("HDLLinphoneKit","------outgoingInit------");
+=======
+>>>>>>> 1697a5c0a1d40e756738d1f99d496c6e33b3fd52
             }
 
             @Override
             public void callConnected() {
                 super.callConnected();
                 // 瑙嗛閫氳瘽榛樿鍏嶆彁锛岃闊抽�氳瘽榛樿闈炲厤鎻�
+                Log.d("HDLLinphoneKit","------callConnected------");
                 toggleSpeaker(true);
-                // 鎵�鏈夐�氳瘽榛樿闈為潤闊�
-                toggleMicro(false);
             }
 
             @Override
             public void callEnd() {
                 super.callEnd();
-                context.sendBroadcast(new Intent(HDLLinphoneIntercomActivity.RECEIVE_FINISH_VIDEO_ACTIVITY));
+<<<<<<< HEAD
+                Log.d("HDLLinphoneKit","------callEnd------");
+//                context.sendBroadcast(new Intent(HDLLinphoneIntercomActivity.RECEIVE_FINISH_VIDEO_ACTIVITY));
 
+=======
+>>>>>>> 1697a5c0a1d40e756738d1f99d496c6e33b3fd52
             }
         });
     }
@@ -131,18 +194,14 @@
      * 璺宠浆鎵撳紑鍛煎彨椤甸潰
      */
     public void gotoHDLLinphoneIntercomActivity() {
-        Intent intent = new Intent(viewContext, HDLLinphoneIntercomActivity.class);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        viewContext.startActivity(intent);
+        try {
+            Intent intent = new Intent(viewContext, HDLLinphoneIntercomActivity.class);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            viewContext.startActivity(intent);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
-
-    /**
-     * showToast
-     */
-    private void showToast(String text) {
-        Toast.makeText(viewContext, text, Toast.LENGTH_SHORT).show();
-    }
-
 
     /**
      * 寮�鍚湇鍔�
@@ -150,25 +209,43 @@
      * @param context 涓婁笅鏂�
      */
     public void startService(Context context) {
-        if (!HDLLinphoneService.isReady()) {
-            Intent intent = new Intent(Intent.ACTION_MAIN);
-            intent.setClass(context, HDLLinphoneService.class);
-            context.startService(intent);
+        try {
+            if (!HDLLinphoneService.isReady()) {
+                Intent intent = new Intent(Intent.ACTION_MAIN);
+                intent.setClass(context, HDLLinphoneService.class);
+                context.startService(intent);
+//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//                    context.startForegroundService(intent);//瑙e喅android8.0浠ヤ笂鏃犳硶鍚姩鏈嶅姟鐨勯棶棰�
+//                } else {
+//                    context.startService(intent);
+//                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
-//    /**
-//     * 璁剧疆 sip 璐︽埛淇℃伅
-//     *
-//     * @param username sip 璐︽埛
-//     * @param password 瀵嗙爜
-//     * @param serverIP sip 鏈嶅姟鍣�
-//     */
-//    public void setAccount(String username, String password, String serverIP) {
-//        mUsername = username;
-//        mPassword = password;
-//        mServerIP = serverIP;
-//    }
+    /**
+     * onResume
+     */
+    public void onResume() {
+
+    }
+
+    /**
+     * onPause
+     */
+    public void onPause() {
+
+    }
+
+    /**
+     * onDestroy
+     */
+    public void onDestroy() {
+        removePreviewWindow();
+        removeVideoWindow();
+    }
 
     /**
      * 璁剧疆 sip 璐︽埛淇℃伅
@@ -177,11 +254,11 @@
      * @param password 瀵嗙爜
      * @param serverIP sip 鏈嶅姟鍣�
      */
-    public void setAccountAndLogin(String username, String password, String serverIP) {
+    public void setAccountAndLogin(String username, String password, String serverIP, String inter_type) {
         mUsername = username;
         mPassword = password;
         mServerIP = serverIP;
-        login();
+        login(inter_type);
     }
 
     /**
@@ -190,8 +267,7 @@
      * @param phoneCallback        閫氳瘽鍥炶皟
      * @param registrationCallback 娉ㄥ唽鐘舵�佸洖璋�
      */
-    public void addCallback(RegistrationCallback registrationCallback,
-                            PhoneCallback phoneCallback) {
+    public void addCallback(RegistrationCallback registrationCallback, PhoneCallback phoneCallback) {
         if (HDLLinphoneService.isReady()) {
             HDLLinphoneService.addRegistrationCallback(registrationCallback);
             HDLLinphoneService.addPhoneCallback(phoneCallback);
@@ -204,24 +280,22 @@
     /**
      * 鐧诲綍鍒� SIP 鏈嶅姟鍣�
      */
-    public void login() {
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                while (!HDLLinphoneService.isReady()) {
-                    try {
-                        sleep(80);
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
+    public void login(String inter_type) {
+        new Thread(() -> {
+            while (!HDLLinphoneService.isReady()) {
+                try {
+                    sleep(80);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
                 }
-                loginToServer();
             }
+            loginToServer(inter_type);
         }).start();
     }
 
     /**
      * 閫�鍑烘竻绌鸿处鍙�
+     * enableRegister false
      */
     public void logout() {
         try {
@@ -235,63 +309,27 @@
                         config.done();
                     }
                 }
-                core.clearAllAuthInfo();
-                core.clearProxyConfig();
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
-
     /**
-     * 鍛煎彨鎸囧畾鍙风爜
-     *
-     * @param num 鍛煎彨鍙风爜
+     * 娓呴櫎閰嶇疆琛�, 鍒囨崲璐﹀彿鏃朵細鐢ㄥ埌
      */
-    public void callTo(String num, boolean isVideoCall) {
-        LinphoneUtils.getInstance().callTo(num, isVideoCall);
+    public void clearProxyConfig() {
+        Core core = HDLLinphoneService.getCore();
+        if (core != null) {
+            core.setDefaultProxyConfig(null);
+            core.clearAllAuthInfo();//娓呴櫎鎵�鏈夎璇佷俊鎭��
+            core.clearProxyConfig();//浠庨厤缃腑鍒犻櫎鎵�鏈変唬鐞嗐��
+        }
     }
 
     /**
-     * 鎺ュ惉鏉ョ數
+     * ServiceWaitThread
      */
-    public void acceptCall() {
-        LinphoneUtils.getInstance().acceptCall();
-    }
-
-//    /**
-//     * 鎺ュ惉鏉ョ數
-//     */
-//    public void acceptCallWithVideo(boolean enableVideo) {
-//        LinphoneUtils.getInstance().acceptCallWithVideo(enableVideo);
-//    }
-
-    /**
-     * 鎸傛柇褰撳墠閫氳瘽
-     */
-    public void hangUp() {
-        LinphoneUtils.getInstance().hangUp();
-    }
-
-    /**
-     * 鍒囨崲闈欓煶
-     *
-     * @param isMicMuted 鏄惁闈欓煶
-     */
-    public void toggleMicro(boolean isMicMuted) {
-        LinphoneUtils.getInstance().toggleMicro(isMicMuted);
-    }
-
-    /**
-     * 鍒囨崲鍏嶆彁
-     *
-     * @param isSpeakerEnabled 鏄惁鍏嶆彁
-     */
-    public void toggleSpeaker(boolean isSpeakerEnabled) {
-        LinphoneUtils.getInstance().toggleSpeaker(isSpeakerEnabled);
-    }
-
     private class ServiceWaitThread extends Thread {
         private PhoneCallback mPhoneCallback;
         private RegistrationCallback mRegistrationCallback;
@@ -320,81 +358,256 @@
     /**
      * 鐧诲綍 SIP 鏈嶅姟鍣�
      */
-    private void loginToServer() {
+    private void loginToServer(String inter_type) {
         try {
             if (mUsername == null || mPassword == null || mServerIP == null) {
                 throw new RuntimeException("The sip account is not configured.");
             }
-            LinphoneUtils.getInstance().registerUserAuth(mUsername, mPassword, mServerIP);
+            if (inter_type.equals(INTER_PHONE_TYPE_FREEVIEW)) {
+                // 鍏ㄨ閫氬彲瑙嗗璁叉敞鍐�
+                freeViewRegisterUserAuth(mUsername, mPassword, mServerIP);
+            } else {
+                // 鍏朵粬鍙瀵硅娉ㄥ唽
+                registerUserAuth(mUsername, mPassword, mServerIP);
+            }
         } catch (CoreException e) {
             e.printStackTrace();
         }
     }
 
-//    public static boolean getVideoEnabled() {
-//        CallParams remoteParams = HDLLinphoneService.getCore().getCurrentCall().getRemoteParams();
-//        return remoteParams != null && remoteParams.videoEnabled();
-//    }
+    /**
+     * 鎻愪氦璐﹀彿鍜屽瘑鐮佹敞鍐屽埌鏈嶅姟鍣�
+     *
+     * @param name
+     * @param password
+     * @param host
+     * @throws CoreException
+     */
+    public void registerUserAuth(String name, String password, String host) throws CoreException {
+        Core mLinphoneCore = HDLLinphoneService.getCore();
+        if (mLinphoneCore == null) return;
+
+        AuthInfo authInfo = Factory.instance().createAuthInfo(name, null, password, null, null, host);
+        AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null);
+        mAccountCreator.setUsername(name);
+        mAccountCreator.setDomain(host);
+        mAccountCreator.setPassword(password);
+        mAccountCreator.setTransport(TransportType.Udp);
+        ProxyConfig prxCfg = mAccountCreator.createProxyConfig();
+
+        prxCfg.enableQualityReporting(false);
+        prxCfg.setQualityReportingCollector(null);
+        prxCfg.setQualityReportingInterval(0);
+        prxCfg.enableRegister(true);
+        mLinphoneCore.addProxyConfig(prxCfg);//娣诲姞浠g悊閰嶇疆銆傚鏋滃惎鐢ㄤ簡娉ㄥ唽锛岃繖灏嗗紑濮嬪湪浠g悊涓婃敞鍐屻��
+        mLinphoneCore.addAuthInfo(authInfo);//娣诲姞璁よ瘉淇℃伅鍒�,璇ヤ俊鎭墖娈靛皢鍦ㄦ墍鏈夐渶瑕佺殑SIP浜嬪姟涓娇鐢ㄨ韩浠介獙璇�
+        mLinphoneCore.setDefaultProxyConfig(prxCfg);//璁剧疆榛樿浠g悊銆�
+    }
 
     /**
-     * 璁剧疆 SurfaceView
+     * 鎻愪氦璐﹀彿鍜屽瘑鐮佹敞鍐屽埌鍏ㄨ閫氭湇鍔″櫒
+     *
+     * @throws CoreException
+     */
+    public void freeViewRegisterUserAuth(String userName, String password, String domain) throws CoreException {
+        Core mLinphoneCore = HDLLinphoneService.getCore();
+        if (mLinphoneCore == null) return;
+
+        AuthInfo authInfo = Factory.instance().createAuthInfo(userName, "", password, null, null, domain);
+
+        AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null);
+        mAccountCreator.setUsername(userName);
+        mAccountCreator.setDomain("yun");
+        mAccountCreator.setPassword(password);
+        mAccountCreator.setTransport(TransportType.Udp);
+
+        ProxyConfig prxCfg = mAccountCreator.createProxyConfig();
+        prxCfg.enableQualityReporting(false);
+        prxCfg.setQualityReportingCollector(null);
+        prxCfg.setQualityReportingInterval(0);
+        prxCfg.enableRegister(true);
+        prxCfg.setServerAddr("sip:139.159.157.75:46000;transport=udp");
+
+        mLinphoneCore.addProxyConfig(prxCfg);//娣诲姞浠g悊閰嶇疆銆傚鏋滃惎鐢ㄤ簡娉ㄥ唽锛岃繖灏嗗紑濮嬪湪浠g悊涓婃敞鍐屻��
+        mLinphoneCore.addAuthInfo(authInfo);//娣诲姞璁よ瘉淇℃伅鍒�,璇ヤ俊鎭墖娈靛皢鍦ㄦ墍鏈夐渶瑕佺殑SIP浜嬪姟涓娇鐢ㄨ韩浠介獙璇�
+        mLinphoneCore.setDefaultProxyConfig(prxCfg);//璁剧疆榛樿浠g悊銆�
+    }
+
+    /**
+     * 鍛煎彨,鍏ㄨ閫氬彲瑙嗗璁查渶瑕佸皢 澶栧嚭浠g悊鏈嶅姟鍣ㄦ墦寮�锛屾墠鑳戒娇鐢� 绌洪棿鍙峰懠鍙紱
+     * 鏆傛椂娌℃壘鍒版�庝箞鎵撳紑锛屾墍浠ラ渶瑕佹墜鍔ㄥ姞涓妏roxy
+     */
+    public Call startSingleCallingTo(String userName, boolean isVideoCall) {
+        Core mLinphoneCore = HDLLinphoneService.getCore();
+        if (mLinphoneCore == null) return null;
+
+        Call call = null;
+        Core core = HDLLinphoneService.getCore();
+        if (core != null) {
+            Address addressToCall = core.interpretUrl(userName);
+            CallParams params = core.createCallParams(null);
+
+            if (isVideoCall) {
+                params.enableVideo(true);
+                params.enableLowBandwidth(false);
+                params.setAudioBandwidthLimit(0); // disable limitation
+            } else {
+                params.enableVideo(false);
+                params.setAudioBandwidthLimit(40); // disable limitation
+            }
+
+            if (addressToCall != null) {
+                call = core.inviteAddressWithParams(addressToCall, params);
+                // 璁剧疆澶栨斁
+                for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) {
+                    if (audioDevice.getType() == AudioDevice.Type.Speaker) {
+                        call.setOutputAudioDevice(audioDevice);
+                    }
+                }
+            }
+        }
+        return call;
+    }
+
+    /**
+     * 鍛煎彨鎸囧畾鍙风爜
+     *
+     * @param num 鍛煎彨鍙风爜
+     */
+    public void callTo(String num, boolean isVideoCall) {
+        if (!HDLLinphoneService.isReady() || !HDLLinphoneService.getCoreIsNotNull()) {
+            return;
+        }
+        if (!num.equals("")) {
+            startSingleCallingTo(num, isVideoCall);
+        }
+    }
+
+    /**
+     * 鎺ュ惉鏉ョ數
+     */
+    public void acceptCall() {
+        try {
+            if (HDLLinphoneService.getCore() == null) return;
+            Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
+            CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall);
+            params.enableVideo(true);
+            params.enableLowBandwidth(false);
+            params.setAudioBandwidthLimit(0); // disable limitation
+            currentCall.acceptWithParams(params);
+            Log.d("HDLLinphoneKit","---acceptCall= ");
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 鎺ュ惉鏉ョ數
+     */
+    public void acceptCallWithVideo(boolean enableVideo) {
+        try {
+            if (HDLLinphoneService.getCore() == null) return;
+            Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
+            CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall);
+            params.enableVideo(enableVideo);
+            params.setAudioBandwidthLimit(enableVideo ? 0 : 40);
+            currentCall.acceptWithParams(params);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 鎸傛柇鐢佃瘽
+     */
+    public void hangUp() {
+        Core mLinphoneCore = HDLLinphoneService.getCore();
+        if (mLinphoneCore == null) return;
+        Call currentCall = mLinphoneCore.getCurrentCall();
+        if (currentCall != null) {
+//            mLinphoneCore.terminateCall(currentCall);
+            mLinphoneCore.terminateAllCalls();
+        } else if (mLinphoneCore.isInConference()) {
+            mLinphoneCore.terminateConference();
+        } else {
+            mLinphoneCore.terminateAllCalls();
+        }
+    }
+
+    /**
+     * 鏄惁闈欓煶
+     *
+     * @param isMicMuted
+     */
+    public void toggleMicro(boolean isMicMuted) {
+        Core mLinphoneCore = HDLLinphoneService.getCore();
+        if (mLinphoneCore == null) return;
+        mLinphoneCore.enableMic(!isMicMuted);
+    }
+
+    /**
+     * 鏄惁澶栨斁
+     *
+     * @param isSpeakerEnabled
+     */
+    public void toggleSpeaker(boolean isSpeakerEnabled) {
+        routeAudioToSpeakerHelper(isSpeakerEnabled);
+    }
+
+    /**
+     * 璁剧疆澶栨斁璁惧
+     */
+    private void routeAudioToSpeakerHelper(boolean speakerOn) {
+        Log.d("HDLLinphoneKit","璁剧疆澶栨斁璁惧[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece"));
+        try {
+            if (HDLLinphoneService.getCore() == null) return;
+            if (HDLLinphoneService.getCore().getCallsNb() == 0) return;
+            Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
+            if (currentCall == null) currentCall = HDLLinphoneService.getCore().getCalls()[0];
+            if (currentCall == null) return;
+
+            for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) {
+                Log.d("HDLLinphoneKit","audioDevice.getType()= " + audioDevice.getType());
+            }
+
+            for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) {
+                Log.d("HDLLinphoneKit","璁剧疆澶栨斁璁惧speakerOn=" + speakerOn + " audioDevice.getType()=" + audioDevice.getType());
+                if (speakerOn && audioDevice.getType() == AudioDevice.Type.Speaker) {
+                    currentCall.setOutputAudioDevice(audioDevice);
+                    Log.d("HDLLinphoneKit","AudioDevice.Type.Speaker");
+                    return;
+                } else if (!speakerOn && audioDevice.getType() == AudioDevice.Type.Earpiece) {
+                    currentCall.setOutputAudioDevice(audioDevice);
+                    return;
+                }
+            }
+            currentCall.setSpeakerVolumeGain(1.0f);
+            currentCall.setSpeakerMuted(speakerOn);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 璁剧疆 TextureView
      *
      * @param renderingView 杩滅▼ TextureView
      * @param previewView   鏈湴 TextureView
      */
     public void setAndroidVideoWindow(final TextureView renderingView, final TextureView previewView) {
-        mRenderingView = renderingView;
-        mPreviewView = previewView;
+//        mRenderingView = renderingView;
+//        mPreviewView = previewView;
         setVideoWindow(renderingView);
         setPreviewWindow(previewView);
 
     }
 
     /**
-     * onResume
+     * 璁剧疆鎾斁View
+     *
+     * @param o
      */
-    public void onResume() {
-//        if (mRenderingView != null) {
-//            ((TextureView) mRenderingView).onResume();
-//        }
-
-//        if (mAndroidVideoWindow != null) {
-//            synchronized (mAndroidVideoWindow) {
-//                LinphoneManager.getLc().setNativeVideoWindowId(mAndroidVideoWindow);
-//            }
-//        }
-    }
-
-    /**
-     * onPause
-     */
-    public void onPause() {
-//        if (mAndroidVideoWindow != null) {
-//            synchronized (mAndroidVideoWindow) {
-//                LinphoneManager.getLc().setNativeVideoWindowId(null);
-//            }
-//        }
-//
-//        if (mRenderingView != null) {
-//            ((GLSurfaceView) mRenderingView).onPause();
-//        }
-    }
-
-    /**
-     * onDestroy
-     */
-    public void onDestroy() {
-        mPreviewView = null;
-        mRenderingView = null;
-
-    }
-
-//    private void fixZOrder(SurfaceView rendering, SurfaceView preview) {
-//        rendering.setZOrderOnTop(false);
-//        preview.setZOrderOnTop(true);
-//        preview.setZOrderMediaOverlay(true); // Needed to be able to display control layout over
-//    }
-
     private void setVideoWindow(Object o) {
         Core linphoneCore = HDLLinphoneService.getCore();
         if (linphoneCore != null) {
@@ -402,6 +615,9 @@
         }
     }
 
+    /**
+     * 绉婚櫎鎾斁View
+     */
     private void removeVideoWindow() {
         Core linphoneCore = HDLLinphoneService.getCore();
         if (linphoneCore != null) {
@@ -409,6 +625,11 @@
         }
     }
 
+    /**
+     * 璁剧疆鏈満鎽勫儚澶撮噰闆嗙殑View
+     *
+     * @param o
+     */
     private void setPreviewWindow(Object o) {
         Core linphoneCore = HDLLinphoneService.getCore();
         if (linphoneCore != null) {
@@ -416,6 +637,9 @@
         }
     }
 
+    /**
+     * 绉婚櫎瑙嗛閲囬泦View
+     */
     private void removePreviewWindow() {
         Core linphoneCore = HDLLinphoneService.getCore();
         if (linphoneCore != null) {
@@ -423,27 +647,26 @@
         }
     }
 
-//    /**
-//     * 鑾峰彇 LinphoneCore
-//     *
-//     * @return LinphoneCore
-//     */
-//    public Core getLC() {
-//        return HDLLinphoneService.getCore();
-//    }
-
     /**
      * 鑾峰彇褰撳墠閫氳瘽鐘舵��
      */
     public Call.State getCallState() {
-        return HDLLinphoneService.getInstance().getCurrentCallState();
+        if (HDLLinphoneService.getInstance() == null) {
+            return null;
+        } else {
+            return HDLLinphoneService.getInstance().getCurrentCallState();
+        }
     }
 
     /**
      * 鑾峰彇褰撳墠閫氳瘽鐘舵�佹槸鍚︿负鏉ョ數涓�
      */
     public boolean isIncomingReceivedCallState() {
-        return HDLLinphoneService.getInstance().getCurrentCallState() == Call.State.IncomingReceived;
+        if (HDLLinphoneService.getInstance() == null || HDLLinphoneService.getInstance().getCurrentCallState() == null) {
+            return false;
+        } else {
+            return (HDLLinphoneService.getInstance().getCurrentCallState() == Call.State.IncomingReceived);
+        }
     }
 
     /**
@@ -452,6 +675,12 @@
     public boolean isAutoJumpCallView() {
         return isAutoJumpCallView;
     }
+
+    /**
+     * 璁剧疆鏄惁鑷姩璺宠浆鍛煎彨椤甸潰鏍囧織
+     *
+     * @param autoJumpCallView
+     */
     public void setAutoJumpCallView(boolean autoJumpCallView) {
         isAutoJumpCallView = autoJumpCallView;
     }
@@ -491,12 +720,29 @@
      */
     private OnHDLLinphoneCallListener mOnHDLLinphoneCallListener;
 
+    /**
+     * 鑾峰彇onHDLLinphoneCallListener
+     * 鎺ュ惉銆佹寕鏂�佸紑閿佺瓑 Listener瀹炵幇
+     *
+     * @return OnHDLLinphoneCallListener
+     */
     public OnHDLLinphoneCallListener getOnHDLLinphoneCallListener() {
         return mOnHDLLinphoneCallListener;
     }
 
+    /**
+     * 璁剧疆onHDLLinphoneCallListener
+     *
+     * @param onHDLLinphoneCallListener
+     */
     public void setOnHDLLinphoneCallListener(OnHDLLinphoneCallListener onHDLLinphoneCallListener) {
         mOnHDLLinphoneCallListener = onHDLLinphoneCallListener;
     }
 
+    /**
+     * showToast
+     */
+    private void showToast(String text) {
+        Toast.makeText(viewContext, text, Toast.LENGTH_SHORT).show();
+    }
 }

--
Gitblit v1.8.0