Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ interface CameraSystem {

suspend fun setCaptureMode(captureMode: CaptureMode)

suspend fun getSupportedMimeTypes(lensFacing: LensFacing): List<String>

/**
* Represents the events required for screen flash.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import androidx.camera.core.takePicture
import androidx.camera.lifecycle.ExperimentalCameraProviderConfiguration
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.lifecycle.awaitInstance
import androidx.camera.video.Quality
import androidx.camera.video.Recorder
import androidx.concurrent.futures.await
import androidx.core.net.toFile
import com.google.jetpackcamera.core.camera.CameraCoreUtil.getAllCamerasPropertiesJSONArray
import com.google.jetpackcamera.core.camera.CameraCoreUtil.writeFileExternalStorage
Expand Down Expand Up @@ -1034,6 +1036,51 @@ constructor(
}
}

override suspend fun getSupportedMimeTypes(lensFacing: LensFacing): List<String> {
val localCameraProvider = if (::cameraProvider.isInitialized) {
cameraProvider
} else {
try {
ProcessCameraProvider.getInstance(application).await()
} catch (e: Exception) {
return emptyList()
}
}
val availableCameras = localCameraProvider.availableCameraInfos
if (availableCameras.isEmpty()) return emptyList()

val result = mutableListOf<String>()
val selector = lensFacing.toCameraSelector()
selector.filter(availableCameras).firstOrNull()?.let { camInfo ->
val imageCapabilities = ImageCapture.getImageCaptureCapabilities(camInfo)
val supportedImageFormats = imageCapabilities.supportedOutputFormats
val videoCapabilities = Recorder.getVideoCapabilities(camInfo)

for (supportedImageFormat in supportedImageFormats) {
when (supportedImageFormat) {
ImageCapture.OUTPUT_FORMAT_JPEG -> { result.add("image/jpeg")}
ImageCapture.OUTPUT_FORMAT_JPEG_ULTRA_HDR -> {
result.add("image/jpeg-ultrahdr")
}
}
}
if (videoCapabilities.getSupportedQualities(
DynamicRange.SDR.toCXDynamicRange()
).isNotEmpty()
) {
// If it supports any SDR quality (SD, HD, FHD, etc.), it can record standard AVC/MP4
result.add("video/mp4")
result.add("video/avc")
// If it supports HLG 10-bit HDR, CameraX will use HEVC (H.265) under the hood
if (videoCapabilities.supportedDynamicRanges.contains(
DynamicRange.HLG10.toCXDynamicRange())) {
result.add("video/hevc")
}
}
}
return result
}

private suspend fun handleLowLightBoostErrors() {
currentCameraState.map { it.lowLightBoostState }.distinctUntilChanged().collect { state ->
if (state is LowLightBoostState.Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ class FakeCameraSystem(defaultCameraSettings: CameraAppSettings = CameraAppSetti
old.copy(captureMode = captureMode)
}
}

override suspend fun getSupportedMimeTypes(lensFacing: LensFacing): List<String> {
return listOf("image/jpeg", "video/mp4")
}
}
Loading