XPSDKDownstreamVideoConnection

@interface XPSDKDownstreamVideoConnection : XPSDKVideoConnection

XPSDKDownstreamVideoConnection

The XPSDKDownstreamVideoConnection class handles the entire delivery of frames from the server to the client. It is not responsible for sending any commands to the server - opening, closing, pausing and etc of a video stream is handled by the XPVideoConnection class.

A video connection basically is a stream of frames from the server to the app. Each frame has a header with some optional fields and optional image (JPEG for the moment). The header may contain information about recording state, motion state, information about changes in the image, changes in the playback state and etc.

A video connection should operate with a delegate. It receives the events and images from the video connection and processes them in any way it wants - display them, change app state and etc.

The implementation of the video connection uses low-level streams & sockets instead of NSURLConnection. The reason is a limitation in the iOS - we cannot keep more than 6 opened connections to the same protocol/host/port. Which means if we start up to 6 cameras and we won’t be able to send commands over the meta connection. Extra requests are being queued. Using sockets goes around that limitation, because it appears to be built in the NSURLConnection class.

The video connection class has very rudimentary support for parsing HTTP headers - just enough to detect if there is HTTP error from the server.

The video connection also supports restoring after broken data stream. When a frame is parsed its header is analyzed and if the video ID and other values in the header structure are wrong it enters a special self repare mode. When in that mode the incomming data is constantly analyzed to attempt to locate the next frame start. If is is found the class attempts to construct complete frame from that location in the data. If sucessfull resumes normal operation and notifies the delegate with the frame. All earlier that is simply discarded.

  • Method of connection

    Declaration

    Objective-C

    XPSDKVideoConnectionMethod method
  • Type of connection signal

    Declaration

    Objective-C

    XPSDKVideoConnectionSignal signal
  • The server address

    Declaration

    Objective-C

    NSString * serverAddress
  • The server port

    Declaration

    Objective-C

    NSUInteger serverPort
  • Data comming from the server

    Declaration

    Objective-C

    NSInputStream * inputStream
  • Data we are sending to the server

    Declaration

    Objective-C

    NSOutputStream * outputStream
  • Raw incoming data buffer

    Declaration

    Objective-C

    uint8_t *buffer
  • Incoming data buffer

    Declaration

    Objective-C

    NSMutableData * responseData
  • Camera resolution

    Declaration

    Objective-C

    CGSize sourceSize
  • The ID of the camera

    Declaration

    Objective-C

    XPSDKViewID cameraID
  • Flag to indicate if camera uses transcoding

    Declaration

    Objective-C

    BOOL usesTranscoding
  • Flag - set to YES if the connection has received all HTTP headers and should begin searching for frames

    Declaration

    Objective-C

    BOOL httpHeaderParsed
  • Flag, used by Pull mode connection - set to yes if the delegate has been informed of a received response (videoConnection:receivedResponse: callback)

    Declaration

    Objective-C

    BOOL receivedResponseSentToDelegate
  • Keeps all http headers of the response

    Declaration

    Objective-C

    NSMutableArray * headerLines
  • Used in case of broken data stream - keeps the video ID as NSData so we can search for in the incomming byte stream and possibly locate the next frame start

    Declaration

    Objective-C

    NSData * searchForUUID
  • Resolution of the camera. It is the delegate’s responsibility to update this property on resolution change!

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int sourceSize;
  • ID of the camera the connection has been initiated to

    Declaration

    Objective-C

    @property (readonly, nonatomic) XPSDKViewID cameraID;
  • Video connection signal

    Declaration

    Objective-C

    @property (readonly, nonatomic) XPSDKVideoConnectionSignal signal;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsLive;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsPlayback;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsPTZ;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsPTZPresets;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsSequences;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsAviExports;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int supportsJpegExports;
  • Set by the main connection when creating the object. It should not be changed.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) int originalSizeRequested;
  • Server address

    Declaration

    Objective-C

    @property (readonly, nonatomic) int *serverAddress;
  • Server port

    Declaration

    Objective-C

    @property (readonly, nonatomic) int serverPort;
  • Designated initializer. Instances should only ne created by the main connection!

    Declaration

    Objective-C

    - (id)initFromControlConnection:(XPSDKConnection *)mainConnection
                           cameraID:(XPSDKViewID)camid
                            videoID:(XPSDKVideoID)vid
                             method:(XPSDKVideoConnectionMethod)connectionMethod
                             signal:(XPSDKVideoConnectionSignal)signalType
                         sourceSize:(id)size
                    usesTranscoding:(id)transcoding;

    Parameters

    mainConnection

    the main connection from which the video connection is derived.

    camid

    ID of the camera

    vid

    Video ID

    connectionMethod

    The method of connection

    signalType

    The Type of signal

    size

    The resolution of the camera

  • Designated initializer. Instances should be only created by the main connection!

    Declaration

    Objective-C

    - (id)initWithServerURL:(id)serverURL
                   cameraID:(XPSDKViewID)camid
                    videoID:(XPSDKVideoID)vid
                     method:(XPSDKVideoConnectionMethod)connectionMethod
                     signal:(XPSDKVideoConnectionSignal)signalType
                 sourceSize:(id)size
            usesTranscoding:(id)transcoding;

    Parameters

    url

    Server url

    camid

    ID of the camera

    vid

    Video ID

    connectionMethod

    The method of connection

    signalType

    The Type of signal

    size

    The resolution of the camera

  • Opens the connection to the video server

    Declaration

    Objective-C

    - (void)open;
  • Allows changing the desired fps

    Declaration

    Objective-C

    - (void)setDesiredFps:(id)fps
        withSuccessHandler:(void (^)(XPSDKResponse *))successHandler
         andFailureHandler:(void (^)(int *))failureHandler;