Skip to content

Commit 8543018

Browse files
authored
Merge pull request #516 from wysaid/min
new option: disable video module
2 parents 9c81c5d + fe07dcf commit 8543018

34 files changed

+233
-122
lines changed

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"cppStandard": "c++17",
2020
"defines": [
2121
"DEBUG=1",
22-
"_CGE_USE_FFMPEG_=1",
22+
"CGE_USE_FFMPEG=1",
2323
"ANDROID_NDK=1",
2424
"_CGE_DISABLE_GLOBALCONTEXT_=1",
2525
"_CGE_ONLY_FILTERS_=1"

.vscode/tasks.json

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"problemMatcher": "$gcc"
111111
},
112112
{
113-
"label": "[Release] Build Native Library With NDK Build",
113+
"label": "[Release] NDK Build Native Library With FFmpeg (Deprecated)",
114114
"type": "shell",
115115
"command": "bash",
116116
"args": [
@@ -122,6 +122,20 @@
122122
"group": "build",
123123
"problemMatcher": "$gcc"
124124
},
125+
{
126+
"label": "[Release] NDK Build Native Library Without FFmpeg (Deprecated)",
127+
"type": "shell",
128+
"command": "bash",
129+
"args": [
130+
"library/src/main/jni/buildJNI",
131+
"--disable-video-module",
132+
],
133+
"options": {
134+
"cwd": "${workspaceFolder}"
135+
},
136+
"group": "build",
137+
"problemMatcher": "$gcc"
138+
},
125139
{
126140
"label": "Enable Gradle CMake Build",
127141
"type": "shell",
@@ -136,6 +150,34 @@
136150
"group": "build",
137151
"problemMatcher": "$gcc"
138152
},
153+
{
154+
"label": "Enable Video Module",
155+
"type": "shell",
156+
"command": "bash",
157+
"args": [
158+
"vscode_tasks.sh",
159+
"--enable-video-module"
160+
],
161+
"options": {
162+
"cwd": "${workspaceFolder}"
163+
},
164+
"group": "build",
165+
"problemMatcher": "$gcc"
166+
},
167+
{
168+
"label": "Disable Video Module",
169+
"type": "shell",
170+
"command": "bash",
171+
"args": [
172+
"vscode_tasks.sh",
173+
"--disable-video-module"
174+
],
175+
"options": {
176+
"cwd": "${workspaceFolder}"
177+
},
178+
"group": "build",
179+
"problemMatcher": "$gcc"
180+
},
139181
{
140182
"label": "Setup Gradle Project",
141183
"type": "shell",

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
Image, Camera And Video Filters Based On OpenGL
44

5-
>To get pure lib without ffmpeg(No feature of video recording), please checkout the branch [min](https://github.com/wysaid/android-gpuimage-plus/tree/min). The whole jni module will be less than 600KB.
6-
75
## New Feature
86

97
See the `image deform demo`.
108

11-
![](screenshots/6.gif) ![](screenshots/5.gif)
9+
![screenshots](screenshots/6.gif) ![screenshots](screenshots/5.gif)
1210

1311
## Gradle dependency
1412

@@ -27,7 +25,9 @@ dependencies {
2725
}
2826
```
2927

30-
> Use other ffmpeg-library, see: <https://github.com/wysaid/FFmpeg-Android.git>
28+
> __The jcenter is out of date, please try the source for now. Latest prebuilt versions will be provided soon.__
29+
30+
> To compile other versions of ffmpeg, see: <https://github.com/wysaid/FFmpeg-Android.git>
3131
3232
## Abstract
3333

@@ -37,6 +37,11 @@ dependencies {
3737

3838
## Build
3939

40+
* Options to know in `local.properties`:
41+
* `usingCMakeCompile=true`: Compile the native library with CMake if set to true. (Default to false, so you can use the prebuilt libs)
42+
* `usingCMakeCompileDebug=true`: Compile the native library in Debug Mode if set to true. (Default to false)
43+
* `disableVideoModule=true`: Disable the video recording feature, The whole jni module will be very small. (Default to false)
44+
4045
* Build with `Android Studio` and CMake: (Recommended)
4146
* Put `usingCMakeCompile=true` in your `local.properties`
4247
* Open the repo with the latest version of `Android Studio`
@@ -125,7 +130,6 @@ protected void onCreate(Bundle savedInstanceState) {
125130
Bitmap dstImage = CGENativeLibrary.filterImage_MultipleEffects(src, ruleString, 1.0f);
126131

127132
//Then the dstImage is applied with the filter.
128-
//It's so convenient, isn't it?
129133

130134
//Save the result image to /sdcard/libCGE/rec_???.jpg.
131135
ImageUtil.saveBitmap(dstImage);

cgeDemo/src/main/java/org/wysaid/cgeDemo/CameraDemoActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import androidx.appcompat.app.AppCompatActivity;
2020

2121
import org.wysaid.camera.CameraInstance;
22+
import org.wysaid.library.BuildConfig;
2223
import org.wysaid.myUtils.FileUtil;
2324
import org.wysaid.myUtils.ImageUtil;
2425
import org.wysaid.myUtils.MsgUtil;
@@ -68,6 +69,12 @@ class RecordListener implements View.OnClickListener {
6869

6970
@Override
7071
public void onClick(View v) {
72+
73+
if (!BuildConfig.CGE_USE_VIDEO_MODULE) {
74+
MsgUtil.toastMsg(CameraDemoActivity.this, "gradle.ext.disableVideoModule is defined to true, video module disabled!!");
75+
return;
76+
}
77+
7178
Button btn = (Button) v;
7279

7380
if (!isValid) {

cgeDemo/src/main/java/org/wysaid/cgeDemo/ImageDeformActivity.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public void surfaceCreated() {
5858
public void run() {
5959
int w = mBitmap.getWidth(), h = mBitmap.getHeight();
6060
float scaling = Math.min(1280.0f / w, 1280.0f / h);
61-
if(scaling < 1.0f) {
61+
if (scaling < 1.0f) {
6262
w *= scaling;
6363
h *= scaling;
6464
}
6565
mDeformWrapper = CGEDeformFilterWrapper.create(w, h, 10.0f);
6666
mDeformWrapper.setUndoSteps(200); // set max undo steps to 200.
67-
if(mDeformWrapper != null) {
67+
if (mDeformWrapper != null) {
6868
CGEImageHandler handler = mImageView.getImageHandler();
6969
handler.setFilterWithAddres(mDeformWrapper.getNativeAddress());
7070
handler.processFilters();
@@ -84,11 +84,11 @@ public void run() {
8484
SeekBar.OnSeekBarChangeListener mSeekListener = new SeekBar.OnSeekBarChangeListener() {
8585
@Override
8686
public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) {
87-
if(mDeformWrapper != null) {
87+
if (mDeformWrapper != null) {
8888
mImageView.lazyFlush(true, new Runnable() {
8989
@Override
9090
public void run() {
91-
if(mDeformWrapper != null) {
91+
if (mDeformWrapper != null) {
9292
float intensity = progress / 100.0f;
9393
mDeformWrapper.restoreWithIntensity(intensity);
9494
}
@@ -108,7 +108,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
108108
}
109109
};
110110

111-
View.OnTouchListener mTouchListener = new View.OnTouchListener(){
111+
View.OnTouchListener mTouchListener = new View.OnTouchListener() {
112112

113113
float mLastX, mLastY;
114114
boolean mIsMoving = false;
@@ -117,7 +117,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
117117
@Override
118118
public boolean onTouch(View v, final MotionEvent event) {
119119

120-
if(mDeformWrapper == null) {
120+
if (mDeformWrapper == null) {
121121
return false;
122122
}
123123

@@ -132,7 +132,7 @@ public boolean onTouch(View v, final MotionEvent event) {
132132
mIsMoving = true;
133133
mLastX = x;
134134
mLastY = y;
135-
if(!mDeformWrapper.canUndo()) {
135+
if (!mDeformWrapper.canUndo()) {
136136
mDeformWrapper.pushDeformStep();
137137
}
138138
return true;
@@ -141,11 +141,11 @@ public boolean onTouch(View v, final MotionEvent event) {
141141
case MotionEvent.ACTION_CANCEL:
142142
case MotionEvent.ACTION_UP:
143143
mIsMoving = false;
144-
if(mHasMotion) {
144+
if (mHasMotion) {
145145
mImageView.queueEvent(new Runnable() {
146146
@Override
147147
public void run() {
148-
if(mImageView != null) {
148+
if (mImageView != null) {
149149
mDeformWrapper.pushDeformStep();
150150
Log.i(Common.LOG_TAG, "Init undo status...");
151151
}
@@ -156,7 +156,7 @@ public void run() {
156156
return true;
157157
}
158158

159-
if(mSeekbar.getProgress() != 0) {
159+
if (mSeekbar.getProgress() != 0) {
160160
mSeekbar.setOnSeekBarChangeListener(null);
161161
mSeekbar.setProgress(0);
162162
mSeekbar.setOnSeekBarChangeListener(mSeekListener);
@@ -168,8 +168,8 @@ public void run() {
168168
mImageView.lazyFlush(true, new Runnable() {
169169
@Override
170170
public void run() {
171-
if(mDeformWrapper == null)
172-
return ;
171+
if (mDeformWrapper == null)
172+
return;
173173
switch (mDeformMode) {
174174
case Restore:
175175
mDeformWrapper.restoreWithPoint(x, y, w, h, mTouchRadius, mTouchIntensaity);
@@ -199,7 +199,7 @@ public void run() {
199199
protected void onPause() {
200200
super.onPause();
201201

202-
if(mDeformWrapper != null) {
202+
if (mDeformWrapper != null) {
203203
mDeformWrapper.release(false);
204204
mDeformWrapper = null;
205205
}
@@ -266,7 +266,7 @@ public void restoreBtnClicked(View view) {
266266
mImageView.flush(true, new Runnable() {
267267
@Override
268268
public void run() {
269-
if(mDeformWrapper != null) {
269+
if (mDeformWrapper != null) {
270270
mDeformWrapper.restore();
271271
mImageView.requestRender();
272272
}
@@ -295,9 +295,9 @@ public void wrinkleModeBtnClicked(View view) {
295295
}
296296

297297
void checkRadius() {
298-
if(mTouchRadius < 10.0f) {
298+
if (mTouchRadius < 10.0f) {
299299
mTouchRadius = 10.0f;
300-
} else if(mTouchRadius > 400.0f) {
300+
} else if (mTouchRadius > 400.0f) {
301301
mTouchRadius = 400.0f;
302302
}
303303
}
@@ -316,9 +316,9 @@ public void radiusDecClicked(View view) {
316316
}
317317

318318
void checkIntensity() {
319-
if(mTouchIntensaity < 0.02f) {
319+
if (mTouchIntensaity < 0.02f) {
320320
mTouchIntensaity = 0.02f;
321-
} else if(mTouchIntensaity > 0.9f) {
321+
} else if (mTouchIntensaity > 0.9f) {
322322
mTouchIntensaity = 0.9f;
323323
}
324324
}
@@ -339,8 +339,8 @@ public void undoBtnClicked(View view) {
339339
mImageView.flush(true, new Runnable() {
340340
@Override
341341
public void run() {
342-
if(mDeformWrapper != null) {
343-
if(!mDeformWrapper.undo()) {
342+
if (mDeformWrapper != null) {
343+
if (!mDeformWrapper.undo()) {
344344
mImageView.post(new Runnable() {
345345
@Override
346346
public void run() {
@@ -381,7 +381,7 @@ public void showMeshBtnClicked(View view) {
381381
mImageView.flush(true, new Runnable() {
382382
@Override
383383
public void run() {
384-
if(mDeformWrapper != null) {
384+
if (mDeformWrapper != null) {
385385
mShowMesh = !mShowMesh;
386386
mDeformWrapper.showMesh(mShowMesh);
387387
mImageView.requestRender();

library/build.gradle

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def usingCMakeCompileDebug() {
1010
return gradle.ext != null && gradle.ext.has("usingCMakeCompileDebug") && gradle.ext.usingCMakeCompileDebug;
1111
}
1212

13+
def disableVideoModule() {
14+
return gradle.ext != null && gradle.ext.has("disableVideoModule") && gradle.ext.disableVideoModule;
15+
}
16+
1317
android {
1418
compileSdkVersion rootProject.ext.android.compileSdkVersion
1519
buildToolsVersion rootProject.ext.android.buildToolsVersion
@@ -22,12 +26,15 @@ android {
2226
minSdkVersion rootProject.ext.android.minSdkVersion
2327
targetSdkVersion rootProject.ext.android.targetSdkVersion
2428

29+
buildConfigField("boolean", "CGE_USE_VIDEO_MODULE", disableVideoModule() ? "false" : "true")
30+
2531
if (usingCMakeCompile()) {
2632
externalNativeBuild {
2733
cmake {
2834

2935
def cmakeBuildType = "";
3036
def cppExtraFlags = "";
37+
def cgeVideoModuleDef = "";
3138

3239
if (usingCMakeCompileDebug()) {
3340
cmakeBuildType = "-DCMAKE_BUILD_TYPE=Debug"
@@ -37,11 +44,17 @@ android {
3744
cppExtraFlags = "-Os -DNDEBUG=1 -D_NDEBUG=1"
3845
}
3946

40-
arguments "-DCGE_USE_VIDEO_MODULE=ON",
41-
"-DANDROID_STL=c++_static",
47+
if (disableVideoModule()) {
48+
cgeVideoModuleDef = "-DCGE_USE_VIDEO_MODULE=OFF"
49+
} else {
50+
cgeVideoModuleDef = "-DCGE_USE_VIDEO_MODULE=ON"
51+
}
52+
53+
arguments "-DANDROID_STL=c++_static",
4254
"-DANDROID_ARM_NEON=TRUE",
4355
"-DANDROID_GRADLE=ON",
44-
cmakeBuildType
56+
cmakeBuildType,
57+
cgeVideoModuleDef
4558

4659
cFlags "-ffast-math -fPIE -fPIC -DNO_LOCALE_SUPPORT=1 -DANDROID_NDK=1 -D__STDC_CONSTANT_MACROS=1 ${cppExtraFlags}"
4760
cppFlags "-ffast-math -fPIE -fPIC -DNO_LOCALE_SUPPORT=1 -DANDROID_NDK=1 -D__STDC_CONSTANT_MACROS=1 -frtti -std=c++14 -fno-exceptions -fvisibility-inlines-hidden ${cppExtraFlags}"

library/src/main/java/org/wysaid/nativePort/NativeLibraryLoader.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package org.wysaid.nativePort;
22

3+
import org.wysaid.library.BuildConfig;
4+
35
/**
46
* Created by wangyang on 15/7/30.
57
*/
68
public class NativeLibraryLoader {
79

810
public static void load() {
9-
System.loadLibrary("ffmpeg");
11+
12+
if (BuildConfig.CGE_USE_VIDEO_MODULE) {
13+
System.loadLibrary("ffmpeg");
14+
}
1015
System.loadLibrary("CGE");
1116
System.loadLibrary("CGEExt");
12-
CGEFFmpegNativeLibrary.avRegisterAll();
17+
if (BuildConfig.CGE_USE_VIDEO_MODULE) {
18+
CGEFFmpegNativeLibrary.avRegisterAll();
19+
}
1320
onLoad();
1421
}
1522

library/src/main/jni/Android.mk

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ LOCAL_LDLIBS := -llog -lEGL -lGLESv2 -ljnigraphics
113113

114114
ifdef CGE_USE_VIDEO_MODULE
115115

116-
VIDEO_MODULE_DEFINE = -D_CGE_USE_FFMPEG_
116+
VIDEO_MODULE_DEFINE = -DCGE_USE_FFMPEG
117117

118118
endif
119119

@@ -124,10 +124,6 @@ BUILD_MODE += -DDEBUG
124124
endif
125125
endif
126126

127-
ifdef CGE_USE_LEAK_TEST
128-
BUILD_MODE += -D_CGE_GENERAL_ERROR_TEST_
129-
endif
130-
131127
LOCAL_CFLAGS := ${VIDEO_MODULE_DEFINE} ${BUILD_MODE} -DANDROID_NDK -DCGE_LOG_TAG=\"libCGE\" -DCGE_TEXTURE_PREMULTIPLIED=1 -D__STDC_CONSTANT_MACROS -D_CGE_DISABLE_GLOBALCONTEXT_ -O3 -ffast-math -D_CGE_ONLY_FILTERS_
132128

133129
ifdef CGE_USE_FACE_MODULE

0 commit comments

Comments
 (0)