Search in sources :

Example 1 with BroadcastVideoSink

use of org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink in project Signal-Android by WhisperSystems.

the class IncomingGroupCallActionProcessor method handleGroupCallRingUpdate.

@Override
@NonNull
protected WebRtcServiceState handleGroupCallRingUpdate(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeerGroup, @NonNull GroupId.V2 groupId, long ringId, @NonNull UUID uuid, @NonNull CallManager.RingUpdate ringUpdate) {
    Log.i(TAG, "handleGroupCallRingUpdate(): recipient: " + remotePeerGroup.getId() + " ring: " + ringId + " update: " + ringUpdate);
    Recipient recipient = remotePeerGroup.getRecipient();
    boolean updateForCurrentRingId = ringId == currentState.getCallSetupState(RemotePeer.GROUP_CALL_ID).getRingId();
    boolean isCurrentlyRinging = currentState.getCallInfoState().getGroupCallState().isRinging();
    if (SignalDatabase.groupCallRings().isCancelled(ringId)) {
        try {
            Log.i(TAG, "Ignoring incoming ring request for already cancelled ring: " + ringId);
            webRtcInteractor.getCallManager().cancelGroupRing(groupId.getDecodedId(), ringId, null);
        } catch (CallException e) {
            Log.w(TAG, "Error while trying to cancel ring: " + ringId, e);
        }
        return currentState;
    }
    if (ringUpdate != CallManager.RingUpdate.REQUESTED) {
        SignalDatabase.groupCallRings().insertOrUpdateGroupRing(ringId, System.currentTimeMillis(), ringUpdate);
        if (updateForCurrentRingId && isCurrentlyRinging) {
            Log.i(TAG, "Cancelling current ring: " + ringId);
            currentState = currentState.builder().changeCallInfoState().callState(WebRtcViewModel.State.CALL_DISCONNECTED).build();
            webRtcInteractor.postStateUpdate(currentState);
            return terminateGroupCall(currentState);
        } else {
            return currentState;
        }
    }
    if (!updateForCurrentRingId && isCurrentlyRinging) {
        try {
            Log.i(TAG, "Already ringing so reply busy for new ring: " + ringId);
            webRtcInteractor.getCallManager().cancelGroupRing(groupId.getDecodedId(), ringId, CallManager.RingCancelReason.Busy);
        } catch (CallException e) {
            Log.w(TAG, "Error while trying to cancel ring: " + ringId, e);
        }
        return currentState;
    }
    if (updateForCurrentRingId) {
        Log.i(TAG, "Already ringing for ring: " + ringId);
        return currentState;
    }
    Log.i(TAG, "Requesting new ring: " + ringId);
    SignalDatabase.groupCallRings().insertGroupRing(ringId, System.currentTimeMillis(), ringUpdate);
    currentState = WebRtcVideoUtil.initializeVideo(context, webRtcInteractor.getCameraEventListener(), currentState, RemotePeer.GROUP_CALL_ID.longValue());
    webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_RINGING, remotePeerGroup);
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.INTERACTIVE);
    webRtcInteractor.initializeAudioForCall();
    boolean shouldDisturbUserWithCall = DoNotDisturbUtil.shouldDisturbUserWithCall(context.getApplicationContext());
    if (shouldDisturbUserWithCall) {
        boolean started = webRtcInteractor.startWebRtcCallActivityIfPossible();
        if (!started) {
            Log.i(TAG, "Unable to start call activity due to OS version or not being in the foreground");
            ApplicationDependencies.getAppForegroundObserver().addListener(webRtcInteractor.getForegroundListener());
        }
    }
    if (shouldDisturbUserWithCall && SignalStore.settings().isCallNotificationsEnabled()) {
        Uri ringtone = recipient.resolve().getCallRingtone();
        RecipientDatabase.VibrateState vibrateState = recipient.resolve().getCallVibrate();
        if (ringtone == null) {
            ringtone = SignalStore.settings().getCallRingtone();
        }
        webRtcInteractor.startIncomingRinger(ringtone, vibrateState == RecipientDatabase.VibrateState.ENABLED || (vibrateState == RecipientDatabase.VibrateState.DEFAULT && SignalStore.settings().isCallVibrateEnabled()));
    }
    webRtcInteractor.registerPowerButtonReceiver();
    return currentState.builder().changeCallSetupState(RemotePeer.GROUP_CALL_ID).isRemoteVideoOffer(true).ringId(ringId).ringerRecipient(Recipient.externalPush(ACI.from(uuid), null, false)).commit().changeCallInfoState().activePeer(new RemotePeer(currentState.getCallInfoState().getCallRecipient().getId(), RemotePeer.GROUP_CALL_ID)).callRecipient(remotePeerGroup.getRecipient()).callState(WebRtcViewModel.State.CALL_INCOMING).groupCallState(WebRtcViewModel.GroupCallState.RINGING).putParticipant(remotePeerGroup.getRecipient(), CallParticipant.createRemote(new CallParticipantId(remotePeerGroup.getRecipient()), remotePeerGroup.getRecipient(), null, new BroadcastVideoSink(currentState.getVideoState().getLockableEglBase(), false, true, currentState.getLocalDeviceState().getOrientation().getDegrees()), true, false, 0, true, 0, false, CallParticipant.DeviceOrdinal.PRIMARY)).build();
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) CallException(org.signal.ringrtc.CallException) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) Recipient(org.thoughtcrime.securesms.recipients.Recipient) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) Uri(android.net.Uri) NonNull(androidx.annotation.NonNull)

