CNLiveGPUStreamerKit.h
7.99 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
//
// CNLiveGPUStreamerKit.h
// KSYLiveDemo
//
// Created by Android on 16/8/3.
// Copyright © 2016年 Android. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
#import "CNLiveTypeDef.h"
@interface CNLiveGPUStreamerKit : NSObject
/**
@abstract 获取SDK版本号
*/
+ (NSString *)getVersion;
#pragma mark - 使用视讯云平台
/**
@abstract 初始化
@warning 实例化的对象必须赋值给一个全局变量
@param appId 应用ID
@param appKey 注册后的应用key
@param activityId 活动ID,确保SP下的唯一性
@param channelId 主播ID
@param isHorizontalScreen 屏幕方向,0:垂直即竖屏 /1:水平即横屏 ,默认为1
@param success 用于返回初始化状态(成功)
@param failure 用于返回初始化状态(失败)
@warning 必传参数
*/
-(instancetype)initWithDefaultConfigWithAppId:(NSString *)appId
appKey:(NSString *)appKey
activityId:(NSString *)activityId
channelId:(NSString *)channelId
isHorizontalScreen:(NSString *)isHorizontalScreen;
/**
@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))success failure:(void (^)(NSError *error))failure;
/**
@abstract 推流过程中异常通知
*/
FOUNDATION_EXPORT NSString *const CNLiveStreamAbnormalNotification NS_AVAILABLE_IOS(7_0);
/**
@abstract 结束推流成功
*/
FOUNDATION_EXPORT NSString *const CNLiveStreamStopSuccessNotification NS_AVAILABLE_IOS(7_0);
/**
@abstract 结束推流失败
*/
FOUNDATION_EXPORT NSString *const CNLiveStreamStopFailedNotification NS_AVAILABLE_IOS(7_0);
#pragma mark - 普通推流
/**
@abstract 初始化
@warning 实例化的对象必须赋值给一个全局变量
*/
-(instancetype)initWithDefaultConfig;
/**
@abstract 视频分辨率
@discussion width x height ( 此处width始终大于高度,是否竖屏取决于videoOrientation的值 )
*/
@property (nonatomic, assign) CNLiveVideoDimension videoDimension;
/**
@abstract 用户定义的视频分辨率
@discussion 当videoDimension 设置为 CNLiveVideoDimension_UserDefine_* 时有效
@discussion 内部始终将较大的值作为宽度 (若需要竖屏,请设置 videoOrientation)
@discussion 宽高都会向上取整为4的整数倍
@discussion 宽度有效范围[160, 1280]
@discussion 高度有效范围[ 90, 720]
*/
@property (nonatomic, assign) CGSize videoDimensionUserDefine;
/**
@abstract 视频编码器
@discussion video codec used for encode
*/
@property (nonatomic, assign) CNLiveVideoCodec videoCodec;
/**
@abstract 视频编码起始码率(单位:kbps)
@discussion 开始推流时的视频码率,开始推流后,根据网络情况在 [Min, Max]范围内调节
@discussion 视频码率上调则画面更清晰,下调则画面更模糊
*/
@property (nonatomic, assign) int videoInitBitrate;
/**
@abstract 视频编码最高码率(单位:kbps)
@discussion 视频码率自适应调整的上限, 为目标码率
*/
@property (nonatomic, assign) int videoMaxBitrate;
/**
@abstract 视频编码最低码率(单位:kbps)
@discussion 视频码率自适应调整的下限
*/
@property (nonatomic, assign) int videoMinBitrate;
/**
@abstract 最大关键帧间隔(单位:秒, 默认:3)
@discussion 即GOP长度 画面静止时,隔n秒插入一个关键帧
*/
@property (nonatomic, assign) int maxKeyInterval;
/**
@abstract 音频编码码率(单位:kbps)
@discussion 音频目标编码码率 (比如48,96,128等)
*/
@property (nonatomic, assign) int audiokBPS;
/**
@abstract 启用自动调整码率
@discussion 默认为关闭自动调整码率,开始预览前设置有效
*/
@property (nonatomic, assign) BOOL enAutoApplyEstimateBW;
/**
@abstract 视频帧率
@discussion video frame per seconds 有效范围[15~30]
*/
@property (nonatomic, assign) int videoFPS;
/**
@abstract 是否开启美颜
@discussion 默认为开启
*/
@property (nonatomic, assign) BOOL isOpenImageFilter;
/**
@abstract 摄像头位置
@discussion 前后摄像头 默认为前摄像头
*/
@property (nonatomic, assign) AVCaptureDevicePosition cameraPosition;
/**
@abstract 切换摄像头
@return TRUE: 成功切换摄像头,开启预览后设置有效
*/
- (BOOL) switchCamera;
/**
@abstract 开关闪光灯
@discussion 切换闪光灯的开关状态 开 <--> 关
@warning 对后摄像头设置有效
*/
- (void) toggleTorch;
- (void) setTorchMode:(AVCaptureTorchMode)mode;
/**
@abstract 画面朝向描述的是横屏还是竖屏,需要与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 获取当前采集设备的指针
@return AVCaptureDevice* 预览开始前调用返回为nil,开始预览后,返回当前正在使用的摄像头
@warning 请勿修改摄像头的像素格式,帧率,分辨率等参数,修改后会导致推流工作异常或崩溃
*/
- (AVCaptureDevice *) getCurrentCameraDevices;
/**
@abstract 采集设备状态
*/
@property (nonatomic, assign) CNLiveCaptureState captureState;
FOUNDATION_EXPORT NSString *const CNLiveCaptureStateDidChangeNotification NS_AVAILABLE_IOS(7_0);
/**
@abstract 推流状态
*/
@property (nonatomic, assign) CNLiveStreamState streamState;
FOUNDATION_EXPORT NSString *const CNLiveStreamStateDidChangeNotification NS_AVAILABLE_IOS(7_0);
/**
* @abstract 推流错误码,用于指示推流失败的原因
*/
@property (nonatomic, assign) CNLiveStreamErrorCode streamErrorCode;
@end