use of org.webrtc.VideoTrack in project Signal-Android by WhisperSystems.
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();
}
use of org.webrtc.VideoTrack in project actor-platform by actorapp.
the class CallFragment method onResume.
@Override
public void onResume() {
super.onResume();
enableWakeLock();
//
// Bind State
//
bind(call.getState(), (val, valueModel) -> {
if (currentState != val) {
currentState = val;
switch(val) {
case RINGING:
if (call.isOutgoing()) {
statusTV.setText(R.string.call_outgoing);
} else {
statusTV.setText(R.string.call_incoming);
toggleSpeaker(speaker, speakerTV, true);
initIncoming();
}
break;
case CONNECTING:
statusTV.setText(R.string.call_connecting);
break;
case IN_PROGRESS:
toggleSpeaker(speaker, speakerTV, false);
onConnected();
startTimer();
break;
case ENDED:
statusTV.setText(R.string.call_ended);
onCallEnd();
break;
}
}
});
//
// Is Muted
//
bind(call.getIsAudioEnabled(), (val, valueModel) -> {
if (getActivity() != null) {
if (!val) {
muteCallTv.setTextColor(getResources().getColor(R.color.picker_grey));
muteCall.setTint(getResources().getColor(R.color.picker_grey));
} else {
muteCallTv.setTextColor(Color.WHITE);
muteCall.setTint(Color.WHITE);
}
}
});
//
if (peer.getPeerType() == PeerType.PRIVATE) {
//
// Video Button
//
bind(call.getIsVideoEnabled(), (val, valueModel) -> {
if (val) {
videoTv.setTextColor(Color.WHITE);
videoIcon.setTint(Color.WHITE);
} else {
videoTv.setTextColor(getResources().getColor(R.color.picker_grey));
videoIcon.setTint(getResources().getColor(R.color.picker_grey));
}
});
//
// Bind Own Stream
//
ACTIVITY_BINDER.bind(call.getOwnVideoTracks(), (videoTracks, valueModel) -> {
boolean isNeedUnbind = true;
if (videoTracks.size() > 0) {
if (!isLocalViewConfigured) {
localVideoView.init(eglContext.getEglBaseContext(), null);
isLocalViewConfigured = true;
}
VideoTrack videoTrack = ((AndroidVideoTrack) videoTracks.get(0)).getVideoTrack();
if (videoTrack != localTrack) {
if (localTrack != null) {
localTrack.removeRenderer(localRender);
localRender.dispose();
}
localTrack = videoTrack;
localRender = new VideoRenderer(localVideoView);
localTrack.addRenderer(localRender);
localVideoView.setVisibility(View.VISIBLE);
}
isNeedUnbind = false;
}
if (isNeedUnbind) {
if (localTrack != null) {
localTrack.removeRenderer(localRender);
localTrack = null;
localRender.dispose();
localRender = null;
}
if (isLocalViewConfigured) {
localVideoView.release();
isLocalViewConfigured = false;
}
localVideoView.setVisibility(View.INVISIBLE);
}
});
//
// Bind Their Stream
//
ACTIVITY_BINDER.bind(call.getTheirVideoTracks(), (videoTracks, valueModel) -> {
boolean isNeedUnbind = true;
if (videoTracks.size() > 0) {
if (!isRemoteViewConfigured) {
remoteVideoView.init(eglContext.getEglBaseContext(), null);
isRemoteViewConfigured = true;
}
VideoTrack videoTrack = ((AndroidVideoTrack) videoTracks.get(0)).getVideoTrack();
if (videoTrack != remoteTrack) {
if (remoteTrack != null) {
remoteTrack.removeRenderer(remoteRender);
remoteRender.dispose();
}
remoteTrack = videoTrack;
remoteRender = new VideoRenderer(remoteVideoView);
remoteTrack.addRenderer(remoteRender);
remoteVideoView.setVisibility(View.VISIBLE);
avatarView.setVisibility(View.INVISIBLE);
nameTV.setVisibility(View.INVISIBLE);
}
isNeedUnbind = false;
}
if (isNeedUnbind) {
if (remoteTrack != null) {
remoteTrack.removeRenderer(remoteRender);
remoteTrack = null;
remoteRender.dispose();
remoteRender = null;
}
if (isRemoteViewConfigured) {
remoteVideoView.release();
isRemoteViewConfigured = false;
}
remoteVideoView.setVisibility(View.INVISIBLE);
avatarView.setVisibility(View.VISIBLE);
nameTV.setVisibility(View.VISIBLE);
}
});
} else {
videoTv.setTextColor(getResources().getColor(R.color.picker_grey));
videoIcon.setTint(getResources().getColor(R.color.picker_grey));
}
//
// Hide "in progress" notification
//
manager.cancel(NOTIFICATION_ID);
}
use of org.webrtc.VideoTrack 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();
}
Aggregations