BJLPlayingVM.h 12.9 KB
Newer Older
root's avatar
1.0.0  
root committed
1 2 3 4 5 6 7 8 9
//
//  BJLPlayingVM.h
//  BJLiveCore
//
//  Created by MingLQ on 2016-12-16.
//  Copyright © 2016 BaijiaYun. All rights reserved.
//

#import "BJLBaseVM.h"
戴曦嘉's avatar
戴曦嘉 committed
10
#import "BJLMediaUser.h"
戴曦嘉's avatar
戴曦嘉 committed
11
#import "BJLWindowUpdateModel.h"
root's avatar
1.0.0  
root committed
12 13 14 15 16 17

NS_ASSUME_NONNULL_BEGIN

/** ### 音视频播放 */
@interface BJLPlayingVM : BJLBaseVM

戴曦嘉's avatar
戴曦嘉 committed
18 19
/**
 音视频用户列表
huangjie's avatar
注释  
huangjie committed
20
 #discussion 包含教室内推送主音视频流的用户,数组内 BJLMediaUser 实例的音视频信息为主音视频流的信息,每个用户在 playingUsers 中只有一个 BJLMediaUser 实例
戴曦嘉's avatar
戴曦嘉 committed
21 22 23
 #discussion 在 webRTC 教室中,数组内的 BJLMediaUser 实例的 mediaSource 为 BJLMediaSource_mainCamera
 #discussion 在非 webRTC 教室中,数组内的 BJLMediaUser 实例的 mediaSource 为 BJLMediaSource_mainCamera、BJLMediaSource_screenShare 或 BJLMediaSource_mediaFile
 #discussion 所有用户的音频会自动播放,视频需要调用 `updatePlayingUserWithID:videoOn:mediaSource:` 打开或者通过 `autoPlayVideoBlock` 控制打开
root's avatar
1.0.0  
root committed
24 25
 #discussion SDK 会处理音视频打断、恢复、前后台切换等情况
 */
戴曦嘉's avatar
戴曦嘉 committed
26
@property (nonatomic, readonly, copy, nullable) NSArray<BJLMediaUser *> *playingUsers;
戴曦嘉's avatar
1.3.10  
戴曦嘉 committed
27

戴曦嘉's avatar
戴曦嘉 committed
28 29 30 31 32 33 34
/**
 扩展音视频流用户列表
 #discussion 包含教室内推送扩展音视频流的用户,音视频信息为扩展音视频流的信息,每个用户在 extraPlayingUsers 中可以有多个 BJLMediaUser 实例
 #discussion 在 webRTC 教室中,数组内的 BJLMediaUser 实例的 mediaSource 为除 BJLMediaSource_mainCamera 之外的音视频流类型
 #discussion 在非 webRTC 教室中,数组内 BJLMediaUser 实例的 mediaSource 为 BJLMediaSource_extraCamera 或 BJLMediaSource_extraScreenShare
 #discussion 所有用户的音频会自动播放,视频需要调用 `updatePlayingUserWithID:videoOn:mediaSource:` 打开或者通过 `autoPlayVideoBlock` 控制打开
 #discussion 打开了扩展音视频流的用户将同时包含在 playingUsers 和 extraPlayingUsers 中,但两个列表中的 BJLMediaUser 实例的音视频信息不同
戴曦嘉's avatar
戴曦嘉 committed
35
 */
戴曦嘉's avatar
戴曦嘉 committed
36
@property (nonatomic, readonly, copy, nullable) NSArray<BJLMediaUser *> *extraPlayingUsers;
戴曦嘉's avatar
戴曦嘉 committed
37

戴曦嘉's avatar
戴曦嘉 committed
38 39
/**
 查找音视频用户
root's avatar
1.0.0  
root committed
40 41
 #param userID 用户 ID
 #param userNumber 用户编号
戴曦嘉's avatar
戴曦嘉 committed
42 43
 #param mediaSource 视频源类型
 #discussion 不同的 mediaSource 取到的 BJLMediaUser 实例可能用户信息相同,但音视频信息是不同的
root's avatar
1.0.0  
root committed
44
 */
