类 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 空间编码图像数据。