Merge pull request #6250 from 21pages/android_ci

fix android ci, replace use with try-finally
This commit is contained in:
RustDesk 2023-11-01 10:54:01 +08:00 committed by GitHub
commit 1a422f318c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -349,12 +349,17 @@ class MainService : Service() {
).apply { ).apply {
setOnImageAvailableListener({ imageReader: ImageReader -> setOnImageAvailableListener({ imageReader: ImageReader ->
try { try {
imageReader.acquireLatestImage().use { image -> // https://stackoverflow.com/questions/35136715/try-with-resources-use-extension-function-in-kotlin-does-not-always-work
if (image == null) return@setOnImageAvailableListener // https://stackoverflow.com/questions/72537045/kotlin-use-with-autocloseable-type-and-a-lambda-returning-boolean
val image = imageReader.acquireLatestImage()
if (image == null) return@setOnImageAvailableListener
try {
val planes = image.planes val planes = image.planes
val buffer = planes[0].buffer val buffer = planes[0].buffer
buffer.rewind() buffer.rewind()
onVideoFrameUpdate(buffer) onVideoFrameUpdate(buffer)
} finally {
image.close()
} }
} catch (ignored: java.lang.Exception) { } catch (ignored: java.lang.Exception) {
} }