8
8
9
9
#import " RoomViewController.h"
10
10
#import < QNRTCKit/QNRTCKit.h>
11
+
12
+ #warning 请到 Podifle 下,重新执行 pod install,确认 Pods/QNRTCKit-iOS/Pod/iphoneos 文件夹下,存在 FFmpeg.framework、QNRTCKit.framework 文件后可运行。
13
+
11
14
@interface RoomViewController ()
12
15
<
13
16
QNRTCClientDelegate,
14
- QNMicrophoneAudioTrackDataDelegate ,
15
- QNCameraTrackVideoDataDelegate ,
16
- QNRemoteTrackVideoDataDelegate ,
17
- QNRemoteTrackAudioDataDelegate
17
+ QNLocalAudioTrackDelegate ,
18
+ QNLocalVideoTrackDelegate ,
19
+ QNRemoteVideoTrackDelegate ,
20
+ QNRemoteAudioTrackDelegate
18
21
>
19
22
@property (nonatomic , assign ) CGFloat screenWidth;
20
23
@property (nonatomic , assign ) CGFloat screenHeight;
@@ -32,7 +35,7 @@ @interface RoomViewController ()
32
35
@property (nonatomic , strong ) QNMicrophoneAudioTrack *audioTrack;
33
36
@property (nonatomic , strong ) QNCameraVideoTrack *cameraTrack;
34
37
35
- @property (nonatomic , strong ) QNGLKView *preview;
38
+ @property (nonatomic , strong ) QNVideoGLView *preview;
36
39
@property (nonatomic , strong ) UIScrollView *scrollView;
37
40
@property (nonatomic , strong ) NSMutableArray *viewsArray;
38
41
@end
@@ -72,37 +75,38 @@ - (void)viewDidLoad {
72
75
#pragma mark - settings
73
76
74
77
- (NSDictionary *)settingsArrayAtIndex : (NSInteger )index {
75
- NSArray *settingsArray = @[@{@" VideoSize" :NSStringFromCGSize(CGSizeMake (288 , 352 )), @" FrameRate" :@15 , @" Bitrate" :@(300 * 1000 )},
76
- @{@" VideoSize" :NSStringFromCGSize(CGSizeMake (480 , 640 )), @" FrameRate" :@15 , @" Bitrate" :@(400 * 1000 ) },
77
- @{@" VideoSize" :NSStringFromCGSize(CGSizeMake (544 , 960 )), @" FrameRate" :@15 , @" Bitrate" :@(700 * 1000 )},
78
- @{@" VideoSize" :NSStringFromCGSize(CGSizeMake (720 , 1280 )), @" FrameRate" :@20 , @" Bitrate" :@(1000 * 1000 )}];
78
+ NSArray *settingsArray = @[@{@" VideoSize" :NSStringFromCGSize(CGSizeMake (288 , 352 )), @" FrameRate" :@15 , @" Bitrate" :@(300 )},
79
+ @{@" VideoSize" :NSStringFromCGSize(CGSizeMake (480 , 640 )), @" FrameRate" :@15 , @" Bitrate" :@(400 ) },
80
+ @{@" VideoSize" :NSStringFromCGSize(CGSizeMake (544 , 960 )), @" FrameRate" :@15 , @" Bitrate" :@(700 )},
81
+ @{@" VideoSize" :NSStringFromCGSize(CGSizeMake (720 , 1280 )), @" FrameRate" :@20 , @" Bitrate" :@(1000 )}];
79
82
return settingsArray[index];
80
83
}
81
84
82
85
#pragma mark - QNRTCKit 核心类
83
86
84
87
- (void )configureRTCEngine {
85
88
// QNRTC 初始化
86
- [QNRTC configRTC : [QNRTCConfiguration defaultConfiguration ]];
89
+ [QNRTC initRTC : [QNRTCConfiguration defaultConfiguration ]];
87
90
88
91
// QNRTCClient 初始化
89
92
self.rtcClient = [QNRTC createRTCClient ];
90
93
self.rtcClient .delegate = self;
91
94
92
95
// 设置本地预览视图 显示在排列第一个
93
- self.preview = [[QNGLKView alloc ] init ];
96
+ self.preview = [[QNVideoGLView alloc ] init ];
94
97
self.preview .frame = CGRectMake (0 , 0 , self.screenWidth /2 , self.screenHeight /2 );
95
98
[self .scrollView addSubview: self .preview];
96
99
97
100
// 视频
98
- QNCameraVideoTrackConfig * cameraConfig = [[QNCameraVideoTrackConfig alloc ] initWithSourceTag: @" camera" bitrate: self .kBitrate videoEncodeSize: self .videoEncodeSize];
101
+ QNVideoEncoderConfig *videoConfig = [[QNVideoEncoderConfig alloc ] initWithBitrate: self .kBitrate videoEncodeSize: self .videoEncodeSize];
102
+ QNCameraVideoTrackConfig * cameraConfig = [[QNCameraVideoTrackConfig alloc ] initWithSourceTag: @" camera" config: videoConfig];
99
103
self.cameraTrack = [QNRTC createCameraVideoTrackWithConfig: cameraConfig];
100
104
// 设置本地预览视图
101
105
[self .cameraTrack play: self .preview];
102
106
103
107
// 设置采集视频的帧率
104
108
self.cameraTrack .videoFrameRate = [self .settingsDic[@" FrameRate" ] integerValue ];
105
- self.cameraTrack .videoDelegate = self;
109
+ self.cameraTrack .delegate = self;
106
110
107
111
// 加入房间
108
112
[self .rtcClient join: self .token];
@@ -114,7 +118,7 @@ - (void)configureRTCEngine {
114
118
房间内状态变化的回调
115
119
*/
116
120
- (void )RTCClient : (QNRTCClient *)client didConnectionStateChanged : (QNConnectionState)state disconnectedInfo : (QNConnectionDisconnectedInfo *)info {
117
- NSDictionary *connectionStateDictionary = @{@(QNConnectionStateIdle ) : @" Idle " ,
121
+ NSDictionary *connectionStateDictionary = @{@(QNConnectionStateDisconnected ) : @" Disconnected " ,
118
122
@(QNConnectionStateConnecting) : @" Connecting" ,
119
123
@(QNConnectionStateConnected): @" Connected" ,
120
124
@(QNConnectionStateReconnecting) : @" Reconnecting" ,
@@ -127,7 +131,7 @@ - (void)RTCClient:(QNRTCClient *)client didConnectionStateChanged:(QNConnectionS
127
131
self.microphoneButton .selected = YES ;
128
132
// 音频
129
133
self.audioTrack = [QNRTC createMicrophoneAudioTrack ];
130
- self.audioTrack .audioDelegate = self;
134
+ self.audioTrack .delegate = self;
131
135
// [self.audioTrack setVolume:0.5];
132
136
133
137
// 发布音视频
@@ -142,7 +146,7 @@ - (void)RTCClient:(QNRTCClient *)client didConnectionStateChanged:(QNConnectionS
142
146
NSLog (@" publish error: %@ " ,error);
143
147
}
144
148
}];
145
- } else if (QNConnectionStateIdle == state) {
149
+ } else if (QNConnectionStateDisconnected == state) {
146
150
self.videoButton .enabled = NO ;
147
151
self.videoButton .selected = NO ;
148
152
} else if (QNConnectionStateReconnecting == state) {
@@ -175,11 +179,11 @@ - (void)RTCClient:(QNRTCClient *)client didSubscribedRemoteVideoTracks:(NSArray<
175
179
NSLog (@" didSubscribedRemoteTracks - %d ,%d userTd %@ " , audioTracks.count , videoTracks.count , userID);
176
180
dispatch_async (dispatch_get_main_queue (), ^{
177
181
for (QNRemoteAudioTrack * audioTrack in audioTracks) {
178
- audioTrack.audioDelegate = self;
182
+ audioTrack.delegate = self;
179
183
}
180
184
for (QNRemoteVideoTrack * videoTrack in videoTracks) {
181
185
[videoTrack play: [self remoteUserView: userID]];
182
- videoTrack.videoDelegate = self;
186
+ videoTrack.delegate = self;
183
187
}
184
188
});
185
189
@@ -217,25 +221,24 @@ - (void)RTCClient:(QNRTCClient *)client didReconnectedOfUserID:(NSString *)userI
217
221
NSLog (@" didReconnectedOfUserID - %@ " ,userID);
218
222
}
219
223
220
-
221
- #pragma mark - QNRemoteTrackVideoDataDelegate
224
+ #pragma mark - QNRemoteVideoTrackDelegate
222
225
- (void )remoteVideoTrack : (QNRemoteVideoTrack *)remoteVideoTrack didGetPixelBuffer : (CVPixelBufferRef)pixelBuffer {
223
226
NSLog (@" remoteVideoTrack: %@ tag: %@ didGetPixelBuffer" ,remoteVideoTrack.trackID ,remoteVideoTrack.tag );
224
227
}
225
228
226
- #pragma mark - QNRemoteTrackAudioDataDelegate
229
+ #pragma mark - QNRemoteAudioTrackDelegate
227
230
- (void )remoteAudioTrack : (QNRemoteAudioTrack *)remoteAudioTrack didGetAudioBuffer : (AudioBuffer *)audioBuffer bitsPerSample : (NSUInteger )bitsPerSample sampleRate : (NSUInteger )sampleRate {
228
231
NSLog (@" remoteAudioTrack: %@ tag: %@ didGetAudioBuffer" ,remoteAudioTrack.trackID ,remoteAudioTrack.tag );
229
232
}
230
233
231
- #pragma mark - QNCameraTrackVideoDataDelegate
232
- - (void )cameraVideoTrack : (QNCameraVideoTrack *)cameraVideoTrack didGetPixelBuffer : (CVPixelBufferRef)pixelBuffer {
234
+ #pragma mark - QNLocalVideoTrackDelegate
235
+ - (void )localVideoTrack : (QNLocalVideoTrack *)localVideoTrack didGetPixelBuffer : (CVPixelBufferRef)pixelBuffer {
233
236
// NSLog(@"cameraVideoTrack: %@ tag: %@ didGetPixelBuffer",cameraVideoTrack.trackID,track.tag);
234
237
235
238
}
236
239
237
- #pragma mark - QNMicrophoneAudioTrackDataDelegate
238
- - (void )microphoneAudioTrack : (QNMicrophoneAudioTrack *)microphoneAudioTrack didGetAudioBuffer : (AudioBuffer *)audioBuffer bitsPerSample : (NSUInteger )bitsPerSample sampleRate : (NSUInteger )sampleRate {
240
+ #pragma mark - QNLocalAudioTrackDelegate
241
+ - (void )localAudioTrack : (QNLocalAudioTrack *)localAudioTrack didGetAudioBuffer : (AudioBuffer *)audioBuffer bitsPerSample : (NSUInteger )bitsPerSample sampleRate : (NSUInteger )sampleRate {
239
242
// NSLog(@"microphoneAudioTrack: %@ tag: %@ didGetAudioBuffer",track.trackID,track.tag);
240
243
}
241
244
@@ -253,9 +256,9 @@ - (void)layoutScrollView {
253
256
#pragma mark - 远端用户画面
254
257
#warning 考虑多个远端排列显示
255
258
256
- - (QNVideoView *)remoteUserView : (NSString *)userId {
259
+ - (QNVideoGLView *)remoteUserView : (NSString *)userId {
257
260
NSInteger count = self.viewsArray .count + 1 ;
258
- QNVideoView *remoteView = [[QNVideoView alloc ] initWithFrame: CGRectMake (self .screenWidth/2 * (count%2 ), self .screenWidth/2 * (count/2 ), self .screenWidth/2 , self .screenWidth/2 )];
261
+ QNVideoGLView *remoteView = [[QNVideoGLView alloc ] initWithFrame: CGRectMake (self .screenWidth/2 * (count%2 ), self .screenWidth/2 * (count/2 ), self .screenWidth/2 , self .screenWidth/2 )];
259
262
[self .scrollView addSubview: remoteView];
260
263
261
264
UILabel *nameLabel = [[UILabel alloc ] initWithFrame: CGRectMake (0 , self .screenWidth/4 - 30 , self .screenWidth/2 , 60 )];
@@ -281,7 +284,7 @@ - (QNVideoView *)remoteUserView:(NSString *)userId {
281
284
- (void )removeRemoteRenderView : (NSString *)userId {
282
285
NSInteger index = -1 ;
283
286
for (NSInteger i = 0 ; i < self.viewsArray .count ; i++) {
284
- QNVideoView *remoteView = self.viewsArray [i];
287
+ QNVideoGLView *remoteView = self.viewsArray [i];
285
288
UILabel *label = remoteView.subviews .lastObject ;
286
289
if ([label.text isEqualToString: userId]) {
287
290
[remoteView removeFromSuperview ];
@@ -292,7 +295,7 @@ - (void)removeRemoteRenderView:(NSString *)userId {
292
295
293
296
// 剔除离开的远端用户画面后,重新调整布局
294
297
for (NSInteger i = 0 ; i < self.viewsArray .count ; i++) {
295
- QNVideoView *remoteView = self.viewsArray [i];
298
+ QNVideoGLView *remoteView = self.viewsArray [i];
296
299
NSInteger count = i + 1 ;
297
300
remoteView.frame = CGRectMake (self.screenWidth /2 * (count%2 ), self.screenWidth /2 * (count/2 ), self.screenWidth /2 , self.screenWidth /2 );
298
301
}
@@ -319,12 +322,12 @@ - (void)closePublishAndBack:(UIButton *)button {
319
322
320
323
- (void )videoButtonAction : (UIButton *)button {
321
324
button.selected = !button.isSelected ;
322
- [self .cameraTrack updataMute : !button.isSelected];
325
+ [self .cameraTrack updateMute : !button.isSelected];
323
326
}
324
327
325
328
- (void )microphoneButtonAction : (UIButton *)button {
326
329
button.selected = !button.isSelected ;
327
- [self .audioTrack updataMute : !button.isSelected];
330
+ [self .audioTrack updateMute : !button.isSelected];
328
331
}
329
332
330
333
- (void )cameraButtonAction : (UIButton *)button {
0 commit comments