Network Protocol Reference

The following documentation describes the lowest level interface to the Virtual Video Tool, and can be used to create client applications on most platforms and programming languages. Before reading the following documentation, users should review the architecture of the Virtual Video Tool described here. The Camera and PTZ Servers are both based on the Windows Sockets 2 API, and can communicate with any compatible socket library. The following table gives the default port numbers on which users can connect to the servers.

Server Port
Camera Server 3166
PTZ Server 3165

Each connection to the PTZ Server can create a new virtual PTZ controller or connect to an existing controller, and similarly each connection to the Camera Server can create and configure a new virtual camera or stream video from an existing camera. Static cameras do not require a connection to the PTZ Server. Each virtual camera is identified by a unique camID, set by the client using the Set Camera ID command; each virtual PTZ controller is identified by a unique ptzID, set using the Set PTZ ID command. A camera can be directed to follow motion commands from a particular virtual PTZ controller by specifying the corresponding ptzID in a Set Camera Type command (and also setting the PTZ control flag field to a non-zero value). This framework allows for static cameras, multiple independent PTZ cameras, and special configurations such as a stereo PTZ cameras in which multiple cameras share the same PTZ controller.

To connect to either server, clients should create a connection-oriented TCP socket and connect to the appropriate port listed above. The following C code snippet shows how to connect to the camera server on localhost (to connecting over a network, replace 127.0.0.1 with the address of the PC running the mod):

SOCKET sock;
sockaddr_in local;
sock = socket(AF_INET, SOCK_STREAM, 0);
local.sin_family=AF_INET;
local.sin_addr.s_addr = inet_addr("127.0.0.1");
local.sin_port=htons(3166);
connect(sock,(sockaddr*)&local,sizeof(local));

The protocol for sending server commands is identical for both servers, and described in the following notes:

  • Each command consists of a single command packet.
  • For every command packet, the server sends a single response packet.
  • The command and response packets have identical structure: a single command byte, followed by zero or more data bytes, as illustrated below. For a given instruction, the command byte is identical in both the command and response packets but the number of data bytes usually differ.

For example, to set the camera intrinsic parameters to 320x240 pixels, 15 frames/sec and 45 degree FOV (see the Set Intrinsic Parameters command below), a client would send the following byte packet to the camera server (recalling that PCs are little-endian):

{0x05, 0x40, 0x01, 0, 0, 0xf0, 0, 0, 0, 0x0f, 0, 0, 0, 0x2d, 0, 0, 0}

The server would then respond with the following single byte packet:

{0x05}

A typical client application would implement the following sequence of commands:

  • Establish a socket connection to the Camera Server and PTZ Server (if active control is required) as outlined above.
  • Create a new camera at by sending a Set Camera ID command to the Camera Server and specifying a unique non-zero identifier in the camera ID field. Note that this step is not necessary if you just intend to use one camera, ie. the default camera.
  • Retrieve the default camera settings by sending the Get Camera Type, Get Intrinsic Parameters and Get Extrinsic Parameters commands to the Camera Server.
  • Make appropriate changes to the default parameters, and send the new parameters to the Camera Server using Set Camera Type, Set Intrinsic Parameters and Set Extrinsic Parameters.
  • If active control is required, the Set Camera Type command should set the PTZ control flag to a non-zero value and set PTZ controller ID to the ptzID of an existing controller (eg. the default controller, ptzID = 0).
  • In the main processing loop, retrieve the latest rendered frame by sending the Get Latest Frame command to the Camera Server. Active PTZ control commands can be sent to the PTZ server using the Set PTZ Status command.
  • Before closing the client application, close the network sockets to disconnect from the servers.

Below is an index of available server commands. The following sections describe the commands in detail, including the command byte, data bytes sent in the command packet and data bytes received in the response.

Camera Server Commands:

PTZ Server Commands:

Camera Server Commands
 
Get Camera ID
Command byte: 0x01
Data bytes sent: none
Data bytes recv: 0-3: (int) camera ID
Description: Gets the Camera ID that identifies the camera to which the client is connected.
 
Set Camera ID
Command byte: 0x02
Data bytes sent: 0-3: (int) camera ID
Data bytes recv: none
Description: Sets the Camera ID that identifies the camera to which the client is connected. If a camera with the corresponding ID already exists, the client is connected to that camera without modifying existing camera settings. If a camera with the corresponding ID does not exist, a new camera is created with the requested ID and default camera settings.
 
Get Camera Type
Command byte: 0x03
Data bytes sent: none
Data bytes recv: 0-3: (int) camera type: standard=0, omni=1
4-7: (int) PTZ control flag
8-11: (int) PTZ controller ID
12-111: (string) path on server to save frames (max 100 chars)
Description: Get global camera settings. Camera type can be 'standard' for a regular projective camera or 'omni' for a spherically projected 360 degree camera. A non-zero value for the PTZ control flag indicates that the camera will respond to Set PTZ Status commands (with matching PTZ controller ID) sent to the PTZ server (see below). PTZ control is initially disabled on new camera connections, and has no effect on omnicams. The final field is a null-terminated string indicating the directory on the server to which all rendered frames are saved. Frames are named clientCCC_frmNNNN.jpg where CCC is the client number (increases for each new connection) and NNNN is the frame number. An empty string for the path indicates that saving of frames is currently disabled. Note: Saving frames to disk incurs a small but noticable hit on rendering performance.
 
