fix: 被控端长时间不动,控制端无输出
This commit is contained in:
@@ -51,6 +51,11 @@ public class WebRtcClient {
|
|||||||
private EglBase eglBase;
|
private EglBase eglBase;
|
||||||
private String currentControllerId;
|
private String currentControllerId;
|
||||||
|
|
||||||
|
private VideoCapturer videoCapturer;
|
||||||
|
private int videoWidth;
|
||||||
|
private int videoHeight;
|
||||||
|
private int videoFps;
|
||||||
|
|
||||||
private InputCommandCallback inputCallback;
|
private InputCommandCallback inputCallback;
|
||||||
|
|
||||||
public interface InputCommandCallback {
|
public interface InputCommandCallback {
|
||||||
@@ -93,6 +98,11 @@ public class WebRtcClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setVideoCapturer(VideoCapturer capturer, int width, int height, int fps) {
|
public void setVideoCapturer(VideoCapturer capturer, int width, int height, int fps) {
|
||||||
|
this.videoCapturer = capturer;
|
||||||
|
this.videoWidth = width;
|
||||||
|
this.videoHeight = height;
|
||||||
|
this.videoFps = fps;
|
||||||
|
|
||||||
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBase.getEglBaseContext());
|
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBase.getEglBaseContext());
|
||||||
// 对于屏幕共享,isScreencast 设为 true,这会优化细节保留
|
// 对于屏幕共享,isScreencast 设为 true,这会优化细节保留
|
||||||
VideoSource videoSource = peerConnectionFactory.createVideoSource(true);
|
VideoSource videoSource = peerConnectionFactory.createVideoSource(true);
|
||||||
@@ -152,6 +162,9 @@ public class WebRtcClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onIceConnectionChange(PeerConnection.IceConnectionState newState) {
|
public void onIceConnectionChange(PeerConnection.IceConnectionState newState) {
|
||||||
Log.d(TAG, "ICE connection state: " + newState);
|
Log.d(TAG, "ICE connection state: " + newState);
|
||||||
|
if (newState == PeerConnection.IceConnectionState.CONNECTED) {
|
||||||
|
refreshVideoSource();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -371,4 +384,16 @@ public class WebRtcClient {
|
|||||||
|
|
||||||
wsClient.sendMessage(msg);
|
wsClient.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshVideoSource() {
|
||||||
|
if (videoCapturer != null) {
|
||||||
|
try {
|
||||||
|
Log.d(TAG, "Refreshing video capture to force a frame update for new connection");
|
||||||
|
videoCapturer.stopCapture();
|
||||||
|
videoCapturer.startCapture(videoWidth, videoHeight, videoFps);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error refreshing video capture: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ public class WebRtcClient {
|
|||||||
config.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
|
config.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
|
||||||
config.iceCandidatePoolSize = 10;
|
config.iceCandidatePoolSize = 10;
|
||||||
|
|
||||||
|
// 建议添加以下配置,增强复杂网络下的稳定性
|
||||||
|
config.iceTransportsType = PeerConnection.IceTransportsType.ALL;
|
||||||
|
config.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.ENABLED;
|
||||||
|
|
||||||
PeerObserver peerObserver = new PeerObserver(new PeerObserver.PeerEventListener() {
|
PeerObserver peerObserver = new PeerObserver(new PeerObserver.PeerEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onIceCandidate(IceCandidate candidate) {
|
public void onIceCandidate(IceCandidate candidate) {
|
||||||
@@ -117,9 +121,13 @@ public class WebRtcClient {
|
|||||||
Log.d(TAG, "ICE connection state: " + newState);
|
Log.d(TAG, "ICE connection state: " + newState);
|
||||||
if (newState == PeerConnection.IceConnectionState.CONNECTED) {
|
if (newState == PeerConnection.IceConnectionState.CONNECTED) {
|
||||||
if (connectionListener != null) connectionListener.onConnectionEstablished();
|
if (connectionListener != null) connectionListener.onConnectionEstablished();
|
||||||
} else if (newState == PeerConnection.IceConnectionState.FAILED ||
|
} else if (newState == PeerConnection.IceConnectionState.DISCONNECTED) {
|
||||||
newState == PeerConnection.IceConnectionState.DISCONNECTED) {
|
// DISCONNECTED 可能是暂时的,通常建议观察一段时间或尝试重放信令
|
||||||
|
Log.w(TAG, "ICE Disconnected, waiting for recovery...");
|
||||||
|
} else if (newState == PeerConnection.IceConnectionState.FAILED) {
|
||||||
|
// FAILED 通常意味着需要重新发起呼叫
|
||||||
if (connectionListener != null) connectionListener.onDisconnected();
|
if (connectionListener != null) connectionListener.onDisconnected();
|
||||||
|
// 这里可以触发重新创建 Offer 的逻辑
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user