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] Add API support query for image streaming #8250

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

liff
Copy link

@liff liff commented Dec 9, 2024

Add API support query, supportsImageStreaming for checking if the camera platform supports image streaming.

As requested on this comment: #8234 (comment)

Attempting to follow the contribution guide wrt. changing federated plugins.

There is no issue to link to, but should I create one?

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@@ -173,6 +173,11 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('resumeVideoRecording() is not implemented.');
}

/// Check whether this platform supports image streaming via [onStreamedFrameAvailable].
bool supportsImageStreaming() {
throw UnimplementedError('supportsImageStreaming() is not implemented.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should be false, not to throw, so that existing implementations that don't support it will automatically get the right behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@@ -661,6 +661,9 @@ class CameraPlugin extends CameraPlatform {
);
}

@override
bool supportsImageStreaming() => false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The web and Windows package changes won't be necessary once the base implementation is changed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed those changes.

/// The `startImageStream` method is only available on Android and iOS (other
/// platforms won't be supported in current setup).
/// The `startImageStream` method is only available on platforms that
/// report support for image streaming via [CameraPlatform.supportsImageStreaming].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be wrapped in a method at this layer; clients are not expected to use the platform interface directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a method.

Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android changes LGTM!

@liff
Copy link
Author

liff commented Dec 10, 2024

Android build is failing in Firebase Test Lab, but I don’t seem to have permission to view the results.

@camsim99
Copy link
Contributor

Android build is failing in Firebase Test Lab, but I don’t seem to have permission to view the results.

The Android image streaming test is failing:

java.lang.Exception: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following assertion was thrown running a test:
'package:camera/src/camera_controller.dart': Failed assertion:
line 488 pos 12: 'supportsImageStreaming()': is not true.

When the exception was thrown, this was the stack:
#2      CameraController.startImageStream (package:camera/src/camera_controller.dart:488:12)
#3      main.<anonymous closure> (file:///b/s/w/ir/x/w/packages/packages/camera/camera/example/integration_test/camera_test.dart:251:24)
<asynchronous suspension>
#4      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:189:15)
<asynchronous suspension>
#5      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1027:5)
<asynchronous suspension>
#6      TestWidgetsFlutterBinding._createTestCompletionHandler.<anonymous closure> (package:flutter_test/src/binding.dart:824:12)
<asynchronous suspension>
(elided 2 frames from class _AssertionError)

The test description was:
  Android image streaming
═════════════════════════════════════════════════════════════════

	at dev.flutter.plugins.integration_test.FlutterTestRunner.run(FlutterTestRunner.java:84)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2361)

@liff liff force-pushed the supportsImageStreaming branch 2 times, most recently from 2927697 to ead8c41 Compare December 10, 2024 19:40
@liff
Copy link
Author

liff commented Dec 11, 2024

I am unable to reproduce the failure locally with an emulator or with Firebase Test Lab.

I tried the integration tests with Firebase Test Lab both in camera/example and camera_android/example:

$ pushd android
$ ./gradlew app:assembleAndroidTest
$ ./gradlew app:assembleDebug -Ptarget=integration_test/camera_test.dart
$ popd
$ gcloud firebase test android run --type instrumentation --app build/app/outputs/apk/debug/app-debug.apk --test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk --timeout 7m --device model=panther,version=33

But I get successful results:

camera_android

┌─────────┬────────────────────────┬─────────────────────┐
│ OUTCOME │    TEST_AXIS_VALUE     │     TEST_DETAILS    │
├─────────┼────────────────────────┼─────────────────────┤
│ Passed  │ panther-33-en-portrait │ 9 test cases passed │
└─────────┴────────────────────────┴─────────────────────┘

camera

┌─────────┬────────────────────────┬─────────────────────┐
│ OUTCOME │    TEST_AXIS_VALUE     │     TEST_DETAILS    │
├─────────┼────────────────────────┼─────────────────────┤
│ Passed  │ panther-33-en-portrait │ 4 test cases passed │
└─────────┴────────────────────────┴─────────────────────┘

and similar results with the emulator, except for this:

Failed assertion: line 89 pos 16: '!(!previousPresetExactlySupported && presetExactlySupported)'

in the “Capture specific image resolutions” test.

Any ideas as to what’s going on?

@liff
Copy link
Author

liff commented Dec 11, 2024

Re-running the check seems to have solved the problem 🎉

@liff liff force-pushed the supportsImageStreaming branch from ead8c41 to 247846d Compare December 13, 2024 07:50
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API changes look good to me; this is ready to split out the first sub-PR for landing.

I left notes about missing tests, but those can be addressed in the sub PRs.

@@ -173,6 +173,9 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('resumeVideoRecording() is not implemented.');
}

/// Check whether this platform supports image streaming via [onStreamedFrameAvailable].
bool supportsImageStreaming() => false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a Dart unit test.

@@ -237,6 +237,9 @@ class AVFoundationCamera extends CameraPlatform {
await _hostApi.resumeVideoRecording();
}

@override
bool supportsImageStreaming() => true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a Dart unit test.

@@ -1152,6 +1152,9 @@ class AndroidCameraCameraX extends CameraPlatform {
}
}

@override
bool supportsImageStreaming() => true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a Dart unit test.

@@ -228,6 +228,9 @@ class AndroidCamera extends CameraPlatform {
Future<void> resumeVideoRecording(int cameraId) =>
_hostApi.resumeVideoRecording();

@override
bool supportsImageStreaming() => true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a Dart unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants