#author Maxim Petrov, VideoNext
#title Connectionless DVR support. Design/Implementation

<contents>

* Basic concepts and terminology

Normally SKM always establishes connect to DVRs and retrieves media
while device is alive. But sometimes it's impossible for some reason
or other. For example device can be behind firewall or even there is no
such possibility (mobile phones). In this case we need to find another
way to retrieve media data. As rule there are two types of those devices: 

 1. Mobile phones with camera inside.
 2. IP, USB cameras configured and prepared on client side.

This document is only describing configuration and retrieving media data
in the SKM. The primary target is keep whole architecture of SKM
unchanged, but just extend. Configuration and handling of such devices
should be simple and transparent as though, as if they are usual IP-cameras. 


* Configuration

The new type of devices should appear in SKM admin GUI (Source->Video
Device). The name of device is not yet defined. But for example can be
"Push in device". Also new text field should appear in case if
this type of device is selected. It's "Device ID". This is
identifier used for authentications needs. For IP-cameras it can be
MAC-address, for mobile phones - IMEI, for USB-cameras - ProductID or
something like this. The rest (useless) fields should be hidden. After
new device is configured, the cam_patrol starts media retriever for
this device and just does work like for usual. No changes in
cam_patrol is expected for now. 

* Implementation

As we see from  "Implementation diagram" external DVR will establish
connect to SKM WEB-server and sends jpeg frames using HTTP POST
method. Important that we must support "Keep-Alive" mode to prevent
connection procedure for every new frame. Apache module will be
implemented on C++ and have only two tasks:

 1. Client authentication (by Device ID which should be sent in one of
    HTTP header).
 2. Write jpeg frame to local domain socket where media retriever will
    listen and wait. 

Media retriever opens local domain socket and waits for data from
apache module. The rest scheme is same as for normal device. When
retriever got frame, it send one to storage and to media server. Etc..
Other words main point that media retriever is working almost all time
in "IDLE" state. And only when local socket becomes active retriever starts
retrieve and stream media data. 
Example of HTTP POST request from DVR to SKM:
<example>
POST /storage/get_frame HTTP/1.1
Host: demo.videonext.com
Content-Length: 12345
Device-ID: 12345dd5656f
[Geo-Latitude: ....]
[Geo-Longitude: ....]

<jpeg-data>

</example>


[[impl.png][Implementation diagram]]

* Conclusion

The effort:
 1. Apache module 
 2. Retriever module which will allow access to local domain socket.

As you see the changes are simple. 

