//package com.hdl.hdllinphonesdk.core.linphone; // //import android.content.Context; //import android.content.pm.PackageManager; //import android.os.Handler; //import android.os.Looper; // // //import com.hdl.hdllinphonesdk.HDLLinphoneKit; //import com.hdl.hdllinphonesdk.R; // // //import org.linphone.core.AudioDevice; //import org.linphone.core.AuthInfo; //import org.linphone.core.AuthMethod; //import org.linphone.core.Call; //import org.linphone.core.CallLog; //import org.linphone.core.CallStats; //import org.linphone.core.ChatMessage; //import org.linphone.core.ChatRoom; //import org.linphone.core.Conference; //import org.linphone.core.ConfiguringState; //import org.linphone.core.Content; //import org.linphone.core.Core; //import org.linphone.core.CoreException; //import org.linphone.core.CoreListener; //import org.linphone.core.EcCalibratorStatus; //import org.linphone.core.Event; //import org.linphone.core.Factory; //import org.linphone.core.Friend; //import org.linphone.core.FriendList; //import org.linphone.core.GlobalState; //import org.linphone.core.InfoMessage; //import org.linphone.core.PayloadType; //import org.linphone.core.PresenceModel; //import org.linphone.core.ProxyConfig; //import org.linphone.core.PublishState; //import org.linphone.core.RegistrationState; //import org.linphone.core.SubscriptionState; //import org.linphone.core.ToneID; //import org.linphone.core.VersionUpdateCheckResult; //import org.linphone.core.VideoActivationPolicy; //import org.linphone.core.VideoDefinition; //import org.linphone.core.tools.Log; // //import java.io.File; //import java.io.IOException; //import java.nio.ByteBuffer; //import java.util.Timer; //import java.util.TimerTask; // //import static com.hdl.hdllinphonesdk.HDLLinphoneKit.HDLLinphoneKitNAME; // ///** // * Linphone 管理器 // */ // //public class LinphoneManager implements CoreListener { // private static final String TAG = "LinphoneManager"; // private static LinphoneManager instance; // private Context mServiceContext; // private Core mLc; // private Timer mTimer; // private static boolean sExited; // // private String mLPConfigXsd = null; // private String mLinphoneFactoryConfigFile = null; // public String mLinphoneConfigFile = null; // private String mLinphoneRootCaFile = null; // private String mRingSoundFile = null; // private String mRingBackSoundFile = null; // private String mPauseSoundFile = null; // private String mChatDatabaseFile = null; // // //// private String mErrorToneFile = null; // // public LinphoneManager(Context serviceContext) { // mServiceContext = serviceContext; // Factory.instance().setDebugMode(true, HDLLinphoneKitNAME); // sExited = false; // // String basePath = mServiceContext.getFilesDir().getAbsolutePath(); // mLPConfigXsd = basePath + "/lpconfig.xsd"; // mLinphoneFactoryConfigFile = basePath + "/linphonerc"; // mLinphoneConfigFile = basePath + "/.linphonerc"; // mLinphoneRootCaFile = basePath + "/rootca.pem"; // mRingSoundFile = basePath + "/oldphone_mono.wav"; // mRingBackSoundFile = basePath + "/ringback.wav"; // mPauseSoundFile = basePath + "/toy_mono.wav"; // mChatDatabaseFile = basePath + "/linphone-history.db"; //// mErrorToneFile = basePath + "/error.wav"; // } // // public synchronized static final LinphoneManager createAndStart(Context context) { // if (instance != null) { // throw new RuntimeException("Linphone Manager is already initialized"); // } // instance = new LinphoneManager(context); // instance.startLibLinphone(context); // return instance; // } // // public static synchronized Core getLcIfManagerNotDestroyOrNull() { // if (sExited || instance == null) { // Log.e("Trying to get linphone core while LinphoneManager already destroyed or not created"); // return null; // } // return getLc(); // } // // public static final boolean isInstanceiated() { // return instance != null; // } // // public static synchronized final Core getLc() { // return getInstance().mLc; // } // // public static synchronized final LinphoneManager getInstance() { // if (instance != null) { // return instance; // } // if (sExited) { // throw new RuntimeException("Linphone Manager was already destroyed. " // + "Better use getLcIfManagerNotDestroyed and check returned value"); // } // throw new RuntimeException("Linphone Manager should be created before accessed"); // } // // private synchronized void startLibLinphone(Context context) { // try { // copyAssetsFromPackage(); //// mLc = Factory.instance().createCore(this, mLinphoneConfigFile, //// mLinphoneFactoryConfigFile, null, context); // mLc = Factory.instance().createCore( mLinphoneConfigFile, // mLinphoneFactoryConfigFile, context); // mLc.addListener((CoreListener)context); // // try { // initLibLinphone(); // } catch (CoreException e) { // Log.e(e); // } // // TimerTask task = new TimerTask() { // @Override // public void run() { // new Handler(Looper.getMainLooper()).post(new Runnable() { // @Override // public void run() { // if (mLc != null) { // mLc.iterate(); // } // } // }); // } // }; // mTimer = new Timer("Linphone Scheduler"); // mTimer.schedule(task, 0, 20); // } catch (Exception e) { // e.printStackTrace(); // Log.e(TAG, "startLibLinphone: cannot start linphone"); // } // } // // private synchronized void initLibLinphone() throws CoreException { //// mLc.setContext(mServiceContext); // setUserAgent(); // mLc.setRemoteRingbackTone(mRingSoundFile); // mLc.setTone(ToneID.CallWaiting, mRingSoundFile); // mLc.setRing(mRingSoundFile); //// mLc.setRootCA(mLinphoneRootCaFile); // mLc.setPlayFile(mPauseSoundFile); //// mLc.setChatDatabasePath(mChatDatabaseFile); // mLc.enableIpv6(true); // mLc.enableDnsSrv(true); //// mLc.setCallErrorTone(Reason.NotFound, mErrorToneFile);//设置呼叫错误播放的铃声 // // setBackCamAsDefault(); // // int availableCores = Runtime.getRuntime().availableProcessors(); // Log.w(TAG, "MediaStreamer : " + availableCores + " cores detected and configured"); //// mLc.setCpuCount(availableCores); // // int migrationResult = getLc().migrateToMultiTransport(); // Log.d(TAG, "Migration to multi transport result = " + migrationResult); // // mLc.setNetworkReachable(true); // // //回声消除 //// boolean isEchoCancellation = (boolean) SPUtils.get(mServiceContext, "echo_cancellation", true); // mLc.enableEchoCancellation(true); // //自适应码率控制 //// boolean isAdaptiveRateControl = (boolean) SPUtils.get(mServiceContext, "adaptive_rate_control", true); // mLc.enableAdaptiveRateControl(true); // // //audio 码率设置 // LinphoneUtils.getConfig(mServiceContext).setInt("audio", "codec_bitrate_limit", 36); // //// mLc.setPreferredVideoSizeByName("qvga"); // // VideoDefinition preferredVideoDefinition = // Factory.instance().createVideoDefinitionFromName("qvga"); // getLc().setPreferredVideoDefinition(preferredVideoDefinition); // // mLc.setUploadBandwidth(1536); // mLc.setDownloadBandwidth(1536); // mLc.setVideoPreset("custom"); // //// mLc.setVideoPolicy(mLc.getVideoAutoInitiatePolicy(), true); //// mLc.setVideoPolicy(true, mLc.getVideoAutoAcceptPolicy()); //// mLc.enableVideo(true, true); //// mLc.enableDownloadOpenH264(true); // // mLc.enableVideoCapture(true); // mLc.enableVideoDisplay(true); // mLc.getConfig().setBool("app", "open_h264_download_enabled", true); // VideoActivationPolicy vap = getLc().getVideoActivationPolicy(); // vap.setAutomaticallyInitiate(true); // mLc.setVideoActivationPolicy(vap); // // // 设置编码格式 // setCodecMime(); // //// IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); //// filter.addAction(Intent.ACTION_SCREEN_OFF); //// mServiceContext.registerReceiver(mKeepAliveReceiver, filter); // } // // private void setCodecMime() { //// for (PayloadType payloadType : mLc.getAudioCodecs()) { //// try { //// mLc.enablePayloadType(payloadType, true); //// } catch (CoreException e) { //// e.printStackTrace(); //// } ////// android.util.Log.e(TAG, "setCodecMime = " + payloadType.getMime() + " Rate " + payloadType.getRate() + " receviceFmtp " + payloadType.getRecvFmtp()); ////// if (payloadType.getMime().equals("PCMA") && payloadType.getRate() == 8000) { ////// try { ////// android.util.Log.e(TAG, "setCodecMime: " + payloadType.getMime() + " " + payloadType.getRate()); ////// mLc.enablePayloadType(payloadType, true); ////// } catch (CoreException e) { ////// android.util.Log.e(TAG, "setCodecMime: " + e); ////// } ////// } else { ////// try { ////// mLc.enablePayloadType(payloadType, false); ////// } catch (CoreException e) { ////// e.printStackTrace(); ////// } ////// } //// } //// for (PayloadType payloadType : mLc.getVideoCodecs()) { //// try { //// android.util.Log.e(TAG, "setCodecMime: mime: " + payloadType.getMime() + " rate: " + payloadType.getRate()); //// mLc.enablePayloadType(payloadType, true); //// } catch (CoreException e) { //// e.printStackTrace(); //// } //// } // // PayloadType[] ptList = mLc.getAudioPayloadTypes(); // for (PayloadType pt : ptList) { // // org.linphone.mediastream.Log.d("payloadaudio",pt.getMimeType()); // if (pt.getMimeType().equals("PCMA") && pt.getClockRate() == 8000) { // pt.enable(true); // // } else { // pt.enable(false); // } // } // mLc.setAudioPayloadTypes(ptList); // // PayloadType[] ptVideoList = mLc.getVideoPayloadTypes(); // for (PayloadType pt : ptVideoList) { // pt.enable(true); // } // mLc.setVideoPayloadTypes(ptVideoList); // } // // private void copyAssetsFromPackage() throws IOException { // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.oldphone_mono, mRingSoundFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.ringback, mRingBackSoundFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.toy_mono, mPauseSoundFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.linphonerc_default, mLinphoneConfigFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.linphonerc_factory, new File(mLinphoneFactoryConfigFile).getName()); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.lpconfig, mLPConfigXsd); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.rootca, mLinphoneRootCaFile); // } // // private void setUserAgent() { // try { // String versionName = mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), // 0).versionName; // if (versionName == null) { // versionName = String.valueOf(mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionCode); // } // mLc.setUserAgent(HDLLinphoneKitNAME, versionName); // } catch (PackageManager.NameNotFoundException e) { // e.printStackTrace(); // } // } // // public static synchronized void destroy() { // if (instance == null) { // return; // } // sExited = true; // instance.doDestroy(); // } // // private void doDestroy() { // try { // mTimer.cancel(); // mLc.stop(); // } catch (RuntimeException e) { // e.printStackTrace(); // } finally { // mLc = null; // instance = null; // } // } // // // private void setBackCamAsDefault() { //// int camId = 0; //// AndroidCameraConfiguration.AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras(); //// for (AndroidCameraConfiguration.AndroidCamera androidCamera : //// cameras) { //// if (!androidCamera.frontFacing) { //// camId = androidCamera.id; //// } //// } //// android.util.Log.e(TAG, "setBackCamAsDefault: cameraId is " + camId); //// mLc.setVideoDevice(0); // } // // @Override // public void onQrcodeFound(Core core, String result) { // // } // // @Override // public void onInfoReceived(Core core, Call call, InfoMessage message) { // // } // // @Override // public void onTransferStateChanged(Core core, Call transfered, Call.State callState) { // // } // // @Override // public void onCallEncryptionChanged(Core core, Call call, boolean mediaEncryptionEnabled, String authenticationToken) { // // } // // @Override // public void onEcCalibrationAudioInit(Core core) { // // } // // @Override // public void onDtmfReceived(Core core, Call call, int dtmf) { // // } // // @Override // public void onChatRoomStateChanged(Core core, ChatRoom chatRoom, ChatRoom.State state) { // // } // // @Override // public void onLogCollectionUploadStateChanged(Core core, Core.LogCollectionUploadState state, String info) { // // } // // @Override // public void onAudioDevicesListUpdated(Core core) { // // } // // @Override // public void onCallIdUpdated(Core core, String previousCallId, String currentCallId) { // // } // // @Override // public void onMessageSent(Core core, ChatRoom chatRoom, ChatMessage message) { // // } // // @Override // public void onFriendListRemoved(Core core, FriendList friendList) { // // } // // @Override // public void onSubscribeReceived(Core core, Event linphoneEvent, String subscribeEvent, Content body) { // // } // // @Override // public void onAuthenticationRequested(Core core, AuthInfo authInfo, AuthMethod method) { // // } // // @Override // public void onEcCalibrationAudioUninit(Core core) { // // } // // @Override // public void onLogCollectionUploadProgressIndication(Core core, int offset, int total) { // // } // // @Override // public void onImeeUserRegistration(Core core, boolean status, String userId, String info) { // // } // // @Override // public void onRegistrationStateChanged(Core core, ProxyConfig proxyConfig, RegistrationState state, String message) { // // } // // @Override // public void onCallStateChanged(Core core, Call call, Call.State state, String message) { // // } // // @Override // public void onConfiguringStatus(Core core, ConfiguringState status, String message) { // // } // // @Override // public void onGlobalStateChanged(Core core, GlobalState state, String message) { // // } // // @Override // public void onChatRoomEphemeralMessageDeleted(Core core, ChatRoom chatRoom) { // // } // // @Override // public void onFriendListCreated(Core core, FriendList friendList) { // // } // // @Override // public void onBuddyInfoUpdated(Core core, Friend linphoneFriend) { // // } // // @Override // public void onChatRoomSubjectChanged(Core core, ChatRoom chatRoom) { // // } // // @Override // public void onNotifyReceived(Core core, Event linphoneEvent, String notifiedEvent, Content body) { // // } // // @Override // public void onLastCallEnded(Core core) { // // } // // @Override // public void onChatRoomRead(Core core, ChatRoom chatRoom) { // // } // // @Override // public void onNotifyPresenceReceived(Core core, Friend linphoneFriend) { // // } // // @Override // public void onConferenceStateChanged(Core core, Conference conference, Conference.State state) { // // } // // @Override // public void onVersionUpdateCheckResultReceived(Core core, VersionUpdateCheckResult result, String version, String url) { // // } // // @Override // public void onMessageReceived(Core core, ChatRoom chatRoom, ChatMessage message) { // // } // // @Override // public void onCallStatsUpdated(Core core, Call call, CallStats callStats) { // // } // // @Override // public void onFirstCallStarted(Core core) { // // } // // @Override // public void onSubscriptionStateChanged(Core core, Event linphoneEvent, SubscriptionState state) { // // } // // @Override // public void onMessageReceivedUnableDecrypt(Core core, ChatRoom chatRoom, ChatMessage message) { // // } // // @Override // public void onEcCalibrationResult(Core core, EcCalibratorStatus status, int delayMs) { // // } // // @Override // public void onIsComposingReceived(Core core, ChatRoom chatRoom) { // // } // // @Override // public void onReferReceived(Core core, String referTo) { // // } // // @Override // public void onNetworkReachable(Core core, boolean reachable) { // // } // // @Override // public void onPublishStateChanged(Core core, Event linphoneEvent, PublishState state) { // // } // // @Override // public void onAudioDeviceChanged(Core core, AudioDevice audioDevice) { // // } // // @Override // public void onCallLogUpdated(Core core, CallLog callLog) { // // } // // @Override // public void onCallCreated(Core core, Call call) { // // } // // @Override // public void onNotifyPresenceReceivedForUriOrTel(Core core, Friend linphoneFriend, String uriOrTel, PresenceModel presenceModel) { // // } // // @Override // public void onNewSubscriptionRequested(Core core, Friend linphoneFriend, String url) { // // } // //// public void resetCameraFromPreferences(boolean useFrontCam) { //// Core core = getCore(); //// if (core == null) return; //// //// //// String firstDevice = null; //// for (String camera : core.getVideoDevicesList()) { //// if (firstDevice == null) { //// firstDevice = camera; //// } //// //// if (useFrontCam) { //// if (camera.contains("Front")) { //// Log.i("[Manager] Found front facing camera: " + camera); //// core.setVideoDevice(camera); //// return; //// } //// } //// } //// //// Log.i("[Manager] Using first camera available: " + firstDevice); //// core.setVideoDevice(firstDevice); //// } //}