-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from AgoraIO-Community/dev_108
feat: beauty api 1.0.8
- Loading branch information
Showing
20 changed files
with
762 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
Android/app/src/main/java/io/agora/beautyapi/demo/module/faceunity/utils/FuDeviceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package io.agora.beautyapi.demo.module.faceunity.utils; | ||
|
||
import static android.content.Context.MODE_PRIVATE; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.os.Build; | ||
import android.util.Log; | ||
|
||
import com.faceunity.core.utils.FULogger; | ||
|
||
import java.io.File; | ||
|
||
import io.agora.beautyapi.demo.module.faceunity.utils.device.DeviceScoreUtils; | ||
|
||
public class FuDeviceUtils { | ||
|
||
public static final String TAG = "FuDeviceUtils"; | ||
|
||
public static final String DEVICE_LEVEL = "device_level"; | ||
|
||
public static final int DEVICE_LEVEL_FOUR = 4; | ||
public static final int DEVICE_LEVEL_THREE = 3; | ||
|
||
public static final int DEVICE_LEVEL_TWO = 2; | ||
public static final int DEVICE_LEVEL_ONE = 1; | ||
public static final int DEVICE_LEVEL_MINUS_ONE = -1; | ||
public static final int DEVICE_LEVEL_EMPTY = -100; | ||
|
||
public static final double DEVICE_SCORE_FOUR = 85.0; | ||
public static final double DEVICE_SCORE_THREE = 78.0; | ||
public static final double DEVICE_SCORE_TWO = 69.0; | ||
public static final double DEVICE_SCORE_ONE = 64.0; | ||
|
||
public static final String[] levelFourDevices = {}; | ||
public static final String[] levelThreeDevices = {}; | ||
public static final String[] levelTwoDevices = {}; | ||
public static final String[] levelOneDevices = {"PRO 7 Plus"}; | ||
public static final String Nexus_6P = "Nexus 6P"; | ||
|
||
|
||
public static int judgeDeviceLevel(Context context) { | ||
return judgeDeviceLevel(context,false); | ||
} | ||
|
||
/** | ||
* 判断设备级别 | ||
* | ||
* @return int | ||
*/ | ||
public static int judgeDeviceLevel(Context context,boolean ignoreCache) { | ||
if (!ignoreCache) { | ||
int cacheDeviceLevel = getCacheDeviceLevel(context); | ||
if (cacheDeviceLevel > DEVICE_LEVEL_EMPTY) { | ||
return cacheDeviceLevel; | ||
} | ||
} | ||
//有一些设备不符合下述的判断规则,则走一个机型判断模式 | ||
int specialDevice = judgeDeviceLevelInDeviceName(); | ||
if (specialDevice > DEVICE_LEVEL_EMPTY) { | ||
return specialDevice; | ||
} | ||
double score = DeviceScoreUtils.getDeviceScore(); | ||
int level = DEVICE_LEVEL_MINUS_ONE; | ||
if (score > DEVICE_SCORE_ONE) { | ||
level = DEVICE_LEVEL_ONE; | ||
} | ||
if (score > DEVICE_SCORE_TWO) { | ||
level = DEVICE_LEVEL_TWO; | ||
} | ||
if (score > DEVICE_SCORE_THREE) { | ||
level = DEVICE_LEVEL_THREE; | ||
} | ||
if (score > DEVICE_SCORE_FOUR) { | ||
level = DEVICE_LEVEL_FOUR; | ||
} | ||
saveCacheDeviceLevel(context,level); | ||
Log.d(TAG, "CPUName: " + DeviceScoreUtils.CPUName + " GPUName: " + DeviceScoreUtils.GPUName + " score: " + score + " level: " + level); | ||
return level; | ||
} | ||
|
||
/** | ||
* -1 不是特定的高低端机型 | ||
* | ||
* @return | ||
*/ | ||
private static int judgeDeviceLevelInDeviceName() { | ||
String currentDeviceName = getDeviceName(); | ||
for (String deviceName : levelFourDevices) { | ||
if (deviceName.equals(currentDeviceName)) { | ||
return DEVICE_LEVEL_FOUR; | ||
} | ||
} | ||
for (String deviceName : levelThreeDevices) { | ||
if (deviceName.equals(currentDeviceName)) { | ||
return DEVICE_LEVEL_THREE; | ||
} | ||
} | ||
for (String deviceName : levelTwoDevices) { | ||
if (deviceName.equals(currentDeviceName)) { | ||
return DEVICE_LEVEL_TWO; | ||
} | ||
} | ||
for (String deviceName : levelOneDevices) { | ||
if (deviceName.equals(currentDeviceName)) { | ||
return DEVICE_LEVEL_ONE; | ||
} | ||
} | ||
return DEVICE_LEVEL_EMPTY; | ||
} | ||
|
||
/** | ||
* 获取设备名 | ||
* | ||
* @return String | ||
*/ | ||
public static String getDeviceName() { | ||
String deviceName = ""; | ||
if (Build.MODEL != null) { | ||
deviceName = Build.MODEL; | ||
} | ||
Log.d(TAG, "deviceName: " + deviceName); | ||
return deviceName; | ||
} | ||
|
||
/** | ||
* 缓存设备等级 | ||
* | ||
* @param level int | ||
*/ | ||
public static void saveCacheDeviceLevel(Context context,int level) { | ||
SharedPreferences sp = context.getSharedPreferences(DEVICE_LEVEL, MODE_PRIVATE); | ||
sp.edit().putInt(DEVICE_LEVEL, level).apply(); | ||
} | ||
|
||
/** | ||
* 获取设备等级 | ||
* | ||
* @return int | ||
*/ | ||
public static int getCacheDeviceLevel(Context context) { | ||
SharedPreferences sp = context.getSharedPreferences(DEVICE_LEVEL, MODE_PRIVATE); | ||
return sp.getInt(DEVICE_LEVEL, DEVICE_LEVEL_EMPTY); | ||
} | ||
|
||
public static class Config{ | ||
/************************** 算法Model ******************************/ | ||
// 人脸识别 | ||
public static String BUNDLE_AI_FACE = "model" + File.separator + "ai_face_processor.bundle"; | ||
// 手势 | ||
public static String BUNDLE_AI_HAND = "model" + File.separator + "ai_hand_processor.bundle"; | ||
// 人体 | ||
public static String BUNDLE_AI_HUMAN = "model" + File.separator + "ai_human_processor.bundle"; | ||
|
||
// 舌头 | ||
public static String BUNDLE_AI_TONGUE = "graphics" + File.separator + "tongue.bundle"; | ||
|
||
//设备等级默认为中级 | ||
public static int DEVICE_LEVEL = FuDeviceUtils.DEVICE_LEVEL_TWO; | ||
|
||
//设备名称 | ||
public static String DEVICE_NAME = ""; | ||
|
||
|
||
//人脸离开之后是否延迟10帧移除人脸相关信息 | ||
public static final boolean FACE_DELAY_LEAVE_ENABLE = false; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...main/java/io/agora/beautyapi/demo/module/faceunity/utils/device/DefaultScoreProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.agora.beautyapi.demo.module.faceunity.utils.device; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
/** | ||
* DESC: | ||
* Created on 2021/3/12 | ||
*/ | ||
public class DefaultScoreProvider implements DeviceScoreProvider { | ||
|
||
public static final String[] badOtherGPUDevices = {"PowerVR Rogue GE"}; | ||
@Override | ||
public double getCpuScore(String cpuName) { | ||
int cpuCores = Runtime.getRuntime().availableProcessors(); | ||
ArrayList<Long> list = DeviceCpuUtils.getCPUFrequencies(); | ||
Collections.sort(list); | ||
Collections.reverse(list); | ||
DeviceScoreUtils.CPUFrequencies.clear(); | ||
for (int i = 0; i < list.size(); i++) { | ||
DeviceScoreUtils.CPUFrequencies.add(list.get(i) / 1000 / 1000f + "GHz"); | ||
} | ||
if (cpuCores <= 4) { | ||
return 65; | ||
} | ||
if (list == null || list.isEmpty()) { | ||
return 65; | ||
} | ||
double maxFre = list.get(0) / 1000 / 1000f; | ||
if (maxFre < 2.2) { | ||
return 65; | ||
} | ||
if (maxFre <= 2.4) { | ||
return 70 - MathUtils.getScore(maxFre, 2.4, 5, 0.2); | ||
} | ||
if (maxFre <= 2.8) { | ||
return 75 - MathUtils.getScore(maxFre, 2.8, 5, 0.4); | ||
} | ||
if (maxFre < 3.2) { | ||
return 85 - MathUtils.getScore(maxFre, 3.2, 10, 0.4); | ||
} | ||
return 90 + (maxFre - 3.2) / 0.2; | ||
} | ||
|
||
@Override | ||
public double getGpuScore(String glRenderer) { | ||
// 处理个别低端设备 | ||
for (String badDevice : badOtherGPUDevices){ | ||
if (glRenderer.startsWith(badDevice)){ | ||
return 55; | ||
} | ||
} | ||
return 65; | ||
} | ||
} |
Oops, something went wrong.