IEMCallManager.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*!
  2. * \~chinese
  3. * @header IEMCallManager.h
  4. * @abstract 此协议定义了实时音频/视频通话相关操作
  5. * @author Hyphenate
  6. * @version 3.00
  7. *
  8. * \~english
  9. * @header IEMCallManager.h
  10. * @abstract This protocol defined the operations of real time voice/video call
  11. * @author Hyphenate
  12. * @version 3.00
  13. */
  14. #import <AVFoundation/AVFoundation.h>
  15. #import <Foundation/Foundation.h>
  16. #import "EMCallOptions.h"
  17. #import "EMCallManagerDelegate.h"
  18. #import "EMCallBuilderDelegate.h"
  19. #import "EMWaterMarkOption.h"
  20. @class EMError;
  21. @class EMCallStream;
  22. /*!
  23. * \~chinese
  24. * 实时音频/视频通话相关操作
  25. *
  26. * \~english
  27. * The operations of real time voice/video call
  28. */
  29. @protocol IEMCallManager <NSObject>
  30. @optional
  31. #pragma mark - Delegate
  32. /*!
  33. * \~chinese
  34. * 添加回调代理
  35. *
  36. * @param aDelegate 要添加的代理
  37. * @param aQueue 执行代理方法的队列
  38. *
  39. * \~english
  40. * Add delegate
  41. *
  42. * @param aDelegate Delegate
  43. * @param aQueue (optional) The queue of calling delegate methods. Pass in nil to run on main thread.
  44. */
  45. - (void)addDelegate:(id<EMCallManagerDelegate>)aDelegate
  46. delegateQueue:(dispatch_queue_t)aQueue;
  47. /*!
  48. * \~chinese
  49. * 移除回调代理
  50. *
  51. * @param aDelegate 要移除的代理
  52. *
  53. * \~english
  54. * Remove delegate
  55. *
  56. * @param aDelegate Delegate
  57. */
  58. - (void)removeDelegate:(id<EMCallManagerDelegate>)aDelegate;
  59. /*!
  60. * \~chinese
  61. * 添加回调代理,该代理只能设置一个
  62. *
  63. * @param aDelegate 要添加的代理
  64. *
  65. * \~english
  66. * Add delegate
  67. *
  68. * @param aDelegate Delegate
  69. */
  70. - (void)setBuilderDelegate:(id<EMCallBuilderDelegate>)aDelegate;
  71. #pragma mark - Options
  72. /*!
  73. * \~chinese
  74. * 设置设置项
  75. *
  76. * @param aOptions 设置项
  77. *
  78. * \~english
  79. * Set setting options
  80. *
  81. * @param aOptions Setting options
  82. */
  83. - (void)setCallOptions:(EMCallOptions *)aOptions;
  84. /*!
  85. * \~chinese
  86. * 获取设置项
  87. *
  88. * @result 设置项
  89. *
  90. * \~english
  91. * Get setting options
  92. *
  93. * @result Setting options
  94. */
  95. - (EMCallOptions *)getCallOptions;
  96. #pragma mark - Make and Answer and End
  97. /*!
  98. * \~chinese
  99. * 发起实时会话
  100. *
  101. * @param aType 通话类型
  102. * @param aRemoteName 被呼叫的用户(不能与自己通话)
  103. * @param aExt 通话扩展信息,会传给被呼叫方
  104. * @param aCompletionBlock 完成的回调
  105. *
  106. * \~english
  107. * Start a call
  108. *
  109. * @param aType Call type
  110. * @param aRemoteName The callee
  111. * @param aExt Call extention, to the callee
  112. * @param aCompletionBlock The callback of completion
  113. *
  114. */
  115. - (void)startCall:(EMCallType)aType
  116. remoteName:(NSString *)aRemoteName
  117. ext:(NSString *)aExt
  118. completion:(void (^)(EMCallSession *aCallSession, EMError *aError))aCompletionBlock;
  119. /*!
  120. * \~chinese
  121. * 发起实时会话
  122. *
  123. * @param aType 通话类型
  124. * @param aRemoteName 被呼叫的用户(不能与自己通话)
  125. * @param isRecord 是否开启服务端录制
  126. * @param isMerge 录制时是否合并数据流
  127. * @param aExt 通话扩展信息,会传给被呼叫方
  128. * @param aCompletionBlock 完成的回调
  129. *
  130. * \~english
  131. * Start a call
  132. *
  133. * @param aType Call type
  134. * @param aRemoteName The callee
  135. * @param isRecord Whether to record using a server
  136. * @param isMerge Whether to merge data streams while recording
  137. * @param aExt Call extention, to the callee
  138. * @param aCompletionBlock The callback of completion
  139. *
  140. */
  141. - (void)startCall:(EMCallType)aType
  142. remoteName:(NSString *)aRemoteName
  143. record:(BOOL)isRecord
  144. mergeStream:(BOOL)isMerge
  145. ext:(NSString *)aExt
  146. completion:(void (^)(EMCallSession *aCallSession, EMError *aError))aCompletionBlock;
  147. /*!
  148. * \~chinese
  149. * 接收方同意通话请求
  150. *
  151. * @param aCallId 通话ID
  152. *
  153. * @result 错误信息
  154. *
  155. * \~english
  156. * Receiver answer the call
  157. *
  158. * @param aCallId Call Id
  159. * @param aRemoteName Remote name
  160. *
  161. * @result Error
  162. */
  163. - (EMError *)answerIncomingCall:(NSString *)aCallId;
  164. /*!
  165. * \~chinese
  166. * 结束通话
  167. *
  168. * @param aCallId 通话的ID
  169. * @param aReason 结束原因
  170. *
  171. * @result 错误
  172. *
  173. * \~english
  174. * End the call
  175. *
  176. * @param aCallId Call ID
  177. * @param aReason End reason
  178. *
  179. * @result Error
  180. */
  181. - (EMError *)endCall:(NSString *)aCallId
  182. reason:(EMCallEndReason)aReason;
  183. /*!
  184. * \~chinese
  185. * 强制结束所有通话
  186. * 使用场景:做了某些错误操作造成Call UI已经消失但是没有释放掉EMCallManager中维护的EMCallSession,造成再次调用方法[IEMCallManager startCall:remoteName:ext:completion:]返回错误EMErrorCallBusy,如果这时无法调用方法[IEMCallManager endCall:reason:],可以调用该方法
  187. *
  188. * \~english
  189. * Forcibly end all calls
  190. * Usage Scenario: An error occurred that caused the Call UI to disappear but did not release the EMCallSession maintained in the EMCallManager, causing the call to the method [IEMCallManager startCall:remoteName:ext:completion:] to return the error EMErrorCallBusy. If this time can not call the method [IEMCallManager endCall:reason:], you can call this method
  191. */
  192. - (void)forceEndAllCall;
  193. #pragma mark - Input Video Data
  194. /*!
  195. * \~chinese
  196. * 自定义本地视频数据
  197. *
  198. * @param aSampleBuffer 视频采样缓冲区
  199. * @param aRotation 旋转方向
  200. * @param aCallId 1v1会话实例ID,即[EMCallSession callId]
  201. * @param aCompletionBlock 完成后的回调
  202. *
  203. * \~english
  204. * Customize local video data
  205. *
  206. * @param aSampleBuffer Video sample buffer
  207. * @param aRotation UIDeviceOrientation
  208. * @param aCallId [EMCallSession callId]
  209. * @param aCompletionBlock The callback block of completion
  210. */
  211. - (void)inputVideoSampleBuffer:(CMSampleBufferRef)aSampleBuffer
  212. rotation:(UIDeviceOrientation)aRotation
  213. callId:(NSString *)aCallId
  214. completion:(void (^)(EMError *aError))aCompletionBlock;
  215. /*!
  216. * \~chinese
  217. * 自定义本地视频数据
  218. *
  219. * @param aPixelBuffer 视频像素缓冲区
  220. * @param aCallId 1v1会话实例ID,即[EMCallSession callId]
  221. * @param aTime 视频原始数据时间戳,CMTime time = CMSampleBufferGetPresentationTimeStamp((CMSampleBufferRef)sampleBuffer);
  222. * @param aRotation 旋转方向
  223. * @param aCompletionBlock 完成后的回调
  224. *
  225. * \~english
  226. * Customize local video data
  227. *
  228. * @param aPixelBuffer Video pixel buffer
  229. * @param aTime CMTime time = CMSampleBufferGetPresentationTimeStamp((CMSampleBufferRef)sampleBuffer);
  230. * @param aRotation UIDeviceOrientation
  231. * @param aCallId [EMCallSession callId]
  232. * @param aCompletionBlock The callback block of completion
  233. */
  234. - (void)inputVideoPixelBuffer:(CVPixelBufferRef)aPixelBuffer
  235. sampleBufferTime:(CMTime)aTime
  236. rotation:(UIDeviceOrientation)aRotation
  237. callId:(NSString *)aCallId
  238. completion:(void (^)(EMError *aError))aCompletionBlock;
  239. #pragma mark - 截图
  240. //截取本地视频图片
  241. - (void)takeLocalVideoPictureWithCallId:(NSString *)aCallId
  242. saveToPath:(NSString *)aSavePath
  243. completion:(void (^)(NSString *aFilePath, NSError *aError))aCompletion;
  244. //截取对方视频图片
  245. - (void)takeRemoteVideoPictureWithCallId:(NSString *)aCallId
  246. saveToPath:(NSString *)aSavePath
  247. completion:(void (^)(NSString *aFilePath, NSError *aError))aCompletion;
  248. #pragma mark - 自定义音频数据
  249. /*!
  250. * \~chinese
  251. * 自定义外部音频数据,PCM格式,一个音频采样16bit,每次最大100ms数据
  252. *
  253. * @param data 外部音频数据
  254. *
  255. * @return int 返回值,0为写入成功,其他失败,-1为enable未启动,-2为channels错误,必须为1,-3为缓冲已满
  256. *
  257. * \~english
  258. * Customize external audio data,PCM format,each audio sample contail 16 bits,the maxinum data durateion is 100ms
  259. *
  260. * @param data Custom audio data,format with PCM
  261. *
  262. * @return int Return 0 when input data is successed.If enabled is false ,return -1.If channels is not equal to 1,return -2.If buffer is full,return -3.
  263. */
  264. - (int) inputCustomAudioData:(NSData*)data;
  265. #pragma mark - Watermark
  266. /*!
  267. * \~chinese
  268. * 开启水印功能
  269. *
  270. * @param option 水印配置项,包括图片URL,marginX,marginY以及起始点
  271. *
  272. * \~english
  273. * Enable water mark feature
  274. *
  275. * @param origin the option of watermark picture,include url,margingX,marginY,margin point
  276. */
  277. - (void)addVideoWatermark:(EMWaterMarkOption*)option;
  278. /*!
  279. * \~chinese
  280. * 取消水印功能
  281. *
  282. * \~english
  283. * Disable water mark feature
  284. *
  285. */
  286. - (void)clearVideoWatermark;
  287. #pragma mark - EM_DEPRECATED_IOS 3.5.2
  288. /*!
  289. * \~chinese
  290. * 自定义本地视频数据
  291. *
  292. * @param aSampleBuffer 视频采样缓冲区
  293. * @param aCallId 1v1会话实例ID,即[EMCallSession callId]
  294. * @param aFormat 视频格式
  295. * @param aRotation 旋转角度0~360,默认0
  296. * @param aCompletionBlock 完成后的回调
  297. *
  298. * \~english
  299. * Customize local video data
  300. *
  301. * @param aSampleBuffer Video sample buffer
  302. * @param aCallId [EMCallSession callId]
  303. * @param aFormat Video format
  304. * @param aRotation Rotation angle 0~360, default 0
  305. * @param aCompletionBlock The callback block of completion
  306. */
  307. - (void)inputVideoSampleBuffer:(CMSampleBufferRef)aSampleBuffer
  308. callId:(NSString *)aCallId
  309. format:(EMCallVideoFormat)aFormat
  310. rotation:(int)aRotation
  311. completion:(void (^)(EMError *aError))aCompletionBlock EM_DEPRECATED_IOS(3_2_2, 3_5_2, "Delete, Use -inputVideoSampleBuffer:rotation:callId:completion:");
  312. /*!
  313. * \~chinese
  314. * 自定义本地视频数据
  315. *
  316. * @param aPixelBuffer 视频像素缓冲区
  317. * @param aCallId 1v1会话实例ID,即[EMCallSession callId]
  318. * @param aFormat 视频格式
  319. * @param aRotation 旋转角度0~360,默认0
  320. * @param aCompletionBlock 完成后的回调
  321. *
  322. * \~english
  323. * Customize local video data
  324. *
  325. * @param aPixelBuffer Video pixel buffer
  326. * @param aCallId [EMCallSession callId]
  327. * @param aFormat Video format
  328. * @param aRotation Rotation angle 0~360, default 0
  329. * @param aCompletionBlock The callback block of completion
  330. */
  331. - (void)inputVideoPixelBuffer:(CVPixelBufferRef)aPixelBuffer
  332. callId:(NSString *)aCallId
  333. format:(EMCallVideoFormat)aFormat
  334. rotation:(int)aRotation
  335. completion:(void (^)(EMError *aError))aCompletionBlock EM_DEPRECATED_IOS(3_2_2, 3_5_2, "Delete, Use -inputVideoPixelBuffer:sampleBufferTime:rotation:callId:completion:");
  336. /*!
  337. * \~chinese
  338. * 自定义本地视频数据
  339. *
  340. * @param aData 视频数据
  341. * @param aCallId 1v1会话实例ID,即[EMCallSession callId]
  342. * @param aWidth 宽度
  343. * @param aHeight 高度
  344. * @param aFormat 视频格式
  345. * @param aRotation 旋转角度0~360,默认0
  346. * @param aCompletionBlock 完成后的回调
  347. *
  348. * \~english
  349. * Customize local video data
  350. *
  351. * @param aData Video data
  352. * @param aCallId [EMCallSession callId]
  353. * @param aWidth Width
  354. * @param aHeight Height
  355. * @param aFormat Video format
  356. * @param aRotation Rotation angle 0~360, default 0
  357. * @param aCompletionBlock The callback block of completion
  358. */
  359. - (void)inputVideoData:(NSData *)aData
  360. callId:(NSString *)aCallId
  361. widthInPixels:(size_t)aWidth
  362. heightInPixels:(size_t)aHeight
  363. format:(EMCallVideoFormat)aFormat
  364. rotation:(int)aRotation
  365. completion:(void (^)(EMError *aError))aCompletionBlock EM_DEPRECATED_IOS(3_2_2, 3_5_2, "Delete");
  366. #pragma mark - EM_DEPRECATED_IOS 3.2.1
  367. /*!
  368. * \~chinese
  369. * 发起语音会话
  370. *
  371. * @param aUsername 被呼叫的用户(不能与自己通话)
  372. * @param aCompletionBlock 完成的回调
  373. *
  374. * \~english
  375. * Start a voice call
  376. *
  377. * @param aUsername The callee
  378. * @param aCompletionBlock The callback of completion
  379. *
  380. */
  381. - (void)startVoiceCall:(NSString *)aUsername
  382. completion:(void (^)(EMCallSession *aCallSession, EMError *aError))aCompletionBlock EM_DEPRECATED_IOS(3_1_0, 3_2_0, "Use -[IEMCallManager startCall:remoteName:ext:completion:]");
  383. /*!
  384. * \~chinese
  385. * 发起视频会话
  386. *
  387. * @param aUsername 被呼叫的用户(不能与自己通话)
  388. * @param aCompletionBlock 完成的回调
  389. *
  390. * \~english
  391. * Start a video call
  392. *
  393. * @param aUsername The callee
  394. * @param aSuccessBlock The callback block of completion
  395. *
  396. */
  397. - (void)startVideoCall:(NSString *)aUsername
  398. completion:(void (^)(EMCallSession *aCallSession, EMError *aError))aCompletionBlock EM_DEPRECATED_IOS(3_1_0, 3_2_0, "Use -[IEMCallManager startCall:remoteName:ext:completion:]");
  399. @end