戴曦嘉's avatar
戴曦嘉 committed
45 46 47
- (nullable __kindof BJLMediaUser *)playingUserWithID:(nullable NSString *)userID
                                               number:(nullable NSString *)userNumber
                                          mediaSource:(BJLMediaSource)mediaSource;
root's avatar
1.0.0  
root committed
48

戴曦嘉's avatar
戴曦嘉 committed
49 50 51 52 53 54 55 56
/**
 查找音视频流对应的用户实例
 #param mediaID 音视频流标识
 */
- (nullable __kindof BJLMediaUser *)playingUserWithMediaID:(nullable NSString *)mediaID;

/**
 用户开关音、视频
root's avatar
1.3.3  
root committed
57
 #discussion - 某个用户主动开关自己的音视频、切换清晰度时发送此通知,但不包含意外掉线等情况
root's avatar
1.0.0  
root committed
58 59
 #discussion - 正在播放的视频用户 关闭视频时 `videoPlayingUser` 将被设置为 nil、同时发送此通知
 #discussion - 进教室后批量更新 `playingUsers` 时『不』发送此通知
戴曦嘉's avatar
戴曦嘉 committed
60
 #discussion - 音视频开关状态通过 `BJLMediaUser` 的 `audioOn`、`videoOn` 获得
root's avatar
1.3.3  
root committed
61
 #discussion - definitionIndex 可能会发生变化,调用 `definitionIndexForUserWithID:` 可获取最新的取值
huangjie's avatar
注释  
huangjie committed
62
 #discussion - 用户退出教室时,new 为 nil,old 的 `mediaSource` 属性为 `BJLMediaSource_all`
root's avatar
1.0.0  
root committed
63 64
 #param now 新用户信息
 #param old 旧用户信息
root's avatar
1.3.3  
root committed
65
 TODO: 增加方法支持同时监听初始音视频状态
root's avatar
1.0.0  
root committed
66
 */
戴曦嘉's avatar
戴曦嘉 committed
67 68 69 70
- (BJLObservable)playingUserDidUpdate:(nullable BJLMediaUser *)now
                                  old:(nullable BJLMediaUser *)old;

/**
huangjie's avatar
注释  
huangjie committed
71
 用户改变视频清晰度
root's avatar
1.3.3  
root committed
72 73
 #param now 新用户信息
 #param old 旧用户信息
huangjie's avatar
注释  
huangjie committed
74
 #discussion 清晰度的变化可对比 `now` 与 `old` 的 `definitions` 属性得知
root's avatar
1.3.3  
root committed
75
 */
戴曦嘉's avatar
戴曦嘉 committed
76 77
- (BJLObservable)playingUserDidUpdateVideoDefinitions:(nullable BJLMediaUser *)now
                                                  old:(nullable BJLMediaUser *)old;
root's avatar
1.0.0  
root committed
78

戴曦嘉's avatar
戴曦嘉 committed
79 80
/**
 `playingUsers`、`extraPlayingUsers` 被覆盖更新
root's avatar
1.0.0  
root committed
81
 #discussion 进教室后批量更新才调用,增量更新不调用
戴曦嘉's avatar
戴曦嘉 committed
82 83
 #param playingUsers 音视频用户列表, 使用主摄像头采集音视频推流的用户列表
 #param extraPlayingUsers 扩展音视频流用户列表,不使用主摄像头采集音视频推流的用户列表
root's avatar
1.3.3  
root committed
84
 TODO: 改进此方法,使之与监听 playingUsers 区别更小
root's avatar
1.0.0  
root committed
85
 */
戴曦嘉's avatar
戴曦嘉 committed
86 87
- (BJLObservable)playingUsersDidOverwrite:(nullable NSArray<BJLMediaUser *> *)playingUsers
                        extraPlayingUsers:(nullable NSArray<BJLMediaUser *> *)extraPlayingUsers;
root's avatar
1.0.0  
root committed
88

戴曦嘉's avatar
戴曦嘉 committed
89 90
/**
 将要播放视频
huangjie's avatar
注释  
huangjie committed
91
 #discussion 播放视频的方法被成功调用时回调
戴曦嘉's avatar
戴曦嘉 committed
92
 #param playingUser 将要播放的视频用户
root's avatar
update  
root committed
93
 */
