Skip to content

Livestreaming server which ingests over SRT and broadcasts over SRT and HTTP

License

Notifications You must be signed in to change notification settings

dexgs/livestreaming

Repository files navigation

💩 ShaRT

ShaRT is a live-streaming server which ingests over SRT and broadcasts over SRT and HTTP licensed under the GPLv3.

Dependencies

ShaRT depends on SRT and PicoHTTPParser which are vendored in the thirdparty/ directory and linked statically. It also depends on openssl, libcrypto and libpthread which must be provided by the host system. cmake is required to compile SRT.

Building

Clone the repository (pass --recurse-submodules or run git submodule update --init --recursive in the project directory after cloning) and run make all in its directory. Make sure you have cmake installed (required to build SRT). An executable will be output at bin/ShaRT.

The following values can be defined at compile time:

  • WEB_LISTEN_BACKLOG : int - Connection backlog size for HTTP
  • SRT_LISTEN_BACKLOG : int - Connection backlog size for SRT
  • MAP_SIZE : int - Number of "buckets" in the hashmap which stores stream information. You should set this to at least double the maximum number of streams you expect to handle to get the best possible performance.
  • UNLISTED_STREAM_NAME_PREFIX : string - Streams published under a name beginning with this string will not be reported by the web API (default value is _).
  • MAX_WEB_SEND_FAILS: int - Number of send EAGAIN/EWOULDBLOCK errors to before disconnecting an HTTP subscriber (all other error types cause HTTP subscribers to be dropped immediately).
  • MAX_PACKETS_IN_FLIGHT : int SRT docs
  • SEND_BUFFER_SIZE : int SRT docs
  • RECV_BUFFER_SIZE : int SRT docs
  • RECV_LATENCY_MS : int SRT docs
  • ENABLE_TIMESTAMPS : bool SRT docs
  • ENABLE_REPEATED_LOSS_REPORTS : bool SRT docs
  • ENABLE_DRIFT_TRACER : bool SRT docs
  • WEB_SEND_BUFFER_SIZE : int - Like SEND_BUFFER_SIZE, but for HTTP connections.

Docker

A configuration to run ShaRT under Docker is provided. By default, it includes an instance of Lighttpd to serve the web interface.

Build and run container WITH Lighttpd

Run HOSTNAME=your-hostname docker-compose build && docker-compose up where your-hostname is replaced with the hostname at which the web interface will be reachable by an end-user (NOT the address at which it is reachable on the local machine).

The web player will be accessible at your-hostname:3000 and ShaRT will listen for SRT publishers on port 9991 and SRT subscribers on port 1234. To change these settings as well as others, modify the relevant values in docker-compose.yml.

Build and run container WITHOUT Lighttpd

Run docker-compose build shart && docker-compose up shart

ShaRT will listen for SRT publishers on port 9991 and SRT subscribers on port 1234. To change these settings as well as others, modify the relevant values in docker-compose.yml.

Usage

See USAGE.md

Notes

  • Connections for watching a stream are handled in non-blocking mode and traffic is managed "leaky bucket" style, i.e. if ShaRT can't broadcast the stream to connected clients in time with the rate at which data arrives, it will drop connections until it can.
  • Stream names may not contain the following characters: $, (, ), [, ], <, >, |, \n (newline), \, &, *, #, ~, !, `, ;, ', ".

Web Player

An example webpage for playing live streams using mpegts.js is provided. To use it, do the following:

  1. Serve the www directory with a web server.
  2. Set the values of web_url and srt_url in www/config.js to the URLs at which ShaRT is configured to accept HTTP and SRT subscriber connections respectively. You must do this because ShaRT itself is served separately from any web interface to which it is attached.

Here is an example NGINX configuration for serving the sample web interface as well as proxying HTTP connections to ShaRT (Assuming ShaRT serves HTTP connections over the default port, 8071):

location /stream {
  alias /path/to/ShaRT/www;
}

location /stream_backend/ {
  proxy_http_version 1.1;
  proxy_pass http://127.0.0.1:8071/;
  proxy_set_header X-Real-IP $proxy_add_x_forwarded_for;
}

Web API

The following HTTP endpoints are exposed:

  • /api/streams/N Returns a JSON-encoded list of stream names with length N sorted by number of viewers. If N is 0, the full stream list will be returned.
  • /api/stream/NAME Returns the number of viewers for NAME. Returns 404 if there is no stream called NAME being published.
  • /stream/NAME This is the HTTP endpoint for serving MPEG-TS encoded streams.