Display audio levels in 1:1 calls.

fork-5.53.8
Rashad Sookram 2022-04-05 13:29:49 -04:00 zatwierdzone przez Cody Henthorne
rodzic dabd131222
commit 73f32868a2
8 zmienionych plików z 34 dodań i 10 usunięć

Wyświetl plik

@ -88,9 +88,8 @@ data class CallParticipant constructor(
* display in the UI. * display in the UI.
*/ */
@JvmStatic @JvmStatic
fun fromRawAudioLevel(raw: Int?): AudioLevel? { fun fromRawAudioLevel(raw: Int): AudioLevel {
return when { return when {
raw == null -> null
raw < 500 -> LOWEST raw < 500 -> LOWEST
raw < 2000 -> LOW raw < 2000 -> LOW
raw < 8000 -> MEDIUM raw < 8000 -> MEDIUM

Wyświetl plik

@ -8,11 +8,17 @@ import androidx.annotation.Nullable;
import org.signal.core.util.logging.Log; import org.signal.core.util.logging.Log;
import org.signal.ringrtc.CallException; import org.signal.ringrtc.CallException;
import org.signal.ringrtc.CallManager; import org.signal.ringrtc.CallManager;
import org.thoughtcrime.securesms.events.CallParticipant;
import org.thoughtcrime.securesms.events.CallParticipantId;
import org.thoughtcrime.securesms.events.WebRtcViewModel; import org.thoughtcrime.securesms.events.WebRtcViewModel;
import org.thoughtcrime.securesms.ringrtc.RemotePeer; import org.thoughtcrime.securesms.ringrtc.RemotePeer;
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcEphemeralState;
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState; import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState;
import org.thoughtcrime.securesms.webrtc.locks.LockManager; import org.thoughtcrime.securesms.webrtc.locks.LockManager;
import java.util.Collections;
import java.util.Optional;
/** /**
* Handles action for a connected/ongoing call. At this point it's mostly responding * Handles action for a connected/ongoing call. At this point it's mostly responding
* to user actions (local and remote) on video/mic and adjusting accordingly. * to user actions (local and remote) on video/mic and adjusting accordingly.
@ -75,6 +81,24 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor {
return currentState; return currentState;
} }
@Override
protected @NonNull WebRtcEphemeralState handleAudioLevelsChanged(@NonNull WebRtcServiceState currentState,
@NonNull WebRtcEphemeralState ephemeralState,
int localLevel,
int remoteLevel) {
Optional<CallParticipantId> callParticipantId = currentState.getCallInfoState()
.getRemoteCallParticipantsMap()
.keySet()
.stream()
.findFirst();
return ephemeralState.copy(
CallParticipant.AudioLevel.fromRawAudioLevel(localLevel),
callParticipantId.map(participantId -> Collections.singletonMap(participantId, CallParticipant.AudioLevel.fromRawAudioLevel(remoteLevel)))
.orElse(Collections.emptyMap())
);
}
@Override @Override
public @NonNull WebRtcServiceState handleCallReconnect(@NonNull WebRtcServiceState currentState, @NonNull CallManager.CallEvent event) { public @NonNull WebRtcServiceState handleCallReconnect(@NonNull WebRtcServiceState currentState, @NonNull CallManager.CallEvent event) {
Log.i(TAG, "handleCallReconnect(): event: " + event); Log.i(TAG, "handleCallReconnect(): event: " + event);

Wyświetl plik

@ -120,15 +120,12 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor {
for (CallParticipant participant : currentState.getCallInfoState().getRemoteCallParticipants()) { for (CallParticipant participant : currentState.getCallInfoState().getRemoteCallParticipants()) {
CallParticipantId callParticipantId = participant.getCallParticipantId(); CallParticipantId callParticipantId = participant.getCallParticipantId();
Integer audioLevel = null;
if (remoteDeviceStates != null) { if (remoteDeviceStates != null) {
GroupCall.RemoteDeviceState state = remoteDeviceStates.get(callParticipantId.getDemuxId()); GroupCall.RemoteDeviceState state = remoteDeviceStates.get(callParticipantId.getDemuxId());
if (state != null) { if (state != null) {
audioLevel = state.getAudioLevel(); remoteAudioLevels.put(callParticipantId, CallParticipant.AudioLevel.fromRawAudioLevel(state.getAudioLevel()));
} }
} }
remoteAudioLevels.put(callParticipantId, CallParticipant.AudioLevel.fromRawAudioLevel(audioLevel));
} }
return ephemeralState.copy(localAudioLevel, remoteAudioLevels); return ephemeralState.copy(localAudioLevel, remoteAudioLevels);

Wyświetl plik

@ -106,7 +106,7 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
callSetupState.getIceServers(), callSetupState.getIceServers(),
hideIp, hideIp,
NetworkUtil.getCallingBandwidthMode(context), NetworkUtil.getCallingBandwidthMode(context),
null, AUDIO_LEVELS_INTERVAL,
false); false);
} catch (CallException e) { } catch (CallException e) {
return callFailure(currentState, "Unable to proceed with call: ", e); return callFailure(currentState, "Unable to proceed with call: ", e);

Wyświetl plik

@ -150,7 +150,7 @@ public class OutgoingCallActionProcessor extends DeviceAwareActionProcessor {
callSetupState.getIceServers(), callSetupState.getIceServers(),
callSetupState.isAlwaysTurnServers(), callSetupState.isAlwaysTurnServers(),
NetworkUtil.getCallingBandwidthMode(context), NetworkUtil.getCallingBandwidthMode(context),
null, AUDIO_LEVELS_INTERVAL,
currentState.getCallSetupState(activePeer).isEnableVideoOnCreate()); currentState.getCallSetupState(activePeer).isEnableVideoOnCreate());
} catch (CallException e) { } catch (CallException e) {
return callFailure(currentState, "Unable to proceed with call: ", e); return callFailure(currentState, "Unable to proceed with call: ", e);

Wyświetl plik

@ -524,7 +524,7 @@ private void processStateless(@NonNull Function1<WebRtcEphemeralState, WebRtcEph
@Override @Override
public void onAudioLevels(Remote remote, int capturedLevel, int receivedLevel) { public void onAudioLevels(Remote remote, int capturedLevel, int receivedLevel) {
// TODO: Implement audio level handling for direct calls. processStateless(s -> serviceState.getActionProcessor().handleAudioLevelsChanged(serviceState, s, capturedLevel, receivedLevel));
} }
@Override @Override

Wyświetl plik

@ -462,6 +462,10 @@ public abstract class WebRtcActionProcessor {
return currentState; return currentState;
} }
protected @NonNull WebRtcEphemeralState handleAudioLevelsChanged(@NonNull WebRtcServiceState currentState, @NonNull WebRtcEphemeralState ephemeralState, int localLevel, int remoteLevel) {
return ephemeralState;
}
public @NonNull WebRtcServiceState handleCallReconnect(@NonNull WebRtcServiceState currentState, @NonNull CallManager.CallEvent event) { public @NonNull WebRtcServiceState handleCallReconnect(@NonNull WebRtcServiceState currentState, @NonNull CallManager.CallEvent event) {
Log.i(tag, "handleCallReconnect not processed"); Log.i(tag, "handleCallReconnect not processed");
return currentState; return currentState;

Wyświetl plik

@ -7,6 +7,6 @@ import org.thoughtcrime.securesms.events.CallParticipantId
* The state of the call system which contains data which changes frequently. * The state of the call system which contains data which changes frequently.
*/ */
data class WebRtcEphemeralState( data class WebRtcEphemeralState(
val localAudioLevel: CallParticipant.AudioLevel? = null, val localAudioLevel: CallParticipant.AudioLevel = CallParticipant.AudioLevel.LOWEST,
val remoteAudioLevels: Map<CallParticipantId, CallParticipant.AudioLevel> = emptyMap(), val remoteAudioLevels: Map<CallParticipantId, CallParticipant.AudioLevel> = emptyMap(),
) )