## 1. GB28181 Protocol Live Streaming Flow for Monitoring Devices

### 1.1 Interaction Flow Between the FastBee Platform and Monitoring Devices

```mermaid
%%{init: {"theme": "base", "themeVariables": {"background": "transparent", "primaryColor": "#edf4ff", "primaryTextColor": "#1f2937", "primaryBorderColor": "#536dfe", "lineColor": "#334155", "textColor": "#1f2937", "actorBkg": "#edf4ff", "actorBorder": "#536dfe", "actorTextColor": "#1f2937", "signalColor": "#334155", "signalTextColor": "#1f2937", "sequenceNumberColor": "#1f2937", "activationBkgColor": "#dbeafe", "activationBorderColor": "#536dfe", "noteBkgColor": "#fff7ed", "noteTextColor": "#1f2937", "noteBorderColor": "#f59e0b"}}}%%
sequenceDiagram
  autonumber
  participant D as Device
  participant F as FastBee
  participant Z as ZLMediaKit
  participant P as Player
  F->>Z: Call openRtpServer to create an RTP service
  Z-->>F: Return the RTP streaming port
  F->>D: INVITE (carrying SDP)
  D-->>F: 100 Trying
  D-->>F: 200 OK (carrying SDP)
  F->>D: ACK
  D->>Z: Push the RTP stream
  Z-->>F: onPublish / onStreamChanged Hook
  P->>Z: Pull the FLV live stream
  Z-->>F: onPlay Hook
```

#### 1. Flow Description

a. The FastBee platform calls the ZLMediaKit API /index/api/openRtpServer to create an RTP server, and fills the returned RTP streaming port into the SDP information of the Invite message

b. The FastBee platform (SIP server) sends an Invite message to the device. The message header carries the Subject field, indicating parameters such as the video source ID of the on-demand request, the sender media stream sequence number, the media stream receiver ID, and the receiver media stream sequence number. In the SDP message body, the s field is "Play", which represents real-time on-demand streaming

c. After receiving the Invite request from the FastBee platform (SIP server), the device first replies with a 100 Trying response, then replies with a 200 OK response carrying the SDP message body, which describes the IP, port, media format, SSRC field, and other content of the media stream sent by the device

d. After receiving the 200 OK response returned by the device, the FastBee platform (SIP server) sends an ACK request to the device. The request carries no message body, completing the Invite session establishment process with the device.

e. The device pushes the stream to the RTP server created by ZLMediaKit

f. ZLMediaKit notifies the FastBee platform through the onPublish hook API that the stream has been published, and performs streaming authentication. The FastBee platform responds with information such as the pull protocols to enable and the stream configuration. ZLMediaKit notifies the FastBee platform through the onStreamChanged hook API about the stream registration status of streamers with different protocols

g. The player pulls the FLV live stream according to the configured default playback address

h. ZLMediaKit notifies the FastBee platform through the onPlay hook API that the player has started playing, and performs playback authentication

### 1.2 Steps Where Major Problems Occur

· In steps b, c, and d, the data packets do not follow the standard protocol format, causing problems in establishing the live streaming session\
· ZLMediaKit configuration problems: check the API http/https ports (8082, 8443), the RTP receiving ports (udp 30000-30100), the HTTPS certificate, and so on\
· Whether connectivity between the device and the server is normal: device SIP packets -> server java 5061; device RTP streaming -> ZLMediaKit 30000-30100. If either is unreachable, the device streaming in step e will fail\
· Whether the hook API is configured correctly: if the Java application is deployed in a container, the hook API is java:8080; if the Java application is started in IDEA and the ZLMediaKit server is started in Docker on the local machine, the hook API is host.docker.internal:8080. Incorrect configuration will cause problems with the callback APIs in steps f and h

### 1.3 Packet Capture Screenshot

<img alt="1.3 Packet capture screenshot" src="../../../../business/v2/dev/images/video/video40.png" style="border:1px solid #ccc;border-radius:6px;margin:8px 0;" loading="lazy" />

### 1.4 GB28181 Standard Live Streaming Protocol Flow

```mermaid
%%{init: {"theme": "base", "themeVariables": {"background": "transparent", "primaryColor": "#edf4ff", "primaryTextColor": "#1f2937", "primaryBorderColor": "#536dfe", "lineColor": "#334155", "textColor": "#1f2937", "actorBkg": "#edf4ff", "actorBorder": "#536dfe", "actorTextColor": "#1f2937", "signalColor": "#334155", "signalTextColor": "#1f2937", "sequenceNumberColor": "#1f2937", "activationBkgColor": "#dbeafe", "activationBorderColor": "#536dfe", "noteBkgColor": "#fff7ed", "noteTextColor": "#1f2937", "noteBorderColor": "#f59e0b"}}}%%
sequenceDiagram
  autonumber
  participant R as Media Stream Receiver
  participant S as SIP Server
  participant M as Media Server
  participant T as Media Stream Sender
  R->>S: INVITE (carrying SDP)
  S->>M: INVITE
  M-->>S: 200 OK (carrying SDP)
  S->>T: INVITE (carrying SDP)
  T-->>S: 200 OK (carrying SDP)
  S->>M: ACK (carrying SDP)
  S->>T: ACK
  T-->>M: Real-time media stream
  S->>M: INVITE (carrying SDP)
  M-->>S: 200 OK (carrying SDP)
  S-->>R: 200 OK (carrying SDP)
  R->>S: ACK
  S->>M: ACK
  M-->>R: Real-time media stream
  R->>S: BYE
  S-->>R: 200 OK
  S->>M: BYE (close the receiving session)
  M-->>S: 200 OK
  S->>M: BYE (close the forwarding session)
  M-->>S: 200 OK
  S->>T: BYE
  T-->>S: 200 OK
```

### 1.5 Player URL Examples

#### 1. HTTP and HTTPS

Under the HTTP protocol, the server is: http://ip:port, for example: http://192.168.1.66:8082

Under the HTTPS protocol, the server is `https://domain:port`, for example `https://fastbee.cn:8443` (format example only, not a live service)

#### 2. FLV Protocol

Playback URL format: server/rtp/streamID.live.flv\
Example: http://192.168.1.66:8082/rtp/gb\_play\_11010100001320000001\_11010100001320000001.live.flv

`https://fastbee.cn:8443/rtp/gb_play_11010100001320000001_11010100001320000001.live.flv` (format example only)

#### 3. FMP4 Protocol

Playback URL format: server/rtp/streamID.live.mp4\
Example: http://192.168.1.66:8082/rtp/gb\_play\_11010100001320000001\_11010100001320000001.live.mp4

`https://fastbee.cn:8443/rtp/gb_play_11010100001320000001_11010100001320000001.live.mp4` (format example only)

#### 4. RTMP Protocol

Playback URL format: rtmp://ip:port/rtp/streamID

Example: rtmp://192.168.1.66:1935/rtp/gb\_play\_11010100001320000001\_11010100001320000001

#### 5. RTSP Protocol

Playback URL format: rtsp://ip:port/rtp/streamID

Example: rtsp://192.168.1.66:554/rtp/gb\_play\_11010100001320000001\_11010100001320000001
