public async Task <OnvifDevice> Setup() { device = await OnvifClientFactory.CreateDeviceClientAsync(Host + ":" + Port, UserName, Password); var devicecapabilities = await device.GetCapabilitiesAsync(new CapabilityCategory[] { CapabilityCategory.All }); var info = await device.GetDeviceInformationAsync(new GetDeviceInformationRequest() { }); media = await OnvifClientFactory.CreateMediaClientAsync(Host + ":" + Port, UserName, Password); var profiles = await media.GetProfilesAsync(); ptz = await Onvif.Core.Client.OnvifClientFactory.CreatePTZClientAsync(Host + ":" + Port, UserName, Password); var capabilities = await ptz.GetServiceCapabilitiesAsync(); var config = await ptz.GetConfigurationsAsync(); var space = config.PTZConfiguration[0].DefaultAbsolutePantTiltPositionSpace; token = profiles.Profiles[0].token; xrange = config.PTZConfiguration[0].PanTiltLimits.Range.XRange; yrange = config.PTZConfiguration[0].PanTiltLimits.Range.YRange; zrange = config.PTZConfiguration[0].ZoomLimits.Range.XRange; var status = await ptz.GetStatusAsync(token); //var presets = await ptz.GetPresetsAsync(token); //Console.WriteLine("preset "); // await ptz.GotoPresetAsync(token, presets.Preset[0].token, null); //Thread.Sleep(4000); var nodes = await ptz.GetNodesAsync(); //Console.WriteLine("home "); //await ptz.GotoHomePositionAsync(token, null); //Thread.Sleep(2000); //Console.WriteLine("ContinuousMoveAsync "); /* * await ptz.ContinuousMoveAsync(token, new PTZSpeed() {PanTilt = new Vector2D() {x = -1f, y = -1}, Zoom = new Vector1D() { x=0f}}, "2"); * Thread.Sleep(2000); * await ptz.StopAsync(token, true, true); */ return(this); }
public async Task <string> GetMediaInfoAsync(string mediaAddress, string userName, string password) { var messageElement = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement { MaxReceivedMessageSize = 1024 * 1024 * 1024 }; CustomBinding bind = new CustomBinding(messageElement, httpBinding); //绑定服务地址 EndpointAddress serviceAddress = new EndpointAddress(mediaAddress); MediaClient mediaClient = new MediaClient(bind, serviceAddress); //给每个请求都添加认证信息 mediaClient.Endpoint.EndpointBehaviors.Add(new CustomEndpointBehavior(userName, password)); //不要少了下面这行,会报异常 var channel = mediaClient.ChannelFactory.CreateChannel(); //查看系统时间 var profilesResponse = await mediaClient.GetProfilesAsync(); foreach (var profile in profilesResponse.Profiles) { } var step = new StreamSetup { Transport = new Transport() { Protocol = TransportProtocol.RTSP }, Stream = StreamType.RTPUnicast }; var streamUri = await mediaClient.GetStreamUriAsync(step, profilesResponse.Profiles[0].token); return(streamUri.Uri); }
public static async Task GetMediaInfoAsync(string address) { var messageElement = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.MaxReceivedMessageSize = 1024 * 1024 * 1024; //httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; CustomBinding bind = new CustomBinding(messageElement, httpBinding); //绑定服务地址 EndpointAddress serviceAddress = new EndpointAddress(address); MediaClient mediaClient = new MediaClient(bind, serviceAddress); //给每个请求都添加认证信息 mediaClient.Endpoint.EndpointBehaviors.Add(new CustomEndpointBehavior()); //不要少了下面这行,会报异常 var channel = mediaClient.ChannelFactory.CreateChannel(); //查看系统时间 var profilesResponse = await mediaClient.GetProfilesAsync(); foreach (var profile in profilesResponse.Profiles) { var step = new StreamSetup { Transport = new Transport() { Protocol = TransportProtocol.RTSP }, Stream = StreamType.RTPUnicast }; var streamUri = await mediaClient.GetStreamUriAsync(step, profile.token); Console.WriteLine(streamUri.Uri); } }