抓娃娃版1127

IAgoraMediaEngine.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef AGORA_MEDIA_ENGINE_H
  2. #define AGORA_MEDIA_ENGINE_H
  3. #if defined _WIN32 || defined __CYGWIN__
  4. typedef __int64 int64_t;
  5. typedef unsigned __int64 uint64_t;
  6. #else
  7. #include <stdint.h>
  8. #endif
  9. namespace agora
  10. {
  11. namespace media
  12. {
  13. class IAudioFrameObserver
  14. {
  15. public:
  16. enum AUDIO_FRAME_TYPE {
  17. FRAME_TYPE_PCM16 = 0, //PCM 16bit little endian
  18. };
  19. struct AudioFrame {
  20. AUDIO_FRAME_TYPE type;
  21. int samples; //number of samples in this frame
  22. int bytesPerSample; //number of bytes per sample: 2 for PCM16
  23. int channels; //number of channels (data are interleaved if stereo)
  24. int samplesPerSec; //sampling rate
  25. void* buffer; //data buffer
  26. int64_t renderTimeMs;
  27. };
  28. public:
  29. virtual bool onRecordAudioFrame(AudioFrame& audioFrame) = 0;
  30. virtual bool onPlaybackAudioFrame(AudioFrame& audioFrame) = 0;
  31. virtual bool onMixedAudioFrame(AudioFrame& audioFrame) = 0;
  32. virtual bool onPlaybackAudioFrameBeforeMixing(unsigned int uid, AudioFrame& audioFrame) = 0;
  33. };
  34. class IVideoFrameObserver
  35. {
  36. public:
  37. enum VIDEO_FRAME_TYPE {
  38. FRAME_TYPE_YUV420 = 0, //YUV 420 format
  39. };
  40. struct VideoFrame {
  41. VIDEO_FRAME_TYPE type;
  42. int width; //width of video frame
  43. int height; //height of video frame
  44. int yStride; //stride of Y data buffer
  45. int uStride; //stride of U data buffer
  46. int vStride; //stride of V data buffer
  47. void* yBuffer; //Y data buffer
  48. void* uBuffer; //U data buffer
  49. void* vBuffer; //V data buffer
  50. int rotation; // rotation of this frame (0, 90, 180, 270)
  51. int64_t renderTimeMs;
  52. };
  53. public:
  54. virtual bool onCaptureVideoFrame(VideoFrame& videoFrame) = 0;
  55. virtual bool onRenderVideoFrame(unsigned int uid, VideoFrame& videoFrame) = 0;
  56. };
  57. class IVideoFrame
  58. {
  59. public:
  60. enum PLANE_TYPE {
  61. Y_PLANE = 0,
  62. U_PLANE = 1,
  63. V_PLANE = 2,
  64. NUM_OF_PLANES = 3
  65. };
  66. enum VIDEO_TYPE {
  67. VIDEO_TYPE_UNKNOWN = 0,
  68. VIDEO_TYPE_I420 = 1,
  69. VIDEO_TYPE_IYUV = 2,
  70. VIDEO_TYPE_RGB24 = 3,
  71. VIDEO_TYPE_ABGR = 4,
  72. VIDEO_TYPE_ARGB = 5,
  73. VIDEO_TYPE_ARGB4444 = 6,
  74. VIDEO_TYPE_RGB565 = 7,
  75. VIDEO_TYPE_ARGB1555 = 8,
  76. VIDEO_TYPE_YUY2 = 9,
  77. VIDEO_TYPE_YV12 = 10,
  78. VIDEO_TYPE_UYVY = 11,
  79. VIDEO_TYPE_MJPG = 12,
  80. VIDEO_TYPE_NV21 = 13,
  81. VIDEO_TYPE_NV12 = 14,
  82. VIDEO_TYPE_BGRA = 15,
  83. VIDEO_TYPE_RGBA = 16,
  84. };
  85. virtual void release() = 0;
  86. virtual const unsigned char* buffer(PLANE_TYPE type) const = 0;
  87. // Copy frame: If required size is bigger than allocated one, new buffers of
  88. // adequate size will be allocated.
  89. // Return value: 0 on success ,-1 on error.
  90. virtual int copyFrame(IVideoFrame** dest_frame) const = 0;
  91. // Convert frame
  92. // Input:
  93. // - src_frame : Reference to a source frame.
  94. // - dst_video_type : Type of output video.
  95. // - dst_sample_size : Required only for the parsing of MJPG.
  96. // - dst_frame : Pointer to a destination frame.
  97. // Return value: 0 if OK, < 0 otherwise.
  98. // It is assumed that source and destination have equal height.
  99. virtual int convertFrame(VIDEO_TYPE dst_video_type, int dst_sample_size, unsigned char* dst_frame) const = 0;
  100. // Get allocated size per plane.
  101. virtual int allocated_size(PLANE_TYPE type) const = 0;
  102. // Get allocated stride per plane.
  103. virtual int stride(PLANE_TYPE type) const = 0;
  104. // Get frame width.
  105. virtual int width() const = 0;
  106. // Get frame height.
  107. virtual int height() const = 0;
  108. // Get frame timestamp (90kHz).
  109. virtual unsigned int timestamp() const = 0;
  110. // Get render time in milliseconds.
  111. virtual int64_t render_time_ms() const = 0;
  112. // Return true if underlying plane buffers are of zero size, false if not.
  113. virtual bool IsZeroSize() const = 0;
  114. };
  115. class IExternalVideoRenderCallback
  116. {
  117. public:
  118. virtual void onViewSizeChanged(int width, int height) = 0;
  119. virtual void onViewDestroyed() = 0;
  120. };
  121. struct ExternalVideoRenerContext
  122. {
  123. IExternalVideoRenderCallback* renderCallback;
  124. void* view;
  125. int renderMode;
  126. int zOrder;
  127. float left;
  128. float top;
  129. float right;
  130. float bottom;
  131. };
  132. class IExternalVideoRender
  133. {
  134. public:
  135. virtual void release() = 0;
  136. virtual int initialize() = 0;
  137. virtual int deliverFrame(const IVideoFrame& videoFrame, int rotation, bool mirrored) = 0;
  138. };
  139. class IExternalVideoRenderFactory
  140. {
  141. public:
  142. virtual IExternalVideoRender* createRenderInstance(const ExternalVideoRenerContext& context) = 0;
  143. };
  144. class IMediaEngine
  145. {
  146. public:
  147. virtual void release() = 0;
  148. virtual int registerAudioFrameObserver(IAudioFrameObserver* observer) = 0;
  149. virtual int registerVideoFrameObserver(IVideoFrameObserver* observer) = 0;
  150. virtual int registerVideoRenderFactory(IExternalVideoRenderFactory* factory) = 0;
  151. };
  152. } //media
  153. } //agora
  154. #endif //AGORA_MEDIA_ENGINE_H