From fd22e6cf2d5f983f336e78d01c32e5cedd602503 Mon Sep 17 00:00:00 2001 From: Per Date: Thu, 18 Feb 2016 11:35:48 +0100 Subject: [PATCH] Change PeerConnectionFactory.setVideoHwAccelerationOptions to be able to replace Egl context. BUG=b/27222102 R=glaznev@webrtc.org Review URL: https://codereview.webrtc.org/1707933003 . Cr-Commit-Position: refs/heads/master@{#11666} --- webrtc/api/java/jni/androidmediadecoder_jni.cc | 5 ++++- webrtc/api/java/jni/androidmediaencoder_jni.cc | 5 ++++- .../api/java/src/org/webrtc/PeerConnectionFactory.java | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/webrtc/api/java/jni/androidmediadecoder_jni.cc b/webrtc/api/java/jni/androidmediadecoder_jni.cc index f7966cc44a..7c303e8fc3 100644 --- a/webrtc/api/java/jni/androidmediadecoder_jni.cc +++ b/webrtc/api/java/jni/androidmediadecoder_jni.cc @@ -896,7 +896,10 @@ MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() { void MediaCodecVideoDecoderFactory::SetEGLContext( JNIEnv* jni, jobject egl_context) { ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext"; - RTC_DCHECK(!egl_context_); + if (egl_context_) { + jni->DeleteGlobalRef(egl_context_); + egl_context_ = nullptr; + } egl_context_ = jni->NewGlobalRef(egl_context); if (CheckException(jni)) { ALOGE << "error calling NewGlobalRef for EGL Context."; diff --git a/webrtc/api/java/jni/androidmediaencoder_jni.cc b/webrtc/api/java/jni/androidmediaencoder_jni.cc index ddfa85affa..7fa93de149 100644 --- a/webrtc/api/java/jni/androidmediaencoder_jni.cc +++ b/webrtc/api/java/jni/androidmediaencoder_jni.cc @@ -1213,7 +1213,10 @@ MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { void MediaCodecVideoEncoderFactory::SetEGLContext( JNIEnv* jni, jobject egl_context) { ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; - RTC_DCHECK(!egl_context_); + if (egl_context_) { + jni->DeleteGlobalRef(egl_context_); + egl_context_ = nullptr; + } egl_context_ = jni->NewGlobalRef(egl_context); if (CheckException(jni)) { ALOGE << "error calling NewGlobalRef for EGL Context."; diff --git a/webrtc/api/java/src/org/webrtc/PeerConnectionFactory.java b/webrtc/api/java/src/org/webrtc/PeerConnectionFactory.java index 51e593e655..17fc7ab8e8 100644 --- a/webrtc/api/java/src/org/webrtc/PeerConnectionFactory.java +++ b/webrtc/api/java/src/org/webrtc/PeerConnectionFactory.java @@ -171,8 +171,13 @@ public class PeerConnectionFactory { */ public void setVideoHwAccelerationOptions(EglBase.Context localEglContext, EglBase.Context remoteEglContext) { - if (localEglbase != null || remoteEglbase != null) { - throw new IllegalStateException("Egl context already set."); + if (localEglbase != null) { + Logging.w(TAG, "Egl context already set."); + localEglbase.release(); + } + if (remoteEglbase != null) { + Logging.w(TAG, "Egl context already set."); + remoteEglbase.release(); } localEglbase = EglBase.create(localEglContext); remoteEglbase = EglBase.create(remoteEglContext);