WebRTC オーディオおよびビデオ通話 - iOS 側通話 ossrs ライブ ストリーミング
iOS ターミナルを実装して ossrs サービスを呼び出す前に、記事ではストリーミングについて言及しました。ストリーミング処理は書いていないので、記事内のWebRTCClientを利用します。詳しくはこちらをご確認ください: https://blog.csdn.net/gloryFlow/article/details/132262724
1. iOSプレーヤーのストリーミング効果
2. ストリームをプルするための iOS 側の ossrs の呼び出しを実現します。
最近友人に質問されたのですが、以前ストリーミング処理が抜けていたことが分かりましたので、ここに追加させていただきます。
2.1. ストリームをプルするときに WebRTCClient を設定する
ストリームをプルするときに WebRTCClient を設定するときに初期化します。isPublish为false
ここでは
#pragma mark - Lazy
- (WebRTCClient *)webRTCClient {
if (!_webRTCClient) {
_webRTCClient = [[WebRTCClient alloc] initWithPublish:NO];
}
return _webRTCClient;
}
2.2. ストリーミング表示の画面ビューを設定します。
前回の記事のカメラ画面表示ではstartCaptureLocalVideoを使用していますが、ストリーミングの設定が必要ですremoteRenderView
WebRTCClient には次の定義があります。
/**
RTCVideoRenderer
*/
@property (nonatomic, weak) id<RTCVideoRenderer> remoteRenderView;
ストリーミング表示の画面表示を設定する
#import "RTCPlayView.h"
@interface RTCPlayView ()
@property (nonatomic, strong) WebRTCClient *webRTCClient;
@property (nonatomic, strong) RTCEAGLVideoView *remoteRenderer;
@end
@implementation RTCPlayView
- (instancetype)initWithFrame:(CGRect)frame webRTCClient:(WebRTCClient *)webRTCClient {
self = [super initWithFrame:frame];
if (self) {
self.webRTCClient = webRTCClient;
self.remoteRenderer = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero];
self.remoteRenderer.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:self.remoteRenderer];
self.webRTCClient.remoteRenderView = self.remoteRenderer;
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.remoteRenderer.frame = self.bounds;
NSLog(@"self.remoteRenderer frame:%@", NSStringFromCGRect(self.remoteRenderer.frame));
}
@end
ここで使用するRTCEAGLVideoViewを作成し、設定self.webRTCClient.remoteRenderView为self.remoteRenderer
2.3. ossrs サービス play を呼び出します。インターフェイスは rtc/v1/play/ です。
プル フロー呼び出しの実装プロセスはプッシュ フローのプロセスと似ているため、ここでは説明しません。https: //blog.csdn.net/gloryFlow/article/details/132262724を参照してください。
具体的な方法は以下の通りです
- (void)playBtnClick {
__weak typeof(self) weakSelf = self;
[self.webRTCClient offer:^(RTCSessionDescription *sdp) {
[weakSelf.webRTCClient changeSDP2Server:sdp urlStr:@"https://192.168.10.102:1990/rtc/v1/play/" streamUrl:@"webrtc://192.168.10.102:1990/live/livestream" closure:^(BOOL isServerRetSuc) {
NSLog(@"isServerRetSuc:%@",(isServerRetSuc?@"YES":@"NO"));
}];
}];
}
完全なコントローラー コードは次のとおりです。
#import "RTCPlayViewController.h"
@interface RTCPlayViewController ()<WebRTCClientDelegate>
@property (nonatomic, strong) WebRTCClient *webRTCClient;
@property (nonatomic, strong) RTCPlayView *rtcPlayView;
@property (nonatomic, strong) UIButton *playBtn;
@end
@implementation RTCPlayViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.rtcPlayView = [[RTCPlayView alloc] initWithFrame:CGRectZero webRTCClient:self.webRTCClient];
[self.view addSubview: self.rtcPlayView];
self.rtcPlayView.backgroundColor = [UIColor lightGrayColor];
self.rtcPlayView.frame = self.view.bounds;
CGFloat screenWidth = CGRectGetWidth(self.view.bounds);
CGFloat screenHeight = CGRectGetHeight(self.view.bounds);
self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.playBtn.frame = CGRectMake(50, screenHeight - 160, screenWidth - 2*50, 46);
self.playBtn.layer.cornerRadius = 4;
self.playBtn.backgroundColor = [UIColor grayColor];
[self.playBtn setTitle:@"publish" forState:UIControlStateNormal];
[self.playBtn addTarget:self action:@selector(playBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.playBtn];
self.webRTCClient.delegate = self;
}
- (void)playBtnClick {
__weak typeof(self) weakSelf = self;
[self.webRTCClient offer:^(RTCSessionDescription *sdp) {
[weakSelf.webRTCClient changeSDP2Server:sdp urlStr:@"https://192.168.10.102:1990/rtc/v1/play/" streamUrl:@"webrtc://192.168.10.102:1990/live/livestream" closure:^(BOOL isServerRetSuc) {
NSLog(@"isServerRetSuc:%@",(isServerRetSuc?@"YES":@"NO"));
}];
}];
}
#pragma mark - WebRTCClientDelegate
- (void)webRTCClient:(WebRTCClient *)client didDiscoverLocalCandidate:(RTCIceCandidate *)candidate {
NSLog(@"webRTCClient didDiscoverLocalCandidate");
}
- (void)webRTCClient:(WebRTCClient *)client didChangeConnectionState:(RTCIceConnectionState)state {
NSLog(@"webRTCClient didChangeConnectionState");
/**
RTCIceConnectionStateNew,
RTCIceConnectionStateChecking,
RTCIceConnectionStateConnected,
RTCIceConnectionStateCompleted,
RTCIceConnectionStateFailed,
RTCIceConnectionStateDisconnected,
RTCIceConnectionStateClosed,
RTCIceConnectionStateCount,
*/
UIColor *textColor = [UIColor blackColor];
BOOL openSpeak = NO;
switch (state) {
case RTCIceConnectionStateCompleted:
case RTCIceConnectionStateConnected:
textColor = [UIColor greenColor];
openSpeak = YES;
break;
case RTCIceConnectionStateDisconnected:
textColor = [UIColor orangeColor];
break;
case RTCIceConnectionStateFailed:
case RTCIceConnectionStateClosed:
textColor = [UIColor redColor];
break;
case RTCIceConnectionStateNew:
case RTCIceConnectionStateChecking:
case RTCIceConnectionStateCount:
textColor = [UIColor blackColor];
break;
default:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
NSString *text = [NSString stringWithFormat:@"%ld", state];
[self.playBtn setTitle:text forState:UIControlStateNormal];
[self.playBtn setTitleColor:textColor forState:UIControlStateNormal];
if (openSpeak) {
[self.webRTCClient speakOn];
}
// if textColor == .green {
// self?.webRTCClient.speakerOn()
// }
});
}
- (void)webRTCClient:(WebRTCClient *)client didReceiveData:(NSData *)data {
NSLog(@"webRTCClient didReceiveData");
}
#pragma mark - Lazy
- (WebRTCClient *)webRTCClient {
if (!_webRTCClient) {
_webRTCClient = [[WebRTCClient alloc] initWithPublish:NO];
}
return _webRTCClient;
}
@end
これまでのところ、iOS 側からの ossrs ビデオ通話ストリーミングが実現できています
その他
ossrs サービスを設定する前に、次を確認できます: https://blog.csdn.net/gloryFlow/article/details/132257196
ossrs の音声通話とビデオ通話を呼び出すために iOS を実装する前に、次を確認できます: https://blog. csdn.net/gloryFlow /article/details/132262724
WebRTC オーディオおよびビデオ通話で高解像度の画像が表示されない前に、次のことを確認できます。https://blog.csdn.net/gloryFlow/article/details/132240952
ビット レートを変更するSDP では、https: //blog.csdn.net/gloryFlow/article/details/132263021を確認できます。GPUImage ビデオ通話ビデオビューティー フィルターは、https: //blog.csdn.net/gloryFlow/article/details
で確認できます。/132265842
RTC ライブ ローカル ビデオまたはアルバム ビデオを表示できます: https://blog.csdn.net/gloryFlow/article/details/132267068
3. まとめ
WebRTC オーディオおよびビデオ通話 - iOS 側が ossrs ライブ ストリーミングを呼び出します。WebRTC は、プッシュプル ストリーミング効果を実現するために ossrs を呼び出すために使用されます。内容が多く、不正確な記述があるかもしれませんが、ご容赦ください。
https://blog.csdn.net/gloryFlow/article/details/132417602
学習記録、日々改善を続けてください。