Skip to content

Commit

Permalink
解决部分应用程序注册多个Surface行为(最大两个)
Browse files Browse the repository at this point in the history
solve some apps register multiply surfaces (up to 2)
  • Loading branch information
w2016561536 committed Sep 12, 2021
1 parent f93409e commit 4288c9b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.example.vcam"
minSdk 21
targetSdk 28
versionCode 9
versionName "2.6"
versionCode 10
versionName "2.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 9,
"versionName": "2.6",
"versionCode": 10,
"versionName": "2.7",
"outputFile": "app-release.apk"
}
],
Expand Down
29 changes: 28 additions & 1 deletion app/src/main/java/com/example/vcam/HookMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class HookMain implements IXposedHookLoadPackage {
//public static Thread prepare_thred;
public static VideoToFrames hw_decode_obj;
public static VideoToFrames c2_hw_decode_obj;
public static VideoToFrames c2_hw_decode_obj_1;
public static SurfaceTexture c1_fake_texture;
public static Surface c1_fake_surface;
public static SurfaceHolder ori_holder;
Expand All @@ -75,6 +76,7 @@ public class HookMain implements IXposedHookLoadPackage {

public static Surface c2_preview_Surfcae;
public static Surface c2_reader_Surfcae;
public static Surface c2_reader_Surfcae_1;
public static MediaPlayer c2_player;
public static CaptureRequest.Builder c2_builder;
public static ImageReader c2_image_reader;
Expand Down Expand Up @@ -207,6 +209,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.findAndHookMethod("android.hardware.camera2.CaptureRequest.Builder", lpparam.classLoader, "addTarget", Surface.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (param.args[0] == null){
return;
}
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/virtual.mp4");
File control_file = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/disable.jpg");
if ((!file.exists()) && control_file.exists() ){
Expand All @@ -215,10 +220,11 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
return;
}
if (HookMain.c2_builder == null || (!param.thisObject.equals(HookMain.c2_builder))){
if ((!param.thisObject.equals(HookMain.c2_builder))){
HookMain.c2_builder = (CaptureRequest.Builder) param.thisObject;
c2_reader_Surfcae = null;
c2_preview_Surfcae = null;
c2_reader_Surfcae_1 = null;
String surfaceInfo = param.args[0].toString();
if (surfaceInfo.contains("Surface(name=null)")){
c2_reader_Surfcae = (Surface) param.args[0];
Expand All @@ -234,6 +240,10 @@ protected void beforeHookedMethod(MethodHookParam param) {
if (surfaceInfo.contains("Surface(name=null)")){
if (c2_reader_Surfcae == null) {
c2_reader_Surfcae = (Surface) param.args[0];
}else {
if ((!c2_reader_Surfcae.equals(param.args[0])) && c2_reader_Surfcae_1 == null){
c2_reader_Surfcae_1 = (Surface) param.args[0];
}
}
}else {
if (c2_preview_Surfcae == null) {
Expand Down Expand Up @@ -560,6 +570,23 @@ public void onPrepared(MediaPlayer mp) {
}
}

if (c2_reader_Surfcae_1 !=null){

if (c2_hw_decode_obj_1 != null){
c2_hw_decode_obj_1.stopDecode();
c2_hw_decode_obj_1 =null;
}

c2_hw_decode_obj_1 = new VideoToFrames();
try {
c2_hw_decode_obj_1.setSaveFrames(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera2/", OutputImageFormat.NV21);
c2_hw_decode_obj_1.set_surfcae(HookMain.c2_reader_Surfcae_1);
c2_hw_decode_obj_1.decode(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/virtual.mp4");
}catch (Throwable throwable){
throwable.printStackTrace();
}
}

}
});
}
Expand Down

0 comments on commit 4288c9b

Please sign in to comment.