Пример #1
0
        public static bool RegisterClient(string sipServer, string username, string password)
        {
            var regID = username + "@" + sipServer;

            log.Info("invoke register client");
            // log.Info("PLCM_MF_PROP_LocalAddr is " + lalProperties.getProperty(PropertyEnum.PLCM_MF_PROP_LocalAddr));
            log.Info("SIP_PROXY_SERVER_ADDRESS is " + sipServer);
            log.Info("SIP_USERNAME is " + username);
            log.Info("PLCM_MFW_KVLIST_KEY_REG_ID is " + regID);

            WrapperProxy.SetProperty(PropertyEnum.SIP_PROXY_SERVER_ADDRESS, sipServer);
            WrapperProxy.SetProperty(PropertyEnum.SIP_USERNAME, username);
            WrapperProxy.SetProperty(PropertyEnum.SIP_PASSWORD, password);
            WrapperProxy.SetProperty(PropertyEnum.PLCM_MFW_KVLIST_KEY_REG_ID, regID);
            WrapperProxy.UpdateConfig();
            var errNo = WrapperProxy.RegisterClient();

            log.Info("registerClient, registerClient errNo=" + errNo);

            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Register failed. Error number = " + errNo.ToString());
                return(false);
            }
            lalProperties.SetProperty(PropertyEnum.SIP_PROXY_SERVER_ADDRESS, sipServer);
            lalProperties.SetProperty(PropertyEnum.SIP_USERNAME, username);
            lalProperties.SetProperty(PropertyEnum.SIP_PASSWORD, password);
            lalProperties.SetProperty(PropertyEnum.PLCM_MFW_KVLIST_KEY_REG_ID, regID);
            return(true);
        }
Пример #2
0
 public static bool Hangup(bool isAuto)
 {
     if (false == isAuto)
     {
         var call = callManager.CurrentCall;
         if (null == call)
         {
             log.Error("Terminating a NULL call.");
             return(false);
         }
         log.Info("normally terminate a call");
         var errno = WrapperProxy.TerminateCall(call.CallHandle);
         if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
         {
             log.Error("Hangup a Call failed. ErrorNum = " + errno.ToString());
             return(false);
         }
     }
     else
     {//automatically hang up a call
         var unestablishedCalls = callManager.GetUnestablishedCalls();
         foreach (var unestablishedCall in unestablishedCalls)
         {
             log.Info("automaticall hang up a call");
             var errno = WrapperProxy.TerminateCall(unestablishedCall.CallHandle);
             if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
             {
                 log.Error("automatically Hangup a Call failed. ErrorNum = " + errno.ToString());
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #3
0
        /**
         * detach stream from video window
         * @param mediaType: stream mediaType- local, remote, PIP and content
         * @return true: successfully detached; false: fail to detach
         * */
        public static bool DetachStreamFromWindow(MediaTypeEnum mediaType, int streamId, int callHandle)
        {
            log.Debug("[detachStreamFromWindow] mediatype " + mediaType.ToString() + " from video window.");
            if (mediaType != MediaTypeEnum.PLCM_MF_STREAM_LOCAL)
            {
                if (invalidCallHandle != callHandle)
                {
                    var errNo = WrapperProxy.DetachStreamWnd(mediaType, streamId, callHandle);
                    if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
                    {
                        log.Error("detach stream from window failed. Error number = " + errNo.ToString());
                        return(false);
                    }
                }
                else
                {
                    log.Error("no such call to detach stream window");
                    return(false);
                }
            }
            else
            {//for local preview
             //when the media type is local, set the call handle to -1 (invalid call handle)
                var errNo = WrapperProxy.DetachStreamWnd(mediaType, streamId, invalidCallHandle);
                if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
                {
                    log.Error("detach stream from window failed. Error number = " + errNo.ToString());
                    return(false);
                }
            }

            return(true);
        }
Пример #4
0
        public static bool Hold(bool isAuto)
        {
            List <Call> calls = new List <Call>();

            if (true == isAuto)
            {
                log.Info("automatically hold the active or held call now");
                calls.AddRange(callManager.GetActiveCalls());
                calls.AddRange(callManager.GetHeldCalls());
            }
            else
            {
                log.Info(" hold the current call now");
                var currentCall = callManager.CurrentCall;
                if (null != currentCall)
                {
                    calls.Add(currentCall);
                }
            }
            foreach (var holdCall in calls)
            {
                var errno = WrapperProxy.HoldCall(holdCall.CallHandle);
                if (ErrorNumberEnum.PLCM_SAMPLE_OK != errno)
                {
                    log.Error("hold a call failed." + "callHanlde is: " + holdCall.CallHandle +
                              ".Error number = " + errno.ToString());
                    return(false);
                }
            }
            return(true);
        }
Пример #5
0
        /**
         * User agent hang up the current call.
         * @param isAuto: true: when the call is not established, incoming another call, automatically hang up the
         * not-established call; false: user normally hang up a connected call
         * @return true: successful; false: fail
         */
        public static bool Hangup(Call call)
        {
            var errno = WrapperProxy.TerminateCall(call.CallHandle);

            if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                log.Error("Hangup a Call failed. ErrorNum = " + errno.ToString());
                return(false);
            }
            return(true);
        }
Пример #6
0
        /**
         * User agent resume the held current call.
         * @return true: successful; false: fail
         */
        public static bool Resume(Call call)
        {
            var errno = WrapperProxy.ResumeCall(call.CallHandle);

            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errno)
            {
                log.Error("resume a call failed." + "callHanlde is: " + call.CallHandle +
                          ".Error number = " + errno.ToString());
                return(false);
            }
            return(true);
        }
Пример #7
0
        public static bool MuteSpeaker(bool isMute)
        {
            log.Debug("[muteSpeaker]");
            var errno = WrapperProxy.MuteSpeaker(isMute);

            if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                log.Error("mute speaker for a Call failed. ErrorNum = " + errno.ToString());
                return(false);
            }
            return(true);
        }
Пример #8
0
        public static bool AttachStreamToWindow(IntPtr wndHandle, int callHandle, MediaTypeEnum mediaType, int streamId, int width, int height)
        {
            log.Debug("[attachStreamToWindow] callHandle:" + callHandle + " mediatype:" + mediaType.ToString() + " streamId:" + streamId + " to window(width: " + width + " height: " + height + " )");
            var errNo = WrapperProxy.AttachStreamWnd(mediaType, streamId, callHandle, wndHandle, 0, 0, width, height);

            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("attach stream to window failed. Error number = " + errNo.ToString());
                return(false);
            }
            return(true);
        }
