cn.tee3.avd_SDK-C++  2.1.0
videorender.h
浏览该文件的文档.
1 #ifndef RTC_VideoRender_H_
2 #define RTC_VideoRender_H_
3 
4 #include "common.h"
5 
6 namespace tee3 {
7  namespace avd {
8  class IVideoRender;
9  class IVideoFrame;
10  class IMAnnotation;
11 
18  public:
19  class IListener {
20  public:
21  virtual void OnDestroy(DestroyNotify* destroy) = 0;
22  };
23  typedef std::vector<IListener*> ListenersType;
24 
29  virtual Result AddDestroyNotify(IListener* pListener) {
30  for (ListenersType::size_type i = 0; i < pListeners_.size(); ++i) {
31  if (pListener == pListeners_[i]) {
32  return AVD_OK;
33  }
34  }
35  pListeners_.push_back(pListener);
36  return AVD_OK;
37  }
38 
43  virtual Result RemoveDestroyNotify(IListener* pListener) {
44  for (ListenersType::iterator it = pListeners_.begin(); it != pListeners_.end(); it++) {
45  if ((*it) == pListener) {
46  pListeners_.erase(it);
47  break;
48  }
49  }
50  return AVD_OK;
51  }
52  virtual ~DestroyNotify() {
53  ListenersType listeners = pListeners_;
54  pListeners_.clear();
55  for (ListenersType::const_iterator it = listeners.begin(); it != listeners.end(); it++) {
56  (*it)->OnDestroy(this);
57  }
58  listeners.clear();
59  }
60  protected:
61  ListenersType pListeners_;
62  };
63 
70  public:
71 
77  virtual void SetSize(int width, int height) = 0;
82  virtual void RenderFrame(const IVideoFrame* frame) = 0;
83  //
91  virtual Result EnableCapture(bool enable) {
92  return Err_Not_Implemented;
93  }
100  virtual Result CaptureImage(const String& fileName, int quality) {
101  return Err_Not_Implemented;
102  }
103 
109  virtual Result GetWindowId(WindowId& id) const {
110  return Err_Not_Implemented;
111  }
112 
119  virtual Result GetSize(int& width, int& height) const {
120  return Err_Not_Implemented;
121  }
122 
129  return Err_Not_Implemented;
130  }
131 
138  return Err_Not_Implemented;
139  }
147  static Result Save2Image(const IVideoFrame* frame, const String& jpegorbmpFileName, int quality/*0-100, higher is better*/);
148  protected:
149  // The destructor is protected to prevent deletion via the interface.
150  // This is so that we allow reference counted classes, where the destructor
151  // should never be public, to implement the interface
152  protected:
153  virtual ~IVideoRender() {
154 
155  }
156  };
157 
159  public:
160  enum ScalingType {
161  Scale_Fill = 1, // video frame is scaled to to fill the size of the view. Video aspect ratio is changed if necessary.
162  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).
163  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.
164  };
165  public:
166  static IVideoRenderView* CreateVideoRenderView(const int32 id,
167  void* window,
168  const bool fullscreen, bool isgdi = false);
169  static void DestroyVideoRenderView(IVideoRenderView* module);
170 
171  virtual IVideoRender*
172  CreateVideoRender(const uint32 renderId,
173  const uint32 zOrder,
174  const float left, const float top,
175  const float right, const float bottom) = 0;
176 
177  virtual IVideoRender* CreateVideoRender(const uint32 renderId,
178  const uint32 zOrder,
179  ScalingType scalingType,
180  const float left, const float top,
181  const float right, const float bottom) = 0;
182 
183  virtual int32
184  DeleteVideoRender(const uint32 renderId) = 0;
185 
186  virtual int32 StartRender(const uint32 renderId) = 0;
187 
188  virtual int32 StopRender(const uint32 renderId) = 0;
189 
190  /*
191  * Set the renderer ScalingType
192  */
193  virtual bool SetScalingType(const uint32 renderId, ScalingType type) = 0;
194 
195  /*
196  * Get the renderer ScalingType
197  */
198  virtual ScalingType RenderScalingType(const uint32 renderId) = 0;
199 
200  virtual int32 UpdateWindowSize() = 0;
201 
202  virtual int32 SetBitmap(const void* bitMap,
203  const uint8 pictureId,
204  const void* colorKey,
205  const float left, const float top,
206  const float right, const float bottom) = 0;
207 
208  virtual int32 SetText(const uint8 textId,
209  const char* text,
210  const int32 textLength,
211  const uint32 textColorRef,
212  const uint32 backgroundColorRef,
213  const float left, const float top,
214  const float right, const float bottom) = 0;
215 
216  virtual int32 SetText(const uint8 textId,
217  const char* text,
218  const int32 textLength,
219  const uint32 textColor,
220  const float left, const float top,
221  const float rigth, const float bottom,
222  const int32 format,
223  const int32 height,
224  const uint32 width,
225  const uint32 weight,
226  const bool italic,
227  const char* faceName,
228  const int32 faceNameSize) = 0;
229  protected:
230  virtual ~IVideoRenderView() {};
231 
232  };
233  enum {
238  };
239 
240  // Represents a YUV420 (a.k.a. I420) video frame.
242  public:
243  virtual ~IVideoFrame() {}
244 
245  virtual bool InitToBlack(int w, int h, size_t pixel_width,
246  size_t pixel_height, int64 elapsed_time,
247  int64 time_stamp) = 0;
248  // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|.
249  // |h| can be negative indicating a vertically flipped image.
250  // |dw| is destination width; can be less than |w| if cropping is desired.
251  // |dh| is destination height, like |dw|, but must be a positive number.
252  // Returns whether the function succeeded or failed.
253  virtual bool Reset(uint32 fourcc, int w, int h, int dw, int dh, uint8 *sample,
254  size_t sample_size, size_t pixel_width,
255  size_t pixel_height, int64 elapsed_time, int64 time_stamp,
256  int rotation) = 0;
257 
258  // Basic accessors.
259  virtual size_t GetWidth() const = 0;
260  virtual size_t GetHeight() const = 0;
261  size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
262  size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
263  size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); }
264  // These can return NULL if the object is not backed by a buffer.
265  virtual const uint8 *GetYPlane() const = 0;
266  virtual const uint8 *GetUPlane() const = 0;
267  virtual const uint8 *GetVPlane() const = 0;
268  virtual uint8 *GetYPlane() = 0;
269  virtual uint8 *GetUPlane() = 0;
270  virtual uint8 *GetVPlane() = 0;
271 
272  virtual int32 GetYPitch() const = 0;
273  virtual int32 GetUPitch() const = 0;
274  virtual int32 GetVPitch() const = 0;
275 
276  // Returns the handle of the underlying video frame. This is used when the
277  // frame is backed by a texture. The object should be destroyed when it is no
278  // longer in use, so the underlying resource can be freed.
279  virtual void* GetNativeHandle() const = 0;
280 
281  // For retrieving the aspect ratio of each pixel. Usually this is 1x1, but
282  // the aspect_ratio_idc parameter of H.264 can specify non-square pixels.
283  virtual size_t GetPixelWidth() const = 0;
284  virtual size_t GetPixelHeight() const = 0;
285 
286  virtual int64 GetElapsedTime() const = 0;
287  virtual int64 GetTimeStamp() const = 0;
288  virtual void SetElapsedTime(int64 elapsed_time) = 0;
289  virtual void SetTimeStamp(int64 time_stamp) = 0;
290 
291  // Indicates the rotation angle in degrees.
292  virtual int GetRotation() const = 0;
293 
294  // Make a shallow copy of the frame. The frame buffer itself is not copied.
295  // Both the current and new IVideoFrame will share a single reference-counted
296  // frame buffer.
297  virtual IVideoFrame *Copy() const = 0;
298 
299  // Since IVideoFrame supports shallow copy and the internal frame buffer might
300  // be shared, in case IVideoFrame needs exclusive access of the frame buffer,
301  // user can call MakeExclusive() to make sure the frame buffer is exclusive
302  // accessable to the current object. This might mean a deep copy of the frame
303  // buffer if it is currently shared by other objects.
304  virtual bool MakeExclusive() = 0;
305 
306  // Writes the frame into the given frame buffer, provided that it is of
307  // sufficient size. Returns the frame's actual size, regardless of whether
308  // it was written or not (like snprintf). If there is insufficient space,
309  // nothing is written.
310  virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const = 0;
311 
312  // Writes the frame into the given planes, stretched to the given width and
313  // height. The parameter "interpolate" controls whether to interpolate or just
314  // take the nearest-point. The parameter "crop" controls whether to crop this
315  // frame to the aspect ratio of the given dimensions before stretching.
316  virtual bool CopyToPlanes(
317  uint8* dst_y, uint8* dst_u, uint8* dst_v,
318  int32 dst_pitch_y, int32 dst_pitch_u, int32 dst_pitch_v) const = 0;
319 
320  // Writes the frame into the target IVideoFrame.
321  virtual void CopyToFrame(IVideoFrame* target) const = 0;
322 
323  // Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
324  // Returns the frame's actual size, regardless of whether it was written or
325  // not (like snprintf). Parameters size and stride_rgb are in units of bytes.
326  // If there is insufficient space, nothing is written.
327  virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer,
328  size_t size, int stride_rgb) const = 0;
329 
330  // Writes the frame into the given planes, stretched to the given width and
331  // height. The parameter "interpolate" controls whether to interpolate or just
332  // take the nearest-point. The parameter "crop" controls whether to crop this
333  // frame to the aspect ratio of the given dimensions before stretching.
334  virtual void StretchToPlanes(
335  uint8 *y, uint8 *u, uint8 *v, int32 pitchY, int32 pitchU, int32 pitchV,
336  size_t width, size_t height, bool interpolate, bool crop) const = 0;
337 
338  // Writes the frame into the target IVideoFrame, stretched to the size of that
339  // frame. The parameter "interpolate" controls whether to interpolate or just
340  // take the nearest-point. The parameter "crop" controls whether to crop this
341  // frame to the aspect ratio of the target frame before stretching.
342  virtual void StretchToFrame(IVideoFrame *target, bool interpolate,
343  bool crop) const = 0;
344 
345  // Stretches the frame to the given size, creating a new IVideoFrame object to
346  // hold it. The parameter "interpolate" controls whether to interpolate or
347  // just take the nearest-point. The parameter "crop" controls whether to crop
348  // this frame to the aspect ratio of the given dimensions before stretching.
349  virtual IVideoFrame *Stretch(size_t w, size_t h, bool interpolate,
350  bool crop) const = 0;
351 
352  // Sets the video frame to black.
353  virtual bool SetToBlack() = 0;
354 
355  // Scale copy
356  virtual IVideoFrame *CopyRange(int x, int y, int w, int h) const = 0;
357 
358  // Tests if sample is valid. Returns true if valid.
359  static bool Validate(uint32 fourcc, int w, int h, const uint8 *sample,
360  size_t sample_size);
361 
362  // Size of an I420 image of given dimensions when stored as a frame buffer.
363  static size_t SizeOf(size_t w, size_t h) {
364  return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
365  }
366  };
367 
368  } // namespace avd
369 } // namespace tee3
370 #endif//RTC_VideoRender_H_
size_t GetChromaWidth() const
Definition: videorender.h:261
Definition: videorender.h:237
int int32
Definition: defines.h:392
int Result
返回值类型
Definition: combase.h:9
#define Err_Not_Implemented
Definition: errorcode.h:20
视频渲染接口类
Definition: videorender.h:69
#define RT_API_EXPORT
Definition: defines.h:186
virtual Result SetAnnotation(tee3::avd::IMAnnotation *atn)
设置注释接口
Definition: videorender.h:128
ListenersType pListeners_
Definition: videorender.h:61
virtual Result EnableCapture(bool enable)
启停图像抓取功能
Definition: videorender.h:91
unsigned int uint32
Definition: defines.h:391
virtual Result RemoveDestroyNotify(IListener *pListener)
删除渲染对象销毁回调指针
Definition: videorender.h:43
Definition: videorender.h:234
long long int64
Definition: defines.h:381
std::string String
tee3定义的String类型
Definition: common.h:10
virtual ~DestroyNotify()
Definition: videorender.h:52
virtual ~IVideoRenderView()
Definition: videorender.h:230
Definition: videorender.h:236
virtual Result GetWindowId(WindowId &id) const
获取render所在的WindowId
Definition: videorender.h:109
virtual ~IVideoFrame()
Definition: videorender.h:243
Definition: common.h:399
Definition: videorender.h:235
Definition: videorender.h:158
virtual Result GetAnnotation(tee3::avd::IMAnnotation **atn)
获取注释接口
Definition: videorender.h:137
virtual Result GetSize(int &width, int &height) const
获取图像大小
Definition: videorender.h:119
#define AVD_OK
Definition: errorcode.h:7
Definition: mannotation.h:18
std::vector< IListener * > ListenersType
Definition: videorender.h:23
unsigned char uint8
Definition: defines.h:395
Definition: videorender.h:241
virtual Result CaptureImage(const String &fileName, int quality)
抓取图像
Definition: videorender.h:100
virtual Result AddDestroyNotify(IListener *pListener)
设置渲染对象销毁回调指针
Definition: videorender.h:29
static size_t SizeOf(size_t w, size_t h)
Definition: videorender.h:363
Definition: audiocapture.h:5
size_t GetChromaHeight() const
Definition: videorender.h:262
virtual ~IVideoRender()
Definition: videorender.h:153
ScalingType
Definition: videorender.h:160
size_t GetChromaSize() const
Definition: videorender.h:263
外部对象销毁通知接口
Definition: videorender.h:17
Definition: videorender.h:19