Ejemplo n.º 1
0
        public virtual bool Equals(VATRPCall other)
        {
            if (object.ReferenceEquals(other, null))
            {
                return(false);
            }
            if (object.ReferenceEquals(other, this))
            {
                return(true);
            }

            return(this.NativeCallPtr == other.NativeCallPtr);
        }
Ejemplo n.º 2
0
        internal static bool ParseSipAddressEx(string sipAddress, out string displayname, out string username,
                                               out string hostname, out int port)
        {
            displayname = string.Empty;
            username    = string.Empty;
            hostname    = string.Empty;
            port        = 0;

            bool bRetVal = false;

            int posStart = sipAddress.IndexOf("\"", StringComparison.InvariantCulture);

            if (posStart != -1)
            {
                int posEnd = posStart;
                int posTmp = posEnd;
                while ((posTmp = sipAddress.IndexOf("\"", posTmp + 1, StringComparison.InvariantCulture)) != -1)
                {
                    if (sipAddress[posTmp - 1] != '\\')
                    {
                        posEnd = posTmp;
                        break;
                    }
                }

                if (posStart < posEnd)
                {
                    int posFirst = sipAddress.IndexOf("<", posEnd + 1, StringComparison.InvariantCulture);
                    if (posFirst != -1)
                    {
                        int posLast = sipAddress.IndexOf(">", posFirst + 1, StringComparison.InvariantCulture);
                        if (posFirst + 1 < posLast)
                        {
                            displayname = sipAddress.Substring(posStart + 1, posEnd - posStart - 1);

                            string stripped = sipAddress.Substring(posFirst + 1, posLast - posFirst - 1);
                            bRetVal = VATRPCall.ParseSipAddress(stripped, out username, out hostname, out port);
                        }
                    }
                }
            }
            else
            {
                bRetVal = ParseSipAddress(sipAddress, out username, out hostname, out port);
            }

            return(bRetVal);
        }