Пример #9
0
        /**
         * used to stop camera
         * */
        public static bool StopCamera()
        {
            log.Debug("[stopCamera]");
            var errNo = WrapperProxy.StopCamera();

            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("stop camera failed. ErrorNum = " + errNo.ToString());
                return(false);
            }
            return(true);
        }
Пример #10
0
        public void start()
        {
            autoEvent = new AutoResetEvent(false);
            isRunning = true;
            var thread = new Thread(() =>
            {
                while (isRunning)
                {
                    log.Info("handle the evt");
                    if (queue.Count() == 0)
                    {
                        lock (synObject)
                        {
                            log.Info("No evt, wait..");
                            //queue.wait();
                            autoEvent.WaitOne();
                        }
                    }
                    log.Info("EventQ getEvent: total = " + queue.Count());
                    while (queue.Count() > 0)
                    {
                        Event evt = null;
                        lock (synObject)
                        {
                            evt = queue.Dequeue();
                        }
                        // dispatch Event to proper modules
                        if (evt == null)
                        {
                            log.Error("Event is null!");
                            continue;
                        }
                        if (null != Dispatcher)
                        {
                            try
                            {
                                Dispatcher.Invoke(new Action(() =>
                                {
                                    DoEvent(evt);
                                }));
                            }catch (Exception ex)
                            {
                                log.Error(ex.Message);
                            }
                        }
                        WrapperProxy.FreeEvent(evt.EventHandle);
                    }
                }
            });

            thread.Start();
        }
Пример #11
0
        /***
         * mute/unmute the localvideo
         * @para hide: true-hide the local video; false-display the local video
         * @return true: successful; false-fail
         * */
        public static bool MuteLocalVideo(bool isHide)
        {
            log.Debug("[muteLocalVideo]" + isHide);
            //isMuteLocalVideo = hide;
            var errno = WrapperProxy.MuteLocalVideo(isHide);

            if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                log.Error("mute local video failed. ErrorNum = " + errno.ToString());
                return(false);
            }
            return(true);
        }
