Skip to content

Commit

Permalink
throw error on submit if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Oct 14, 2024
1 parent f0b9aa3 commit 5428aac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion common/src/main/java/com/pedro/common/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import kotlin.coroutines.Continuation

/**
Expand Down Expand Up @@ -100,7 +101,10 @@ fun ExecutorService.secureSubmit(timeout: Long = 5000, code: () -> Unit) {
if (isTerminated || isShutdown) return
submit { code() }.get(timeout, TimeUnit.MILLISECONDS)
} catch (e: Exception) {
Log.e("ExecutorService", "secureSubmit Error", e)
when (e) {
is InterruptedException, is TimeoutException -> {}
else -> throw e
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,

override fun start() {
threadQueue.clear()
mainRender.release()
val executor = newSingleThreadExecutor(threadQueue)
executor.secureSubmit {
surfaceManager.release()
Expand All @@ -167,6 +166,7 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
surfaceManagerPhoto.release()
surfaceManagerEncoder.release()
surfaceManager.release()
mainRender.release()
}
executor?.shutdownNow()
executor = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ public void removeMediaCodecSurface() {
@Override
public void start() {
threadQueue.clear();
mainRender.release();
ExecutorService executor = ExtensionsKt.newSingleThreadExecutor(threadQueue);
ExtensionsKt.secureSubmit(executor, () -> {
surfaceManager.release();
Expand Down Expand Up @@ -338,6 +337,7 @@ public void stop() {
surfaceManagerPhoto.release();
surfaceManagerEncoder.release();
surfaceManager.release();
mainRender.release();
return null;
});
executor.shutdownNow();
Expand Down

0 comments on commit 5428aac

Please sign in to comment.