Display audio levels in 1:1 calls.
This commit is contained in:
parent
dabd131222
commit
73f32868a2
8 changed files with 34 additions and 10 deletions
|
@ -88,9 +88,8 @@ data class CallParticipant constructor(
|
|||
* display in the UI.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun fromRawAudioLevel(raw: Int?): AudioLevel? {
|
||||
fun fromRawAudioLevel(raw: Int): AudioLevel {
|
||||
return when {
|
||||
raw == null -> null
|
||||
raw < 500 -> LOWEST
|
||||
raw < 2000 -> LOW
|
||||
raw < 8000 -> MEDIUM
|
||||
|
|
|
@ -8,11 +8,17 @@ import androidx.annotation.Nullable;
|
|||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.ringrtc.CallException;
|
||||
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.ringrtc.RemotePeer;
|
||||
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcEphemeralState;
|
||||
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState;
|
||||
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
|
||||
* to user actions (local and remote) on video/mic and adjusting accordingly.
|
||||
|
@ -75,6 +81,24 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor {
|
|||
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
|
||||
public @NonNull WebRtcServiceState handleCallReconnect(@NonNull WebRtcServiceState currentState, @NonNull CallManager.CallEvent event) {
|
||||
Log.i(TAG, "handleCallReconnect(): event: " + event);
|
||||
|
|
|
@ -120,15 +120,12 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor {
|
|||
for (CallParticipant participant : currentState.getCallInfoState().getRemoteCallParticipants()) {
|
||||
CallParticipantId callParticipantId = participant.getCallParticipantId();
|
||||
|
||||
Integer audioLevel = null;
|
||||
if (remoteDeviceStates != null) {
|
||||
GroupCall.RemoteDeviceState state = remoteDeviceStates.get(callParticipantId.getDemuxId());
|
||||
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);
|
||||
|
|
|
@ -106,7 +106,7 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
|
|||
callSetupState.getIceServers(),
|
||||
hideIp,
|
||||
NetworkUtil.getCallingBandwidthMode(context),
|
||||
null,
|
||||
AUDIO_LEVELS_INTERVAL,
|
||||
false);
|
||||
} catch (CallException e) {
|
||||
return callFailure(currentState, "Unable to proceed with call: ", e);
|
||||
|
|
|
@ -150,7 +150,7 @@ public class OutgoingCallActionProcessor extends DeviceAwareActionProcessor {
|
|||
callSetupState.getIceServers(),
|
||||
callSetupState.isAlwaysTurnServers(),
|
||||
NetworkUtil.getCallingBandwidthMode(context),
|
||||
null,
|
||||
AUDIO_LEVELS_INTERVAL,
|
||||
currentState.getCallSetupState(activePeer).isEnableVideoOnCreate());
|
||||
} catch (CallException e) {
|
||||
return callFailure(currentState, "Unable to proceed with call: ", e);
|
||||
|
|
|
@ -524,7 +524,7 @@ private void processStateless(@NonNull Function1<WebRtcEphemeralState, WebRtcEph
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -462,6 +462,10 @@ public abstract class WebRtcActionProcessor {
|
|||
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) {
|
||||
Log.i(tag, "handleCallReconnect not processed");
|
||||
return currentState;
|
||||
|
|
|
@ -7,6 +7,6 @@ import org.thoughtcrime.securesms.events.CallParticipantId
|
|||
* The state of the call system which contains data which changes frequently.
|
||||
*/
|
||||
data class WebRtcEphemeralState(
|
||||
val localAudioLevel: CallParticipant.AudioLevel? = null,
|
||||
val localAudioLevel: CallParticipant.AudioLevel = CallParticipant.AudioLevel.LOWEST,
|
||||
val remoteAudioLevels: Map<CallParticipantId, CallParticipant.AudioLevel> = emptyMap(),
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue