浏览代码

Migrate WebRTC from plan b to unified plan

The in 'MagicPeerConnectionWrapper#removePeerConnection' used method
'PeerConnection#removeStream' was not longer available in the unified
plan. So to make sure that the local stream is disposed, it will now be
done in 'CallActivity#hangup'.

Resolves: #1773
See: [1]

[1] https://webrtc.org/getting-started/unified-plan-transition-guide
Signed-off-by: Tim Krüger <t@timkrueger.me>
Tim Krüger 3 年之前
父节点
当前提交
86f20dcfd3

+ 7 - 1
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -1608,7 +1608,13 @@ public class CallActivity extends CallBaseActivity {
                 peerConnectionFactory = null;
             }
 
-            localMediaStream = null;
+            if(localMediaStream != null) {
+                localMediaStream.dispose();
+                localMediaStream = null;
+                Log.d(TAG, "Disposed localMediaStream");
+            } else {
+                Log.d(TAG, "localMediaStream is null");
+            }
             localAudioTrack = null;
             localVideoTrack = null;
 

+ 22 - 11
app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java

@@ -2,6 +2,8 @@
  * Nextcloud Talk application
  *
  * @author Mario Danic
+ * @author Tim Krüger
+ * Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
  * Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -37,6 +39,7 @@ import com.nextcloud.talk.models.json.signaling.DataChannelMessageNick;
 import com.nextcloud.talk.models.json.signaling.NCIceCandidate;
 
 import org.greenrobot.eventbus.EventBus;
+import org.webrtc.AudioTrack;
 import org.webrtc.DataChannel;
 import org.webrtc.IceCandidate;
 import org.webrtc.MediaConstraints;
@@ -46,10 +49,12 @@ import org.webrtc.PeerConnectionFactory;
 import org.webrtc.RtpReceiver;
 import org.webrtc.SdpObserver;
 import org.webrtc.SessionDescription;
+import org.webrtc.VideoTrack;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 
@@ -60,7 +65,7 @@ import autodagger.AutoInjector;
 
 @AutoInjector(NextcloudTalkApplication.class)
 public class MagicPeerConnectionWrapper {
-    private static final String TAG = "MagicPeerConWrapper";
+    private static final String TAG = MagicPeerConnectionWrapper.class.getCanonicalName();
 
     private List<IceCandidate> iceCandidates = new ArrayList<>();
     private PeerConnection peerConnection;
@@ -107,14 +112,18 @@ public class MagicPeerConnectionWrapper {
         this.isMCUPublisher = isMCUPublisher;
 
         PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(iceServerList);
-        configuration.sdpSemantics = PeerConnection.SdpSemantics.PLAN_B;
-
-        peerConnection = peerConnectionFactory.createPeerConnection(configuration, sdpConstraints,
-                                                                    new MagicPeerConnectionObserver());
+        configuration.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
+        peerConnection = peerConnectionFactory.createPeerConnection(configuration, new MagicPeerConnectionObserver());
 
         if (peerConnection != null) {
-            if (localMediaStream != null) {
-                peerConnection.addStream(localMediaStream);
+            if (localStream != null) {
+                List<String> localMediaStreamIds = Collections.singletonList(localMediaStream.getId());
+                for(AudioTrack track : localMediaStream.audioTracks) {
+                    peerConnection.addTrack(track, localMediaStreamIds);
+                }
+                for(VideoTrack track : localStream.videoTracks) {
+                    peerConnection.addTrack(track, localMediaStreamIds);
+                }
             }
 
             if (hasMCU || hasInitiated) {
@@ -145,15 +154,17 @@ public class MagicPeerConnectionWrapper {
         if (magicDataChannel != null) {
             magicDataChannel.dispose();
             magicDataChannel = null;
+            Log.d(TAG, "Disposed DataChannel");
+        } else {
+            Log.d(TAG, "DataChannel is null.");
         }
 
         if (peerConnection != null) {
-            if (localMediaStream != null) {
-                peerConnection.removeStream(localMediaStream);
-            }
-
             peerConnection.close();
             peerConnection = null;
+            Log.d(TAG, "Disposed PeerConnection");
+        } else {
+            Log.d(TAG, "PeerConnection is null.");
         }
     }