API目錄
- KY_SetDelegate - 注冊(cè)/反注冊(cè)監(jiān)聽(tīng)回調(diào)接口
- KY_DeviceStatus - 指定通道的連線狀態(tài)回調(diào)
- KY_StartTalkSuccess - 對(duì)講通道建立成功的回調(diào)
- KY_StartListenSuccess - 監(jiān)聽(tīng)通道建立成功的回調(diào)
- KY_UpdateDecodedImage - 獲取解碼后的數(shù)據(jù)回調(diào)
- KY_DecodeVideoFramInfo - 視頻調(diào)試信息回調(diào)
- KY_DidReceiveIOCtrlWithUid - 獲取Command回復(fù)數(shù)據(jù)回調(diào)
- KY_startVideoToDevice - 開(kāi)始預(yù)覽并發(fā)送視頻數(shù)據(jù)
- KY_stopVideoToDevice - 停止預(yù)覽并發(fā)送視頻數(shù)據(jù)
- KY_preview_switchCamera - 切換前后攝像頭
- KY_preview_changePreviewFormat - 更改采集視頻質(zhì)量等級(jí)
- KY_isVideoOutputavChannel - 采集視頻數(shù)據(jù)上拋
- KY_sendVideo - client端開(kāi)啟發(fā)送視頻
- KY_downloadUploadWithUid - 輸出文件傳輸數(shù)據(jù)結(jié)果
回調(diào)接口模塊介紹
回調(diào)接口是Kalay SDK針對(duì)iOS平臺(tái)提供的核心事件通知機(jī)制,用于接收設(shè)備狀態(tài)變更、數(shù)據(jù)傳輸結(jié)果、音視頻處理反饋等關(guān)鍵事件,為APP與設(shè)備的異步交互提供標(biāo)準(zhǔn)化的回調(diào)方式。所有回調(diào)接口均需通過(guò)KY_SetDelegate注冊(cè)監(jiān)聽(tīng)后才能生效。
KY_SetDelegate
功能描述:注冊(cè)/反注冊(cè)監(jiān)聽(tīng)回調(diào)接口。
接口定義
- (void)KY_SetDelegate:(id _Nullable)delegate;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| delegate | id _Nullable | 實(shí)現(xiàn)了KYCameraDelegate協(xié)議的類,nil為反注冊(cè) |
KY_DeviceStatus
功能描述:指定通道的連線狀態(tài)回調(diào)。
接口定義
// 指定通道的連線狀態(tài)回調(diào):
- (void)KY_DeviceStatus:(NSString *)uid Status:(KYDeviceState)status errorCode:(NSInteger)errorCode;
// 指定通道的連線狀態(tài)回調(diào)(指定通道):
- (void)KY_DeviceStatus:(NSString *)uid withChannel:(NSInteger)channel ChannelStatus:(KYDeviceState)status errorCode:(NSInteger)errorCode;
// 指定通道的連線狀態(tài)回調(diào) (調(diào)試模式):
- (void)KY_DeviceStatus:(NSString *)uid withChannel:(NSInteger)channel debugChannelStatus:(NSInteger)status errorCode:(NSInteger)errorCode;
// Bind狀態(tài)回調(diào):
- (void)KY_DeviceStatus:(NSString *)uid didChangeBindStatus:(NSInteger)status credentialInfo:(NSString *)credential errorCode:(NSInteger)errorCode;
// 上拋采集到的yuv數(shù)據(jù):
- (void)KY_outPutVideoData:(NSString *)uid data:(NSData *)data timestamp:(uint64_t)timestamp channel:(NSInteger)channel;
// 視頻發(fā)送通道建立的回調(diào):
- (void)KY_sendVideoSuccess:(NSString *)uid isSuccess:(BOOL)isSuccess ErrorCode:(NSInteger) errorCode;
參數(shù)說(shuō)明
指定通道的連線狀態(tài)回調(diào):
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| status | KYDeviceState | 連線狀態(tài)。詳細(xì)定義參考:KYStatus 枚舉 |
| errorCode | NSInteger | P2P SDK錯(cuò)誤碼 |
指定通道的連線狀態(tài)回調(diào)(指定通道):
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| channel | NSInteger | 設(shè)備連線的channel(默認(rèn)為0) |
| status | KYDeviceState | 連線狀態(tài)。詳細(xì)定義參考:KYStatus 枚舉 |
| errorCode | NSInteger | P2P SDK錯(cuò)誤碼 |
指定通道的連線狀態(tài)回調(diào) (調(diào)試模式):
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| channel | NSInteger | 設(shè)備連線的channel(默認(rèn)為0) |
| status | NSInteger | 連線狀態(tài)。詳細(xì)定義參考:KYStatus 枚舉 |
| errorCode | NSInteger | P2P SDK錯(cuò)誤碼 |
Bind狀態(tài)回調(diào):
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| status | NSInteger | bind結(jié)果。0 成功,other 失敗 |
| credential | NSString * | 連線credential值 |
| errorCode | NSInteger | P2P SDK錯(cuò)誤碼 |
上拋采集到的yuv數(shù)據(jù):
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| data | NSData * | 采集后的yuv數(shù)據(jù) |
| timestamp | uint64_t | 時(shí)間戳 |
| channel | NSInteger | av通道 |
視頻發(fā)送通道建立的回調(diào):
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| isSuccess | BOOL | 是否建立成功 |
| errorCode | NSInteger | 錯(cuò)誤碼 (success: >=0; fail:<0) |
KYStatus 枚舉
| 值 | 說(shuō)明 |
|---|---|
| 0 | _NONE,初始化連線狀態(tài) |
| 1 | _CONNECTING,設(shè)備連線中,未返回狀態(tài) |
| 2 | _CONNECTED,設(shè)備已連線,返回狀態(tài)>= 0 |
| 3 | _DISCONNECTED,設(shè)備未連線,返回狀態(tài) -22 AV其它 |
| 4 | _UNKNOWN_DEVICE,未知設(shè)備,返回狀態(tài) -15 |
| 5 | _WRONG_PASSWORD,設(shè)備連線密碼錯(cuò)誤,返回狀態(tài) -20009 |
| 6 | _TIMEOUT,設(shè)備連線超時(shí),返回狀態(tài)-13 -23 -20016 -20011 |
| 7 | _UNSUPPORTED,不支持設(shè)備,返回狀態(tài)-40 |
| 8 | _CONNECT_FAILED,設(shè)備連線失敗 其它 |
| 9 | _UNKNOWN_LICENSE,設(shè)備uid未在license中,返回狀態(tài) -10 |
| 10 | _SLEEP,設(shè)備睡眠狀態(tài) |
| 11 | _DEVICE_MAX_SESSION,超過(guò)設(shè)備最大連線數(shù),返回狀態(tài)-48 |
| 12 | _POOR_NETWORKSIGNAL,網(wǎng)絡(luò)信號(hào)差,返回狀態(tài) -19 -42 |
| 13 | _WRONG_AUTHKEY,authkey不正確,返回狀態(tài) -46 -68 |
KY_StartTalkSuccess
功能描述:對(duì)講通道建立成功的回調(diào)。
接口定義
- (void)KY_StartTalkSuccess:(NSString * _Nonnull)uid
isSuccess:(BOOL)isSuccess;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| isSuccess | BOOL | 是否建立成功 |
KY_StartListenSuccess
功能描述:監(jiān)聽(tīng)通道建立成功的回調(diào)。
接口定義
- (void)KY_StartListenSuccess:(NSString * _Nonnull)uid
isSuccess:(BOOL)isSuccess;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| isSuccess | BOOL | 是否建立成功 |
返回碼
暫無(wú)
KY_UpdateDecodedImage
功能描述:獲取當(dāng)前設(shè)備指定通道解碼后的數(shù)據(jù)回調(diào)。
接口定義
- (void)KY_UpdateDecodedImage:(NSString * _Nonnull)uid
channel:(NSInteger)channel
timestamp:(int64_t)timestamp
image:(UIImage * _Nullable)image;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| channel | NSInteger | 設(shè)備連線的channel(默認(rèn)為0) |
| timestamp | int64_t | 當(dāng)前解碼成功的幀時(shí)間戳 |
| image | UIImage * _Nullable | 解碼成功產(chǎn)生的UIImage |
KY_DecodeVideoFramInfo
功能描述:指定通道的視頻寬高/fps/bps/在線人數(shù)/幀數(shù)/丟幀數(shù)等調(diào)試信息回調(diào)。
接口定義
- (void)KY_DecodeVideoFramInfo:(NSString * _Nonnull)uid
channel:(NSInteger)channel
connectMode:(NSInteger)connectMode
videoWidth:(NSInteger)videoWidth
videoHeight:(NSInteger)videoHeight
fps:(NSInteger)fps
videoBps:(NSInteger)videoBps
audioBps:(NSInteger)audioBps
onlineNum:(NSInteger)onlineNum
frameCount:(NSInteger)frameCount
incompleteFrameCount:(NSInteger)incompleteFrameCount
isHWDecode:(BOOL)isHWDecode
sessionID:(NSInteger)sessionID
avIndex:(NSInteger)avIndex
cmdNum:(NSInteger)cmdNum
cmdReturn:(NSInteger)cmdReturn;
注:原始文檔中接口定義存在重復(fù)參數(shù) `videoWidth`,已修正為 `videoHeight`。
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| channel | NSInteger | 設(shè)備連線的channel,默認(rèn)為0 |
| connectMode | NSInteger | 連線模式 (-1:NONE,0:P2P,1:RELAY,2:LAN) |
| videoWidth | NSInteger | 視頻寬 |
| videoHeight | NSInteger | 視頻高 |
| fps | NSInteger | fps |
| videoBps | NSInteger | 視頻bps |
| audioBps | NSInteger | 音頻bps |
| onlineNum | NSInteger | 在線人數(shù) |
| frameCount | NSInteger | 幀數(shù) |
| incompleteFrameCount | NSInteger | 丟幀數(shù) |
| isHWDecode | BOOL | 是否是硬解 |
| sessionID | NSInteger | 連線返回的session號(hào) |
| avIndex | NSInteger | 開(kāi)啟通道返回的av通道 |
| cmdNum | NSInteger | command指令類型值 |
| cmdReturn | NSInteger | command指令返回值 |
注:原始表格中參數(shù) `onlineNm` 和 `avChannelIndex` 與接口定義不一致,已根據(jù)接口定義修正為 `onlineNum` 和 `avIndex`。
KY_DidReceiveIOCtrlWithUid
功能描述:獲取設(shè)備回復(fù)Command的數(shù)據(jù)信息回調(diào)。
接口定義
- (void)KY_DidReceiveIOCtrlWithUid:(NSString * _Nonnull)uid
channel:(NSInteger)channel
type:(ENUM_AVIOCTRL_MSGTYPE)type
data:(NSData * _Nonnull)data;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| channel | NSInteger | 設(shè)備連線的channel,默認(rèn)為0 |
| type | ENUM_AVIOCTRL_MSGTYPE | command指令類型,AVIOCTRLDEFs.h |
| data | NSData * | command對(duì)應(yīng)指令的結(jié)構(gòu)體數(shù)據(jù) |
KY_startVideoToDevice
功能描述:開(kāi)始預(yù)覽并發(fā)送視頻數(shù)據(jù)。
接口定義
- (void)KY_startVideoToDevice:(UIView *)previewView
previewFormat:(PreviewFormat)previewFormat
channel:(NSInteger)channel
ScreenObject:(NSObject*)obScreen;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| previewView | UIView * | 預(yù)覽視圖 |
| previewFormat | PreviewFormat | 編碼格式 |
| channel | NSInteger | 通道號(hào) |
| obScreen | NSObject * | 屏幕顯示對(duì)象 |
代碼示例
PreviewFormat *format = (PreviewFormat *)malloc(sizeof(PreviewFormat));
format->resolution = PreviewResolution_Low;
format->fps = PreviewFPS_Low;
format->gop = PreviewGOP_Low;
format->orientation = AVCaptureVideoOrientationPortrait;
format->bitrate = PreviewBitRate_Low;
[self.camera KY_startVideoToDevice:self.preView previewFormat:*format channel:self.selectChannel ScreenObject:self];
KY_stopVideoToDevice
功能描述:停止預(yù)覽并發(fā)送視頻數(shù)據(jù)。
接口定義
- (void)KY_stopVideoToDevice:(NSInteger)channel;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| channel | NSInteger | 設(shè)備連線的channel,默認(rèn)為0 |
代碼示例
[self.camera KY_stopVideoToDevice:self.selectChannel];
KY_preview_switchCamera
功能描述:切換前后攝像頭。
接口定義
- (void)TK_preview_switchCamera:(AVCaptureDevicePosition)positon;
注:接口命名為 `TK_preview_switchCamera`,可能是一個(gè)筆誤,應(yīng)為 `KY_preview_switchCamera`。
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| positon | AVCaptureDevicePosition | 設(shè)置攝像頭 |
代碼示例
[self.camera TK_preview_switchCamera:AVCaptureDevicePositionFront];
KY_preview_changePreviewFormat
功能描述:更改采集的視頻質(zhì)量等級(jí)。
接口定義
- (void)KY_preview_changePreviewFormat:(PreviewFormat)previewFormat
presetBlock:(PresetBlock)presetBlock;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| previewFormat | PreviewFormat | 編碼格式 |
| presetBlock | PresetBlock | 回調(diào)是否支持 |
代碼示例
PreviewFormat *format = (PreviewFormat *)malloc(sizeof(PreviewFormat));
format->resolution = PreviewResolution_Low;
format->fps = PreviewFPS_Low;
format->gop = PreviewGOP_Low;
format->orientation = AVCaptureVideoOrientationPortrait;
format->bitrate = PreviewBitRate_Low;
[self.camera KY_preview_changePreviewFormat:format presetBlock:^{
}];
KY_isVideoOutputavChannel
功能描述:采集視頻數(shù)據(jù)上拋。
接口定義
- (void)KY_isVideoOutputavChannel:(NSInteger)avChannel
isSendVideo:(BOOL)isSendVideo;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| avChannel | NSInteger | av通道號(hào) |
| isSendVideo | BOOL | 發(fā)送上拋 |
代碼示例
[self.camera KY_isVideoOutputavChannel:0 isSendVideo:YES];
KY_sendVideo
功能描述:client端開(kāi)啟發(fā)送視頻。
接口定義
- (void) KY_sendVideo:(NSData *)videoData
Length:(NSInteger)length
Codec:(NSInteger)codec
isKeyFrame:(BOOL)isKeyFrame
channel:(NSInteger)channel;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| videoData | NSData * | 視頻數(shù)據(jù) |
| length | NSInteger | 視頻數(shù)據(jù)長(zhǎng)度 |
| codec | NSInteger | 視頻編碼格式 |
| isKeyFrame | BOOL | 是否是關(guān)鍵幀 |
| channel | NSInteger | av通道 |
代碼示例
[self.camera KY_sendVideo:data Length:data.length Codec:MEDIA_CODEC_VIDEO_H264 isKeyFrame:isKeyFrame channel:channell];
KY_downloadUploadWithUid
功能描述:輸出文件下載或上傳的數(shù)據(jù)結(jié)果。
接口定義
- (void)KY_downloadUploadWithUid:(NSString *)uid fileName:(NSString *)fileName progress:(NSInteger)progress loadType:(FILETransferType)type result:(NSInteger)result channel:(NSInteger)channel;
參數(shù)說(shuō)明
| 參數(shù) | 類型 | 說(shuō)明 |
|---|---|---|
| uid | NSString * | 當(dāng)前設(shè)備的uid |
| fileName | NSString * | 文件名稱 |
| progress | NSInteger | 文件傳輸進(jìn)度 |
| type | FILETransferType | 傳輸方式。詳細(xì)定義參考:KYTransferType 枚舉 |
| result | NSInteger | 傳輸結(jié)果 |
| channel | NSInteger | 通道號(hào) |
