Feature: listening the orientation of screen

pull/209/head
xufuji456 3 years ago
parent f9f146245b
commit dbf34fc9c9
  1. 32
      Live/src/main/java/com/frank/live/camera/Camera2Helper.java
  2. 3
      app/src/main/AndroidManifest.xml
  3. 6
      app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt

@ -86,32 +86,32 @@ public class Camera2Helper {
start(); start();
} }
private int getCameraOri(int rotation, String cameraId) { private int getCameraOrientation(int rotation, String cameraId) {
int degrees = rotation * 90; int degree = rotation * 90;
switch (rotation) { switch (rotation) {
case Surface.ROTATION_0: case Surface.ROTATION_0:
degrees = 0; degree = 0;
break; break;
case Surface.ROTATION_90: case Surface.ROTATION_90:
degrees = 90; degree = 90;
break; break;
case Surface.ROTATION_180: case Surface.ROTATION_180:
degrees = 180; degree = 180;
break; break;
case Surface.ROTATION_270: case Surface.ROTATION_270:
degrees = 270; degree = 270;
break; break;
default: default:
break; break;
} }
int result; int result;
if (CAMERA_ID_FRONT.equals(cameraId)) { if (CAMERA_ID_FRONT.equals(cameraId)) {
result = (mSensorOrientation + degrees) % 360; result = (mSensorOrientation + degree) % 360;
result = (360 - result) % 360; result = (360 - result) % 360;
} else { } else {
result = (mSensorOrientation - degrees + 360) % 360; result = (mSensorOrientation - degree + 360) % 360;
} }
Log.i(TAG, "getCameraOri: " + rotation + " " + result + " " + mSensorOrientation); Log.i(TAG, "getCameraOrientation, result=" + result);
return result; return result;
} }
@ -120,19 +120,19 @@ public class Camera2Helper {
@Override @Override
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
Log.i(TAG, "onSurfaceTextureAvailable: "); Log.i(TAG, "onSurfaceTextureAvailable...");
openCamera(); openCamera();
} }
@Override @Override
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
Log.i(TAG, "onSurfaceTextureSizeChanged: "); Log.i(TAG, "onSurfaceTextureSizeChanged, width=" + width + "--height=" + height);
configureTransform(width, height); configureTransform(width, height);
} }
@Override @Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) { public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {
Log.i(TAG, "onSurfaceTextureDestroyed: "); Log.i(TAG, "onSurfaceTextureDestroyed...");
return true; return true;
} }
@ -151,7 +151,7 @@ public class Camera2Helper {
mCameraDevice = cameraDevice; mCameraDevice = cameraDevice;
createCameraPreviewSession(); createCameraPreviewSession();
if (camera2Listener != null) { if (camera2Listener != null) {
camera2Listener.onCameraOpened(mPreviewSize, getCameraOri(rotation, mCameraId)); camera2Listener.onCameraOpened(mPreviewSize, getCameraOrientation(rotation, mCameraId));
} }
} }
@ -179,6 +179,7 @@ public class Camera2Helper {
} }
}; };
private final CameraCaptureSession.StateCallback mCaptureStateCallback = new CameraCaptureSession.StateCallback() { private final CameraCaptureSession.StateCallback mCaptureStateCallback = new CameraCaptureSession.StateCallback() {
@Override @Override
@ -286,7 +287,7 @@ public class Camera2Helper {
context = null; context = null;
} }
private void setUpCameraOutputs(CameraManager cameraManager) { private void setUpCameraOutput(CameraManager cameraManager) {
try { try {
if (configCameraParams(cameraManager, specificCameraId)) { if (configCameraParams(cameraManager, specificCameraId)) {
return; return;
@ -330,7 +331,7 @@ public class Camera2Helper {
private void openCamera() { private void openCamera() {
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
setUpCameraOutputs(cameraManager); setUpCameraOutput(cameraManager);
configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
try { try {
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
@ -463,7 +464,6 @@ public class Camera2Helper {
} else if (Surface.ROTATION_180 == rotation) { } else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY); matrix.postRotate(180, centerX, centerY);
} }
Log.i(TAG, "configureTransform: " + getCameraOri(rotation, mCameraId) + " " + rotation * 90);
mTextureView.setTransform(matrix); mTextureView.setTransform(matrix);
} }

@ -20,7 +20,6 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:screenOrientation="landscape"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
tools:replace="android:name"> tools:replace="android:name">
@ -39,7 +38,7 @@
<activity android:name=".activity.PushActivity" /> <activity android:name=".activity.PushActivity" />
<activity <activity
android:name=".activity.LiveActivity" android:name=".activity.LiveActivity"
android:screenOrientation="landscape" /> android:configChanges="orientation" />
<activity <activity
android:name=".activity.FilterActivity" android:name=".activity.FilterActivity"
android:screenOrientation="landscape" /> android:screenOrientation="landscape" />

@ -2,6 +2,7 @@ package com.frank.ffmpeg.activity
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.IntentFilter import android.content.IntentFilter
import android.content.res.Configuration
import android.media.AudioFormat import android.media.AudioFormat
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.os.Bundle import android.os.Bundle
@ -153,6 +154,11 @@ open class LiveActivity : BaseActivity(), CompoundButton.OnCheckedChangeListener
} }
} }
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
Log.i(TAG, "onConfigurationChanged, orientation=" + newConfig.orientation)
}
companion object { companion object {
private val TAG = LiveActivity::class.java.simpleName private val TAG = LiveActivity::class.java.simpleName

Loading…
Cancel
Save