戴曦嘉's avatar
戴曦嘉 committed
94
- (BJLObservable)playingUserDidStartLoadingVideo:(nullable BJLMediaUser *)playingUser;
戴曦嘉's avatar
戴曦嘉 committed
95

戴曦嘉's avatar
戴曦嘉 committed
96
/**
huangjie's avatar
注释  
huangjie committed
97 98 99
 视频播放成功
 #discussion 用户视频播放成功
 #param playingUser 播放的视频对应的用户
root's avatar
update  
root committed
100
 */
戴曦嘉's avatar
戴曦嘉 committed
101
- (BJLObservable)playingUserDidFinishLoadingVideo:(nullable BJLMediaUser *)playingUser;
root's avatar
update  
root committed
102

戴曦嘉's avatar
戴曦嘉 committed
103 104 105
/**
 播放出现卡顿
 #param user 出现卡顿的正在播放的视频用户实例
戴曦嘉's avatar
1.3.7  
戴曦嘉 committed
106
 */
戴曦嘉's avatar
戴曦嘉 committed
107
- (BJLObservable)playLagWithPlayingUser:(BJLMediaUser *)user;
戴曦嘉's avatar
1.3.7  
戴曦嘉 committed
108

root's avatar
1.0.0  
root committed
109 110
#pragma mark -

戴曦嘉's avatar
戴曦嘉 committed
111 112
/**
 正在播放的视频用户
huangjie's avatar
注释  
huangjie committed
113
 #discussion 数组内元素包含在 `playingUsers`、`extraPlayingUsers` 之中,在当前打开了音视频的用户列表中,本地在播放的用户列表。
戴曦嘉's avatar
戴曦嘉 committed
114 115 116
 #discussion 断开重连、暂停恢复等操作不自动重置 `videoPlayingUsers`,除非对方用户掉线、离线等
 */
@property (nonatomic, readonly, copy, nullable) NSArray<BJLMediaUser *> *videoPlayingUsers;
戴曦嘉's avatar
戴曦嘉 committed
117

戴曦嘉's avatar
戴曦嘉 committed
118 119
/**
 从 `videoPlayingUsers` 查找用户
root's avatar
1.3.3  
root committed
120 121
 #param userID 用户 ID
 #param userNumber 用户编号
戴曦嘉's avatar
戴曦嘉 committed
122
 #param mediaSource 视频源类型
root's avatar
1.3.3  
root committed
123
 */
戴曦嘉's avatar
戴曦嘉 committed
124 125 126
- (nullable __kindof BJLMediaUser *)videoPlayingUserWithID:(nullable NSString *)userID
                                                    number:(nullable NSString *)userNumber
                                               mediaSource:(BJLMediaSource)mediaSource;
root's avatar
1.0.0  
root committed
127

戴曦嘉's avatar
2.9.3  
戴曦嘉 committed
128 129
/**
 自动播放视频并指定清晰度回调
root's avatar
1.3.3  
root committed
130 131
 #discussion 传入参数 user 和 cachedDefinitionIndex 分别为 用户 和 上次播放该用户视频时使用的清晰度
 #discussion 返回结果 autoPlay 和 definitionIndex 分别为 是否自动播放视频 和 播放视频使用的视频清晰度,例如
root's avatar
root committed
132
 |  self.room.playingVM.autoPlayVideoBlock = ^BJLAutoPlayVideo(BJLMediaUser *user, NSInteger cachedDefinitionIndex) {
root's avatar
1.3.3  
root committed
133 134 135
 |      BOOL autoPlay = user.number && ![self.autoPlayVideoBlacklist containsObject:user.number];
 |      NSInteger definitionIndex = cachedDefinitionIndex;
 |      if (autoPlay) {
root's avatar
update  
root committed
136
 |          NSInteger maxDefinitionIndex = MAX(0, (NSInteger)user.definitions.count - 1);
root's avatar
1.3.3  
root committed
137 138 139
 |          definitionIndex = (cachedDefinitionIndex <= maxDefinitionIndex
 |                             ? cachedDefinitionIndex : maxDefinitionIndex);
 |      }
root's avatar
root committed
140
 |      return BJLAutoPlayVideoMake(autoPlay, definitionIndex);
root's avatar
1.3.3  
root committed
141 142
 |  };
 */
