Camera2 修改旋转角度

master
liuguijing 7 months ago
parent 8b42f2ce75
commit e525f7d2c9

@ -140,10 +140,11 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
String url = intent.getStringExtra("url");
if (!TextUtils.isEmpty(url)) {
rtmpUrl = url;
// rtmpUrl = "rtmp://61.169.135.146/live/0";
}
efu.setText(rtmpUrl);
mCameraView = (SrsCameraView) findViewById(R.id.glsurfaceview_camera);
final int rotation = intent.getIntExtra("rotation", -1);
final int rotation = intent.getIntExtra("rotation", 0);
if (rotation != -1) {
//设置图像显示方向
mCameraView.setPreviewOrientation(rotation);
@ -164,7 +165,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
mPublisher.setVideoHDMode();
cameraId = intent.getIntExtra("cameraId", 1);
cameraId = intent.getIntExtra("cameraId", 0);
// mPublisher.startCamera();
mCameraView.setCameraCallbacksHandler(new SrsCameraView.CameraCallbacksHandler() {
@ -176,7 +177,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
final int autoStart = intent.getIntExtra("autoStart", 1);
if (autoStart != 0) {
mPublisher.switchCameraFace(cameraId,rotation);
mPublisher.switchCameraFace(cameraId, rotation);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@ -184,7 +185,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
SharedPreferences.Editor editor = sp.edit();
editor.putString("rtmpUrl", rtmpUrl);
editor.apply();
efu.setText(rtmpUrl + " cameraid=" + cameraId + " auto=" + autoStart);
efu.setText(rtmpUrl + "rotation= " + rotation + " cameraid=" + cameraId + " auto=" + autoStart);
mPublisher.startPublish(rtmpUrl);
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
Toast.makeText(getApplicationContext(), "Use hard encoder", Toast.LENGTH_SHORT).show();
@ -197,7 +198,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
}
}, 500);
} else {
mPublisher.switchCameraFace(cameraId,rotation);
mPublisher.switchCameraFace(cameraId, rotation);
}
int autoClose = intent.getIntExtra("autoClose", 0);
@ -226,7 +227,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
efu.setText(rtmpUrl);
mPublisher.startPublish(rtmpUrl);
// mPublisher.startCamera();
mPublisher.switchCameraFace(cameraId,rotation);
mPublisher.switchCameraFace(cameraId, rotation);
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
Toast.makeText(getApplicationContext(), "Use hard encoder", Toast.LENGTH_SHORT).show();
@ -265,7 +266,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
int size = cameraData.size();
if (size > 0) {
int i = (++cameraId) % size;
mPublisher.switchCameraFace(cameraId,rotation);
mPublisher.switchCameraFace(cameraId, rotation);
}
}
});

@ -412,6 +412,60 @@ public class GPUImageFilter {
}
}
// //设置纹理旋转角度
// public void setOrtation(int rotation) {
//
//// //纹理坐标
//// TEX_COORD = new float[]{0.0f, 0.0f, // Bottom left.
//// 1.0f, 0.0f, // Bottom right.
//// 0.0f, 1.0f, // Top left.
//// 1.0f, 1.0f // Top right.
//// };
//
// final float TEX_COORD0[] = {
////1号摄像头 正
// 0.0f, 1.0f, // Bottom left.
// 0.0f, 0.0f, // Bottom right.
// 1.0f, 1.0f, // Top left.
// 1.0f, 0.0f // Top right.
// };
// final float TEX_COORD_90[] = {
////二号摄像头正
// 1.0f, 1.0f, // Bottom left.
// 0.0f, 1.0f, // Bottom right.
// 1.0f, 0.0f, // Top left.
// 0.0f, 0.0f // Top right.
// };
// final float TEX_COORD_180[] = {
////三号摄像头正
// 1.0f, 0.0f, // Bottom left.
// 1.0f, 1.0f, // Bottom right.
// 0.0f, 0.0f, // Top left.
// 0.0f, 1.0f // Top right.
// };
//
// final float TEX_COORD_270[] = {0.0f, 0.0f, // Bottom left.
// 1.0f, 0.0f, // Bottom right.
// 0.0f, 1.0f, // Top left.
// 1.0f, 1.0f // Top right.
// };
// //纹理坐标
// TEX_COORD = TEX_COORD0;
// if (rotation == 0) {
// TEX_COORD = TEX_COORD0;
// } else if (rotation == 90) {
// TEX_COORD = TEX_COORD_270;
// } else if (rotation == 180) {
// TEX_COORD = TEX_COORD_180;
// } else if (rotation == 270) {
// TEX_COORD = TEX_COORD_90;
// } else {
// TEX_COORD = TEX_COORD0;
// }
//
// }
//设置纹理旋转角度
public void setOrtation(int rotation) {
@ -423,42 +477,40 @@ public class GPUImageFilter {
// };
final float TEX_COORD0[] = {
//1号摄像头 正
0.0f, 0.0f, // Bottom left.
1.0f, 0.0f, // Bottom right.
0.0f, 1.0f, // Top left.
1.0f, 1.0f // Top right.
};
final float TEX_COORD_90[] = {
0.0f, 1.0f, // Bottom left.
0.0f, 0.0f, // Bottom right.
1.0f, 1.0f, // Top left.
1.0f, 0.0f // Top right.
};
final float TEX_COORD_90[] = {
//二号摄像头正
final float TEX_COORD_180[] = {
1.0f, 1.0f, // Bottom left.
0.0f, 1.0f, // Bottom right.
1.0f, 0.0f, // Top left.
0.0f, 0.0f // Top right.
};
final float TEX_COORD_180[] = {
//三号摄像头正
final float TEX_COORD_270[] = {
1.0f, 0.0f, // Bottom left.
1.0f, 1.0f, // Bottom right.
0.0f, 0.0f, // Top left.
0.0f, 1.0f // Top right.
};
final float TEX_COORD_270[] = {0.0f, 0.0f, // Bottom left.
1.0f, 0.0f, // Bottom right.
0.0f, 1.0f, // Top left.
1.0f, 1.0f // Top right.
};
//纹理坐标
TEX_COORD = TEX_COORD0;
if (rotation == 0) {
TEX_COORD = TEX_COORD0;
} else if (rotation == 90) {
TEX_COORD = TEX_COORD_270;
TEX_COORD = TEX_COORD_90;
} else if (rotation == 180) {
TEX_COORD = TEX_COORD_180;
} else if (rotation == 270) {
TEX_COORD = TEX_COORD_90;
TEX_COORD = TEX_COORD_270;
} else {
TEX_COORD = TEX_COORD0;
}

Loading…
Cancel
Save