Set Camera Type
Command byte: 0x04
Data bytes sent: 0-3: (int) camera type: standard=0, omni=1
4-7: (int) PTZ control flag
8-11: (int) PTZ controller ID
12-111: (string) path on server to save frames (max 100 chars)
Data bytes recv: none
Description: Set global camera settings. Camera type can be 'standard' for a regular projective camera or 'omni' for a spherically projected 360 degree camera. To enable PTZ control, set the 'PTZ control flag' to a non-zero value and 'PTZ controller ID' to a value that matches the ID in the Set PTZ Status command. The final field is a null-terminated string indicating the directory on the server to which all rendered frames (even those not retrieved by the client) are to be saved. Frames are named clientCCC_frmNNNNNN.jpg where CCC is the client number (increases for each new connection) and NNNNNN is the frame number. Setting this field to an empty string disables saving of frames. Note: The server must have write access to the specified directory, and saving frames to disk incurs a small but noticable hit on rendering performance. Finally, frames are not saved when a camera has no active client connection.
 
Get Instrinsic Parameters
Command byte: 0x05
Data bytes sent: none
Data bytes recv: 0-3: (int) frame width in pixels
4-7: (int) frame height in pixels
8-11: (int) frame rate in frames/sec
12-15: (float) FOV in deg
Description: Set the instrinsic camera parameters. Framerate should be treated as a maximum framerate; the actual framerate may be lower depending on computational load. Also note that retrieving the latest frame more frequently than the framerate may result in duplicate frames.
 
Set Instrinsic Parameters
Command byte: 0x06
Data bytes sent: 0-3: (int) frame width in pixels
4-7: (int) frame height in pixels
8-11: (int) frame rate in frames/sec
12-15: (float) FOV in deg
Data bytes recv: none
Description: Get the current intrinsic camera parameters. Framerate should be treated as a maximum framerate; the actual framerate may be lower depending on computational load.
 
Get Extrinsic Parameters
Command byte: 0x07
Data bytes sent: none
Data bytes recv: 0-3: (float) x-coordinate (forward) of camera in inches
4-7: (float) y-coordinate (left) of camera in inches
8-11: (float) z-coordinate (up) of camera in inches
12-15: (float) rotation about x axis in deg
16-19: (float) rotation about y axis in deg
20-23: (float) rotation about z axis in deg
Description: Get the position and orientation of the camera with repsect to the initial player position in the map. Angles are with respect to right-handed convention and applied in order x, y, z when computing orientation.
 
Set Extrinsic Parameters
Command byte: 0x08
Data bytes sent: 0-3: (float) x-coordinate (forward) of camera in inches
4-7: (float) y-coordinate (left) of camera in inches
8-11: (float) z-coordinate (up) of camera in inches
12-15: (float) rotation about x axis in deg
16-19: (float) rotation about y axis in deg
20-23: (float) rotation about z axis in deg
Data bytes recv: none
Description: Set the position and orientation of the camera with repsect to the initial player position in the map. Angles are with respect to right-handed convention and applied in order x, y, z when computing orientation.
 
Get Latest Frame
Command byte: 0x09
Data bytes sent: none
Data bytes recv: 0-3: (int) frame number
4-7: (float) elapsed time in seconds since game launched
8-11: (int) frame width in pixels
12-15: (int) frame height in pixels
16-19: (float) camera horizontal field of view in degrees
20-24: (float) camera x-coord (forward) in inches relative to world origin
24-27: (float) camera y-coord (left) in inches relative to world origin
28-31: (float) camera z-coord (up) in inches relative to world origin
32-35: (float) camera rotation about x axis in deg
36-39: (float) camera rotation about y axis in deg
40-43: (float) camera rotation about z axis in deg
44-47: (int) J = length in bytes of jpeg data
48-51: (int) T = number of ground truth targets
52-55: (int) L = length in elements of RLE encoded label map data
data buffer (J bytes): jpeg compressed frame
data buffer (T*56 bytes): target ground truth data
data buffer (L*4 bytes): run-length encoded label map data
Description: Retrieve the latest rendered frame, along with camera parameters used to generate the frame and target ground truth (if available). The frame number can be used to detect duplicate frames, ie. if Get Latest Frame is called again before the next frame is rendered then the frame number will be unchanged. Note that the camera position is specified relative to the world origin, rather than the initial player position as used in Get Extrinsic Parameters. Target ground truth generation is enabled using the groundtruth console command, otherwise T=0 and L=0. If ground truth is enabled, the target ground truth data contains T 56-byte elements with the following structure:

