開播設置,修改開播接口新增分辨率設置參數,網絡內存檢測和提示信息

This commit is contained in:
18401019693
2022-12-30 14:47:25 +08:00
parent 06b5f99930
commit 8b357233c2
10 changed files with 477 additions and 90 deletions

View File

@@ -112,10 +112,14 @@ import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Random;
import cn.rongcloud.rtc.api.RCRTCEngine;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
import cn.rongcloud.rtc.api.callback.IRCRTCStatusReportListener;
import cn.rongcloud.rtc.api.report.StatusBean;
import cn.rongcloud.rtc.api.report.StatusReport;
import cn.rongcloud.rtc.base.RCRTCRect;
import cn.rongcloud.rtc.base.RTCErrorCode;
import io.rong.imlib.IRongCallback;
@@ -208,6 +212,27 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
Bus.getOn(this);
Intent intent = getIntent();
initFaceManager();
// RCRTCEngine.getInstance().registerStatusReportListener(new IRCRTCStatusReportListener() {
//
// @Override
// public void onConnectionStats(StatusReport statusReport) {
// //视频发送信息
// for (Map.Entry<String, StatusBean> entry : statusReport.statusVideoSends.entrySet()) {
// StatusBean statusBean = entry.getValue();
// //获取userID
// String userId = statusBean.uid;
// //获取视频 宽x高@帧率
// String resolution = statusBean.frameWidth + "x" + statusBean.frameHeight + "@" + statusBean.frameRate;
// //获取码率
// long bitRate = statusBean.bitRate;
// //丢包率
// long lossRate = statusBean.packetLostRate;
// //带宽
// String googAvailableSendBandwidth = statusReport.googAvailableSendBandwidth;
// Log.e("网速和内存", "码率:" +bitRate+ " 丢包率:" + lossRate+" 带宽:"+googAvailableSendBandwidth);
// }
// }
// });
leave_img = findViewById(R.id.leave_img);
mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY);
mLiveKsyConfigBean = intent.getParcelableExtra(Constants.LIVE_KSY_CONFIG);

View File

