BeautyAPI.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // BeautyAPI.h
  3. // BeautyAPi
  4. //
  5. // Created by zhaoyongqiang on 2023/5/31.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #if __has_include(<AgoraRtcKit/AgoraRtcKit.h>)
  9. #import <AgoraRtcKit/AgoraRtcKit.h>
  10. #else
  11. #import <AVFoundation/AVFoundation.h>
  12. #endif
  13. NS_ASSUME_NONNULL_BEGIN
  14. typedef NS_ENUM(NSInteger, BeautyPresetMode) {
  15. /// 默认美颜参数
  16. BeautyPresetModeDefault = 0,
  17. /// 外部自定义美颜参数, 外部自行设置
  18. BeautyPresetModeCustom = 1
  19. };
  20. @protocol BeautyRenderDelegate <NSObject>
  21. - (CVPixelBufferRef)onCapture: (CVPixelBufferRef)pixelBuffer;
  22. #if __has_include(<AgoraRtcKit/AgoraRtcKit.h>)
  23. - (AgoraVideoFormat)getVideoFormatPreference;
  24. #endif
  25. - (void)destroy;
  26. @optional
  27. - (void)setBeautyPreset;
  28. - (void)setMakeup: (BOOL)isSelected;
  29. - (void)setSticker: (BOOL)isSelected;
  30. - (void)reset;
  31. @end
  32. typedef NS_ENUM(NSInteger, CaptureMode) {
  33. CaptureModeAgora = 0,
  34. CaptureModeCustom = 1
  35. };
  36. @interface BeautyStats : NSObject
  37. /// 美颜最小耗时
  38. @property (nonatomic, assign)double minCostMs;
  39. /// 美颜最大耗时
  40. @property (nonatomic, assign)double maxCostMs;
  41. /// 美颜平均耗时
  42. @property (nonatomic, assign)double averageCostMs;
  43. @end
  44. typedef NS_ENUM(NSInteger, MirrorMode) {
  45. /// 本地远端都镜像,前置默认
  46. MirrorMode_LOCAL_REMOTE = 0,
  47. /// 仅本地镜像,远端不镜像,用于打电话场景,电商直播场景(保证电商直播后面的告示牌文字是正的);这种模式因为本地远端是反的,所以肯定有一边的文字贴纸方向会是反的
  48. MirrorMode_LOCAL_ONLY = 1,
  49. /// 仅远端镜像
  50. MirrorMode_REMOTE_ONLY= 2,
  51. /// 本地远端都不镜像,后置默认
  52. MirrorMode_NONE
  53. };
  54. @interface CameraConfig : NSObject
  55. // 前置默认镜像
  56. @property(nonatomic, assign) MirrorMode frontMirror;
  57. // 后置默认镜像
  58. @property(nonatomic, assign) MirrorMode backMirror;
  59. @end
  60. @interface BeautyConfig : NSObject
  61. #if __has_include(<AgoraRtcKit/AgoraRtcKit.h>)
  62. // 由外部传入的rtc对象,不可为空
  63. @property(nonatomic, weak)AgoraRtcEngineKit *rtcEngine;
  64. #endif
  65. // 由外部传入的美颜SDK接口对象(不同厂家不一样),不可为空
  66. @property(nonatomic, weak)id<BeautyRenderDelegate>beautyRender;
  67. // 是否由内部自动注册祼数据回调处理
  68. @property(nonatomic, assign)CaptureMode captureMode;
  69. // 事件回调,包含美颜耗时
  70. @property(nonatomic, copy)void (^eventCallback)(BeautyStats *stats);
  71. // 统计区间 单位: 秒 默认: 1s
  72. @property(nonatomic, assign)NSInteger statsDuration;
  73. // 是否开启统计
  74. @property(nonatomic, assign)BOOL statsEnable;
  75. // 配置摄像头镜像
  76. @property(nonatomic, strong)CameraConfig *cameraConfig;
  77. @end
  78. @interface BeautyAPI : NSObject
  79. /**
  80. * Render
  81. **/
  82. @property (nonatomic, weak) id<BeautyRenderDelegate>beautyRender;
  83. /**
  84. * 创建并初始化美颜场景化API,如果外部调用过registerVideoFrameObserver,那create必须在此之后调用
  85. *
  86. * @param config 配置
  87. *
  88. * @return 0: 成功, 非0: 见错误码
  89. **/
  90. - (int)initialize: (BeautyConfig *)config;
  91. /**
  92. * 美颜开关
  93. *
  94. * @param enable 是否打开美颜
  95. *
  96. * @return 0: 成功, 非0: 见错误码
  97. **/
  98. - (int)enable: (BOOL)enable;
  99. /**
  100. * 读取美颜开关状态
  101. **/
  102. @property (nonatomic, readonly, assign) BOOL isEnable;
  103. /**
  104. * 是否是前置摄像头
  105. **/
  106. @property (nonatomic, assign, readonly) BOOL isFrontCamera;
  107. /**
  108. * 切换摄像头
  109. *
  110. *
  111. * @return 0: 成功;非0:见错误码
  112. **/
  113. - (int)switchCamera;
  114. /**
  115. * 设置摄像头镜像模式,注意前置和后置要单独控制
  116. *
  117. *
  118. * @return 0: 成功;非0:见错误码
  119. **/
  120. - (int)updateCameraConfig: (CameraConfig *)cameraConfig;
  121. /**
  122. * 本地视图渲染,由内部来处理镜像问题
  123. *
  124. * @param view 渲染视图
  125. * @param renderMode 渲染缩放模式
  126. * @return 0: 成功, 非0: 见错误码
  127. **/
  128. #if __has_include(<AgoraRtcKit/AgoraRtcKit.h>)
  129. - (int)setupLocalVideo: (UIView *)view renderMode: (AgoraVideoRenderMode)renderMode;
  130. #endif
  131. /**
  132. * 镜像处理方法,当useCustom为true时才需要调用
  133. *
  134. * @return 采集时是否需要镜像
  135. **/
  136. - (BOOL)getMirrorApplied;
  137. /**
  138. * 美颜处理方法,当useCustom为true时才需要调用,否则会报错
  139. *
  140. *
  141. * @return 0: 成功;非0:见错误码
  142. **/
  143. - (int)onFrame: (CVPixelBufferRef)pixelBuffer callback: (void (^)(CVPixelBufferRef))callback;
  144. /**
  145. * 设置美颜最佳默认参数
  146. *
  147. * @param mode 美颜参数模式
  148. *
  149. * @return 0: 成功;非0:见错误码
  150. **/
  151. - (int)setBeautyPreset: (BeautyPresetMode)mode;
  152. /**
  153. * 销毁美颜场景化API。
  154. * 当创建useCustome=true时,会调用rtcEngine.registerVideoFrameObserver(null)将祼数据回调解绑。
  155. *
  156. * @return 0: 成功;非0: 见错误码表
  157. **/
  158. - (int)destroy;
  159. /**
  160. * @return 版本号
  161. **/
  162. - (NSString *)getVersion;
  163. @end
  164. typedef NS_ENUM(NSInteger, LogLevel) {
  165. LogLevelInfo,
  166. LogLevelError,
  167. LogLevelDebug
  168. };
  169. @interface LogUtil : NSObject
  170. + (void)log:(NSString *)message;
  171. + (void)log:(NSString *)message level:(LogLevel)level;
  172. @end
  173. NS_ASSUME_NONNULL_END