Skip to content

Commit

Permalink
修复bug,优化camera接口
Browse files Browse the repository at this point in the history
fix bugs ,polish camera api
  • Loading branch information
w2016561536 committed Sep 17, 2021
1 parent 2f4545d commit bd6cbb5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 104 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 12
versionName "2.9"
versionCode 13
versionName "3.0"

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": 12,
"versionName": "2.9",
"versionCode": 13,
"versionName": "3.0",
"outputFile": "app-release.apk"
}
],
Expand Down
173 changes: 73 additions & 100 deletions app/src/main/java/com/example/vcam/HookMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class HookMain implements IXposedHookLoadPackage {
public static Camera reallycamera;

public static Camera data_camera;
public static Camera start_preview_camera;
public static volatile byte[] data_buffer;
public static byte[] input;
public static int mhight;
Expand Down Expand Up @@ -105,6 +106,9 @@ protected void beforeHookedMethod(MethodHookParam param) {
if (param.args[0] == null) {
return;
}
if (param.args[0].equals(c1_fake_texture)){
return;
}
if (reallycamera != null && reallycamera.equals(param.thisObject)) {
param.args[0] = HookMain.virtual_st;
XposedBridge.log("发现重复" + reallycamera.toString());
Expand All @@ -115,55 +119,13 @@ protected void beforeHookedMethod(MethodHookParam param) {

reallycamera = (Camera) param.thisObject;
HookMain.msurftext = (SurfaceTexture) param.args[0];


if (HookMain.virtual_st == null) {
HookMain.virtual_st = new SurfaceTexture(10);
} else {
HookMain.virtual_st.release();
HookMain.virtual_st = new SurfaceTexture(10);
}
param.args[0] = HookMain.virtual_st;

if (HookMain.msurf == null) {
HookMain.msurf = new Surface(HookMain.msurftext);
} else {
HookMain.msurf.release();
HookMain.msurf = new Surface(HookMain.msurftext);
}

if (HookMain.mMedia == null) {
HookMain.mMedia = new MediaPlayer();
} else {
HookMain.mMedia.release();
HookMain.mMedia = new MediaPlayer();
}

HookMain.mMedia.setSurface(HookMain.msurf);

File sfile = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/no-silent.jpg");
if (!(sfile.exists() && (!is_someone_playing))){
HookMain.mMedia.setVolume(0, 0);
is_someone_playing =false;
}else {
is_someone_playing = true;
}
HookMain.mMedia.setLooping(true);

HookMain.mMedia.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
HookMain.mMedia.start();
}
});

try {
HookMain.mMedia.setDataSource(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/virtual.mp4");
HookMain.mMedia.prepare();
} catch (IOException e) {
e.printStackTrace();
}

}
});
} else {
Expand Down Expand Up @@ -348,28 +310,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
});

XposedHelpers.findAndHookMethod("android.hardware.Camera", lpparam.classLoader, "setPreviewDisplay", SurfaceHolder.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod("android.hardware.Camera", lpparam.classLoader, "startPreview", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!param.thisObject.equals(mcamera1)) {
XposedBridge.log("创建Surfaceview预览");
mcamera1 = (Camera) param.thisObject;
ori_holder = (SurfaceHolder) param.args[0];
if (c1_fake_texture == null) {
c1_fake_texture = new SurfaceTexture(11);
} else {
c1_fake_texture.release();
c1_fake_texture = null;
c1_fake_texture = new SurfaceTexture(11);
}

if (c1_fake_surface == null) {
c1_fake_surface = new Surface(c1_fake_texture);
} else {
c1_fake_surface.release();
c1_fake_surface = null;
c1_fake_surface = new Surface(c1_fake_texture);
}
is_someone_playing = false;
start_preview_camera = (Camera) param.thisObject;
if (ori_holder != null){

if (mplayer1 == null) {
mplayer1 = new MediaPlayer();
Expand All @@ -378,10 +324,10 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
mplayer1 = null;
mplayer1 = new MediaPlayer();
}

if (!HookMain.ori_holder.getSurface().isValid() || HookMain.ori_holder == null){
return;
}
HookMain.mplayer1.setSurface(HookMain.ori_holder.getSurface());
is_hooked =true;
mcamera1.setPreviewTexture(c1_fake_texture);
File sfile = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/no-silent.jpg");
if (!(sfile.exists() && (!is_someone_playing))){
HookMain.mplayer1.setVolume(0, 0);
Expand All @@ -404,52 +350,76 @@ public void onPrepared(MediaPlayer mp) {
} catch (IOException e) {
e.printStackTrace();
}

} else {
XposedBridge.log("发现重复Surfaceview");
is_hooked = true;
mcamera1.setPreviewTexture(c1_fake_texture);
}
param.setResult(null);
}
});

