-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera] Fix: use legacy profiles when list is empty #6867
Changes from all commits
ff484f9
5c15870
6480493
80887eb
bdd7e6a
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 |
|---|---|---|
|
|
@@ -114,19 +114,22 @@ static Size computeBestPreviewSize(int cameraId, ResolutionPreset preset) | |
| if (preset.ordinal() > ResolutionPreset.high.ordinal()) { | ||
| preset = ResolutionPreset.high; | ||
| } | ||
|
|
||
| if (Build.VERSION.SDK_INT >= 31) { | ||
| EncoderProfiles profile = | ||
| getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); | ||
| getBestAvailableCamcorderProfileForResolutionPreset(cameraId, preset); | ||
| List<EncoderProfiles.VideoProfile> videoProfiles = profile.getVideoProfiles(); | ||
| EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); | ||
|
|
||
| return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); | ||
| } else { | ||
| @SuppressWarnings("deprecation") | ||
| CamcorderProfile profile = | ||
| getBestAvailableCamcorderProfileForResolutionPresetLegacy(cameraId, preset); | ||
| return new Size(profile.videoFrameWidth, profile.videoFrameHeight); | ||
| if (defaultVideoProfile != null) { | ||
| return new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| CamcorderProfile profile = | ||
| getBestAvailableCamcorderProfileForResolutionPresetLegacy(cameraId, preset); | ||
| return new Size(profile.videoFrameWidth, profile.videoFrameHeight); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -235,20 +238,25 @@ private void configureResolution(ResolutionPreset resolutionPreset, int cameraId | |
| return; | ||
| } | ||
|
|
||
| captureSize = null; | ||
|
|
||
| if (Build.VERSION.SDK_INT >= 31) { | ||
| recordingProfile = | ||
| getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); | ||
| getBestAvailableCamcorderProfileForResolutionPreset(cameraId, resolutionPreset); | ||
| List<EncoderProfiles.VideoProfile> videoProfiles = recordingProfile.getVideoProfiles(); | ||
|
|
||
| EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0); | ||
| captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); | ||
| } else { | ||
| if (defaultVideoProfile != null) { | ||
| captureSize = new Size(defaultVideoProfile.getWidth(), defaultVideoProfile.getHeight()); | ||
| } | ||
| } | ||
|
|
||
| if (captureSize == null) { | ||
|
Contributor
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. As a follow up to the comment I left below with regards to constructing |
||
| @SuppressWarnings("deprecation") | ||
| CamcorderProfile camcorderProfile = | ||
| getBestAvailableCamcorderProfileForResolutionPresetLegacy(cameraId, resolutionPreset); | ||
| getBestAvailableCamcorderProfileForResolutionPresetLegacy(cameraId, resolutionPreset); | ||
| recordingProfileLegacy = camcorderProfile; | ||
| captureSize = | ||
| new Size(recordingProfileLegacy.videoFrameWidth, recordingProfileLegacy.videoFrameHeight); | ||
| captureSize = new Size(recordingProfileLegacy.videoFrameWidth, recordingProfileLegacy.videoFrameHeight); | ||
| } | ||
|
|
||
| previewSize = computeBestPreviewSize(cameraId, resolutionPreset); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -75,33 +75,48 @@ public MediaRecorder build() throws IOException, NullPointerException, IndexOutO | |||||||||||
| if (enableAudio) mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); | ||||||||||||
| mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); | ||||||||||||
|
|
||||||||||||
| if (Build.VERSION.SDK_INT >= 31) { | ||||||||||||
| boolean isFormatNeedSetup = true; | ||||||||||||
| boolean isAudioNeedSetup = enableAudio; | ||||||||||||
| boolean isVideoNeedSetup = true; | ||||||||||||
|
|
||||||||||||
| if (Build.VERSION.SDK_INT >= 31 && encoderProfiles != null) { | ||||||||||||
|
Contributor
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. The changes here seem to suggest that there may be a case where one of Thus, you could add a check here for In order for that to work (and I think the code you have here, as well, since one of plugins/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java Lines 261 to 265 in 0a0e3d2
Contributor
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 left a comment above in |
||||||||||||
| EncoderProfiles.VideoProfile videoProfile = encoderProfiles.getVideoProfiles().get(0); | ||||||||||||
| EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0); | ||||||||||||
|
|
||||||||||||
| mediaRecorder.setOutputFormat(encoderProfiles.getRecommendedFileFormat()); | ||||||||||||
| if (enableAudio) { | ||||||||||||
| isFormatNeedSetup = false; | ||||||||||||
|
|
||||||||||||
| if (isAudioNeedSetup && audioProfile != null) { | ||||||||||||
| mediaRecorder.setAudioEncoder(audioProfile.getCodec()); | ||||||||||||
| mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate()); | ||||||||||||
| mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate()); | ||||||||||||
| isAudioNeedSetup = false; | ||||||||||||
| } | ||||||||||||
| mediaRecorder.setVideoEncoder(videoProfile.getCodec()); | ||||||||||||
| mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); | ||||||||||||
| mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); | ||||||||||||
| mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); | ||||||||||||
| mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); | ||||||||||||
| } else { | ||||||||||||
| mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); | ||||||||||||
| if (enableAudio) { | ||||||||||||
| mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec); | ||||||||||||
| mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate); | ||||||||||||
| mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate); | ||||||||||||
| if (videoProfile != null) { | ||||||||||||
| mediaRecorder.setVideoEncoder(videoProfile.getCodec()); | ||||||||||||
| mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate()); | ||||||||||||
| mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate()); | ||||||||||||
| mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); | ||||||||||||
| mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight()); | ||||||||||||
| isVideoNeedSetup = false; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (isFormatNeedSetup && camcorderProfile != null) { | ||||||||||||
| mediaRecorder.setOutputFormat(camcorderProfile.fileFormat); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (isAudioNeedSetup && camcorderProfile != null) { | ||||||||||||
| mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec); | ||||||||||||
| mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate); | ||||||||||||
| mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (isVideoNeedSetup && camcorderProfile != null) { | ||||||||||||
| mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec); | ||||||||||||
| mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate); | ||||||||||||
| mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate); | ||||||||||||
| mediaRecorder.setVideoSize( | ||||||||||||
| camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); | ||||||||||||
| mediaRecorder.setVideoSize(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| mediaRecorder.setOutputFile(outputFilePath); | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.