Skip to content

Commit

Permalink
applied suggestions. 05/04/2024
Browse files Browse the repository at this point in the history
suggestions applied

AssertPositiveNumberOrNil: macro to inline

formatted

.class to +class

Update packages/camera/camera_avfoundation/ios/Classes/FLTCamMediaSettings.m

Co-authored-by: Jenn Magder <[email protected]>

applied suggestions. 02/25/2024.

dependency injection (DI) variant for unit test

ObjC suggestions applied

suggestion applied

updated camera_platform_interface versions

reverted changes to camera

merged 01/07/2024

refactored and co0mmented warning suppressions. renamed MediaRecorderBuilder.RecordingParameters

merged 12/07/2023
  • Loading branch information
PROGrand committed Apr 5, 2024
1 parent cbd7eed commit adf6929
Show file tree
Hide file tree
Showing 49 changed files with 1,449 additions and 530 deletions.
2 changes: 1 addition & 1 deletion packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.11.0
## 0.10.9

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Camera
private int initialCameraFacing;

private final SurfaceTextureEntry flutterTexture;
private final Parameters parameters;
private final VideoCaptureSettings videoCaptureSettings;
private final Context applicationContext;
final DartMessenger dartMessenger;
private CameraProperties cameraProperties;
Expand Down Expand Up @@ -218,7 +218,7 @@ public Camera(
final CameraFeatureFactory cameraFeatureFactory,
final DartMessenger dartMessenger,
final CameraProperties cameraProperties,
final VideoCaptureSettings parameters) {
final VideoCaptureSettings videoCaptureSettings) {

if (activity == null) {
throw new IllegalStateException("No activity available!");
Expand All @@ -229,19 +229,19 @@ public Camera(
this.applicationContext = activity.getApplicationContext();
this.cameraProperties = cameraProperties;
this.cameraFeatureFactory = cameraFeatureFactory;
this.parameters = parameters;
this.videoCaptureSettings = videoCaptureSettings;
this.cameraFeatures =
CameraFeatures.init(
cameraFeatureFactory,
cameraProperties,
activity,
dartMessenger,
parameters.resolutionPreset);
videoCaptureSettings.resolutionPreset);

Integer recordingFps = null;

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

if (SdkCapabilityChecker.supportsEncoderProfiles()) {
Expand Down Expand Up @@ -313,25 +313,25 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
mediaRecorderBuilder =
new MediaRecorderBuilder(
getRecordingProfile(),
new MediaRecorderBuilder.Parameters(
new MediaRecorderBuilder.RecordingParameters(
outputFilePath,
parameters.fps,
parameters.videoBitrate,
parameters.audioBitrate));
videoCaptureSettings.fps,
videoCaptureSettings.videoBitrate,
videoCaptureSettings.audioBitrate));
} else {
mediaRecorderBuilder =
new MediaRecorderBuilder(
getRecordingProfileLegacy(),
new MediaRecorderBuilder.Parameters(
new MediaRecorderBuilder.RecordingParameters(
outputFilePath,
parameters.fps,
parameters.videoBitrate,
parameters.audioBitrate));
videoCaptureSettings.fps,
videoCaptureSettings.videoBitrate,
videoCaptureSettings.audioBitrate));
}

mediaRecorder =
mediaRecorderBuilder
.setEnableAudio(parameters.enableAudio)
.setEnableAudio(videoCaptureSettings.enableAudio)
.setMediaOrientation(
lockedOrientation == null
? getDeviceOrientationManager().getVideoOrientation()
Expand Down Expand Up @@ -1385,7 +1385,7 @@ public void setDescriptionWhileRecording(
cameraProperties,
activity,
dartMessenger,
parameters.resolutionPreset);
videoCaptureSettings.resolutionPreset);
cameraFeatures.setAutoFocus(
cameraFeatureFactory.createAutoFocusFeature(cameraProperties, true));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ private void instantiateCamera(MethodCall call, Result result) throws CameraAcce
new CameraFeatureFactoryImpl(),
dartMessenger,
cameraProperties,
new Camera.VideoCaptureSettings(resolutionPreset, enableAudio, fps, videoBitrate, audioBitrate));
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 @@ -20,17 +20,17 @@ MediaRecorder makeMediaRecorder() {
}
}

