public OnVifPTZController(OnVifDevice OnVifDevice) : base(OnVifDevice) { // m_onVifDevice = OnVifDevice; // m_mediaClient = null; //m_profile = null; m_Timer = null; m_velocity = null; m_vector = null; m_options = null; m_relative = false; m_initialised = false; m_direction = m_direction = Direction.None; m_Presets = null; m_capabilities = null; m_ptzClient = null; m_ErrorMessage = ""; m_configs = null; m_initialised = false; m_panDistance = 0; m_tiltDistance = 0; m_bMoveActiv = false; m_timeinmsec = 200; m_doContineousMode = false; m_ProfileRefToken = ""; }
// public bool IsInitialized { get { return m_initialised; } } public override async Task <bool> InitalizeAsync() { if (this.m_onVifDevice.ServicesResponse == null) { bool b = await this.m_onVifDevice.InitalizeDeviceAsync(); if (this.m_onVifDevice.ServicesResponse == null) { return(false); } } try { foreach (var service in this.m_onVifDevice.ServicesResponse.Service) { if (service.Namespace == "http://www.onvif.org/ver20/ptz/wsdl") { string serviceAdress = service.XAddr; m_ErrorMessage = ""; // m_profile = this.m_media10Services.ProfilesResponse.Profiles[0]; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); CustomBinding binding = new CustomBinding(messageElement, httpBinding); this.m_ptzClient = new PTZClient(binding, new EndpointAddress(serviceAdress)); /* * while (m_ptzClient.Endpoint.EndpointBehaviors.Count > 0) * { * m_ptzClient.Endpoint.EndpointBehaviors.RemoveAt(0); * } */ m_ptzClient.Endpoint.EndpointBehaviors.Add(m_onVifDevice.GetBasicBasicAuthBehaviour); m_ptzClient.Endpoint.EndpointBehaviors.Add(m_onVifDevice.GetPasswordDigestBehavior); m_configs = await m_ptzClient.GetConfigurationsAsync(); m_options = await m_ptzClient.GetConfigurationOptionsAsync(m_configs.PTZConfiguration[0].token); m_capabilities = await m_ptzClient.GetServiceCapabilitiesAsync(); m_velocity = new OnvifPTZService.PTZSpeed() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = m_options.Spaces.ContinuousPanTiltVelocitySpace[0].URI, } , Zoom = new OnvifPTZService.Vector1D() { x = 0, space = m_options.Spaces.ContinuousZoomVelocitySpace[0].URI, } }; m_vector = new PTZVector() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = m_options.Spaces.RelativePanTiltTranslationSpace[0].URI } }; m_initialised = true; m_bMoveActiv = false; if (m_relative) { m_velocity.PanTilt.space = m_options.Spaces.ContinuousPanTiltVelocitySpace[0].URI; m_velocity.PanTilt.space = m_configs.PTZConfiguration[0].DefaultPTZSpeed.PanTilt.space; m_panDistance = (m_options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Max - m_options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Min) / PanIncrements; m_tiltDistance = (m_options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Max - m_options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Min) / TiltIncrements; } break; } } } catch (Exception ex) { m_ErrorMessage = ex.Message; throw new OnVifException("OnVifPTZController.InitalizeAsync", ex); // return false; } return(m_initialised); }
public bool Initialise(string cameraAddress, string userName, string password) { bool result = false; cam_ip = cameraAddress; cam_id = userName; cam_pw = password; //ConnectCam(); try { var messageElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.CreateVersion( EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest; CustomBinding bind = new CustomBinding(messageElement, httpBinding); //mediaClient = new Media2Client(bind, // new EndpointAddress($"http://{cameraAddress}/onvif/device_service")); //mediaClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = // System.Security.Principal.TokenImpersonationLevel.Impersonation; //mediaClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; //mediaClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; //ptzClient = new PTZClient(bind, // new EndpointAddress($"http://{cameraAddress}/onvif/device_service")); //ptzClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = // System.Security.Principal.TokenImpersonationLevel.Impersonation; //ptzClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; //ptzClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; deviceclient = new DeviceClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/device_service")); deviceclient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; deviceclient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; deviceclient.ClientCredentials.HttpDigest.ClientCredential.Password = password; mediaClient10 = new MediaClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/media_service")); mediaClient10.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; mediaClient10.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; mediaClient10.ClientCredentials.HttpDigest.ClientCredential.Password = password; //onvif ver 1.0 var profs = mediaClient10.GetProfiles(); profile10 = mediaClient10.GetProfile(profs[0].token); ONVIF_MediaProfilDashboard.Media10.StreamSetup streamSetup = new ONVIF_MediaProfilDashboard.Media10.StreamSetup() { }; streamSetup.Stream = StreamType.RTPUnicast; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.RTSP; MediaUri mediaUri = mediaClient10.GetStreamUri(streamSetup, profs[0].token); //string string2222 = deviceclient.GetWsdlUrl(); var configs = ptzClient.GetConfigurations(); options = ptzClient.GetConfigurationOptions(configs[0].token); velocity = new OnvifPTZService.PTZSpeed() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = options.Spaces.ContinuousPanTiltVelocitySpace[0].URI, }, Zoom = new OnvifPTZService.Vector1D() { x = 0, space = options.Spaces.ContinuousZoomVelocitySpace[0].URI, } }; ErrorMessage = ""; result = initialised = true; } catch (Exception ex) { ErrorMessage = ex.Message; } return(result); }