GrabBag/Module/FFMediaStream/Inc/IVrFFMediaPusher.h

134 lines
2.8 KiB
C
Raw Normal View History

#pragma once
#include <cstdint>
#include <cstddef>
#include <string>
#include <memory>
// 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;
};