全部产品
云市场
云游戏

iOS 进阶功能

更新时间:2020-06-18 10:04:03

渲染 View 相关

实现 ARTVCEngineDelegate 中部分和渲染相关的回调接口。

  1. 渲染 View 对象被创建。
    1. //渲染 View 对象被创建,同时 feed 相关联,业务收到此回调时可将此 view 加入到布局中,//并设置其 frame。
    2. -(void)didVideoRenderViewInitialized:(UIView*)renderView forFeed:(ARTVCFeed*)feed{
    3. }
  2. 渲染首帧视频。
    1. -(void)didFirstVideoFrameRendered:(UIView*)renderView forFeed:(ARTVCFeed*)feed{
    2. }
  3. 停止渲染视频。
    1. -(void)didVideoViewRenderStopped:(UIView*)renderView forFeed:(ARTVCFeed*)feed{
    2. }

统一错误处理

  • 所有错误。通过统计的错误回调接口回调业务,业务根据不同的错误码,进行相应的错误处理。
    1. -(void)didEncounterError:(NSError *)error forFeed:(ARTVCFeed*)feed{
    2. //业务根据不同错误码,进行错误处理。
    3. }
  • 错误定义如下:
    1. typedef NS_ENUM(int,ARTVCErrorCode){
    2. /**
    3. bad parameters passed to API
    4. */
    5. ARTVCErrorCodeBadParameters = - 103,
    6. /**
    7. camera permission is denied by user
    8. without this permission,video call cann't be continued,please advise user enable camera permission in settings.
    9. */
    10. ARTVCErrorCodeCameraPermissionNOtAllowed = -104,
    11. /**
    12. microphone permission is denied by user
    13. without this permission,video call cann't be continued,please advise user enable camera permission in settings.
    14. */
    15. ARTVCErrorCodeMicrophonePermissionNOtAllowed = -105,
    16. /**
    17. timeout happened,publish/subscribe cann't be finishied successfully
    18. */
    19. ARTVCErrorCodeTimeout = -108,
    20. /**
    21. you has already published or subsrcibed a feed .
    22. you cann't publish or subsrcibe the same feed once again when it has NOt been unpublished or unsubscribed.
    23. */
    24. ARTVCErrorCodeAlreadyPublishedOrSubsrcibed = -111,
    25. /**
    26. you has NOt published or subsrcibed the feed .so you cann't do unpublish or unsubscribe operation.
    27. */
    28. ARTVCErrorCodeFeedHasNOtBeenPublishedOrSubsrcibed = -119,
    29. /**
    30. internal webrtc-relative error when doing publish/subscribe,for example,setting sdp failed,creating sdp failed,e.g.
    31. */
    32. ARTVCErrorCodeInternalError = -113,
    33. /**
    34. * current room has become invalid .most of all,it's because network's down,heartbeat abNOrmal.
    35. * if you wanna continue,you MUST call createRoom again to get a new valid room.
    36. */
    37. ARTVCErrorCodeCurrentRoomHasBecomeInvalid = -114,
    38. /**
    39. server error hanppened.CreateRoom request failed,it's a server internal error.
    40. */
    41. ARTVCErrorCodeProtocolErrorCreateRoomFailed = -115,
    42. /**
    43. server error hanppened.JoinRoom request failed,it's a server internal error.maybe the room you joined has been became invalid yet.
    44. */
    45. ARTVCErrorCodeProtocolErrorJoinRoomFailed = -116,
    46. /**
    47. server error hanppened.Publish request failed,it's a server internal error.
    48. */
    49. ARTVCErrorCodeProtocolErrorPublishFailed = -117,
    50. /**
    51. server error hanppened.Subscribe request failed,it's a server internal error.maybe the stream you subscribed has been unpunlished yet or some error else.
    52. */
    53. ARTVCErrorCodeProtocolErrorSubscribeFailed = -118,
    54. };

切换摄像头

  1. [_artvcEgnie switchCamera];

mute 远端视频

  1. ARTVCFeed* feed = mute 操作的远端 feed;
  2. [_artvcEgnie muteRemoteVideo:YES forFeed:feed];

麦克风静音

  1. [_artvcEgnie muteMicrophone:YES];

mute 远端音频

  1. ARTVCFeed* feed = mute 操作的远端 feed;
  2. [_artvcEgnie muteRemoteAudio:YES forFeed:feed];

