• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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 // This sub-API supports the following functionalities:
12 //  - Specify render destinations for incoming video streams, capture devices
13 //    and files.
14 //  - Configuring render streams.
15 
16 #ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_RENDER_H_
17 #define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_RENDER_H_
18 
19 #include "webrtc/common_types.h"
20 
21 namespace webrtc {
22 
23 class VideoEngine;
24 class VideoRender;
25 class VideoRenderCallback;
26 
27 // This class declares an abstract interface to be used for external renderers.
28 // The user implemented derived class is registered using AddRenderer().
29 class ExternalRenderer {
30  public:
31   // This method will be called when the stream to be rendered changes in
32   // resolution or number of streams mixed in the image.
33   virtual int FrameSizeChange(unsigned int width,
34                               unsigned int height,
35                               unsigned int number_of_streams) = 0;
36 
37   // This method is called when a new frame should be rendered.
38   virtual int DeliverFrame(unsigned char* buffer,
39                            int buffer_size,
40                            // RTP timestamp in 90kHz.
41                            uint32_t timestamp,
42                            // NTP time of the capture time in local timebase
43                            // in milliseconds.
44                            int64_t ntp_time_ms,
45                            // Wallclock render time in milliseconds.
46                            int64_t render_time_ms,
47                            // Handle of the underlying video frame.
48                            void* handle) = 0;
49 
50   // Returns true if the renderer supports textures. DeliverFrame can be called
51   // with NULL |buffer| and non-NULL |handle|.
52   virtual bool IsTextureSupported() = 0;
53 
54  protected:
~ExternalRenderer()55   virtual ~ExternalRenderer() {}
56 };
57 
58 class ViERender {
59  public:
60   // Factory for the ViERender sub‐API and increases an internal reference
61   // counter if successful. Returns NULL if the API is not supported or if
62   // construction fails.
63   static ViERender* GetInterface(VideoEngine* video_engine);
64 
65   // Releases the ViERender sub-API and decreases an internal reference
66   // counter. Returns the new reference count. This value should be zero
67   // for all sub-API:s before the VideoEngine object can be safely deleted.
68   virtual int Release() = 0;
69 
70   // Registers render module.
71   virtual int RegisterVideoRenderModule(VideoRender& render_module) = 0;
72 
73   // Deregisters render module.
74   virtual int DeRegisterVideoRenderModule(VideoRender& render_module) = 0;
75 
76   // Sets the render destination for a given render ID.
77   virtual int AddRenderer(const int render_id,
78                           void* window,
79                           const unsigned int z_order,
80                           const float left,
81                           const float top,
82                           const float right,
83                           const float bottom) = 0;
84 
85   // Removes the renderer for a stream.
86   virtual int RemoveRenderer(const int render_id) = 0;
87 
88   // Starts rendering a render stream.
89   virtual int StartRender(const int render_id) = 0;
90 
91   // Stops rendering a render stream.
92   virtual int StopRender(const int render_id) = 0;
93 
94   // Set expected render time needed by graphics card or external renderer, i.e.
95   // the number of ms a frame will be sent to rendering before the actual render
96   // time.
97   virtual int SetExpectedRenderDelay(int render_id, int render_delay) = 0;
98 
99   // Configures an already added render stream.
100   virtual int ConfigureRender(int render_id,
101                               const unsigned int z_order,
102                               const float left,
103                               const float top,
104                               const float right,
105                               const float bottom) = 0;
106 
107   // This function mirrors the rendered stream left and right or up and down.
108   virtual int MirrorRenderStream(const int render_id,
109                                  const bool enable,
110                                  const bool mirror_xaxis,
111                                  const bool mirror_yaxis) = 0;
112 
113   // External render.
114   virtual int AddRenderer(const int render_id,
115                           RawVideoType video_input_format,
116                           ExternalRenderer* renderer) = 0;
117 
118   // Propagating VideoRenderCallback down to the VideoRender module for new API.
119   // Contains default-implementation not to break code mocking this interface.
120   // (Ugly, but temporary.)
AddRenderCallback(int render_id,VideoRenderCallback * callback)121   virtual int AddRenderCallback(int render_id, VideoRenderCallback* callback) {
122     return 0;
123   }
124 
125  protected:
ViERender()126   ViERender() {}
~ViERender()127   virtual ~ViERender() {}
128 };
129 
130 }  // namespace webrtc
131 
132 #endif  // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_RENDER_H_
133