Ejemplo n.º 3
0
		private void OnCallStateChanged(IntPtr lc, IntPtr callPtr, LinphoneCallState cstate, string message)
		{
			if (linphoneCore == IntPtr.Zero) return;

			LOG.Info(string.Format( "OnCallStateChanged: State - {0}, CallPtr - {1}, Message: {2}", cstate, callPtr, message));

			var newstate = VATRPCallState.None;
			var direction = LinphoneCallDir.LinphoneCallIncoming;
			string remoteParty = "";
			IntPtr addressStringPtr;
		    bool removeCall = false;
			// detecting direction, state and source-destination data by state
			switch (cstate)
			{
				case LinphoneCallState.LinphoneCallIncomingReceived:
				case LinphoneCallState.LinphoneCallIncomingEarlyMedia:
					newstate = cstate == LinphoneCallState.LinphoneCallIncomingReceived
						? VATRPCallState.InProgress
						: VATRPCallState.EarlyMedia;
					addressStringPtr = LinphoneAPI.linphone_call_get_remote_address_as_string(callPtr);
			        if (addressStringPtr != IntPtr.Zero)
			        {
			            identity = Marshal.PtrToStringAnsi(addressStringPtr);
                        LinphoneAPI.ortp_free(addressStringPtr);
			        }
					remoteParty = identity;
					break;

                case LinphoneCallState.LinphoneCallOutgoingEarlyMedia:
				case LinphoneCallState.LinphoneCallConnected:
					newstate = VATRPCallState.Connected;
					break;
				case LinphoneCallState.LinphoneCallStreamsRunning:
                    newstate = VATRPCallState.StreamsRunning;
					break;
				case LinphoneCallState.LinphoneCallPausedByRemote:
                    newstate = VATRPCallState.RemotePaused;
			        break;
				case LinphoneCallState.LinphoneCallPausing:
                    newstate = VATRPCallState.LocalPausing;
					break;
                case LinphoneCallState.LinphoneCallPaused:
                    newstate = VATRPCallState.LocalPaused;
                    break;
                case LinphoneCallState.LinphoneCallResuming:
                    newstate = VATRPCallState.LocalResuming;
			        break;
				case LinphoneCallState.LinphoneCallOutgoingInit:
				case LinphoneCallState.LinphoneCallOutgoingProgress:
				case LinphoneCallState.LinphoneCallOutgoingRinging:
                    newstate = cstate != LinphoneCallState.LinphoneCallOutgoingRinging
						? VATRPCallState.Trying
						: VATRPCallState.Ringing;
					direction = LinphoneCallDir.LinphoneCallOutgoing;
					addressStringPtr = LinphoneAPI.linphone_call_get_remote_address_as_string(callPtr);
			        if (addressStringPtr != IntPtr.Zero)
			        {
			            remoteParty = Marshal.PtrToStringAnsi(addressStringPtr);
                        LinphoneAPI.ortp_free(addressStringPtr);
			        }
					break;

				case LinphoneCallState.LinphoneCallError:
                    string linphoneLibraryVersion = VATRP.LinphoneWrapper.LinphoneAPI.linphone_core_get_version_asString();
                    LOG.Info("OnCallStateChanged: CallState=LinphoneCallError .LinphoneLib Version: " + linphoneLibraryVersion);
					newstate = VATRPCallState.Error;
			        removeCall = true;
					break;

				case LinphoneCallState.LinphoneCallEnd:
					newstate = VATRPCallState.Closed;
                    removeCall = true;
					break;
				case LinphoneCallState.LinphoneCallReleased:
			        if ((_declinedCallsList != null) && _declinedCallsList.Contains(callPtr))
			        {
                        LOG.Info("   trying to remove callPtr from declinedCallList");
			            _declinedCallsList.Remove(callPtr);
                    }
                    LOG.Info("   calling linphone_call_unref");
                    try
                    {
                        LinphoneAPI.linphone_call_unref(callPtr);
                        LOG.Info("   passed unref");
                    }
                    catch (Exception ex)
                    {
                        LOG.Error("LinphoneService.OnCallStateChanged: Exception occured while calling linphone_call_unref. Details: " + ex.Message);
                    }
			        return;
			}

		    lock (callLock)
		    {
		        VATRPCall call = FindCall(callPtr);

		        if (call == null)
		        {
		            if (_declinedCallsList.Contains(callPtr))
		                return;

		            if (GetActiveCallsCount > 1)
		            {
                        callPtr = LinphoneAPI.linphone_call_ref(callPtr);
                        var cmd = new DeclineCallCommand(callPtr, LinphoneReason.LinphoneReasonBusy);
		                commandQueue.Enqueue(cmd);
                        _declinedCallsList.Add(callPtr);
		                return;
		            }

		            if (!removeCall)
		            {
		                LOG.Info("Call not found. Adding new call into list. ID - " + callPtr + " Calls count: " +
		                         callsList.Count);
                        callPtr = LinphoneAPI.linphone_call_ref(callPtr);
		                call = new VATRPCall(callPtr) {CallState = newstate, CallDirection = direction};
		                CallParams from = direction == LinphoneCallDir.LinphoneCallIncoming ? call.From : call.To;
		                CallParams to = direction == LinphoneCallDir.LinphoneCallIncoming ? call.To : call.From;

		                if (
		                    !VATRPCall.ParseSipAddressEx(remoteParty, out from.DisplayName, out from.Username,
		                        out from.HostAddress,
		                        out from.HostPort))
		                    from.Username = "******";

		                if (
		                    !VATRPCall.ParseSipAddressEx(remoteParty, out to.DisplayName, out to.Username, out to.HostAddress,
		                        out to.HostPort))
		                    to.Username = "******";

		                IntPtr chatPtr = LinphoneAPI.linphone_call_get_chat_room(callPtr);

		                if (chatPtr != IntPtr.Zero)
		                {
		                    VATRPContact contact;
		                    var contactAddress = string.Empty;
		                    if (direction == LinphoneCallDir.LinphoneCallIncoming)
		                    {
		                        contactAddress = string.Format("{0}@{1}", from.Username, from.HostAddress);
		                        contact = new VATRPContact(new ContactID(contactAddress, chatPtr))
		                        {
		                            DisplayName = from.DisplayName,
		                            Fullname = from.Username,
		                            SipUsername = from.Username
		                        };
		                    }
		                    else
		                    {
		                        contactAddress = string.Format("{0}@{1}", to.Username, to.HostAddress);
		                        contact = new VATRPContact(new ContactID(contactAddress, chatPtr))
		                        {
		                            DisplayName = to.DisplayName,
		                            Fullname = to.Username,
		                            SipUsername = to.Username
		                        };
		                    }
		                    contact.RegistrationName = contactAddress;
                            call.ChatRoom = manager.ChatService.InsertRttChat(contact, chatPtr, callPtr);
		                    var loggedContact = manager.ContactService.FindLoggedInContact();
		                    if (loggedContact != null)
		                        call.ChatRoom.AddContact(loggedContact);
		                }

		                callsList.Add(call);
		            }
		        }

		        if (call != null)
		        {
		            call.LinphoneMessage = message;
		            call.CallState = newstate;

                    if (call.CallState == VATRPCallState.Error || call.CallState == VATRPCallState.Closed)
		            {
		                IntPtr errorReason = LinphoneAPI.linphone_call_get_error_info(callPtr);
		                if (errorReason != IntPtr.Zero)
		                {
                            call.SipErrorCode = LinphoneAPI.linphone_error_info_get_protocol_code(errorReason);
		                }
		            }
                    if (CallStateChangedEvent != null)
                        CallStateChangedEvent(call);
		            if (removeCall)
		            {
		                callsList.Remove(call);
		                LOG.Info(string.Format("Call removed from list. Call - {0}. Total calls in list: {1}", callPtr,
		                    callsList.Count));
		            }
		        }
		    }
		}
