trtc-electron-sdk
Version:
trtc electron sdk
388 lines (387 loc) • 19.7 kB
TypeScript
/**
* V2Live 关键类型定义
*/
export declare enum V2LiveCode {
V2LIVE_OK = 0,
V2LIVE_ERROR_FAILED = -1,
V2LIVE_ERROR_INVALID_PARAMETER = -2,
V2LIVE_ERROR_REFUSED = -3,
V2LIVE_ERROR_NOT_SUPPORTED = -4,
V2LIVE_ERROR_INVALID_LICENSE = -5,
V2LIVE_ERROR_REQUEST_TIMEOUT = -6,
V2LIVE_ERROR_SERVER_PROCESS_FAILED = -7,
V2LIVE_ERROR_DISCONNECTED = -8,
V2LIVE_ERROR_NO_AVAILABLE_HEVC_DECODERS = -2304,
V2LIVE_WARNING_NETWORK_BUSY = 1101,
V2LIVE_WARNING_VIDEO_BLOCK = 2105
}
export declare enum V2LiveMode {
V2LiveModeRTMP = 0,
V2LiveModeRTC = 1
}
/**
* @namespace V2LivePusherEvent
* @description V2LivePusher 事件定义
*
*/
export declare enum V2LivePusherEvent {
/**
* @description 错误回调:SDK 不可恢复的错误,一定要监听,并分情况给用户适当的界面提示。
*
* @event V2LivePusherEvent#onError
* @param {Number} errCode - 错误码
* @param {String} errMsg - 错误信息
*/
onError = "onError",
/**
* @description 警告回调:SDK 可恢复的错误,需要监听,并给用户适当的界面提示。
*
* @event V2LivePusherEvent#onWarning
* @param {Number} warnCode - 警告码
* @param {String} warnMsg - 警告信息
*/
onWarning = "onWarning",
/**
* @description 音频采集状态回调:音频采集状态回调。
*
* @event V2LivePusherEvent#onCaptureFirstAudioFrame
*/
onCaptureFirstAudioFrame = "onCaptureFirstAudioFrame",
/**
* @description 视频采集状态回调:视频采集状态回调。
*
* @event V2LivePusherEvent#onCaptureFirstVideoFrame
*/
onCaptureFirstVideoFrame = "onCaptureFirstVideoFrame",
/**
* @description 麦克风音量回调:麦克风音量回调。
*
* @event V2LivePusherEvent#onMicrophoneVolumeUpdate
* @param {Number} volume - 麦克风音量
*/
onMicrophoneVolumeUpdate = "onMicrophoneVolumeUpdate",
/**
* @description 推流状态更新回调:推流状态更新回调。
*
* @event V2LivePusherEvent#onPushStatusUpdate
* @param {Number} status - 推流状态
* @param {String} message - 推流状态信息
*/
onPushStatusUpdate = "onPushStatusUpdate",
/**
* @description 推流统计回调:推流统计信息变化时,会回调该接口。
*
* @event V2LivePusherEvent#onStatisticsUpdate
* @param {V2LivePusherStatistics} statistics - 推流统计信息
*/
onStatisticsUpdate = "onStatisticsUpdate"
}
/**
* @namespace V2LivePlayerEvent
* @description V2LivePlayer 事件定义
*
*/
export declare enum V2LivePlayerEvent {
/**
* @description 错误回调:直播播放器错误通知,播放器出现错误时,会回调该通知。
*
* @event V2LivePlayerEvent#onError
* @param {Number} errCode - 错误码
* @param {String} errMsg - 错误信息
*/
onError = "onError",
/**
* @description 直播播放器警告通知。
*
* @event V2LivePlayerEvent#onError
* @param {Number} warnCode - 警告码
* @param {String} warnMsg - 警告信息
*/
onWarning = "onWarning",
/**
* @description 直播播放器分辨率变化通知。
*
* @event V2LivePlayerEvent#onVideoResolutionChanged
* @param {Number} width - 视频宽。
* @param {Number} height - 视频高。
*/
onVideoResolutionChanged = "onVideoResolutionChanged",
/**
* @description 已经成功连接到服务器。
*
* @event V2LivePlayerEvent#onConnected
*/
onConnected = "onConnected",
/**
* @description 视频播放事件。
*
* @event V2LivePlayerEvent#onVideoPlaying
* @param {Boolean} firstPlay - 第一次播放标志。
*/
onVideoPlaying = "onVideoPlaying",
/**
* @description 音频播放事件。
*
* @event V2LivePlayerEvent#onAudioPlaying
* @param {Boolean} firstPlay - 第一次播放标志。
*/
onAudioPlaying = "onAudioPlaying",
/**
* @description 视频加载事件。
*
* @event V2LivePlayerEvent#onVideoLoading
*/
onVideoLoading = "onVideoLoading",
/**
* @description 音频加载事件。
*
* @event V2LivePlayerEvent#onAudioLoading
*/
onAudioLoading = "onAudioLoading",
/**
* @description 播放器音量大小回调。
*
* @event V2LivePlayerEvent#onPlayoutVolumeUpdate
* @param {Number} volume - 音量大小。
*/
onPlayoutVolumeUpdate = "onPlayoutVolumeUpdate",
/**
* @description 直播播放器统计数据回调。
*
* @event V2LivePlayerEvent#onStatisticsUpdate
* @param {V2TXLivePlayerStatistics} statistics - 播放器统计数据。
*/
onStatisticsUpdate = "onStatisticsUpdate",
/**
* @description 分辨率无缝切换回调。
*
* @event V2LivePlayerEvent#onStreamSwitched
* @param {String} url - 流地址。
* @param {Number} code - 状态码,0:成功,-1:切换超时,-2:切换失败,服务端错误,-3:切换失败,客户端错误。
*/
onStreamSwitched = "onStreamSwitched"
}
export declare enum V2LiveVideoResolution {
V2LiveVideoResolution160x160 = 0,
V2LiveVideoResolution270x270 = 1,
V2LiveVideoResolution480x480 = 2,
V2LiveVideoResolution320x240 = 3,
V2LiveVideoResolution480x360 = 4,
V2LiveVideoResolution640x480 = 5,
V2LiveVideoResolution320x180 = 6,
V2LiveVideoResolution480x270 = 7,
V2LiveVideoResolution640x360 = 8,
V2LiveVideoResolution960x540 = 9,
V2LiveVideoResolution1280x720 = 10,
V2LiveVideoResolution1920x1080 = 11
}
export declare enum V2LiveVideoResolutionMode {
V2LiveVideoResolutionModeLandscape = 0,
V2LiveVideoResolutionModePortrait = 1
}
/**
* 视频编码参数
*
* 该设置决定远端用户看到的画面质量。、
*
* @param {V2LiveVideoResolution} videoResolution - 【字段含义】 视频分辨率。
* - 【特别说明】如需使用竖屏分辨率,请指定 videoResolutionMode 为 Portrait,例如: 640 × 360 + Portrait = 360 × 640。
* - 【推荐取值】
* - 注意:桌面平台(Win + Mac):建议选择 640 × 360 及以上分辨率,videoResolutionMode 选择 Landscape,即横屏分辨率。
* @param {V2LiveVideoResolutionMode} videoResolutionMode - 【字段含义】分辨率模式(横屏分辨率 or 竖屏分辨率)。
* - 【推荐取值】桌面平台(Windows、Mac)建议选择 Landscape。
* - 【特别说明】如需使用竖屏分辨率,请指定 resMode 为 Portrait,例如: 640 × 360 + Portrait = 360 × 640。
* @param {Number} videoFps - 【字段含义】视频采集帧率。
* - 【推荐取值】15fps 或 20fps。5fps 以下,卡顿感明显。10fps 以下,会有轻微卡顿感。20fps 以上,会浪费带宽(电影的帧率为 24fps)。
* @param {Number} videoBitrate - 【字段含义】目标视频码率,SDK 会按照目标码率进行编码,只有在弱网络环境下才会主动降低视频码率。
* - 【推荐取值】请参考 V2LiveVideoResolution 在各档位注释的最佳码率,也可以在此基础上适当调高。
* - 比如:V2LiveVideoResolution1280x720 对应 1200kbps 的目标码率,您也可以设置为 1500kbps 用来获得更好的观感清晰度。
* - 【特别说明】您可以通过同时设置 videoBitrate 和 minVideoBitrate 两个参数,用于约束 SDK 对视频码率的调整范围:
* - 如果您将 videoBitrate 和 minVideoBitrate 设置为同一个值,等价于关闭 SDK 对视频码率的自适应调节能力。
* @param {Number} minVideoBitrate - 【字段含义】最低视频码率,SDK 会在网络不佳的情况下主动降低视频码率以保持流畅度,最低会降至 minVideoBitrate 所设定的数值。
* - 【推荐取值】您可以通过同时设置 videoBitrate 和 minVideoBitrate 两个参数,用于约束 SDK 对视频码率的调整范围:
* - 如果您将 videoBitrate 和 minVideoBitrate 设置为同一个值,等价于关闭 SDK 对视频码率的自适应调节能力。
*/
export declare class V2LiveVideoEncoderParam {
videoResolution: V2LiveVideoResolution;
videoResolutionMode: V2LiveVideoResolutionMode;
videoFps: number;
videoBitrate: number;
minVideoBitrate: number;
constructor(videoResolution?: V2LiveVideoResolution, videoResolutionMode?: V2LiveVideoResolutionMode, videoFps?: number, videoBitrate?: number, minVideoBitrate?: number);
}
export declare enum V2LiveMirrorType {
V2LiveMirrorTypeAuto = 0,
V2LiveMirrorTypeEnable = 1,
V2LiveMirrorTypeDisable = 2
}
export declare enum V2LiveFillMode {
V2LiveFillModeFill = 0,
V2LiveFillModeFit = 1
}
export declare enum V2LiveRotation {
V2LiveRotation0 = 0,
V2LiveRotation90 = 1,
V2LiveRotation180 = 2,
V2LiveRotation270 = 3
}
export declare enum V2LivePixelFormat {
V2LivePixelFormatUnknown = 0,
V2LivePixelFormatI420 = 1,
V2LivePixelFormatBGRA32 = 2,
V2LivePixelFormatRGBA32 = 3
}
export declare enum V2LiveBufferType {
V2LiveBufferTypeUnknown = 0,
V2LiveBufferTypeByteBuffer = 1
}
export declare enum V2LiveAudioQuality {
V2LiveAudioQualitySpeech = 0,
V2LiveAudioQualityDefault = 1,
V2LiveAudioQualityMusic = 2
}
/**
* 推流器的统计数据
*
* @param {Number} appCpu - 当前 App 的 CPU 使用率(%)
* @param {Number} systemCpu - 当前系统的 CPU 使用率(%)
* @param {Number} width - 视频宽度
* @param {Number} height - 视频高度
* @param {Number} fps - 帧率(fps)
* @param {Number} videoBitrate - 视频码率(Kbps)
* @param {Number} audioBitrate - 音频码率(Kbps)
* @param {Number} rtt - 从 SDK 到云端的往返延时(ms)
* @param {Number} netSpeed - 上行速度(kbps)
*/
export declare class V2LivePusherStatistics {
appCpu: number;
systemCpu: number;
width: number;
height: number;
fps: number;
videoBitrate: number;
audioBitrate: number;
rtt: number;
netSpeed: number;
constructor(appCpu?: number, systemCpu?: number, width?: number, height?: number, fps?: number, videoBitrate?: number, audioBitrate?: number, rtt?: number, netSpeed?: number);
}
/**
* 推流器的统计数据
*
* @param {Number} appCpu - 当前 App 的 CPU 使用率(%)
* @param {Number} systemCpu - 当前系统的 CPU 使用率(%)
* @param {Number} width - 视频宽度
* @param {Number} height - 视频高度
* @param {Number} fps - 帧率(fps)
* @param {Number} videoBitrate - 视频码率(Kbps)
* @param {Number} audioBitrate - 音频码率(Kbps)
* @param {Number} audioPacketLoss - 网络音频丢包率(%),注:仅支持前缀为 [trtc://] 或 [webrtc://] 的播放地址
* @param {Number} videoPacketLoss - 网络视频丢包率(%),注:仅支持前缀为 [trtc://] 或 [webrtc://] 的播放地址
* @param {Number} jitterBufferDelay - 播放延迟(ms)
* @param {Number} audioTotalBlockTime - 音频播放的累计卡顿时长(ms),该时长为区间(2s)内的卡顿时长
* @param {Number} audioBlockRate - 音频播放卡顿率,单位(%)
* @param {Number} videoTotalBlockTime - 视频播放的累计卡顿时长(ms),该时长为区间(2s)内的卡顿时长
* @param {Number} videoBlockRate - 视频播放卡顿率,单位(%)
* @param {Number} rtt - 从 SDK 到云端的往返延时(ms)
* @param {Number} netSpeed - 上行速度(kbps)
*/
export declare class V2LivePlayerStatistics {
appCpu: number;
systemCpu: number;
width: number;
height: number;
fps: number;
videoBitrate: number;
audioBitrate: number;
audioPacketLoss: number;
videoPacketLoss: number;
jitterBufferDelay: number;
audioTotalBlockTime: number;
audioBlockRate: number;
videoTotalBlockTime: number;
videoBlockRate: number;
rtt: number;
netSpeed: number;
constructor(appCpu?: number, systemCpu?: number, width?: number, height?: number, fps?: number, videoBitrate?: number, audioBitrate?: number, audioPacketLoss?: number, videoPacketLoss?: number, jitterBufferDelay?: number, audioTotalBlockTime?: number, audioBlockRate?: number, videoTotalBlockTime?: number, videoBlockRate?: number, rtt?: number, netSpeed?: number);
}
export declare enum V2LivePushStatus {
V2LivePushStatusDisconnected = 0,
V2LivePushStatusConnecting = 1,
V2LivePushStatusConnectSuccess = 2,
V2LivePushStatusReconnecting = 3
}
export declare enum V2TXLiveMixInputType {
V2TXLiveMixInputTypeAudioVideo = 0,
V2TXLiveMixInputTypePureVideo = 1,
V2TXLiveMixInputTypePureAudio = 2
}
/**
* 云端混流中每一路子画面的位置信息
*
* @param {String} userId - 参与混流的 userId
* @param {String} streamId - 参与混流的 userId 所在对应的推流 streamId, 空的话表示当前推流 streamId。
* @param {Number} x - 图层位置 x 坐标(绝对像素值)。
* @param {Number} y - 图层位置 y 坐标(绝对像素值)。
* @param {Number} width - 图层位置宽度(绝对像素值)。
* @param {Number} height - 图层位置高度(绝对像素值)。
* @param {Number} zOrder - 图层层次(1 - 15)不可重复。
* @param {V2TXLiveMixInputType} inputType - 该直播流的输入类型。
*/
export declare class V2TXLiveMixStream {
userId: string;
streamId: string;
x: number;
y: number;
width: number;
height: number;
zOrder: number;
inputType: V2TXLiveMixInputType;
constructor(userId?: string, streamId?: string, x?: number, y?: number, width?: number, height?: number, zOrder?: number, inputType?: V2TXLiveMixInputType);
}
/**
* 云端混流(转码)配置
*
* @param {Number} videoWidth - 【字段含义】最终转码后的视频分辨率的宽度。<br>
* 【推荐取值】推荐值:360px ,如果你是纯音频推流,请将 width × height 设为 0px × 0px,否则混流后会携带一条画布背景的视频流。
* @param {Number} videoHeight - 【字段含义】最终转码后的视频分辨率的高度。<br>
* 【推荐取值】推荐值:640px ,如果你是纯音频推流,请将 width × height 设为 0px × 0px,否则混流后会携带一条画布背景的视频流。
* @param {Number} videoBitrate - 【字段含义】最终转码后的视频分辨率的码率(kbps)<br>
* 【推荐取值】如果填0,后台会根据videoWidth和videoHeight来估算码率,您也可以参考枚举定义TRTCVideoResolution_640_480的注释。
* @param {Number} videoFramerate - 【字段含义】最终转码后的视频分辨率的帧率(FPS)<br>
* 【推荐取值】默认值:15fps,取值范围是 (0,30]。
* @param {Number} videoGOP - 【字段含义】最终转码后的视频分辨率的关键帧间隔(又称为 GOP)。<br>
* 【推荐取值】默认值:2,单位为秒,取值范围是 [1,8]。
* @param {Number} backgroundColor - 【字段含义】混合后画面的底色颜色,默认为黑色,格式为十六进制数字,比如:“0x61B9F1” 代表 RGB 分别为(97,158,241)。<br>
* 【推荐取值】默认值:0x000000,黑色
* @param {String} backgroundImage - 【字段含义】混合后画面的背景图。<br>
* 【推荐取值】默认值:'',即不设置背景图<br>
* 【特别说明】背景图需要您事先在 “[控制台](https://console.cloud.tencent.com/trtc) => 应用管理 => 功能配置 => 素材管理” 中上传,<br>
* 上传成功后可以获得对应的“图片ID”,然后将“图片ID”转换成字符串类型并设置到 backgroundImage 里即可。<br>
* 例如:假设“图片ID” 为 63,可以设置 backgroundImage = @"63";
* @param {Number} audioSampleRate - 【字段含义】最终转码后的音频采样率。<br>
* 【推荐取值】默认值:48000Hz。支持12000HZ、16000HZ、22050HZ、24000HZ、32000HZ、44100HZ、48000HZ。
* @param {Number} audioBitrate - 【字段含义】最终转码后的音频码率。<br>
* 【推荐取值】默认值:64kbps,取值范围是 [32,192]。
* @param {Number} audioChannels - 【字段含义】最终转码后的音频声道数<br>
* 【推荐取值】默认值:1。取值范围为 [1,2] 中的整型。
* @param {V2TXLiveMixStream[]} mixStreams - 【字段含义】每一路子画面的位置信息
* @param {String} outputStreamId - 【字段含义】输出到 CDN 上的直播流 ID。<br>
* 如不设置该参数,SDK 会执行默认逻辑,即房间里的多路流会混合到该接口调用者的视频流上,也就是 A+B =>A;<br>
* 如果设置该参数,SDK 会将房间里的多路流混合到您指定的直播流 ID 上,也就是 A+B =>C。<br>
* 【推荐取值】默认值:'',即房间里的多路流会混合到该接口调用者的视频流上。
*/
export declare class V2TXLiveTranscodingConfig {
videoWidth: number;
videoHeight: number;
videoBitrate: number;
videoFramerate: number;
videoGOP: number;
backgroundColor: number;
backgroundImage: string;
audioSampleRate: number;
audioBitrate: number;
audioChannels: number;
mixStreams: V2TXLiveMixStream[];
outputStreamId: string;
constructor(videoWidth?: number, videoHeight?: number, videoBitrate?: number, videoFramerate?: number, videoGOP?: number, backgroundColor?: number, backgroundImage?: string, audioSampleRate?: number, audioBitrate?: number, audioChannels?: number, mixStreams?: any[], outputStreamId?: string);
}