Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b56e05a

Browse files
Disabled surface hardware scaler due to resizing bugs when starting/stopping stream. Provided methods to gracefully pause the stream and camera. Improved overlay texture stability
1 parent 2f2e396 commit b56e05a

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/WebRTCClient.java

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ public void setRendererForVideoTrack(SurfaceViewRenderer renderer, VideoTrack vi
638638
remoteVideoSink.setTarget(renderer);
639639
renderer.init(eglBase.getEglBaseContext(), null);
640640
renderer.setScalingType(config.scalingType);
641-
renderer.setEnableHardwareScaler(true);
641+
renderer.setEnableHardwareScaler(false); /* This was enabled, but causes weird resizing and resolutions on Samsung S23 Ultra */
642642
renderer.setTag(renderer.getId(), remoteVideoSink);
643643
}
644644
videoTrack.addSink(remoteVideoSink);
@@ -784,7 +784,7 @@ public void initializeRenderers() {
784784
config.localVideoRenderer.init(eglBase.getEglBaseContext(), null);
785785
config.localVideoRenderer.setScalingType(config.scalingType);
786786
config.localVideoRenderer.setZOrderMediaOverlay(true);
787-
config.localVideoRenderer.setEnableHardwareScaler(true /* enabled */);
787+
config.localVideoRenderer.setEnableHardwareScaler(false); /* This was enabled, but causes weird resizing and resolutions on Samsung S23 Ultra */
788788
config.localVideoRenderer.setOnTouchListener(this::handleFocusTouch);
789789
localVideoSink.setTarget(config.localVideoRenderer);
790790
}
@@ -843,6 +843,52 @@ public void initializeVideoCapturer() {
843843
});
844844
}
845845

846+
public void releaseVideoCapturer() {
847+
localVideoTrack = null;
848+
localAudioTrack = null;
849+
850+
mainHandler.post(() -> {
851+
executor.execute(() -> {
852+
if (videoCapturer != null && !videoCapturerStopped) {
853+
try {
854+
videoCapturer.stopCapture();
855+
videoCapturer.dispose();
856+
videoCapturer = null;
857+
} catch (InterruptedException e) {
858+
throw new RuntimeException(e);
859+
}
860+
videoCapturerStopped = true;
861+
}
862+
863+
Log.d(TAG, "Closing audio source.");
864+
if (audioSource != null) {
865+
audioSource.dispose();
866+
audioSource = null;
867+
}
868+
Log.d(TAG, "Stopping capture.");
869+
if (videoCapturer != null && !videoCapturerStopped) {
870+
try {
871+
videoCapturer.stopCapture();
872+
videoCapturer.dispose();
873+
videoCapturer = null;
874+
} catch (InterruptedException e) {
875+
throw new RuntimeException(e);
876+
}
877+
videoCapturerStopped = true;
878+
}
879+
Log.d(TAG, "Closing video source.");
880+
if (videoSource != null) {
881+
videoSource.dispose();
882+
videoSource = null;
883+
}
884+
if (surfaceTextureHelper != null) {
885+
surfaceTextureHelper.dispose();
886+
surfaceTextureHelper = null;
887+
}
888+
});
889+
});
890+
}
891+
846892
public void setBitrate(int bitrate) {
847893
setVideoMaxBitrate(bitrate);
848894
}
@@ -957,6 +1003,30 @@ public void stop(String streamId, boolean byUser) {
9571003
}
9581004
}
9591005

1006+
public void stopPublish(String streamId) {
1007+
if(released){
1008+
return;
1009+
}
1010+
1011+
mainHandler.post(() -> {
1012+
executor.execute(() -> {
1013+
PeerInfo peerInfo = peers.get(streamId);
1014+
if (peerInfo != null) {
1015+
Log.d(TAG, "Closing peer connections for " + peerInfo.id);
1016+
PeerConnection peerConnection = peerInfo.peerConnection;
1017+
if (peerConnection != null) {
1018+
peerConnection.dispose();
1019+
peerInfo.peerConnection = null;
1020+
}
1021+
}
1022+
peers.clear();
1023+
1024+
Log.d(TAG, "Closing peer connection done.");
1025+
onPeerConnectionClosed();
1026+
});
1027+
});
1028+
}
1029+
9601030
@Override
9611031
public void switchCamera() {
9621032
if (config.videoSource == StreamSource.FRONT_CAMERA) {

webrtc-android-framework/src/main/java/org/webrtc/OverlayManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ public int compare(OverlayBitmap a, OverlayBitmap b) {
112112
}
113113

114114
OverlayManager.renderThreadHandler.post(() -> {
115-
if (textureId != 0) {
116-
GLES20.glDeleteTextures(1, new int[] { textureId }, 0);
117-
}
115+
int oldTextureId = textureId;
118116
textureId = GlUtil.loadTexture(currentBitmap);
117+
if (oldTextureId != 0) {
118+
GLES20.glDeleteTextures(1, new int[] { oldTextureId }, 0);
119+
}
119120
});
120121
}
121122

0 commit comments

Comments
 (0)