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.collect.ImmutableList;
import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoTrack;
@ -241,6 +242,8 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
@Override
public void onStop() {
binding.remoteVideo.release();
binding.localVideo.release();
releaseProximityWakeLock();
//TODO maybe we want to finish if call had ended
super.onStop();

View File

@ -139,6 +139,7 @@ public class WebRTCWrapper {
private AppRTCAudioManager appRTCAudioManager = null;
private Context context = null;
private EglBase eglBase = null;
private Optional<CameraVideoCapturer> optionalCapturer;
public WebRTCWrapper(final EventCallback eventCallback) {
this.eventCallback = eventCallback;
@ -167,10 +168,10 @@ public class WebRTCWrapper {
final MediaStream stream = peerConnectionFactory.createLocalMediaStream("my-media-stream");
final Optional<CameraVideoCapturer> optionalCapturer = getVideoCapturer();
this.optionalCapturer = getVideoCapturer();
if (optionalCapturer.isPresent()) {
final CameraVideoCapturer capturer = optionalCapturer.get();
if (this.optionalCapturer.isPresent()) {
final CameraVideoCapturer capturer = this.optionalCapturer.get();
final VideoSource videoSource = peerConnectionFactory.createVideoSource(false);
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("webrtc", eglBase.getEglBaseContext());
capturer.initialize(surfaceTextureHelper, requireContext(), videoSource.getCapturerObserver());
@ -207,6 +208,16 @@ public class WebRTCWrapper {
if (audioManager != null) {
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() {
@ -326,7 +337,7 @@ public class WebRTCWrapper {
private Optional<CameraVideoCapturer> getVideoCapturer() {
final CameraEnumerator enumerator = getCameraEnumerator();
final String[] deviceNames = enumerator.getDeviceNames();
for (String deviceName : deviceNames) {
for (final String deviceName : deviceNames) {
if (enumerator.isFrontFacing(deviceName)) {
return Optional.fromNullable(enumerator.createCapturer(deviceName, null));
}

View File

@ -35,24 +35,28 @@
</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
android:id="@+id/remote_video"
android:layout_width="100dp"
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: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
android:layout_width="288dp"