From 5dc625a64cf58d798929f22c3073cd06b837f87a Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期四, 25 十一月 2021 16:44:57 +0800
Subject: [PATCH] 2021-11-25 1.更新

---
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java |   82 +++++++++++++++++++++++------------------
 1 files changed, 46 insertions(+), 36 deletions(-)

diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java
index 8772ac9..e84e103 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java
@@ -175,12 +175,18 @@
     public void onDestroy() {
         removeAllCallback();
         logout();
-        mCore.removeListener(mCoreListener);
-        mTimer.cancel();
-        mCore.stop();
-        // A stopped Core can be started again
-        // To ensure resources are freed, we must ensure it will be garbage collected
-        mCore = null;
+
+        if(mTimer != null) {
+            mTimer.cancel();
+        }
+
+        if(mCore != null){
+            mCore.removeListener(mCoreListener);
+            mCore.stop();
+            // A stopped Core can be started again
+            // To ensure resources are freed, we must ensure it will be garbage collected
+            mCore = null;
+        }
         // Don't forget to free the singleton as well
         sInstance = null;
 
@@ -202,6 +208,7 @@
      * 鍒濆鍖朙inphone
      */
     private void initLinphone() {
+        currentCallState = Call.State.Idle;
         String basePath = getFilesDir().getAbsolutePath();
         Factory.instance().setLogCollectionPath(basePath);
         Factory.instance().enableLogCollection(LogCollectionState.Enabled);
@@ -309,42 +316,42 @@
                 HDLLog.E(userCerts + " can't be created.");
             }
         }
-        //璁剧疆UserAgent
-        setUserAgent();
 
+        //1.璁剧疆瀛樺偍鐢ㄦ埛x509璇佷功鐨勭洰褰曠殑璺緞
         mCore.setUserCertificatesPath(userCerts);
+        //2.璁剧疆UserAgent
+        setUserAgent();
+        //3.璁剧疆鎾斁閾冨0
 //        mCore.setNativeRingingEnabled(true);
 //        mCore.setRemoteRingbackTone(mRingSoundFile);
 //        mCore.setTone(ToneID.CallWaiting, mRingSoundFile);
-        mCore.setRing(mRingSoundFile);
+//        mCore.setRing(mRingSoundFile);
 //        mCore.setPlayFile(mPauseSoundFile);
+        //4.绂佺敤鎵嬫満鎽勫儚澶磋棰戦噰闆�
 //        mCore.enableVideoCapture(false);//绂佺敤鎵嬫満鎽勫儚澶磋棰戦噰闆�
-
-        mCore.setNetworkReachable(true);
-        //鍥炲0娑堥櫎
-//        boolean isEchoCancellation = (boolean) SPUtils.get(mServiceContext, "echo_cancellation", true);
-        //鍥炲0娑堥櫎
+//        mCore.setNetworkReachable(true);
+        //5.鍥炲0娑堥櫎
         mCore.enableEchoCancellation(true);
-        mCore.enableEchoLimiter(true);
-
-        //鑷�傚簲鐮佺巼鎺у埗
+//        mCore.enableEchoLimiter(false);
+        mCore.enableMic(true);//鍚敤楹﹀厠椋�
+        //6.鑷�傚簲鐮佺巼鎺у埗
         mCore.enableAdaptiveRateControl(true);
-        //audio 鐮佺巼璁剧疆
+        //7.audio 鐮佺巼璁剧疆
         mCore.getConfig().setInt("audio", "codec_bitrate_limit", 36);
-
+        //8.瑙嗛鐩稿叧璁剧疆
+        mCore.setVideoPreset("custom");//瑙嗛棰勮涓篶ustom
+        mCore.setPreferredFramerate(5);//FPS浼樺厛璁剧疆涓�5
         VideoDefinition preferredVideoDefinition =
                 Factory.instance().createVideoDefinitionFromName("qvga");
-        mCore.setPreferredVideoDefinition(preferredVideoDefinition);
-
-        mCore.setUploadBandwidth(1536);
-        mCore.setDownloadBandwidth(1536);
-
-        mCore.getConfig().setBool("app", "open_h264_download_enabled", true);
+        mCore.setPreferredVideoDefinition(preferredVideoDefinition);//瑙嗛灏哄鍋忓ソ榛樿qvga
+        //9.璁剧疆甯﹀闄愬埗锛屽甫瀹藉崟浣嶄负kbits/s, 0琛ㄧず鏃犻檺
+//        mCore.setUploadBandwidth(1536);
+//        mCore.setDownloadBandwidth(1536);
+        //10.璁剧疆瑙嗛鐨勯粯璁ょ瓥鐣�
         VideoActivationPolicy vap = mCore.getVideoActivationPolicy();
         vap.setAutomaticallyInitiate(true);
         mCore.setVideoActivationPolicy(vap);
-
-        // 璁剧疆缂栫爜鏍煎紡
+        //11.璁剧疆缂栫爜鏍煎紡
         setCodecMime();
     }
 
@@ -352,21 +359,21 @@
      * 璁剧疆缂栫爜鏍煎紡
      */
     private void setCodecMime() {
+        //1.鍚敤PCMA PCMU 8000Hz
         PayloadType[] ptList = mCore.getAudioPayloadTypes();
         for (PayloadType pt : ptList) {
-
-            org.linphone.mediastream.Log.d("payloadaudio", pt.getMimeType());
-            if (pt.getMimeType().equals("PCMA") && pt.getClockRate() == 8000) {
+//           HDLLog.i("payloadaudio", pt.getMimeType());
+            if ((pt.getMimeType().equals("PCMA") || pt.getMimeType().equals("PCMU")) && pt.getClockRate() == 8000) {
                 pt.enable(true);
-
             } else {
                 pt.enable(false);
             }
         }
         mCore.setAudioPayloadTypes(ptList);
-
+        //2.璁剧疆VP8銆丠264銆丠265 绛夊惎鐢�
         PayloadType[] ptVideoList = mCore.getVideoPayloadTypes();
         for (PayloadType pt : ptVideoList) {
+//            HDLLog.i("VideoPayload", pt.getMimeType());
             pt.enable(true);
         }
         mCore.setVideoPayloadTypes(ptVideoList);
@@ -448,10 +455,13 @@
             // The factory config is used to override any other setting, let's copy it each time
             copyFromPackage(R.raw.linphonerc_factory, "linphonerc");
             mRingSoundFile = basePath + "/oldphone_mono.wav";
-            copyIfNotExist(R.raw.oldphone_mono, basePath + "/oldphone_mono.wav");
-            copyIfNotExist(R.raw.ringback, basePath + "/ringback.wav");
-            mPauseSoundFile = basePath + "/toy_mono.wav";
-            copyIfNotExist(R.raw.toy_mono, basePath + "/toy_mono.wav");
+            copyIfNotExist(R.raw.oldphone_mono, mRingSoundFile);
+//            copyIfNotExist(R.raw.ringback, basePath + "/ringback.wav");
+//            mPauseSoundFile = basePath + "/toy_mono.wav";
+//            copyIfNotExist(R.raw.toy_mono, basePath + "/toy_mono.wav");
+
+            String mLPConfigXsd = basePath + "/lpconfig.xsd";
+            copyIfNotExist(R.raw.lpconfig, mLPConfigXsd);
 
         } catch (IOException ioe) {
             Log.e(ioe);

--
Gitblit v1.8.0