public static class Parameters {
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 Parameters(@NonNull String outputFilePath) {
public RecordingParameters(@NonNull String outputFilePath) {
this(outputFilePath, null, null, null);
}

public Parameters(
public RecordingParameters(
@NonNull String outputFilePath,
@Nullable Integer fps,
@Nullable Integer videoBitrate,
Expand All @@ -45,25 +45,25 @@ public Parameters(
private final CamcorderProfile camcorderProfile;
private final EncoderProfiles encoderProfiles;
private final MediaRecorderFactory recorderFactory;
@NonNull private final Parameters parameters;
@NonNull private final RecordingParameters parameters;

private boolean enableAudio;
private int mediaOrientation;

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

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

MediaRecorderBuilder(
@NonNull CamcorderProfile camcorderProfile,
MediaRecorderFactory helper,
@NonNull Parameters parameters) {
@NonNull RecordingParameters parameters) {
this.camcorderProfile = camcorderProfile;
this.encoderProfiles = null;
this.recorderFactory = helper;
Expand All @@ -73,7 +73,7 @@ public MediaRecorderBuilder(
MediaRecorderBuilder(
@NonNull EncoderProfiles encoderProfiles,
MediaRecorderFactory helper,
@NonNull Parameters parameters) {
@NonNull RecordingParameters parameters) {
this.encoderProfiles = encoderProfiles;
this.camcorderProfile = null;
this.recorderFactory = helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public class CameraTest {
private RangeConstruction mockRangeConstruction;

@Before
@SuppressWarnings("unchecked")
public void before() {

mockRangeConstruction = new RangeConstruction();
Expand All @@ -149,6 +148,9 @@ public void before() {
.when(() -> Camera.HandlerThreadFactory.create(any()))
.thenReturn(mockHandlerThread);

// Use a wildcard, since `new Range<Integer>[] {...}`
// results in a 'Generic array creation' error.
@SuppressWarnings("unchecked")
final Range<Integer>[] mockRanges =
(Range<Integer>[]) new Range<?>[] {new Range<Integer>(10, 20)};

Expand Down Expand Up @@ -192,7 +194,6 @@ public void shouldNotImplementLifecycleObserverInterface() {
}

@Test
@SuppressWarnings("unchecked")
public void shouldCreateCameraPluginAndSetAllFeatures() {
final Activity mockActivity = mock(Activity.class);
final TextureRegistry.SurfaceTextureEntry mockFlutterTexture =
Expand Down Expand Up @@ -1196,7 +1197,6 @@ public void close_doesNotCloseCaptureSessionWhenCameraDeviceNonNull() {
}

@Test
@SuppressWarnings({"unchecked", "try", "rawtypes"})
public void startVideoRecording_shouldApplySettingsToMediaRecorder()
throws InterruptedException, IOException, CameraAccessException {

Expand All @@ -1216,8 +1216,12 @@ public void startVideoRecording_shouldApplySettingsToMediaRecorder()
when(mockCameraProperties.getCameraName()).thenReturn(cameraName);

final Camera.VideoCaptureSettings parameters =
new Camera.VideoCaptureSettings(resolutionPreset, enableAudio, fps, videoBitrate, audioBitrate);
new Camera.VideoCaptureSettings(
resolutionPreset, enableAudio, fps, videoBitrate, audioBitrate);

// Use a wildcard, since `new Range<Integer>[] {...}`
// results in a 'Generic array creation' error.
@SuppressWarnings("unchecked")
final Range<Integer>[] mockRanges =
(Range<Integer>[]) new Range<?>[] {new Range<Integer>(10, 20)};

Expand All @@ -1230,6 +1234,9 @@ public void startVideoRecording_shouldApplySettingsToMediaRecorder()
try (final MockedStatic<File> mockFile = mockStatic(File.class);
final MockedConstruction<MediaRecorder> mockMediaRecorder =
Mockito.mockConstruction(MediaRecorder.class)) {

assertNotNull(mockMediaRecorder);

mockFile
.when(() -> File.createTempFile(any(), any(), any()))
.thenReturn(new File("/tmp/file.mp4"));
Expand Down Expand Up @@ -1280,7 +1287,10 @@ public void startVideoRecording_shouldApplySettingsToMediaRecorder()
(ResolutionFeature)
TestUtils.getPrivateField(mockCameraFeatureFactory, "mockResolutionFeature");

assertNotNull(cameraFlutterTexture);
when(cameraFlutterTexture.surfaceTexture()).thenReturn(mockSurfaceTexture);

assertNotNull(resolutionFeature);
when(resolutionFeature.getPreviewSize()).thenReturn(mockSize);

camera.startVideoRecording(mockResult, null);
Expand All @@ -1305,20 +1315,19 @@ public void startVideoRecording_shouldApplySettingsToMediaRecorder()
verify(recorder).setVideoEncodingBitRate(videoBitrate);
//endregion
}
}

@Test
public void pausePreview_doesNotCallStopRepeatingWhenCameraClosed() throws CameraAccessException
{
ArrayList<CaptureRequest.Builder> mockRequestBuilders = new ArrayList<>();
mockRequestBuilders.add(mock(CaptureRequest.Builder.class));
CameraDeviceWrapper fakeCamera = new FakeCameraDeviceWrapper(mockRequestBuilders);
TestUtils.setPrivateField(camera, "cameraDevice", fakeCamera);
@Test
public void pausePreview_doesNotCallStopRepeatingWhenCameraClosed() throws CameraAccessException {
ArrayList<CaptureRequest.Builder> mockRequestBuilders = new ArrayList<>();
mockRequestBuilders.add(mock(CaptureRequest.Builder.class));
CameraDeviceWrapper fakeCamera = new FakeCameraDeviceWrapper(mockRequestBuilders);
TestUtils.setPrivateField(camera, "cameraDevice", fakeCamera);

camera.close();
camera.pausePreview();
camera.close();
camera.pausePreview();

verify(mockCaptureSession, never()).stopRepeating();
}
verify(mockCaptureSession, never()).stopRepeating();
}

/// Allow to use `new android.util.Range(Integer, Integer)`
Expand All @@ -1329,7 +1338,7 @@ private static class RangeConstruction implements Closeable {
@SuppressWarnings({"rawtypes"})
final MockedConstruction<Range> rangeMockedConstruction;

@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings({"unchecked"})
public RangeConstruction() {
this.rangeMockedConstruction =
Mockito.mockConstruction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public void getRecordingProfileLegacy() {

CamcorderProfile actualRecordingProfile = camera.getRecordingProfileLegacy();

// First time: getRecordingProfileLegacy() is called in `before()` when
// camera constructor tries to determine default recording Fps.
// Second time: in this test case.
verify(mockResolutionFeature, times(2)).getRecordingProfileLegacy();
assertEquals(mockCamcorderProfile, actualRecordingProfile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ctor_testLegacy() {
MediaRecorderBuilder builder =
new MediaRecorderBuilder(
CamcorderProfile.get(CamcorderProfile.QUALITY_1080P),
new MediaRecorderBuilder.Parameters(""));
new MediaRecorderBuilder.RecordingParameters(""));

assertNotNull(builder);
}
Expand All @@ -44,7 +44,7 @@ public void ctor_test() {
MediaRecorderBuilder builder =
new MediaRecorderBuilder(
CamcorderProfile.getAll("0", CamcorderProfile.QUALITY_1080P),
new MediaRecorderBuilder.Parameters(""));
new MediaRecorderBuilder.RecordingParameters(""));

assertNotNull(builder);
}
Expand All @@ -56,7 +56,7 @@ public void ctor_testDefaultsLegacy() {
MediaRecorderBuilder builder =
new MediaRecorderBuilder(
CamcorderProfile.get(CamcorderProfile.QUALITY_1080P),
new MediaRecorderBuilder.Parameters(""));
new MediaRecorderBuilder.RecordingParameters(""));

assertNotNull(builder);
}
Expand All @@ -67,7 +67,7 @@ public void ctor_testDefaults() {
MediaRecorderBuilder builder =
new MediaRecorderBuilder(
CamcorderProfile.getAll("0", CamcorderProfile.QUALITY_1080P),
new MediaRecorderBuilder.Parameters(""));
new MediaRecorderBuilder.RecordingParameters(""));

assertNotNull(builder);
}
Expand All @@ -86,7 +86,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledLegacy() throw
new MediaRecorderBuilder(
recorderProfile,
mockFactory,
new MediaRecorderBuilder.Parameters(
new MediaRecorderBuilder.RecordingParameters(
outputFilePath, testFps, testVideoBitrate, null))
.setEnableAudio(false)
.setMediaOrientation(mediaOrientation);
Expand Down Expand Up @@ -126,7 +126,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOEx
new MediaRecorderBuilder(
recorderProfile,
mockFactory,
new MediaRecorderBuilder.Parameters(
new MediaRecorderBuilder.RecordingParameters(
outputFilePath, testFps, testVideoBitrate, null))
.setEnableAudio(false)
.setMediaOrientation(mediaOrientation);
Expand Down Expand Up @@ -162,7 +162,9 @@ public void build_shouldThrowExceptionWithoutVideoOrAudioProfiles() throws IOExc
int mediaOrientation = 1;
MediaRecorderBuilder builder =
new MediaRecorderBuilder(
recorderProfile, mockFactory, new MediaRecorderBuilder.Parameters(outputFilePath))
recorderProfile,
mockFactory,
new MediaRecorderBuilder.RecordingParameters(outputFilePath))
.setEnableAudio(false)
.setMediaOrientation(mediaOrientation);

Expand All @@ -185,7 +187,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledLegacy() throws
new MediaRecorderBuilder(
recorderProfile,
mockFactory,
new MediaRecorderBuilder.Parameters(
new MediaRecorderBuilder.RecordingParameters(
outputFilePath, testFps, testVideoBitrate, testAudioBitrate))
.setEnableAudio(true)
.setMediaOrientation(mediaOrientation);
Expand Down Expand Up @@ -229,7 +231,7 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOExc
new MediaRecorderBuilder(
recorderProfile,
mockFactory,
new MediaRecorderBuilder.Parameters(
new MediaRecorderBuilder.RecordingParameters(
outputFilePath, testFps, testVideoBitrate, testAudioBitrate))
.setEnableAudio(true)
.setMediaOrientation(mediaOrientation);
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
# When depending on this package from a real application you should use:
# camera_android: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin, so we use a path dependency on
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
camera_platform_interface: ^2.6.0
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22

version: 0.11.0
version: 0.10.9

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.6.0
## 0.5.1

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
# When depending on this package from a real application you should use:
# camera_android_camerax: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin, so we use a path dependency on
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
camera_platform_interface: ^2.6.0
Expand Down
Loading

0 comments on commit adf6929

Please sign in to comment.