Skip to content
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

[camera] Camera with MediaSettings: platform implementations (federated) #5223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
224 commits
Select commit Hold shift + click to select a range
f294625
added MediaSettings
PROGrand Mar 29, 2023
5ca79b9
updated changelog
PROGrand Mar 29, 2023
e08e046
MediaSettings introduced.
PROGrand Mar 29, 2023
21617de
Merge branch 'flutter:main' into main
PROGrand Mar 29, 2023
59d66d3
excerpts added. formatted.
PROGrand Mar 29, 2023
aeec92e
versions and changelogs
PROGrand Mar 29, 2023
869b787
CameraPlatform.createCameraWithSettings
PROGrand Mar 29, 2023
3cf6030
Merge branch 'main' into main
PROGrand Mar 30, 2023
6ac763e
Merge branch 'flutter:main' into main
PROGrand Mar 30, 2023
a40177a
Update CHANGELOG.md
PROGrand Mar 30, 2023
fea1fc7
Update camera_test.dart
PROGrand Mar 30, 2023
9f71f8d
Update main.dart
PROGrand Mar 30, 2023
4a0ac77
MediaSettings.low removed
PROGrand Mar 30, 2023
8fcf1ae
media settings low
PROGrand Mar 30, 2023
da4ecd8
merger mediasettings
PROGrand Mar 30, 2023
16645ef
resolved multiple @hellohuanlin зкщзÑproposals
PROGrand Mar 30, 2023
d7dea54
fps control
PROGrand Mar 31, 2023
6caea7e
Fixed pausing preview on already paused or closed session.
PROGrand Mar 31, 2023
4bec8f3
Prevent pausing preview on uninitialized controller.
PROGrand Mar 31, 2023
11b43c1
Prevent pausing preview on disposed controller.
PROGrand Mar 31, 2023
772e011
Merge branch 'flutter:main' into main
PROGrand Mar 31, 2023
dbb752d
formatted
PROGrand Mar 31, 2023
7f01b93
Merge branch 'main' into main
PROGrand Apr 5, 2023
3506af1
Update packages/camera/camera_android/CHANGELOG.md
PROGrand Apr 26, 2023
8f95dc2
Update packages/camera/camera/CHANGELOG.md
PROGrand Apr 26, 2023
6b1f96c
bump gradle:7.20 in CHANGELOG
PROGrand Apr 26, 2023
6f97b51
commented feature properties
PROGrand Apr 26, 2023
d96f9d5
android_camera_camerax CHANGELOD update
PROGrand Apr 26, 2023
401adce
revert default enableAudio to false
PROGrand Apr 26, 2023
8edd212
properly commented IntFeature
PROGrand Apr 26, 2023
0a8fe17
clarify test constants
PROGrand Apr 26, 2023
d072dfb
pass logic to to _getTargetResolutionForPreview
PROGrand Apr 26, 2023
accef7c
versions fix
PROGrand Apr 26, 2023
480761c
Update packages/camera/camera_platform_interface/lib/src/types/media_…
PROGrand Apr 26, 2023
bdd74a8
Comments improved
PROGrand Apr 26, 2023
ec5856f
minor version increased.
PROGrand Apr 26, 2023
6736802
resolve upstream conflict
PROGrand Apr 26, 2023
9fdd1e0
Merge branch 'main' into main
PROGrand Apr 26, 2023
8a55d87
merged
PROGrand Jun 5, 2023
7d88b16
merge with camera: 0.10.5+2
PROGrand Jun 5, 2023
86c95e9
flutter 3.10.3 + analysis: error 'Found an extra analysis_options.yaml'
PROGrand Jun 5, 2023
c78cfc5
multiple analysis issues: const, await etc.
PROGrand Jun 5, 2023
5597838
expectLater for exceptions checking on async methods
PROGrand Jun 5, 2023
d006820
order of call and verify for mockito is important
PROGrand Jun 5, 2023
f60804d
ios tests passed
PROGrand Jun 5, 2023
d21dd5b
lint suppress
PROGrand Jun 5, 2023
b08f5f1
annotation imports
PROGrand Jun 5, 2023
d361800
mark IntFeature usages as NonNull
PROGrand Jun 5, 2023
a29b222
IntFeature NonNull
PROGrand Jun 5, 2023
1020ee7
import NonNull
PROGrand Jun 5, 2023
c31a502
NonNull
PROGrand Jun 5, 2023
dc0620e
Merge branch 'main' into main
PROGrand Jun 5, 2023
d185de2
Update CHANGELOG and Version
PROGrand Jun 5, 2023
a1fe134
interface version
PROGrand Jun 5, 2023
58aa61d
flutter_plugin_tools.dart make-deps-path-based
PROGrand Jun 5, 2023
ecae539
temporary publish_to: none
PROGrand Jun 5, 2023
2eb0657
temporary deps change: avoid The following unexpected non-local depen…
PROGrand Jun 5, 2023
a3f9c1d
deps order
PROGrand Jun 5, 2023
0d3d0a9
Merge branch 'main' into main
PROGrand Jun 5, 2023
076110f
mistype
PROGrand Jun 5, 2023
ce05518
args package changed.
PROGrand Jun 5, 2023
618a432
args changed: errorHandler
PROGrand Jun 5, 2023
e81dfee
args updated
PROGrand Jun 5, 2023
c95b6d5
bump dart version
PROGrand Jun 5, 2023
e392d1d
args: ^2.3.2
PROGrand Jun 5, 2023
72233fc
workaround args version
PROGrand Jun 5, 2023
0a81ffe
workaround args version
PROGrand Jun 5, 2023
8b0c6e8
merged
PROGrand Jun 5, 2023
dfe7b5a
dependency overrides
PROGrand Jun 6, 2023
277d4ae
Merge remote-tracking branch 'upstream/main'
PROGrand Jun 6, 2023
863f79a
examples deps
PROGrand Jun 6, 2023
3bdf221
examples deps
PROGrand Jun 6, 2023
6060603
packages deps
PROGrand Jun 6, 2023
ca7e7c6
publish_to: none removed
PROGrand Jun 6, 2023
5146a65
examples deps
PROGrand Jun 6, 2023
4e881fd
removed host deps
PROGrand Jun 6, 2023
4f07db2
camera deps
PROGrand Jun 6, 2023
a707e48
camera deps
PROGrand Jun 6, 2023
d50992d
camera deps
PROGrand Jun 6, 2023
fb99586
camera deps
PROGrand Jun 6, 2023
a0ca63a
around dependabot
PROGrand Jun 6, 2023
59186e6
merged
PROGrand Jun 21, 2023
0653456
changelogs updated
PROGrand Jun 21, 2023
0cb06da
MediaSettings export from camera/camera.dart
PROGrand Jun 21, 2023
2cc95af
camera/camera_controller.dart restored resolutionPreset and enableAudio
PROGrand Jun 21, 2023
22656de
Update packages/camera/camera/lib/src/camera_controller.dart
PROGrand Jun 21, 2023
1401590
Update packages/camera/camera_platform_interface/lib/src/types/media_…
PROGrand Jun 21, 2023
0ed67df
Update packages/camera/camera_platform_interface/lib/src/types/media_…
PROGrand Jun 21, 2023
c24d21e
Merge branch 'main' into main
PROGrand Jun 21, 2023
ff29e3f
version fix
PROGrand Jun 21, 2023
fdd75fd
Merge branch 'main' into main
PROGrand Jun 22, 2023
85a49f1
merged latest main 07/25/2023
PROGrand Jul 25, 2023
7088c8a
Object.hash
PROGrand Jul 25, 2023
85d6f20
bump gradle version moved to last entry changelog entry
PROGrand Jul 25, 2023
597dcc2
fixed format and analyzer issues
PROGrand Jul 25, 2023
c1bac8b
reverted merge for onStreamedFrameAvailable test
PROGrand Jul 25, 2023
8a90eee
Merge branch 'main' into main
PROGrand Jul 26, 2023
d7bc0be
camsim99 requests to remove gradle upgrade
PROGrand Aug 4, 2023
ea1777a
added safety checks for preview.
PROGrand Aug 4, 2023
e0ffa44
merged 08/04/2023
PROGrand Aug 4, 2023
f80e65f
Merge branch 'main' of github.com:mtbo-org/packages
PROGrand Aug 4, 2023
8e14f0d
version check
PROGrand Aug 4, 2023
aa4802e
merged
PROGrand Aug 14, 2023
ea9e49e
merged
PROGrand Aug 14, 2023
aa6cc8b
Update packages/camera/camera_android/CHANGELOG.md
PROGrand Aug 15, 2023
8d5a701
[file_selector] Fix default accept types on iOS (#4691)
stuartmorgan Aug 14, 2023
97abc1b
merged
PROGrand Aug 15, 2023
2d7ec3d
7.3.0
PROGrand Aug 15, 2023
def599e
7.4.2
PROGrand Aug 15, 2023
0b5d0ac
Merge branch 'main' into main
PROGrand Aug 15, 2023
d2dd528
merged with upstream/main (CHANGELOGs and package versions)
PROGrand Sep 4, 2023
14993b5
yaml: topics
PROGrand Sep 4, 2023
18be71c
touch
PROGrand Sep 4, 2023
b144466
Update packages/camera/camera_web/lib/src/camera.dart
PROGrand Sep 19, 2023
c7140d5
Update packages/camera/camera_web/lib/src/camera_service.dart
PROGrand Sep 19, 2023
81d3ba9
merged
PROGrand Sep 19, 2023
541b307
tested
PROGrand Sep 19, 2023
9776de3
analyzed
PROGrand Sep 19, 2023
a1bf2a0
audio bitrate constraints removed from test
PROGrand Sep 19, 2023
25e2241
Update packages/camera/camera_web/lib/src/camera_service.dart
PROGrand Sep 20, 2023
6fd3f07
Update packages/camera/camera_web/lib/src/camera.dart
PROGrand Sep 20, 2023
8204c5c
Merge branch 'main' into main
PROGrand Sep 20, 2023
ca0cc6b
applied suggestions
PROGrand Sep 20, 2023
cc6a0bd
Merge branch 'main' into main
PROGrand Sep 21, 2023
5cf735d
Merge branch 'main' into main
PROGrand Sep 22, 2023
59f3464
Merge branch 'main' into main
PROGrand Sep 24, 2023
5d0d68c
merged
PROGrand Sep 27, 2023
14ce07f
merged 09/30/2023
PROGrand Sep 30, 2023
d04448b
Merge branch 'main' into main
PROGrand Oct 2, 2023
835ce37
merged: camera_platform_interface
PROGrand Oct 24, 2023
70de8ff
Changing federated plugins: repeat 3 after camera_platform_interface …
PROGrand Oct 24, 2023
a5fd114
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 24, 2023
ea46393
change platform interface deps to hosted
PROGrand Oct 24, 2023
b7e7897
implement createCamera (with default settings)
PROGrand Oct 24, 2023
1e2d307
added attributes for fps, videoBitrate, audioBitrate properties.
PROGrand Oct 24, 2023
96dbf3e
surface the outError to dart side
PROGrand Oct 24, 2023
1b38cb0
formatted
PROGrand Oct 24, 2023
ae61ba3
do not log nil lockForConfiguration error
PROGrand Oct 24, 2023
196bba6
formatted
PROGrand Oct 24, 2023
c9d35b9
Update packages/camera/camera_web/lib/src/types/camera_options.dart
PROGrand Oct 25, 2023
71db82a
Update packages/camera/camera_web/pubspec.yaml
PROGrand Oct 25, 2023
177ee87
Update packages/camera/camera_web/CHANGELOG.md
PROGrand Oct 25, 2023
f532de4
createCamera using createCameraWithSettings
PROGrand Oct 25, 2023
23139b1
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 25, 2023
b35e972
fps -> FPS
PROGrand Oct 25, 2023
c1495bf
fixed comments for real application programmers
PROGrand Oct 25, 2023
c161ccc
* constants in `if` moved to right
PROGrand Oct 25, 2023
88f2edd
fps -> FPS
PROGrand Oct 25, 2023
7d30a8c
fps -> FPS
PROGrand Oct 25, 2023
8d442cb
* constants in `if` moved to right
PROGrand Oct 25, 2023
b17128e
fps -> FPS
PROGrand Oct 25, 2023
40d1b66
* constants in `if` moved to right
PROGrand Oct 25, 2023
f027d9f
* a local variable instead of force-unwrapping.
PROGrand Oct 25, 2023
c2e7f46
* an `enableAudio` default reverted to `false`
PROGrand Oct 25, 2023
71aff9f
* incremented the second version component (new functionality added)
PROGrand Oct 25, 2023
0ed0138
* reverted original changelog parts
PROGrand Oct 25, 2023
655d119
* reverted to original
PROGrand Oct 25, 2023
8a4c9db
* formatted
PROGrand Oct 25, 2023
1f9fdca
* removed bugfix
PROGrand Oct 25, 2023
1a81a80
* reverted to original
PROGrand Oct 25, 2023
35ae23f
* reverted to original
PROGrand Oct 25, 2023
3d96ee5
* reverted to original
PROGrand Oct 25, 2023
ab1f6d2
* reverted to original
PROGrand Oct 25, 2023
68cd07e
parameters becomes part of data class that groups settings (thx to @s…
PROGrand Oct 25, 2023
49db796
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 25, 2023
b944dc6
camera settings test
PROGrand Oct 26, 2023
b1d3280
merged
PROGrand Oct 26, 2023
1afac68
analyzed
PROGrand Oct 26, 2023
e7554e2
format
PROGrand Oct 26, 2023
207266c
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 27, 2023
48d4349
integration test for camera_android
PROGrand Oct 27, 2023
8be254d
Log.d -> Log.i, removed camerax settings integration test
PROGrand Oct 27, 2023
1e9cc5c
if (BuildConfig.DEBUG) { Log.d }
PROGrand Oct 27, 2023
299f2fd
if (BuildConfig.DEBUG) { Log.d }
PROGrand Oct 27, 2023
9c9aa18
if (BuildConfig.DEBUG) { Log.d }
PROGrand Oct 27, 2023
bdb5c9f
call order sync
PROGrand Oct 27, 2023
61518c2
camera settings native test
PROGrand Oct 28, 2023
67ac38e
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 28, 2023
73beede
removed camera_android IntFeature. tested
PROGrand Oct 28, 2023
6262758
camera_android cleanup.
PROGrand Oct 28, 2023
9ccb47f
change camera_web/example sdk requirements, according to camera_web r…
PROGrand Oct 29, 2023
a7e90f3
added camera_web bitrate test
PROGrand Oct 29, 2023
7a3eb16
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 29, 2023
93a54f7
camera_web tested.
PROGrand Oct 29, 2023
a0935d4
camera_avfoundation: withSettings tests
PROGrand Oct 30, 2023
4b633fd
test adopted
PROGrand Oct 30, 2023
4685bbf
Update CameraSettingsTests.m: license block
PROGrand Oct 30, 2023
b23d42b
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 30, 2023
3e9a3c4
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 31, 2023
4276560
check error in FLTCreateCamWithCaptureSessionQueue
PROGrand Oct 31, 2023
0cdaf73
check error in FLTCreateCamWithCaptureSessionQueue
PROGrand Oct 31, 2023
8899f59
testSampleBufferCallbackQueueMustBeCaptureSessionQueue assertions added
PROGrand Oct 31, 2023
80f4536
FLTCreateCamWithCaptureSessionQueueWithError added
PROGrand Oct 31, 2023
559b801
FLTCreateCamWithCaptureSessionQueueWithError added
PROGrand Oct 31, 2023
f7f6e13
FLTCreateCamWithCaptureSessionQueueWithError added
PROGrand Oct 31, 2023
391dd4d
queue errors
PROGrand Oct 31, 2023
a4602d0
CameraSettingsTest: expectations as local vars
PROGrand Oct 31, 2023
1ea063a
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 31, 2023
f428db4
check testCopyPixelBuffer error
PROGrand Oct 31, 2023
8b89d77
format
PROGrand Oct 31, 2023
b2cc958
disabled settings test
PROGrand Oct 31, 2023
4ea8e2a
stopMocking in settings test
PROGrand Oct 31, 2023
b91c82f
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 31, 2023
63c0ad4
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 31, 2023
29bd588
camera_avfoundation: tests
PROGrand Oct 31, 2023
4c1fda8
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Oct 31, 2023
21ae908
[tool] Add option for Android compile SDK version to update-dependenc…
camsim99 Oct 31, 2023
1aef8bd
merged upstream
PROGrand Nov 1, 2023
490f7e6
merged upstream
PROGrand Nov 1, 2023
d157eb1
cleanup
PROGrand Nov 1, 2023
24146c3
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Nov 1, 2023
f3ed1d3
camera android: integration tests - check lengths
PROGrand Nov 1, 2023
b8a17bc
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Nov 1, 2023
7dc6689
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Nov 2, 2023
5a89123
merged
PROGrand Nov 5, 2023
7972a19
Update packages/camera/camera/example/ios/Runner.xcodeproj/xcsharedda…
PROGrand Nov 13, 2023
bfface0
Update packages/camera/camera/example/pubspec.yaml
PROGrand Nov 13, 2023
e144df4
Update packages/camera/camera/example/ios/Runner.xcodeproj/project.pb…
PROGrand Nov 13, 2023
a00172b
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Nov 13, 2023
cbd7eed
merged 12/07/2023
PROGrand Dec 7, 2023
adf6929
applied suggestions. 05/04/2024
PROGrand Dec 7, 2023
864b2e1
Merge branch 'main' into camera-with-settings-platform-implementations
PROGrand Apr 5, 2024
30837eb
rebased, squashed, merged
PROGrand Apr 5, 2024
8b29fa0
suggestions applied
PROGrand Apr 5, 2024
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
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.9

* Adds support to control video FPS and bitrate. See `CameraController.withSettings`.

## 0.10.8+18

* Updates annotations lib to 1.7.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;
import android.util.Range;
import android.util.Size;
import android.view.Display;
import android.view.Surface;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.BuildConfig;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodChannel;
Expand All @@ -52,6 +54,7 @@
import io.flutter.plugins.camera.features.flash.FlashFeature;
import io.flutter.plugins.camera.features.flash.FlashMode;
import io.flutter.plugins.camera.features.focuspoint.FocusPointFeature;
import io.flutter.plugins.camera.features.fpsrange.FpsRangeFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
import io.flutter.plugins.camera.features.sensororientation.DeviceOrientationManager;
Expand Down Expand Up @@ -111,8 +114,7 @@ class Camera
private int initialCameraFacing;

private final SurfaceTextureEntry flutterTexture;
private final ResolutionPreset resolutionPreset;
private final boolean enableAudio;
private final VideoCaptureSettings videoCaptureSettings;
private final Context applicationContext;
final DartMessenger dartMessenger;
private CameraProperties cameraProperties;
Expand Down Expand Up @@ -185,29 +187,80 @@ public void close() {
}
}

public static class VideoCaptureSettings {
@NonNull public final ResolutionPreset resolutionPreset;
public final boolean enableAudio;
@Nullable public final Integer fps;
@Nullable public final Integer videoBitrate;
@Nullable public final Integer audioBitrate;

public VideoCaptureSettings(
@NonNull ResolutionPreset resolutionPreset,
boolean enableAudio,
@Nullable Integer fps,
@Nullable Integer videoBitrate,
@Nullable Integer audioBitrate) {
this.resolutionPreset = resolutionPreset;
this.enableAudio = enableAudio;
this.fps = fps;
this.videoBitrate = videoBitrate;
this.audioBitrate = audioBitrate;
}

public VideoCaptureSettings(@NonNull ResolutionPreset resolutionPreset, boolean enableAudio) {
this(resolutionPreset, enableAudio, null, null, null);
}
}

public Camera(
final Activity activity,
final SurfaceTextureEntry flutterTexture,
final CameraFeatureFactory cameraFeatureFactory,
final DartMessenger dartMessenger,
final CameraProperties cameraProperties,
final ResolutionPreset resolutionPreset,
final boolean enableAudio) {
final VideoCaptureSettings videoCaptureSettings) {

if (activity == null) {
throw new IllegalStateException("No activity available!");
}
this.activity = activity;
this.enableAudio = enableAudio;
this.flutterTexture = flutterTexture;
this.dartMessenger = dartMessenger;
this.applicationContext = activity.getApplicationContext();
this.cameraProperties = cameraProperties;
this.cameraFeatureFactory = cameraFeatureFactory;
this.resolutionPreset = resolutionPreset;
this.videoCaptureSettings = videoCaptureSettings;
this.cameraFeatures =
CameraFeatures.init(
cameraFeatureFactory, cameraProperties, activity, dartMessenger, resolutionPreset);
cameraFeatureFactory,
cameraProperties,
activity,
dartMessenger,
videoCaptureSettings.resolutionPreset);

Integer recordingFps = null;

if (videoCaptureSettings.fps != null && videoCaptureSettings.fps.intValue() > 0) {
recordingFps = videoCaptureSettings.fps;
} else {

if (SdkCapabilityChecker.supportsEncoderProfiles()) {
EncoderProfiles encoderProfiles = getRecordingProfile();
if (encoderProfiles != null && encoderProfiles.getVideoProfiles().size() > 0) {
recordingFps = encoderProfiles.getVideoProfiles().get(0).getFrameRate();
}
} else {
CamcorderProfile camcorderProfile = getRecordingProfileLegacy();
recordingFps = null != camcorderProfile ? camcorderProfile.videoFrameRate : null;
}
}

if (recordingFps != null && recordingFps.intValue() > 0) {

final FpsRangeFeature fpsRange = new FpsRangeFeature(cameraProperties);
fpsRange.setValue(new Range<Integer>(recordingFps, recordingFps));
this.cameraFeatures.setFpsRange(fpsRange);
}

// Create capture callback.
captureTimeouts = new CaptureTimeoutsWrapper(3000, 3000);
Expand Down Expand Up @@ -257,14 +310,28 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
// TODO(camsim99): Revert changes that allow legacy code to be used when recordingProfile is null
// once this has largely been fixed on the Android side. https://github.com/flutter/flutter/issues/119668
if (SdkCapabilityChecker.supportsEncoderProfiles() && getRecordingProfile() != null) {
mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfile(), outputFilePath);
mediaRecorderBuilder =
new MediaRecorderBuilder(
getRecordingProfile(),
new MediaRecorderBuilder.RecordingParameters(
outputFilePath,
videoCaptureSettings.fps,
videoCaptureSettings.videoBitrate,
videoCaptureSettings.audioBitrate));
} else {
mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfileLegacy(), outputFilePath);
mediaRecorderBuilder =
new MediaRecorderBuilder(
getRecordingProfileLegacy(),
new MediaRecorderBuilder.RecordingParameters(
outputFilePath,
videoCaptureSettings.fps,
videoCaptureSettings.videoBitrate,
videoCaptureSettings.audioBitrate));
}

