release resource. stop caputuring when webrtc ends

This commit is contained in:
Daniel Gultsch 2020-04-14 21:06:26 +02:00
parent b20b00e77f
commit 1489dba44f
3 changed files with 34 additions and 16 deletions

View File

@ -18,6 +18,7 @@ import android.widget.Toast;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer; import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoTrack; import org.webrtc.VideoTrack;
@ -241,6 +242,8 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
@Override @Override
public void onStop() { public void onStop() {
binding.remoteVideo.release();
binding.localVideo.release();
releaseProximityWakeLock(); releaseProximityWakeLock();
//TODO maybe we want to finish if call had ended //TODO maybe we want to finish if call had ended
super.onStop(); super.onStop();

View File

@ -139,6 +139,7 @@ public class WebRTCWrapper {
private AppRTCAudioManager appRTCAudioManager = null; private AppRTCAudioManager appRTCAudioManager = null;
private Context context = null; private Context context = null;
private EglBase eglBase = null; private EglBase eglBase = null;
private Optional<CameraVideoCapturer> optionalCapturer;
public WebRTCWrapper(final EventCallback eventCallback) { public WebRTCWrapper(final EventCallback eventCallback) {
this.eventCallback = eventCallback; this.eventCallback = eventCallback;
@ -167,10 +168,10 @@ public class WebRTCWrapper {
final MediaStream stream = peerConnectionFactory.createLocalMediaStream("my-media-stream"); final MediaStream stream = peerConnectionFactory.createLocalMediaStream("my-media-stream");
final Optional<CameraVideoCapturer> optionalCapturer = getVideoCapturer(); this.optionalCapturer = getVideoCapturer();
if (optionalCapturer.isPresent()) { if (this.optionalCapturer.isPresent()) {
final CameraVideoCapturer capturer = optionalCapturer.get(); final CameraVideoCapturer capturer = this.optionalCapturer.get();
final VideoSource videoSource = peerConnectionFactory.createVideoSource(false); final VideoSource videoSource = peerConnectionFactory.createVideoSource(false);
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("webrtc", eglBase.getEglBaseContext()); SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("webrtc", eglBase.getEglBaseContext());
capturer.initialize(surfaceTextureHelper, requireContext(), videoSource.getCapturerObserver()); capturer.initialize(surfaceTextureHelper, requireContext(), videoSource.getCapturerObserver());
@ -207,6 +208,16 @@ public class WebRTCWrapper {
if (audioManager != null) { if (audioManager != null) {
mainHandler.post(audioManager::stop); mainHandler.post(audioManager::stop);
} }
this.localVideoTrack = null;
this.remoteVideoTrack = null;
if (this.optionalCapturer.isPresent()) {
try {
this.optionalCapturer.get().stopCapture();
} catch (InterruptedException e) {
Log.e(Config.LOGTAG,"unable to stop capturing");
}
}
eglBase.release();
} }
public boolean isMicrophoneEnabled() { public boolean isMicrophoneEnabled() {
@ -326,7 +337,7 @@ public class WebRTCWrapper {
private Optional<CameraVideoCapturer> getVideoCapturer() { private Optional<CameraVideoCapturer> getVideoCapturer() {
final CameraEnumerator enumerator = getCameraEnumerator(); final CameraEnumerator enumerator = getCameraEnumerator();
final String[] deviceNames = enumerator.getDeviceNames(); final String[] deviceNames = enumerator.getDeviceNames();
for (String deviceName : deviceNames) { for (final String deviceName : deviceNames) {
if (enumerator.isFrontFacing(deviceName)) { if (enumerator.isFrontFacing(deviceName)) {
return Optional.fromNullable(enumerator.createCapturer(deviceName, null)); return Optional.fromNullable(enumerator.createCapturer(deviceName, null));
} }

View File

@ -35,24 +35,28 @@
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<org.webrtc.SurfaceViewRenderer
android:id="@+id/local_video"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@+id/app_bar_layout"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:visibility="gone" />
<org.webrtc.SurfaceViewRenderer <org.webrtc.SurfaceViewRenderer
android:id="@+id/remote_video" android:id="@+id/remote_video"
android:layout_width="100dp" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_below="@+id/app_bar_layout" android:layout_below="@+id/app_bar_layout"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:visibility="gone" /> android:layout_alignParentBottom="true"
android:visibility="visible" />
<org.webrtc.SurfaceViewRenderer
android:id="@+id/local_video"
android:layout_width="80dp"
android:layout_height="128dp"
android:layout_below="@+id/app_bar_layout"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:visibility="visible" />
<RelativeLayout <RelativeLayout
android:layout_width="288dp" android:layout_width="288dp"