Skip to main content
Version: 8.0 (Unstable) 🚧🚀

GB28181

SRS uses an external SIP server, such as srs-sip, for GB28181 signaling and receives the media stream as RTP/PS over TCP. The external SIP server creates the SRS media session through the HTTP API, then instructs the device to publish to the TCP port returned by SRS.

Build SRS with GB28181 enabled:

./configure --gb28181=on && make

Configure the GB28181 stream caster:

stream_caster {
    enabled on;
    caster gb28181;
    output rtmp://127.0.0.1/live/[stream];
    listen 9000;

    # Maximum time, in seconds, that an API-created session waits for its
    # media TCP connection. Fractional values such as 0.5 are supported.
    # Default: 10
    media_connect_timeout 10;
}

http_api {
    enabled on;
    listen 1985;
}

External SIP API

After completing the SIP negotiation, create the media session with the stream ID and decimal RTP SSRC selected by the external SIP server:

curl -X POST http://127.0.0.1:1985/gb/v1/publish/ \
  -H 'Content-Type: application/json' \
  -d '{"id":"34020000001320000001","ssrc":"47190001"}'

SRS returns the media endpoint:

{"code":0,"port":9000,"is_tcp":true}

The device or external SIP service should then connect to the returned port and publish RFC4571-framed RTP/PS over TCP using the same SSRC.

Session Lifecycle

The stream ID and SSRC uniquely reserve a GB28181 session. Creating another session with either value while it remains reserved returns StreamBusy.

media_connect_timeout controls how long SRS keeps a session that was created through /gb/v1/publish/ but never receives its media TCP connection. It is measured in seconds, supports fractional values, and defaults to 10 seconds. When the timeout expires, SRS releases both the stream ID and SSRC so the external SIP server can publish them again.

Once the media TCP connection binds, the connection owns the media-session lifecycle and media_connect_timeout no longer applies. Closing the current TCP connection destroys the session and releases its stream ID and SSRC. A later publish request may therefore reuse both values.