CNLiveGPUStreamerKit.h
8.71 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
//
// CNLiveGPUStreamerKit.h
// KSYLiveDemo
//
// Created by Android on 16/8/3.
// Copyright © 2016年 Android. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CNLiveWebcastManager.h"
#import <AVFoundation/AVFoundation.h>
@interface CNLiveGPUStreamerKit : NSObject
#pragma mark - 使用视讯云平台
/**
@abstract 初始化
@warning 实例化的对象必须赋值给一个全局变量
@param activityId 活动ID,确保SP下的唯一性
@param channelId 主播ID
@param isHorizontalScreen 屏幕方向,0:垂直即竖屏 /1:水平即横屏 ,默认为1
@warning 必传参数
*/
-(instancetype)initWithDefaultConfigWithActivityId:(NSString *)activityId
channelId:(NSString *)channelId
isHorizontalScreen:(NSString *)isHorizontalScreen;
/**
@abstract 是否开启控制台输出日志
@discussion 默认为开启
*/
@property (nonatomic, assign) BOOL logPrintEnable;
/**
@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;
/**
@abstract 启动推流
@warning 鉴权成功后开启推流
*/
- (void) startStream:(void (^)(void))successBlock failure:(void (^)(NSDictionary *errorDic))failureBlock;
#pragma mark - 普通推流
/**
@abstract 初始化
@warning 实例化的对象必须赋值给一个全局变量
*/
-(instancetype)initWithDefaultConfig;
/**
@abstract 获取水印工具
@discussion 通过它来设置水印图片/文字
*/
@property (nonatomic, readonly) CNLiveWatermark *watermark;
/**
@abstract 获取底层推流工具
@discussion 通过它来设置推流参数
*/
@property (nonatomic, readonly) CNLiveStreamerBase *streamerBase;
/**
@abstract 获取音频采集工具
*/
@property (nonatomic, readonly) CNLiveAudioCapture *audioCapture;
/**
@abstract 获取美颜工具
*/
@property (nonatomic, readonly) CNLiveBeautifyFaceFilter *beautifyFaceFilter;
#pragma mark - capture & preview settings
/**
@abstract 采集分辨率 (仅在开始采集前设置有效)
@discussion 参见iOS的 AVCaptureSessionPresetXXX的定义 默认值为AVCaptureSessionPreset640x480
@discussion 不同设备支持的预设分辨率可能不同, 请尽量与预览分辨率一致
*/
@property (nonatomic, assign) NSString * capPreset;
/**
@abstract 查询实际的采集分辨率
@discussion 参见iOS的 AVCaptureSessionPresetXXX的定义
*/
- (CGSize) captureDimension;
/**
@abstract 预览分辨率 (仅在开始采集前设置有效)
@discussion 内部始终将较大的值作为宽度 (若需要竖屏,请设置 videoOrientation)
@discussion 宽高都会向上取整为4的整数倍
@discussion 有效范围: 宽度[160, 1920] 高度[ 90, 1080], 超出范围会取边界有效值
@discussion 当预览分辨率与采集分辨率不一致时:
若宽高比不同, 先进行裁剪, 再进行缩放
若宽高比相同, 直接进行缩放
@discussion 默认值为(640, 360)
*/
@property (nonatomic, assign) CGSize previewDimension;
/**
@abstract 用户定义的视频 **推流** 分辨率
@discussion 有效范围: 宽度[160, 1280] 高度[ 90, 720], 超出范围会取边界有效值
@discussion 其他与previewDimension限定一致,
@discussion 当与previewDimension不一致时, 同样先裁剪到相同宽高比, 再进行缩放
@discussion 默认值为(640, 360)
@see previewDimension
*/
@property (nonatomic, assign) CGSize streamDimension;
/**
@abstract 采集及编码视频帧率 (开始采集前设置有效)
@discussion video frame per seconds 有效范围[1~30], 超出范围会取边界有效值
@discussion 默认值为15 */
@property (nonatomic, assign) int videoFPS;
/**
@abstract 摄像头位置
@discussion 前后摄像头 默认为前摄像头
*/
@property (nonatomic, assign) AVCaptureDevicePosition cameraPosition;
/**
@abstract 获取当前采集设备的指针
@return AVCaptureDevice* 预览开始前调用返回为nil,开始预览后,返回当前正在使用的摄像头
@warning 请勿修改摄像头的像素格式,帧率,分辨率等参数,修改后会导致推流工作异常或崩溃
*/
- (AVCaptureDevice *) getCurrentCameraDevices;
/**
@abstract 采集设备状态
*/
@property (nonatomic, readonly) CNLiveCaptureState captureState;
FOUNDATION_EXPORT NSString *const CNLiveCaptureStateDidChangeNotification NS_AVAILABLE_IOS(7_0);
#pragma mark - stream settings
/**
@abstract 推流状态
*/
@property (nonatomic, readonly) CNLiveStreamState streamState;
FOUNDATION_EXPORT NSString *const CNLiveStreamStateDidChangeNotification NS_AVAILABLE_IOS(7_0);
/**
* @abstract 推流错误码,用于指示推流失败的原因
*/
@property (nonatomic, readonly) CNLiveStreamErrorCode streamErrorCode;
/**
@abstract 切换摄像头
@return TRUE: 成功切换摄像头,开启预览后设置有效
*/
- (BOOL) switchCamera;
/**
@abstract 开关闪光灯
@discussion 切换闪光灯的开关状态 开 <--> 关
@warning 对后摄像头设置有效
*/
- (void) toggleTorch;
- (void) setTorchMode:(AVCaptureTorchMode)mode;
/**
@abstract 摄像头朝向
@discussion 参见UIInterfaceOrientation
@discussion 竖屏时: width < height
@discussion 横屏时: width > height
@discussion 需要与UI方向一致
*/
- (void) setVideoOrientationBy:(UIInterfaceOrientation)uiOrien;
/**
@abstract 启动预览
@param view 预览画面作为subview,插入到 view 的最底层
@discussion 设置完成采集参数之后,按照设置值启动预览,启动后对采集参数修改不会生效
@discussion 需要访问摄像头和麦克风的权限,若授权失败,其他API都会拒绝服务
@warning: 开始推流前必须先启动预览
*/
- (void) startPreview:(UIView*) view;
/**
@abstract 停止预览,停止采集设备,并清理会话
@warning 若推流未结束,则先停止推流
*/
- (void) stopPreview;
/**
@abstract 启动推流
@param hostURL rtmp 服务器地址 “rtmp://xxx.xxx.xxx.xxx/appname/streamKey"
*/
- (void) startStream:(NSURL *)hostURL;
/**
@abstract 停止推流
*/
- (void) stopStream;
/**
@abstract 进入后台: 暂停图像采集
@discussion 暂停图像采集和预览
*/
- (void) appEnterBackground;
/**
@abstract 回到前台: 恢复采集
@discussion 恢复图像采集和预览
*/
- (void) appBecomeActive;
/**
@abstract 退出推流页面时调用
*/
- (void)quitStreaming;
#pragma mark - mirror & rotate
/**
@abstract 预览设置成镜像模式,默认为NO
*/
@property (nonatomic, assign) BOOL previewMirrored;
/**
@abstract 推流设置成镜像模式,默认为NO
*/
@property (nonatomic, assign) BOOL streamerMirrored;
/**
@abstract 根据UI的朝向旋转预览视图, 保证预览视图全屏铺满窗口
@param orie 旋转到目标朝向, 需要从demo中获取UI的朝向传入
@discussion 采集到的图像的朝向还是和启动时的朝向一致
*/
- (void) rotatePreviewTo: (UIInterfaceOrientation) orie;
/**
@abstract 根据UI的朝向旋转推流画面
@param orie 旋转到目标朝向, 需要从demo中获取UI的朝向传入
*/
- (void) rotateStreamTo: (UIInterfaceOrientation) orie;
/**
@abstract 当前采集设备是否支持自动变焦
@param point相机对焦的位置
*/
- (void)focusAtPoint:(CGPoint )point;
/**
@abstract 当前采集设备是否支持自动曝光
@param point相机曝光的位置
*/
- (void)exposureAtPoint:(CGPoint )point;
/**
@abstract 触摸缩放因子
*/
@property (nonatomic, assign) CGFloat pinchZoomFactor;
@end