Skip to content

feat(IVideoDevice): add GetPreviewData method#5965

Merged
ArgoZhang merged 11 commits intomainfrom
feat-video
May 5, 2025
Merged

feat(IVideoDevice): add GetPreviewData method#5965
ArgoZhang merged 11 commits intomainfrom
feat-video

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 5, 2025

Link issues

fixes #5964

Summary By Copilot

This pull request introduces functionality to download captured video frames as image files, along with related updates to services, interfaces, and tests. The most important changes include adding a download button to the UI, implementing a method to retrieve image data from the video stream, and updating the JavaScript module and unit tests to support this feature.

UI Enhancements:

  • Added a new "Download" button to the video controls in VideoDevices.razor, allowing users to download captured frames as images. The button is disabled when no video is active (src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor).

Backend Service Updates:

  • Injected a new DownloadService into the VideoDevices component to handle file downloads (src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs).
  • Added a GetPreviewData method in the DefaultMediaDevices service to retrieve the image data as a stream (src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs).
  • Updated the IVideoDevice and IMediaDevices interfaces to include the new GetPreviewData method (src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs, src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs). [1] [2]

JavaScript Module Enhancements:

  • Added a getPreviewData function to the media.js module to retrieve the captured image blob for download (src/BootstrapBlazor/wwwroot/modules/media.js).
  • Updated error handling and streamlined logic in other functions for better robustness (src/BootstrapBlazor/wwwroot/modules/media.js). [1] [2] [3]

Unit Tests:

  • Extended the VideoDeviceTest unit tests to verify the new GetPreviewData functionality, ensuring that the data stream is correctly retrieved and validated (test/UnitTest/Services/VideoDeviceTest.cs). [1] [2]

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add functionality to download captured video frames as image files in the video device component

New Features:

  • Add GetPreviewData method to retrieve captured image data
  • Implement download button for captured video frames

Enhancements:

  • Improve error handling in device enumeration
  • Streamline JavaScript module logic for media devices

Tests:

  • Extend unit tests to verify new GetPreviewData functionality

@ArgoZhang ArgoZhang requested a review from Copilot May 5, 2025 07:28
@bb-auto bb-auto Bot added the enhancement New feature or request label May 5, 2025
@bb-auto bb-auto Bot added this to the v9.6.0 milestone May 5, 2025
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 5, 2025

Reviewer's Guide

This pull request introduces functionality to download captured video frames. It adds a GetPreviewData method to the video device interfaces and implementations, retrieving image data as a stream via JS interop from a new JavaScript function. A download button and corresponding handler were added to the UI component, utilizing a DownloadService to initiate the file download using the stream from GetPreviewData. Unit tests were updated to cover the new functionality.

Sequence diagram for downloading a captured video frame

sequenceDiagram
    actor User
    participant Razor as VideoDevices (Razor)
    participant CSharp as VideoDevices (C#)
    participant VDS as VideoDeviceService (IVideoDevice)
    participant DMD as DefaultMediaDevices (IMediaDevices)
    participant JSI as JS Interop
    participant JS as media.js
    participant DS as DownloadService

    User->>Razor: Click Download Button
    Razor->>CSharp: OnDownload()
    CSharp->>VDS: GetPreviewData()
    VDS->>DMD: GetPreviewData()
    DMD->>JSI: InvokeAsync("getPreviewData")
    JSI->>JS: getPreviewData()
    JS-->>JSI: Return previewBlob (as JSStreamReference)
    JSI-->>DMD: Return JSStreamReference
    DMD-->>VDS: Return Stream
    VDS-->>CSharp: Return Stream
    CSharp->>DS: DownloadFromStreamAsync("preview.png", stream)
    DS-->>User: Initiate file download
Loading

File-Level Changes

Change Details Files
Added backend logic to retrieve captured video frame data as a stream.
  • Defined GetPreviewData method in IVideoDevice and IMediaDevices interfaces.
  • Implemented GetPreviewData in DefaultMediaDevices using JS interop to call a new JavaScript function.
  • Implemented GetPreviewData in DefaultVideoDevice by delegating to the media devices service.
src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs
src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs
Added JavaScript function to provide captured frame data.
  • Stored the captured image blob in getPreviewUrl.
  • Created getPreviewData function to return the stored blob.
src/BootstrapBlazor/wwwroot/modules/media.js
Integrated download functionality into the UI component.
  • Added a 'Download' button to the Razor component.
  • Injected DownloadService.
  • Added OnDownload handler to fetch the preview data stream using VideoDeviceService.GetPreviewData and trigger download via DownloadService.
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs
Updated unit tests for the new download functionality.
  • Added JS interop setup for the getPreviewData call.
  • Added assertions to verify the stream returned by GetPreviewData.
test/UnitTest/Services/VideoDeviceTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#5964 Add a GetPreviewData method to the IVideoDevice interface and its implementations.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces a new GetPreviewData method to allow users to download captured video frames as image files, updating both backend and frontend components while extending test coverage.

  • Added a download button and OnDownload handler in the UI component.
  • Updated the video device and media services (both interfaces and implementations) to include GetPreviewData.
  • Enhanced the JavaScript module to support retrieval of preview data and adjusted unit tests accordingly.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/UnitTest/Services/VideoDeviceTest.cs Added unit tests for GetPreviewData functionality.
src/BootstrapBlazor/wwwroot/modules/media.js Modified functions to handle preview data retrieval and updated error handling.
src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs, IMediaDevices.cs Updated interfaces with the new GetPreviewData method.
src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs, DefaultMediaDevices.cs Implemented GetPreviewData method, delegating to the underlying device service and JS module.
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs, VideoDevices.razor Added download button and OnDownload handler to support the new feature.

Comment thread src/BootstrapBlazor/wwwroot/modules/media.js
Comment thread src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs
Co-Authored-By: pomeara <8163710+pomeara@users.noreply.github.com>
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes May 5, 2025
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • The GetPreviewData method relies on GetPreviewUrl having been called previously to store the image blob in JavaScript; consider making this dependency clearer or allowing GetPreviewData to capture the image independently if needed.
  • Consider disabling the download button until a preview image has actually been captured (e.g., _previewUrl is not null), not just when the video stream is open.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/BootstrapBlazor/wwwroot/modules/media.js
Comment thread test/UnitTest/Services/VideoDeviceTest.cs
Comment thread test/UnitTest/Services/VideoDeviceTest.cs
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (6a3df54) to head (171fd44).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5965   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          670       670           
  Lines        30576     30589   +13     
  Branches      4350      4351    +1     
=========================================
+ Hits         30576     30589   +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit b7e0afe into main May 5, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the feat-video branch May 5, 2025 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(IVideoDevice): add GetPreviewData method

2 participants