0
votes

I have successfully used the code that I found in below URL:
https://www.codeproject.com/Tips/1192709/ONVIF-PTZ-Control-in-Csharp

To be able to Pan/Tilt an IP Camera using the ONVIF protocol, where as seen in above URL uses:
Address, Namespace
http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl, OnvifMedia10
http://onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl, OnvifPTZService

As this type of code is very new, I would be very happy for some help how I can get the stream from the IP Camera as well. (I am using a software to look at the stream at the moment)

I would need to be able to get the stream also so I later can record/take snapshots.

I have looked at Chapter 7.1 on this link and I am trying to implement this:
https://www.onvif.org/wp-content/uploads/2016/12/ONVIF_WG-APG-Application_Programmers_Guide-1.pdf

I have come up with the below code. But wonder for this line that seems to put the stream to some kind of player called "App". "App" is not compiling and wonder how to put this stream to some kind of player or control?

App.DoStreaming(mediaUri.Uri);

 Streaming streaming;
        public class Streaming
        {
            OnvifMedia10.StreamSetup streamSetup;
            OnvifMedia10.MediaUri mediaUri;
            OnvifMedia10.MediaClient mediaClient;
            String mediaProfileToken = "";
            String ErrorMessage = "";
            bool initialised = false;

            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 OnvifMedia10.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;

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

                    // setup stream configuration
                    streamSetup = new OnvifMedia10.StreamSetup();
                    streamSetup.Stream = OnvifMedia10.StreamType.RTPUnicast; //"RTP-Unicast";
                    streamSetup.Transport.Protocol = OnvifMedia10.TransportProtocol.UDP; //"UDP";

                    // RTP/RTSP/UDP is not a special tunnelling setup (is not requiring)!
                    streamSetup.Transport.Tunnel = null;

                    // get stream URI
                    mediaUri = new OnvifMedia10.MediaUri();
                    mediaUri = mediaClient.GetStreamUri(streamSetup, mediaProfileToken);
                    App.DoStreaming(mediaUri.Uri);



                    ErrorMessage = "";
                    result = initialised = true;
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                }
                return result;
            }
        }
1

1 Answers

0
votes

If I understand your question correctly, you want to be able to see the stream in a control of your choice in your App.

I would suggest you to look at the Vlc.DotNet package.

https://github.com/ZeBobo5/Vlc.DotNet

It enables you to put a vlc player in a c# windows form and play streams/video on it.

If you are using visual studio, you can get this package from the NuGet Package manager for solution. You'll find it under Tools->NuGet Package Manager->Manage NuGet Packages for Solution.... The vlc control given by this VLC.DotNet package also lets you record and take snapshots from videos.

Here's a link to the wiki to help you start developing with the Vlc.DotNet package.

https://github.com/ZeBobo5/Vlc.DotNet/wiki/Getting-started