修复设置焦距浮点型炸裂的问题

重新设置测光点
This commit is contained in:
Yutousama 2022-03-17 11:41:05 +08:00
parent 8f9ae202db
commit 16a552d80c
3 changed files with 35 additions and 16 deletions

View File

@ -27,6 +27,7 @@ import me.lake.librestreaming.ws.filter.hardfilter.WatermarkFilter
import me.lake.librestreaming.ws.filter.hardfilter.extra.GPUImageCompatibleFilter import me.lake.librestreaming.ws.filter.hardfilter.extra.GPUImageCompatibleFilter
import org.json.JSONObject import org.json.JSONObject
import java.io.File import java.io.File
import java.math.BigDecimal
import java.util.* import java.util.*
@ -37,7 +38,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var button_open: Button private lateinit var button_open: Button
private lateinit var button_af: Button private lateinit var button_af: Button
private lateinit var mLiveCameraView: StreamLiveCameraView private lateinit var mLiveCameraView: StreamLiveCameraView
private var zoom = 0.0f private var zoom =BigDecimal(0)
private var isUpdate = true private var isUpdate = true
public lateinit var myDataListener: MyDataListener public lateinit var myDataListener: MyDataListener
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -74,19 +75,20 @@ class MainActivity : AppCompatActivity() {
button_open = findViewById(R.id.openPC) button_open = findViewById(R.id.openPC)
button_af = findViewById(R.id.af) button_af = findViewById(R.id.af)
button_up.setOnClickListener { button_up.setOnClickListener {
zoom += 0.1f zoom.add(BigDecimal(0.1))
if (zoom > 1.0f) { if (zoom.toFloat() > 1.0f) {
zoom = 1.0f zoom = BigDecimal(1.0)
} }
mLiveCameraView.setZoomByPercent(zoom)
mLiveCameraView.setZoomByPercent(zoom.toFloat())
uploadZoom(zoom) uploadZoom(zoom)
} }
button_down.setOnClickListener { button_down.setOnClickListener {
zoom -= 0.1f zoom.subtract(BigDecimal(0.1))
if (zoom < 0f) { if (zoom.toFloat() < 0f) {
zoom = 0.0f zoom = BigDecimal(0)
} }
mLiveCameraView.setZoomByPercent(zoom) mLiveCameraView.setZoomByPercent(zoom.toFloat())
uploadZoom(zoom) uploadZoom(zoom)
} }
button_screen.setOnClickListener { button_screen.setOnClickListener {
@ -119,14 +121,14 @@ class MainActivity : AppCompatActivity() {
} }
} }
private fun uploadZoom(zoom: Float) { private fun uploadZoom(zoom: BigDecimal) {
val json = JSONObject() val json = JSONObject()
json.put("zoom", zoom) json.put("zoom", "${zoom.toFloat()}")
HttpUtils.post("http://192.168.31.88:8000/door/zoom.do", json, null, object : HttpListener { HttpUtils.post("http://192.168.31.88:8000/door/zoom.do", json, null, object : HttpListener {
override fun data(code: Int, data: String) { override fun data(code: Int, data: String) {
if (data == "1") { if (data == "1") {
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
Toast.makeText(this@MainActivity, "设置成功:${zoom}", Toast.LENGTH_LONG).show() Toast.makeText(this@MainActivity, "设置成功:${zoom.toFloat()}", Toast.LENGTH_LONG).show()
} }
} }
} }
@ -170,7 +172,7 @@ class MainActivity : AppCompatActivity() {
Timer().schedule(object : TimerTask() { Timer().schedule(object : TimerTask() {
override fun run() { override fun run() {
watermark.updateText(32f, Utils.getTime()+" 推流:${mLiveCameraView.avSpeed}") watermark.updateText(32f, Utils.getTime()+" 推流:${mLiveCameraView.avSpeed}")
if (!mLiveCameraView.isStreaming||mLiveCameraView.avSpeed==0) { if (mLiveCameraView.avSpeed==0) {
mLiveCameraView.stopStreaming() mLiveCameraView.stopStreaming()
mLiveCameraView.startStreaming("rtmp://192.168.31.88/live") mLiveCameraView.startStreaming("rtmp://192.168.31.88/live")
} }
@ -194,8 +196,8 @@ class MainActivity : AppCompatActivity() {
inner class MyDataListener : DataListener { inner class MyDataListener : DataListener {
override fun out(json: JSONObject) { override fun out(json: JSONObject) {
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
zoom = json.getDouble("zoom").toFloat() zoom = BigDecimal(json.getDouble("zoom"))
mLiveCameraView.setZoomByPercent(zoom) mLiveCameraView.setZoomByPercent(zoom.toFloat())
if (json.getString("restart").equals("1")) { if (json.getString("restart").equals("1")) {
val intent = packageManager.getLaunchIntentForPackage(packageName); val intent = packageManager.getLaunchIntentForPackage(packageName);
intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

View File

@ -5,6 +5,7 @@ android {
compileSdkVersion 31 compileSdkVersion 31
defaultConfig { defaultConfig {
targetSdkVersion 31 targetSdkVersion 31
minSdk 21
ndk{ ndk{
abiFilters "armeabi-v7a" abiFilters "armeabi-v7a"
} }
@ -22,6 +23,13 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
/* externalNativeBuild{ /* externalNativeBuild{
ndkBuild{ ndkBuild{
path file("src/main/jni/rtmp/Android.mk") path file("src/main/jni/rtmp/Android.mk")
@ -39,4 +47,13 @@ android {
dependencies { dependencies {
implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1' implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
def camerax_version = "1.1.0-beta01"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-video:${camerax_version}"
implementation "androidx.camera:camera-view:${camerax_version}"
implementation "androidx.camera:camera-extensions:${camerax_version}"
} }

View File

@ -511,7 +511,7 @@ public class RESVideoClient {
public void setCameraArea(){ public void setCameraArea(){
System.out.println("设置对焦"); System.out.println("设置对焦");
List<Camera.Area> focusAreas = new ArrayList<>(); List<Camera.Area> focusAreas = new ArrayList<>();
focusAreas.add(new Camera.Area(calculateTapArea(0,0,5,5,1.0f), 800)); focusAreas.add(new Camera.Area(new Rect(-100, -100, 100, 100), 1000));
Camera.Parameters parameters=camera.getParameters(); Camera.Parameters parameters=camera.getParameters();
parameters.setFocusAreas(focusAreas); parameters.setFocusAreas(focusAreas);
camera.setParameters(parameters); camera.setParameters(parameters);