Commit 420d1038 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Feature/android texture display

parent c08c8b9d
......@@ -5348,7 +5348,7 @@ static void unset_video_window_id(LinphoneCore *lc, bool_t preview, void *id){
L_GET_PRIVATE_FROM_C_OBJECT(lc)->unsetVideoWindowId(!!preview, id);
}
void linphone_core_set_native_video_window_id(LinphoneCore *lc, void *id){
void _linphone_core_set_native_video_window_id(LinphoneCore *lc, void *id) {
if ((id == NULL)
#ifndef _WIN32
|| ((unsigned long)id == (unsigned long)-1)
......@@ -5369,6 +5369,14 @@ void linphone_core_set_native_video_window_id(LinphoneCore *lc, void *id){
#endif
}
void linphone_core_set_native_video_window_id(LinphoneCore *lc, void *id) {
#ifdef ANDROID
getPlatformHelpers(lc)->setVideoWindow(id);
#else
_linphone_core_set_native_video_window_id(lc, id);
#endif
}
void * linphone_core_get_native_preview_window_id(const LinphoneCore *lc){
if (lc->preview_window_id){
/*case where the id was set by the app previously*/
......@@ -5389,7 +5397,7 @@ void * linphone_core_get_native_preview_window_id(const LinphoneCore *lc){
return 0;
}
void linphone_core_set_native_preview_window_id(LinphoneCore *lc, void *id){
void _linphone_core_set_native_preview_window_id(LinphoneCore *lc, void *id) {
if ((id == NULL)
#ifndef _WIN32
|| ((unsigned long)id == (unsigned long)-1)
......@@ -5412,6 +5420,14 @@ void linphone_core_set_native_preview_window_id(LinphoneCore *lc, void *id){
#endif
}
void linphone_core_set_native_preview_window_id(LinphoneCore *lc, void *id) {
#ifdef ANDROID
getPlatformHelpers(lc)->setVideoPreviewWindow(id);
#else
_linphone_core_set_native_preview_window_id(lc, id);
#endif
}
void linphone_core_show_video(LinphoneCore *lc, bool_t show){
#ifdef VIDEO_ENABLED
LinphoneCall *call=linphone_core_get_current_call(lc);
......
......@@ -458,11 +458,11 @@ LinphoneReason linphone_reason_from_sal(SalReason r){
* @ingroup media_parameters
**/
void linphone_core_set_video_display_filter(LinphoneCore *lc, const char *filter_name){
lp_config_set_string(lc->config,"video","displaytype",filter_name);
lp_config_set_string(lc->config,"video", "displaytype", filter_name);
}
const char *linphone_core_get_video_display_filter(LinphoneCore *lc){
return lp_config_get_string(lc->config,"video","displaytype",NULL);
return lp_config_get_string(lc->config, "video","displaytype", NULL);
}
void linphone_core_set_echo_canceller_filter_name(LinphoneCore *lc, const char *filtername) {
......
......@@ -583,6 +583,9 @@ void linphone_info_message_set_headers (LinphoneInfoMessage *im, const SalCustom
void _linphone_core_set_log_handler(OrtpLogFunc logfunc);
void _linphone_core_set_native_preview_window_id(LinphoneCore *lc, void *id);
void _linphone_core_set_native_video_window_id(LinphoneCore *lc, void *id);
#ifdef __cplusplus
}
#endif
......
......@@ -45,6 +45,11 @@ public:
void releaseCpuLock () override;
string getDataPath () override;
string getConfigPath () override;
void setVideoWindow (void *windowId) override;
void setVideoPreviewWindow (void *windowId) override;
void _setPreviewVideoWindow(jobject window);
void _setVideoWindow(jobject window);
private:
int callVoidMethod (jmethodID id);
......@@ -62,6 +67,10 @@ private:
jmethodID mGetDataPathId;
jmethodID mGetConfigPathId;
jmethodID mGetNativeLibraryDirId;
jmethodID mSetNativeVideoWindowId;
jmethodID mSetNativePreviewVideoWindowId;
jobject mPreviewVideoWindow;
jobject mVideoWindow;
};
static const char *GetStringUTFChars (JNIEnv *env, jstring string) {
......@@ -86,8 +95,8 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
if (!klass)
lFatal() << "Could not find java AndroidPlatformHelper class.";
jmethodID ctor = env->GetMethodID(klass, "<init>", "(Ljava/lang/Object;)V");
mJavaHelper = env->NewObject(klass, ctor, (jobject)systemContext);
jmethodID ctor = env->GetMethodID(klass, "<init>", "(JLjava/lang/Object;)V");
mJavaHelper = env->NewObject(klass, ctor, this, (jobject)systemContext);
if (!mJavaHelper) {
lError() << "Could not instanciate AndroidPlatformHelper object.";
return;
......@@ -105,6 +114,8 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
mGetDataPathId = getMethodId(env, klass, "getDataPath", "()Ljava/lang/String;");
mGetConfigPathId = getMethodId(env, klass, "getConfigPath", "()Ljava/lang/String;");
mGetNativeLibraryDirId = getMethodId(env, klass, "getNativeLibraryDir", "()Ljava/lang/String;");
mSetNativeVideoWindowId = getMethodId(env, klass, "setVideoRenderingView", "(Ljava/lang/Object;)V");
mSetNativePreviewVideoWindowId = getMethodId(env, klass, "setVideoPreviewView", "(Ljava/lang/Object;)V");
jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId);
belle_sip_wake_lock_init(env, pm);
......@@ -112,6 +123,9 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
linphone_factory_set_top_resources_dir(linphone_factory_get() , getDataPath().append("share").c_str());
linphone_factory_set_msplugins_dir(linphone_factory_get(), getNativeLibraryDir().c_str());
lInfo() << "AndroidPlatformHelpers is fully initialised.";
mPreviewVideoWindow = nullptr;
mVideoWindow = nullptr;
}
AndroidPlatformHelpers::~AndroidPlatformHelpers () {
......@@ -225,8 +239,72 @@ int AndroidPlatformHelpers::callVoidMethod (jmethodID id) {
return -1;
}
void AndroidPlatformHelpers::setVideoPreviewWindow (void *windowId) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
string displayFilter = linphone_core_get_video_display_filter(getCore());
if (windowId && (displayFilter.empty() || displayFilter == "MSAndroidTextureDisplay")) {
env->CallVoidMethod(mJavaHelper, mSetNativePreviewVideoWindowId, (jobject)windowId);
} else {
_setPreviewVideoWindow((jobject)windowId);
}
}
}
void AndroidPlatformHelpers::setVideoWindow (void *windowId) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
string displayFilter = linphone_core_get_video_display_filter(getCore());
if (windowId && (displayFilter.empty() || displayFilter == "MSAndroidTextureDisplay")) {
env->CallVoidMethod(mJavaHelper, mSetNativeVideoWindowId, (jobject)windowId);
} else {
_setVideoWindow((jobject)windowId);
}
}
}
void AndroidPlatformHelpers::_setPreviewVideoWindow(jobject window) {
JNIEnv *env = ms_get_jni_env();
LinphoneCore *lc = getCore();
if (window != nullptr && window != mPreviewVideoWindow) {
if (mPreviewVideoWindow != nullptr) {
env->DeleteGlobalRef(mPreviewVideoWindow);
}
mPreviewVideoWindow = env->NewGlobalRef(window);
} else if (window == nullptr && mPreviewVideoWindow != nullptr) {
env->DeleteGlobalRef(mPreviewVideoWindow);
mPreviewVideoWindow = nullptr;
}
_linphone_core_set_native_preview_window_id(lc, (void *)mPreviewVideoWindow);
}
void AndroidPlatformHelpers::_setVideoWindow(jobject window) {
JNIEnv *env = ms_get_jni_env();
LinphoneCore *lc = getCore();
if (window != nullptr && window != mVideoWindow) {
if (mVideoWindow != nullptr) {
env->DeleteGlobalRef(mVideoWindow);
}
mVideoWindow = env->NewGlobalRef(window);
} else if (window == nullptr && mVideoWindow != nullptr) {
env->DeleteGlobalRef(mVideoWindow);
mVideoWindow = nullptr;
}
_linphone_core_set_native_video_window_id(lc, (void *)mVideoWindow);
}
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) {
return new AndroidPlatformHelpers(lc, systemContext);
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setNativePreviewWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
AndroidPlatformHelpers *androidPlatformHelper = (AndroidPlatformHelpers *)ptr;
androidPlatformHelper->_setPreviewVideoWindow(id);
}
extern "C" JNIEXPORT void JNICALL Java_org_linphone_core_tools_AndroidPlatformHelper_setNativeVideoWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
AndroidPlatformHelpers *androidPlatformHelper = (AndroidPlatformHelpers *)ptr;
androidPlatformHelper->_setVideoWindow(id);
}
LINPHONE_END_NAMESPACE
......@@ -55,6 +55,8 @@ public:
void releaseCpuLock () override;
string getDataPath () override {return Utils::getEmptyConstRefObject<string>();}
string getConfigPath () override {return Utils::getEmptyConstRefObject<string>();}
void setVideoWindow (void *windowId) override {}
void setVideoPreviewWindow (void *windowId) override {}
private:
void bgTaskTimeout ();
......
......@@ -49,4 +49,12 @@ string StubbedPlatformHelpers::getConfigPath () {
return "";
}
void StubbedPlatformHelpers::setVideoPreviewWindow (void *windowId) {
}
void StubbedPlatformHelpers::setVideoWindow (void *windowId) {
}
LINPHONE_END_NAMESPACE
......@@ -38,6 +38,8 @@ class PlatformHelpers {
public:
virtual ~PlatformHelpers () = default;
LinphoneCore *getCore() { return mCore; }
// This method shall retrieve DNS server list from the platform and assign it to the core.
virtual void setDnsServers () = 0;
virtual void acquireWifiLock () = 0;
......@@ -48,6 +50,8 @@ public:
virtual void releaseCpuLock () = 0;
virtual std::string getDataPath () = 0;
virtual std::string getConfigPath () = 0;
virtual void setVideoWindow (void *windowId) = 0;
virtual void setVideoPreviewWindow (void *windowId) = 0;
protected:
inline explicit PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
......@@ -69,6 +73,8 @@ public:
void releaseCpuLock () override;
std::string getDataPath () override;
std::string getConfigPath () override;
void setVideoWindow (void *windowId) override;
void setVideoPreviewWindow (void *windowId) override;
};
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
......
......@@ -20,11 +20,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
package org.linphone.core.tools;
import org.linphone.core.Core;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.MediastreamerAndroidContext;
import org.linphone.mediastream.Version;
import android.content.res.Resources;
import android.graphics.SurfaceTexture;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.MulticastLock;
import android.net.wifi.WifiManager.WifiLock;
......@@ -36,6 +38,8 @@ import android.net.NetworkInfo;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Build;
import android.view.Surface;
import android.view.TextureView;
import java.net.InetAddress;
import java.util.List;
......@@ -50,6 +54,7 @@ import java.io.InputStream;
**/
public class AndroidPlatformHelper {
private long mNativePtr;
private Context mContext;
private WifiManager.WifiLock mWifiLock;
private WifiManager.MulticastLock mMcastLock;
......@@ -65,8 +70,13 @@ public class AndroidPlatformHelper {
private String mGrammarCpimFile;
private String mGrammarVcardFile ;
private String mUserCertificatePath;
private Surface mSurface;
public AndroidPlatformHelper(Object ctx_obj) {
private native void setNativePreviewWindowId(long nativePtr, Object view);
private native void setNativeVideoWindowId(long nativePtr, Object view);
public AndroidPlatformHelper(long nativePtr, Object ctx_obj) {
mNativePtr = nativePtr;
mContext = (Context) ctx_obj;
mResources = mContext.getResources();
MediastreamerAndroidContext.setContext(mContext);
......@@ -93,14 +103,13 @@ public class AndroidPlatformHelper {
mGrammarVcardFile = basePath + "/share/belr/grammars/vcard_grammar";
mUserCertificatePath = basePath;
try{
try {
copyAssetsFromPackage();
}catch (IOException e) {
} catch (IOException e) {
Log.e("AndroidPlatformHelper(): failed to install some resources.");
}
}
public Object getPowerManager() {
return mPowerManager;
}
......@@ -260,6 +269,84 @@ public class AndroidPlatformHelper {
lInputStream.close();
}
}
public void setVideoPreviewView(Object view) {
if (!(view instanceof TextureView)) {
throw new RuntimeException("Preview window id is not an instance of TextureView.
Please update your UI layer so that the preview video view is a TextureView (or an instance of it)
or enable compatibility mode by setting displaytype=MSAndroidOpenGLDisplay in the [video] section your linphonerc factory configuration file
so you can keep using your existing application code for managing video views.");
}
TextureView textureView = (TextureView)view;
textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.i("Preview window surface is available");
setNativePreviewWindowId(mNativePtr, surface);
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("Preview window surface is no longer available");
setNativePreviewWindowId(mNativePtr, null);
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
});
if (textureView.isAvailable()) {
Log.i("Preview window surface is available");
setNativePreviewWindowId(mNativePtr, textureView.getSurfaceTexture());
}
}
public void setVideoRenderingView(Object view) {
if (!(view instanceof TextureView)) {
throw new RuntimeException("Rendering window id is not an instance of TextureView.
Please update your UI layer so that the video rendering view is a TextureView (or an instance of it)
or enable compatibility mode by setting displaytype=MSAndroidOpenGLDisplay in the [video] section your linphonerc factory configuration file
so you can keep using your existing application code for managing video views.");
}
TextureView textureView = (TextureView)view;
textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.i("Rendering window surface is available");
mSurface = new Surface(surface);
setNativeVideoWindowId(mNativePtr, mSurface);
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.i("Rendering window surface is no longer available");
setNativeVideoWindowId(mNativePtr, null);
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
});
if (textureView.isAvailable()) {
Log.i("Rendering window surface is available");
mSurface = new Surface(textureView.getSurfaceTexture());
setNativeVideoWindowId(mNativePtr, mSurface);
}
}
};
......@@ -574,20 +574,8 @@ JNIEXPORT void JNICALL Java_org_linphone_core_CallImpl_setNativeVideoWindowId(JN
bctbx_error("LinphoneCall C ptr is null!");
return;
}
jobject oldWindow = (jobject) linphone_call_get_native_video_window_id(cptr);
if (oldWindow == id) {
bctbx_warning("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): new id (%p) is the same as the current one, skipping...", id);
return;
}
if (id != nullptr) {
id = env->NewGlobalRef(id);
bctbx_message("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): NewGlobalRef(%p)", id);
} else bctbx_message("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): setting to nullptr");
linphone_call_set_native_video_window_id(cptr, (void *)id);
if (oldWindow != nullptr) {
bctbx_message("Java_org_linphone_core_CallImpl_setNativeVideoWindowId(): DeleteGlobalRef(%p)", oldWindow);
env->DeleteGlobalRef(oldWindow);
}
LinphoneCore *lc = linphone_call_get_core(cptr);
linphone_core_set_native_video_window_id(lc, (void *)id);
}
JNIEXPORT void JNICALL Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
......@@ -596,20 +584,7 @@ JNIEXPORT void JNICALL Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(
bctbx_error("LinphoneCore C ptr is null!");
return;
}
jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id(cptr);
if (oldWindow == id) {
bctbx_warning("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): new id (%p) is the same as the current one, skipping...", id);
return;
}
if (id != nullptr) {
id = env->NewGlobalRef(id);
bctbx_message("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): NewGlobalRef(%p)", id);
} else bctbx_message("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): setting to nullptr");
linphone_core_set_native_preview_window_id(cptr, (void *)id);
if (oldWindow != nullptr) {
bctbx_message("Java_org_linphone_core_CoreImpl_setNativePreviewWindowId(): DeleteGlobalRef(%p)", oldWindow);
env->DeleteGlobalRef(oldWindow);
}
}
JNIEXPORT void JNICALL Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(JNIEnv *env, jobject thiz, jlong ptr, jobject id) {
......@@ -618,20 +593,7 @@ JNIEXPORT void JNICALL Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(JN
bctbx_error("LinphoneCore C ptr is null!");
return;
}
jobject oldWindow = (jobject) linphone_core_get_native_video_window_id(cptr);
if (oldWindow == id) {
bctbx_warning("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): new id (%p) is the same as the current one, skipping...", id);
return;
}
if (id != nullptr) {
id = env->NewGlobalRef(id);
bctbx_message("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): NewGlobalRef(%p)", id);
} else bctbx_message("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): setting to nullptr");
linphone_core_set_native_video_window_id(cptr, (void *)id);
if (oldWindow != nullptr) {
bctbx_message("Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(): DeleteGlobalRef(%p)", oldWindow);
env->DeleteGlobalRef(oldWindow);
}
}
JNIEXPORT jobject JNICALL Java_org_linphone_core_FactoryImpl_getCore(JNIEnv *env, jobject thiz, jlong ptr, jlong lcPtr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment