Improvements to cleanup

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-01-12 22:10:35 +01:00
parent 2e6804dc35
commit b7539bfc12
2 changed files with 28 additions and 17 deletions

View File

@ -978,31 +978,37 @@ public class CallActivity extends AppCompatActivity {
if (!dueToNetworkChange) { if (!dueToNetworkChange) {
pipVideoView.release(); pipVideoView.release();
if (localMediaStream != null) { if (audioSource != null) {
if (localMediaStream.videoTracks != null && localMediaStream.videoTracks.size() > 0) { audioSource.dispose();
localMediaStream.removeTrack(localMediaStream.videoTracks.get(0)); audioSource = null;
} }
if (localMediaStream.audioTracks != null && localMediaStream.audioTracks.size() > 0) { if (audioManager != null) {
localMediaStream.removeTrack(localMediaStream.audioTracks.get(0)); audioManager.stop();
} audioManager = null;
} }
if (videoCapturer != null) {
try {
videoCapturer.stopCapture();
} catch (InterruptedException e) {
Log.e(TAG, "Failed to stop capturing while hanging up");
}
videoCapturer.dispose();
videoCapturer = null;
}
localVideoTrack = null; Log.d(TAG, "Closing video source.");
localAudioTrack = null; if (videoSource != null) {
localRenderer = null; videoSource.dispose();
localMediaStream = null; videoSource = null;
}
if (peerConnectionFactory != null) { if (peerConnectionFactory != null) {
peerConnectionFactory.dispose(); peerConnectionFactory.dispose();
peerConnectionFactory = null; peerConnectionFactory = null;
} }
if (videoCapturer != null) {
videoCapturer.dispose();
videoCapturer = null;
}
hangupNetworkCalls(); hangupNetworkCalls();

View File

@ -93,8 +93,13 @@ public class MagicPeerConnectionWrapper {
} }
public void removePeerConnection() { public void removePeerConnection() {
if (magicDataChannel != null) {
magicDataChannel.dispose();
magicDataChannel = null;
}
if (peerConnection != null) { if (peerConnection != null) {
peerConnection.close(); peerConnection.dispose();
peerConnection = null; peerConnection = null;
} }
} }