Skip to content

Commit

Permalink
feat(android): add global setting
Browse files Browse the repository at this point in the history
  • Loading branch information
I-m-SuperMan committed Apr 9, 2020
1 parent 67c1aba commit 50a8a55
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 2 deletions.
1 change: 1 addition & 0 deletions platform/Android/source/premierlibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_library(CicadaPlayer SHARED
src/main/jni/player/NativeBase.cpp
src/main/jni/player/JavaTrackInfo.cpp
src/main/jni/player/JavaMediaInfo.cpp
src/main/jni/player/JavaGlobalSettings.cpp
src/main/jni/utils/JavaLogger.cpp

)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.cicada.player;


public class CicadaPlayerGlobalSettings {

static {
System.loadLibrary("alivcffmpeg");
System.loadLibrary("CicadaPlayer");
}

/**
* 设置域名对应的解析ip
* @param host 域名,需指定端口(http默认端口80,https默认端口443)。例如player.alicdn.com:80
* @param ip 相应的ip,设置为空字符串清空设定。
*/
/****
* Set a DNS ip to resolve the host.
* @param host The host. Need to specify the port(http defualt port is 80,https default port is 443). E.g player.alicdn.com:80
* @param ip The ip address, set as empty string to clear the setting.
*/
public static void setDNSResolve(String host, String ip){
nSetDNSResolve(host, ip);
}

private static native void nSetDNSResolve(String host, String ip);

}
13 changes: 11 additions & 2 deletions platform/Android/source/premierlibrary/src/main/jni/JniLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "player/JavaCacheConfig.h"
#include "player/JavaMediaInfo.h"
#include "player/JavaTrackInfo.h"
#include "player/JavaGlobalSettings.h"
#include "player/NativeBase.h"

using namespace Cicada;
Expand All @@ -25,16 +26,23 @@ int initJavaInfo(JNIEnv *env)
JavaPlayerConfig::init(env);
AndroidVSync::init(env);
DecoderSurface::init(env);
JavaGlobalSettings::init(env);
int result = NativeBase::registerMethod(env);

if (result == JNI_FALSE) {
return false;
return JNI_FALSE;
}

result = JavaLogger::registerMethod(env);

if (result == JNI_FALSE) {
return false;
return JNI_FALSE;
}

result = JavaGlobalSettings::registerMethod(env);

if (result == JNI_FALSE) {
return JNI_FALSE;
}

return JNI_TRUE;
Expand All @@ -50,6 +58,7 @@ void unInitJavaInfo(JNIEnv *env)
AndroidVSync::unInit(env);
DecoderSurface::unInit(env);
JavaLogger::unInit(env);
JavaGlobalSettings::unInit(env);
}

extern "C"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Created by lifujun on 2020/4/9.
//

#include <utils/Android/FindClass.h>
#include <utils/globalSettings.h>
#include <utils/Android/GetStringUTFChars.h>
#include "JavaGlobalSettings.h"

static char *globalSettingsPath = (char *) ("com/cicada/player/CicadaPlayerGlobalSettings");
static jclass gj_GlobalSettings_Class = nullptr;

void JavaGlobalSettings::init(JNIEnv *pEnv)
{
if (gj_GlobalSettings_Class == nullptr) {
FindClass cls(pEnv, globalSettingsPath);
gj_GlobalSettings_Class = (jclass) pEnv->NewGlobalRef(cls.getClass());
}
}

void JavaGlobalSettings::unInit(JNIEnv *pEnv)
{
if (gj_GlobalSettings_Class != nullptr) {
pEnv->DeleteGlobalRef(gj_GlobalSettings_Class);
gj_GlobalSettings_Class = nullptr;
}
}

void JavaGlobalSettings::java_setDNSResolve(JNIEnv *mEnv, jclass clazz, jstring jhost, jstring jip)
{
GetStringUTFChars hostStr(mEnv, jhost);
char *hostChars = hostStr.getChars();

if (hostChars == nullptr || strlen(hostChars) == 0) {
return;
}

Cicada::globalSettings::getSetting()->removeResolve(hostChars, "");
GetStringUTFChars ipStr(mEnv, jip);
char *ipChars = ipStr.getChars();

if (ipChars != nullptr && strlen(ipChars) > 0) {
Cicada::globalSettings::getSetting()->addResolve(hostChars, ipChars);
}
}


static JNINativeMethod globalSettings_method_table[] = {
{"nSetDNSResolve", "(Ljava/lang/String;Ljava/lang/String;)V", (void *) JavaGlobalSettings::java_setDNSResolve},
};

int JavaGlobalSettings::registerMethod(JNIEnv *pEnv)
{
if (gj_GlobalSettings_Class == nullptr) {
return JNI_FALSE;
}

if (pEnv->RegisterNatives(gj_GlobalSettings_Class, globalSettings_method_table,
sizeof(globalSettings_method_table) / sizeof(JNINativeMethod)) < 0) {
return JNI_FALSE;
}

return JNI_TRUE;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by lifujun on 2020/4/9.
//

#ifndef SOURCE_JAVAGLOBALSETTINGS_H
#define SOURCE_JAVAGLOBALSETTINGS_H


#include <jni.h>

class JavaGlobalSettings {

public:
static void init(JNIEnv *pEnv);

static void unInit(JNIEnv *pEnv);

static int registerMethod(JNIEnv *pEnv);

static void java_setDNSResolve(JNIEnv *mEnv, jclass clazz, jstring host, jstring ip);
};


#endif //SOURCE_JAVAGLOBALSETTINGS_H

0 comments on commit 50a8a55

Please sign in to comment.