Skip to content

Support Image Frame Streaming and flutter v3.32.7 - #69

Open
faisalramdan17 wants to merge 1 commit into
alexey-pelykh:mainfrom
faisalramdan17:main
Open

Support Image Frame Streaming and flutter v3.32.7#69
faisalramdan17 wants to merge 1 commit into
alexey-pelykh:mainfrom
faisalramdan17:main

Conversation

@faisalramdan17

Copy link
Copy Markdown

No description provided.

@alexey-pelykh
alexey-pelykh requested a review from Copilot July 21, 2025 04:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds image frame streaming functionality to the UVCCamera Flutter plugin and updates the version to 0.0.13. It enables real-time access to raw camera frame data for image processing, analysis, or other use cases while maintaining the existing camera preview and recording features.

  • Introduces UvcCameraFrameEvent class for representing frame data with metadata
  • Adds streaming API methods startImageStream() and stopImageStream() to UvcCameraController
  • Implements native Android support using EventChannel for frame data transmission

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
flutter/pubspec.yaml Version bump from snapshot to 0.0.13
flutter/lib/uvccamera.dart Export new UvcCameraFrameEvent class
flutter/lib/src/uvccamera_frame_event.dart New frame event model with image data and metadata
flutter/lib/src/uvccamera_platform_interface.dart Platform interface methods for frame streaming
flutter/lib/src/uvccamera_platform.dart Platform implementation for frame event channels
flutter/lib/src/uvccamera_controller_state.dart Add isStreamingImages state tracking
flutter/lib/src/uvccamera_controller.dart Frame streaming API and lifecycle management
flutter/example/lib/uvccamera_widget.dart Example integration with streaming controls
flutter/example/lib/uvccamera_image_stream_demo.dart Complete demo showcasing frame streaming
flutter/example/lib/uvccamera_device_screen.dart Navigation to streaming demo
flutter/android/src/main/java/org/uvccamera/flutter/*.java Native Android implementation

_onImageAvailable = onImageAvailable;

// Start native frame streaming
await UvcCameraPlatformInterface.instance.attachToCameraFrameCallback(_cameraId!);

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

The frame callback is attached twice - once during initialization (line 83) and again in startImageStream() (line 265). This creates duplicate event channels and potential resource leaks. Consider removing the attachment during initialization since streaming should be opt-in.

Suggested change
await UvcCameraPlatformInterface.instance.attachToCameraFrameCallback(_cameraId!);
// Line 83 removed to prevent redundant callback attachment during initialization.

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +71
frameEvent.put("width", 640); // Default width - should be configurable
frameEvent.put("height", 480); // Default height - should be configurable

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

Hardcoded width and height values (640x480) will not match actual camera resolution. These should be retrieved from the camera's actual configuration or passed as parameters to ensure frame metadata accuracy.

Suggested change
frameEvent.put("width", 640); // Default width - should be configurable
frameEvent.put("height", 480); // Default height - should be configurable
frameEvent.put("width", width); // Use dynamic width
frameEvent.put("height", height); // Use dynamic height

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +71
frameEvent.put("width", 640); // Default width - should be configurable
frameEvent.put("height", 480); // Default height - should be configurable

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

Hardcoded width and height values (640x480) will not match actual camera resolution. These should be retrieved from the camera's actual configuration or passed as parameters to ensure frame metadata accuracy.

Suggested change
frameEvent.put("width", 640); // Default width - should be configurable
frameEvent.put("height", 480); // Default height - should be configurable
frameEvent.put("width", width); // Use actual width
frameEvent.put("height", height); // Use actual height

Copilot uses AI. Check for mistakes.
frameEvent.put("width", 640); // Default width - should be configurable
frameEvent.put("height", 480); // Default height - should be configurable
frameEvent.put("timestamp", System.currentTimeMillis());
frameEvent.put("format", "yuv420"); // Default format - should be determined from actual format

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded format 'yuv420' may not reflect the actual pixel format being used. This should be determined from the actual UVCCamera configuration or passed as a parameter to ensure accurate format reporting.

Suggested change
frameEvent.put("format", "yuv420"); // Default format - should be determined from actual format
frameEvent.put("format", pixelFormat); // Use dynamically determined format

Copilot uses AI. Check for mistakes.

try {
// Stop native frame streaming
await UvcCameraPlatformInterface.instance.detachFromCameraFrameCallback(_cameraId!);

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

This detachment may fail if the frame callback was never properly attached due to the duplicate attachment issue. The detachment should be more defensive and handle cases where the callback wasn't attached.

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +137
// _frameEventSubscription = _cameraController!.cameraFrameEvents.listen((event) {
// log('frame: ${event.imageData.length}');
// setState(() {
// _log = 'frame: ${event.imageData.length}\n$_log';
// });
// });

Copilot AI Jul 21, 2025

Copy link

Choose a reason for hiding this comment

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

Commented-out code should be removed rather than left in the production codebase. This reduces clutter and potential confusion for future developers.

Suggested change
// _frameEventSubscription = _cameraController!.cameraFrameEvents.listen((event) {
// log('frame: ${event.imageData.length}');
// setState(() {
// _log = 'frame: ${event.imageData.length}\n$_log';
// });
// });

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants