-
Notifications
You must be signed in to change notification settings - Fork 209
Info&Error_Listener
buliaoyin edited this page Aug 23, 2017
·
19 revisions
状态错误回调
KSYStreamer中提供以下两种回调接口:
- OnInfoListener 推流过程中状态变更事件回调,事件触发时不影响推流,状态码为正数
- OnErrorListener 推流过程中错误事件回调,事件触发时,sdk内部会停止推流。状态码为负数
注:
- 所有的回调都在主线程,不需要再切换回主线程
- 状态码和错误码的定义在StreamerConstants中,不要使用RecordConstants中的定义
名称 | 数值 | 含义 | msg1 |
---|---|---|---|
KSY_STREAMER_CAMERA_INIT_DONE | 1000 | 初始化完毕 | N/A |
KSY_STREAMER_OPEN_STREAM_SUCCESS | 0 | 推流成功 | N/A |
KSY_STREAMER_FRAME_SEND_SLOW | 3001 | 网络状态不佳,数据发送可能有延迟 | 发送当前帧的时长 |
KSY_STREAMER_EST_BW_RAISE | 3002 | 码率上调了 | 码率上调的目标值 单位bps |
KSY_STREAMER_EST_BW_DROP | 3003 | 码率下调了 | 码率下调到的值 单位bps |
名称 | 数值 | 含义 | msg1 |
---|---|---|---|
KSY_STREAMER_RTMP_ERROR_UNKNOWN | -3000 | RTMP推流未知错误 | N/A |
KSY_STREAMER_ERROR_DNS_PARSE_FAILED | -1009 | url域名解析失败 | N/A |
KSY_STREAMER_ERROR_CONNECT_FAILED | -1006 | 网络连接失败,无法建立连接 | N/A |
KSY_STREAMER_ERROR_PUBLISH_FAILED | -1010 | 跟RTMP服务器完成握手后,向{streamname}推流失败) | N/A |
KSY_STREAMER_ERROR_CONNECT_BREAKED | -1007 | 网络连接断开 | N/A |
KSY_STREAMER_ERROR_AV_ASYNC | -2004 | 音视频采集pts差值超过5s | 音视频采集pts具体差值,单位ms |
KSY_STREAMER_VIDEO_ENCODER_ERROR_UNSUPPORTED | -1004 | 编码器初始化失败 | N/A |
KSY_STREAMER_VIDEO_ENCODER_ERROR_UNKNOWN | -1003 | 视频编码失败 | N/A |
KSY_STREAMER_AUDIO_ENCODER_ERROR_UNSUPPORTED | -1008 | 音频初始化失败 | N/A |
KSY_STREAMER_AUDIO_ENCODER_ERROR_UNKNOWN | -1011 | 音频编码失败 | N/A |
KSY_STREAMER_CAMERA_ERROR_UNKNOWN | -2001 | 摄像头未知错误 | N/A |
KSY_STREAMER_CAMERA_ERROR_START_FAILED | -2002 | 打开摄像头失败 | N/A |
KSY_STREAMER_CAMERA_ERROR_SERVER_DIED | -2006 | 系统Camera服务进程退出 | N/A |
KSY_STREAMER_AUDIO_RECORDER_ERROR_START_FAILED | -2003 | 录音开启失败 | N/A |
KSY_STREAMER_AUDIO_RECORDER_ERROR_UNKNOWN | -2005 | 录音开启未知错误 | N/A |
KSY_STREAMER_CAMERA_ERROR_EVICTED | -2007 | Camera服务异常退出 | N/A |
金山云扩展的RTMP推流错误码:
名称 | 数值 | 含义 |
---|---|---|
KSY_STREAMER_RTMP_ERROR_NonExistDomain | -3101 | RTMP推流域名不存在 |
KSY_STREAMER_RTMP_ERROR_NonExistApplication | -3102 | RTMP应用名不存在 |
KSY_STREAMER_RTMP_ERROR_AlreadyExistStreamName | -3103 | RTMP流名已存在 |
KSY_STREAMER_RTMP_ERROR_ForbiddenByBlacklist | -3104 | RTMP推流被黑名单拒绝 |
KSY_STREAMER_RTMP_ERROR_InternalError | -3105 | RTMP server内部错误 |
KSY_STREAMER_RTMP_ERROR_URLExpired | -3106 | RTMP URL地址已过期 |
KSY_STREAMER_RTMP_ERROR_SignatureDoesNotMatch | -3107 | RTMP URL 地址签名错误 |
KSY_STREAMER_RTMP_ERROR_InvalidAccessKeyId | -3108 | RTMP URL 中AccessKeyId非法 |
KSY_STREAMER_RTMP_ERROR_BadParams | -3109 | RTMP URL 中参数错误 |
KSY_STREAMER_RTMP_ERROR_ForbiddenByRegion | -3110 | RTMP URL 中的推流不在发布点内 |
KSY_STREAMER_RTMP_ERROR_GetUserIdFailed | -3111 | 获取用户ID失败 |
KSY_STREAMER_RTMP_ERROR_AkAndUserIsNotMatch | -3112 | AK和用户ID不匹配 |
KSY_STREAMER_RTMP_ERROR_GetServerInfoFailed | -3113 | 获取服务器信息失败 |
KSY_STREAMER_RTMP_ERROR_IllegalOutsideUrl | -3114 | 非法的外部URL |
KSY_STREAMER_RTMP_ERROR_OutsideAuthFailed | -3115 | 外部鉴权失败 |
KSY_STREAMER_RTMP_ERROR_SimpleAuthFailed | -3116 | 简单鉴权失败 |
KSY_STREAMER_RTMP_ERROR_InvalidAuthType | -3117 | 鉴权类型非法 |
KSY_STREAMER_RTMP_ERROR_IllegalUserId | -3118 | 用户ID非法 |
示例代码(CameraActiviy中mOnInfoListener和mOnErrorListener)
//状态回调
private KSYStreamer.OnInfoListener mOnInfoListener = new KSYStreamer.OnInfoListener() {
@Override
public void onInfo(int what, int msg1, int msg2) {
switch (what) {
case StreamerConstants.KSY_STREAMER_CAMERA_INIT_DONE:
Log.d(TAG, "KSY_STREAMER_CAMERA_INIT_DONE");
setCameraAntiBanding50Hz();
if (mAutoStart) {
startStream();
}
break;
case StreamerConstants.KSY_STREAMER_OPEN_STREAM_SUCCESS:
Log.d(TAG, "KSY_STREAMER_OPEN_STREAM_SUCCESS");
mChronometer.setBase(SystemClock.elapsedRealtime());
mChronometer.start();
beginInfoUploadTimer();
break;
case StreamerConstants.KSY_STREAMER_FRAME_SEND_SLOW:
Log.d(TAG, "KSY_STREAMER_FRAME_SEND_SLOW " + msg1 + "ms");
Toast.makeText(CameraActivity.this, "Network not good!",
Toast.LENGTH_SHORT).show();
break;
case StreamerConstants.KSY_STREAMER_EST_BW_RAISE:
Log.d(TAG, "BW raise to " + msg1 / 1000 + "kbps");
break;
case StreamerConstants.KSY_STREAMER_EST_BW_DROP:
Log.d(TAG, "BW drop to " + msg1 / 1000 + "kpbs");
break;
default:
Log.d(TAG, "OnInfo: " + what + " msg1: " + msg1 + " msg2: " + msg2);
break;
}
}
};
//错误回调
private KSYStreamer.OnErrorListener mOnErrorListener = new KSYStreamer.OnErrorListener() {
@Override
public void onError(int what, int msg1, int msg2) {
switch (what) {
case StreamerConstants.KSY_STREAMER_ERROR_DNS_PARSE_FAILED:
Log.d(TAG, "KSY_STREAMER_ERROR_DNS_PARSE_FAILED");
break;
case StreamerConstants.KSY_STREAMER_ERROR_CONNECT_FAILED:
Log.d(TAG, "KSY_STREAMER_ERROR_CONNECT_FAILED");
break;
case StreamerConstants.KSY_STREAMER_ERROR_PUBLISH_FAILED:
Log.d(TAG, "KSY_STREAMER_ERROR_PUBLISH_FAILED");
break;
case StreamerConstants.KSY_STREAMER_ERROR_CONNECT_BREAKED:
Log.d(TAG, "KSY_STREAMER_ERROR_CONNECT_BREAKED");
break;
case StreamerConstants.KSY_STREAMER_ERROR_AV_ASYNC:
Log.d(TAG, "KSY_STREAMER_ERROR_AV_ASYNC " + msg1 + "ms");
break;
case StreamerConstants.KSY_STREAMER_VIDEO_ENCODER_ERROR_UNSUPPORTED:
Log.d(TAG, "KSY_STREAMER_VIDEO_ENCODER_ERROR_UNSUPPORTED");
break;
case StreamerConstants.KSY_STREAMER_VIDEO_ENCODER_ERROR_UNKNOWN:
Log.d(TAG, "KSY_STREAMER_VIDEO_ENCODER_ERROR_UNKNOWN");
break;
case StreamerConstants.KSY_STREAMER_AUDIO_ENCODER_ERROR_UNSUPPORTED:
Log.d(TAG, "KSY_STREAMER_AUDIO_ENCODER_ERROR_UNSUPPORTED");
break;
case StreamerConstants.KSY_STREAMER_AUDIO_ENCODER_ERROR_UNKNOWN:
Log.d(TAG, "KSY_STREAMER_AUDIO_ENCODER_ERROR_UNKNOWN");
break;
case StreamerConstants.KSY_STREAMER_AUDIO_RECORDER_ERROR_START_FAILED:
Log.d(TAG, "KSY_STREAMER_AUDIO_RECORDER_ERROR_START_FAILED");
break;
case StreamerConstants.KSY_STREAMER_AUDIO_RECORDER_ERROR_UNKNOWN:
Log.d(TAG, "KSY_STREAMER_AUDIO_RECORDER_ERROR_UNKNOWN");
break;
case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_UNKNOWN:
Log.d(TAG, "KSY_STREAMER_CAMERA_ERROR_UNKNOWN");
break;
case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_START_FAILED:
Log.d(TAG, "KSY_STREAMER_CAMERA_ERROR_START_FAILED");
break;
case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_SERVER_DIED:
Log.d(TAG, "KSY_STREAMER_CAMERA_ERROR_SERVER_DIED");
break;
default:
Log.d(TAG, "what=" + what + " msg1=" + msg1 + " msg2=" + msg2);
break;
}
switch (what) {
case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_UNKNOWN:
case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_START_FAILED:
case StreamerConstants.KSY_STREAMER_AUDIO_RECORDER_ERROR_START_FAILED:
case StreamerConstants.KSY_STREAMER_AUDIO_RECORDER_ERROR_UNKNOWN:
break;
case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_SERVER_DIED:
mStreamer.stopCameraPreview();
mMainHandler.postDelayed(new Runnable() {
@Override
public void run() {
startCameraPreviewWithPermCheck();
}
}, 5000);
break;
default:
stopStream();
mMainHandler.postDelayed(new Runnable() {
@Override
public void run() {
startStream();
}
}, 3000);
break;
}
}
};