Home | History | Annotate | Download | only in video_render
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_VIDEO_RENDER_IMPL_H_
     12 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_VIDEO_RENDER_IMPL_H_
     13 
     14 #include <map>
     15 
     16 #include "webrtc/engine_configurations.h"
     17 #include "webrtc/modules/video_render/include/video_render.h"
     18 
     19 namespace webrtc {
     20 class CriticalSectionWrapper;
     21 class IncomingVideoStream;
     22 class IVideoRender;
     23 
     24 // Class definitions
     25 class ModuleVideoRenderImpl: public VideoRender
     26 {
     27 public:
     28     /*
     29      *   VideoRenderer constructor/destructor
     30      */
     31     ModuleVideoRenderImpl(const int32_t id,
     32                           const VideoRenderType videoRenderType,
     33                           void* window, const bool fullscreen);
     34 
     35     virtual ~ModuleVideoRenderImpl();
     36 
     37     /*
     38      *   Change the unique identifier of this object
     39      */
     40     virtual int32_t ChangeUniqueId(const int32_t id);
     41 
     42     virtual int32_t TimeUntilNextProcess();
     43     virtual int32_t Process();
     44 
     45     /*
     46      *   Returns the render window
     47      */
     48     virtual void* Window();
     49 
     50     /*
     51      *   Change render window
     52      */
     53     virtual int32_t ChangeWindow(void* window);
     54 
     55     /*
     56      *   Returns module id
     57      */
     58     int32_t Id();
     59 
     60     /**************************************************************************
     61      *
     62      *   Incoming Streams
     63      *
     64      ***************************************************************************/
     65 
     66     /*
     67      *   Add incoming render stream
     68      */
     69     virtual VideoRenderCallback
     70             * AddIncomingRenderStream(const uint32_t streamId,
     71                                       const uint32_t zOrder,
     72                                       const float left, const float top,
     73                                       const float right, const float bottom);
     74     /*
     75      *   Delete incoming render stream
     76      */
     77     virtual int32_t
     78             DeleteIncomingRenderStream(const uint32_t streamId);
     79 
     80     /*
     81      *   Add incoming render callback, used for external rendering
     82      */
     83     virtual int32_t
     84             AddExternalRenderCallback(const uint32_t streamId,
     85                                       VideoRenderCallback* renderObject);
     86 
     87     /*
     88      *   Get the porperties for an incoming render stream
     89      */
     90     virtual int32_t
     91             GetIncomingRenderStreamProperties(const uint32_t streamId,
     92                                               uint32_t& zOrder,
     93                                               float& left, float& top,
     94                                               float& right, float& bottom) const;
     95     /*
     96      *   Incoming frame rate for the specified stream.
     97      */
     98     virtual uint32_t GetIncomingFrameRate(const uint32_t streamId);
     99 
    100     /*
    101      *   Returns the number of incoming streams added to this render module
    102      */
    103     virtual uint32_t GetNumIncomingRenderStreams() const;
    104 
    105     /*
    106      *   Returns true if this render module has the streamId added, false otherwise.
    107      */
    108     virtual bool HasIncomingRenderStream(const uint32_t streamId) const;
    109 
    110     /*
    111      *
    112      */
    113     virtual int32_t
    114             RegisterRawFrameCallback(const uint32_t streamId,
    115                                      VideoRenderCallback* callbackObj);
    116 
    117     virtual int32_t GetLastRenderedFrame(const uint32_t streamId,
    118                                          I420VideoFrame &frame) const;
    119 
    120     virtual int32_t SetExpectedRenderDelay(uint32_t stream_id,
    121                                            int32_t delay_ms);
    122 
    123     /**************************************************************************
    124      *
    125      *   Start/Stop
    126      *
    127      ***************************************************************************/
    128 
    129     /*
    130      *   Starts rendering the specified stream
    131      */
    132     virtual int32_t StartRender(const uint32_t streamId);
    133 
    134     /*
    135      *   Stops the renderer
    136      */
    137     virtual int32_t StopRender(const uint32_t streamId);
    138 
    139     /*
    140      *   Sets the renderer in start state, no streams removed.
    141      */
    142     virtual int32_t ResetRender();
    143 
    144     /**************************************************************************
    145      *
    146      *   Properties
    147      *
    148      ***************************************************************************/
    149 
    150     /*
    151      *   Returns the prefered render video type
    152      */
    153     virtual RawVideoType PreferredVideoType() const;
    154 
    155     /*
    156      *   Returns true if the renderer is in fullscreen mode, otherwise false.
    157      */
    158     virtual bool IsFullScreen();
    159 
    160     /*
    161      *   Gets screen resolution in pixels
    162      */
    163     virtual int32_t
    164             GetScreenResolution(uint32_t& screenWidth,
    165                                 uint32_t& screenHeight) const;
    166 
    167     /*
    168      *   Get the actual render rate for this stream. I.e rendered frame rate,
    169      *   not frames delivered to the renderer.
    170      */
    171     virtual uint32_t RenderFrameRate(const uint32_t streamId);
    172 
    173     /*
    174      *   Set cropping of incoming stream
    175      */
    176     virtual int32_t SetStreamCropping(const uint32_t streamId,
    177                                       const float left, const float top,
    178                                       const float right, const float bottom);
    179 
    180     virtual int32_t ConfigureRenderer(const uint32_t streamId,
    181                                       const unsigned int zOrder,
    182                                       const float left, const float top,
    183                                       const float right, const float bottom);
    184 
    185     virtual int32_t SetTransparentBackground(const bool enable);
    186 
    187     virtual int32_t FullScreenRender(void* window, const bool enable);
    188 
    189     virtual int32_t SetBitmap(const void* bitMap,
    190                               const uint8_t pictureId,
    191                               const void* colorKey,
    192                               const float left, const float top,
    193                               const float right, const float bottom);
    194 
    195     virtual int32_t SetText(const uint8_t textId,
    196                             const uint8_t* text,
    197                             const int32_t textLength,
    198                             const uint32_t textColorRef,
    199                             const uint32_t backgroundColorRef,
    200                             const float left, const float top,
    201                             const float right, const float bottom);
    202 
    203     virtual int32_t SetStartImage(const uint32_t streamId,
    204                                   const I420VideoFrame& videoFrame);
    205 
    206     virtual int32_t SetTimeoutImage(const uint32_t streamId,
    207                                     const I420VideoFrame& videoFrame,
    208                                     const uint32_t timeout);
    209 
    210     virtual int32_t MirrorRenderStream(const int renderId,
    211                                        const bool enable,
    212                                        const bool mirrorXAxis,
    213                                        const bool mirrorYAxis);
    214 
    215 private:
    216     int32_t _id;
    217     CriticalSectionWrapper& _moduleCrit;
    218     void* _ptrWindow;
    219     bool _fullScreen;
    220 
    221     IVideoRender* _ptrRenderer;
    222     typedef std::map<uint32_t, IncomingVideoStream*> IncomingVideoStreamMap;
    223     IncomingVideoStreamMap _streamRenderMap;
    224 };
    225 
    226 }  // namespace webrtc
    227 
    228 #endif  // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_VIDEO_RENDER_IMPL_H_
    229