听筒扬声器模式

  • 切换模式
    1. [_artvcEgnie switchAudioPlayModeTo:ARTVCAudioPlayModeReceiver complete:nil];
  • 变化通知

    1. -(void)didAudioPlayModeChangedTo:(ARTVCAudioPlayMode)audioPlayMode{
    2. NSString *toast = nil;
    3. switch (audioPlayMode) {
    4. case ARTVCAudioPlayModeSpeaker:{
    5. toast = @"扬声器模式";
    6. }
    7. break;
    8. case ARTVCAudioPlayModeReceiver:{
    9. toast = @"听筒模式";
    10. }
    11. break;
    12. case ARTVCAudioPlayModeHeadphone:{
    13. toast = @"耳机模式";
    14. }
    15. break;
    16. case ARTVCAudioPlayModeBluetooth:{
    17. toast = @"蓝牙设备模式";
    18. }
    19. break;
    20. case ARTVCAudioPlayModeInit:{
    21. toast = @"未知模式";
    22. }
    23. break;
    24. }
    25. [self showToastWith:toast duration:2.0];
    26. }

网络变化通知

对于移动网络,业务可做弹窗提示用户有流量风险。

  1. -(void)didNetworkChangedTo:(APMNetworkReachabilityStatus)netStatus{
  2. if(netStatus == APMNetReachabilityStatusReachableViaWiFi){
  3. return ;
  4. }
  5. [self showToastWith:[NSString stringWithFormat:@"网络切换到:%@",[APMNetworkStatusManager stringOfNetworkStatus:netStatus]] duration:2.0];
  6. }

带宽不足通知

  1. -(void)didAvailabeSendBandwidthBecomeLow:(BOOL)isLow currentBandwidth:(double)bw forFeed:(ARTVCFeed*)feed{
  2. if(isLow){
  3. [self showToastWith:@"当前通话质量不佳" duration:2.0];
  4. }
  5. }

截屏功能

可对任意流进行截屏。

  1. ARTVCFeed* feed = 要截屏的feed;
  2. [_artvcEgnie snapshotForFeed:feed complete:^(UIImage* image){
  3. //根据需要对截屏图片进行处理
  4. }];

获取通话质量的 Debug 信息

通过回调来返回任意流的 Debug 信息。

  1. /**
  2. brief debug information is generated(including bitrate/cpu/codec,e.g.),you can show this on your debug information view.
  3. */
  4. - (void)didBriefDebugInformationGenerated:(NSString*)debugInfo forFeed:(ARTVCFeed*)feed{
  5. //如果有需要,可以将 debugInfo 按流展示在 debug 窗口。
  6. }

获取通话质量的实时监控信息

  • 通过回调可获取任意流的实时监控信息,包括码率、帧率、CPU 等。
    1. -(void)didRealtimeStatisticGenerated:(ARTVCRealtimeStatisticSummary*)summary forFeed:(ARTVCFeed*)feed{
    2. }
  • 返回的数据内容如下:
    1. @interface ARTVCRealtimeStatisticSummary : NSObject
    2. //connection stats googCandidatePair
    3. /** 实际总发码率 单位bps*/
    4. @property(NOnatomic,copy) NSString* totalSendBitrate;
    5. /** 实际总的收码率 单位bps*/
    6. @property(NOnatomic,copy) NSString* totalRecvBitrate;
    7. /** 网络延迟(毫秒)*/
    8. /** 网络延迟(毫秒)*/
    9. @property(NOnatomic,copy) NSString* rtt;
    10. //video send
    11. /** 视频码率发 单位bps*/
    12. @property(NOnatomic,copy) NSString* videoSendBitrate;
    13. /** 实际视频发帧率 */
    14. @property(NOnatomic,copy) NSString* videoSendFps;
    15. //video recv
    16. /** 视频码率收 单位bps*/
    17. @property(NOnatomic,copy) NSString* videoRecvBitrate;
    18. /** 实际视频收帧率 */
    19. @property(NOnatomic,copy) NSString* videoRecvFps;
    20. /** 声音码率发 单位bps*/
    21. @property(NOnatomic,copy) NSString* audioSendBitrate;
    22. /** 声音码率收 单位bps*/
    23. @property(NOnatomic,copy) NSString* audioRecvBitrate;
    24. /** 视频发送丢包率*/
    25. @property(NOnatomic,copy) NSString* videoLossRate;
    26. //audio send
    27. /** 音频发送丢包率*/
    28. @property(NOnatomic,copy) NSString* audioLossRate;
    29. /** cpu */
    30. @property(NOnatomic,copy) NSString* cpu;
    31. @end

