Pelco Developer Network (PDN)

Video Input and Video Output General Usage

 

Getting Started

 

Pelco Device Port Number

Pelco device port numbers will rarely change. However a device port number may change when a device restarts. While the port number still is unlikely to change when the device restarts, it is still good to account for it. For details on determining a device's current port number, refer to the Determining a Pelco Device's Port Number entry.

 

Pelco Device Control URL

All examples utilize a method of determining the device's control URL in a way that is not suitable for production. This was done to keep our example code simple, and focused on the main task being demonstrated.

C# Notes

For the C# code examples assume that you have either already generated proxy classes from the WSDLs or you have access to generated proxy classes.

If for some reason you want to generate the classes that represent the web services yourself, it is assumed that you will use MS Visual Studio (2005 or up) for WSDL stub/proxy class generation.

Video Output

Initializing a Connection to a Video Stream and Playing It

This entry is no longer the recommended way to play back a video stream. Instead, users should utilize RTSP natively for PELCO devices supporting it and/or through Pelco's RTSP Server reference implementations for products do not supporting it natively.
This entry is specific for situations that only require playing only one of a camera's streams.
Please refer to the Pelco Device Control URL and Pelco Device Port Number entries below for important details about the code sample.
  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the VideoOutput web service
  3. Begin creating your StreamParameters parameter
    • Initialize its StreamSession attribute. In this case we simply use the StreamSession attribute of the first StreamParameters result we find from a Query action result
      • View the code comments for details on how the StreamSession instance was configured
  4. Now make a request to the VideoOutput service's Connect action using your created StreamParameter instance as the parameter. If the request was valid, the action will return a StreamParameters instance with the following additional data (for use with a StreamControl Play request):
    The following example doesn't make use of the response data.
      • The URI of the StreamControl service that should be used to control the session.
      • The URI of the video source.
      • The sessionId to be used when addressing the StreamControl service. This refers to a specific video stream.
      • The transportURL which refers to the URL to which the video data will be streamed.
      • The transport state of the stream
      • The number of clients currently attached to the session.
  5. Make the stream play, by making a request to the StreamControl service's Play action along with the video stream session id and some other parameters. For more details on the Play action's parameters, refer to StreamControl's Play data type

C# Example

using CSharpIPCam.StreamControlRef;
using CSharpIPCam.VideoOutputRef;

