Sunshine master
Self-hosted game stream host for Moonlight.
nv12_zero_device.h
Go to the documentation of this file.
1
5#pragma once
6
7// local includes
9
10struct AVFrame;
11
12namespace platf {
18 void free_frame(AVFrame *frame);
19
24 // display holds a pointer to an av_video object. Since the namespaces of AVFoundation
25 // and FFMPEG collide, we need this opaque pointer and cannot use the definition
26 void *display;
27
28 public:
29 // this function is used to set the resolution on an av_video object that we cannot
30 // call directly because of namespace collisions between AVFoundation and FFMPEG
34 using resolution_fn_t = std::function<void(void *display, int width, int height)>;
39 using pixel_format_fn_t = std::function<void(void *display, int pixelFormat)>;
40
50 int init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, const pixel_format_fn_t &pixel_format_fn);
51
58 int convert(img_t &img) override;
66 int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override;
67
68 private:
70 };
71
72} // namespace platf
macOS zero-copy encode device that forwards NV12 frames from AVFoundation to FFmpeg.
Definition nv12_zero_device.h:23
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.
Definition nv12_zero_device.cpp:67
std::function< void(void *display, int pixelFormat)> pixel_format_fn_t
Callback signature used to update the opaque AVFoundation pixel format.
Definition nv12_zero_device.h:39
std::function< void(void *display, int width, int height)> resolution_fn_t
Callback signature used to update the opaque AVFoundation display resolution.
Definition nv12_zero_device.h:34
int convert(img_t &img) override
Forward a captured AVFoundation frame to FFmpeg without copying.
Definition nv12_zero_device.cpp:38
int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override
Attach frame resources used by the next conversion or encode operation.
Definition nv12_zero_device.cpp:57
resolution_fn_t resolution_fn
Callback stored for later AVFoundation resolution updates.
Definition nv12_zero_device.h:35
Unique pointer wrapper with customizable pointer and deleter types.
Definition utility.h:820
Declarations for common platform specific utilities.
pix_fmt_e
Enumerates supported pix fmt options.
Definition common.h:316
void free_frame(AVFrame *frame)
Release an FFmpeg frame allocated by the capture or conversion backend.
Definition graphics.cpp:1403
AVCodec-backed encode device and frame state.
Definition common.h:566
AVFrame * frame
FFmpeg frame currently owned by the encode device.
Definition common.h:568
Captured frame buffer shared between capture and encode stages.
Definition common.h:502