Skip to content

Commit

Permalink
Cleanup PhotoOutputSynchronizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Aug 4, 2023
1 parent 8221fd2 commit bf059d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/com/mrousavy/camera/CameraSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class CameraSession(private val cameraManager: CameraManager,
val timestamp = result[CaptureResult.SENSOR_TIMESTAMP]!!
Log.i(TAG, "Photo capture 1/2 complete - received metadata with timestamp $timestamp")
try {
val image = photoOutputSynchronizer[timestamp].await()
val image = photoOutputSynchronizer.await(timestamp)
// TODO: Correctly get rotationDegrees and isMirrored
val rotation = ExifUtils.computeExifOrientation(0, false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import kotlinx.coroutines.CompletableDeferred
class PhotoOutputSynchronizer {
private val photoOutputQueue = HashMap<Long, CompletableDeferred<Image>>()

operator fun get(key: Long): CompletableDeferred<Image> {
private operator fun get(key: Long): CompletableDeferred<Image> {
if (!photoOutputQueue.containsKey(key)) {
photoOutputQueue[key] = CompletableDeferred()
}
return photoOutputQueue[key]!!
}

fun set(key: Long, image: Image) {
this[key].complete(image)
suspend fun await(timestamp: Long): Image {
val image = this[timestamp].await()
photoOutputQueue.remove(timestamp)
return image
}

fun set(timestamp: Long, image: Image) {
this[timestamp].complete(image)
}

fun clear() {
Expand Down

0 comments on commit bf059d3

Please sign in to comment.