Пример #12
0
        public static bool Resume()
        {
            var heldCalls = callManager.GetHeldCalls();

            foreach (var call in heldCalls)
            {
                var errno = WrapperProxy.ResumeCall(call.CallHandle);
                if (ErrorNumberEnum.PLCM_SAMPLE_OK != errno)
                {
                    log.Error("resume a call failed." + "callHanlde is: " + call.CallHandle +
                              ".Error number = " + errno.ToString());
                    return(false);
                }
            }
            return(true);
        }
Пример #13
0
        public void AddDevice(Device device)
        {
            if (device.DeviceName.Contains("none"))
            {
                return;
            }
            devices.Add(device);
            switch (device.DeviceType)
            {
            case DeviceTypeEnum.AUDIO_INPUT:
            case DeviceTypeEnum.AUDIO_OUTPUT:
            {
                var audioInput   = GetDevicesByType(DeviceTypeEnum.AUDIO_INPUT).FirstOrDefault();
                var audioOutput  = GetDevicesByType(DeviceTypeEnum.AUDIO_OUTPUT).FirstOrDefault();
                var inputHandle  = audioInput?.DeviceHandle;
                var outputHandle = audioOutput?.DeviceHandle;
                if (null == CurrentAudioInputDevice && null != audioInput)
                {
                    CurrentAudioInputDevice = audioInput;
                    WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                    WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                }
                if (null == CurrentAudioOutputDevice && null != outputHandle)
                {
                    CurrentAudioOutputDevice = audioOutput;
                    WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                    WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                }
            }
            break;

            case DeviceTypeEnum.VIDEO_INPUT:
            {
                if (null == CurrentAudioOutputDevice)
                {
                    var video       = GetDevicesByType(DeviceTypeEnum.VIDEO_INPUT).FirstOrDefault();
                    var videoHandle = video?.DeviceHandle;
                    if (null != videoHandle)
                    {
                        CurrentVideoInputDevice = video;
                        WrapperProxy.SetVideoDevice(videoHandle);
                    }
                }
            } break;
            }
        }
Пример #14
0
        /***
         * mute/unmute the mirophone
         * @para mute: true-mute the microphone; false-unmute the mircophone
         * @return true: successful; false-fail
         * */
        public static bool MuteMic(Call call, bool isMute)
        {
            log.Debug("[muteMic]");
            if (null == call)
            {
                log.Error("unmute/mute a NULL call.");
                return(false);
            }
            var errno = WrapperProxy.MuteMic(call.CallHandle, isMute);

            if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                log.Error("mute a Call failed. ErrorNum = " + errno.ToString());
                return(false);
            }
            call.IsMute = isMute;
            return(true);
        }
Пример #15
0
        public static bool Answer(int callHandle, CallModeEnum callMode, bool sutLiteEnable)
        {
            var errno = ErrorNumberEnum.PLCM_SAMPLE_OK;

            string CryptoSuiteType = "AES_CM_128_HMAC_SHA1_80";
            string SRTPKey         = "HfVGG79oW5XStt9DewUYrdngYlV/QqDBGIDNFB7m";
            var    m_authToken     = "AApzdG1lZXRpbmcxAAdzdHVzZXIxAAABPcJe1o4CsXgvirq1RQys3JCU0U8RvJ4uoA==";

            log.Debug("[answer], CryptoSuiteType=" + CryptoSuiteType + "  SRTPKey:" + SRTPKey);
            errno = WrapperProxy.AnswerCall(callHandle, callMode, m_authToken, CryptoSuiteType, SRTPKey, sutLiteEnable);

            if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                log.Error("Answer a Call failed. ErrorNum = " + errno.ToString());
                return(false);
            }
            return(true);
        }
