Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Add fix attempt
  • Loading branch information
camsim99 committed Jul 18, 2023
commit 6af128268efde8b5630f044d478bc8c845c6d885
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,6 @@ class AndroidCameraCameraX extends CameraPlatform {
/// Configures the [imageAnalysis] instance for image streaming and binds it
/// to camera lifecycle controlled by the [processCameraProvider].
Future<void> _configureAndBindImageAnalysisToLifecycle() async {
if (imageAnalysis != null &&
await processCameraProvider!.isBound(imageAnalysis!)) {
// imageAnalysis already configured and bound to lifecycle.
return;
}

// Create Analyzer that can read image data for image streaming.
final WeakReference<AndroidCameraCameraX> weakThis =
WeakReference<AndroidCameraCameraX>(this);
Expand Down Expand Up @@ -648,9 +642,14 @@ class AndroidCameraCameraX extends CameraPlatform {

// TODO(camsim99): Support resolution configuration.
// Defaults to YUV_420_888 image format.
imageAnalysis = createImageAnalysis(null);
imageAnalysis ??= createImageAnalysis(null);
unawaited(imageAnalysis!.setAnalyzer(analyzer));

if (await processCameraProvider!.isBound(imageAnalysis!)) {
// No need to bind imageAnalysis to lifecycle again.
return;
}

// TODO(camsim99): Reset live camera state observers here when
// https://github.com/flutter/packages/pull/3419 lands.
camera = await processCameraProvider!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,47 @@ void main() {
});

test(
'onStreamedFrameAvaiable returns stream that responds expectedly to being listened to',
'onStreamedFrameAvailable emits CameraImageData when listened to after cancelation',
() async {
final FakeAndroidCameraCameraX camera =
FakeAndroidCameraCameraX(shouldCreateDetachedObjectForTesting: true);
final MockProcessCameraProvider mockProcessCameraProvider =
MockProcessCameraProvider();
final MockCamera mockCamera = MockCamera();
const int cameraId = 22;

camera.processCameraProvider = mockProcessCameraProvider;
camera.cameraSelector = MockCameraSelector();

when(mockProcessCameraProvider.bindToLifecycle(any, any))
.thenAnswer((_) => Future<Camera>.value(mockCamera));
when(mockCamera.getCameraInfo())
.thenAnswer((_) => Future<CameraInfo>.value(MockCameraInfo()));

final CameraImageData mockCameraImageData = MockCameraImageData();
final Stream<CameraImageData> imageStream =
camera.onStreamedFrameAvailable(cameraId);

// Listen to image stream.
final StreamSubscription<CameraImageData> imageStreamSubscription =
imageStream.listen((CameraImageData data) {});

// Cancel subscription to image stream.
await imageStreamSubscription.cancel();
final Stream<CameraImageData> imageStream2 =
camera.onStreamedFrameAvailable(cameraId);

// Listen to image stream again.
final StreamQueue<CameraImageData> streamQueue =
StreamQueue<CameraImageData>(imageStream2);
camera.cameraImageDataStreamController!.add(mockCameraImageData);

expect(await streamQueue.next, equals(mockCameraImageData));
await streamQueue.cancel();
});

test(
'onStreamedFrameAvailable returns stream that responds expectedly to being listened to',
() async {
final FakeAndroidCameraCameraX camera =
FakeAndroidCameraCameraX(shouldCreateDetachedObjectForTesting: true);
Expand Down Expand Up @@ -1011,7 +1051,7 @@ void main() {
});

test(
'onStreamedFrameAvaiable returns stream that responds expectedly to being canceled',
'onStreamedFrameAvailable returns stream that responds expectedly to being canceled',
() async {
final FakeAndroidCameraCameraX camera =
FakeAndroidCameraCameraX(shouldCreateDetachedObjectForTesting: true);
Expand Down