Ejemplo n.º 4
0
		public bool IsVideoEnabled(VATRPCall call)
		{
            if (linphoneCore == IntPtr.Zero)
                return false;
		    IntPtr curCallPtr = LinphoneAPI.linphone_core_get_current_call(linphoneCore);
		    if (curCallPtr == IntPtr.Zero)
		        return false;
            var linphoneCallParams = LinphoneAPI.linphone_call_get_current_params(curCallPtr);
            var videoCodecName = string.Empty;
            if (linphoneCallParams != IntPtr.Zero)
                videoCodecName = GetUsedVideoCodec(linphoneCallParams);
			return !string.IsNullOrEmpty(videoCodecName);
		}
Ejemplo n.º 5
0
        public void SendDtmf(VATRPCall call, char dtmf)
        {
            if (call == null)
            {
                LOG.Warn("Cannot terminate call. Cause - Null call");
                return;
            }

            if ( LinphoneAPI.linphone_call_send_dtmf(call.NativeCallPtr, dtmf) != 0 )
                LOG.Error(string.Format( "Can't send dtmf {0}. Call {1}", dtmf, call.NativeCallPtr));
        }
Ejemplo n.º 6
0
        public virtual bool Equals(VATRPCall other)
        {
            if (object.ReferenceEquals(other, null))
            {
                return false;
            }
            if (object.ReferenceEquals(other, this))
            {
                return true;
            }

            return (this.NativeCallPtr == other.NativeCallPtr);
        }
 internal CallViewModel FindCallViewModel(VATRPCall call)
 {
     if (call == null)
         return null;
     lock (CallsViewModelList)
     {
         foreach (var callVM in CallsViewModelList)
         {
             if (callVM.Equals(call))
                 return callVM;
         }
     }
     return null;
 }
 private QualityIndicator ConvertToNamedQuality(VATRPCall call)
 {
     var rating = (float)LinphoneAPI.linphone_call_get_current_quality(call.NativeCallPtr);
     if (rating >= 4.0)
         return QualityIndicator.Good;
     if (rating >= 3.0)
         return QualityIndicator.Medium;
     if (rating >= 2.0)
         return QualityIndicator.Poor;
     if (rating >= 1.0)
         return QualityIndicator.VeryPoor;
     if (rating >= 0)
         return QualityIndicator.ToBad;
     return QualityIndicator.Unknown;
 }
        internal void UpdateCallInfo(VATRPCall call)
        {
            if (call == null || call.CallState != VATRPCallState.StreamsRunning)
            {
                ResetCallInfoView();
                return;
            }

            ServiceManager.Instance.LinphoneService.LockCalls();
            ServiceManager.Instance.LinphoneService.GetCallAudioStats(call.NativeCallPtr, ref _audioStats);
            ServiceManager.Instance.LinphoneService.GetCallVideoStats(call.NativeCallPtr, ref _videoStats);

            IntPtr curparams = ServiceManager.Instance.LinphoneService.GetCallParams(call.NativeCallPtr);
            if (curparams != IntPtr.Zero)
            {

                int sipPort, rtpPort;
                ServiceManager.Instance.LinphoneService.GetUsedPorts(out sipPort, out rtpPort);

                SipPort = sipPort;
                RtpPort = rtpPort;
                bool has_video = LinphoneAPI.linphone_call_params_video_enabled(curparams) == 1;

                MSVideoSizeDef size_received = LinphoneAPI.linphone_call_params_get_received_video_size(curparams);
                MSVideoSizeDef size_sent = LinphoneAPI.linphone_call_params_get_sent_video_size(curparams);
                IntPtr rtp_profile = LinphoneAPI.linphone_call_params_get_rtp_profile(curparams);

                if (rtp_profile != IntPtr.Zero)
                {
                    RtpProfile = Marshal.PtrToStringAnsi(rtp_profile);
                }
                AudioCodec = ServiceManager.Instance.LinphoneService.GetUsedAudioCodec(curparams);

                int avpf_mode = ServiceManager.Instance.LinphoneService.GetAVPFMode();

                if (avpf_mode == 0)
                {
                    AVPFEnabled = false;
                }
                else if (avpf_mode == 1)
                {
                    AVPFEnabled = true;
                }

                var videoCodecName = ServiceManager.Instance.LinphoneService.GetUsedVideoCodec(curparams);

                if (has_video && !string.IsNullOrWhiteSpace(videoCodecName))
                {
                    VideoCodec = videoCodecName;
                    UploadBandwidth = string.Format("{0:0.##} kbit/s a {1:0.##} kbit/s v {2:0.##} kbit/s",
                        _audioStats.upload_bandwidth + _videoStats.upload_bandwidth, _audioStats.upload_bandwidth,
                        _videoStats.upload_bandwidth);

                    DownloadBandwidth = string.Format("{0:0.##} kbit/s a {1:0.##} kbit/s v {2:0.##} kbit/s",
                        _audioStats.download_bandwidth + _videoStats.download_bandwidth, _audioStats.download_bandwidth,
                        _videoStats.download_bandwidth);
                    ReceivingFPS = ServiceManager.Instance.LinphoneService.GetFrameRate(curparams, false);
                    SendingFPS = ServiceManager.Instance.LinphoneService.GetFrameRate(curparams, true);
                    var vs = ServiceManager.Instance.LinphoneService.GetVideoSize(curparams, false);
                    ReceivingVideoResolution = string.Format("{0}({1}x{2})", "", vs.width, vs.height);

                    vs = ServiceManager.Instance.LinphoneService.GetVideoSize(curparams, true);
                    SendingVideoResolution = string.Format("{0}({1}x{2})", "", vs.width, vs.height);

                }
                else
                {
                    VideoCodec = "Not used";
                    ReceivingFPS = 0;
                    SendingFPS = 0;
                    UploadBandwidth = string.Format("a {0:0.##} kbit/s", _audioStats.upload_bandwidth);
                    DownloadBandwidth = string.Format("a {0:0.##} kbit/s", _audioStats.download_bandwidth);
                    ReceivingVideoResolution = "N/A";
                    SendingVideoResolution = "N/A";
                }
                switch ((LinphoneIceState) _audioStats.ice_state)
                {
                    case LinphoneIceState.LinphoneIceStateNotActivated:
                        IceSetup = "Not Activated";
                        break;
                    case LinphoneIceState.LinphoneIceStateFailed:
                        IceSetup = "Failed";
                        break;
                    case LinphoneIceState.LinphoneIceStateInProgress:
                        IceSetup = "In Progress";
                        break;
                    case LinphoneIceState.LinphoneIceStateHostConnection:
                        IceSetup = "Connected directly";
                        break;
                    case LinphoneIceState.LinphoneIceStateReflexiveConnection:
                        IceSetup = "Connected through NAT";
                        break;
                    case LinphoneIceState.LinphoneIceStateRelayConnection:
                        IceSetup = "Connected through a relay";
                        break;
                }

                switch (ServiceManager.Instance.LinphoneService.GetMediaEncryption(curparams))
                {
                    case LinphoneMediaEncryption.LinphoneMediaEncryptionNone:
                        MediaEncryption = "None";
                        break;
                    case LinphoneMediaEncryption.LinphoneMediaEncryptionSRTP:
                        MediaEncryption = "SRTP";
                        break;
                    case LinphoneMediaEncryption.LinphoneMediaEncryptionZRTP:
                        MediaEncryption = "ZRTP";
                        break;
                    case LinphoneMediaEncryption.LinphoneMediaEncryptionDTLS:
                        MediaEncryption = "DTLS";
                        break;
                }

                var curQuality = ConvertToNamedQuality(call);
                if (CallQuality != curQuality)
                {
                    CallQuality = curQuality;
                    if (CallQualityChangedEvent != null)
                        CallQualityChangedEvent(curQuality);
                }

                    AudioPacketLossSending = "Sending " + _audioStats.sender_loss_rate;
                    AudioPacketLossReceiving = "Receiving " + _audioStats.receiver_loss_rate;
                    AudioPacketLate = _audioStats.total_late_packets.ToString();
                    AudioInterarrivalJitterSending = "Sending " + _audioStats.sender_interarrival_jitter;
                    AudioInterarrivalJitterReceiving = "Receiving " + _audioStats.receiver_interarrival_jitter;

                    VideoPacketLossSending = "Sending " + _videoStats.sender_loss_rate;
                    VideoPacketLossReceiving = "Receiving " + _audioStats.receiver_loss_rate;
                    VideoPacketLate = _videoStats.total_late_packets.ToString();
                    VideoInterarrivalJitterSending = "Sending " + _audioStats.sender_interarrival_jitter;
                    VideoInterarrivalJitterReceiving = "Receiving " + _audioStats.receiver_interarrival_jitter;
            }
            ServiceManager.Instance.LinphoneService.UnlockCalls();
        }
        internal void OnCallStatisticsChanged(VATRPCall call)
        {
            if (ServiceManager.Instance.Dispatcher.Thread != Thread.CurrentThread)
            {
                ServiceManager.Instance.Dispatcher.BeginInvoke((Action)(() => this.OnCallStatisticsChanged(call)));
                return;
            }

            UpdateCallInfo(call);
        }