Пример #16
0
        public static void LoadSettingsFromConfFile(bool isUpdateKVList)
        {
            var errNo        = ErrorNumberEnum.PLCM_SAMPLE_OK;
            var propertyMaps = PropertyEnumMap.GetPropertiesMaps();
            var properties   = lalProperties.GetProperties();

            foreach (var map in propertyMaps)
            {
                var key = map.Key;
                var val = confManager.GetPropertyFromConfigFile(key);
                if (null != val)
                {
                    if (PropertyEnum.NULL != key)
                    {
                        switch (key)
                        {
                        case PropertyEnum.SIP_PROXY_SERVER_ADDRESS:
                        case PropertyEnum.SIP_USERNAME:
                        case PropertyEnum.SIP_PASSWORD:
                        case PropertyEnum.PLCM_MFW_KVLIST_KEY_REG_ID:
                        {
                            val = string.Empty;
                        }
                        break;
                        }
                        lalProperties.SetProperty(key, val);
                        if (isUpdateKVList)
                        {
                            errNo = WrapperProxy.SetProperty(key, properties[key]);
                            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
                            {
                                log.Error("AddProperty failed. Error number = " + errNo.ToString());
                                throw new Exception("AddProperty failed");
                            }
                        }
                    }
                    else
                    {
                        log.Error("no such setting in PropertyEnum for key" + key);
                        throw new Exception("no such setting in PropertyEnum for key" + key);
                    }
                }
            }
        }
Пример #17
0
        public static bool Initialize()
        {
            var errNo = ErrorNumberEnum.PLCM_SAMPLE_OK;

            /*PreInitialize*/
            errNo = WrapperProxy.InstallCallback(addEventCallback, dispatchEventsCallback, addLogCallback, addDeviceCallback,
                                                 displayMediaStatisticsCallback, displayCallStatisticsCallback, displayCodecCapabilities, addAppCallback);
            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Register callback functions failed. Error number = " + errNo.ToString());
                return(false);
            }

            /*in wrapper, create instances, load library*/
            errNo = WrapperProxy.PreInitialize();
            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                var msg = "Pre-initialization failed. Error number = " + errNo.ToString();
                log.Error(msg);
                throw new Exception(msg);
            }

            /* KVList*/
            confManager.LoadFromXML(@"conf\cfg.xml", @"conf\common.xml");
            LoadSettingsFromConfFile(true);


            errNo = WrapperProxy.Initialize();
            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Initialize failed. Error number = " + errNo.ToString());
                return(false);
            }
            var version = WrapperProxy.GetVersion();

            log.Info("**********************************************************************");
            log.Info("        PLCM MFW Sample App Initialized Successful ( version: " + version + " )");
            log.Info("**********************************************************************");

            /*get devices enumerate*/

            return(true);
        }
Пример #18
0
        /**
         * User agent dial out a call.
         * @return successful or failed.
         */
        public static ErrorNumberEnum Dial(string callAddr, CallModeEnum callMode)
        {
            log.Info("place call: callername:" + callAddr);
            int callHandleReference = 0;
            var errno = WrapperProxy.SetProperty(PropertyEnum.PLCM_MF_PROP_CalleeAddr, callAddr);

            if (errno != ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                return(errno);
            }
            lalProperties.SetProperty(PropertyEnum.PLCM_MF_PROP_CalleeAddr, callAddr);
            errno = WrapperProxy.PlaceCall(callAddr, ref callHandleReference, callMode);
            if (errno == ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
            }
            else
            {
                log.Error("Dial a Call failed. ErrorNum = " + errno.ToString());
                return(errno);
            }
            return(errno);
        }
Пример #19
0
        public static void GetDevices()
        {
            var errNo = WrapperProxy.GetDeviceEnum(DeviceTypeEnum.AUDIO_INPUT);

            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Get audio input device failed. Error number = " + errNo.ToString());
            }
            errNo = WrapperProxy.GetDeviceEnum(DeviceTypeEnum.VIDEO_INPUT);
            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Get video input device failed. Error number = " + errNo.ToString());
            }
            errNo = WrapperProxy.GetDeviceEnum(DeviceTypeEnum.AUDIO_OUTPUT);
            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Get audio output device failed. Error number = " + errNo.ToString());
            }
            errNo = WrapperProxy.GetDeviceEnum(DeviceTypeEnum.DEV_MONITOR);
            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("Get monitor device failed. Error number = " + errNo.ToString());
            }
        }
