webrtc视频引擎之video_render(视频渲染)介绍

  • Post author:
  • Post category:其他

 此部分为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, // 此定于如下枚举<pre name="code" class="cpp">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等接口供外部调用控制视频渲染

</pre><pre code_snippet_id="1842801" snippet_file_name="blog_20160821_7_7573210" name="code" class="cpp">
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 <span style="color:#ff0000;">StartRende</span>r(const uint32_t streamId);

    /*
     *   Stops the renderer
     */
    virtual int32_t <span style="color:#ff0000;">StopRender</span>(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<uint32_t, IncomingVideoStream*> IncomingVideoStreamMap;
    IncomingVideoStreamMap _streamRenderMap;
};

  有兴趣的同学朋友可以自行去研究每个设备是怎么显示视频,  至于每个设备如何显示视频这个后面都单独介绍,这里只做个整体的介绍。


版权声明:本文为qazwsxwtc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。