root's avatar
root committed
143
@property (nonatomic, copy, nullable) BJLAutoPlayVideo (^autoPlayVideoBlock)(BJLMediaUser *user, NSInteger cachedDefinitionIndex);
root's avatar
update  
root committed
144

戴曦嘉's avatar
2.9.3  
戴曦嘉 committed
145
/** 播放画面显示模式,默认 BJLVideoContentMode_aspectFit */
戴曦嘉's avatar
2.2.0  
戴曦嘉 committed
146 147
@property (nonatomic) BJLVideoContentMode videoContentMode;

戴曦嘉's avatar
2.9.3  
戴曦嘉 committed
148 149
/**
 更新播放画面的水印显示
戴曦嘉's avatar
戴曦嘉 committed
150 151 152 153 154 155 156 157 158 159
 #param user 播放画面的用户
 #param size 显示播放画面的容器的尺寸或者视频的实际尺寸
 #param videoContentMode 播放画面的显示模式
 #discussion 目前只有主讲人的视图才会显示水印,主讲人只能是老师或者助教身份。
 #discussion 播放画面显示模式为 BJLVideoContentMode_aspectFill 时,size 为显示播放画面的容器的尺寸。
 #discussion 播放画面显示模式为 BJLVideoContentMode_aspectFit 时,size 为视频的尺寸比例。
 #discussion 例如尺寸比例为 ratio,size 的值为 CGSizeMake(ratio, 1.0),尺寸比例参考 `playingViewAspectRatioForUserWithID:mediaSource:`。
 */
- (void)updateWatermarkWithUser:(BJLMediaUser *)user size:(CGSize)size videoContentMode:(BJLVideoContentMode)videoContentMode;

戴曦嘉's avatar
2.9.3  
戴曦嘉 committed
160 161
/** 禁止自动播放除老师,助教以外的视频,目前仅专业小班课使用 */
@property (nonatomic, readonly) BOOL disableAutoPlayVideoExceptTeacherAndAssistant;
戴曦嘉's avatar
2.9.2  
戴曦嘉 committed
162

戴曦嘉's avatar
戴曦嘉 committed
163 164
/**
 设置播放用户的视频
root's avatar
1.0.0  
root committed
165 166
 #param userID 用户 ID
 #param videoOn YES:打开视频,NO:关闭视频
戴曦嘉's avatar
戴曦嘉 committed
167 168
 #param definitionIndex `BJLMediaUser` 的 `definitions` 属性的 index,参考 `BJLLiveDefinitionKey`、`BJLLiveDefinitionNameForKey()`
 #param mediaSource 视频源类型
root's avatar
update  
root committed
169
 #return BJLError:
root's avatar
1.0.0  
root committed
170 171 172
 BJLErrorCode_invalidArguments  错误参数,如 `playingUsers` 中不存在此用户;
 BJLErrorCode_invalidCalling    错误调用,如用户视频已经在播放、或用户没有开启摄像头。
 */
root's avatar
1.3.3  
root committed
173
- (nullable BJLError *)updatePlayingUserWithID:(NSString *)userID
戴曦嘉's avatar
戴曦嘉 committed
174
                                       videoOn:(BOOL)videoOn
戴曦嘉's avatar
戴曦嘉 committed
175
                                   mediaSource:(BJLMediaSource)mediaSource;
root's avatar
1.3.3  
root committed
176 177
- (nullable BJLError *)updatePlayingUserWithID:(NSString *)userID
                                       videoOn:(BOOL)videoOn
戴曦嘉's avatar
戴曦嘉 committed
178 179
                                   mediaSource:(BJLMediaSource)mediaSource
                               definitionIndex:(NSInteger)definitionIndex;
root's avatar
1.3.3  
root committed
180

戴曦嘉's avatar
戴曦嘉 committed
181 182
/**
 获取播放用户的清晰度
root's avatar
1.3.3  
root committed
183
 #param userID 用户 ID
戴曦嘉's avatar
戴曦嘉 committed
184
 #param mediaSource 视频源类型
root's avatar
1.3.3  
root committed
185 186
 #return 播放时传入的 `definitionIndex`
 */
