rtc.avd_SDK-C++  3.2.0
videorender.h
浏览该文件的文档.
1 #ifndef RTC_VideoRender_H_
2 #define RTC_VideoRender_H_
3 
4 #include "common.h"
5 
6 namespace rtc {
7  class IVideoRender;
8  class IVideoFrame;
9  class IMAnnotation;
10  class IRemoteCtrl;
11 
16  public:
21  virtual void onFirstFrameArrived(IVideoRender* render) = 0;
22  protected:
24  }
25  };
26 
33  public:
34  class IListener {
35  public:
36  virtual void OnDestroy(DestroyNotify* destroy) = 0;
37  protected:
38  virtual ~IListener() {}
39  };
40  typedef std::vector<IListener*> ListenersType;
41 
46  virtual Result AddDestroyNotify(IListener* pListener) {
47  for (ListenersType::size_type i = 0; i < pListeners_.size(); ++i) {
48  if (pListener == pListeners_[i]) {
49  return AVD_OK;
50  }
51  }
52  pListeners_.push_back(pListener);
53  return AVD_OK;
54  }
55 
60  virtual Result RemoveDestroyNotify(IListener* pListener) {
61  for (ListenersType::iterator it = pListeners_.begin(); it != pListeners_.end(); it++) {
62  if ((*it) == pListener) {
63  pListeners_.erase(it);
64  break;
65  }
66  }
67  return AVD_OK;
68  }
69  virtual ~DestroyNotify() {
70  Clear();
71  }
72  void Clear() {
73  ListenersType listeners = pListeners_;
74  pListeners_.clear();
75  for (ListenersType::const_iterator it = listeners.begin(); it != listeners.end(); it++) {
76  (*it)->OnDestroy(this);
77  }
78  listeners.clear();
79  }
80 
81  protected:
83  };
84 
91  public:
97  virtual void SetSize(int width, int height) = 0;
102  virtual void RenderFrame(const IVideoFrame& frame) = 0;
103  //
111  virtual Result EnableCapture(bool enable) {
112  return Err_Not_Implemented;
113  }
120  virtual Result CaptureImage(const String& fileName, int quality) {
121  return Err_Not_Implemented;
122  }
123 
129  virtual Result GetWindowId(AvdWindowId& id) const {
130  return Err_Not_Implemented;
131  }
132 
139  virtual Result GetSize(int& width, int& height) const {
140  return Err_Not_Implemented;
141  }
142 
149  return Err_Not_Implemented;
150  }
151 
158  return Err_Not_Implemented;
159  }
160 
169  return Err_Not_Implemented;
170  }
178  static Result Save2Image(const IVideoFrame* frame, const String& jpegorbmpFileName, int quality/*0-100, higher is better*/);
179 
183  virtual int32 SetRemoteCtrlModule(IRemoteCtrl* remote,std::string othersideuid){
184  return Err_Not_Implemented;
185  }
186  virtual Result FillBlack() {
187  return Err_Not_Implemented;
188  }
192  virtual bool getIsGdiView() {
193  return false;
194  }
195  protected:
196  // The destructor is protected to prevent deletion via the interface.
197  // This is so that we allow reference counted classes, where the destructor
198  // should never be public, to implement the interface
199  protected:
200  virtual ~IVideoRender() {
201  }
202  };
203 
205  public:
206  enum ScalingType {
207  Scale_Fill = 1, // video frame is scaled to to fill the size of the view. Video aspect ratio is changed if necessary.
208  Scale_Aspect_Fit = 2, // video frame is scaled to fit the size of the view by maintaining the aspect ratio (black borders may be displayed).
209  Scale_Aspect_Full = 3, // video frame is scaled to fill the size of the view by maintaining the aspect ratio. Some portion of the video frame may be clipped.
210  };
211  public:
212  static IVideoRenderView* CreateVideoRenderView(const int32 id,
213  void* window,
214  const bool fullscreen, bool isgdi = false);
215  static void DestroyVideoRenderView(IVideoRenderView* module);
216 
217  virtual IVideoRender*
218  CreateVideoRender(const uint32 renderId,
219  const uint32 zOrder,
220  const float left, const float top,
221  const float right, const float bottom) = 0;
222 
223  virtual IVideoRender* CreateVideoRender(const uint32 renderId,
224  const uint32 zOrder,
225  ScalingType scalingType,
226  const float left, const float top,
227  const float right, const float bottom) = 0;
228 
229  virtual int32
230  DeleteVideoRender(const uint32 renderId) = 0;
231 
232  virtual int32 StartRender(const uint32 renderId) = 0;
233 
234  virtual int32 StopRender(const uint32 renderId) = 0;
235 
236  /*
237  * Set the renderer ScalingType
238  */
239  virtual bool SetScalingType(const uint32 renderId, ScalingType type) = 0;
240 
241  /*
242  * Get the renderer ScalingType
243  */
244  virtual ScalingType RenderScalingType(const uint32 renderId) = 0;
245 
246  virtual int32 UpdateWindowSize(bool fillblack = false) = 0;
247 
248 
249  virtual int32 SetBitmap(const void* bitMap,
250  const uint8 pictureId,
251  const void* colorKey,
252  const float left, const float top,
253  const float right, const float bottom) = 0;
254 
255  virtual int32 SetText(const uint8 textId,
256  const char* text,
257  const int32 textLength,
258  const uint32 textColorRef,
259  const uint32 backgroundColorRef,
260  const float left, const float top,
261  const float right, const float bottom) = 0;
262 
263  virtual int32 SetText(const uint8 textId,
264  const char* text,
265  const int32 textLength,
266  const uint32 textColor,
267  const float left, const float top,
268  const float rigth, const float bottom,
269  const int32 format,
270  const int32 height,
271  const uint32 width,
272  const uint32 weight,
273  const bool italic,
274  const char* faceName,
275  const int32 faceNameSize) = 0;
276  protected:
277  virtual ~IVideoRenderView() {};
278 
279  };
280  enum {
285  };
286 
289  public:
290  virtual ~IVideoFrame() {}
291 
292  // Size of an I420 image of given dimensions when stored as a frame buffer.
293  static size_t SizeOf(size_t w, size_t h) {
294  return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
295  }
296  static const IVideoFrame& getBlackFrame();
297  int32 size() const { return width() * height() + ((width() + 1) / 2) * ((height() + 1) / 2) * 2; }
298  virtual int32 width() const = 0;
299  virtual int32 height() const = 0;
300  virtual bool is_texture() const = 0;
301 
302  virtual const uint8 *dataY() const = 0;
303  virtual const uint8 *dataU() const = 0;
304  virtual const uint8 *dataV() const = 0;
305 
306  virtual uint8* mutableDataY() = 0;
307  virtual uint8* mutableDataU() = 0;
308  virtual uint8* mutableDataV() = 0;
309 
310  virtual int32 strideY() const = 0;
311  virtual int32 strideU() const = 0;
312  virtual int32 strideV() const = 0;
313 
314  virtual int32 rotation() const = 0;
315 
316  virtual IVideoFrame* copy() const = 0;
317  virtual int32 convertToRgb(uint32 to_fourcc, uint8 *buffer,
318  size_t size, int stride_rgb) const = 0;
319 
320  // Scale copy
321  virtual IVideoFrame *CopyRange(int x, int y, int w, int h) const = 0;
322  virtual bool MakeExclusive() = 0;
323  virtual IVideoFrame *Stretch(size_t w, size_t h, bool interpolate,bool crop) const = 0;
324 
325  size_t GetWidth() const { return width(); }
326  size_t GetHeight() const { return height(); }
327  size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
328  size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
329  size_t GetChromaSize() const { return strideU() * GetChromaHeight(); }
330 
331  const uint8 *GetYPlane() const { return dataY(); }
332  const uint8 *GetUPlane() const { return dataU(); }
333  const uint8 *GetVPlane() const { return dataV(); }
334  uint8 *GetYPlane() { return mutableDataY(); }
335  uint8 *GetUPlane() { return mutableDataU(); }
336  uint8 *GetVPlane() { return mutableDataV(); }
337 
338  int32 GetYPitch() const { return strideY(); }
339  int32 GetUPitch() const { return strideU(); }
340  int32 GetVPitch() const { return strideV(); }
341 
342  virtual IVideoFrame *Copy() const { return copy(); }
343 
344  virtual int64 GetTimeStamp() const = 0;
345  static IVideoFrame *CreateFrame(uint32 format, const uint8 *data, int32 size, size_t width, size_t height, size_t widthDst, size_t heightDst);
346 
347  static IVideoFrame *CreateFrame(uint32 format, const uint8 *src_y, const uint8 *src_uv, size_t width, size_t height, size_t widthDst, size_t heightDst);
348  };
349 
350 } // namespace rtc
351 #endif//RTC_VideoRender_H_
void Clear()
Definition: videorender.h:72
ListenersType pListeners_
Definition: videorender.h:82
视频渲染接口类
Definition: videorender.h:90
Definition: annotationobject.h:71
virtual Result RemoveDestroyNotify(IListener *pListener)
删除渲染对象销毁回调指针
Definition: videorender.h:60
Definition: mremotectrl.h:76
Definition: videorender.h:282
virtual ~IListener()
Definition: videorender.h:38
int32 GetYPitch() const
Definition: videorender.h:338
uint8 * GetVPlane()
Definition: videorender.h:336
int int32
Definition: defines.h:388
virtual Result AddDestroyNotify(IListener *pListener)
设置渲染对象销毁回调指针
Definition: videorender.h:46
virtual Result GetWindowId(AvdWindowId &id) const
获取render所在的WindowId
Definition: videorender.h:129
int Result
返回值类型
Definition: combase.h:13
#define Err_Not_Implemented
Definition: errorcode.h:20
uint8 * GetYPlane()
Definition: videorender.h:334
int32 GetUPitch() const
Definition: videorender.h:339
#define RT_API_EXPORT
Definition: defines.h:216
int32 GetVPitch() const
Definition: videorender.h:340
virtual int32 SetRemoteCtrlModule(IRemoteCtrl *remote, std::string othersideuid)
设置远程控制模块,对方userid
Definition: videorender.h:183
Definition: videorender.h:204
virtual IVideoFrame * Copy() const
Definition: videorender.h:342
unsigned int uint32
Definition: defines.h:387
virtual Result FillBlack()
Definition: videorender.h:186
IVideoRender attach到某个视频后,接收到首帧视频的回调
Definition: videorender.h:15
long long int64
Definition: defines.h:377
std::string String
定义的String类型
Definition: common.h:10
int32 size() const
Definition: videorender.h:297
外部对象销毁通知接口
Definition: videorender.h:32
ScalingType
Definition: videorender.h:206
std::vector< IListener * > ListenersType
Definition: videorender.h:40
virtual Result EnableCapture(bool enable)
启停图像抓取功能
Definition: videorender.h:111
Definition: videorender.h:34
virtual Result GetSize(int &width, int &height) const
获取图像大小
Definition: videorender.h:139
virtual Result CaptureImage(const String &fileName, int quality)
抓取图像
Definition: videorender.h:120
Definition: videorender.h:288
size_t GetHeight() const
Definition: videorender.h:326
#define AVD_OK
Definition: errorcode.h:7
virtual ~IVideoFrame()
Definition: videorender.h:290
Definition: videorender.h:284
size_t GetChromaWidth() const
Definition: videorender.h:327
size_t GetWidth() const
Definition: videorender.h:325
virtual Result setFirstFrameListener(IFirstFrameListener *listener)
设置首帧数据回调指针
Definition: videorender.h:168
Definition: common.h:412
const uint8 * GetVPlane() const
Definition: videorender.h:333
static size_t SizeOf(size_t w, size_t h)
Definition: videorender.h:293
virtual ~IVideoRender()
Definition: videorender.h:200
const uint8 * GetUPlane() const
Definition: videorender.h:332
Definition: mannotation.h:29
unsigned char uint8
Definition: defines.h:391
virtual Result SetAnnotation(rtc::IMAnnotation *atn)
设置注释接口
Definition: videorender.h:148
size_t GetChromaHeight() const
Definition: videorender.h:328
Definition: videorender.h:281
const uint8 * GetYPlane() const
Definition: videorender.h:331
virtual ~DestroyNotify()
Definition: videorender.h:69
virtual ~IVideoRenderView()
Definition: videorender.h:277
size_t GetChromaSize() const
Definition: videorender.h:329
virtual Result GetAnnotation(rtc::IMAnnotation **atn)
获取注释接口
Definition: videorender.h:157
virtual ~IFirstFrameListener()
Definition: videorender.h:23
Definition: videorender.h:283
uint8 * GetUPlane()
Definition: videorender.h:335
virtual bool getIsGdiView()
获取该render是否用gdi模式创建的
Definition: videorender.h:192