Commit 41e46616 authored by 马乐's avatar 马乐

增加channel

parent 7773cb05
...@@ -38,6 +38,7 @@ import kotlinx.coroutines.Dispatchers ...@@ -38,6 +38,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
...@@ -69,6 +70,8 @@ class MainActivity : AppCompatActivity() { ...@@ -69,6 +70,8 @@ class MainActivity : AppCompatActivity() {
private var job:Job? = null private var job:Job? = null
private var avmStartScope:AvmCoroutineScope ?= null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
...@@ -130,7 +133,11 @@ class MainActivity : AppCompatActivity() { ...@@ -130,7 +133,11 @@ class MainActivity : AppCompatActivity() {
} }
binding.startAvm.setOnClickListener { binding.startAvm.setOnClickListener {
openAuxiliaryPresentation() openAuxiliaryPresentation()
avmCoroutineScope.launch { if (avmStartScope == null) {
avmStartScope = AvmCoroutineScope(AvmCoroutineContext(engine = avmEngine) + Dispatchers.IO + COROUTINE_AVM + Job())
}
val channel = Channel<Boolean>()
avmStartScope?.launch {
launch(Dispatchers.Default) { launch(Dispatchers.Default) {
avmFrontCamera.startPictureSequence( avmFrontCamera.startPictureSequence(
PictureSequenceSource.GENERAL_CAMERA, PictureSequenceSource.GENERAL_CAMERA,
...@@ -138,6 +145,9 @@ class MainActivity : AppCompatActivity() { ...@@ -138,6 +145,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) { if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofFront(data).also { ArcAVMInputImageFactory.ofFront(data).also {
avmInputImages[0] = it avmInputImages[0] = it
launch {
channel.send(true)
}
} }
} }
} }
...@@ -150,6 +160,9 @@ class MainActivity : AppCompatActivity() { ...@@ -150,6 +160,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) { if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofRight(data).also { ArcAVMInputImageFactory.ofRight(data).also {
avmInputImages[1] = it avmInputImages[1] = it
launch {
channel.send(true)
}
} }
} }
} }
...@@ -162,6 +175,9 @@ class MainActivity : AppCompatActivity() { ...@@ -162,6 +175,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) { if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofBack(data).also { ArcAVMInputImageFactory.ofBack(data).also {
avmInputImages[2] = it avmInputImages[2] = it
launch {
channel.send(true)
}
} }
} }
} }
...@@ -174,6 +190,9 @@ class MainActivity : AppCompatActivity() { ...@@ -174,6 +190,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) { if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofLeft(data).also { ArcAVMInputImageFactory.ofLeft(data).also {
avmInputImages[3] = it avmInputImages[3] = it
launch {
channel.send(true)
}
} }
} }
} }
...@@ -185,14 +204,18 @@ class MainActivity : AppCompatActivity() { ...@@ -185,14 +204,18 @@ class MainActivity : AppCompatActivity() {
} }
LogUtils.d("准备播放融合图...") LogUtils.d("准备播放融合图...")
if (spUtils.getBoolean(CALIB_RESULT) && spUtils.getBoolean(LOOKUP_TABLE)) { if (spUtils.getBoolean(CALIB_RESULT) && spUtils.getBoolean(LOOKUP_TABLE)) {
val result = coroutineContext[AvmCoroutineContext]?.engine?.drawAVM( launch(Dispatchers.Default) {
31, while (channel.receive()) {
avmInputImages, val result = coroutineContext[AvmCoroutineContext]?.engine?.drawAVM(
outputImageList 31,
) avmInputImages,
if (result == ArcErrorInfo.ARC_ERROR_OK) { outputImageList
if (outputImageList.isNotEmpty()) { )
feedData(outputImageList[0].imageData) if (result == ArcErrorInfo.ARC_ERROR_OK) {
if (outputImageList.isNotEmpty()) {
feedData(outputImageList[0].imageData)
}
}
} }
} }
} else { } else {
...@@ -203,13 +226,13 @@ class MainActivity : AppCompatActivity() { ...@@ -203,13 +226,13 @@ class MainActivity : AppCompatActivity() {
} }
} }
binding.stopAvm.setOnClickListener { binding.stopAvm.setOnClickListener {
avmCoroutineScope.launch { avmStartScope?.launch {
avmLeftCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA) avmLeftCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA)
avmFrontCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA) avmFrontCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA)
avmRightCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA) avmRightCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA)
avmBackCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA) avmBackCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA)
cancel(kotlinx.coroutines.CancellationException("Click Stop Avm Button"))
} }
avmCoroutineScope.cancel(kotlinx.coroutines.CancellationException("Click Stop Avm Button"))
closeAuxiliaryPresentation() closeAuxiliaryPresentation()
} }
} }
......
...@@ -72,17 +72,8 @@ val avmCoroutineScope by lazy { ...@@ -72,17 +72,8 @@ val avmCoroutineScope by lazy {
AvmCoroutineScope(AvmCoroutineContext(engine = avmEngine) + Dispatchers.IO + COROUTINE_AVM) AvmCoroutineScope(AvmCoroutineContext(engine = avmEngine) + Dispatchers.IO + COROUTINE_AVM)
} }
class AvmCoroutineScope(context: CoroutineContext) : Closeable, CoroutineScope { class AvmCoroutineScope(context: CoroutineContext) : CoroutineScope {
override val coroutineContext: CoroutineContext = context + avmJob override val coroutineContext: CoroutineContext = context
override fun close() {
LogUtils.e("Avm关闭")
SmartPlatformManager.get().closeCameraDevice(avmFrontCamera)
SmartPlatformManager.get().closeCameraDevice(avmLeftCamera)
SmartPlatformManager.get().closeCameraDevice(avmRightCamera)
SmartPlatformManager.get().closeCameraDevice(avmBackCamera)
coroutineContext[AvmCoroutineContext]?.engine?.unInit()
coroutineContext.cancel()
}
} }
fun ArcVisDriveAVMEngine.initializeAvmParams(calibResultPath:File,lookupPath:File):Int { fun ArcVisDriveAVMEngine.initializeAvmParams(calibResultPath:File,lookupPath:File):Int {
......
/*
* Copyright (c) 2021 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
* distribute, sublicense, create a derivative work, and/or sell copies of the
* Software in any work that is designed, intended, or marketed for pedagogical or
* instructional purposes related to programming, coding, application development,
* or information technology. Permission for such use, copying, modification,
* merger, publication, distribution, sublicensing, creation of derivative works,
* or sale is expressly withheld.
*
* This project and source code may use libraries or frameworks that are
* released under various Open-Source licenses. Use of those libraries and
* frameworks are governed by their own individual licenses.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intergration.avm.utils
import kotlinx.coroutines.Dispatchers
class DefaultDispatchersProvider : DispatchersProvider {
override fun io() = Dispatchers.IO
override fun main() = Dispatchers.Main
override fun avm() = Dispatchers.Default
override fun camera() = Dispatchers.IO
}
\ No newline at end of file
/*
* Copyright (c) 2021 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
* distribute, sublicense, create a derivative work, and/or sell copies of the
* Software in any work that is designed, intended, or marketed for pedagogical or
* instructional purposes related to programming, coding, application development,
* or information technology. Permission for such use, copying, modification,
* merger, publication, distribution, sublicensing, creation of derivative works,
* or sale is expressly withheld.
*
* This project and source code may use libraries or frameworks that are
* released under various Open-Source licenses. Use of those libraries and
* frameworks are governed by their own individual licenses.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intergration.avm.utils
import kotlinx.coroutines.CoroutineDispatcher
interface DispatchersProvider {
fun io(): CoroutineDispatcher
fun main(): CoroutineDispatcher
fun avm(): CoroutineDispatcher
fun camera(): CoroutineDispatcher
}
\ No newline at end of file
...@@ -51,8 +51,10 @@ fun Context.openAuxiliaryPresentation(){ ...@@ -51,8 +51,10 @@ fun Context.openAuxiliaryPresentation(){
} }
fun Context.closeAuxiliaryPresentation(){ fun Context.closeAuxiliaryPresentation(){
multiScreenService?.dismissSecondPresentation() if (multiScreenService != null) {
unbindService(serviceConnection) multiScreenService?.dismissSecondPresentation()
unbindService(serviceConnection)
}
} }
fun feedData(data: ByteArray){ fun feedData(data: ByteArray){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment