RtpPusher C++ lib. H.264 (RFC 6184), H.265 (RFC 7798) and JPEG (RFC 2435) video over UDP, in three transport modes selectable

€2,000.00

The RtpPusher C++ library is a H.264 (RFC 6184), H.265 (RFC 7798) and JPEG (RFC 2435) video over UDP streamer with supported RTP, MPEG-TS and MPEG-TS-RTP transport with KLV metadata support.

LICENSE: We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE.

The RtpPusher C++ library is a H.264 (RFC 6184), H.265 (RFC 7798) and JPEG (RFC 2435) video over UDP streamer with supported RTP, MPEG-TS and MPEG-TS-RTP transport with KLV metadata support.

LICENSE: We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE.

Overview

RtpPusher is a C++ library that delivers H.264 (RFC 6184), H.265 (RFC 7798) and JPEG (RFC 2435) video over UDP, in three transport modes selectable per send() call:

  • rtp (default) — codec-specific RTP framing (RFC 6184 / RFC 7798 / RFC 2435).

  • mpegts — MPEG-2 Transport Stream over UDP, 7×188-byte TS packets per UDP datagram, with optional KLV metadata on its own PID.

  • mpegts-rtp — MPEG-2 TS encapsulated in RTP per RFC 2250, payload type 33, 7 TS packets per RTP packet.

The library parses each input frame, splits it into RFC-conformant packets and emits them on a single shared UDP socket via a single internal pacing thread. The application calls only send(); everything else — Annex B start-code parsing, FU-A / FU fragmentation, JPEG segment extraction, MPEG-TS muxing (PAT/PMT/PCR/PES), KLV Tag 2 / Tag 1 auto-refresh, RTP header construction, sequence numbers, the 90 kHz timestamp clock, HEVC parameter-set replay on every IRAP frame, drop-oldest-frame back-pressure — is handled internally. The library has no third-party runtime dependencies.

Documentation

Documentation: GO TO DOCUMENTATION

Simple interface

class RtpPusher
{
public:

    /// Return codes for send().
    static constexpr int SEND_OK{0};
    static constexpr int SEND_INVALID_INPUT{-1};
    static constexpr int SEND_FRAME_DROP{-2};
    static constexpr int SEND_MODE_MISMATCH{-3};

    /// Get the library version string.
    static std::string getVersion();

    /// Send a coded video frame.
    int send(uint8_t* data,
             size_t size,
             const std::string& fourcc,
             std::string ip,
             uint16_t port,
             uint16_t userDataPort,
             float fps,
             size_t maxPayloadSize = 1420,
             int targetBitrateKbps = 5000,
             uint8_t* userData = nullptr,
             size_t userDataSize = 0,
             const std::string& streamType = "rtp");

    /// Stop sending and release all resources.
    void stop();
};

Simple example

#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include "RtpPusher.h"
#include "VSourceFile.h"

int main()
{
    // Open the input file. Resolution and frame rate are taken from the file.
    rapidpixel::VSourceFile source;
    std::string initString = "test.h264";
    if (!source.openVSource(initString))
    {
        return -1;
    }

    // No init() / open(): the pusher allocates resources on the first send().
    rapidpixel::RtpPusher rtpPusher;

    rapidpixel::Frame frame;
    int errorsInRow = 0;
    while (errorsInRow < 10)
    {
        // A coded fourcc asks VSourceFile for the coded frames of the file
        // (an uncompressed fourcc would give decoded pictures).
        frame.fourcc = rapidpixel::Fourcc::H264;
        if (!source.getFrame(frame, 1000))
        {
            ++errorsInRow;
            continue;
        }

        // Map the fourcc of the frame to the string accepted by send(). The
        // library uses "H265" (not "HEVC") for H.265.
        std::string codec;
        switch (frame.fourcc)
        {
        case rapidpixel::Fourcc::H264:
            codec = "H264";
            break;
        case rapidpixel::Fourcc::HEVC:
            codec = "H265";
            break;
        case rapidpixel::Fourcc::JPEG:
            codec = "JPEG";
            break;
        default:
            ++errorsInRow;
            continue;
        }

        const float fps = 30.0f;
        const uint16_t port = 7032;
        const uint16_t userDataPort = 0;           // embed user data as SEI
        const size_t maxPayloadSize = 1420;
        const int targetBitrateKbps = 5000;        // ~5 Mbps pacing
        const int rc = rtpPusher.send(frame.data,
                                      static_cast<size_t>(frame.size), codec,
                                      "127.0.0.1", port, userDataPort, fps,
                                      maxPayloadSize, targetBitrateKbps);
        switch (rc)
        {
        case rapidpixel::RtpPusher::SEND_OK:
            errorsInRow = 0;
            std::cout << "Frame: " << frame.frameId << std::endl;
            break;
        case rapidpixel::RtpPusher::SEND_FRAME_DROP:
            errorsInRow = 0;
            std::cerr << "[drop] frame " << frame.frameId
                      << ": frames dropped (producer outrunning the network)"
                      << std::endl;
            break;
        default:
            // SEND_INVALID_INPUT or SEND_MODE_MISMATCH.
            ++errorsInRow;
            std::cerr << "send() rejected the frame: " << rc << std::endl;
            break;
        }
    }

    // rtpPusher.stop() is called automatically by the destructor.
    return -1;
}