Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

升级 v8.0.2 #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
yoreland merged 2 commits into AgoraIO:master from benyq:master
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import android.os.Looper;
import android.util.Log;

import com.faceunity.FUConfig;
import com.faceunity.core.faceunity.FUAIKit;
import com.faceunity.core.faceunity.FURenderKit;
import com.faceunity.core.model.facebeauty.FaceBeautyBlurTypeEnum;
import com.faceunity.nama.FURenderer;
import com.faceunity.nama.utils.FuDeviceUtils;

import io.agora.capture.framework.modules.channels.VideoChannel;
import io.agora.capture.framework.modules.processors.IPreprocessor;
Expand All @@ -16,14 +21,12 @@ public class PreprocessorFaceUnity implements IPreprocessor {
private final static String TAG = PreprocessorFaceUnity.class.getSimpleName();

private FURenderer mFURenderer = FURenderer.getInstance();
private Context mContext;
private boolean renderSwitch;
private int skipFrame = 0;

private Handler mGLHandler;

public PreprocessorFaceUnity(Context context) {
mContext = context;
}

@Override
Expand All @@ -40,6 +43,10 @@ public VideoCaptureFrame onPreProcessFrame(VideoCaptureFrame outFrame, VideoChan
return outFrame;
}
mFURenderer.setInputOrientation(outFrame.rotation);

if (FUConfig.DEVICE_LEVEL > FuDeviceUtils.DEVICE_LEVEL_MID)//高性能设备
cheekFaceNum();

int texId = mFURenderer.onDrawFrameDualInput(outFrame.image,
outFrame.textureId, outFrame.format.getWidth(),
outFrame.format.getHeight());
Expand Down Expand Up @@ -77,6 +84,7 @@ public void releasePreprocessor(VideoChannel.ChannelContext context) {
private void startGLThread() {
if (mGLHandler == null) {
mGLHandler = new Handler(Looper.myLooper());
mGLHandler.post(() -> {if (mSurfaceViewListener !=null ) mSurfaceViewListener.onSurfaceCreated();});
}
}

Expand All @@ -98,9 +106,40 @@ public void skipFrame() {
public void releaseFURender() {
renderSwitch = false;
mGLHandler.removeCallbacksAndMessages(0);
mGLHandler.post(() -> FURenderer.getInstance().release());
mGLHandler.post(() -> {
if (mSurfaceViewListener !=null ) mSurfaceViewListener.onSurfaceDestroyed();
});
mGLHandler = null;
}

private SurfaceViewListener mSurfaceViewListener;

public interface SurfaceViewListener{
void onSurfaceCreated();
void onSurfaceDestroyed();
}

public void setSurfaceListener(SurfaceViewListener surfaceViewListener) {
this.mSurfaceViewListener = surfaceViewListener;
}

/**
* 检查当前人脸数量
*/
private void cheekFaceNum() {
//根据有无人脸 + 设备性能 判断开启的磨皮类型
float faceProcessorGetConfidenceScore = FUAIKit.getInstance().getFaceProcessorGetConfidenceScore(0);
if (faceProcessorGetConfidenceScore >= 0.95) {
//高端手机并且检测到人脸开启均匀磨皮,人脸点位质
if (FURenderKit.getInstance() != null && FURenderKit.getInstance().getFaceBeauty() != null && FURenderKit.getInstance().getFaceBeauty().getBlurType() != FaceBeautyBlurTypeEnum.EquallySkin) {
FURenderKit.getInstance().getFaceBeauty().setBlurType(FaceBeautyBlurTypeEnum.EquallySkin);
FURenderKit.getInstance().getFaceBeauty().setEnableBlurUseMask(true);
}
} else {
if (FURenderKit.getInstance() != null && FURenderKit.getInstance().getFaceBeauty() != null && FURenderKit.getInstance().getFaceBeauty().getBlurType() != FaceBeautyBlurTypeEnum.FineSkin) {
FURenderKit.getInstance().getFaceBeauty().setBlurType(FaceBeautyBlurTypeEnum.FineSkin);
FURenderKit.getInstance().getFaceBeauty().setEnableBlurUseMask(false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public void removeRtcHandler(RtcEngineEventHandler handler) {
mRtcEventHandler.removeEventHandler(handler);
}

public RtcEngineEventHandlerProxy getRtcEventHandler() {
return mRtcEventHandler;
}

public CameraVideoManager videoManager() {
return mVideoManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.agora.rtc.IRtcEngineEventHandler;

public class RtcEngineEventHandlerProxy extends IRtcEngineEventHandler {
private static final String TAG = "RtcEngineEventHandlerPr";
private ArrayList<RtcEngineEventHandler> mEventHandlers = new ArrayList<>();

public void addEventHandler(RtcEngineEventHandler handler) {
Expand Down Expand Up @@ -42,4 +43,59 @@ public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapse
handler.onRemoteVideoStateChanged(uid, state, reason, elapsed);
}
}

private int mCallbackCount;
private int mWidth;
private int mHeight;
private int mSumRenderFps;
private int mSumDecoderFps;
private int mSumReceivedBitrate;

public static class StatsInfo {
public int width;
public int height;
public int renderFps;
public int decoderFps;

public int receivedBitrate;
}

public StatsInfo retrieveStatsInfo() {
StatsInfo statsInfo = new StatsInfo();
synchronized (this) {
statsInfo.width = mWidth;
statsInfo.height = mHeight;
int count = mCallbackCount;
if (count > 0) {
statsInfo.renderFps = mSumRenderFps / count;
statsInfo.decoderFps = mSumDecoderFps / count;
statsInfo.receivedBitrate = mSumReceivedBitrate / count;
}
mCallbackCount = 0;
mSumRenderFps = 0;
mSumDecoderFps = 0;
mSumReceivedBitrate = 0;
}
return statsInfo;
}

@Override
public void onRemoteVideoStats(RemoteVideoStats remoteVideoStats) {
super.onRemoteVideoStats(remoteVideoStats);
// Log.d(TAG, String.format("onRemoteVideoStats. width %d, height %d, " +
// "delay %d, receivedBitrate %d, decoderOutputFrameRate %d, rendererOutputFrameRate %d, " +
// "packetLossRate %d, totalFrozenTime %d, totalActiveTime %d, rxStreamType %d",
// remoteVideoStats.width, remoteVideoStats.height, remoteVideoStats.delay, remoteVideoStats.receivedBitrate,
// remoteVideoStats.decoderOutputFrameRate, remoteVideoStats.rendererOutputFrameRate,
// remoteVideoStats.packetLossRate, remoteVideoStats.totalFrozenTime, remoteVideoStats.totalActiveTime,
// remoteVideoStats.rxStreamType));
synchronized (this) {
mWidth = remoteVideoStats.width;
mHeight = remoteVideoStats.height;
mSumRenderFps += remoteVideoStats.rendererOutputFrameRate;
mSumDecoderFps += remoteVideoStats.decoderOutputFrameRate;
mSumReceivedBitrate += remoteVideoStats.receivedBitrate;
++mCallbackCount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.faceunity.core.enumeration.FUAIProcessorEnum;
import com.faceunity.nama.FURenderer;
import com.faceunity.nama.data.FaceUnityDataFactory;
import com.faceunity.nama.dialog.ToastHelper;
import com.faceunity.nama.listener.FURendererListener;
import com.faceunity.nama.ui.FaceUnityView;

import java.util.concurrent.CountDownLatch;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import io.agora.capture.video.camera.CameraVideoManager;
import io.agora.capture.video.camera.Constant;
Expand All @@ -32,6 +35,7 @@
import io.agora.rtc.RtcEngine;
import io.agora.rtc.video.VideoCanvas;
import io.agora.rtc.video.VideoEncoderConfiguration;
import io.agora.rtcwithfu.MyApplication;
import io.agora.rtcwithfu.R;
import io.agora.rtcwithfu.RtcEngineEventHandler;
import io.agora.rtcwithfu.utils.Constants;
Expand Down Expand Up @@ -64,6 +68,7 @@ public class FUChatActivity extends RtcBasedActivity implements RtcEngineEventHa
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_base);
initUI();
initRoom();
Expand Down Expand Up @@ -131,6 +136,17 @@ public void onCameraClosed() {
TextureView localVideo = findViewById(R.id.local_video_view);
mVideoManager.setLocalPreview(localVideo);

preprocessor.setSurfaceListener(new PreprocessorFaceUnity.SurfaceViewListener() {
@Override
public void onSurfaceCreated() {
mFaceUnityDataFactory.bindCurrentRenderer();
}

@Override
public void onSurfaceDestroyed() {
mFURenderer.release();
}
});
}

private void joinChannel() {
Expand Down Expand Up @@ -186,7 +202,6 @@ protected void onResume() {
super.onResume();
Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
mFaceUnityDataFactory.bindCurrentRenderer();
preprocessor.setRenderEnable(true);
mVideoManager.startCapture();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import android.widget.EditText;
import android.widget.Toast;

import io.agora.rtcwithfu.utils.Constants;
import com.faceunity.FUConfig;
import com.faceunity.nama.utils.FuDeviceUtils;

import io.agora.rtcwithfu.R;
import io.agora.rtcwithfu.utils.Constants;

public class MainActivity extends Activity {
private static final int REQUEST_CODE_ALL_PERMISSIONS = 999;
Expand All @@ -25,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_navigation);
mChannelName = findViewById(R.id.edt_channel);
checkPermissions();
FUConfig.DEVICE_LEVEL = FuDeviceUtils.judgeDeviceLevel(this);
}

private void checkPermissions() {
Expand Down Expand Up @@ -68,6 +72,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

public void onStartBroadcastClick(View view) {
if (!isFastClick()) {return;}
String name = mChannelName.getText().toString();
if (name.isEmpty()) {
Toast.makeText(this, R.string.empty_room_name_toast, Toast.LENGTH_SHORT).show();
Expand All @@ -77,4 +82,18 @@ public void onStartBroadcastClick(View view) {
startActivity(intent);
}
}

// 两次点击按钮之间的点击间隔不能少于1000毫秒
private static final int MIN_CLICK_DELAY_TIME = 1000;
private static long lastClickTime;

public static boolean isFastClick() {
boolean flag = false;
long curClickTime = System.currentTimeMillis();
if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
flag = true;
}
lastClickTime = curClickTime;
return flag;
}
}
9 changes: 4 additions & 5 deletions Agora-Video-With-FaceUnity-Android/faceunity/build.gradle
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 741
versionName "7.4.1.0"
// 7.3.0_phy_505b959b_bf80f59
versionCode 802
versionName "8.0.2"
}
buildTypes {
release {
Expand All @@ -28,7 +27,7 @@ dependencies {
resolutionStrategy.cacheDynamicVersionsFor 0,'seconds'
}
implementation 'com.android.support:appcompat-v7:28.0.0'
api 'com.faceunity:core:7.4.1.0'
implementation 'com.faceunity:model:7.4.1.0'
api 'com.faceunity:core:8.0.2'
implementation 'com.faceunity:model:8.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.faceunity;

import com.faceunity.nama.utils.FuDeviceUtils;

public class FUConfig {
//设备等级默认为中级
public static int DEVICE_LEVEL = FuDeviceUtils.DEVICE_LEVEL_MID;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public static FURenderer getInstance() {
/*检测标识*/
private int aIProcessTrackStatus = -1;

/**
*
* @return version
*/
public String getVersion() {
return mFURenderKit.getVersion();
}

/**
* 初始化鉴权
*
Expand Down Expand Up @@ -122,8 +130,8 @@ public int onDrawFrameDualInput(byte[] img, int texId, int width, int height) {
prepareDrawFrame();
FURenderInputData inputData = new FURenderInputData(width, height);
/*注释掉Buffer配置,启用单纹理模式,防止Buffer跟纹理存在不对齐造成,美妆偏移*/
//inputData.setImageBuffer(new FURenderInputData.FUImageBuffer(inputBufferType, img));//设置为单Buffer输入
inputData.setTexture(new FURenderInputData.FUTexture(inputTextureType, texId));
// inputData.setImageBuffer(new FURenderInputData.FUImageBuffer(inputBufferType, img));//设置为单Buffer输入
inputData.setTexture(new FURenderInputData.FUTexture(inputTextureType, texId));
FURenderInputData.FURenderConfig config = inputData.getRenderConfig();
config.setExternalInputType(externalInputType);
config.setInputOrientation(inputOrientation);
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /