|
@@ -8,18 +8,267 @@
|
|
#import "webRtcPlayerViewController.h"
|
|
#import "webRtcPlayerViewController.h"
|
|
#import <WebRTC/AMediaStream.h>
|
|
#import <WebRTC/AMediaStream.h>
|
|
#import <WebRTC/RTCMacros.h>
|
|
#import <WebRTC/RTCMacros.h>
|
|
|
|
+#import "UIView+View.h"
|
|
|
|
|
|
-@interface webRtcPlayerViewController ()
|
|
|
|
-
|
|
|
|
|
|
+@interface webRtcPlayerViewController ()<MediaStreamClientEventsDelegate>
|
|
|
|
+@property (nonatomic, strong) AMediaStream *mediaStream;
|
|
|
|
+@property(nonatomic,strong)UIButton *controlBtn;
|
|
@end
|
|
@end
|
|
|
|
|
|
@implementation webRtcPlayerViewController
|
|
@implementation webRtcPlayerViewController
|
|
|
|
+@synthesize controlBtn;
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
// Do any additional setup after loading the view.
|
|
|
|
+
|
|
|
|
+ [self.toolBar setHidden:YES];
|
|
|
|
+ [self.navigationBar setHidden:YES];
|
|
|
|
+ [self.navBarBGView setHidden:YES];
|
|
|
|
+ [self.view setBackgroundColor:[UIColor blackColor]];
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (void)viewDidDisappear:(BOOL)animated{
|
|
|
|
+ [super viewDidDisappear:animated];
|
|
|
|
+
|
|
|
|
+ [_mediaStream disconnect];
|
|
|
|
+}
|
|
|
|
|
|
|
|
+- (void)setWebRtcMsgMod:(webRtcMsgModel *)webRtcMsgMod
|
|
|
|
+{
|
|
|
|
+ _webRtcMsgMod = webRtcMsgMod;
|
|
|
|
+ [self beginWebRtcPlayFun];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#pragma mark 开始拉流
|
|
|
|
+- (void)beginWebRtcPlayFun
|
|
|
|
+{
|
|
|
|
+ _mediaStream = [[RTC_OBJC_TYPE(AMediaStream) alloc] initWithFrame:CGRectZero];
|
|
|
|
+ [_mediaStream setEventDelegate:self];
|
|
|
|
+ [self.view addSubview:_mediaStream];
|
|
|
|
+
|
|
|
|
+ [_mediaStream mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.left.mas_equalTo(0.f);
|
|
|
|
+ make.bottom.mas_equalTo(0.f);
|
|
|
|
+ make.right.mas_equalTo(0.f);
|
|
|
|
+ make.top.mas_equalTo(0.f);
|
|
|
|
+ }];
|
|
|
|
+
|
|
|
|
+ //链接用
|
|
|
|
+ NSString *signallingUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.signalling.domainName,_webRtcMsgMod.data.signalling.port];
|
|
|
|
+ NSURL *url = [NSURL URLWithString:signallingUrl];
|
|
|
|
+
|
|
|
|
+ //ice用
|
|
|
|
+ NSString *iceUrl = [[NSString alloc] initWithFormat:@"%@:%@",_webRtcMsgMod.data.turn.domainName,_webRtcMsgMod.data.turn.port];
|
|
|
|
+
|
|
|
|
+ NSMutableDictionary *ice = [NSMutableDictionary new];
|
|
|
|
+ if(iceUrl){
|
|
|
|
+ [ice setValue:iceUrl forKey:@"CHINANET"];
|
|
|
|
+ [ice setValue:iceUrl forKey:@"CMNET"];
|
|
|
|
+ [ice setValue:iceUrl forKey:@"UNICOM"];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ NSString *roomName = _webRtcMsgMod.data.uniqueIdentifier;
|
|
|
|
+
|
|
|
|
+ NSInteger result = [_mediaStream start:url
|
|
|
|
+ ice:ice
|
|
|
|
+ sn:roomName
|
|
|
|
+ direct:0
|
|
|
|
+ fmt:1//1(h264) 5(h265)
|
|
|
|
+ videoWidth:1080.0
|
|
|
|
+ videoHeight:1920.0
|
|
|
|
+ fps:30
|
|
|
|
+ bitrate:3000
|
|
|
|
+ cardWidth:0
|
|
|
|
+ cardHeight:0
|
|
|
|
+ cardDensity:0
|
|
|
|
+ token:@"vclusters"];
|
|
|
|
+
|
|
|
|
+ HLog(@"result:%ld",result)
|
|
|
|
+
|
|
|
|
+ CGFloat curRate = 1080.0/1920.0;
|
|
|
|
+ [self setPoMas_makeWithImageRate:curRate];
|
|
|
|
+ [self showNewIndicatorWithCanBack:YES canTouch:NO];
|
|
|
|
+
|
|
|
|
+ [self initBaseUIFun];
|
|
|
|
+}
|
|
|
|
|
|
|
|
+#pragma mark 初始化其他UI
|
|
|
|
+- (void)initBaseUIFun
|
|
|
|
+{
|
|
|
|
+ /*控制按钮*/
|
|
|
|
+ UIImage *driftBtnImage = [UIImage imageNamed:@"you_icon"];
|
|
|
|
+ controlBtn = [[UIButton alloc] init];
|
|
|
|
+ [controlBtn setBackgroundColor:[UIColor clearColor]];
|
|
|
|
+ [controlBtn setBackgroundImage:driftBtnImage forState:(UIControlStateNormal)];
|
|
|
|
+ [controlBtn addTarget:self
|
|
|
|
+ action:@selector(controlBtnPressed:)
|
|
|
|
+ forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
|
+
|
|
|
|
+ [self.view addSubview:controlBtn];
|
|
|
|
+ [self initPointForControlBtnFun];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#pragma mark 设置 controlBtn 的初始位置
|
|
|
|
+- (void)initPointForControlBtnFun
|
|
|
|
+{
|
|
|
|
+ CGFloat h_w_controlBtn = 60.f;
|
|
|
|
+ /*区分横竖屏*/
|
|
|
|
+ if (_mediaStream.width > _mediaStream.height){
|
|
|
|
+ [controlBtn setFrame:CGRectMake((_mediaStream.width - h_w_controlBtn)/2.f, _mediaStream.height - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
|
|
|
|
+ }else{
|
|
|
|
+ //默认居右
|
|
|
|
+ //[mPlayerView.controlBtn setFrame:CGRectMake(mPlayerView.width - h_w_controlBtn - 20.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
|
|
|
|
+
|
|
|
|
+ //默认居左
|
|
|
|
+ [controlBtn setFrame:CGRectMake( h_w_controlBtn + 10.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#pragma mark 控制按钮点击事件
|
|
|
|
+- (void)controlBtnPressed:(UIButton*)but
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#pragma mark WebRTC 回调 MediaStreamClientEventsDelegate
|
|
|
|
+#pragma mark - 宽高变化
|
|
|
|
+-(void)onFrameResolutionChangedFromPeerName:(NSString*)peerName videoWidth:(int)videoWidth videoHeight:(int)videoHeight rotation:(int)rotation {
|
|
|
|
+ HLog(@"peerName:%@---%d---%d--%d",peerName,videoWidth,videoHeight,rotation)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//code 0 成功 1失败
|
|
|
|
+-(void)onAuthResultFromPeerName:(NSString*)peerName code:(int)code descriptions:(NSString*)descriptions
|
|
|
|
+{
|
|
|
|
+ HLog(@"onAuthResultFromPeerName:%@---%d---%@",peerName,code,descriptions)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)dataChannelDidChangeFromPeerName:(NSString*)peerName State:(RTCDataChannelState)state{
|
|
|
|
+ ;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+-(void)onIceConnectedFromPeerName:(NSString*)peerName{
|
|
|
|
+ HLog(@"onIceConnectedFromPeerName:%@",peerName);
|
|
|
|
+ mainBlock(^{
|
|
|
|
+ [self removeNewIndicator];
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+-(void)didGetStats:(NSString*)peerName stats:(RTC_OBJC_TYPE(RTCStatisticsReport) *)stats {
|
|
|
|
+ HLog(@"stats:%@",stats);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)setPoMas_makeWithImageRate:(CGFloat)w_h_rate{
|
|
|
|
+ /*播放视图*/
|
|
|
|
+// touchCommondView.isLan = NO;
|
|
|
|
+ BOOL fullScreenShow = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
|
|
|
|
+
|
|
|
|
+ [_mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ CGFloat scr_W = SCREEN_W;
|
|
|
|
+ CGFloat scr_H = SCREEN_H;
|
|
|
|
+ if (SCREEN_W > SCREEN_H){
|
|
|
|
+ scr_W = SCREEN_H;
|
|
|
|
+ scr_H = SCREEN_W;
|
|
|
|
+ }
|
|
|
|
+ if ((scr_H - scr_W/w_h_rate - 40.f)/2.f < 0){
|
|
|
|
+ if(fullScreenShow){
|
|
|
|
+ make.height.mas_equalTo(scr_H);
|
|
|
|
+ make.width.mas_equalTo(scr_W);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ make.height.mas_equalTo(scr_H - 40.f);
|
|
|
|
+ make.width.mas_equalTo((scr_H - 40.f)*w_h_rate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ make.centerX.equalTo(self.view.mas_centerX);
|
|
|
|
+ make.top.mas_equalTo(0);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ make.left.mas_equalTo(0.f);
|
|
|
|
+ make.right.mas_equalTo(0.f);
|
|
|
|
+ if(fullScreenShow){
|
|
|
|
+ make.height.mas_equalTo(scr_H);
|
|
|
|
+ make.top.mas_equalTo(0.f);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ make.height.mas_equalTo(scr_W/w_h_rate);
|
|
|
|
+ make.top.mas_equalTo((scr_H - scr_W/w_h_rate - 40.f)/2.f);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// [bottomContrView setHidden:NO];
|
|
|
|
+// [bottomContrView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+// make.height.mas_equalTo(40.f);
|
|
|
|
+// make.right.equalTo(touchCommondView.mas_right);
|
|
|
|
+// if(fullScreenShow){
|
|
|
|
+// make.bottom.mas_equalTo(0);
|
|
|
|
+// }
|
|
|
|
+// else{
|
|
|
|
+// make.top.equalTo(touchCommondView.mas_bottom);
|
|
|
|
+// }
|
|
|
|
+// make.left.equalTo(touchCommondView.mas_left);
|
|
|
|
+// }];
|
|
|
|
+//
|
|
|
|
+// [mueBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+// make.right.mas_equalTo(-80.f);
|
|
|
|
+// make.width.and.height.mas_equalTo(40.f);
|
|
|
|
+// make.top.mas_equalTo(0);
|
|
|
|
+//
|
|
|
|
+// }];
|
|
|
|
+//
|
|
|
|
+// [homeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+// make.centerX.equalTo(bottomContrView.mas_centerX);
|
|
|
|
+// make.width.and.height.mas_equalTo(40.f);
|
|
|
|
+// make.top.mas_equalTo(0);
|
|
|
|
+// }];
|
|
|
|
+//
|
|
|
|
+// UIImage *backBtnImage = [UIImage imageNamed:@"fanhui_you_icon"];
|
|
|
|
+//// UIImage *backBtnImage = [UIImage imageNamed:@"fanhui_icon"];
|
|
|
|
+// [backBtn setImage:backBtnImage forState:(UIControlStateNormal)];
|
|
|
|
+// [backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+// make.left.mas_equalTo(80.f);
|
|
|
|
+// make.width.and.height.mas_equalTo(40.f);
|
|
|
|
+// make.top.mas_equalTo(0);
|
|
|
|
+// }];
|
|
|
|
+//
|
|
|
|
+// [showHomeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+// make.right.mas_equalTo(-20.f);
|
|
|
|
+// make.width.and.height.mas_equalTo(40.f);
|
|
|
|
+// make.top.mas_equalTo(0);
|
|
|
|
+// }];
|
|
|
|
+//
|
|
|
|
+// [self getPlayerBottomNavShowOrHidefun];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @brief 设置横屏模式UI布局
|
|
|
|
+ *
|
|
|
|
+ * @param w_h_rate 宽高比
|
|
|
|
+
|
|
|
|
+ */
|
|
|
|
+- (void)setLanMas_makeWithImageRate:(CGFloat)w_h_rate{
|
|
|
|
+ /*需要考虑专业模式*/
|
|
|
|
+
|
|
|
|
+ /*暂时只考虑非专业模式无虚拟键布局*/
|
|
|
|
+ CGFloat h_forPhoneTop = 0;
|
|
|
|
+ if (IPHONE_X){
|
|
|
|
+ h_forPhoneTop = 44.f;
|
|
|
|
+ }
|
|
|
|
+ CGFloat des_W = SCREEN_W<SCREEN_H?SCREEN_W:SCREEN_H;/*实际较小的数字*/
|
|
|
|
+ CGFloat des_H = (SCREEN_W>SCREEN_H?SCREEN_W:SCREEN_H) - h_forPhoneTop;/*实际较大的数字*/
|
|
|
|
+ [_mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
+ make.bottom.mas_equalTo(0.f);
|
|
|
|
+ make.width.mas_equalTo(des_W*w_h_rate);
|
|
|
|
+ make.left.mas_equalTo(h_forPhoneTop + (des_H - des_W*w_h_rate)/2.f);
|
|
|
|
+ make.top.mas_equalTo(0);
|
|
|
|
+ }];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
@end
|
|
@end
|