XposedHelpers.findAndHookMethod("android.hardware.Camera", lpparam.classLoader, "stopPreview", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (param.thisObject.equals(HookMain.reallycamera) || param.thisObject.equals(HookMain.data_camera) || param.thisObject.equals(HookMain.mcamera1)) {
if (hw_decode_obj != null){
hw_decode_obj.stopDecode();

if (msurftext != null){
if (HookMain.msurf == null) {
HookMain.msurf = new Surface(HookMain.msurftext);
} else {
HookMain.msurf.release();
HookMain.msurf = new Surface(HookMain.msurftext);
}
if (mplayer1 != null){
mplayer1.release();
mplayer1 = null;

if (HookMain.mMedia == null) {
HookMain.mMedia = new MediaPlayer();
} else {
HookMain.mMedia.release();
HookMain.mMedia = new MediaPlayer();
}
if (mMedia != null){
mMedia.release();
mMedia = null;

HookMain.mMedia.setSurface(HookMain.msurf);

File sfile = new File(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/no-silent.jpg");
if (!(sfile.exists() && (!is_someone_playing))){
HookMain.mMedia.setVolume(0, 0);
is_someone_playing =false;
}else {
is_someone_playing = true;
}
HookMain.mMedia.setLooping(true);

HookMain.mMedia.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
HookMain.mMedia.start();
}
});

try {
HookMain.mMedia.setDataSource(Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/virtual.mp4");
HookMain.mMedia.prepare();
} catch (IOException e) {
e.printStackTrace();
}
is_someone_playing = false;
}
}
});

XposedHelpers.findAndHookMethod("android.hardware.Camera", lpparam.classLoader, "stopPreview", new XC_MethodHook() {
XposedHelpers.findAndHookMethod("android.hardware.Camera", lpparam.classLoader, "setPreviewDisplay", SurfaceHolder.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
if (param.thisObject.equals(HookMain.reallycamera) || param.thisObject.equals(HookMain.data_camera) || param.thisObject.equals(HookMain.mcamera1)) {
if (hw_decode_obj != null){
hw_decode_obj.stopDecode();
}
if (mplayer1 != null){
mplayer1.release();
mplayer1 = null;
}
if (mMedia != null){
mMedia.release();
mMedia = null;
}
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("创建Surfaceview预览");
mcamera1 = (Camera) param.thisObject;
ori_holder = (SurfaceHolder) param.args[0];
if (c1_fake_texture == null) {
c1_fake_texture = new SurfaceTexture(11);
} else {
c1_fake_texture.release();
c1_fake_texture = null;
c1_fake_texture = new SurfaceTexture(11);
}

if (c1_fake_surface == null) {
c1_fake_surface = new Surface(c1_fake_texture);
} else {
c1_fake_surface.release();
c1_fake_surface = null;
c1_fake_surface = new Surface(c1_fake_texture);
}
is_hooked =true;
mcamera1.setPreviewTexture(c1_fake_texture);
param.setResult(null);
}
});

Expand All @@ -468,6 +438,9 @@ protected void beforeHookedMethod(MethodHookParam param) {
mMedia.release();
mMedia = null;
}
is_someone_playing = false;
msurftext = null;
msurf = null;
}
}
});
Expand Down

0 comments on commit bd6cbb5

Please sign in to comment.