mediaRecorder =
mediaRecorderBuilder
.setEnableAudio(enableAudio)
.setEnableAudio(videoCaptureSettings.enableAudio)
.setMediaOrientation(
lockedOrientation == null
? getDeviceOrientationManager().getVideoOrientation()
Expand Down Expand Up @@ -1314,7 +1381,11 @@ public void setDescriptionWhileRecording(
cameraProperties = properties;
cameraFeatures =
CameraFeatures.init(
cameraFeatureFactory, cameraProperties, activity, dartMessenger, resolutionPreset);
cameraFeatureFactory,
cameraProperties,
activity,
dartMessenger,
videoCaptureSettings.resolutionPreset);
cameraFeatures.setAutoFocus(
cameraFeatureFactory.createAutoFocusFeature(cameraProperties, true));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ private void instantiateCamera(MethodCall call, Result result) throws CameraAcce
String cameraName = call.argument("cameraName");
String preset = call.argument("resolutionPreset");
boolean enableAudio = call.argument("enableAudio");
Integer fps = call.argument("fps");
Integer videoBitrate = call.argument("videoBitrate");
Integer audioBitrate = call.argument("audioBitrate");

TextureRegistry.SurfaceTextureEntry flutterSurfaceTexture =
textureRegistry.createSurfaceTexture();
Expand All @@ -405,8 +408,8 @@ private void instantiateCamera(MethodCall call, Result result) throws CameraAcce
new CameraFeatureFactoryImpl(),
dartMessenger,
cameraProperties,
resolutionPreset,
enableAudio);
new Camera.VideoCaptureSettings(
resolutionPreset, enableAudio, fps, videoBitrate, audioBitrate));