通话过程中动态调整编码分辨率和相机 FPS(仅使用于内置 camera)

  • 当前分辨率以及 FPS 分别为 640x360、15FPS 时,设置如下:
    1. _artvcEgnine.videoProfileType = ARTVCVideoProfileType_640x360_15Fps;
  • 假设,因业务需求需要将分辨率以及 FPS 临时调高至 960x540、30FPS,设置如下:
    1. _artvcEgnine.videoProfileType = ARTVCVideoProfileType_960x540_30Fps;
  • 处理完特定业务需求后,恢复至 640x360,15FPS。
    1. _artvcEgnine.videoProfileType = ARTVCVideoProfileType_640x360_15Fps;

通话过程中动态调整编码分辨率(适应于所有 video source)

  • 自定义推流中,当前分辨率为 640x360,若因业务需求需要临时调高至 960x540,设置如下:
    1. [ _artvcEgnine changeVideoProfileTo:ARTVCVideoProfileType_960x540_15Fps forVideoSource:ARTVCVideoSourceType_Custom];
  • 内置 camera,当前分辨率为 640x360,若因业务需求需要临时调高至 960x540,设置如下:
    1. [ _artvcEgnine changeVideoProfileTo:ARTVCVideoProfileType_960x540_30Fps forVideoSource:ARTVCVideoSourceType_Camera];

自定义推视频流

自定义推视频流约束

  • 只支持 NV12 格式的视频帧,以 CVPixelBufferRef 格式输入.
  • 调用方目前需要保证 FPS,按照一定的 FPS 来输入。建议使用 15-24FPS。
  • 只支持手动模式推流。

自定义推视频流流程

  1. //自定义推流中,必须设置为手动推流模式
  2. [ _artvcEgnine setAutoPublish:NO];
  3. //创建一个自定义推流类
  4. ARTVCCreateCustomVideoCaputurerParams* params = [[ARTVCCreateCustomVideoCaputurerParams alloc] init];
  5. //如果需要SDK帮忙渲染,需要设置provideRenderView为YES,SDK默认不帮业务渲染。
  6. params.provideRenderView = YES;
  7. self.customCapturer = [_artvcEgnine createCustomVideoCapturer:params];
  8. //按照一定的频率喂数据给SDK,格式是CVPixelBufferRef,只支持NV12格式。
  9. [self.customCapturer provideCustomVideoFramePeriodlyWith:CVPixelBufferRef];
  10. //主动调用推流
  11. ARTVCPublishConfig* config = [[ARTVCPublishConfig alloc] init];
  12. config.videoSource = ARTVCVideoSourceType_Custom;
  13. config.videoProfile = ARTVCVideoProfileType_640x360_15Fps;
  14. self.customPublishConfig = config;
  15. [_artvcEgnine publish:config];

屏幕共享

  1. //必须设置为手动推流模式
  2. [ _artvcEgnine setAutoPublish:NO];
  3. //开始屏幕共享
  4. -(void)startScreenSharing{
  5. NSLog(@"start screen sharing");
  6. ARTVCCreateScreenCaputurerParams* screenParams = [[ARTVCCreateScreenCaputurerParams alloc] init];
  7. screenParams.provideRenderView = YES;
  8. [_artvcEgnine startScreenCaptureWithParams:screenParams complete:^(NSError* error){
  9. NSLog(@"start screen sharing finish,error:%@",error);
  10. if(error){
  11. //这里的code 见 2.15.1章节
  12. }else{
  13. //屏幕捕捉成功后再调用publish进行推流
  14. ARTVCPublishConfig* config = [[ARTVCPublishConfig alloc] init];
  15. config.videoSource = ARTVCVideoSourceType_Screen;
  16. config.audioEnable = NO;
  17. config.videoProfile = ARTVCVideoProfileType_1280x720_30Fps;
  18. [_artvcEgnine publish:config];
  19. }
  20. }];
  21. }
  22. //停止屏幕共享
  23. -(void)stopScreenSharing{
  24. NSLog(@"stop screen sharing");
  25. //停止屏幕捕捉
  26. [_artvcEgnine stopScreenCapture];
  27. //取消发布屏幕共享流
  28. ARTVCUnpublishConfig* config = [[ARTVCUnpublishConfig alloc] init];
  29. config.feed = self.screenLocalFeed;
  30. [_artvcEgnine unpublish:config];
  31. }

启动屏幕捕捉的错误码

  1. /**
  2. screen capture alrady under running, you cann't start it again before you call stop
  3. */
  4. ARTVCErrorCodeScreenCapturerAlreadyUnderRunning = -1011,
  5. /**
  6. starting screen capture failed
  7. */
  8. ARTVCErrorCodeStartScreenCaptureFailed = -1012,
  9. /**
  10. start screen capture success,but may be encounter errors during the processing of the capure operation.
  11. */
  12. ARTVCErrorCodeScreenCaptureFailedInProcessing = -1013,