Nvidia Jetson 开发套件,视频编码的相关源码解读:videoOutput.h、videoOutput.cpp

本文介绍了videoOutput类的定义及其核心成员函数Render的功能。该类作为抽象类,支持多种图像格式的输出,并能从GPU空间直接编码图像数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

类 videoOutput 的定义如下。查看了一下 videoOutput.cpp,发现它作为一个抽象类,依然很流氓地引用了其衍生类 glDisplay.h、gstEncoder.h。

1. videoOutput 的定义

class videoOutput
{
public:
	static videoOutput* Create( const videoOptions& options );
	static videoOutput* Create( const char* URI, const videoOptions& options=videoOptions() );
	static videoOutput* Create( const char* URI, const commandLine& cmdLine );
	static videoOutput* Create( const char* URI, const int argc, char** argv );
	static videoOutput* Create( const int argc, char** argv, int positionArg=-1 );
	static videoOutput* Create( const commandLine& cmdLine, int positionArg=-1 );
	static videoOutput* CreateNullOutput();
	virtual ~videoOutput();
	static inline const char* Usage() 		{ return VIDEO_OUTPUT_USAGE_STRING; }
	template<typename T> bool Render( T* image, uint32_t width, uint32_t height )		{ return Render((void**)image, width, height, imageFormatFromType<T>()); }
	virtual bool Render( void* image, uint32_t width, uint32_t height, imageFormat format );
	virtual bool Open();
	virtual void Close();
	inline bool IsStreaming() const	   					{ return mStreaming; }
	inline uint32_t GetWidth() const						{ return mOptions.width; }
	inline uint32_t GetHeight() const						{ return mOptions.height; }
	inline float GetFrameRate() const						{ return mOptions.frameRate; }
	inline const URI& GetResource() const					{ return mOptions.resource; }
	inline const videoOptions& GetOptions() const			{ return mOptions; }
	inline void AddOutput( videoOutput* output )				{ if(output != NULL) mOutputs.push_back(output); }
	inline uint32_t GetNumOutputs( videoOutput* output ) const	{ mOutputs.size(); }
	inline videoOutput* GetOutput( uint32_t index ) const		{ return mOutputs[index]; }
	virtual void SetStatus( const char* str );
	virtual inline uint32_t GetType() const			{ return 0; }
	inline bool IsType( uint32_t type ) const		{ return (type == GetType()); }
	template<typename T> bool IsType() const		{ return IsType(T::Type); }
	inline const char* TypeToStr() const			{ return TypeToStr(GetType()); }
	static const char* TypeToStr( uint32_t type );
protected:
	videoOutput( const videoOptions& options );
	bool         mStreaming;
	videoOptions mOptions;
	std::vector<videoOutput*> mOutputs;
};

2. Render 函数

Render 函数用来把图像数据输出,其声明如下:

template<typename T> bool Render( T* image, uint32_t width, uint32_t height )
{ 
	return Render((void**)image, width, height, imageFormatFromType<T>()); 
}

源代码注释翻译如下:

渲染并将下一帧输出到流。
此模板化版本的Render()支持的图像格式包括:

  • uchar3(IMAGE_RGB8
  • uchar4(IMAGE_RGBA8
  • float3(IMAGE_RGB32F
  • float4(IMAGE_RGBA32F

图像格式将自动从这些类型中推导出来。如果与此重载一起使用其他类型,则会断言静态编译时错误。

  • @参数 image 包含要输出的图像的 CUDA 指针。
  • @参数 image 的宽度,以像素为单位。
  • @参数 image 的高度,以像素为单位。
  • @成功时返回 true,错误时返回 false。

【重点说明】
参数 image 包含要输出的图像的 CUDA 指针。
正因为这个机制,才可以实现从 GPU 空间编码图像数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

许野平

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值