Map<String, Object> reply = new HashMap<>();
reply.put("cameraId", flutterSurfaceTexture.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.media.EncoderProfiles;
import android.media.MediaRecorder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.plugins.camera.SdkCapabilityChecker;
import java.io.IOException;

Expand All @@ -19,42 +20,64 @@ MediaRecorder makeMediaRecorder() {
}
}

private final String outputFilePath;
public static class RecordingParameters {
@NonNull public final String outputFilePath;
@Nullable public final Integer fps;
@Nullable public final Integer videoBitrate;
@Nullable public final Integer audioBitrate;

public RecordingParameters(@NonNull String outputFilePath) {
this(outputFilePath, null, null, null);
}

public RecordingParameters(
@NonNull String outputFilePath,
@Nullable Integer fps,
@Nullable Integer videoBitrate,
@Nullable Integer audioBitrate) {
this.outputFilePath = outputFilePath;
this.fps = fps;
this.videoBitrate = videoBitrate;
this.audioBitrate = audioBitrate;
}
}

private final CamcorderProfile camcorderProfile;
private final EncoderProfiles encoderProfiles;
private final MediaRecorderFactory recorderFactory;
@NonNull private final RecordingParameters parameters;

private boolean enableAudio;
private int mediaOrientation;

public MediaRecorderBuilder(
@NonNull CamcorderProfile camcorderProfile, @NonNull String outputFilePath) {
this(camcorderProfile, outputFilePath, new MediaRecorderFactory());
@NonNull CamcorderProfile camcorderProfile, @NonNull RecordingParameters parameters) {
this(camcorderProfile, new MediaRecorderFactory(), parameters);
}

