/// <summary> /// Gets the first media profile that contains a PTZConfiguration from the the MediaClient GetProfiles command /// </summary> /// <returns>Media profile with PTZConfiguration</returns> private Onvif_Interface.OnvifMediaServiceReference.Profile GetMediaProfile() { if (MediaProfile != null) { return(MediaProfile); } else { //log.Warn(string.Format("PTZ Media profile not assigned. Finding first available PTZ-enabled profile - THIS MAY CAUSE ISSUES (commands sent to wrong stream) AND NEEDS TO BE CHANGED")); // If no profile defined, take a guess and select the first available one - THIS NEEDS TO GO AWAY EVENTUALLY Onvif_Interface.OnvifMediaServiceReference.Profile[] mediaProfiles = MediaClient.GetProfiles(); foreach (Onvif_Interface.OnvifMediaServiceReference.Profile p in mediaProfiles) { if (p.PTZConfiguration != null) { // This should eliminate the redundant GetProfiles() / GetProfile() calls that were being done on every command MediaProfile = MediaClient.GetProfile(p.token); return(MediaProfile); } } } throw new Exception("No media profiles containing a PTZConfiguration on this device"); }
/// <summary> /// Move PTZ to provided preset number (defaults to media profile 0) /// </summary> /// <param name="presetNumber">Preset to use</param> public void ShowPreset(int presetNumber) { string presetToken = string.Empty; Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); string profileToken = mediaProfile.token; PTZPreset[] presets = PtzClient.GetPresets(profileToken); if (presets.Length >= presetNumber) { presetToken = presets[presetNumber - 1].token; PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = (float)-0.5, y = 0 };; PtzClient.GotoPreset(profileToken, presetToken, velocity); } else { throw new Exception(string.Format("Invalid Preset requested - preset number {0}", presetNumber)); } }
public PTZStatus GetPtzLocation() { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZStatus status = PtzClient.GetStatus(mediaProfile.token); return(status); }
/// <summary> /// Tilt the camera (uses the first media profile that is PTZ capable) /// </summary> /// <param name="speed">Percent of max speed to move the camera (1-100)</param> public void Tilt(float speed) { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = 0, y = speed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Max }; PtzClient.ContinuousMove(mediaProfile.token, velocity, null); }
public bool IsPtz() { try { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PtzAvailable = true; } catch (Exception ex) { PtzAvailable = false; } return(PtzAvailable); }
/// <summary> /// Pan the camera (uses the first media profile that is PTZ capable) /// </summary> /// <param name="speed">Percent of max speed to move the camera (1-100)</param> public void Pan(float speed) { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); File.AppendAllText("info.txt", string.Format("Media Profile [Name: {0}, Token: {1}, PTZ Config. Name: {2}, PTZ Config. Token: {3}]\n", mediaProfile.Name, mediaProfile.token, mediaProfile.PTZConfiguration.Name, mediaProfile.PTZConfiguration.token)); PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = speed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max, y = 0 }; PtzClient.ContinuousMove(mediaProfile.token, velocity, null); }
/// <summary> /// Stop the camera (uses the first media profile that is PTZ capable). /// NOTE: may not work if not issued in conjunction with a move command /// </summary> public void Stop() { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PtzClient.Stop(mediaProfile.token, true, true); }