Overview
RtpPusher is a C++ library that provides H264 RTP and H265 RTP packet sending to network. The library internally handles extracting NAL units and fragmenting them to UDP packets. The library depends on: Frame library (provides declaration of video frame object, source code included, Apache 2.0 license) and UdpSocket library (provides methods to work with UDP sockets). Also, example application depends on VSourceFile library to read H264/H265 frames from the file (source code included). The library controls time interval between RTP packets to prevent network overload (the network bandwidth set by user). The library doesn’t have third-party dependencies to be installed in OS. The library is compatible with Linux and Windows.
Documentation
Documentation: GO TO DOCUMENTATION
Simple interface
class RtpPusher
{
public:
/// Get string of current library version.
static std::string getVersion();
/// Init video streamer by set of parameters.
bool init(std::string ip,
uint16_t port,
int bandwidthKbps = 1000000,
int maxPayloadSize = 1420);
/// Get init status.
bool isInit();
/// Close video streamer.
void close();
/// Send frame to video streamer.
bool sendFrame(cr::video::Frame &frame);
};
Simple example
#include <iostream>
#include "VSourceFile.h"
#include "RtpPusher.h"
int main()
{
// Init video source.
cr::video::VSourceFile source;
std::string initString = "test.h264";
if (!source.openVSource(initString)) // Default 128x720, 30 FPS
return -1;
std::cout << "Enter IP address: ";
std::string ip = "127.0.0.1";
std::cin >> ip;
std::cout << "Enter port number: ";
int port = 7032;
std::cin >> port;
// Init streamer.
cr::rtp::RtpPusher rtpPusher;
if (!rtpPusher.init(ip, port))
return -1;
// Main loop.
cr::video::Frame sourceFrame;
while (true)
{
// Get H264 frame from video source. We wait new frame for 1 sec.
if (!source.getFrame(sourceFrame, 1000))
continue;
// Send frame.
if (!rtpPusher.sendFrame(sourceFrame))
continue;
std::cout << "Frame : " << sourceFrame.frameId << std::endl;
}
return 1;
}