Example 2 with BroadcastVideoSink

use of org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink in project Signal-Android by WhisperSystems.

the class GroupPreJoinActionProcessor method handleGroupJoinedMembershipChanged.

@Override
@NonNull
protected WebRtcServiceState handleGroupJoinedMembershipChanged(@NonNull WebRtcServiceState currentState) {
    Log.i(tag, "handleGroupJoinedMembershipChanged():");
    GroupCall groupCall = currentState.getCallInfoState().requireGroupCall();
    PeekInfo peekInfo = groupCall.getPeekInfo();
    if (peekInfo == null) {
        Log.i(tag, "No peek info available");
        return currentState;
    }
    List<Recipient> callParticipants = Stream.of(peekInfo.getJoinedMembers()).map(uuid -> Recipient.externalPush(ACI.from(uuid), null, false)).toList();
    WebRtcServiceStateBuilder.CallInfoStateBuilder builder = currentState.builder().changeCallInfoState().remoteDevicesCount(peekInfo.getDeviceCount()).participantLimit(peekInfo.getMaxDevices()).clearParticipantMap();
    for (Recipient recipient : callParticipants) {
        builder.putParticipant(recipient, CallParticipant.createRemote(new CallParticipantId(recipient), recipient, null, new BroadcastVideoSink(), true, true, 0, false, 0, false, CallParticipant.DeviceOrdinal.PRIMARY));
    }
    return builder.build();
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) Stream(com.annimon.stream.Stream) ACI(org.whispersystems.signalservice.api.push.ACI) NonNull(androidx.annotation.NonNull) WebRtcViewModel(org.thoughtcrime.securesms.events.WebRtcViewModel) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) TYPE_OUTGOING_RINGING(org.thoughtcrime.securesms.webrtc.CallNotificationBuilder.TYPE_OUTGOING_RINGING) CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) EglBaseWrapper(org.thoughtcrime.securesms.components.webrtc.EglBaseWrapper) CallException(org.signal.ringrtc.CallException) GroupCall(org.signal.ringrtc.GroupCall) Log(org.signal.core.util.logging.Log) List(java.util.List) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) PeekInfo(org.signal.ringrtc.PeekInfo) NetworkUtil(org.thoughtcrime.securesms.util.NetworkUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) WebRtcServiceState(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) GroupCall(org.signal.ringrtc.GroupCall) PeekInfo(org.signal.ringrtc.PeekInfo) Recipient(org.thoughtcrime.securesms.recipients.Recipient) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) NonNull(androidx.annotation.NonNull)

Example 3 with BroadcastVideoSink

use of org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink in project Signal-Android by WhisperSystems.

the class BeginCallActionProcessorDelegate method handleStartIncomingCall.