public MediaRecorderBuilder(
@NonNull EncoderProfiles encoderProfiles, @NonNull String outputFilePath) {
this(encoderProfiles, outputFilePath, new MediaRecorderFactory());
@NonNull EncoderProfiles encoderProfiles, @NonNull RecordingParameters parameters) {
this(encoderProfiles, new MediaRecorderFactory(), parameters);
}

MediaRecorderBuilder(
@NonNull CamcorderProfile camcorderProfile,
@NonNull String outputFilePath,
MediaRecorderFactory helper) {
this.outputFilePath = outputFilePath;
MediaRecorderFactory helper,
@NonNull RecordingParameters parameters) {
this.camcorderProfile = camcorderProfile;
this.encoderProfiles = null;
this.recorderFactory = helper;
this.parameters = parameters;
}

MediaRecorderBuilder(
@NonNull EncoderProfiles encoderProfiles,
@NonNull String outputFilePath,
MediaRecorderFactory helper) {
this.outputFilePath = outputFilePath;
MediaRecorderFactory helper,
@NonNull RecordingParameters parameters) {
this.encoderProfiles = encoderProfiles;
this.camcorderProfile = null;
this.recorderFactory = helper;
this.parameters = parameters;
}

@NonNull
Expand All @@ -79,34 +102,62 @@ public MediaRecorder build() throws IOException, NullPointerException, IndexOutO
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);

