Skip to content

fix: Add handling for missing VideoFormat on Linux #169

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

meocoder31099
Copy link

@meocoder31099 meocoder31099 commented Aug 4, 2025

In the current code, VideoFormat::RGBA is included in the list of output formats for the buffer

pw::spa::pod::property!(
FormatProperties::VideoFormat,
Choice,
Enum,
Id,
pw::spa::param::video::VideoFormat::RGB,
pw::spa::param::video::VideoFormat::RGBA,
pw::spa::param::video::VideoFormat::RGBx,
pw::spa::param::video::VideoFormat::BGRx,
),

but the case where VideoFormat is VideoFormat::RGBA is not handled
if let Err(e) = match user_data.format.format() {
VideoFormat::RGBx => user_data.tx.send(Frame::RGBx(RGBxFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
VideoFormat::RGB => user_data.tx.send(Frame::RGB(RGBFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
VideoFormat::xBGR => user_data.tx.send(Frame::XBGR(XBGRFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
VideoFormat::BGRx => user_data.tx.send(Frame::BGRx(BGRxFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
_ => panic!("Unsupported frame format received"),
} {
eprintln!("{e}");
}

This PR will fix it.

Summary by CodeRabbit

  • New Features
    • Added support for processing and transmitting video frames in the RGBA format on Linux systems.

Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

The process_callback function in the Linux engine module was updated to recognize and handle the VideoFormat::RGBA frame format. When an RGBA frame is received, it is now packaged as a Frame::RGBx variant and sent through the established channel, aligning its handling with other supported video formats.

Changes

Cohort / File(s) Change Summary
Linux Engine Video Format Handling
src/capturer/engine/linux/mod.rs
Added support for the VideoFormat::RGBA format in process_callback, sending it as Frame::RGBx.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

Hopping through code with a pixel parade,
Now RGBA frames join the masquerade.
With every new format, the engine grows bright,
Colors and channels all handled just right.
A rabbit’s delight in this rainbow array—
More formats to capture, more reasons to play! 🐇🎨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9a6214 and 6e4f793.

📒 Files selected for processing (1)
  • src/capturer/engine/linux/mod.rs (1 hunks)

Comment on lines +161 to +166
VideoFormat::RGBA => user_data.tx.send(Frame::RGBx(RGBxFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider adding a dedicated Frame::RGBA variant for semantic clarity.

The fix correctly addresses the missing handling for VideoFormat::RGBA and follows the established pattern. However, mapping RGBA frames to Frame::RGBx might be semantically confusing since RGBA includes meaningful alpha channel data while RGBx typically has undefined alpha values.

Consider these alternatives:

  1. Add a dedicated Frame::RGBA variant in the frame module
  2. If Frame::RGBx is intended to handle both RGBx and RGBA formats, consider renaming it to be more generic

Verify that downstream frame processing code can handle RGBA data correctly when it receives Frame::RGBx frames that actually contain alpha channel information.


🏁 Script executed:

#!/bin/bash
# Description: Check if Frame enum has RGBA variant and how RGBx frames are processed downstream

# Check Frame enum definition
ast-grep --pattern 'enum Frame {
  $$$
}'

# Check how Frame::RGBx is processed in the codebase
rg -A 10 "Frame::RGBx" --type rust

Length of output: 2362


#!/bin/bash
set -e

echo "### linux mod imports ###"
sed -n '1,50p' src/capturer/engine/linux/mod.rs

echo
echo "### VideoFrame enum ###"
rg -A 20 "enum VideoFrame" --type rust

echo
echo "### Frame alias ###"
rg "type Frame" -A 5 --type rust

echo
echo "### RGBxFrame struct ###"
rg -A 10 "struct RGBxFrame" --type rust

echo
echo "### RGBAFrame struct ###"
rg -A 10 "struct RGBAFrame" --type rust


🏁 Script executed:

#!/bin/bash
set -e

echo "### Imports in src/capturer/engine/linux/mod.rs ###"
sed -n '1,50p' src/capturer/engine/linux/mod.rs || echo "File not found"

echo
echo "### Searching for 'enum Frame' definitions ###"
rg -n "enum Frame" --type rust || echo "enum Frame not found"

echo
echo "### Searching for 'type Frame' alias ###"
rg -n "type Frame" --type rust || echo "type Frame alias not found"

echo
echo "### Searching for 'struct RGBxFrame' ###"
rg -n "struct RGBxFrame" --type rust || echo "RGBxFrame struct not found"

echo
echo "### Searching for 'struct RGBAFrame' ###"
rg -n "struct RGBAFrame" --type rust || echo "RGBAFrame struct not found"

Length of output: 2189


🏁 Script executed:

#!/bin/bash
set -e

echo "### Displaying Frame enum in src/frame/mod.rs ###"
sed -n '1,200p' src/frame/mod.rs

Length of output: 275


🏁 Script executed:

#!/bin/bash
set -e

echo "### Displaying src/frame/video.rs ###"
sed -n '1,200p' src/frame/video.rs || echo "src/frame/video.rs not found"

Length of output: 4357


Implement dedicated RGBA frame variant for clarity

The current change handles the missing VideoFormat::RGBA case, but mapping true RGBA frames into the RGBx variant conflates two distinct formats. RGBA carries a meaningful alpha channel, while RGBx implies a padded or ignored fourth byte. To avoid downstream confusion, we should:

  • Define a new RGBAFrame struct and corresponding VideoFrame::RGBA(RGBAFrame) variant in src/frame/video.rs.
  • Update the match arm in src/capturer/engine/linux/mod.rs to emit Frame::Video(VideoFrame::RGBA(...)) instead of Frame::RGBx.
  • If alpha really isn’t used downstream, explicitly strip it (e.g. via remove_alpha_channel) and map to RGB or RGBx, making the drop deliberate.

Suggested diffs:

// src/frame/video.rs
 use std::time::SystemTime;
 
+#[derive(Debug, Clone)]
+pub struct RGBAFrame {
+    pub display_time: SystemTime,
+    pub width: i32,
+    pub height: i32,
+    pub data: Vec<u8>, // Red, Green, Blue, Alpha
+}

 #[derive(Debug, Clone)]
 pub enum VideoFrame {
     YUVFrame(YUVFrame),
     RGB(RGBFrame),
     RGBx(RGBxFrame),
     XBGR(XBGRFrame),
     BGRx(BGRxFrame),
     BGR0(BGRFrame),
     BGRA(BGRAFrame),
+    RGBA(RGBAFrame),
 }
// src/capturer/engine/linux/mod.rs
 match video_info.format {
     VideoFormat::RGBA => user_data.tx.send(
-        Frame::RGBx(RGBxFrame { 
+        Frame::Video(VideoFrame::RGBA(RGBAFrame {
             display_time: timestamp as u64,
             width: frame_size.width as i32,
             height: frame_size.height as i32,
             data: frame_data,
-        }))
+        })),
     ),
     _ => panic!("Unsupported frame format received"),
 }

If alpha is guaranteed unused, explicitly drop it:

let rgb_data = remove_alpha_channel(frame_data);
user_data.tx.send(Frame::Video(VideoFrame::RGB(RGBFrame {
    display_time: timestamp as u64,
    width: frame_size.width as i32,
    height: frame_size.height as i32,
    data: rgb_data,
})))?;

This preserves clear semantics around alpha handling and keeps downstream frame consumers unambiguous.

🤖 Prompt for AI Agents
In src/capturer/engine/linux/mod.rs around lines 161 to 166, the code
incorrectly maps VideoFormat::RGBA frames to the RGBx variant, which conflates
distinct formats and can cause confusion about alpha channel usage. To fix this,
define a new RGBAFrame struct and add a corresponding VideoFrame::RGBA variant
in src/frame/video.rs. Then update the match arm in
src/capturer/engine/linux/mod.rs to send Frame::Video(VideoFrame::RGBA(...))
with the RGBAFrame data. If the alpha channel is not used downstream, explicitly
remove it before mapping to RGB or RGBx to make the alpha drop deliberate and
clear.

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.

1 participant