JLChen
2021-11-25 5dc625a64cf58d798929f22c3073cd06b837f87a
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 @@
     * 初始化Linphone
     */
    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.设置播放铃声
//        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);
        //回声消除
//        boolean isEchoCancellation = (boolean) SPUtils.get(mServiceContext, "echo_cancellation", true);
        //回声消除
//        mCore.setNetworkReachable(true);
        //5.回声消除
        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");//视频预设为custom
        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、H264、H265 等启用
        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);