docs(doxygen): enforce warn if undocumented (#5337)
This commit is contained in:
@@ -14,7 +14,14 @@ extern "C" {
|
||||
#include <va/va.h>
|
||||
#include <va/va_drm.h>
|
||||
#if !VA_CHECK_VERSION(1, 9, 0)
|
||||
// vaSyncBuffer stub allows Sunshine built against libva <2.9.0 to link against ffmpeg on libva 2.9.0 or later
|
||||
/**
|
||||
* @brief Stub vaSyncBuffer when building against libva before 2.9.0.
|
||||
*
|
||||
* @param dpy VA display.
|
||||
* @param buf_id VA buffer ID.
|
||||
* @param timeout_ns Sync timeout in nanoseconds.
|
||||
* @return VA status code.
|
||||
*/
|
||||
VAStatus
|
||||
vaSyncBuffer(
|
||||
VADisplay dpy,
|
||||
@@ -25,7 +32,15 @@ extern "C" {
|
||||
}
|
||||
#endif
|
||||
#if !VA_CHECK_VERSION(1, 21, 0)
|
||||
// vaMapBuffer2 stub allows Sunshine built against libva <2.21.0 to link against ffmpeg on libva 2.21.0 or later
|
||||
/**
|
||||
* @brief Stub vaMapBuffer2 when building against libva before 2.21.0.
|
||||
*
|
||||
* @param dpy VA display.
|
||||
* @param buf_id VA buffer ID.
|
||||
* @param pbuf Output mapped buffer pointer.
|
||||
* @param flags Mapping flags.
|
||||
* @return VA status code.
|
||||
*/
|
||||
VAStatus
|
||||
vaMapBuffer2(
|
||||
VADisplay dpy,
|
||||
@@ -52,24 +67,39 @@ using namespace std::literals;
|
||||
extern "C" struct AVBufferRef;
|
||||
|
||||
namespace va {
|
||||
constexpr auto SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 = 0x40000000;
|
||||
constexpr auto EXPORT_SURFACE_WRITE_ONLY = 0x0002;
|
||||
constexpr auto EXPORT_SURFACE_SEPARATE_LAYERS = 0x0004;
|
||||
constexpr auto SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 = 0x40000000; ///< Protocol or platform constant for surface attrib mem type drm prime 2.
|
||||
constexpr auto EXPORT_SURFACE_WRITE_ONLY = 0x0002; ///< GameStream port offset for export surface write only.
|
||||
constexpr auto EXPORT_SURFACE_SEPARATE_LAYERS = 0x0004; ///< GameStream port offset for export surface separate layers.
|
||||
|
||||
/**
|
||||
* @brief Native VA display handle.
|
||||
*/
|
||||
using VADisplay = void *;
|
||||
/**
|
||||
* @brief Status code returned by VAAPI functions.
|
||||
*/
|
||||
using VAStatus = int;
|
||||
/**
|
||||
* @brief Generic numeric VAAPI object identifier.
|
||||
*/
|
||||
using VAGenericID = unsigned int;
|
||||
/**
|
||||
* @brief VAAPI surface identifier.
|
||||
*/
|
||||
using VASurfaceID = VAGenericID;
|
||||
|
||||
/**
|
||||
* @brief DRM PRIME descriptor imported from a VAAPI surface.
|
||||
*/
|
||||
struct DRMPRIMESurfaceDescriptor {
|
||||
// VA Pixel format fourcc of the whole surface (VA_FOURCC_*).
|
||||
uint32_t fourcc;
|
||||
uint32_t fourcc; ///< VA fourcc pixel format for the imported surface.
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t width; ///< Surface width in pixels.
|
||||
uint32_t height; ///< Surface height in pixels.
|
||||
|
||||
// Number of distinct DRM objects making up the surface.
|
||||
uint32_t num_objects;
|
||||
uint32_t num_objects; ///< Num objects.
|
||||
|
||||
struct {
|
||||
// DRM PRIME file descriptor for this object.
|
||||
@@ -80,10 +110,10 @@ namespace va {
|
||||
uint32_t size;
|
||||
// Format modifier applied to this object, not sure what that means
|
||||
uint64_t drm_format_modifier;
|
||||
} objects[4];
|
||||
} objects[4]; ///< DRM PRIME backing objects referenced by the descriptor..
|
||||
|
||||
// Number of layers making up the surface.
|
||||
uint32_t num_layers;
|
||||
uint32_t num_layers; ///< Num layers.
|
||||
|
||||
struct {
|
||||
// DRM format fourcc of this layer (DRM_FOURCC_*).
|
||||
@@ -100,15 +130,36 @@ namespace va {
|
||||
|
||||
// Pitch of each plane.
|
||||
uint32_t pitch[4];
|
||||
} layers[4];
|
||||
} layers[4]; ///< DRM PRIME layer descriptions for the frame..
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief VA display handle released with `vaTerminate`.
|
||||
*/
|
||||
using display_t = util::safe_ptr_v2<void, VAStatus, vaTerminate>;
|
||||
|
||||
/**
|
||||
* @brief Create an FFmpeg VA-API hardware device context from a Sunshine encode device.
|
||||
*
|
||||
* @param encode_device Encode device.
|
||||
* @param hw_device_buf Output FFmpeg hardware device buffer.
|
||||
* @return 0 when the buffer is initialized; negative FFmpeg error code on failure.
|
||||
*/
|
||||
int vaapi_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf);
|
||||
|
||||
/**
|
||||
* @brief VAAPI encode device that imports captured frames into VA surfaces.
|
||||
*/
|
||||
class va_t: public platf::avcodec_encode_device_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Initialize VAAPI display, EGL, and conversion resources.
|
||||
*
|
||||
* @param in_width In width.
|
||||
* @param in_height In height.
|
||||
* @param render_device Render device.
|
||||
* @return 0 on success; nonzero or negative platform status on failure.
|
||||
*/
|
||||
int init(int in_width, int in_height, file_t &&render_device) {
|
||||
file = std::move(render_device);
|
||||
|
||||
@@ -229,6 +280,12 @@ namespace va {
|
||||
return VAProfileNone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize codec options.
|
||||
*
|
||||
* @param ctx Native context object used by the operation or callback.
|
||||
* @param options Request options or socket options to apply.
|
||||
*/
|
||||
void init_codec_options(AVCodecContext *ctx, AVDictionary **options) override {
|
||||
auto va_profile = get_va_profile(ctx);
|
||||
if (va_profile == VAProfileNone || !is_va_profile_supported(va_profile)) {
|
||||
@@ -303,6 +360,13 @@ namespace va {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Attach frame resources used by the next conversion or encode operation.
|
||||
*
|
||||
* @param frame Video or graphics frame being processed.
|
||||
* @param hw_frames_ctx_buf Hardware frames context buffer.
|
||||
* @return Status from updating frame.
|
||||
*/
|
||||
int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx_buf) override {
|
||||
this->hwframe.reset(frame);
|
||||
this->frame = frame;
|
||||
@@ -380,30 +444,42 @@ namespace va {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Apply the configured colorspace metadata to the active frame.
|
||||
*/
|
||||
void apply_colorspace() override {
|
||||
sws.apply_colorspace(colorspace, false);
|
||||
}
|
||||
|
||||
va::display_t::pointer va_display;
|
||||
file_t file;
|
||||
va::display_t::pointer va_display; ///< VA display used to allocate and destroy surfaces.
|
||||
file_t file; ///< DRM render-node file descriptor used by VAAPI and EGL.
|
||||
|
||||
gbm::gbm_t gbm;
|
||||
egl::display_t display;
|
||||
egl::ctx_t ctx;
|
||||
gbm::gbm_t gbm; ///< GBM device used for buffer allocation.
|
||||
egl::display_t display; ///< EGL display created from the DRM render node.
|
||||
egl::ctx_t ctx; ///< EGL context used for VA-API frame conversion.
|
||||
|
||||
// This must be destroyed before display_t to ensure the GPU
|
||||
// driver is still loaded when vaDestroySurfaces() is called.
|
||||
frame_t hwframe;
|
||||
frame_t hwframe; ///< FFmpeg hardware frame backed by a VAAPI surface.
|
||||
|
||||
egl::sws_t sws;
|
||||
egl::nv12_t nv12;
|
||||
egl::sws_t sws; ///< EGL/OpenGL conversion pipeline for VA-API frames.
|
||||
egl::nv12_t nv12; ///< EGL/OpenGL resources used for NV12 output frames.
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int width; ///< Frame or display width in pixels.
|
||||
int height; ///< Frame or display height in pixels.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief VAAPI encode path that copies converted frames through system memory.
|
||||
*/
|
||||
class va_ram_t: public va_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Convert a captured VAAPI frame into system-memory encoder input.
|
||||
*
|
||||
* @param img Image or frame object to read from or populate.
|
||||
* @return Conversion status.
|
||||
*/
|
||||
int convert(platf::img_t &img) override {
|
||||
sws.load_ram(img);
|
||||
|
||||
@@ -412,8 +488,17 @@ namespace va {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief VAAPI encode path that keeps converted frames in GPU memory.
|
||||
*/
|
||||
class va_vram_t: public va_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Convert a captured VAAPI frame into GPU encoder input.
|
||||
*
|
||||
* @param img Image or frame object to read from or populate.
|
||||
* @return Conversion status.
|
||||
*/
|
||||
int convert(platf::img_t &img) override {
|
||||
auto &descriptor = (egl::img_descriptor_t &) img;
|
||||
|
||||
@@ -440,6 +525,16 @@ namespace va {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize VAAPI GPU-frame conversion for the selected display.
|
||||
*
|
||||
* @param in_width In width.
|
||||
* @param in_height In height.
|
||||
* @param render_device Render device.
|
||||
* @param offset_x Offset x.
|
||||
* @param offset_y Offset y.
|
||||
* @return 0 on success; nonzero or negative platform status on failure.
|
||||
*/
|
||||
int init(int in_width, int in_height, file_t &&render_device, int offset_x, int offset_y) {
|
||||
if (va_t::init(in_width, in_height, std::move(render_device))) {
|
||||
return -1;
|
||||
@@ -453,11 +548,11 @@ namespace va {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::uint64_t sequence;
|
||||
egl::rgb_t rgb;
|
||||
std::uint64_t sequence; ///< Monotonic sequence used to recreate imported EGL resources.
|
||||
egl::rgb_t rgb; ///< Imported RGB image used before VAAPI conversion.
|
||||
|
||||
int offset_x;
|
||||
int offset_y;
|
||||
int offset_x; ///< Horizontal offset in physical pixels.
|
||||
int offset_y; ///< Vertical offset in physical pixels.
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -470,9 +565,9 @@ namespace va {
|
||||
union {
|
||||
void *xdisplay;
|
||||
int fd;
|
||||
} drm;
|
||||
} drm; ///< Native display or DRM fd passed to FFmpeg's VA-API context.
|
||||
|
||||
int drm_fd;
|
||||
int drm_fd; ///< DRM fd.
|
||||
} VAAPIDevicePriv;
|
||||
|
||||
/**
|
||||
@@ -508,6 +603,9 @@ namespace va {
|
||||
av_freep(&priv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize FFmpeg's VA-API hardware device buffer.
|
||||
*/
|
||||
int vaapi_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *base, AVBufferRef **hw_device_buf) {
|
||||
auto va = (va::va_t *) base;
|
||||
auto fd = dup(va->file.el);
|
||||
@@ -583,6 +681,9 @@ namespace va {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Validate that the configured VAAPI device can be used.
|
||||
*/
|
||||
bool validate(int fd) {
|
||||
va::display_t display {vaGetDisplayDRM(fd)};
|
||||
if (!display) {
|
||||
@@ -619,6 +720,9 @@ namespace va {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create AVCodec encode device.
|
||||
*/
|
||||
std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, file_t &&card, int offset_x, int offset_y, bool vram) {
|
||||
if (vram) {
|
||||
auto egl = std::make_unique<va::va_vram_t>();
|
||||
@@ -639,6 +743,9 @@ namespace va {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create AVCodec encode device.
|
||||
*/
|
||||
std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, int offset_x, int offset_y, bool vram) {
|
||||
auto render_device = platf::resolve_render_device();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user