Ejemplo n.º 11
0
 public InfoEventArgs(VATRPCall call)
     : base(call)
 {
 }
        private void OnCallStateChanged(VATRPCall call)
        {
            if (this.Dispatcher == null)
                return;

            if (this.Dispatcher.Thread != Thread.CurrentThread)
            {
                this.Dispatcher.BeginInvoke((Action)(() => this.OnCallStateChanged(call)));
                return;
            }

            if (call == null)
                return;

            lock (deferredLock)
            {
                if (deferredHideTimer != null && deferredHideTimer.IsEnabled)
                    deferredHideTimer.Stop();
            }

            if (_mainViewModel == null)
                return;

            if (_mainViewModel.ActiveCallModel != null &&
                _mainViewModel.ActiveCallModel.CallState == VATRPCallState.Declined)
            {
                _mainViewModel.ActiveCallModel.DeclinedMessage = string.Empty;
                _mainViewModel.RemoveCalViewModel(_mainViewModel.ActiveCallModel);
            }

            CallViewModel callViewModel = _mainViewModel.FindCallViewModel(call);

            if (callViewModel == null)
            {
                callViewModel = new CallViewModel(_linphoneService, call)
                {
                    CallInfoCtrl = _callInfoView
                };

                callViewModel.CallQualityChangedEvent += OnCallQualityChanged;

                callViewModel.VideoWidth = (int)CombinedUICallViewSize.Width;
                callViewModel.VideoHeight = (int)CombinedUICallViewSize.Height;
                _mainViewModel.AddCalViewModel(callViewModel);
            }

            if ((call.CallState == VATRPCallState.InProgress) ||
                (call.CallState == VATRPCallState.StreamsRunning))
            {
                _mainViewModel.ActiveCallModel = callViewModel;
            }

            if (callViewModel.Declined)
            {
                // do not process declined call
                _mainViewModel.RemoveCalViewModel(callViewModel);
                return;
            }

            if (_mainViewModel.ActiveCallModel == null)
                _mainViewModel.ActiveCallModel = callViewModel;

            LOG.Info(string.Format("CallStateChanged: State - {0}. Call: {1}", call.CallState, call.NativeCallPtr));
            ctrlCall.SetCallViewModel(_mainViewModel.ActiveCallModel);
            VATRPContact contact = null;

            var stopPlayback = false;
            var destroycall = false;
            var callDeclined = false;
            bool isError = false;
            switch (call.CallState)
            {
                case VATRPCallState.Trying:
                    // call started,
                    call.RemoteParty = call.To;
                    callViewModel.OnTrying();
                    _mainViewModel.IsCallPanelDocked = true;

                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.To.DisplayName,
                            Fullname = call.To.Username,
                            SipUsername = call.To.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    break;
                case VATRPCallState.InProgress:
                    WakeupScreenSaver();
                    this.ShowSelfPreviewItem.IsEnabled = false;
                    call.RemoteParty = call.From;
                    ServiceManager.Instance.SoundService.PlayRingTone();
                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.From.Username, call.From.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.From.Username, call.From.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.From.DisplayName,
                            Fullname = call.From.Username,
                            SipUsername = call.From.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    callViewModel.OnIncomingCall();

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        ShowOverlayNewCallWindow(true);
                        ctrlCall.ctrlOverlay.SetNewCallerInfo(callViewModel.CallerInfo);
                    }
                    else
                    {
                        callViewModel.ShowIncomingCallPanel = true;
                    }

                    if (WindowState != WindowState.Minimized)
                        _mainViewModel.IsCallPanelDocked = true;

                    if (_flashWindowHelper != null)
                        _flashWindowHelper.FlashWindow(this);
                    if (WindowState == WindowState.Minimized)
                        this.WindowState = WindowState.Normal;

                    Topmost = true;
                    Activate();
                    Topmost = false;
                    break;
                case VATRPCallState.Ringing:
                    this.ShowSelfPreviewItem.IsEnabled = false;
                    callViewModel.OnRinging();
                    _mainViewModel.IsCallPanelDocked = true;
                    call.RemoteParty = call.To;
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Ringing");
                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.To.DisplayName,
                            Fullname = call.To.Username,
                            SipUsername = call.To.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    ServiceManager.Instance.SoundService.PlayRingBackTone();
                    break;
                case VATRPCallState.EarlyMedia:
                    callViewModel.OnEarlyMedia();
                    break;
                case VATRPCallState.Connected:
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                        Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.IsRTTViewEnabled = true;
                        ctrlRTT.SetViewModel(_mainViewModel.RttMessagingModel);
                        _mainViewModel.RttMessagingModel.CreateRttConversation(call.RemoteParty.Username, call.NativeCallPtr);
                    }
                    else
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                    }

                    callViewModel.OnConnected();
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    stopPlayback = true;
                    callViewModel.ShowOutgoingEndCall = false;
                    callViewModel.IsRTTEnabled =
                        ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                            Configuration.ConfEntry.USE_RTT, true) && callViewModel.ActiveCall != null &&
                        _linphoneService.IsRttEnabled(callViewModel.ActiveCall.NativeCallPtr);

                    ShowCallOverlayWindow(true);
                    ShowOverlayNewCallWindow(false);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.ctrlOverlay.ForegroundCallDuration = callViewModel.CallDuration;

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);
                        if (nextVM != null)
                        {
                            ShowOverlaySwitchCallWindow(true);
                            ctrlCall.ctrlOverlay.SetPausedCallerInfo(nextVM.CallerInfo);
                            ctrlCall.ctrlOverlay.BackgroundCallDuration = nextVM.CallDuration;
                            ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                            ctrlCall.BackgroundCallViewModel = nextVM;
                        }
                    }
                    else
                    {
                        ShowOverlaySwitchCallWindow(false);
                    }

                    ctrlCall.ctrlOverlay.StartCallTimer(ctrlCall.ctrlOverlay.ForegroundCallDuration);
                    _callOverlayView.EndCallRequested = false;

                    if (_selfView.IsVisible)
                    {
                        _selfView.ResetNativePreviewHandle = false;
                        _selfView.Hide();
                    }

                    ctrlCall.ctrlVideo.DrawCameraImage = false;
                    ctrlCall.AddVideoControl();
                    ctrlCall.RestartInactivityDetectionTimer();
                    ctrlCall.UpdateVideoSettingsIfOpen();
                    ctrlCall.UpdateMuteSettingsIfOpen();

            //                    MuteCall(createCmd.MuteMicrophone);
            //                    MuteSpeaker(createCmd.MuteSpeaker);

                    break;
                case VATRPCallState.StreamsRunning:
                    callViewModel.OnStreamRunning();
                    ShowCallOverlayWindow(true);

                    // VATRP-1623: we are setting mute microphone true prior to initiating a call, but the call is always started
                    //   with the mic enabled. attempting to mute right after call is connected here to side step this issue -
                    //   it appears to be an initialization issue in linphone
                    if (_linphoneService.GetActiveCallsCount == 1)
                    {
                        ServiceManager.Instance.ApplyMediaSettingsChanges();
                    }
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.UpdateControls();
                    ctrlCall.ctrlOverlay.ForegroundCallDuration = _mainViewModel.ActiveCallModel.CallDuration;
                    ctrlCall.RestartInactivityDetectionTimer();
                    ctrlCall.UpdateVideoSettingsIfOpen();
                    // VATRP-1899: This is a quick and dirty solution for POC. It will be funational, but not the end implementation we will want.
                    if ((App.CurrentAccount != null) && App.CurrentAccount.UserNeedsAgentView)
                    {
                        _mainViewModel.IsMessagingDocked = true;
                    }
                    break;
                case VATRPCallState.RemotePaused:
                    callViewModel.OnRemotePaused();
                    callViewModel.CallState = VATRPCallState.RemotePaused;
                    ShowCallOverlayWindow(true);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("On Hold");
                    ctrlCall.UpdateControls();
                    break;
                case VATRPCallState.LocalPausing:
                    callViewModel.CallState = VATRPCallState.LocalPausing;
                    break;
                case VATRPCallState.LocalPaused:
                    callViewModel.OnLocalPaused();
                    callViewModel.CallState = VATRPCallState.LocalPaused;
                    callViewModel.IsCallOnHold = true;
                    bool updateInfoView = callViewModel.PauseRequest;
                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        if (!callViewModel.PauseRequest)
                        {
                            CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);

                            if (nextVM != null)
                            {
                                ShowOverlaySwitchCallWindow(true);
                                ctrlCall.ctrlOverlay.SetPausedCallerInfo(callViewModel.CallerInfo);
                                ctrlCall.ctrlOverlay.BackgroundCallDuration = callViewModel.CallDuration;
                                ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                                ctrlCall.BackgroundCallViewModel = callViewModel;
                                ctrlCall.ctrlOverlay.ForegroundCallDuration = nextVM.CallDuration;
                                ctrlCall.SetCallViewModel(nextVM);
                                if (!nextVM.PauseRequest)
                                    _mainViewModel.ResumeCall(nextVM);
                                else
                                    updateInfoView = true;
                            }
                        }
                    }

                    if (updateInfoView)
                    {
                        ShowCallOverlayWindow(true);
                        ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                        ctrlCall.ctrlOverlay.SetCallState("On Hold");
                        ctrlCall.UpdateControls();
                    }
                    break;
                case VATRPCallState.LocalResuming:
                    callViewModel.OnResumed();
                    callViewModel.IsCallOnHold = false;
                    ShowCallOverlayWindow(true);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.UpdateControls();

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);
                        if (nextVM != null)
                        {
                            ShowOverlaySwitchCallWindow(true);
                            ctrlCall.ctrlOverlay.SetPausedCallerInfo(nextVM.CallerInfo);
                            ctrlCall.ctrlOverlay.BackgroundCallDuration = nextVM.CallDuration ;
                            ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                            ctrlCall.BackgroundCallViewModel = nextVM;
                            ctrlCall.SetCallViewModel(callViewModel);
                            ctrlCall.ctrlOverlay.ForegroundCallDuration = callViewModel.CallDuration;
                            if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                        Configuration.ConfEntry.USE_RTT, true))
                            {
                                _mainViewModel.RttMessagingModel.CreateRttConversation(call.RemoteParty.Username, call.NativeCallPtr);
                            }
                        }
                        else
                        {
                            ShowOverlaySwitchCallWindow(false);
                        }
                    }
                    else
                    {
                        ShowOverlaySwitchCallWindow(false);
                    }
                    ctrlCall.ctrlVideo.DrawCameraImage = false;
                    ctrlCall.AddVideoControl();
                    break;
                case VATRPCallState.Closed:
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    LOG.Info(string.Format("CallStateChanged: Result Code - {0}. Message: {1} Call: {2}", call.SipErrorCode, call.LinphoneMessage, call.NativeCallPtr));
                    callDeclined = call.SipErrorCode == 603;
                    callViewModel.OnClosed(ref isError, call.LinphoneMessage, call.SipErrorCode, callDeclined);
                    stopPlayback = true;
                    destroycall = true;
                    callViewModel.CallQualityChangedEvent -= OnCallQualityChanged;
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                       Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.RttMessagingModel.ClearRTTConversation(call.NativeCallPtr);
                        ctrlRTT.SetViewModel(null);
                    }
                    ShowOverlayNewCallWindow(false);
                    ShowOverlaySwitchCallWindow(false);
                    ctrlCall.BackgroundCallViewModel = null;

                    if (callDeclined)
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                        this.ShowSelfPreviewItem.IsEnabled = true;
                        _callInfoView.Hide();
                        ctrlCall.ctrlOverlay.StopCallTimer();
                        ShowCallOverlayWindow(false);
                        _mainViewModel.IsMessagingDocked = false;
                        if (_mainViewModel.ActiveCallModel.DeclinedMessage.NotBlank())
                            _mainViewModel.ActiveCallModel.ShowDeclinedMessage = true;
                        else
                        {
                            _mainViewModel.ActiveCallModel.WaitForDeclineMessage = true;
                        }
                        if (deferredHideTimer != null)
                        {
                            lock (deferredLock)
                            {
                                deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                deferredHideTimer.Start();
                            }
                        }
                    }
                    else
                    {
                        int callsCount = _mainViewModel.RemoveCalViewModel(callViewModel);
                        if (callsCount == 0)
                        {
                            _mainViewModel.IsRTTViewEnabled = false;
                            this.ShowSelfPreviewItem.IsEnabled = true;
                            _callInfoView.Hide();
                            ctrlCall.ctrlOverlay.StopCallTimer();

                            if (!isError)
                            {
                                this.SizeToContent = SizeToContent.WidthAndHeight;
                                ctrlCall.SetCallViewModel(null);
                                _mainViewModel.IsCallPanelDocked = false;
                            }
                            else
                            {
                                if (deferredHideTimer != null)
                                {
                                    lock (deferredLock)
                                    {
                                        deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                        deferredHideTimer.Start();
                                    }
                                }
                            }
                            ShowCallOverlayWindow(false);
                            _mainViewModel.IsMessagingDocked = false;
                            _mainViewModel.ActiveCallModel = null;
                            OnFullScreenToggled(false); // restore main window to dashboard

                            if (this.ShowSelfPreviewItem.IsChecked && !_selfView.ResetNativePreviewHandle)
                            {
                                _selfView.ResetNativePreviewHandle = true;
                                deferredShowPreviewTimer.Start();
                            }
                        }
                        else
                        {
                            var nextVM = _mainViewModel.GetNextViewModel(null);
                            if (nextVM != null)
                            {
                                // defensive coding here- do not try to operate on an errored call state object
                                if (nextVM.CallState != VATRPCallState.Error)
                                {
                                    _mainViewModel.ActiveCallModel = nextVM;
                                    nextVM.CallSwitchLastTimeVisibility = Visibility.Hidden;

                                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                        Configuration.ConfEntry.USE_RTT, true))
                                    {
                                        _mainViewModel.IsRTTViewEnabled = true;
                                        ctrlRTT.SetViewModel(_mainViewModel.RttMessagingModel);
                                        _mainViewModel.RttMessagingModel.CreateRttConversation(
                                            nextVM.ActiveCall.RemoteParty.Username, nextVM.ActiveCall.NativeCallPtr);
                                    }
                                    else
                                    {
                                        _mainViewModel.IsRTTViewEnabled = false;
                                    }
                                    ShowCallOverlayWindow(true);
                                    ctrlCall.ctrlOverlay.SetCallerInfo(nextVM.CallerInfo);
                                    ctrlCall.ctrlOverlay.ForegroundCallDuration = _mainViewModel.ActiveCallModel.CallDuration;
                                    ctrlCall.SetCallViewModel(_mainViewModel.ActiveCallModel);
                                    ctrlCall.UpdateControls();
                                    if (nextVM.ActiveCall.CallState == VATRPCallState.LocalPaused)
                                    {
                                        if (!nextVM.PauseRequest)
                                            _mainViewModel.ResumeCall(nextVM);
                                        else
                                        {
                                            ctrlCall.ctrlOverlay.SetCallState("On Hold");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ((registerRequested || signOutRequest || defaultConfigRequest) && _linphoneService.GetActiveCallsCount == 0)
                    {
                        _linphoneService.Unregister(false);
                    }

                    break;
                case VATRPCallState.Error:
                    destroycall = true;
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    ctrlCall.BackgroundCallViewModel = null;
                    isError = true;
                    callViewModel.OnClosed(ref isError, call.LinphoneMessage, call.SipErrorCode, false);
                    callViewModel.CallSwitchLastTimeVisibility = Visibility.Hidden;
                    stopPlayback = true;
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                       Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.RttMessagingModel.ClearRTTConversation(call.NativeCallPtr);
                        ctrlRTT.SetViewModel(null);
                    }

                    if (_linphoneService.GetActiveCallsCount == 0)
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                        this.ShowSelfPreviewItem.IsEnabled = true;
                        if (this.ShowSelfPreviewItem.IsChecked && !_selfView.ResetNativePreviewHandle)
                        {
                            _selfView.ResetNativePreviewHandle = true;
                            deferredShowPreviewTimer.Start();
                        }
                        if (callViewModel.CallState != VATRPCallState.Declined)
                            _mainViewModel.RemoveCalViewModel(callViewModel);
                        _callInfoView.Hide();
                        ctrlCall.ctrlOverlay.StopCallTimer();
                        ShowCallOverlayWindow(false);
                        _mainViewModel.IsMessagingDocked = false;

                        if (deferredHideTimer != null)
                        {
                            lock (deferredLock)
                            {
                                deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                deferredHideTimer.Start();
                            }
                        }

                        _mainViewModel.ActiveCallModel = null;
                        OnFullScreenToggled(false); // restore main window to dashboard
                    }
                    else
                    {
                        _mainViewModel.RemoveCalViewModel(callViewModel);
                    }

                    break;
                default:
                    break;
            }

            if (stopPlayback)
            {
                ServiceManager.Instance.SoundService.StopRingBackTone();
                ServiceManager.Instance.SoundService.StopRingTone();
            }

            if (destroycall)
            {
                if (_linphoneService.GetActiveCallsCount == 0)
                {
                    if (_mainViewModel.IsCallPanelDocked)
                    {
                        ServiceManager.Instance.LinphoneService.SetVideoCallWindowHandle(IntPtr.Zero, true);
                        if (_remoteVideoView != null)
                        {
                            _remoteVideoView.DestroyOnClosing = true; // allow window to be closed
                            _remoteVideoView.Close();
                            _remoteVideoView = null;
                        }
                        if (deferredHideTimer != null && !deferredHideTimer.IsEnabled)
                        {
                            _mainViewModel.IsMessagingDocked = false;
                            _mainViewModel.IsCallPanelDocked = false;
                        }
                    }

                    if (!callDeclined)
                        _mainViewModel.ActiveCallModel = null;
                }
            }
        }
 public CameraMuteEventArgs(VATRPCall call, bool muted)
     : base(call)
 {
     IsMuted = muted;
 }
 protected InfoEventBaseArgs(VATRPCall call)
 {
     ActiveCall = call;
 }