#pragma once #include #include #include #include // DLL 导出宏(FFMEDIASTREAM_LIBRARY 在 .pro 中已定义) #ifdef _WIN32 # ifdef FFMEDIASTREAM_LIBRARY # define VR_FFMEDIA_API __declspec(dllexport) # else # define VR_FFMEDIA_API __declspec(dllimport) # endif #else # define VR_FFMEDIA_API #endif /** * @brief 推流帧像素格式 */ enum class EFFPushPixelFormat { NV12 = 0, // 4:2:0 半平面 (Y + UV) YUV420P, // 4:2:0 平面 BGR24, // OpenCV 默认 RGB24, BGRA32, RGBA32, }; /** * @brief 编码类型 */ enum class EFFEncodeType { H264 = 0, H265, MJPEG, }; /** * @brief 码率控制模式 */ enum class EFFRcMode { CBR = 0, VBR, }; /** * @brief 推流参数 */ struct VrFFPushConfig { // 帧参数 unsigned int width{1920}; unsigned int height{1080}; EFFPushPixelFormat pixelFormat{EFFPushPixelFormat::NV12}; // 编码参数 EFFEncodeType encodeType{EFFEncodeType::H264}; unsigned int fps{30}; unsigned int gop{60}; unsigned int bitrateKbps{4096}; // 码率 (kbps) EFFRcMode rcMode{EFFRcMode::CBR}; // RTSP 服务参数 std::string rtspPath{"/live/stream"}; // URL 路径 unsigned short rtspPort{8554}; std::string authRealm; std::string authUser; std::string authPass; }; /** * @brief IVrFFMediaPusher * * 基于 ffmedia_release 的 RTSP 推流(内存输入 -> RGA 格式转换 -> MPP 编码 -> RTSP)。 * * 典型用法: * IVrFFMediaPusher* pusher = nullptr; * IVrFFMediaPusher::CreateObject(&pusher); * pusher->Init(cfg); * pusher->Start(); * pusher->PushFrame(data, size); * ... * pusher->Stop(); * delete pusher; */ class VR_FFMEDIA_API IVrFFMediaPusher { public: virtual ~IVrFFMediaPusher() = default; // 工厂 static bool CreateObject(IVrFFMediaPusher** ppPusher); /** * @brief 初始化推流链路 * @return 0 成功 */ virtual int Init(const VrFFPushConfig& config) = 0; /** * @brief 启动推流(建立 RTSP 服务,等待客户端拉流) */ virtual int Start() = 0; /** * @brief 喂入一帧待编码的图像 * @param data 帧数据指针 * @param size 帧数据大小(字节) * @param ptsUs PTS,单位微秒;传 0 由内部生成 * @return 0 成功 */ virtual int PushFrame(const void* data, size_t size, int64_t ptsUs = 0) = 0; /** * @brief 停止推流 */ virtual int Stop() = 0; /** * @brief 反初始化 */ virtual int UnInit() = 0; /** * @brief 获取当前推流 URL(含 IP/端口/路径) */ virtual std::string GetRtspUrl(const std::string& localIp) const = 0; };