Skip to content

Feature: OSX Supported Screen Capture Source + Encoding Builder #11

Open
ash30 wants to merge 1 commit into
bitwhip:masterfrom
ash30:osx_screen_capture_source
Open

Feature: OSX Supported Screen Capture Source + Encoding Builder #11
ash30 wants to merge 1 commit into
bitwhip:masterfrom
ash30:osx_screen_capture_source

Conversation

@ash30

@ash30 ash30 commented Jul 31, 2025

Copy link
Copy Markdown

This change is as small as I can make it, so I'll try and break it down

1. CLI options to choose the source of screen capture source, device and frame rate.

Usage: bitwhip stream [OPTIONS] <URL> [TOKEN]

Arguments:
  <URL>    The WHIP URL
  [TOKEN]  The WHIP bearer token

Options:
  -c <CAPTURE_METHOD>          Capture method [default: av-foundation] [possible values: av-foundation, dxgi]
  -f, --framerate <FRAMERATE>  Target frames per second for capture device [default: 60]
  -d, --device <DEVICE>        Device(s) to capture, source specific
  -v...                        Increase log verbosity, multiple occurrences (-vvv) further increase
  -h, --help

2. Add AVFoundation based screen capture 'source'

3. Add Encoder Builder

  • the logic now needs to fork based on platform + source, I felt the builder pattern could help tame the complexity.
  • Example code:
let encoder = EncoderBuilder::new()
            .for_source(&mut source)
            .customise(move |encoder| {
                encoder.set_frame_rate(Some(frame_rate));
                encoder.set_time_base(frame_rate.invert());
                encoder.set_gop(120);
                encoder.set_max_b_frames(0);
            })
            .open()?;
  • the for_source method sets options based on captured frame ( dimensions, formats etc )
  • we keep a similar configuration closure as previous impl to set other fields. In future, these could all be exposed via cli args ( is my thinking)

4. Small Change to the Source trait

  • we allow the frame to be passed as ref for better reuse
  • hw_support allow source to dictate encoder builder logic around hw frames
pub trait Source {
    fn next_frame(&mut self, out: &mut frame::Video) -> Result<(), Error>;
    fn hw_support(&self) -> bool {
        false
    }

@ash30 ash30 changed the title Feat: OSX Supported Screen Capture Source + Encoding Builder Feature: OSX Supported Screen Capture Source + Encoding Builder Jul 31, 2025

@ghost ghost 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.

I don't know how to make a pull request on your fork, so this is the best I can do for suggesting something. lol

Comment thread src/main.rs
pub enum CaptureMethod {
AVFoundation,
DXGI,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I added a NoCaptureMethod to this enum.

Comment thread src/main.rs
return CaptureMethod::DXGI;
#[cfg(target_os = "macos")]
return CaptureMethod::AVFoundation;
panic!("unsupported platform")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Then I added
#[cfg(target_os = "linux")]
return CaptureMethod::NoCaptureMethod;

Comment thread src/main.rs
CaptureMethod::AVFoundation => _stream(AFScreenCapturer::new(&config)?, &config),
#[cfg(target_os = "windows")]
CaptureMethod::DXGI => _stream(DisplayDuplicator::new()?, &config),
_ => Err(anyhow!("unsupported on this platform"))?,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Then finally I just added
CaptureMethod::NoCaptureMethod => panic!("unsupported capture_method for platform"),
for it to stop if for some reason, a use is trying to record their screen on linux.

Adding all those parts let me watch streams again on linux.

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