webrtc 渲染_webrtc視訊引擎之video_render(視訊渲染)介紹
技術標籤:webrtc 渲染
此部分為webrtc視訊渲染顯示,程式碼結構如下:
其實此部分程式碼與《webrtc視訊引擎之vedio_capture_module介紹》的程式碼結構一樣
1,圖中能夠直接看到的.h和.cc檔案也是一個適配作用,用於根據系統平臺適配採用某部分進行視訊渲染;
2, android資料夾用於在android平臺渲染顯示視訊影象;
3, IOS資料夾用於在IOS平臺渲染顯示視訊影象;
4, linux資料夾用於在linux平臺渲染顯示視訊影象;
5, mac資料夾用於在mac平臺渲染顯示視訊影象;
6,windows資料夾用於在windows平臺渲染顯示視訊影象;
render影象顯示模組的介面類:
在呼叫該介面類建立例項物件的時候需要從建構函式傳入 相關的顯示引數, 如下:
const int32_t id, //本路顯示視訊的ID,使用者自定義,用於唯一區分本路視訊即可
const VideoRenderType videoRenderType, // 此定於如下列舉
enum VideoRenderType
{
kRenderExternal = 0, // External
kRenderWindows = 1, // Windows
kRenderCocoa = 2, // Mac
kRenderCarbon = 3,
kRenderiOS = 4, // iPhone
kRenderAndroid = 5, // Android
kRenderX11 = 6, // Linux
kRenderDefault
};
void* window, //用於顯示視訊的視窗物件指標
const bool fullscreen //是否需要全屏顯示
ModuleVideoRenderImpl(const int32_t id, const VideoRenderType videoRenderType, void* window, const bool fullscreen);
該介面還是StartRender 、StopRender等介面供外部呼叫控制視訊渲染
class ModuleVideoRenderImpl: public VideoRender
{
public:
/*
* VideoRenderer constructor/destructor
*/
ModuleVideoRenderImpl(const int32_t id,
const VideoRenderType videoRenderType,
void* window, const bool fullscreen);
virtual ~ModuleVideoRenderImpl();
/*
* Change the unique identifier of this object
*/
virtual int32_t ChangeUniqueId(const int32_t id);
virtual int32_t TimeUntilNextProcess();
virtual int32_t Process();
/*
* Returns the render window
*/
virtual void* Window();
/*
* Change render window
*/
virtual int32_t ChangeWindow(void* window);
/*
* Returns module id
*/
int32_t Id();
/**************************************************************************
*
* Incoming Streams
*
***************************************************************************/
/*
* Add incoming render stream
*/
virtual VideoRenderCallback
* AddIncomingRenderStream(const uint32_t streamId,
const uint32_t zOrder,
const float left, const float top,
const float right, const float bottom);
/*
* Delete incoming render stream
*/
virtual int32_t
DeleteIncomingRenderStream(const uint32_t streamId);
/*
* Add incoming render callback, used for external rendering
*/
virtual int32_t
AddExternalRenderCallback(const uint32_t streamId,
VideoRenderCallback* renderObject);
/*
* Get the porperties for an incoming render stream
*/
virtual int32_t
GetIncomingRenderStreamProperties(const uint32_t streamId,
uint32_t& zOrder,
float& left, float& top,
float& right, float& bottom) const;
/*
* Incoming frame rate for the specified stream.
*/
virtual uint32_t GetIncomingFrameRate(const uint32_t streamId);
/*
* Returns the number of incoming streams added to this render module
*/
virtual uint32_t GetNumIncomingRenderStreams() const;
/*
* Returns true if this render module has the streamId added, false otherwise.
*/
virtual bool HasIncomingRenderStream(const uint32_t streamId) const;
/*
*
*/
virtual int32_t
RegisterRawFrameCallback(const uint32_t streamId,
VideoRenderCallback* callbackObj);
virtual int32_t GetLastRenderedFrame(const uint32_t streamId,
I420VideoFrame &frame) const;
virtual int32_t SetExpectedRenderDelay(uint32_t stream_id,
int32_t delay_ms);
/**************************************************************************
*
* Start/Stop
*
***************************************************************************/
/*
* Starts rendering the specified stream
*/
virtual int32_t StartRender(const uint32_t streamId);
/*
* Stops the renderer
*/
virtual int32_t StopRender(const uint32_t streamId);
/*
* Sets the renderer in start state, no streams removed.
*/
virtual int32_t ResetRender();
/**************************************************************************
*
* Properties
*
***************************************************************************/
/*
* Returns the prefered render video type
*/
virtual RawVideoType PreferredVideoType() const;
/*
* Returns true if the renderer is in fullscreen mode, otherwise false.
*/
virtual bool IsFullScreen();
/*
* Gets screen resolution in pixels
*/
virtual int32_t
GetScreenResolution(uint32_t& screenWidth,
uint32_t& screenHeight) const;
/*
* Get the actual render rate for this stream. I.e rendered frame rate,
* not frames delivered to the renderer.
*/
virtual uint32_t RenderFrameRate(const uint32_t streamId);
/*
* Set cropping of incoming stream
*/
virtual int32_t SetStreamCropping(const uint32_t streamId,
const float left, const float top,
const float right, const float bottom);
virtual int32_t ConfigureRenderer(const uint32_t streamId,
const unsigned int zOrder,
const float left, const float top,
const float right, const float bottom);
virtual int32_t SetTransparentBackground(const bool enable);
virtual int32_t FullScreenRender(void* window, const bool enable);
virtual int32_t SetBitmap(const void* bitMap,
const uint8_t pictureId,
const void* colorKey,
const float left, const float top,
const float right, const float bottom);
virtual int32_t SetText(const uint8_t textId,
const uint8_t* text,
const int32_t textLength,
const uint32_t textColorRef,
const uint32_t backgroundColorRef,
const float left, const float top,
const float right, const float bottom);
virtual int32_t SetStartImage(const uint32_t streamId,
const I420VideoFrame& videoFrame);
virtual int32_t SetTimeoutImage(const uint32_t streamId,
const I420VideoFrame& videoFrame,
const uint32_t timeout);
virtual int32_t MirrorRenderStream(const int renderId,
const bool enable,
const bool mirrorXAxis,
const bool mirrorYAxis);
private:
int32_t _id;
CriticalSectionWrapper& _moduleCrit;
void* _ptrWindow;
bool _fullScreen;
IVideoRender* _ptrRenderer;
typedef std::map IncomingVideoStreamMap;
IncomingVideoStreamMap _streamRenderMap;
}; 有興趣的同學朋友可以自行去研究每個裝置是怎麼顯示視訊, 至於每個裝置如何顯示視訊這個後面都單獨介紹,這裡只做個整體的介紹。