Search in sources :

Example 11 with BroadcastVideoSink

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

the class DeviceAwareActionProcessor method handleCameraSwitchCompleted.

@Override
@NonNull
public WebRtcServiceState handleCameraSwitchCompleted(@NonNull WebRtcServiceState currentState, @NonNull CameraState newCameraState) {
    Log.i(tag, "handleCameraSwitchCompleted():");
    BroadcastVideoSink localSink = currentState.getVideoState().getLocalSink();
    if (localSink != null) {
        localSink.setRotateToRightSide(newCameraState.getActiveDirection() == CameraState.Direction.BACK);
    }
    return currentState.builder().changeLocalDeviceState().cameraState(newCameraState).build();
}
Also used : BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) NonNull(androidx.annotation.NonNull)

Example 12 with BroadcastVideoSink

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

the class DeviceAwareActionProcessor method handleCameraSwitchCompleted.

@Override
@NonNull
public WebRtcServiceState handleCameraSwitchCompleted(@NonNull WebRtcServiceState currentState, @NonNull CameraState newCameraState) {
    Log.i(tag, "handleCameraSwitchCompleted():");
    BroadcastVideoSink localSink = currentState.getVideoState().getLocalSink();
    if (localSink != null) {
        localSink.setRotateToRightSide(newCameraState.getActiveDirection() == CameraState.Direction.BACK);
    }
    return currentState.builder().changeLocalDeviceState().cameraState(newCameraState).build();
}
Also used : BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) NonNull(androidx.annotation.NonNull)

Example 13 with BroadcastVideoSink

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

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 14 with BroadcastVideoSink

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

the class WebRtcActionProcessor method handleOrientationChanged.

@NonNull
protected WebRtcServiceState handleOrientationChanged(@NonNull WebRtcServiceState currentState, boolean isLandscapeEnabled, int orientationDegrees) {
    Camera camera = currentState.getVideoState().getCamera();
    if (camera != null) {
        camera.setOrientation(orientationDegrees);
    }
    int sinkRotationDegrees = isLandscapeEnabled ? BroadcastVideoSink.DEVICE_ROTATION_IGNORE : orientationDegrees;
    int stateRotationDegrees = isLandscapeEnabled ? 0 : orientationDegrees;
    BroadcastVideoSink sink = currentState.getVideoState().getLocalSink();
    if (sink != null) {
        sink.setDeviceOrientationDegrees(sinkRotationDegrees);
    }
    for (CallParticipant callParticipant : currentState.getCallInfoState().getRemoteCallParticipants()) {
        callParticipant.getVideoSink().setDeviceOrientationDegrees(sinkRotationDegrees);
    }
    return currentState.builder().changeLocalDeviceState().setOrientation(Orientation.fromDegrees(stateRotationDegrees)).setLandscapeEnabled(isLandscapeEnabled).setDeviceOrientation(Orientation.fromDegrees(orientationDegrees)).build();
}
Also used : CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) Camera(org.thoughtcrime.securesms.ringrtc.Camera) NonNull(androidx.annotation.NonNull)

Example 15 with BroadcastVideoSink

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

the class GroupActionProcessor method handleGroupRemoteDeviceStateChanged.

@Override
@NonNull
protected WebRtcServiceState handleGroupRemoteDeviceStateChanged(@NonNull WebRtcServiceState currentState) {
    Log.i(tag, "handleGroupRemoteDeviceStateChanged():");
    GroupCall groupCall = currentState.getCallInfoState().requireGroupCall();
    Map<CallParticipantId, CallParticipant> participants = currentState.getCallInfoState().getRemoteCallParticipantsMap();
    LongSparseArray<GroupCall.RemoteDeviceState> remoteDevices = groupCall.getRemoteDeviceStates();
    if (remoteDevices == null) {
        Log.w(tag, "Unable to update remote devices with null list.");
        return currentState;
    }
    WebRtcServiceStateBuilder.CallInfoStateBuilder builder = currentState.builder().changeCallInfoState().clearParticipantMap();
    List<GroupCall.RemoteDeviceState> remoteDeviceStates = new ArrayList<>(remoteDevices.size());
    for (int i = 0; i < remoteDevices.size(); i++) {
        remoteDeviceStates.add(remoteDevices.get(remoteDevices.keyAt(i)));
    }
    Collections.sort(remoteDeviceStates, (a, b) -> Long.compare(a.getAddedTime(), b.getAddedTime()));
    Set<Recipient> seen = new HashSet<>();
    seen.add(Recipient.self());
    for (GroupCall.RemoteDeviceState device : remoteDeviceStates) {
        Recipient recipient = Recipient.externalPush(ACI.from(device.getUserId()), null, false);
        CallParticipantId callParticipantId = new CallParticipantId(device.getDemuxId(), recipient.getId());
        CallParticipant callParticipant = participants.get(callParticipantId);
        BroadcastVideoSink videoSink;
        VideoTrack videoTrack = device.getVideoTrack();
        if (videoTrack != null) {
            videoSink = (callParticipant != null && callParticipant.getVideoSink().getLockableEglBase().getEglBase() != null) ? callParticipant.getVideoSink() : new BroadcastVideoSink(currentState.getVideoState().getLockableEglBase(), true, true, currentState.getLocalDeviceState().getOrientation().getDegrees());
            videoTrack.addSink(videoSink);
        } else {
            videoSink = new BroadcastVideoSink();
        }
        builder.putParticipant(callParticipantId, CallParticipant.createRemote(callParticipantId, recipient, null, videoSink, Boolean.FALSE.equals(device.getAudioMuted()), Boolean.FALSE.equals(device.getVideoMuted()), device.getSpeakerTime(), device.getMediaKeysReceived(), device.getAddedTime(), Boolean.TRUE.equals(device.getPresenting()), seen.contains(recipient) ? CallParticipant.DeviceOrdinal.SECONDARY : CallParticipant.DeviceOrdinal.PRIMARY));
        seen.add(recipient);
    }
    builder.remoteDevicesCount(remoteDevices.size());
    return builder.build();
}
Also used : CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) ArrayList(java.util.ArrayList) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) VideoTrack(org.webrtc.VideoTrack) GroupCall(org.signal.ringrtc.GroupCall) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Aggregations

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