KSYStreamerPublic.h
5.69 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
//
// KSYStreamerPublic.h
// Pods
//
// Created by 江东 on 17/6/28.
//
//
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
#import "KSYTypeDef.h"
@interface KSYStreamerPublic : NSObject
/**
带鉴权的构造实例
@param token 鉴权信息, 请联系商务获取
@param error 鉴权过程中的错误信息
@return 新构造的实例
*/
- (instancetype) initWithToken:(NSString*) token
error:(NSError**) error;
/**
@abstract 推流参数配置
*/
- (void) setStreamerCfg;
/**
@abstract 启动推流
@param url 目标地址
@discussion 实现直播功能时, url为 rtmp 服务器地址 “rtmp://xxx.xx/appname/streamKey"
@discussion 设置完成推流参数之后,将媒体流推送到 publishURL 对应的地址
@discussion 实现本地录制功能时, url为本地文件地址 "/var/xxx/xx.mp4"
@discussion 本地录制支持mp4和flv两种输出格式, 通过url的文件后缀指定
@discussion 推流参数主要是视频编码器,音视频码率的设置
@see hostURL, videoCodec,videokBPS,audiokBPS
*/
- (void) startStream: (NSURL*) url;
/**
@abstract 停止推流
@discussion 断开网络连接 或停止文件写入
*/
- (void) stopStream;
/**
@abstract 处理一个视频帧(只支持编码前的原始图像数据)
@param sampleBuffer Buffer to process
@discussion 应当在开始推流前定期调用此接口,比如按照采集帧率调用
@discussion 支持的图像格式包括: BGR0,NV12,YUVA444P,YUV420P
*/
- (void)processVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer;
/**
@abstract 处理一个视频帧(只支持编码前的原始图像数据)
@param pixelBuffer 待编码的像素数据
@param timeStamp 待编码的时间戳
@discussion 应当在开始推流前定期调用此接口,比如按照采集帧率调用
@discussion 支持的图像格式包括: BGR0,NV12,YUVA444P,YUV420P
*/
- (void)processVideoPixelBuffer:(CVPixelBufferRef)pixelBuffer
timeInfo:(CMTime)timeStamp;
/**
@abstract 处理一段音频数据
@param sampleBuffer Buffer to process
@discussion 应当在开始推流前定期调用此接口,与processVideoSampleBuffer 交错进行
@warning 目前只支持 单通道 S16 格式的PCM数据
*/
- (void)processAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer;
#pragma mark - configures
/**
@abstract 视频帧率 默认:15
@discussion 请保持调用 processVideoSampleBuffer 或 processVideoPixelBuffer 的频率与此设置的帧率一致
@discussion 当实际送入的视频帧率过高时会主动丢帧
@discussion video frame per seconds 有效范围[1~30], 超出会提示参数错误
*/
@property (nonatomic, assign) int videoFPS;
/**
@abstract 视频编码器 默认为 自动选择
@discussion video codec used for encode
@see KSYVideoCodec
*/
@property (nonatomic, assign) KSYVideoCodec videoCodec;
/**
@abstract 音频编码器 (默认为AAC-HE)
@discussion audio codec used for encode
@see KSYAudioCodec
*/
@property (nonatomic, assign) KSYAudioCodec audioCodec;
/**
@abstract 视频编码起始码率(单位:kbps, 默认:500)
@discussion 开始推流时的视频码率,开始推流后,根据网络情况在Min~Max范围内调节
@discussion 视频码率上调则画面更清晰,下调则画面更模糊
@see videoMaxBitrate, videoMinBitrate
*/
@property (nonatomic, assign) int videoInitBitrate; // kbit/s of video
/**
@abstract 视频编码最高码率(单位:kbps, 默认:800)
@discussion 视频码率自适应调整的上限, 为目标码率
@see videoInitBitrate, videoMinBitrate
*/
@property (nonatomic, assign) int videoMaxBitrate; // kbit/s of video
/**
@abstract 视频编码最低码率(单位:kbps, 默认:200)
@discussion 视频码率自适应调整的下限
@see videoInitBitrate, videoMaxBitrate
*/
@property (nonatomic, assign) int videoMinBitrate; // kbit/s of video
/**
@abstract 音频编码码率(单位:kbps)
@discussion 音频目标编码码率 (比如48,96,128等)
*/
@property (nonatomic, assign) int audiokBPS; // kbit/s of audio
#pragma mark - Status Notification
/**
@abstract 获取当前推流状态对应的字符串
@return 当前状态名称
*/
- (NSString*) getCurStreamStateName;
/**
@abstract 获取当前错误码对应的字符串
*/
- (NSString*) getCurKSYStreamErrorCodeName;
/**
@abstract 当前推流的错误码
@discussion 可以通过该属性获取推流失败的原因
@discussion 当streamState 为KSYStreamStateError时可查询
@discussion KSYStreamErrorCode_KSYAUTHFAILED 除外
@discussion 在streamState 为KSYStreamStateConnected 时查询到
@discussion 状态变化后清0
@see streamState
*/
@property (nonatomic, readonly) KSYStreamErrorCode streamErrorCode;
/**
@abstract 当前推流状况
@discussion 可以通过该属性获取推流会话的工作状况
@discussion 通知:
* KSYStreamPubilcStateDidChangeNotification 当推流工作状态发生变化时提供通知
* 收到通知后,通过本属性查询新的状态,并作出相应的动作
*/
@property (nonatomic, readonly) KSYStreamState streamState;
/**
@abstract 发生推流状态变化时的回调函数
@discussion 参数为新状态
*/
@property (nonatomic, copy)void (^streamStateChange)(KSYStreamState newState);
/**
@abstract 查询当前是否处于推流状态 (建立连接中, 或连接中)
*/
- (BOOL) isStreaming;
/**
@abstract 获取当前SDK过期时间
@discussion 为nil时,可以永久使用不会过期
*/
@property (nonatomic, readonly) NSDate *expireDate;
// Posted when stream state changes
FOUNDATION_EXPORT NSString *const KSYStreamPubilcStateDidChangeNotification NS_AVAILABLE_IOS(7_0);
@end