# onCuePoint Message Insertion

라이브 스트림을 RTMP 프로토콜로 다른  시스템에 재스트리밍 할 때 AMF0 message를 삽입 할 수 있습니다. 이 기능을 활용하여 자막 삽입, 광고 마커 삽입과 같은 message를 다른 시스템에 전달 할 수 있습니다. message를 삽입하는 방법은 아래와 같습니다.

* RTMP Provider를 통해 입력받은 Media Source에 message가 포함되어 있는 경우 자동으로 삽입 됩니다.
* OvenMediaEngine의 Send Event API를 사용하여 동적으로 message를 삽입 할 수 있습니다.

## onCuePoint message 삽입하기

`onCuePoint` message는 Youtube 라이브 방송에 자동 광고 Cue Point 삽입을 위한 목적으로 사용됩니다.

### API Interface

**Request**

<details>

<summary><mark style="color:blue;">POST</mark> /v1/vhosts{vhost}/apps/{app}/streams/{stream}:sendEvent</summary>

**Header**

```http
Authorization: Basic {credentials}

# Authorization
Credentials for HTTP Basic Authentication created with <AccessToken>
```

**Body**

```json
{
  "eventFormat": "amf",
  "events":[
    {
      "amfType": "onCuePoint.YouTube",
      "version": "0.1",
      "preRollTimeSec": 2.56,
      "cuePointStart": true,
      "breakDurationSec": 30,
      "spliceEventId": 0
    }
  ]
}
```

</details>

<details>

<summary><mark style="color:blue;">POST</mark> /v1/vhosts{vhost}/apps/{app}/streams/{stream}:sendEvents</summary>

**Header**

```http
Authorization: Basic {credentials}

# Authorization
Credentials for HTTP Basic Authentication created with <AccessToken>
```

**Body**

```json
[
  {
    "eventFormat": "id3v2",
    "eventType": "video", // "eventTarget": "video" is same
    "events":[
      {
        "frameType": "TXXX",
        "info": "AirenSoft",
        "data": "OvenMediaEngine"
      },
      {
        "frameType": "TIT2",
        "data": "OvenMediaEngine 123"
      }
    ]
  },
  {
    "eventFormat": "amf",
    "events":[
      {
        "amfType": "onCuePoint.YouTube",
        "version": "0.1",
        "preRollTimeSec": 2.56,
        "cuePointStart": true,
        "breakDurationSec": 30,
        "spliceEventId": 0
      }
    ]
  }
]
```

</details>

**Responses**

<details>

<summary><mark style="color:blue;">200</mark> Ok</summary>

The request has succeeded

**Header**

```http
Content-Type: application/json
```

**Body**

```json
{
    "message": "OK",
    "statusCode": 200
}
```

</details>

<details>

<summary><mark style="color:red;">400</mark> Bad Request</summary>

Invalid request. Body is not a Json Object or does not have a required value

</details>

<details>

<summary><mark style="color:red;">401</mark> Unauthorized</summary>

Authentication required

**Header**

```http
WWW-Authenticate: Basic realm=”OvenMediaEngine”
```

**Body**

```json
{
    "message": "[HTTP] Authorization header is required to call API (401)",
    "statusCode": 401
}
```

</details>

<details>

<summary><mark style="color:red;">404</mark> Not Found</summary>

The given vhost name or application name could not be found.

**Body**

```json
{
    "message": "[HTTP] Could not find the application: [default/app2] (404)",
    "statusCode": 404
}
```

</details>

## Payload 예제

AMF0로 인코딩 된 `onCuePoint` message payload의 예제입니다.

```
string-marker “onCuePoint”
object-marker
“type” string-marker “com.youtube.cuepoint”
“version” string-marker “0.1”
“pre_roll_time_sec” number-marker 2.56
“cue_point_start” boolean-marker 1
“break_duration_sec” number-marker 30
“splice_event_id” number-marker 0
UTF-8-empty object-end-marker
```