戴曦嘉's avatar
戴曦嘉 committed
187 188
- (NSInteger)definitionIndexForUserWithID:(NSString *)userID
                              mediaSource:(BJLMediaSource)mediaSource;
root's avatar
1.0.0  
root committed
189

戴曦嘉's avatar
戴曦嘉 committed
190 191
/**
 获取播放用户的视频视图
root's avatar
1.0.0  
root committed
192
 #param userID 用户 ID
戴曦嘉's avatar
戴曦嘉 committed
193
 #param mediaSource 视频源类型
root's avatar
1.0.0  
root committed
194
 */
戴曦嘉's avatar
戴曦嘉 committed
195 196
- (nullable UIView *)playingViewForUserWithID:(NSString *)userID
                                  mediaSource:(BJLMediaSource)mediaSource;
root's avatar
1.0.0  
root committed
197

戴曦嘉's avatar
戴曦嘉 committed
198 199
/**
 获取播放用户的视频视图宽高比
root's avatar
1.0.0  
root committed
200
 #param userID 用户 ID
戴曦嘉's avatar
戴曦嘉 committed
201
 #param mediaSource 视频源类型
root's avatar
1.0.0  
root committed
202
 */
戴曦嘉's avatar
戴曦嘉 committed
203 204
- (CGFloat)playingViewAspectRatioForUserWithID:(NSString *)userID
                                   mediaSource:(BJLMediaSource)mediaSource;
root's avatar
1.0.0  
root committed
205

戴曦嘉's avatar
戴曦嘉 committed
206 207
/**
 用户视频宽高比发生变化的通知
root's avatar
1.0.0  
root committed
208
 #param videoAspectRatio 视频宽高比
huangjie's avatar
注释  
huangjie committed
209
 #param user             用户音视频流信息
root's avatar
1.0.0  
root committed
210
 */
root's avatar
1.3.3  
root committed
211
- (BJLObservable)playingViewAspectRatioChanged:(CGFloat)videoAspectRatio
戴曦嘉's avatar
戴曦嘉 committed
212
                                       forUser:(BJLMediaUser *)user;
root's avatar
1.0.0  
root committed
213

戴曦嘉's avatar
戴曦嘉 committed
214 215
/**
 老师在 PC 上更改共享桌面设置、媒体文件播放状态
戴曦嘉's avatar
戴曦嘉 committed
216 217
 #discussion 这两个属性需要与老师的在线状态、音视频状态配合使用
 */
戴曦嘉's avatar
2.2.0  
戴曦嘉 committed
218
@property (nonatomic, readonly) BOOL teacherSharingDesktop, teacherPlayingMedia;
戴曦嘉's avatar
戴曦嘉 committed
219

戴曦嘉's avatar
2.9.3  
戴曦嘉 committed
220 221 222 223 224
/**
 拉流时大小流切换
 #param user user
 #param useLowDefinition 是否切换为小流, yes: 切为小流, no: 切为大流
 */
戴曦嘉's avatar
戴曦嘉 committed
225 226
- (void)switchVideoDefinitionWithUser:(BJLMediaUser *)user useLowDefinition:(BOOL)useLowDefinition;

戴曦嘉's avatar
戴曦嘉 committed
227
#pragma mark - interactive class 专业版小班课 API
root's avatar
update  
root committed
228

戴曦嘉's avatar
1.3.9  
戴曦嘉 committed
229
/**
戴曦嘉's avatar
戴曦嘉 committed
230
 专业版小班课 - 更新视频窗口
huangjie's avatar
注释  
huangjie committed
231
 #param mediaID 视频流标识
戴曦嘉's avatar
戴曦嘉 committed
232 233 234 235
 #param action 更新类型,参考 BJLWindowsUpdateModel 的 BJLWindowsUpdateAction
 #param displayInfos 教室内所有视频窗口显示信息
 #return 调用错误, 参考 BJLErrorCode
 */
