RTSP API#
Oasis supports an RTSP server.
Supported video codecs are H264 and H265, and audio codecs are OPUS, AAC, MP3, and PCM. For live streaming, OPUS operates as the default codec.
Header File#
OasisRtsp.h
URL Format#
The URL format used when a client media player, such as VLC, connects to the Oasis RTSP server is as follows:
rtsp://<Server Address>[:Port Number][/RTSP Streaming Session Configuration Key-Value List]/<Streaming Destination Path>
-
Server Address: The address of the RTSP server.
-
Port Number: If not specified, the default value is 554.
-
RTSP Streaming Session Configuration Key-Value List: This is optional and supports the following key-values. Each key-value pair is separated by "&".
| Key | Description |
|---|---|
| resolution | Video resolution. Can be specified as one of the following values: 2160p, 1440p, 1080p, 720p, 480p. If it is smaller than the camera video size, it is scaled. Applies only to live streaming. |
| out-width | Video width. Measured in pixels. Applies only to live streaming. |
| out-height | Video height. Measured in pixels. Applies only to live streaming. |
| bitrate | Video transmission bitrate. Applies only to live streaming. |
| fps | Video fps. Applies only to live streaming. |
| audio-only | Streams audio only. No separate value is required. |
| video-only | Streams video only. No separate value is required. |
Note
If resolution, out-width, and out-height exist simultaneously, resolution takes priority.
- Streaming Destination Path: Specifies the target to be streamed. A live camera path or a file path can be specified. In the case of a file path, it must be located within the
root-dirspecified when creating the RTSP server. The live camera path is formatted asLive/<Camera Device ID>.<Camera Device ID>is the value specified as a key-value map in theoasis::configCamerasAPI. In the case of a file path, a relative path is specified based onroot-dir. If a video file contains multiple video tracks, a specific track can be specified in the format of/<File Path>/TrackID=<Track Number>.
Below are examples of URLs:
| URL | Description |
|---|---|
| rtsp://192.168.10.2:554/example.mp4 | Connects to port 554 of the server 192.168.10.2 and streams the example.mp4 file. |
| rtsp://192.168.10.2:554/example.mp4/TrackID=1 | Connects to port 554 of the server 192.168.10.2 and streams track 1 of the example.mp4 file. |
| rtsp://192.168.10.2:554/Live/0 | Connects to port 554 of the server 192.168.10.2 and streams the video of camera ID 0. |
| rtsp://192.168.10.2:554/resolution=720p&fps=10&bitrate=128000/Live/0 | Connects to port 554 of the server 192.168.10.2 and streams the video of camera ID 0 at 720p, 10fps, and 128Kbps. |
Note
If the TCP interleave method is selected in the RTSP streaming options of the media player, data is sent via TCP instead of using RTP/RTCP. This option can be used for reasons such as firewalls.
RtspEventDelegate Interface#
The user can verify events occurring during streaming between the RTSP server and connected clients by creating an object derived from the RtspEventDelegate interface.
This interface is not mandatory for the operation of the RTSP server.
class RtspEventDelegate : public std::enable_shared_from_this<RtspEventDelegate>
{
public:
RtspEventDelegate();
virtual ~RtspEventDelegate();
public:
virtual void onDescription(const char *uri, const char *remote, const char *sdp);
virtual void onSetup(const char *uri, const char *remote, const char *transport_line);
virtual void onPlay(const char *uri, const char *remote, const char *rtp_info);
virtual void onTeardown(const char *uri, const char *remote);
virtual void onPause(const char *uri, const char *remote);
virtual void onError(int error_code, const char *error_msg, const char *error_desc);
virtual void onClosed(const char *uri, const char *remote);
};
The error response codes sent by the RTSP server are as follows:
| Error Code | Message | Detailed Description |
|---|---|---|
| 400 | Bad Request | DESCRIBE invalid uri |
| 400 | Bad Request | SETUP bad uri |
| 400 | Bad Request | OPTIONS bad uri |
| 400 | Bad Request | PLAY bad uri |
| 400 | Bad Request | PLAY transport not found |
| 400 | Bad Request | PAUSE bad uri |
| 400 | Bad Request | PAUSE transport not found |
| 400 | Bad Request | TEARDOWN bad uri |
| 454 | Session Not Found | SETUP session not found |
| 454 | Session Not Found | PLAY session not found |
| 454 | Session Not Found | PAUSE session not found |
| 454 | Session Not Found | TEARDOWN session not found |
| 459 | Aggregate operation not allowed | SETUP aggregate operation not supported |
| 500 | Internal Server Error | DESCRIBE no SDP available |
| 500 | Internal Server Error | PAUSE failed to pause the transport |
| 501 | Not Implemented | RECORD not supported |
| 501 | Not Implemented | REDIRECT not supported |
| 501 | Not Implemented | SET PARAMETER not supported |
| 503 | Service Unavailable | DESCRIBE session limited |
| 503 | Service Unavailable | OPTIONS session limited |
| 503 | Service Unavailable | SETUP session limited |
| 503 | Service Unavailable | SETUP new session not available |
| 503 | Service Unavailable | Session Play failed |
| 503 | Service Unavailable | PAUSE failed to pause the session |
| 503 | Service Unavailable | TEARDOWN failed to teardown the session |
Functions#
RtspEventDelegate.
RtspEventDelegate.
- 0: Success
- -1: Failure
- 0: Success
- -1: Failure
- 0: Success
- -1: Failure
true. Outputs the video with ISE functions applied if false.
- 0: Success
- -1: Failure
Example#
Below is an RTSP server example.
#include "OasisAPI.h"
#include "OasisLog.h"
#include "OasisRtsp.h"
#include <thread>
#include <mutex>
#include <memory>
#include <condition_variable>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#define DLOG_TRACE 0x00080000
#undef DLOG_FLAGS
#define DLOG_FLAGS (DLOG_FLAGS_DEFAULT|DLOG_TRACE/***/)
#undef DLOG_TAG
#define DLOG_TAG "RTSP"
#define RTSP_PORT 554
using namespace oasis;
namespace oasis {
uint64_t getFreeMemorySize();
}
static bool continuing = true;
void cancel_handler(int signum)
{
continuing = false;
}
int main(int argc, char* argv[])
{
int32_t err;
int32_t c;
std::thread t2, t3;
uint16_t rtsp_port = RTSP_PORT;
RtspServerRef rtsp_server;
oasis::key_value_map_t parameters;
parameters["offs-disable"] = "1";
if(oasis::initialize(parameters) < 0) {
DLOG(DLOG_ERROR, "Oasis init failed\n");
return -1;
}
//Oasis set SIGINT
signal(SIGINT, cancel_handler);
// config cameras
// ...
// Create RTSP server
parameters.clear();
parameters["port"] = std::to_string(rtsp_port);
parameters["root-dir"] = "/mnt/extsd";
parameters["remote-pool-size"] = std::to_string(20); //max con-current network connections
parameters["scheduler-size"] = std::to_string(10); //max working threads
parameters["upstreamer-size"] = std::to_string(10); //max working threads
parameters["transmitter-size"] = std::to_string(15);
parameters["timer-size"] = std::to_string(3);
parameters["file-session-max"] = std::to_string(1); //0: unlimited
parameters["live-session-max"] = std::to_string(6); //0: unlimited
parameters["linger-time-max"] = std::to_string(1000);
parameters["rtp-data-size-max"] = std::to_string(1024);
parameters["rtp-packet-pool-count-max"] = std::to_string(6);
parameters["rtp-packet-pool-size"] = std::to_string(256);
rtsp_server = createRtspServer(parameters);
if(rtsp_server) {
// Start RTSP server
err = oasis::startRtspServer(rtsp_server);
ASSERT(err == 0);
if(err < 0) {
DLOG(DLOG_ERROR, "RTSP server failed\n");
goto done;
}
DLOG(DLOG_TRACE, "RTSP running at %d...\n", rtsp_port);
}
do {
usleep(10000);
} while(continuing);
if(rtsp_server) {
oasis::destroyRtspServer(rtsp_server);
}
oasis::finalize();
return 0;
}