if (SdkCapabilityChecker.supportsEncoderProfiles() && encoderProfiles != null) {
mediaRecorder.setOutputFormat(encoderProfiles.getRecommendedFileFormat());

EncoderProfiles.VideoProfile videoProfile = encoderProfiles.getVideoProfiles().get(0);
EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0);

mediaRecorder.setOutputFormat(encoderProfiles.getRecommendedFileFormat());
if (enableAudio) {
EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0);

mediaRecorder.setAudioEncoder(audioProfile.getCodec());
mediaRecorder.setAudioEncodingBitRate(audioProfile.getBitrate());
mediaRecorder.setAudioEncodingBitRate(
(parameters.audioBitrate != null && parameters.audioBitrate.intValue() > 0)
? parameters.audioBitrate
: audioProfile.getBitrate());
mediaRecorder.setAudioSamplingRate(audioProfile.getSampleRate());
}

mediaRecorder.setVideoEncoder(videoProfile.getCodec());
mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate());
mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate());

int videoBitrate =
(parameters.videoBitrate != null && parameters.videoBitrate.intValue() > 0)
? parameters.videoBitrate
: videoProfile.getBitrate();

mediaRecorder.setVideoEncodingBitRate(videoBitrate);

int fps =
(parameters.fps != null && parameters.fps.intValue() > 0)
? parameters.fps
: videoProfile.getFrameRate();

mediaRecorder.setVideoFrameRate(fps);

mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight());
} else if (camcorderProfile != null) {
mediaRecorder.setOutputFormat(camcorderProfile.fileFormat);
if (enableAudio) {
mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec);
mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate);
mediaRecorder.setAudioEncodingBitRate(
(parameters.audioBitrate != null && parameters.audioBitrate.intValue() > 0)
? parameters.audioBitrate
: camcorderProfile.audioBitRate);
mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
}
mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec);
mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate);
mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
mediaRecorder.setVideoEncodingBitRate(
(parameters.videoBitrate != null && parameters.videoBitrate.intValue() > 0)
? parameters.videoBitrate
: camcorderProfile.videoBitRate);
mediaRecorder.setVideoFrameRate(
(parameters.fps != null && parameters.fps.intValue() > 0)
? parameters.fps
: camcorderProfile.videoFrameRate);
mediaRecorder.setVideoSize(
camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight);
}

mediaRecorder.setOutputFile(outputFilePath);
mediaRecorder.setOutputFile(parameters.outputFilePath);
mediaRecorder.setOrientationHint(this.mediaOrientation);

mediaRecorder.prepare();
Expand Down
Loading