Пример #20
0
        public static bool Answer(bool isVideo, bool sutLiteEnable)
        {
            var currentCall = callManager.CurrentCall;

            if (currentCall == null)
            {
                log.Error("answer a NULL call.");
                return(false);
            }
            var errno = ErrorNumberEnum.PLCM_SAMPLE_OK;

            string CryptoSuiteType = "AES_CM_128_HMAC_SHA1_80";
            string SRTPKey         = "HfVGG79oW5XStt9DewUYrdngYlV/QqDBGIDNFB7m";
            var    m_authToken     = "AApzdG1lZXRpbmcxAAdzdHVzZXIxAAABPcJe1o4CsXgvirq1RQys3JCU0U8RvJ4uoA==";

            log.Debug("[answer], CryptoSuiteType=" + CryptoSuiteType + "  SRTPKey:" + SRTPKey);
            if (isVideo)
            {
                errno = WrapperProxy.AnswerCall(currentCall.CallHandle, CallModeEnum.PLCM_MFW_AUDIOVIDEO_CALL, m_authToken, CryptoSuiteType, SRTPKey, sutLiteEnable);
            }
            else
            {
                errno = WrapperProxy.AnswerCall(currentCall.CallHandle, CallModeEnum.PLCM_MFW_AUDIO_CALL, m_authToken, CryptoSuiteType, SRTPKey, sutLiteEnable);
            }
            if (errno == ErrorNumberEnum.PLCM_SAMPLE_OK)
            {
                /*add the answered call to calllist*/
                callManager.AddCall(currentCall);
            }
            else
            {
                log.Error("Answer a Call failed. ErrorNum = " + errno.ToString());
                return(false);
            }
            return(true);
        }
Пример #21
0
 public void PlaySound(string filePath, bool loop, int interval)
 {
     log.Info("startPlayingAlert filePath:" + filePath);
     WrapperProxy.StartPlayAlert(filePath, loop, interval);
 }
Пример #22
0
        public bool RemoveDevice(string deviceHandle)
        {
            for (int i = 0; i < devices.Count(); i++)
            {
                var device = devices[i];
                if (deviceHandle == device.DeviceHandle)
                {
                    devices.Remove(device);
                    switch (device.DeviceType)
                    {
                    case DeviceTypeEnum.AUDIO_INPUT:
                    {
                        if (CurrentAudioInputDevice == device)
                        {
                            var audioInput   = GetDevicesByType(DeviceTypeEnum.AUDIO_INPUT).FirstOrDefault();
                            var audioOutput  = GetDevicesByType(DeviceTypeEnum.AUDIO_OUTPUT).FirstOrDefault();
                            var inputHandle  = audioInput?.DeviceHandle;
                            var outputHandle = audioOutput?.DeviceHandle;
                            if (null == CurrentAudioInputDevice && null != audioInput)
                            {
                                CurrentAudioInputDevice = audioInput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                            if (null == CurrentAudioOutputDevice && null != outputHandle)
                            {
                                CurrentAudioOutputDevice = audioOutput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                        }
                    } break;

                    case DeviceTypeEnum.AUDIO_OUTPUT:
                    {
                        if (CurrentAudioOutputDevice == device)
                        {
                            var audioInput   = GetDevicesByType(DeviceTypeEnum.AUDIO_INPUT).FirstOrDefault();
                            var audioOutput  = GetDevicesByType(DeviceTypeEnum.AUDIO_OUTPUT).FirstOrDefault();
                            var inputHandle  = audioInput?.DeviceHandle;
                            var outputHandle = audioOutput?.DeviceHandle;
                            if (null == CurrentAudioInputDevice && null != audioInput)
                            {
                                CurrentAudioInputDevice = audioInput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                            if (null == CurrentAudioOutputDevice && null != outputHandle)
                            {
                                CurrentAudioOutputDevice = audioOutput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                        }
                    }
                    break;

                    case DeviceTypeEnum.VIDEO_INPUT:
                    {
                        if (CurrentVideoInputDevice == device)
                        {
                            var video       = GetDevicesByType(DeviceTypeEnum.VIDEO_INPUT).FirstOrDefault();
                            var videoHandle = video?.DeviceHandle;
                            WrapperProxy.SetVideoDevice(videoHandle);
                        }
                    }
                    break;
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #23
0
 public void StopSound()
 {
     WrapperProxy.StopPlayAlert();
 }
Пример #24
0
 public static void UnregisterClient()
 {
     log.Info("invoke unregister client");
     log.Info("PLCM_MFW_KVLIST_KEY_REG_ID is " + lalProperties.GetProperty(PropertyEnum.PLCM_MFW_KVLIST_KEY_REG_ID));
     WrapperProxy.UnregisterClient();
 }