Exemple #1
0
        /// <summary>
        /// Instantiates PTZ object with known media profile
        /// </summary>
        /// <param name="mediaUri">Camera's Media URI (from device client GetServices())</param>
        /// <param name="ptzUri">Camera's PTZ URI (from device client GetServices())</param>
        /// <param name="deviceTimeOffset">Difference between device time and client time (seconds)</param>
        /// <param name="mediaProfile">Media Profile to use</param>
        /// <param name="user">Username</param>
        /// <param name="password">Password</param>
        public OnvifPtz(string mediaUri, string ptzUri, double deviceTimeOffset, RTSP_Viewer.OnvifMediaServiceReference.Profile mediaProfile, string user, string password)
        {
            User     = user;
            Password = password;

            if (string.IsNullOrEmpty(mediaUri) | string.IsNullOrEmpty(ptzUri))
            {
                throw new Exception("Media and/or PTZ URI is empty or null.  PTZ object cannot be created");
            }

            PtzClient    = OnvifServices.GetOnvifPTZClient(ptzUri, deviceTimeOffset, User, Password);
            MediaProfile = mediaProfile;

            // Should be able to remove this once all instantiates go through this constructor (only used by GetMediaProfile - which is only necessary if a mediaProfile is not provided)
            MediaClient = OnvifServices.GetOnvifMediaClient(mediaUri, deviceTimeOffset, User, Password);
        }
        public static RTSP_Viewer.OnvifMediaServiceReference.MediaClient GetOnvifMediaClient(string Uri, double deviceTimeOffset, string username = "", string password = "")
        {
            EndpointAddress serviceAddress = new EndpointAddress(Uri);

            HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();

            httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;

            var messageElement = new TextMessageEncodingBindingElement();

            messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
            CustomBinding bind = new CustomBinding(messageElement, httpBinding);

            RTSP_Viewer.OnvifMediaServiceReference.MediaClient mediaClient = new RTSP_Viewer.OnvifMediaServiceReference.MediaClient(bind, serviceAddress);

            if (username != string.Empty)
            {
                // Handles adding of SOAP Security header containing User Token (user, nonce, pwd digest)
                PasswordDigestBehavior behavior = new PasswordDigestBehavior(username, password, deviceTimeOffset);
                mediaClient.Endpoint.Behaviors.Add(behavior);
            }

            return(mediaClient);
        }