戴曦嘉's avatar
戴曦嘉 committed
236 237 238
- (nullable BJLError *)updateVideoWindowWithMediaID:(NSString *)mediaID
                                             action:(NSString *)action
                                       displayInfos:(NSArray<BJLWindowDisplayInfo *> *)displayInfos;
root's avatar
1.3.3  
root committed
239

戴曦嘉's avatar
戴曦嘉 committed
240 241 242
/**
 专业版小班课 - 视频窗口更新通知
 #param updateModel 更新信息
huangjie's avatar
注释  
huangjie committed
243
 #param shouldReset 是否重置
戴曦嘉's avatar
戴曦嘉 committed
244
 */
戴曦嘉's avatar
戴曦嘉 committed
245 246
- (BJLObservable)didUpdateVideoWindowWithModel:(BJLWindowUpdateModel *)updateModel
                                   shouldReset:(BOOL)shouldReset;
戴曦嘉's avatar
戴曦嘉 committed
247 248 249 250 251

/**
 专业版小班课 - 用户上台请求
 #param user 对象用户
 #return 错误调用
戴曦嘉's avatar
戴曦嘉 committed
252
 */
戴曦嘉's avatar
戴曦嘉 committed
253
- (nullable BJLError *)requestAddActiveUser:(BJLUser *)user;
戴曦嘉's avatar
戴曦嘉 committed
254

戴曦嘉's avatar
戴曦嘉 committed
255 256
/**
 专业版小班课 - 用户下台请求
root's avatar
update  
root committed
257
 #param user 对象用户
戴曦嘉's avatar
戴曦嘉 committed
258
 #return 错误调用
root's avatar
update  
root committed
259
 */
戴曦嘉's avatar
戴曦嘉 committed
260 261
- (nullable BJLError *)requestRemoveActiveUser:(BJLUser *)user;

戴曦嘉's avatar
戴曦嘉 committed
262 263 264 265
/**
 专业版小班课 - 用户上台成功回调
 #param user 用户信息
 */
戴曦嘉's avatar
戴曦嘉 committed
266 267 268 269
- (BJLObservable)didAddActiveUser:(BJLUser *)user;

/**
 专业版小班课 - 用户上台请求被服务端拒绝
huangjie's avatar
注释  
huangjie committed
270
 #param user 上台对象信息
huangjie's avatar
source  
huangjie committed
271
 #param responseCode: 拒绝原因对应的状态码:1.上台人数达到上限; 2.用户已离开教室
戴曦嘉's avatar
戴曦嘉 committed
272
 */
huangjie's avatar
source  
huangjie committed
273
- (BJLObservable)didAddActiveUserDeny:(BJLUser *)user responseCode:(NSInteger)responseCode;
戴曦嘉's avatar
戴曦嘉 committed
274

戴曦嘉's avatar
戴曦嘉 committed
275 276 277 278
/**
 专业版小班课 - 用户下台成功回调
 #param user 用户信息
 */
戴曦嘉's avatar
戴曦嘉 committed
279
- (BJLObservable)didRemoveActiveUser:(BJLUser *)user;
root's avatar
update  
root committed
280

281
#pragma mark - mix video
戴曦嘉's avatar
2.7.2  
戴曦嘉 committed
282

戴曦嘉's avatar
戴曦嘉 committed
283 284 285
/** 当前是否在播放合流 */
@property (nonatomic, readonly) BOOL playMixedVideo;

戴曦嘉's avatar
2.7.2  
戴曦嘉 committed
286 287 288 289
/** 视频合流时的被混合的音视频用户列表 */
@property (nonatomic, readonly, nullable) NSArray<BJLMediaUser *> *mixedPlayingUsers __APPLE_API_UNSTABLE;
@property (nonatomic, readonly, nullable) NSArray<BJLMediaUser *> *extraMixedPlayingUsers __APPLE_API_UNSTABLE;

huangjie's avatar
source  
huangjie committed
290 291 292 293
#pragma mark - DEPRECATED

- (BJLObservable)didAddActiveUserDeny:(BJLUser *)user DEPRECATED_MSG_ATTRIBUTE("use `didAddActiveUserDeny:responseCode:` instead");

root's avatar
1.0.0  
root committed
294 295 296
@end

NS_ASSUME_NONNULL_END