@@ -9,6 +9,8 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
@@ -32,6 +34,7 @@ import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.interfaces.ImageResultCallback;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.ProcessImageUtil;
@@ -60,9 +63,15 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.util.Map;
import cn.rongcloud.rtc.api.RCRTCEngine;
import cn.rongcloud.rtc.api.callback.IRCRTCStatusReportListener;
import cn.rongcloud.rtc.api.report.StatusBean;
import cn.rongcloud.rtc.api.report.StatusReport;
import cn.rongcloud.rtc.api.stream.RCRTCCameraOutputStream;
import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig;
import cn.rongcloud.rtc.base.RCRTCParamsType;
public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnClickListener {
@@ -202,12 +211,16 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl
}
//设置清晰度
// DeviceUtils.getMemory(mContext); //获取可用内存
// DeviceUtils.getNetSpeed(mContext);//获取当前上传网速
// Log.e("网速和内存", "内存:" + + " 网速:" + DeviceUtils.getNetSpeed(mContext));
selectClarity = IMLoginManager.get(mContext).getSelectClarity();
setSelectClarity(selectClarity);
ViewClicksAntiShake
.clicksAntiShake(
findViewById(R.id.btn_live_clarity), () -> {
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, selectClarity);
LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, IMLoginManager.get(mContext).getSelectClarity());
new XPopup.Builder(mContext)
.setPopupCallback(new XPopupCallback() {
@Override
@@ -261,6 +274,7 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl
}
private void setSelectClarity(int selectClarity) {
this.selectClarity = selectClarity;
IMLoginManager.get(mContext).setSelectClarity(selectClarity);
switch (selectClarity) {
@@ -280,12 +294,43 @@ public class LiveNewReadyRyViewHolder extends AbsViewHolder implements View.OnCl
if (liveOpenCustomPopup != null) {
liveOpenCustomPopup.setSelectClarity(selectClarity);
}
//設置開播分辨率
RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
int minRate = 200;
int maxRate = 900;
switch (selectClarity) {
case 0:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
minRate = 200;
maxRate = 900;
break;
case 1:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280;
minRate = 250;
maxRate = 2200;
break;
case 2:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920;
minRate = 400;
maxRate = 4000;
break;
}
RCRTCVideoStreamConfig config =
RCRTCVideoStreamConfig.Builder.create()
.setMinRate(minRate)
.setMaxRate(maxRate)
.setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_15)
.setVideoResolution(rcrtcVideoResolution)
.build();
RCRTCEngine.getInstance().getDefaultVideoStream().setVideoConfig(config);
}
public void setManager(FaceManager manager) {
this.manager = manager;
}
@Override
public void onClick(View v) {
if (!canClick()) {

View File

@@ -25,7 +25,6 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.alibaba.fastjson.JSONObject;
import com.makeramen.roundedimageview.RoundedImageView;
import com.tencent.liteav.device.TXDeviceManager;
import com.tencent.rtmp.ITXLivePushListener;
import com.tencent.rtmp.TXLiveConstants;
@@ -35,11 +34,11 @@ import com.yunbao.common.Constants;
import com.yunbao.common.bean.HttpCallbackModel;
import com.yunbao.common.bean.UserBean;
import com.yunbao.common.event.AnchorInfoEvent;
import com.yunbao.common.event.FollowEvent;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.manager.IMRTCManager;
import com.yunbao.common.manager.RandomPkManager;
import com.yunbao.common.utils.DialogUitl;
@@ -72,12 +71,14 @@ import cn.rongcloud.rtc.api.RCRTCRoomConfig;
import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback;
import cn.rongcloud.rtc.api.callback.IRCRTCResultDataCallback;
import cn.rongcloud.rtc.api.callback.IRCRTCRoomEventsListener;
import cn.rongcloud.rtc.api.callback.IRCRTCVideoOutputFrameListener;
import cn.rongcloud.rtc.api.stream.RCRTCInputStream;
import cn.rongcloud.rtc.api.stream.RCRTCLiveInfo;
import cn.rongcloud.rtc.api.stream.RCRTCVideoStreamConfig;
import cn.rongcloud.rtc.api.stream.RCRTCVideoView;
import cn.rongcloud.rtc.base.RCRTCParamsType;
import cn.rongcloud.rtc.base.RCRTCRoomType;
import cn.rongcloud.rtc.base.RCRTCVideoFrame;
import cn.rongcloud.rtc.base.RTCErrorCode;
import cn.rongcloud.rtc.core.CameraVideoCapturer;
import cn.rongcloud.rtc.core.RendererCommon;
@@ -114,11 +115,11 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
@Subscribe(threadMode = ThreadMode.MAIN)
public void onUPAnchorInfo(AnchorInfoEvent e) {
if (e != null) {
if(e.isClear()==false) {
if (e.isClear() == false) {
tv_avatarOther_name.setText(e.getUserNiceName());
ImgLoader.displayAvatar(mContext, e.getAvatar(), avatarOther);
goto_room_view.setVisibility(View.VISIBLE);
}else{
} else {
goto_room_view.setVisibility(View.GONE);
}
@@ -417,7 +418,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
@Override
public void onConfirmClick(Dialog dialog, String content) {
//断开连麦
LiveRyAnchorActivity.isDRPK=0;
LiveRyAnchorActivity.isDRPK = 0;
HttpClient.getInstance().post("livepk.setliveuserout", "livepk.setliveuserout")
.execute(new HttpCallback() {
@Override
@@ -560,16 +561,37 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
RCRTCEngine.getInstance().init(contexts, config);
RCRTCEngine.getInstance().getDefaultAudioStream().setAudioQuality(RCRTCParamsType.AudioQuality.MUSIC_HIGH, RCRTCParamsType.AudioScenario.MUSIC_CHATROOM);
//設置開播分辨率
RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
int minRate = 200;
int maxRate = 900;
switch (IMLoginManager.get(mContext).getSelectClarity()) {
case 0:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
minRate = 200;
maxRate = 900;
break;
case 1:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280;
minRate = 250;
maxRate = 2200;
break;
case 2:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920;
minRate = 400;
maxRate = 4000;
break;
}
RCRTCVideoStreamConfig videoConfigBuilder = RCRTCVideoStreamConfig.Builder.create()
//设置分辨率
.setVideoResolution(RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_640)
.setVideoResolution(rcrtcVideoResolution)
//设置帧率
.setVideoFps(RCRTCParamsType.RCRTCVideoFps.Fps_24)
//设置最小码率480P下推荐200
.setMinRate(250)
.setMinRate(minRate)
//设置最大码率480P下推荐900
.setMaxRate(5000)
.setMaxRate(maxRate)
.build();
// 创建本地视频显示视图
@@ -595,7 +617,6 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
mPreView.addView(rongRTCVideoView);
tencentTRTCBeautyManager = new TencentTRTCBeautyManager(mContext);
//加入房间成功后可以通过 RCRTCLocalUser 对象发布本地默认音视频流,包括:麦克风采集的音频和摄像头采集的视频。
RCRTCEngine.getInstance().getDefaultVideoStream().setEncoderMirror(true);
if (rtcRoom == null || rtcRoom.getLocalUser() == null) {
@@ -615,20 +636,13 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
room.registerRoomListener(roomEventsListener);
//美颜
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
//旧美颜不需要了
/*RCRTCEngine.getInstance().getDefaultVideoStream().setVideoFrameListener(new IRCRTCVideoOutputFrameListener() {
@Override
public RCRTCVideoFrame processVideoFrame(RCRTCVideoFrame rtcVideoFrame) {
// 使用数据进行美颜/录像等处理后,需要把数据再返回给 SDK 做发送。
rtcVideoFrame.setTextureId(tencentTRTCBeautyManager.renderWithTexture(rtcVideoFrame.getTextureId(), rtcVideoFrame.getWidth(), rtcVideoFrame.getHeight(), false));
return rtcVideoFrame;
}
});*/
}
});
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// public void run() {
// //旧美颜不需要了
//
//
// }
// });
}
@Override
@@ -716,24 +730,38 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
RCRTCMixConfig config = new RCRTCMixConfig();
RCRTCMixConfig.MediaConfig mediaConfig = new RCRTCMixConfig.MediaConfig();
config.setMediaConfig(mediaConfig);
//视频输出配置
//视频输出配置
RCRTCMixConfig.MediaConfig.VideoConfig videoConfig = new RCRTCMixConfig.MediaConfig.VideoConfig();
mediaConfig.setVideoConfig(videoConfig);
//大流视频的输出参数
//大流视频的输出参数
RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout normal = new RCRTCMixConfig.MediaConfig.VideoConfig.VideoLayout();
videoConfig.setVideoLayout(normal);
//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置
//如不设置宽高值则服务端将使用默认宽高 360 * 640
//例:发布的视频分辨率为720 * 1280如果不设置则观众端看到的视频分辨率为 360 * 640,
//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中
RCRTCVideoStreamConfig defaultVideoConfig = RCRTCEngine.getInstance().getDefaultVideoStream().getVideoConfig();
int fps = defaultVideoConfig.getVideoFps().getFps();
int width = 720;
int height = 1280;
//推荐宽、高、帧率参数值可以通过默认视频流的配置获取,也可以根据实际需求来自定义设置
//如不设置宽高值则服务端将使用默认宽高 360 * 640
//例:发布的视频分辨率为720 * 1280如果不设置则观众端看到的视频分辨率为 360 * 640,
//所以如果想让观众端看到的视频分辨率和发布视频分辨率一致,则应从发布的视频流中获取分辨率配置并设置到 mediaConfig 中
//設置開播分辨率
//設置開播分辨率
RCRTCParamsType.RCRTCVideoResolution rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
int minRate = 200;
int maxRate = 900;
switch (IMLoginManager.get(mContext).getSelectClarity()) {
case 0:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_480_848;
break;
case 1:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_720_1280;
break;
case 2:
rcrtcVideoResolution = RCRTCParamsType.RCRTCVideoResolution.RESOLUTION_1080_1920;
break;
}
int width = rcrtcVideoResolution.getWidth();
int height = rcrtcVideoResolution.getHeight();
normal.setWidth(width); //视频宽
normal.setHeight(height); //视频高
normal.setFps(25); //视频帧率
normal.setFps(15); //视频帧率
videoConfig.setVideoLayout(normal);
//2. 合流画布设置
//(请参照画布和声音配置示例代码)
//3. 假设以画布设置的宽高为 300 * 300为例(应以真实设置的宽高为准),设置每个视频流小窗口的坐标及宽高
@@ -747,6 +775,16 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
videoLayout1.setY(0); //Y 坐标
videoLayout1.setWidth(720); // 视频窗口的宽
videoLayout1.setHeight(1280); // 视频窗口的高
RCRTCEngine.getInstance().getDefaultVideoStream().setVideoFrameListener(new IRCRTCVideoOutputFrameListener() {
@Override
public RCRTCVideoFrame processVideoFrame(RCRTCVideoFrame rtcVideoFrame) {
// 使用数据进行美颜/录像等处理后,需要把数据再返回给 SDK 做发送。
// rtcVideoFrame.setTextureId(tencentTRTCBeautyManager.renderWithTexture(rtcVideoFrame.getTextureId(), rtcVideoFrame.getWidth(), rtcVideoFrame.getHeight(), false));
Log.e("视频流", "Width---------------------" + rtcVideoFrame.getWidth());
Log.e("视频流", "Height---------------------" + rtcVideoFrame.getHeight());
return rtcVideoFrame;
}
});
//2. 合流画布设置
rcrtcLiveInfo.setMixConfig(config, new IRCRTCResultCallback() {
@Override
@@ -762,6 +800,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX
});
}
}
@Override