properly paint local video over remote

This commit is contained in:
Daniel Gultsch 2020-04-15 13:21:21 +02:00
parent d057ae3439
commit 17d9b02f41
3 changed files with 32 additions and 25 deletions

View File

@ -62,6 +62,7 @@
android:networkSecurityConfig="@xml/network_security_configuration"
android:theme="@style/ConversationsTheme"
tools:replace="android:label"
android:hardwareAccelerated="true"
tools:targetApi="o">
<meta-data

View File

@ -201,7 +201,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
resetIntent(intent.getExtras());
}
} else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(intent.getAction())) {
proposeJingleRtpSession(account, with, ImmutableSet.of(Media.AUDIO));
proposeJingleRtpSession(account, with, ImmutableSet.of(Media.AUDIO, Media.VIDEO));
binding.with.setText(account.getRoster().getContact(with).getDisplayName());
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
@ -296,27 +296,33 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
private void updateVideoViews() {
final Optional<VideoTrack> localVideoTrack = requireRtpConnection().geLocalVideoTrack();
if (localVideoTrack.isPresent()) {
try {
binding.localVideo.init(requireRtpConnection().getEglBaseContext(), null);
} catch (IllegalStateException e) {
Log.d(Config.LOGTAG,"ignoring already init for now",e);
}
binding.localVideo.setEnableHardwareScaler(true);
ensureSurfaceViewRendererIsSetup(binding.localVideo);
//paint local view over remote view
binding.localVideo.setZOrderMediaOverlay(true);
binding.localVideo.setMirror(true);
localVideoTrack.get().addSink(binding.localVideo);
} else {
binding.localVideo.setVisibility(View.GONE);
}
final Optional<VideoTrack> remoteVideoTrack = requireRtpConnection().getRemoteVideoTrack();
if (remoteVideoTrack.isPresent()) {
try {
binding.remoteVideo.init(requireRtpConnection().getEglBaseContext(), null);
} catch (IllegalStateException e) {
Log.d(Config.LOGTAG,"ignoring already init for now",e);
}
binding.remoteVideo.setEnableHardwareScaler(true);
ensureSurfaceViewRendererIsSetup(binding.remoteVideo);
remoteVideoTrack.get().addSink(binding.remoteVideo);
} else {
binding.remoteVideo.setVisibility(View.GONE);
}
}
private void ensureSurfaceViewRendererIsSetup(final SurfaceViewRenderer surfaceViewRenderer) {
surfaceViewRenderer.setVisibility(View.VISIBLE);
try {
surfaceViewRenderer.init(requireRtpConnection().getEglBaseContext(), null);
} catch (IllegalStateException e) {
Log.d(Config.LOGTAG, "SurfaceViewRenderer was already initialized");
}
surfaceViewRenderer.setEnableHardwareScaler(true);
}
private void updateStateDisplay(final RtpEndUserState state) {
switch (state) {
case INCOMING_CALL:
@ -484,7 +490,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
final Account account = extractAccount(intent);
final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
this.rtpConnectionReference = null;
proposeJingleRtpSession(account, with, ImmutableSet.of(Media.AUDIO));
proposeJingleRtpSession(account, with, ImmutableSet.of(Media.AUDIO, Media.VIDEO));
}
private void exit(View view) {

View File

@ -35,16 +35,6 @@
</android.support.design.widget.AppBarLayout>
<org.webrtc.SurfaceViewRenderer
android:id="@+id/remote_video"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/app_bar_layout"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:visibility="visible" />
<org.webrtc.SurfaceViewRenderer
android:id="@+id/local_video"
android:layout_width="80dp"
@ -55,7 +45,17 @@
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:visibility="visible" />
android:visibility="gone" />
<org.webrtc.SurfaceViewRenderer
android:id="@+id/remote_video"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/app_bar_layout"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:visibility="gone" />
<RelativeLayout