-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HDR capture support #86
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,15 @@ import android.content.ContentValues | |
import android.content.Context | ||
import android.os.Build | ||
import android.provider.MediaStore | ||
import android.util.Log | ||
import android.view.Display | ||
import android.widget.Toast | ||
import androidx.annotation.RequiresPermission | ||
import androidx.camera.core.AspectRatio | ||
import androidx.camera.core.Camera | ||
import androidx.camera.core.CameraSelector | ||
import androidx.camera.core.DisplayOrientedMeteringPointFactory | ||
import androidx.camera.core.DynamicRange | ||
import androidx.camera.core.FocusMeteringAction | ||
import androidx.camera.core.ImageCapture | ||
import androidx.camera.core.ImageCaptureException | ||
|
@@ -60,6 +62,8 @@ import javax.inject.Inject | |
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
private const val TAG = "CameraViewModel" | ||
|
||
@HiltViewModel | ||
class CameraViewModel @Inject constructor( | ||
@ApplicationContext private val application: Context, | ||
|
@@ -69,6 +73,7 @@ class CameraViewModel @Inject constructor( | |
) : ViewModel() { | ||
private lateinit var camera: Camera | ||
private lateinit var extensionsManager: ExtensionsManager | ||
private lateinit var videoCaptureUseCase: VideoCapture<Recorder> | ||
|
||
val chatId: Long? = savedStateHandle.get("chatId") | ||
var viewFinderState = MutableStateFlow(ViewFinderState()) | ||
|
@@ -93,12 +98,42 @@ class CameraViewModel @Inject constructor( | |
.setQualitySelector(QualitySelector.from(Quality.HIGHEST)) | ||
.build() | ||
|
||
private val videoCaptureUseCase = VideoCapture.Builder(recorder) | ||
.build() | ||
|
||
private var currentRecording: Recording? = null | ||
private lateinit var recordingState: VideoRecordEvent | ||
|
||
init { | ||
val videoCaptureBuilder = VideoCapture.Builder(recorder) | ||
|
||
viewModelScope.launch { | ||
val hdrCameraInfo = getHdrCameraInfo() | ||
|
||
if (hdrCameraInfo != null) { | ||
Log.i(TAG, "Capturing HDR video") | ||
videoCaptureBuilder.setDynamicRange(hdrCameraInfo) | ||
} | ||
|
||
videoCaptureUseCase = videoCaptureBuilder.build() | ||
} | ||
} | ||
|
||
private suspend fun getHdrCameraInfo(): DynamicRange? { | ||
var supportedHdrEncoding: DynamicRange? = null | ||
|
||
cameraProviderManager.getCameraProvider().availableCameraInfos | ||
.first { cameraInfo -> | ||
val videoCapabilities = Recorder.getVideoCapabilities(cameraInfo) | ||
val supportedDynamicRanges = | ||
videoCapabilities.supportedDynamicRanges | ||
|
||
supportedHdrEncoding = supportedDynamicRanges.firstOrNull { | ||
it != DynamicRange.SDR // Ensure an HDR encoding is found | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you directly check HDR, not SDR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to this, can we just check if it is HDR instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not sure, i copied the code snippet from https://android-developers.googleblog.com/2023/06/camerax-13-is-now-in-beta.html which has the snippet:
@donovanfm any idea why we are checking for NOT SDR instead of checking for HDR directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we actually make this more specific as well? There seem to be multiple different dynamic range profiles and to make it consistent, we should choose one we know they all support, which would be HLG 10-bit https://developer.android.com/reference/androidx/camera/core/DynamicRange Any device that supports HDR should support HLG 10-bit at a minimum There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
} | ||
return@first true | ||
} | ||
|
||
return supportedHdrEncoding | ||
} | ||
|
||
fun setChatId(chatId: Long) { | ||
savedStateHandle.set("chatId", chatId) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: any reason for the space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think just habit for personal preference for code readability, but removed