Target ground truth data bytes:
0-3: (int) target label
4-7: (float) x-coord of 3D target centroid in inches
8-11: (float) y-coord of 3D target centroid in inches
12-15: (float) z-coord of 3D target centroid in inches
16-19: (int) top y-coord of bounding box around visible target pixels
20-23: (int) bottom y-coord of bounding box around visible target pixels
24-27: (int) left x-coord of bounding box around visible target pixels
28-31: (int) right x-coord of bounding box around visible target pixels
32-35: (int) number of visible foreground pixels in bounding box
36-39: (int) top y-coord of bounding box around all target pixels
40-43: (int) bottom y-coord of bounding box around all target pixels
44-47: (int) left x-coord of bounding box around all target pixels
48-51: (int) right x-coord of bounding box around all target pixels
52-55: (int) number of foreground pixels in bounding box

See Ground Truth for an explanation of ground truth data. The ground truth foreground label map is provided as a run-length encoded image buffer with L 32-bit integer elements, where each pixel label corresponds to a target label in the above structure. Details on decoding this map are provided in Ground Truth.
PTZ Server Commands
 
Get PTZ ID
Command byte: 0x01
Data bytes sent: none
Data bytes recv: 0-3: (int) controller ID (ptzID)
Description: Gets the ptzID that identifies the controller to which the client is connected.
 
Set PTZ ID
Command byte: 0x02
Data bytes sent: 0-3: (int) controller ID (ptzID)
Data bytes recv: none
Description: Sets the ptzID that identifies the controller to which the client is connected. If a controller with the corresponding ID already exists, the client is connected to that controller without modifying existing controller settings. If a controller with the corresponding ID does not exist, a new controller is created with the requested ID and default controller settings.
 
Get PTZ Status
Command byte: 0x03
Data bytes sent: none
Data bytes recv: 0-3: (float) pan in deg
4-7: (float) pan_vel in deg/sec
8-11: (float) tilt in deg
12-15: (float) tilt_vel in deg/sec
16-19: (float) zoom in multiples of focal length
20-23: (float) zoom vel in magnification/sec
Description: Retrieve the target pan, tilt, zoom and velocities sent by the last Set PTZ Status command. Absolute positions are always returned regardless of the current control mode. Note that the target parameters may differ slightly from the actual current position and velocity of the camera depending on the control mode and specified velocities (see Set PTZ Status).
 
Set PTZ Status
Command byte: 0x04
Data bytes sent: 0: (byte) mode flags
1-4: (float) pan in deg
5-8: (float) pan_vel in deg/sec
9-12: (float) tilt in deg
13-16: (float) tilt_vel in deg/sec
17-20: (float) zoom in multiples of focal length
21-24: (float) zoom vel in magnification/sec
Data bytes recv: none
Description: Set the target pan, tilt, zoom and velocities. The bits of the mode flags byte determine how the position and velocity parameters are interpreted, and are defined as follows:

Bit Description
0-1 Control mode:
  00 = Send axis to absolute position at specified velocity
  01 = Offset axis relative to current position at specified velocity
  10 = Move axis at specified velocity (position ignored)
2 If set, ignore pan position
3 If set, ignore pan velocity
4 If set, ignore tilt position
5 If set, ignore tilt velocity
6 If set, ignore zoom position
7 If set, ignore zoom velocity

The mode flags allow the axes to be controlled independently in different control modes. To update all axes in absolute position mode, set mode flags = 0x00. Note that changes in camera position may not be instantaneous; camera will take some time to reach the target position depending on the control mode and specified velocity.
 
Get Auto Scan
Command byte: 0x05
Data bytes sent: none
Data bytes recv: 0-3: (float) minimum pan angle in degrees
4-7: (float) maximum pan angle in degrees
8-11: (float) pan velocity in deg/sec
12-15: (float) tilt angle in degrees
16-19: (float) zoom in multiples of focal length
20-23: (int) scanning flag
Description: Returns the current scanning parameters (see Set Auto Scan). A non-zero value for the scanning flag indicates that the camera is currently in automatic scanning mode, while a value of zero indicates that the camera is static.
 
Set Auto Scan
Command byte: 0x06
Data bytes sent: 0-3: (float) minimum pan angle in degrees
4-7: (float) maximum pan angle in degrees
8-11: (float) pan velocity in deg/sec
12-15: (float) tilt angle in degrees
16-19: (float) zoom in multiples of focal length
20-23: (int) scanning flag
Data bytes recv: none
Description: In automatic scanning mode, the camera pans back and forth at a fixed tilt, zoom and angular velocity set by the parameters. A non-zero value for the scanning flag enables automatic scanning mode, while a value of zero disables scanning (however the internal scanning parameters are still updated and can be retrieved with Get Auto Scan). This command has no effect on an omnicam.
© Copyright ObjectVideo, 2006. All rights reserved.