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

增加channel

parent 7773cb05
......@@ -38,6 +38,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
......@@ -69,6 +70,8 @@ class MainActivity : AppCompatActivity() {
private var job:Job? = null
private var avmStartScope:AvmCoroutineScope ?= null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
......@@ -130,7 +133,11 @@ class MainActivity : AppCompatActivity() {
}
binding.startAvm.setOnClickListener {
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) {
avmFrontCamera.startPictureSequence(
PictureSequenceSource.GENERAL_CAMERA,
......@@ -138,6 +145,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofFront(data).also {
avmInputImages[0] = it
launch {
channel.send(true)
}
}
}
}
......@@ -150,6 +160,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofRight(data).also {
avmInputImages[1] = it
launch {
channel.send(true)
}
}
}
}
......@@ -162,6 +175,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofBack(data).also {
avmInputImages[2] = it
launch {
channel.send(true)
}
}
}
}
......@@ -174,6 +190,9 @@ class MainActivity : AppCompatActivity() {
if (status == SpmCameraDevice.ImageDataCallback.IMAGE_STATUS_SUCCEEDED) {
ArcAVMInputImageFactory.ofLeft(data).also {
avmInputImages[3] = it
launch {
channel.send(true)
}
}
}
}
......@@ -185,14 +204,18 @@ class MainActivity : AppCompatActivity() {
}
LogUtils.d("准备播放融合图...")
if (spUtils.getBoolean(CALIB_RESULT) && spUtils.getBoolean(LOOKUP_TABLE)) {
val result = coroutineContext[AvmCoroutineContext]?.engine?.drawAVM(
31,
avmInputImages,
outputImageList
)
if (result == ArcErrorInfo.ARC_ERROR_OK) {
if (outputImageList.isNotEmpty()) {
feedData(outputImageList[0].imageData)
launch(Dispatchers.Default) {
while (channel.receive()) {
val result = coroutineContext[AvmCoroutineContext]?.engine?.drawAVM(
31,
avmInputImages,
outputImageList
)
if (result == ArcErrorInfo.ARC_ERROR_OK) {
if (outputImageList.isNotEmpty()) {
feedData(outputImageList[0].imageData)
}
}
}
}
} else {
......@@ -203,13 +226,13 @@ class MainActivity : AppCompatActivity() {
}
}
binding.stopAvm.setOnClickListener {
avmCoroutineScope.launch {
avmStartScope?.launch {
avmLeftCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA)
avmFrontCamera.stopPictureSequence(PictureSequenceSource.GENERAL_CAMERA)
avmRightCamera.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()
}
}
......
......@@ -72,17 +72,8 @@ val avmCoroutineScope by lazy {
AvmCoroutineScope(AvmCoroutineContext(engine = avmEngine) + Dispatchers.IO + COROUTINE_AVM)
}
class AvmCoroutineScope(context: CoroutineContext) : Closeable, CoroutineScope {
override val coroutineContext: CoroutineContext = context + avmJob
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()
}
class AvmCoroutineScope(context: CoroutineContext) : CoroutineScope {
override val coroutineContext: CoroutineContext = context
}
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(){
}
fun Context.closeAuxiliaryPresentation(){
multiScreenService?.dismissSecondPresentation()
unbindService(serviceConnection)
if (multiScreenService != null) {
multiScreenService?.dismissSecondPresentation()
unbindService(serviceConnection)
}
}
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