CNLiveStreamingKit.h
10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
//
// CNLiveStreamingKit.h
// QNLiveStreamingDemo
//
// Created by iOS on 16/12/29.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CNLiveQNLivingKit.h"
@protocol CNLiveStreamingKitDelagate <NSObject>
@optional
/**
* 推流状态发生改变的回调
*/
- (void)streamStateDidChange:(PLStreamState)state;
/**
* 因产生了某个 error 而断开推流的回调
*/
- (void)didDisconnectWithError:(NSDictionary *)errorDic;
/**
* 当开始推流时,会每间隔 3s 调用该回调方法来反馈该 3s 内的流状态,包括视频帧率、音频帧率、音视频总码率
*/
- (void)streamStatusDidUpdate:(PLStreamStatus *)status;
/**
* 摄像头授权状态发生变化的回调
*/
- (void)didGetCameraAuthorizationStatus:(PLAuthorizationStatus)status;
/**
* 麦克风授权状态发生变化的回调
*/
- (void)didGetMicrophoneAuthorizationStatus:(PLAuthorizationStatus)status;
@end
@interface CNLiveStreamingKit : NSObject
/**
@abstract 初始化(视讯云)
@warning 实例化的对象必须赋值给一个全局变量
@param videoCaptureConfiguration 视频采集配置
@param audioCaptureConfiguration 音频采集配置
@param videoStreamingConfiguration 视频推流配置
@param audioStreamingConfiguration 音频推流配置
@param activityId 活动ID,确保SP下的唯一性
@param channelId 主播ID
@param isHorizontalScreen 屏幕方向,0:垂直即竖屏 /1:水平即横屏 ,默认为1
@warning 必传参数
*/
-(instancetype)initWithVideoCaptureConfiguration:(PLVideoCaptureConfiguration *)videoCaptureConfiguration
audioCaptureConfiguration:(PLAudioCaptureConfiguration *)audioCaptureConfiguration
videoStreamingConfiguration:(PLVideoStreamingConfiguration *)videoStreamingConfiguration
audioStreamingConfiguration:(PLAudioStreamingConfiguration *)audioStreamingConfiguration
activityId:(NSString *)activityId
channelId:(NSString *)channelId
isHorizontalScreen:(NSString *)isHorizontalScreen;
/**
* 初始化(普通推流)
@warning 实例化的对象必须赋值给一个全局变量
@param videoCaptureConfiguration 视频采集配置
@param audioCaptureConfiguration 音频采集配置
@param videoStreamingConfiguration 视频推流配置
@param audioStreamingConfiguration 音频推流配置
*/
- (instancetype)initWithVideoCaptureConfiguration:(PLVideoCaptureConfiguration *)videoCaptureConfiguration
audioCaptureConfiguration:(PLAudioCaptureConfiguration *)audioCaptureConfiguration
videoStreamingConfiguration:(PLVideoStreamingConfiguration *)videoStreamingConfiguration
audioStreamingConfiguration:(PLAudioStreamingConfiguration *)audioStreamingConfiguration;
/**
@abstract 是否开启控制台输出日志
@discussion 默认为开启
*/
@property (nonatomic, assign) BOOL logPrintEnable;
@property (nonatomic, assign) id<CNLiveStreamingKitDelagate> delegate;
#pragma mark -
#pragma mark - 与活动相关参数(非必传)
/**
@abstract 活动名称(非必传)
*/
@property (nonatomic, strong) NSString *activityName;
/**
@abstract 活动状态,0:未开始 /1:已开始 /3:已结束 /4 已下线,默认为0(非必传)
*/
@property (nonatomic, strong) NSString *activityStatus;
/**
@abstract 开始时间,格式yyyyMMddHHmmss(非必传)
*/
@property (nonatomic, strong) NSString *startTime;
/**
@abstract 结束时间,格式yyyyMMddHHmmss(非必传)
*/
@property (nonatomic, strong) NSString *endTime;
/**
@abstract 活动封面(非必传)
*/
@property (nonatomic, strong) NSString *coverImgUrl;
/**
@abstract 活动分类ID(非必传)
*/
@property (nonatomic, strong) NSString *activityCategory;
/**
@abstract 扩展字段,参数格式为Map对象的Json字符串(主播昵称、头像、)(非必传)
*/
@property (nonatomic, strong) NSString *extensions;
/**
@abstract 回调通知活动状态(错误,结束、心跳异常等状态),post 参数activityid、activitystatus值...(非必传)
*/
@property (nonatomic, strong) NSString *callbackAcitvityStatushttpPostUrl;
/**
* 是否正在推流中,只读
*/
@property (nonatomic, assign, readonly) BOOL isStreamingRunning;
/**
* 视频编码及推流配置,只读
*/
@property (nonatomic, copy, readonly) PLVideoCaptureConfiguration *videoCaptureConfiguration;
/**
* 音频编码及推流配置,只读
*/
@property (nonatomic, copy, readonly) PLAudioCaptureConfiguration *audioCaptureConfiguration;
/**
* 视频编码及推流配置,只读
*/
@property (nonatomic, copy, readonly) PLVideoStreamingConfiguration *videoStreamingConfiguration;
/**
* 音频编码及推流配置,只读
*/
@property (nonatomic, copy, readonly) PLAudioStreamingConfiguration *audioStreamingConfiguration;
/**
* 摄像头的预览视图
*/
@property (nonatomic, strong, readonly) UIView *previewView;
/**
* 中视频的填充方式,默认使用 PLVideoFillModePreserveAspectRatioAndFill
*/
@property(readwrite, nonatomic) PLVideoFillModeType fillMode;
#pragma mark -
#pragma mark - 与推流相关的接口
/**
* 流的状态
*/
@property (nonatomic, assign, readonly) PLStreamState streamState;
/**
* 网络连接和接收数据超时,以秒作为单位。默认为 15s, 设定最小数值不得低于 3s,否则不变更。
*/
@property (nonatomic, assign) int receiveTimeout;
/**
* 网络发送数据超时。reload
*/
@property (nonatomic, assign) int sendTimeout;
/**
* 开启动态帧率功能,自动调整的最大帧率不超过 videoStreamingConfiguration.expectedSourceVideoFrameRate。该功能默认为关闭状态。
*/
@property (nonatomic,assign) BOOL dynamicFrameEnable;
/**
* 开启自适应码率调节功能
*/
- (void)enableAdaptiveBitrateControlWithMinVideoBitRate:(NSUInteger)minVideoBitRate;
/**
* 关闭自适应码率调节功能,默认即为关闭状态
*/
- (void)disableAdaptiveBitrateControl;
/**
* 开始推流(视讯云)
*/
- (void)startStreamingWithFeedback:(void (^)(PLStreamStartStateFeedback feedback))handler failure:(void (^)(NSDictionary *errorDic))failureBlock;
/**
* 普通开始推流
*/
- (void)startStreamingWithPushURL:(NSURL *)pushURL feedback:(void (^)(PLStreamStartStateFeedback feedback))handler;
/**
* 结束推流
*/
- (void)stopStreaming;
/**
* 重新加载视频推流配置
*/
- (void)reloadVideoStreamingConfiguration:(PLVideoStreamingConfiguration *)videoStreamingConfiguration;
#pragma mark -
#pragma mark - 与摄像头相关的接口
/**
* 摄像头配置(默认 AVCaptureDevicePositionBack)
*/
@property (nonatomic, assign) AVCaptureDevicePosition captureDevicePosition;
/**
* 摄像头朝向(默认 AVCaptureVideoOrientationPortrait)
*/
@property (nonatomic, assign) AVCaptureVideoOrientation videoOrientation;
/**
* 闪光灯设置(默认 NO)
*/
@property (nonatomic, assign) BOOL torchOn;
/**
* 连续自动对焦(默认开启)
*/
@property (nonatomic, assign) BOOL continuousAutofocusEnable;
/**
* 手动点击屏幕进行对焦(默认开启)
*/
@property (nonatomic, assign) BOOL touchToFocusEnable;
/**
* 该属性适用于视频拍摄过程中用来减缓因自动对焦产生的镜头伸缩,使画面不因快速的对焦而产生抖动感。(默认开启)
*/
@property (nonatomic, assign) BOOL smoothAutoFocusEnabled;
/// 默认为 1.0,设置的数值需要小于等于 videoActiveForat.videoMaxZoomFactor,如果大于会设置失败。
@property (nonatomic, assign) CGFloat videoZoomFactor;
@property (nonatomic, strong, readonly) NSArray<AVCaptureDeviceFormat *> *videoFormats;
@property (nonatomic, strong) AVCaptureDeviceFormat *cnVideoActiveFormat;
/**
* 采集的视频的 sessionPreset,默认为 AVCaptureSessionPreset640x480
*/
@property (nonatomic, copy) NSString *sessionPreset;
/**
* 采集的视频数据的帧率,默认为 30
*/
@property (nonatomic, assign) NSUInteger videoFrameRate;
/**
* 前置预览是否开启镜像,默认为 YES
*/
@property (nonatomic, assign) BOOL previewMirrorFrontFacing;
/**
* 后置预览是否开启镜像,默认为 NO
*/
@property (nonatomic, assign) BOOL previewMirrorRearFacing;
/**
* 前置摄像头,推的流是否开启镜像,默认 NO
*/
@property (nonatomic, assign) BOOL streamMirrorFrontFacing;
/**
* 后置摄像头,推的流是否开启镜像,默认 NO
*/
@property (nonatomic, assign) BOOL streamMirrorRearFacing;
/**
* 切换前后摄像头
*/
- (void)toggleCamera;
/**
* 销毁推流核心类
*/
- (void)destroy;
#pragma mark -
#pragma mark - 与麦克风相关接口
/**
* 耳返(默认NO 关闭)
*/
@property (nonatomic, assign) BOOL playback;
/**
* 静音(默认NO 关闭)
*/
@property (nonatomic, assign) BOOL muted;
/**
* 麦克风采集的音量,设置范围为 0~1,各种机型默认值不同。
* @warning iPhone 6s 系列不支持调节麦克风采集的音量。
*/
@property (nonatomic, assign) float inputGain;
/**
* 音效,所有生效音效的一个数组。
*/
@property (nonatomic, strong) NSArray<PLAudioEffectConfiguration *> *audioEffectConfigurations;
/**
* 绑定一个音频文件播放器。该播放器播放出的声音将和麦克风声音混和,并推流出去。
* @param audioFilePath 音频文件路径
*/
- (PLAudioPlayer *)audioPlayerWithFilePath:(NSString *)audioFilePath;
/**
* 关闭当前的音频文件播放器
*/
- (void)closeCurrentAudio;
#pragma mark -
#pragma mark - 美颜
/**
* 是否开启美颜
*/
-(void)setBeautifyModeOn:(BOOL)beautifyModeOn;
/**
* 设置对应 Beauty 的程度参数.
* @param beautify 范围从 0 ~ 1,0 为不美颜
*/
-(void)setBeautify:(CGFloat)beautify;
/**
* 设置美白程度(注意:如果美颜不开启,设置美白程度参数无效)
* @param whiten 范围是从 0 ~ 1,0 为不美白
*/
-(void)setWhiten:(CGFloat)whiten;
/**
* 设置红润的程度参数.(注意:如果美颜不开启,设置美白程度参数无效)
* @param redden 范围是从 0 ~ 1,0 为不红润
*/
-(void)setRedden:(CGFloat)redden;
#pragma mark -
#pragma mark - 水印
/**
* 开启水印
* @param wateMarkImage 水印的图片
* @param position 水印的位置
*/
-(void)setWaterMarkWithImage:(UIImage *)wateMarkImage position:(CGPoint)position;
/**
* 移除水印
*/
-(void)clearWaterMark;
@end