# 请求摄像头视频文件协议

## 目的

当云端需要某时间段的视频时, 可按本文定义的协议按需从摄像头获取视频文件. 应用场景包括但不仅限于**视频补缺, 视频重传**

## 总览

```mermaid
sequenceDiagram
  participant JavaVideoUploadSVC
	participant CloudSvc_X
	participant MessageBroker
	participant EVCamera
	EVCamera ->> MessageBroker: sub <<MD>> VIDEO_FILE_REQ
	CloudSvc_X ->> MessageBroker: pub <<MD>>VIDEO_FILE_REQ
	MessageBroker ->> EVCamera: Notify
	EVCamera ->>EVCamera: <<FD>>VIDEO_FILE_REQ_HANDLE
	EVCamera ->>JavaVideoUploadSVC: UPLOAD_STREAM_TRANSFER [defined in video_upload_stream.md]
	JavaVideoUploadSVC ->>CloudSvc_X: Notify {file_url, file_meta}
```

## 消息定义 VIDEO_FILE_REQ

#### MQTT (proposed)

```yaml
topic: evcamera/v1.0/request/<CAMERA_SN>
qos: 1
retain: false
payload: {
  "time": 1567669674,
  "cmd": "upload_video",
  "rid": "<random_str>",
  "data": {
    {
      "start": 1567669674,
      "end": 1567668000,
      "type": 6
    }
}
```

#### RabbitMQ(when durability is mandatory)

```yaml
routing_key: evcamera.v1.video.request.<CAMERA_SN>
payload: {
  "time": 1567669674,
  "cmd": "upload_video",
  "rid": "<random_str>",
  "data": {
    {
      "start": 1567669674,
      "end": 1567668000,
      "type": 6
    }
}
```



### Response

```json
{
  "time": 1567669674,
  "type": "response",
  "rid": "<request_rid>",
  "cata": "upload_video",
  "sn": "A000000Z",
  "code": 1,
  "msg": "failed to upload video: file not exist",
  "data":{
    // empty
  }
}
```



```json
{    "time":1567669674,    "cmd":"upload_video",    "rid":"001231554A20",    "data":{       "start":1590716600,       "end":1590716700,       "type":6    } }
```