static class Program
{
    static void Main()
    {
        string UniStreamIP = "10.80.136.238"; //Unicast IP address, normally the user PC IP address
        string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
        string UniListeningPort = ""; //You must insert your own Unicast Listening Port ex. 9000
        string cameraNumber = "1"; //Camera number on a multi-channel encoder

        try
        {
            VideoOutput videoOutput = new VideoOutput();

            //The URL where the service exists. (your requests are sent here.)
            videoOutput.Url = "http://" + CameraAddress + "/control/VideoOutput-" + cameraNumber;

            {
                System.Net.ServicePoint vosp = System.Net.ServicePointManager.FindServicePoint(new Uri(videoOutput.Url));
                vosp.Expect100Continue = false;
            }

            StreamQuery streamQuery = new StreamQuery();
            StreamCatalog streamCatalog = videoOutput.Query(streamQuery, ref asyncId, ref asyncIdSpecified); // Video Query
            StreamParameters sp = new StreamParameters(); // Stream Parameters
            sp.streamSession = streamCatalog.entries[0].streamSession; // Assign stream parameters session

            //Set to 1 (true) if you are only sending the iFrame portion of a video stream, 0 (false) otherwise.
            //The IFrame (or intra-coded frame) is a compressed version of a full MPEG video frame.
            //Setting this option to true requires less bandwidth and typically results in better performance
            sp.streamSession.iFrameOnly = 0;
            sp.preAlarmDurationInManualRecord = 0;

            //The URL to which the selected video data is transmitted
            //* By default, video streams are multicast unless this value is present
            sp.streamSession.transportURL = "rtp://" + UniStreamIP + ":" + UniListeningPort; // Set stream parameters Listening Port

            // When to start the stream (for continuous streaming use NOW).
            sp.streamSession.startTime = NOW;

            // Never end the stream (for continuous streaming use INFINITE).
            sp.streamSession.endTime = INFINITE;

            //This is the interval in seconds to be used in the RefreshSession action in the urn:schemas-pelco-com:StreamControl service indicated by controlURI.
            //If the camera does not receive any calls to the RefreshSession action within the specified interval, the video stream session identified by sessionId is disconnected.
            //* units are in seconds, minimum value is 30 and the maximum value is 900
            sp.streamSession.refreshInterval = 900;

            videoOutput.Connect(ref sp, ref asyncId, ref asyncIdSpecified); //Connect
            StreamControl streamControl = new StreamControl();
            streamControl.Url = "http://" + CameraAddress + "/control/StreamControl-" + cameraNumber;

            {
                System.Net.ServicePoint scsp = System.Net.ServicePointManager.FindServicePoint(new Uri(streamControl.Url));
                scsp.Expect100Continue = false;
            }

            //session id, speed, max bytes, actionVersion, actionVersionSpecified
            streamControl.Play(sp.streamSession.sessionId, 1, 52488, 0, false, ref asyncId, ref asyncIdSpecified, out streamPos, out streamPosSpecified); //Start Playing
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

Maintaining an Existing Video Stream Session and Keeping It Alive

To conserve resources and for security reasons, every video stream will eventually die after a set period of time. This is referred to as the refresh interval. Currently, the refresh interval ranges from 30 seconds to 15 minutes (based on current settings). This does not mean that new video stream instances need to be created every 30 seconds.

Refer to the Pelco Device Control URL and Pelco Device Port Number entries below for important details about the code sample.
  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the VideoOutput web service
  3. Send a request to the RefreshSession action along with a session id and the refresh interval value (30 - 900 seconds)

C# Example

using CSharpIPCam.VideoOutputRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            VideoOutput videoOutput = new VideoOutput();
            videoOutput.Url = "http://" + cameraAddress + "/control/VideoOutput-" + cameraNumber;

            {
                System.Net.ServicePoint scsp = System.Net.ServicePointManager.FindServicePoint(new Uri(videoOutput.Url));
                scsp.Expect100Continue = false;
            }

            //session id, refresh interval value
            videoOutput.RefreshSession( "uuid:0ba59aea1dd211b29820d054733cf8dd ", 900 );
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

Retrieving Live Video Stream Configuration Data

Refer to the Pelco Device Control URL and Pelco Device Port Number entries below for important details about the code sample.

To retrieve configuration data related to available live video streams, there are two methods:

Send a Request to the GetSessionParameters action of the VideoOutput Service

  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the VideoOutput web service
  3. Send a request to the GetSessionParameters action and include the stream's session ID

C# Example

using CSharpIPCam.VideoOutputRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            VideoOutput videoOutput = new VideoOutput();
            videoOutput.Url = "http://" + cameraAddress + "/control/VideoOutput-" + cameraNumber;

            {
                System.Net.ServicePoint vosp = System.Net.ServicePointManager.FindServicePoint(new Uri(videoOutput.Url));
                vosp.Expect100Continue = false;
            }

            StreamParameters sp = videoOutput.GetSessionParameters("uuid:bd56239c-1dd1-11b2-a4b1-da45d016f727");
            Console.WriteLine(sp.preAlarmDurationInManualRecord);
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

Send a Request to the Query action of the VideoOutput Service

  1. If you have not already done so, refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the VideoOutput web service
  3. Send a request to the Query action. If the request was accepted and there are results, you have received an array of StreamParameter instances (which belong to currently live streams)

C# Example

using CSharpIPCam.VideoOutputRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            VideoOutput videoOutput = new VideoOutput();
            videoOutput.Url = "http://" + cameraAddress + "/control/VideoOutput-" + cameraNumber;

            {
                System.Net.ServicePoint vosp = System.Net.ServicePointManager.FindServicePoint(new Uri(videoOutput.Url));
                vosp.Expect100Continue = false;
            }

            StreamCatalog sc = videoOutput.Query(new StreamQuery(), ref asyncId, ref asyncIdSpecified);
            StreamParameters[] stream_array = sc.entries;
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

Retrieving the Current Number of Live Video Streams Associated with a Device

In some cases, an IP camera may already have live video streams. There are two ways to determine the number of live video sessions: call either VideoOutput service's GetActiveSessions or GetActiveSessionIds actions along with the camera's URL/IP, the port number, and its number designation.

Refer to the Pelco Device Control URL and Pelco Device Port Number entries below for important details about the code sample.

For the first method:

  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the VideoOutput web service
  3. Call the GetActiveSessions action
    • this returns the number of active video streams and the maximum number of active video streams that the IP Camera can manage

C# Example

using CSharpIPCam.VideoOutputRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            VideoOutput videoOutput = new VideoOutput();
            videoOutput.Url = "http://" + cameraAddress + "/control/VideoOutput-" + cameraNumber;

            {
                System.Net.ServicePoint vosp = System.Net.ServicePointManager.FindServicePoint(new Uri(videoOutput.Url));
                vosp.Expect100Continue = false;
            }

            int numActiveSession = videoOutput.GetActiveSessions();
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

The second sample focuses on a request to the GetActiveSessionIds action.

  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the VideoOutput web service
  3. Call the GetActiveSessionIds action. Instead of returning the number of active and max number of possible active sessions, it returns the ids of currently active streams

C# Example

using CSharpIPCam.VideoOutputRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            VideoOutput videoOutput = new VideoOutput();
            videoOutput.Url = "http://" + cameraAddress + "/control/VideoOutput-" + cameraNumber;

            {
                System.Net.ServicePoint vosp = System.Net.ServicePointManager.FindServicePoint(new Uri(videoOutput.Url));
                vosp.Expect100Continue = false;
            }

            string[] actionSessionIds = videoOutput.GetActiveSessionIds();

            foreach (string entry in actionSessionIds)
            {
                Console.WriteLine(entry);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

Pausing a Video Stream

Sometimes users need to temporarily pause playback associated with sessionId instead of killing a live stream completely.

If the stream is a shared stream, (that is, multicast), a Pause request will not pause that particular video stream. Pause will only halt the stream if there is only one client connected to it.

Pause is a feature that is more suited to NVR/DVR devices.
Refer to the Pelco Device Control URL and Pelco Device Port Number entries below for important details about the code sample.
  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the StreamControl web service
  3. Make a call to the StreamControl web service's Pause action with the stream's session id. asyncId and asyncIdSpecified are only relevant to multicast streams

C# Example

using CSharpIPCam.StreamControlRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            StreamControl streamControl = new StreamControl();
            streamControl.Url = "http://" + cameraAddress + "/control/StreamControl-" + cameraNumber;

            {
                System.Net.ServicePoint scsp = 
                    System.Net.ServicePointManager.FindServicePoint(new Uri(streamControl.Url));
                scsp.Expect100Continue = false;
            }

            streamControl.Pause("uuid:bd56239c-1dd1-11b2-a4b1-da45d016f727", ref asyncId, ref asyncIdSpecified);
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}

 

Resume Playing a Paused Video Stream

After a user pauses an active video stream, this user will inevitably need to resume forward playback of that stream (using the stream's sessionId). This request does not affect the given video stream if that video stream was not in a Paused state.

While this works for IP Cameras, this action is more applicable in the context of an NVR device.
Refer to the Pelco Device Control URL and Pelco Device Port Number entries below for important details about the code sample.
  1. If you have not already done so, please refer to the "Getting Started" section.
  2. Initialize an instance of the class that acts as a representative of the StreamControl web service
  3. Make a request to Play action with the stream's session id

C# Example

using CSharpIPCam.StreamControlRef;

static class Program
{
    static void Main()
    {
        try
        {
            string cameraAddress = "10.80.136.194:49152"; //camera URL or IP address followed by the port number
            string cameraNumber = "1"; //Camera number on a multi-channel encoder
            StreamControl streamControl = new StreamControl();
            streamControl.Url = "http://" + cameraAddress + "/control/StreamControl-" + cameraNumber;

            {
                System.Net.ServicePoint scsp = 
                    System.Net.ServicePointManager.FindServicePoint(new Uri(streamControl.Url));
                scsp.Expect100Continue = false;
            }

            //session id, speed, max bytes, actionVersion, actionVersionSpecified
            streamControl.Play("uuid:bd56239c-1dd1-11b2-a4b1-da45d016f727", 1, 52488, 0, false, 
                ref asyncId, ref asyncIdSpecified, out streamPos, out streamPosSpecified);
        }
        catch (Exception ex)
        {
            Console.WriteLine( ex.ToString() );
        }
    }
}