Skip to content

[camera_web] Re: Support for camera stream on web#7950

Open
TecHaxter wants to merge 74 commits into
flutter:mainfrom
TecHaxter:camera_web_stream
Open

[camera_web] Re: Support for camera stream on web#7950
TecHaxter wants to merge 74 commits into
flutter:mainfrom
TecHaxter:camera_web_stream

Conversation

@TecHaxter
Copy link
Copy Markdown

This PR aims to provide support for strartImageStream and stopImageStream on Web.

#92460

Based on #6944 from the archived plugins repository

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

POV: my first PR on a public repo
Contains required commits from the PR #6443, resolves unnecessary 202 commits

@TecHaxter
Copy link
Copy Markdown
Author

Demo

Dummy example app source code

2026-04-03.19-47-24.mp4

@mdebbar mdebbar added the CICD Run CI/CD label Apr 3, 2026
@mdebbar mdebbar requested review from ditman and removed request for ditman April 6, 2026 17:13
@mdebbar mdebbar added CICD Run CI/CD and removed CICD Run CI/CD labels Apr 6, 2026
@mdebbar
Copy link
Copy Markdown
Contributor

mdebbar commented Apr 7, 2026

Some lints have been reported here: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8685251527310718641/+/u/Run_package_tests/analyze/stdout

@mdebbar mdebbar dismissed ditman’s stale review April 7, 2026 17:29

Many changes have been done since this review.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 8, 2026
Comment on lines +51 to +53
({int? audioBitrate, int? videoBitrate})? recorderOptions,
}) : recorderOptions =
recorderOptions ?? (audioBitrate: null, videoBitrate: null),
Copy link
Copy Markdown
Author

@TecHaxter TecHaxter Apr 8, 2026

Choose a reason for hiding this comment

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

Why this change?

  • mockito walks the constructor and inspects parameter defaults.
  • For a const record literal, it goes through source_gen constant revival (reviveInstance).
  • That code path of the current version of the dependency does not handle record constants properly.
  • As a result, it hits a null and throws Null check operator used on a null value.

@mdebbar mdebbar added the CICD Run CI/CD label Apr 9, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 11, 2026
@TecHaxter
Copy link
Copy Markdown
Author

Ready for review

@stuartmorgan-g stuartmorgan-g requested a review from mdebbar April 13, 2026 15:21
@bparrishMines bparrishMines removed their request for review April 14, 2026 17:41
@mdebbar mdebbar added the CICD Run CI/CD label Apr 17, 2026
Copy link
Copy Markdown
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

This is very cool! I don't work on this nowadays, but here's some extra comments:

Anyway, very cool. Thanks for reviving this!

// package:camera_platform_interface.
// https://github.com/flutter/flutter/issues/176148
/// Used for running the camera frame stream at a specified FPS
final int cameraStreamFPS = 60;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this @visibleForTesting?

Also I think we should let the user know that this FPS is a maximum cap in the framerate, but not a guarantee. (Web devs should already know this, but maybe this is surprising for a mobile developer compiling for web)

final num elapsed = timestamp - lastFrameTimestamp;

// If we're close to the next frame (~`_frameTimeToleranceMs`), do it.
if (fpsInterval - elapsed <= _frameTimeToleranceMs) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh! So it is NOT a maximum cap on FPS. Does this mean that at 60fps we can trigger a new frame 8ms early?

as web.OffscreenCanvasRenderingContext2D;

_offscreenCanvasContext!.drawImage(videoElement, 0, 0);
imageData = _offscreenCanvasContext!.getImageData(0, 0, width, height);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please split the behavior of taking an offscreen frame vs the fallback into two smaller methods? _takeOffscreenCanvasFrame and _takeFallbackCanvasFrame (both return imageData). That way the takeFrame method becomes smaller?

final ByteBuffer byteBuffer = imageData.data.toDart.buffer;

return CameraImageData(
format: const CameraImageFormat(ImageFormatGroup.unknown, raw: 0),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to extend the ImageFormatGroup to better describe what the browser is capturing here?

(There's also settings for getImageData that may be used here to capture frames in a "less unknown" format, maybe?)

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

Labels

CICD Run CI/CD p: camera platform-web triage-web Should be looked at in web triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants