示例#1
0
        public static Profile GetProfile(BaseOnvifTest test, MediaClient client, string token, string stepName)
        {
            Profile profile = null;

            RunStep(test, () => { profile = client.GetProfile(token); }, stepName);
            DoRequestDelay(test);
            return(profile);
        }
        public bool Initialise(string cameraAddress, string userName, string password)
        {
            bool result = false;

            try
            {
                var messageElement = new TextMessageEncodingBindingElement()
                {
                    MessageVersion = MessageVersion.CreateVersion(
                        EnvelopeVersion.Soap12, AddressingVersion.None)
                };
                HttpTransportBindingElement httpBinding = new HttpTransportBindingElement()
                {
                    AuthenticationScheme = AuthenticationSchemes.Digest
                };
                CustomBinding bind = new CustomBinding(messageElement, httpBinding);
                mediaClient = new MediaClient(bind,
                                              new EndpointAddress($"http://{cameraAddress}/onvif/Media"));
                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/PTZ"));
                ptzClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel =
                    System.Security.Principal.TokenImpersonationLevel.Impersonation;
                ptzClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
                ptzClient.ClientCredentials.HttpDigest.ClientCredential.Password = password;

                var profs = mediaClient.GetProfiles();
                profile = mediaClient.GetProfile(profs[0].token);

                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,
                    }
                };
                if (relative)
                {
                    timer                  = new Timer(TimerInterval);
                    timer.Elapsed         += Timer_Elapsed;
                    velocity.PanTilt.space = options.Spaces.RelativePanTiltTranslationSpace[0].URI;
                    panDistance            = (options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Max -
                                              options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Min) / PanIncrements;
                    tiltDistance = (options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Max -
                                    options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Min) / TiltIncrements;
                }

                vector = new PTZVector()
                {
                    PanTilt = new OnvifPTZService.Vector2D()
                    {
                        x     = 0,
                        y     = 0,
                        space = options.Spaces.RelativePanTiltTranslationSpace[0].URI
                    }
                };

                ErrorMessage = "";
                result       = initialised = true;
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
            return(result);
        }
示例#3
0
        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);
        }