public class TXLivePusher
extends java.lang.Object
implements com.tencent.liteav.TXICustomPreprocessListenner, com.tencent.liteav.TXCCaptureAndEnc.TXICaptureAndEncDelegate
Modifier and Type | Class and Description |
---|---|
static interface |
TXLivePusher.AudioCustomProcessListener |
static interface |
TXLivePusher.ITXSnapshotListener |
static interface |
TXLivePusher.OnBGMNotify
播放背景音乐的回调接口
|
static interface |
TXLivePusher.VideoCustomProcessListener |
Modifier and Type | Field and Description |
---|---|
static int |
RGB_BGRA |
static int |
RGB_RGBA |
static int |
YUV_420P |
static int |
YUV_420SP
视频格式
|
static int |
YUV_420YpCbCr |
Constructor and Description |
---|
TXLivePusher(Context context)
构建一个 TXLivePusher 对象.
|
Modifier and Type | Method and Description |
---|---|
TXLivePushConfig |
getConfig()
获取推流器配置信息.
|
int |
getMaxZoom()
获取摄像头支持的最大焦距,此方法同时可以检查是否支持变焦
|
int |
getMusicDuration(java.lang.String path)
获取音乐文件时长.
|
boolean |
isPushing()
是否正在推流.
|
void |
onLogRecord(java.lang.String str)
将非SDK(用户)的log存入本地文件
|
boolean |
pauseBGM()
暂停播放背景音乐.
|
void |
pausePusher()
暂停推流.
|
boolean |
playBGM(java.lang.String path)
播放背景音乐.
|
boolean |
resumeBGM()
恢复播放背景音乐.
|
void |
resumePusher()
恢复推流.
|
void |
sendCustomPCMData(byte[] pcmBuffer)
发送客户自定义的音频PCM数据.
|
int |
sendCustomVideoData(byte[] buffer,
int bufferType,
int w,
int h)
发送客户自定义的视频数据.
|
int |
sendCustomVideoTexture(int textureID,
int w,
int h)
发送客户自定义的视频纹理。注意,该接口需要在OpenGL线程调用。
|
void |
sendMessage(byte[] msg)
Deprecated.
|
boolean |
sendMessageEx(byte[] msg)
向播放端发送消息 (消息大小不允许超过2K)
|
void |
setAudioProcessListener(TXLivePusher.AudioCustomProcessListener listener)
设置自定义音频处理回调
|
boolean |
setBeautyFilter(int style,
int beautyLevel,
int whiteningLevel,
int ruddyLevel)
设置美颜效果.
|
void |
setBGMNofify(TXLivePusher.OnBGMNotify notify)
设置背景音乐的回调接口
|
void |
setBgmPitch(float pitch)
设置背景音乐的音调.
|
boolean |
setBGMVolume(float x)
设置背景音乐的音量大小.
|
void |
setChinLevel(int chinLevel)
setChinLevel 设置下巴拉伸或收缩(特权版本有效,普通版本设置此参数无效)
|
void |
setConfig(TXLivePushConfig config)
设置推流器配置信息.推荐在启动推流前设置配置信息.
|
void |
setExposureCompensation(float value)
调整曝光
|
void |
setEyeScaleLevel(int eyeScaleLevel)
setEyeScaleLevel 设置大眼级别(特权版本有效,普通版本设置此参数无效)
|
void |
setFaceShortLevel(int faceShortlevel)
setFaceShortLevel 设置短脸(特权版本有效,普通版本设置此参数无效)
|
void |
setFaceSlimLevel(int faceScaleLevel)
setFaceSlimLevel 设置瘦脸级别(特权版本有效,普通版本设置此参数无效)
|
void |
setFaceVLevel(int faceVLevel)
setFaceVLevel 设置V脸(特权版本有效,普通版本设置此参数无效)
|
void |
setFilter(Bitmap bmp)
setFilter 设置指定素材滤镜特效
|
boolean |
setGreenScreenFile(java.lang.String file)
设置绿幕文件。仅增值版有效
|
boolean |
setMicVolume(float x)
设置麦克风的音量大小.
|
boolean |
setMirror(boolean enable)
设置播放端水平镜像与否(tips:推流端前置摄像头默认看到的是镜像画面,后置摄像头默认看到的是非镜像画面)
|
void |
setMotionTmpl(java.lang.String motionPath)
设置动效。仅企业版SDK有效
|
void |
setMute(boolean mute)
设置是否静音播放预览视频.
|
void |
setNoseSlimLevel(int noseSlimLevel)
setNoseSlimLevel 设置瘦鼻(特权版本有效,普通版本设置此参数无效)
|
void |
setPushListener(ITXLivePushListener listener)
设置推流器的回调.
|
void |
setRenderRotation(int rotation)
设置图像渲染角度.
|
void |
setReverb(int reverbType)
设置推流端混响效果
|
void |
setSpecialRatio(float ratio)
setSpecialRatio 设置滤镜效果程度
|
void |
setVideoProcessListener(TXLivePusher.VideoCustomProcessListener listener)
设置自定义图像处理回调
|
void |
setVideoQuality(int quality,
boolean adjustBitrate,
boolean adjustResolution)
setVideoQuality 设置视频质量
|
void |
setVideoRecordListener(TXRecordCommon.ITXVideoRecordListener listener)
设置录制回调
|
void |
setVoiceChangerType(int voiceChangerType)
设置变声类型
|
boolean |
setZoom(int value)
调整摄像头焦距
|
void |
snapshot(TXLivePusher.ITXSnapshotListener listener)
推流截图
|
void |
startCameraPreview(com.tencent.rtmp.ui.TXCloudVideoView view)
启动摄像头预览.
|
int |
startPusher(java.lang.String url)
启动推流.
|
int |
startRecord(java.lang.String videoFilePath)
开始视频录制
|
void |
startScreenCapture()
启动录屏.
|
boolean |
stopBGM()
停止播放背景音乐.
|
void |
stopCameraPreview(boolean isNeedClearLastImg)
停止摄像头预览.
|
void |
stopPusher()
停止推流.
|
void |
stopRecord()
停止视频录制
|
void |
stopScreenCapture()
结束录屏.
|
void |
switchCamera()
切换前置或后置摄像头
该接口在启动预览
startCameraPreview(TXCloudVideoView) 后调用才能生效,预览前调用无效. |
boolean |
turnOnFlashLight(boolean enable)
打开或关闭闪光灯.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final int RGB_BGRA
public static final int RGB_RGBA
public static final int YUV_420P
public static final int YUV_420SP
public static final int YUV_420YpCbCr
public TXLivePusher(Context context)
context
- 运行 TXLivePusher 的 Context.public TXLivePushConfig getConfig()
public int getMaxZoom()
public int getMusicDuration(java.lang.String path)
path
- 音乐文件路径
path == null 获取当前播放歌曲时长
path != null 获取path路径歌曲时长public boolean isPushing()
public void onLogRecord(java.lang.String str)
str
- 存入本地文件的log.public boolean pauseBGM()
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
public void pausePusher()
该接口和resumePusher()
主要用于管理APP切后台后SDK的推流表现.
当APP从前台切到后台时或录屏进入隐私模式,调用该接口,SDK会暂停推流,后台服务器会接管推流工作,向播放端观众播放暂停图片,暂停图片可以通过TXLivePushConfig.setPauseImg(Bitmap)
配置.
当APP从后台回到前台时或录屏取消隐私模式,调用resumePusher()
,后台服务器停止播放暂停图片,SDK会恢复推流.
pause时不需要stopCameraPreview(boolean)
具体使用方法请参考demo
public boolean playBGM(java.lang.String path)
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
path
- 背景音乐文件路径.public boolean resumeBGM()
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
public void resumePusher()
public void sendCustomPCMData(byte[] pcmBuffer)
目前SDK只支持16位采样的PCM编码,如果是单声道,请保证传入的PCM长度为2048;如果是双声道,请保证传入的PCM长度为4096.
pcmBuffer
- pcm音频数据.public int sendCustomVideoData(byte[] buffer, int bufferType, int w, int h)
变更历史:
1.5.2版本增加函数返回值,SDK内部不再做帧率控制,请务必保证调用该函数的频率和TXLivePushConfig中设置的帧率一致,否则编码器输出的码率会不受控制.
1.6.1版本修改此方法支持多种格式及分辨率的视频数据,具体支持的格式请参考bufferType.
buffer
- 视频数据.bufferType
- 视频格式.取值请参考视频格式w
- 视频图像的宽度.h
- 视频图像的高度.public int sendCustomVideoTexture(int textureID, int w, int h)
textureID
- 视频纹理ID.w
- 视频图像的宽度.h
- 视频图像的高度.@Deprecated public void sendMessage(byte[] msg)
推荐使用新接口sendMessageEx(byte[])
该接口存在的问题: 会导致在iOS上使用浏览器播放HLS流时,会出现无法播放的异常现象
注意:
1. 若您使用过该接口,切换到sendMessageEx(byte[])
时会有兼容性问题: 使用sendMessageEx发送消息给旧版本的SDK(5.0及5.0以下)时,解析会出现错误,会显示出异常字符但APP不会crash;其余情况不受影响
2. 若您未使用过该接口,请务必直接使用sendMessageEx(byte[])
msg
- 需要发送的msg.public boolean sendMessageEx(byte[] msg)
可在推出的流中携带消息,能够解决旧接口sendMessage(byte[])
在iOS上无法播放HLS流的问题
注意:
若您使用过sendMessage(byte[])
该旧接口,请务必悉知: 使用sendMessageEx发送消息给旧版本的SDK(5.0及5.0以下)时,解析会出现错误,会显示出异常字符但APP不会crash;其余情况不受影响
msg
- public void setAudioProcessListener(TXLivePusher.AudioCustomProcessListener listener)
listener
- 音频数据回调,在编码前回调出来.public boolean setBeautyFilter(int style, int beautyLevel, int whiteningLevel, int ruddyLevel)
style
- 美颜风格.三种美颜风格:0 :光滑 1:自然 2:朦胧beautyLevel
- 美颜等级.美颜等级即 beautyLevel 取值为0-9.取值为0时代表关闭美颜效果.默认值:0,即关闭美颜效果.whiteningLevel
- 美白等级.美白等级即 whiteningLevel 取值为0-9.取值为0时代表关闭美白效果.默认值:0,即关闭美白效果.ruddyLevel
- 红润等级.美白等级即 ruddyLevel 取值为0-9.取值为0时代表关闭美白效果.默认值:0,即关闭美白效果.public void setBGMNofify(TXLivePusher.OnBGMNotify notify)
notify
- 回调接口public void setBgmPitch(float pitch)
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
pitch
- 音调,0为正常音量,范围是 [-1,1].public boolean setBGMVolume(float x)
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
x
- 音量大小,1为正常音量,建议值为0~2,如果需要调大背景音量可以设置更大的值.public void setChinLevel(int chinLevel)
chinLevel
- : 下巴拉伸或收缩级别取值范围 -9 ~ 9; 0 表示关闭 -9收缩 ~ 9拉伸。public void setConfig(TXLivePushConfig config)
config
- 推流器配置信息.配置信息请参考 TXLivePushConfig.public void setExposureCompensation(float value)
value
- 曝光比例,表示该手机支持最大曝光调整值的比例,取值范围从-1到1。
负数表示调低曝光,-1是最小值,对应getMinExposureCompensation。
正数表示调高曝光,1是最大值,对应getMaxExposureCompensation。
0表示不调整曝光public void setEyeScaleLevel(int eyeScaleLevel)
eyeScaleLevel
- : 大眼级别取值范围 0 ~ 9; 0 表示关闭 1 ~ 9值越大 效果越明显。public void setFaceShortLevel(int faceShortlevel)
faceShortlevel
- : 短脸级别取值范围 0 ~ 9; 0 表示关闭 1 ~ 9值越大 效果越明显。public void setFaceSlimLevel(int faceScaleLevel)
faceScaleLevel
- : 瘦脸级别取值范围 0 ~ 9; 0 表示关闭 1 ~ 9值越大 效果越明显。public void setFaceVLevel(int faceVLevel)
faceVLevel
- : V脸级别取值范围 0 ~ 9; 0 表示关闭 1 ~ 9值越大 效果越明显。public void setFilter(Bitmap bmp)
bmp:
- 指定素材,即颜色查找表图片。注意:一定要用png图片格式!!!
demo用到的滤镜查找表图片位于app/src/main/res/drawable-xxhdpi/目录下。public boolean setGreenScreenFile(java.lang.String file)
file:
- 绿幕文件路径。支持mp4; nil 关闭绿幕public boolean setMicVolume(float x)
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
x:
- 音量大小,1为正常音量,建议值为0~2,如果需要调大音量可以设置更大的值.public boolean setMirror(boolean enable)
enable
- true:播放端看到的是镜像画面,false:播放端看到的是镜像画面public void setMotionTmpl(java.lang.String motionPath)
motionPath:
- 动效完整路径public void setMute(boolean mute)
mute
- 是否静音播放预览视频. true:静音播放. false:不静音播放.public void setNoseSlimLevel(int noseSlimLevel)
noseSlimLevel
- : 瘦鼻级别取值范围 0 ~ 9; 0 表示关闭 1 ~ 9值越大 效果越明显。public void setPushListener(ITXLivePushListener listener)
listener
- 播放器回调,请参考类ITXLivePushListener.public void setRenderRotation(int rotation)
rotation
- 图像渲染角度.public void setReverb(int reverbType)
reverbType
- 混响类型。具体值请参考 TXLiveConstants.REVERB_TYPE_0
(关闭混响)
TXLiveConstants.REVERB_TYPE_1
(KTV)
TXLiveConstants.REVERB_TYPE_2
(小房间)
TXLiveConstants.REVERB_TYPE_3
(大会堂)
TXLiveConstants.REVERB_TYPE_4
(低沉)
TXLiveConstants.REVERB_TYPE_5
(洪亮)
TXLiveConstants.REVERB_TYPE_6
(磁性)*public void setSpecialRatio(float ratio)
ratio:
- 从0到1,越大滤镜效果越明显,默认取值0.5public void setVideoProcessListener(TXLivePusher.VideoCustomProcessListener listener)
listener
- public void setVideoQuality(int quality, boolean adjustBitrate, boolean adjustResolution)
quality
- : 画质类型,可设置值:TXLiveConstants.VIDEO_QUALITY_STANDARD_DEFINITION
(标清)
TXLiveConstants.VIDEO_QUALITY_HIGH_DEFINITION
(高清)
TXLiveConstants.VIDEO_QUALITY_SUPER_DEFINITION
(超高清)adjustBitrate
- : 动态码率开关adjustResolution
- : 动态切分辨率开关public void setVideoRecordListener(TXRecordCommon.ITXVideoRecordListener listener)
public void setVoiceChangerType(int voiceChangerType)
voiceChangerType
- 变声类型public boolean setZoom(int value)
value
- 焦距,取值 0~getMaxZoom();public void snapshot(TXLivePusher.ITXSnapshotListener listener)
listener:
- 截图完成回调public void startCameraPreview(com.tencent.rtmp.ui.TXCloudVideoView view)
view
- 预览视频的渲染view.public int startPusher(java.lang.String url)
url
- 推流的流地址.public int startRecord(java.lang.String videoFilePath)
请在接口 {@link #startCameraPreview(TXCloudVideoView) 后调用
注意:客户需要自己管理生成的视频,在不需要视频的时候自行删除
videoFilePath
- 视频文件全路径,调用者保证拥有该路径权限public void startScreenCapture()
开启隐私模式请调用pausePusher()
接口推默认图及静音数据,取消隐私模式调用resumePusher()
.
public boolean stopBGM()
该接口用于混音处理,比如将背景音乐与麦克风采集到的声音混合后播放.
public void stopCameraPreview(boolean isNeedClearLastImg)
isNeedClearLastImg
- 是否需要清除最后一帧画面. true:清除最后一帧画面. false:保留最后一帧画面.public void stopPusher()
public void stopRecord()
public void stopScreenCapture()
public void switchCamera()
public boolean turnOnFlashLight(boolean enable)
请在开启摄像头预览之后打开闪光灯.
enable
- 是否打开闪光灯. true:打开闪光灯. false:关闭闪光灯.