@Override
@NonNull
protected WebRtcServiceState handleStartIncomingCall(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) {
    remotePeer.answering();
    Log.i(tag, "assign activePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode());
    webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_CONNECTING, remotePeer);
    webRtcInteractor.retrieveTurnServers(remotePeer);
    webRtcInteractor.initializeAudioForCall();
    return currentState.builder().actionProcessor(new IncomingCallActionProcessor(webRtcInteractor)).changeCallInfoState().callRecipient(remotePeer.getRecipient()).activePeer(remotePeer).callState(WebRtcViewModel.State.CALL_INCOMING).putParticipant(remotePeer.getRecipient(), CallParticipant.createRemote(new CallParticipantId(remotePeer.getRecipient()), remotePeer.getRecipient(), null, new BroadcastVideoSink(currentState.getVideoState().getLockableEglBase(), false, true, currentState.getLocalDeviceState().getOrientation().getDegrees()), true, false, 0, true, 0, false, CallParticipant.DeviceOrdinal.PRIMARY)).build();
}
Also used : BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) NonNull(androidx.annotation.NonNull)

Example 4 with BroadcastVideoSink

use of org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink in project Signal-Android by WhisperSystems.

the class WebRtcVideoUtil method initializeVideo.

@NonNull
public static WebRtcServiceState initializeVideo(@NonNull Context context, @NonNull CameraEventListener cameraEventListener, @NonNull WebRtcServiceState currentState, @NonNull Object eglBaseHolder) {
    final WebRtcServiceStateBuilder builder = currentState.builder();
    ThreadUtil.runOnMainSync(() -> {
        EglBaseWrapper eglBase = EglBaseWrapper.acquireEglBase(eglBaseHolder);
        BroadcastVideoSink localSink = new BroadcastVideoSink(eglBase, true, false, currentState.getLocalDeviceState().getOrientation().getDegrees());
        Camera camera = new Camera(context, cameraEventListener, eglBase, CameraState.Direction.FRONT);
        camera.setOrientation(currentState.getLocalDeviceState().getOrientation().getDegrees());
        builder.changeVideoState().eglBase(eglBase).localSink(localSink).camera(camera).commit().changeLocalDeviceState().cameraState(camera.getCameraState()).commit();
    });
    return builder.build();
}
Also used : BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) EglBaseWrapper(org.thoughtcrime.securesms.components.webrtc.EglBaseWrapper) Camera(org.thoughtcrime.securesms.ringrtc.Camera) NonNull(androidx.annotation.NonNull)

Example 5 with BroadcastVideoSink

use of org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink in project Signal-Android by WhisperSystems.

the class GroupActionProcessor method handleUpdateRenderedResolutions.

@Override
@NonNull
protected WebRtcServiceState handleUpdateRenderedResolutions(@NonNull WebRtcServiceState currentState) {
    Map<CallParticipantId, CallParticipant> participants = currentState.getCallInfoState().getRemoteCallParticipantsMap();
    ArrayList<GroupCall.VideoRequest> resolutionRequests = new ArrayList<>(participants.size());
    for (Map.Entry<CallParticipantId, CallParticipant> entry : participants.entrySet()) {
        BroadcastVideoSink videoSink = entry.getValue().getVideoSink();
        BroadcastVideoSink.RequestedSize maxSize = videoSink.getMaxRequestingSize();
        resolutionRequests.add(new GroupCall.VideoRequest(entry.getKey().getDemuxId(), maxSize.getWidth(), maxSize.getHeight(), null));
        videoSink.setCurrentlyRequestedMaxSize(maxSize);
    }
    try {
        currentState.getCallInfoState().requireGroupCall().requestVideo(resolutionRequests);
    } catch (CallException e) {
        return groupCallFailure(currentState, "Unable to set rendered resolutions", e);
    }
    return currentState;
}
Also used : CallException(org.signal.ringrtc.CallException) CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) ArrayList(java.util.ArrayList) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) GroupCall(org.signal.ringrtc.GroupCall) Map(java.util.Map) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)8 BroadcastVideoSink (org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink)8 CallParticipantId (org.thoughtcrime.securesms.events.CallParticipantId)5 CallParticipant (org.thoughtcrime.securesms.events.CallParticipant)4 CallException (org.signal.ringrtc.CallException)3 GroupCall (org.signal.ringrtc.GroupCall)3 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 WebRtcServiceStateBuilder (org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder)3 ArrayList (java.util.ArrayList)2 EglBaseWrapper (org.thoughtcrime.securesms.components.webrtc.EglBaseWrapper)2 Camera (org.thoughtcrime.securesms.ringrtc.Camera)2 RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)2 Uri (android.net.Uri)1 Stream (com.annimon.stream.Stream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Log (org.signal.core.util.logging.Log)1 PeekInfo (org.signal.ringrtc.PeekInfo)1 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)1