修改短视频预览摄像头不正的bug

lowmem
liuguijing 2 months ago
parent e0a23a6c3b
commit 7a557ac8fd

@ -65,8 +65,8 @@ android {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
externalNativeBuild {
cmake {

@ -2498,15 +2498,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
}
//为修复宁夏短视频拍照翻转的bug 临时修改方法
// int orientation = mPhotoInfo.orientation == 0 ? -1 : (mPhotoInfo.orientation - 1) * 90;
int orientation = -1;
if (mPhotoInfo.cameraId == 0) {
orientation = -1;
} else if (mPhotoInfo.cameraId == 1) {
orientation = 0;
} else if (mPhotoInfo.cameraId == 2) {
orientation =-3;
}
int orientation = mPhotoInfo.orientation == 0 ? -1 : (mPhotoInfo.orientation - 1);
jboolean photoOrVideo = mPhotoInfo.mediaType == 0 ? JNI_TRUE : JNI_FALSE;
env->CallVoidMethod(m_javaService, mStartRecordingMid, photoOrVideo, mPhotoInfo.cameraId, (uint64_t)mPhotoInfo.photoId,
mPhotoInfo.duration, mPhotoInfo.width, mPhotoInfo.height, mPhotoInfo.duration, orientation,

@ -812,6 +812,7 @@ public class Camera2VideoActivity extends AppCompatActivity {
.cameraId(Integer.toString(mCameraId))
.mute(true)
.duration(mDuration * 1000)
.rotation(mOrientation)
.build();
Log.i("OSD", "mGPUCameraRecorder created");

@ -41,6 +41,7 @@ public class GPUCameraRecorder {
private final int degrees;
private final boolean recordNoFilter;
private final long duration;
private final boolean ismirror;
private long startTime;
@ -59,7 +60,8 @@ public class GPUCameraRecorder {
final boolean isLandscapeDevice,
final int degrees,
final boolean recordNoFilter,
final long duration
final long duration,
final boolean ismirror
) {
@ -81,6 +83,7 @@ public class GPUCameraRecorder {
this.degrees = degrees;
this.recordNoFilter = recordNoFilter;
this.duration = duration;
this.ismirror = ismirror;
// create preview Renderer
if (null == glPreviewRenderer) {
@ -119,7 +122,7 @@ public class GPUCameraRecorder {
public void run() {
if (glPreviewRenderer != null) {
glPreviewRenderer.setAngle(degrees);
glPreviewRenderer.onStartPreview(previewWidth, previewHeight, isLandscapeDevice);
glPreviewRenderer.onStartPreview(previewWidth, previewHeight, isLandscapeDevice,ismirror);
}
}
});

@ -4,10 +4,12 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.Surface;
import com.xypower.gpuv.egl.filter.GlFilter;
@ -31,6 +33,10 @@ public class GPUCameraRecorderBuilder {
private GlFilter glFilter;
private long duration;
private int rotation;
private Integer sensororientation;
private Integer facing;
private boolean ifmirror = false;
public GPUCameraRecorderBuilder(Activity activity, GLSurfaceView glSurfaceView) {
this.activity = activity;
this.glSurfaceView = glSurfaceView;
@ -88,6 +94,7 @@ public class GPUCameraRecorderBuilder {
this.rotation = d;
return this;
}
public GPUCameraRecorderBuilder recordNoFilter(boolean recordNoFilter) {
this.recordNoFilter = recordNoFilter;
return this;
@ -101,15 +108,31 @@ public class GPUCameraRecorderBuilder {
CameraManager cameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
boolean isLandscapeDevice = resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
CameraCharacteristics cameraCharacteristics = null;
try {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
} catch (Exception ex) {
ex.printStackTrace();
}
if (cameraCharacteristics != null) {
facing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
sensororientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}
int degrees = 0;
// if (isLandscapeDevice) {
// int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
// Log.d("GPUCameraRecorder", "Surface.ROTATION_90 = " + Surface.ROTATION_90 + " rotation = " + rotation);
// degrees = 90 * (rotation - 2);
// }
if (isLandscapeDevice) {
Log.d("GPUCameraRecorder", "测试测试rotation" + rotation);
degrees = rotation * 90;
if (facing == 1) {
if (rotation == -1) {
degrees = sensororientation;
} else {
degrees = sensororientation + (rotation - 1) * 90;
}
ifmirror = false;
} else {
if (rotation == -1) {
degrees = sensororientation + 180;
} else {
degrees = sensororientation + (rotation - 1) * 90 + 180;
}
ifmirror = true;
}
Log.d("GPUCameraRecorder", "测试测试" + degrees);
@ -129,7 +152,8 @@ public class GPUCameraRecorderBuilder {
isLandscapeDevice,
degrees,
recordNoFilter,
duration
duration,
ifmirror
);
GPUCameraRecorder.setFilter(glFilter);

@ -7,6 +7,7 @@ import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Handler;
import android.util.Size;
import com.xypower.gpuv.camerarecorder.capture.MediaVideoEncoder;
import com.xypower.gpuv.egl.filter.GlFilter;
@ -15,7 +16,6 @@ import javax.microedition.khronos.egl.EGLConfig;
import static android.opengl.GLES20.*;
public class GlPreviewRenderer extends GlFrameBufferObjectRenderer implements SurfaceTexture.OnFrameAvailableListener {
private final Handler handler = new Handler();
@ -66,11 +66,14 @@ public class GlPreviewRenderer extends GlFrameBufferObjectRenderer implements Su
Matrix.setIdentityM(STMatrix, 0);
}
public void onStartPreview(float cameraPreviewWidth, float cameraPreviewHeight, boolean isLandscapeDevice) {
public void onStartPreview(float cameraPreviewWidth, float cameraPreviewHeight, boolean isLandscapeDevice, boolean ismirror) {
Matrix.setIdentityM(MMatrix, 0);
Matrix.rotateM(MMatrix, 0, -angle, 0.0f, 0.0f, 1.0f);
Matrix.rotateM(MMatrix, 0, angle, 0.0f, 0.0f, 1.0f);
if (ismirror) {
Matrix.scaleM(MMatrix, 0, 1, -1, 1);
}
// Log.d("GPUCameraRecorder ", "angle" + angle);
// Log.d("GPUCameraRecorder ", "getMeasuredHeight " + glView.getMeasuredHeight());
// Log.d("GPUCameraRecorder ", "getMeasuredWidth " + glView.getMeasuredWidth());

Loading…
Cancel
Save