Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
vaapi.cpp File Reference

Definitions for VA-API hardware accelerated capture. More...

#include <array>
#include <cstddef>
#include <fcntl.h>
#include <format>
#include <sstream>
#include <string>
#include <libavcodec/avcodec.h>
#include <libavutil/pixdesc.h>
#include <va/va.h>
#include <va/va_drm.h>
#include <va/va_drmcommon.h>
#include "graphics.h"
#include "misc.h"
#include "src/config.h"
#include "src/logging.h"
#include "src/platform/common.h"
#include "src/utility.h"
#include "src/video.h"
Include dependency graph for vaapi.cpp:

Classes

struct  va::AVVAAPIDeviceContext
 VA-API connection details allocated as AVHWDeviceContext.hwctx. More...
struct  va::DRMPRIMESurfaceDescriptor
 DRM PRIME descriptor imported from a VAAPI surface. More...
struct  va::DRMPRIMESurfaceDescriptor::layer_t
 DRM layer describing the planes of an exported surface. More...
struct  va::DRMPRIMESurfaceDescriptor::object_t
 Backing DRM PRIME object with its file descriptor and layout. More...
class  va::va_ram_t
 VAAPI encode path that copies converted frames through system memory. More...
class  va::va_t
 VAAPI encode device that imports captured frames into VA surfaces. More...
class  va::va_vram_t
 VAAPI encode path that keeps converted frames in GPU memory. More...
struct  va::VAAPIDevicePriv
 FFmpeg-private device data used to create a VA-API hardware context. More...

Typedefs

using va::display_t = util::safe_ptr_v2<void, VAStatus, &vaTerminate>
 VA display handle released with vaTerminate.
using va::VADisplay = void *
 Native VA display handle.
using va::VAGenericID = unsigned int
 Generic numeric VAAPI object identifier.
using va::VAStatus = int
 Status code returned by VAAPI functions.
using va::VASurfaceID = VAGenericID
 VAAPI surface identifier.

Functions

std::unique_ptr< platf::avcodec_encode_device_t > va::make_avcodec_encode_device (int width, int height, bool vram)
std::unique_ptr< platf::avcodec_encode_device_t > va::make_avcodec_encode_device (int width, int height, file_t &&card, int offset_x, int offset_y, bool vram)
 Create AVCodec encode device.
std::unique_ptr< platf::avcodec_encode_device_t > va::make_avcodec_encode_device (int width, int height, int offset_x, int offset_y, bool vram)
 Create AVCodec encode device.
int va::vaapi_init_avcodec_hardware_input_buffer (platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf)
 Create an FFmpeg VA-API hardware device context from a Sunshine encode device.
bool va::validate (int fd)
 Validate that the configured VAAPI device can be used.
VAStatus vaMapBuffer2 (VADisplay dpy, VABufferID buf_id, void **pbuf, uint32_t)
 Stub vaMapBuffer2 when building against libva before 2.21.0.
VAStatus vaSyncBuffer (VADisplay dpy, VABufferID buf_id, uint64_t timeout_ns)
 Stub vaSyncBuffer when building against libva before 2.9.0.

Variables

constexpr auto va::EXPORT_SURFACE_SEPARATE_LAYERS = 0x0004
 GameStream port offset for export surface separate layers.
constexpr auto va::EXPORT_SURFACE_WRITE_ONLY = 0x0002
 GameStream port offset for export surface write only.
constexpr auto va::SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 = 0x40000000
 Protocol or platform constant for surface attrib mem type drm prime 2.

Detailed Description

Definitions for VA-API hardware accelerated capture.

Function Documentation

◆ make_avcodec_encode_device() [1/3]

std::unique_ptr< platf::avcodec_encode_device_t > va::make_avcodec_encode_device ( int width,
int height,
bool vram )

Width --> Width of the image Height --> Height of the image offset_x --> Horizontal offset of the image in the texture offset_y --> Vertical offset of the image in the texture file_t card --> The file descriptor of the render device used for encoding

Parameters
widthFrame or display width in pixels.
heightFrame or display height in pixels.
vramWhether the image should use GPU memory instead of system memory.
Returns
Constructed AVCodec encode device object.

◆ make_avcodec_encode_device() [2/3]

std::unique_ptr< platf::avcodec_encode_device_t > va::make_avcodec_encode_device ( int width,
int height,
file_t && card,
int offset_x,
int offset_y,
bool vram )

Create AVCodec encode device.

Parameters
widthFrame or display width in pixels.
heightFrame or display height in pixels.
cardVideo device path or render node used for VAAPI.
offset_xOffset x.
offset_yOffset y.
vramWhether the image should use GPU memory instead of system memory.
Returns
Constructed AVCodec encode device object.

◆ make_avcodec_encode_device() [3/3]

std::unique_ptr< platf::avcodec_encode_device_t > va::make_avcodec_encode_device ( int width,
int height,
int offset_x,
int offset_y,
bool vram )

Create AVCodec encode device.

Parameters
widthFrame or display width in pixels.
heightFrame or display height in pixels.
offset_xOffset x.
offset_yOffset y.
vramWhether the image should use GPU memory instead of system memory.
Returns
Constructed AVCodec encode device object.

◆ vaapi_init_avcodec_hardware_input_buffer()

int va::vaapi_init_avcodec_hardware_input_buffer ( platf::avcodec_encode_device_t * encode_device,
AVBufferRef ** hw_device_buf )

Create an FFmpeg VA-API hardware device context from a Sunshine encode device.

Initialize FFmpeg's VA-API hardware device buffer.

Parameters
encode_deviceEncode device.
hw_device_bufOutput FFmpeg hardware device buffer.
Returns
0 when the buffer is initialized; negative FFmpeg error code on failure.

◆ validate()

bool va::validate ( int fd)

Validate that the configured VAAPI device can be used.

Parameters
fdNative file descriptor to wrap or inspect.
Returns
True when the VAAPI device is usable for capture or encode.

◆ vaMapBuffer2()

VAStatus vaMapBuffer2 ( VADisplay dpy,
VABufferID buf_id,
void ** pbuf,
uint32_t  )

Stub vaMapBuffer2 when building against libva before 2.21.0.

The older vaMapBuffer API does not accept the mapping flags supplied by the new ABI.

Parameters
dpyVA display.
buf_idVA buffer ID.
pbufOutput mapped buffer pointer.
Returns
VA status code.

◆ vaSyncBuffer()

VAStatus vaSyncBuffer ( VADisplay dpy,
VABufferID buf_id,
uint64_t timeout_ns )

Stub vaSyncBuffer when building against libva before 2.9.0.

Parameters
dpyVA display.
buf_idVA buffer ID.
timeout_nsSync timeout in nanoseconds.
Returns
VA status code.