Sunshine master
Self-hosted game stream host for Moonlight.
platf::nv12_zero_device Class Reference

macOS zero-copy encode device that forwards NV12 frames from AVFoundation to FFmpeg. More...

#include <src/platform/macos/nv12_zero_device.h>

Inheritance diagram for platf::nv12_zero_device:
[legend]
Collaboration diagram for platf::nv12_zero_device:
[legend]

Public Types

using pixel_format_fn_t = std::function<void(void *display, int pixelFormat)>
 Callback signature used to update the opaque AVFoundation pixel format.
 
using resolution_fn_t = std::function<void(void *display, int width, int height)>
 Callback signature used to update the opaque AVFoundation display resolution.
 

Public Member Functions

int convert (img_t &img) override
 Forward a captured AVFoundation frame to FFmpeg without copying.
 
int init (void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, const pixel_format_fn_t &pixel_format_fn)
 Initialize zero-copy NV12 encoding for an AVFoundation display.
 
int set_frame (AVFrame *frame, AVBufferRef *hw_frames_ctx) override
 Attach frame resources used by the next conversion or encode operation.
 
- Public Member Functions inherited from platf::avcodec_encode_device_t
virtual void apply_colorspace ()
 Apply the configured colorspace metadata to the active frame.
 
virtual void init_codec_options (AVCodecContext *ctx, AVDictionary **options)
 Provides a hook for allow platform-specific code to adjust codec options.
 
virtual void init_hwframes (AVHWFramesContext *frames)
 Initialize the hwframes context.
 
virtual int prepare_to_derive_context (int hw_device_type)
 Prepare to derive a context.
 
- Public Member Functions inherited from platf::encode_device_t

Public Attributes

resolution_fn_t resolution_fn
 Callback stored for later AVFoundation resolution updates.
 
- Public Attributes inherited from platf::avcodec_encode_device_t
void * data {}
 Backend-specific conversion state.
 
AVFrame * frame {}
 FFmpeg frame currently owned by the encode device.
 
- Public Attributes inherited from platf::encode_device_t
video::sunshine_colorspace_t colorspace
 Colorspace metadata expected by the encoder.
 

Detailed Description

macOS zero-copy encode device that forwards NV12 frames from AVFoundation to FFmpeg.

Member Function Documentation

◆ convert()

int platf::nv12_zero_device::convert ( platf::img_t & img)
overridevirtual

Forward a captured AVFoundation frame to FFmpeg without copying.

Parameters
imgImage or frame object to read from or populate.
Returns
Conversion status.

Reimplemented from platf::avcodec_encode_device_t.

◆ init()

int platf::nv12_zero_device::init ( void * display,
pix_fmt_e pix_fmt,
resolution_fn_t resolution_fn,
const pixel_format_fn_t & pixel_format_fn )

Initialize zero-copy NV12 encoding for an AVFoundation display.

Parameters
displayDisplay object or identifier associated with the operation.
pix_fmtSunshine pixel format to convert or allocate for.
resolution_fnCallback used to resize the AVFoundation capture output.
pixel_format_fnPixel format.
Returns
0 on success; nonzero or negative platform status on failure.

◆ set_frame()

int platf::nv12_zero_device::set_frame ( AVFrame * frame,
AVBufferRef * hw_frames_ctx )
overridevirtual

Attach frame resources used by the next conversion or encode operation.

Parameters
frameVideo or graphics frame being processed.
hw_frames_ctxFFmpeg hardware frames context associated with the frame.
Returns
Status from updating frame.

Reimplemented from platf::avcodec_encode_device_t.


The documentation for this class was generated from the following files: