Overview
The RtspServer C++ library implements an RTSP server. The RtspServer library inherits from the VStreamer interface. The library supports H264 and HEVC(H265) video streams via TCP / UDP / UDP multicast. Users can set general RTSP server parameters such as: RTSP server port, IP, stream name, user name, password etc. The server works frame-by-frame. RtspServer accepts both RAW frame formats (such as NV12) and compressed formats H264 and HEVC(H265). If the frame is in a compressed format (H264 or HEVC), it bypasses any overlay and resizing processes and is sent directly to clients. However, if the frame is RAW, it undergoes a series of processing steps. First, resizing is performed if necessary (if the input frame size differs from the video stream resolution). Second, video overlay is applied if a pointer to a video overlay engine is provided by the user (as defined by the VOverlay interface). Finally, the frame is encoded into a compressed format (H264 or HEVC) before being transmitted to clients (to use these functions the user must define a video codec as defined by the VCodec interface). The library relies on several dependencies: VCodec (defines video codec interface, source code included, Apache 2.0 license), VOverlay (defines video overlay interface, source code included, Apache 2.0 license), FormatConverter (provides methods to convert pixel formats, source code included), ImageResizer (provides methods for image resizing, source code included), ConfigReader (provides methods to work with JSON files, source code included, Apache 2.0 license). In addition, the test application depends on the VSourceFile library (provides functions to capture compressed data from video files, source code included). The library is compatible with Linux and Windows operating systems. The RTSP server is compatible with all popular RTSP clients: ffmpeg, gstreamer, VLC, Milestone etc. The library uses parts of source code from PHZ76/RtspServer (highly modified, source code included, MIT license).
Documentation
Documentation: GO TO DOCUMENTATION
Simple interface
namespace cr
{
namespace rtsp
{
class RtspServer : public cr::video::VStreamer
{
public:
/// Get string of current library version.
static std::string getVersion();
/// Class constructor.
RtspServer();
/// Class destructor.
~RtspServer();
/// Init video streamer by set of parameters.
bool initVStreamer(cr::video::VStreamerParams ¶ms,
cr::video::VCodec *codec = nullptr,
cr::video::VOverlay *overlay = nullptr) override;
/// Get init status.
bool isVStreamerInit() override;
/// Close video streamer.
void closeVStreamer() override;
/// Send frame to video streamer.
bool sendFrame(cr::video::Frame& frame, uint8_t* userData = nullptr, int userDataSize = 0) override;
/// Set video streamer parameter.
bool setParam(cr::video::VStreamerParam id, float value) override;
/// Set video streamer parameter.
bool setParam(cr::video::VStreamerParam id, std::string value) override;
/// Get all video streamer parameters.
void getParams(cr::video::VStreamerParams& params) override;
/// Execute action command.
bool executeCommand(cr::video::VStreamerCommand id) override;
};
}
}
Simple example
#include <iostream>
#include "RtspServer.h"
#include "VSourceFile.h"
using namespace std;
using namespace cr::rtsp;
using namespace cr::video;
int main(void)
{
cout << "RtspServer v" << RtspServer::getVersion() << endl << endl;
// Init RTSP server params for encoded frames with default params.
VStreamerParams params;
params.rtspPort = 7031;
params.ip = "0.0.0.0";
params.suffix = "live";
params.user = ""; // No user name.
params.password = ""; // No password.
params.fps = 30;
// RTSP server.
RtspServer server;
if(!server.initVStreamer(params))
return -1;
cout << "RTSP init string: rtsp://127.0.0.1:7031/live" << endl;
// Set video source init string.
string initString = "out.h264;1920;1080;30";
// Init file video source.
VSourceFile fileSource;
if(!fileSource.openVSource(initString))
return -1;
// Main thread.
Frame sourceFrame;
while(1)
{
// Get new frame from video file.
if(!fileSource.getFrame(sourceFrame, 1000))
continue;
// Send frame to RTSP server.
if(!server.sendFrame(sourceFrame))
cout << "Cannot send frame to RTSP server" << endl;
}
return 1;
}

