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:networkSecurityConfig="@xml/network_security_configuration"
android:theme="@style/ConversationsTheme" android:theme="@style/ConversationsTheme"
tools:replace="android:label" tools:replace="android:label"
android:hardwareAccelerated="true"
tools:targetApi="o"> tools:targetApi="o">
<meta-data <meta-data

View File

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

View File

@ -35,16 +35,6 @@
</android.support.design.widget.AppBarLayout> </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 <org.webrtc.SurfaceViewRenderer
android:id="@+id/local_video" android:id="@+id/local_video"
android:layout_width="80dp" android:layout_width="80dp"
@ -55,7 +45,17 @@
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginRight="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 <RelativeLayout