-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera_web] Re: Support for camera stream on web #7950
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
base: main
Are you sure you want to change the base?
Changes from all commits
2552bdc
72a7127
d366566
4a18e22
b12f7e7
8697046
b42fbb9
b7b9342
8ec3a04
622841c
096ac4d
ed6f086
d1244a0
d891a36
7dfb194
b9111cb
f80cb03
41ac242
3edea8c
d1e4d95
86da719
dcf48f9
7e01244
6d20e38
f56879e
1e7c869
5b10bce
90bb72e
b196180
5c1c662
f484f02
98bceb7
bf9c3fe
f183b04
22cad65
380c35b
e31fbf2
cc818ba
a04a472
aa9a819
5941119
3756949
74bb74e
54aa92e
e46ef6f
5e7bb5e
c48418b
a0cd373
d7b7d5c
6cd955a
a959df5
526160b
98af1e3
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import 'dart:async'; | ||
import 'dart:js_interop'; | ||
import 'dart:js_interop_unsafe'; | ||
import 'dart:typed_data'; | ||
import 'dart:ui'; | ||
|
||
import 'package:async/async.dart'; | ||
|
@@ -61,6 +62,10 @@ void main() { | |
cameraId: any(named: 'cameraId'), | ||
), | ||
).thenAnswer((_) => Future<MediaStream>.value(mediaStream)); | ||
|
||
when( | ||
() => cameraService.hasPropertyOffScreenCanvas(), | ||
).thenAnswer((_) => true); | ||
Comment on lines
+66
to
+68
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. Same comment as above, we need a test where offscreen canvas is available, and one where it isn't, so we test both code paths. 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. This is fixed, can be marked as resolved? |
||
}); | ||
|
||
setUpAll(() { | ||
|
@@ -1704,5 +1709,107 @@ void main() { | |
}); | ||
}); | ||
}); | ||
group('cameraFrameStream', () { | ||
testWidgets( | ||
'CameraImageData bytes is a multiple of 4 ' | ||
'when browser supports OffscreenCanvas', | ||
(WidgetTester tester) async { | ||
final VideoElement videoElement = getVideoElementWithBlankStream( | ||
const Size(10, 10), | ||
); | ||
|
||
final Camera camera = Camera( | ||
textureId: textureId, | ||
cameraService: cameraService, | ||
)..videoElement = videoElement; | ||
|
||
when(() => cameraService.hasPropertyOffScreenCanvas()).thenReturn( | ||
true, | ||
); | ||
|
||
when( | ||
() => cameraService.takeFrame(videoElement), | ||
).thenAnswer( | ||
(_) => CameraImageData( | ||
format: const CameraImageFormat( | ||
ImageFormatGroup.unknown, | ||
raw: 0, | ||
), | ||
planes: <CameraImagePlane>[ | ||
CameraImagePlane( | ||
bytes: Uint8List(32), | ||
bytesPerRow: videoElement.width * 4, | ||
), | ||
], | ||
height: 10, | ||
width: 10, | ||
), | ||
); | ||
|
||
final CameraImageData cameraImageData = | ||
await camera.cameraFrameStream().first; | ||
expect( | ||
cameraImageData, | ||
equals( | ||
isA<CameraImageData>().having( | ||
(CameraImageData e) => e.planes.first.bytes.length % 4, | ||
'bytes', | ||
equals(0), | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
testWidgets( | ||
'CameraImageData bytes is a multiple of 4 ' | ||
'when browser does not supports OffscreenCanvas', | ||
(WidgetTester tester) async { | ||
final VideoElement videoElement = getVideoElementWithBlankStream( | ||
const Size(10, 10), | ||
); | ||
|
||
final Camera camera = Camera( | ||
textureId: textureId, | ||
cameraService: cameraService, | ||
)..videoElement = videoElement; | ||
|
||
when(() => cameraService.hasPropertyOffScreenCanvas()).thenReturn( | ||
false, | ||
); | ||
|
||
when( | ||
() => cameraService.takeFrame(videoElement), | ||
).thenAnswer( | ||
(_) => CameraImageData( | ||
format: const CameraImageFormat( | ||
ImageFormatGroup.unknown, | ||
raw: 0, | ||
), | ||
planes: <CameraImagePlane>[ | ||
CameraImagePlane( | ||
bytes: Uint8List(32), | ||
bytesPerRow: videoElement.width * 4, | ||
), | ||
], | ||
height: 10, | ||
width: 10, | ||
), | ||
); | ||
|
||
final CameraImageData cameraImageData = | ||
await camera.cameraFrameStream().first; | ||
expect( | ||
cameraImageData, | ||
equals( | ||
isA<CameraImageData>().having( | ||
(CameraImageData e) => e.planes.first.bytes.length % 4, | ||
'bytes', | ||
equals(0), | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,10 @@ void main() { | |
(_) async => videoElement.captureStream(), | ||
); | ||
|
||
when( | ||
() => cameraService.hasPropertyOffScreenCanvas(), | ||
).thenAnswer((_) => true); | ||
Comment on lines
+103
to
+105
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. This shouldn't be needed. 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 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. Can we mark this resolved? |
||
|
||
CameraPlatform.instance = CameraPlugin( | ||
cameraService: cameraService, | ||
)..window = window; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to mock this? The code should be running on Chrome, which AFAIK has an offscreen canvas. What happens to this test if we revert this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
cameraService
is a mock class object itself.If we don't stub
hasPropertyOffScreenCanvas
, it throws an error - "TypeError: null: type 'Null' is not a subtype of type 'bool'There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we mark this resolved?