Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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,16 @@ interface CameraSystem {

suspend fun setCaptureMode(captureMode: CaptureMode)

/**
* Returns a list of supported MIME types for the given [lensFacing].
*
* This function queries the underlying camera hardware for its capabilities.
*
* @param lensFacing The camera lens to query.
* @return A list of supported MIME type strings (e.g., "image/jpeg", "video/mp4").
*/
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 @@ -37,6 +37,7 @@ import androidx.camera.lifecycle.ExperimentalCameraProviderConfiguration
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.lifecycle.awaitInstance
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 +1035,60 @@ constructor(
}
}

/**
* Returns a list of supported MIME types for the given [lensFacing].
*
* This function can be called before the camera is initialized. It will temporarily create a
* [ProcessCameraProvider] instance if one is not already available.
*
* @param lensFacing The camera lens to query for supported types.
* @return A list of MIME type strings. Returns an empty list if capabilities cannot be queried.
*/
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,11 @@ class FakeCameraSystem(defaultCameraSettings: CameraAppSettings = CameraAppSetti
old.copy(captureMode = captureMode)
}
}

/**
* Returns a fake list of supported MIME types.
*/
override suspend fun getSupportedMimeTypes(lensFacing: LensFacing): List<String> {
return listOf("image/jpeg", "video/mp4")
}
}
Loading