C++SDK  1.0.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  class IRemoteCtrl;
12 
17  public:
22  virtual void onFirstFrameArrived(IVideoRender* render) = 0;
23  protected:
25  }
26  };
27 
34  public:
35  class IListener {
36  public:
37  virtual void OnDestroy(DestroyNotify* destroy) = 0;
38  };
39  typedef std::vector<IListener*> ListenersType;
40 
45  virtual Result AddDestroyNotify(IListener* pListener) {
46  for (ListenersType::size_type i = 0; i < pListeners_.size(); ++i) {
47  if (pListener == pListeners_[i]) {
48  return AVD_OK;
49  }
50  }
51  pListeners_.push_back(pListener);
52  return AVD_OK;
53  }
54 
59  virtual Result RemoveDestroyNotify(IListener* pListener) {
60  for (ListenersType::iterator it = pListeners_.begin(); it != pListeners_.end(); it++) {
61  if ((*it) == pListener) {
62  pListeners_.erase(it);
63  break;
64  }
65  }
66  return AVD_OK;
67  }
68  virtual ~DestroyNotify() {
69  ListenersType listeners = pListeners_;
70  pListeners_.clear();
71  for (ListenersType::const_iterator it = listeners.begin(); it != listeners.end(); it++) {
72  (*it)->OnDestroy(this);
73  }
74  listeners.clear();
75  }
76  protected:
77  ListenersType pListeners_;
78  };
79 
86  public:
87 
93  virtual void SetSize(int width, int height) = 0;
98  virtual void RenderFrame(const IVideoFrame* frame) = 0;
99  //
107  virtual Result EnableCapture(bool enable) {
108  return Err_Not_Implemented;
109  }
116  virtual Result CaptureImage(const String& fileName, int quality) {
117  return Err_Not_Implemented;
118  }
119 
125  virtual Result GetWindowId(WindowId& id) const {
126  return Err_Not_Implemented;
127  }
128 
135  virtual Result GetSize(int& width, int& height) const {
136  return Err_Not_Implemented;
137  }
138 
145  return Err_Not_Implemented;
146  }
147 
154  return Err_Not_Implemented;
155  }
156 
165  return Err_Not_Implemented;
166  }
174  static Result Save2Image(const IVideoFrame* frame, const String& jpegorbmpFileName, int quality/*0-100, higher is better*/);
175 
179  virtual int32 SetRemoteCtrlModule(IRemoteCtrl* remote,std::string othersideuid){
180  return Err_Not_Implemented;
181  }
182 
186  virtual bool getIsGdiView() {
187  return false;
188  }
189  protected:
190  // The destructor is protected to prevent deletion via the interface.
191  // This is so that we allow reference counted classes, where the destructor
192  // should never be public, to implement the interface
193  protected:
194  virtual ~IVideoRender() {
195  }
196  };
197 
199  public:
200  enum ScalingType {
201  Scale_Fill = 1, // video frame is scaled to to fill the size of the view. Video aspect ratio is changed if necessary.
202  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).
203  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.
204  };
205  public:
206  static IVideoRenderView* CreateVideoRenderView(const int32 id,
207  void* window,
208  const bool fullscreen, bool isgdi = false);
209  static void DestroyVideoRenderView(IVideoRenderView* module);
210 
211  virtual IVideoRender*
212  CreateVideoRender(const uint32 renderId,
213  const uint32 zOrder,
214  const float left, const float top,
215  const float right, const float bottom) = 0;
216 
217  virtual IVideoRender* CreateVideoRender(const uint32 renderId,
218  const uint32 zOrder,
219  ScalingType scalingType,
220  const float left, const float top,
221  const float right, const float bottom) = 0;
222 
223  virtual int32
224  DeleteVideoRender(const uint32 renderId) = 0;
225 
226  virtual int32 StartRender(const uint32 renderId) = 0;
227 
228  virtual int32 StopRender(const uint32 renderId) = 0;
229 
230  /*
231  * Set the renderer ScalingType
232  */
233  virtual bool SetScalingType(const uint32 renderId, ScalingType type) = 0;
234 
235  /*
236  * Get the renderer ScalingType
237  */
238  virtual ScalingType RenderScalingType(const uint32 renderId) = 0;
239 
240  virtual int32 UpdateWindowSize() = 0;
241 
242  virtual int32 SetBitmap(const void* bitMap,
243  const uint8 pictureId,
244  const void* colorKey,
245  const float left, const float top,
246  const float right, const float bottom) = 0;
247 
248  virtual int32 SetText(const uint8 textId,
249  const char* text,
250  const int32 textLength,
251  const uint32 textColorRef,
252  const uint32 backgroundColorRef,
253  const float left, const float top,
254  const float right, const float bottom) = 0;
255 
256  virtual int32 SetText(const uint8 textId,
257  const char* text,
258  const int32 textLength,
259  const uint32 textColor,
260  const float left, const float top,
261  const float rigth, const float bottom,
262  const int32 format,
263  const int32 height,
264  const uint32 width,
265  const uint32 weight,
266  const bool italic,
267  const char* faceName,
268  const int32 faceNameSize) = 0;
269  protected:
270  virtual ~IVideoRenderView() {};
271 
272  };
273  enum {
278  };
279 
280  // Represents a YUV420 (a.k.a. I420) video frame.
282  public:
283  virtual ~IVideoFrame() {}
284 
285  virtual bool InitToBlack(int w, int h, size_t pixel_width,
286  size_t pixel_height, int64 elapsed_time,
287  int64 time_stamp) = 0;
288  // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|.
289  // |h| can be negative indicating a vertically flipped image.
290  // |dw| is destination width; can be less than |w| if cropping is desired.
291  // |dh| is destination height, like |dw|, but must be a positive number.
292  // Returns whether the function succeeded or failed.
293  virtual bool Reset(uint32 fourcc, int w, int h, int dw, int dh, uint8 *sample,
294  size_t sample_size, size_t pixel_width,
295  size_t pixel_height, int64 elapsed_time, int64 time_stamp,
296  int rotation) = 0;
297 
298  // Basic accessors.
299  virtual size_t GetWidth() const = 0;
300  virtual size_t GetHeight() const = 0;
301  size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
302  size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
303  size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); }
304  // These can return NULL if the object is not backed by a buffer.
305  virtual const uint8 *GetYPlane() const = 0;
306  virtual const uint8 *GetUPlane() const = 0;
307  virtual const uint8 *GetVPlane() const = 0;
308  virtual uint8 *GetYPlane() = 0;
309  virtual uint8 *GetUPlane() = 0;
310  virtual uint8 *GetVPlane() = 0;
311 
312  virtual int32 GetYPitch() const = 0;
313  virtual int32 GetUPitch() const = 0;
314  virtual int32 GetVPitch() const = 0;
315 
316  // Returns the handle of the underlying video frame. This is used when the
317  // frame is backed by a texture. The object should be destroyed when it is no
318  // longer in use, so the underlying resource can be freed.
319  virtual void* GetNativeHandle() const = 0;
320 
321  // For retrieving the aspect ratio of each pixel. Usually this is 1x1, but
322  // the aspect_ratio_idc parameter of H.264 can specify non-square pixels.
323  virtual size_t GetPixelWidth() const = 0;
324  virtual size_t GetPixelHeight() const = 0;
325 
326  virtual int64 GetElapsedTime() const = 0;
327  virtual int64 GetTimeStamp() const = 0;
328  virtual void SetElapsedTime(int64 elapsed_time) = 0;
329  virtual void SetTimeStamp(int64 time_stamp) = 0;
330 
331  // Indicates the rotation angle in degrees.
332  virtual int GetRotation() const = 0;
333 
334  // Make a shallow copy of the frame. The frame buffer itself is not copied.
335  // Both the current and new IVideoFrame will share a single reference-counted
336  // frame buffer.
337  virtual IVideoFrame *Copy() const = 0;
338 
339  // Since IVideoFrame supports shallow copy and the internal frame buffer might
340  // be shared, in case IVideoFrame needs exclusive access of the frame buffer,
341  // user can call MakeExclusive() to make sure the frame buffer is exclusive
342  // accessable to the current object. This might mean a deep copy of the frame
343  // buffer if it is currently shared by other objects.
344  virtual bool MakeExclusive() = 0;
345 
346  // Writes the frame into the given frame buffer, provided that it is of
347  // sufficient size. Returns the frame's actual size, regardless of whether
348  // it was written or not (like snprintf). If there is insufficient space,
349  // nothing is written.
350  virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const = 0;
351 
352  // Writes the frame into the given planes, stretched to the given width and
353  // height. The parameter "interpolate" controls whether to interpolate or just
354  // take the nearest-point. The parameter "crop" controls whether to crop this
355  // frame to the aspect ratio of the given dimensions before stretching.
356  virtual bool CopyToPlanes(
357  uint8* dst_y, uint8* dst_u, uint8* dst_v,
358  int32 dst_pitch_y, int32 dst_pitch_u, int32 dst_pitch_v) const = 0;
359 
360  // Writes the frame into the target IVideoFrame.
361  virtual void CopyToFrame(IVideoFrame* target) const = 0;
362 
363  // Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
364  // Returns the frame's actual size, regardless of whether it was written or
365  // not (like snprintf). Parameters size and stride_rgb are in units of bytes.
366  // If there is insufficient space, nothing is written.
367  virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer,
368  size_t size, int stride_rgb) const = 0;
369 
370  // Writes the frame into the given planes, stretched to the given width and
371  // height. The parameter "interpolate" controls whether to interpolate or just
372  // take the nearest-point. The parameter "crop" controls whether to crop this
373  // frame to the aspect ratio of the given dimensions before stretching.
374  virtual void StretchToPlanes(
375  uint8 *y, uint8 *u, uint8 *v, int32 pitchY, int32 pitchU, int32 pitchV,
376  size_t width, size_t height, bool interpolate, bool crop) const = 0;
377 
378  // Writes the frame into the target IVideoFrame, stretched to the size of that
379  // frame. The parameter "interpolate" controls whether to interpolate or just
380  // take the nearest-point. The parameter "crop" controls whether to crop this
381  // frame to the aspect ratio of the target frame before stretching.
382  virtual void StretchToFrame(IVideoFrame *target, bool interpolate,
383  bool crop) const = 0;
384 
385  // Stretches the frame to the given size, creating a new IVideoFrame object to
386  // hold it. The parameter "interpolate" controls whether to interpolate or
387  // just take the nearest-point. The parameter "crop" controls whether to crop
388  // this frame to the aspect ratio of the given dimensions before stretching.
389  virtual IVideoFrame *Stretch(size_t w, size_t h, bool interpolate,
390  bool crop) const = 0;
391 
392  // Sets the video frame to black.
393  virtual bool SetToBlack() = 0;
394 
395  // Scale copy
396  virtual IVideoFrame *CopyRange(int x, int y, int w, int h) const = 0;
397 
398  // Tests if sample is valid. Returns true if valid.
399  static bool Validate(uint32 fourcc, int w, int h, const uint8 *sample,
400  size_t sample_size);
401 
402  // Size of an I420 image of given dimensions when stored as a frame buffer.
403  static size_t SizeOf(size_t w, size_t h) {
404  return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
405  }
406  };
407 
408  } // namespace avd
409 } // namespace tee3
410 #endif//RTC_VideoRender_H_
static size_t SizeOf(size_t w, size_t h)
Definition: videorender.h:403
virtual ~IVideoFrame()
Definition: videorender.h:283
size_t GetChromaWidth() const
Definition: videorender.h:301
Definition: videorender.h:277
virtual Result GetWindowId(WindowId &id) const
Definition: videorender.h:125
NAMESPACE_TEE3_BEGIN typedef std::string String
Definition: common.h:10
Definition: videorender.h:198
int int32
Definition: defines.h:394
virtual Result GetAnnotation(tee3::avd::IMAnnotation **atn)
Definition: videorender.h:153
ListenersType pListeners_
Definition: videorender.h:77
Definition: mremotectrl.h:77
size_t GetChromaHeight() const
Definition: videorender.h:302
virtual ~IVideoRender()
Definition: videorender.h:194
int Result
Definition: combase.h:13
#define Err_Not_Implemented
Definition: errorcode.h:20
#define RT_API_EXPORT
Definition: defines.h:188
virtual Result CaptureImage(const String &fileName, int quality)
Definition: videorender.h:116
ScalingType
Definition: videorender.h:200
Definition: videorender.h:33
virtual ~IFirstFrameListener()
Definition: videorender.h:24
unsigned int uint32
Definition: defines.h:393
Definition: videorender.h:274
virtual Result SetAnnotation(tee3::avd::IMAnnotation *atn)
Definition: videorender.h:144
long long int64
Definition: defines.h:383
virtual ~IVideoRenderView()
Definition: videorender.h:270
Definition: videorender.h:16
Definition: videorender.h:276
virtual Result setFirstFrameListener(IFirstFrameListener *listener)
Definition: videorender.h:164
virtual Result GetSize(int &width, int &height) const
Definition: videorender.h:135
Definition: videorender.h:85
Definition: videorender.h:275
virtual Result RemoveDestroyNotify(IListener *pListener)
Definition: videorender.h:59
virtual Result AddDestroyNotify(IListener *pListener)
Definition: videorender.h:45
#define AVD_OK
Definition: errorcode.h:7
Definition: common.h:399
Definition: videorender.h:281
virtual ~DestroyNotify()
Definition: videorender.h:68
virtual Result EnableCapture(bool enable)
Definition: videorender.h:107
unsigned char uint8
Definition: defines.h:397
virtual int32 SetRemoteCtrlModule(IRemoteCtrl *remote, std::string othersideuid)
Definition: videorender.h:179
size_t GetChromaSize() const
Definition: videorender.h:303
Definition: audiocapture.h:5
Definition: videorender.h:35
std::vector< IListener * > ListenersType
Definition: videorender.h:39
Definition: mannotation.h:27
virtual bool getIsGdiView()
Definition: videorender.h:186