From 0bb65795ad410fe6d0886be680cd304c3ec0e977 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 16 Oct 2018 21:53:35 +0200 Subject: [PATCH] Revert "Prefer H264" This reverts commit 589f7f934f12d287ebdf001bc40699da2e06b0df. --- .../talk/controllers/CallController.java | 2 +- .../com/nextcloud/talk/utils/MagicMap.java | 31 ++++++++++++++++ .../webrtc/MagicPeerConnectionWrapper.java | 2 +- .../talk/webrtc/MagicWebSocketInstance.java | 35 +++++-------------- 4 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/utils/MagicMap.java diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java index 07f73c5f6..b828fab32 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallController.java @@ -1263,7 +1263,7 @@ public class CallController extends BaseController { magicPeerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick()); String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec (ncSignalingMessage.getPayload().getSdp(), - "H264", false); + "VP8", false); SessionDescription sessionDescriptionWithPreferredCodec = new SessionDescription( SessionDescription.Type.fromCanonicalForm(type), diff --git a/app/src/main/java/com/nextcloud/talk/utils/MagicMap.java b/app/src/main/java/com/nextcloud/talk/utils/MagicMap.java new file mode 100644 index 000000000..0ae3d82c6 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/MagicMap.java @@ -0,0 +1,31 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.utils; + +import java.util.concurrent.ConcurrentHashMap; + +public class MagicMap extends ConcurrentHashMap { + public int add(Object element) { + int key = System.identityHashCode(element); + super.put(key, element); + return key; + } +} diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java index 5a91e2206..b967afb03 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicPeerConnectionWrapper.java @@ -340,7 +340,7 @@ public class MagicPeerConnectionWrapper { public void onCreateSuccess(SessionDescription sessionDescription) { String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec (sessionDescription.description, - "H264", false); + "VP8", false); SessionDescription sessionDescriptionWithPreferredCodec = new SessionDescription( sessionDescription.type, diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index b4298622f..883fd3199 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -33,6 +33,7 @@ import com.nextcloud.talk.models.json.websocket.CallOverallWebSocketMessage; import com.nextcloud.talk.models.json.websocket.ErrorOverallWebSocketMessage; import com.nextcloud.talk.models.json.websocket.EventOverallWebSocketMessage; import com.nextcloud.talk.models.json.websocket.HelloResponseOverallWebSocketMessage; +import com.nextcloud.talk.utils.MagicMap; import org.greenrobot.eventbus.EventBus; @@ -41,6 +42,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; import javax.inject.Inject; @@ -70,7 +72,7 @@ public class MagicWebSocketInstance extends WebSocketListener { private boolean connected; private WebSocketConnectionHelper webSocketConnectionHelper; private WebSocket webSocket; - private ConcurrentHashMap concurrentHashMapQueue; + private MagicMap magicMap; MagicWebSocketInstance(UserEntity conversationUser, String connectionUrl, String webSocketTicket) { NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); @@ -82,7 +84,7 @@ public class MagicWebSocketInstance extends WebSocketListener { this.webSocketTicket = webSocketTicket; this.webSocketConnectionHelper = new WebSocketConnectionHelper(); - concurrentHashMapQueue = new ConcurrentHashMap<>(); + magicMap = new MagicMap(); } @Override @@ -150,18 +152,8 @@ public class MagicWebSocketInstance extends WebSocketListener { Map participantsUpdateMap = eventOverallWebSocketMessage.getEventMap(); HashMap refreshChatHashMap = new HashMap<>(); refreshChatHashMap.put("roomToken", (String) eventOverallWebSocketMessage.getEventMap().get("roomid")); - int newId; - do { - Random rand = new Random(); - newId = rand.nextInt(1000); - if (!concurrentHashMapQueue.contains(newId)) { - concurrentHashMapQueue.put(newId, participantsUpdateMap.get("users")); - refreshChatHashMap.put("roomToken", (String) eventOverallWebSocketMessage.getEventMap().get("roomid")); - refreshChatHashMap.put("jobId", Integer.toString(newId)); - eventBus.post(new WebSocketCommunicationEvent("participantsUpdate", refreshChatHashMap)); - } - } while (!concurrentHashMapQueue.contains(newId)); - + refreshChatHashMap.put("jobId", Integer.toString(magicMap.add(participantsUpdateMap.get("users")))); + eventBus.post(new WebSocketCommunicationEvent("participantsUpdate", refreshChatHashMap)); } break; } @@ -169,18 +161,9 @@ public class MagicWebSocketInstance extends WebSocketListener { break; case "message": CallOverallWebSocketMessage callOverallWebSocketMessage = LoganSquare.parse(text, CallOverallWebSocketMessage.class); - int newId; - do { - HashMap messageHashMap = new HashMap<>(); - Random rand = new Random(); - newId = rand.nextInt(1000); - if (!concurrentHashMapQueue.contains(newId)) { - concurrentHashMapQueue.put(newId, callOverallWebSocketMessage.getCallWebSocketMessage().getNcSignalingMessage()); - messageHashMap.put("jobId", Integer.toString(newId)); - eventBus.post(new WebSocketCommunicationEvent("signalingMessage", messageHashMap)); - } - } while (!concurrentHashMapQueue.contains(newId)); - + HashMap messageHashMap = new HashMap<>(); + messageHashMap.put("jobId", Integer.toString(magicMap.add(callOverallWebSocketMessage.getCallWebSocketMessage().getNcSignalingMessage()))); + eventBus.post(new WebSocketCommunicationEvent("signalingMessage", messageHashMap)); break; default: break;