Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
encode_gpu.cpp File Reference

Choosing the GPU a stream is encoded on. More...

#include <algorithm>
#include <cctype>
#include <array>
#include <cerrno>
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <format>
#include <fstream>
#include <mutex>
#include <string>
#include <string_view>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h>
#include <xf86drm.h>
#include "misc.h"
#include "src/config.h"
#include "src/logging.h"
#include "src/utility.h"
#include "vaapi.h"
Include dependency graph for encode_gpu.cpp:

Go to the source code of this file.

Functions

int platf::open_encode_render_node (bool nvenc=false)
 Open the render node of the best GPU to encode a stream on.
std::string platf::encode_gpu_description (bool nvenc=false)
 Describe the GPU a stream encodes on, for logs and diagnostics: its render node, driver and the name it is sold under, or its PCI id.
void platf::note_vaapi_encode_gpu (int fd)
 Record the GPU a VAAPI encoder actually opened, from its DRM fd.
std::string platf::last_vaapi_encode_gpu ()
 The GPU the last VAAPI encoder opened, described as encode_gpu_description() does, or an empty string.
std::vector< std::string > platf::render_node_descriptions ()
 Describe every GPU render node, as encode_gpu_description() does, the capture-only Hermes-KMS node included and marked as such.

Detailed Description

Choosing the GPU a stream is encoded on.

Definition in file encode_gpu.cpp.

Function Documentation

◆ encode_gpu_description()

std::string platf::encode_gpu_description ( bool nvenc = false)

Describe the GPU a stream encodes on, for logs and diagnostics: its render node, driver and the name it is sold under, or its PCI id.

Parameters
nvencWhether the stream encodes with NVENC rather than VAAPI.
Returns
For example "/dev/dri/renderD128 (amdgpu, AMD Radeon RX 9070 XT)", or "(amdgpu, AMD 1002:7550)" where the name is unknown, or an empty string when no GPU qualifies.

Definition at line 266 of file encode_gpu.cpp.

◆ last_vaapi_encode_gpu()

std::string platf::last_vaapi_encode_gpu ( )

The GPU the last VAAPI encoder opened, described as encode_gpu_description() does, or an empty string.

Definition at line 294 of file encode_gpu.cpp.

◆ note_vaapi_encode_gpu()

void platf::note_vaapi_encode_gpu ( int fd)

Record the GPU a VAAPI encoder actually opened, from its DRM fd.

KMS capture hands the encoder the render node of the GPU the captured display is on, which need not be the one adapter_name names. A negative fd forgets the last one.

Definition at line 282 of file encode_gpu.cpp.

◆ open_encode_render_node()

int platf::open_encode_render_node ( bool nvenc = false)

Open the render node of the best GPU to encode a stream on.

adapter_name when it is set. Otherwise every real GPU is ranked by the video it can encode - AV1, then HEVC Main10, HEVC, H.264 - with more video memory breaking a tie, and the best one wins; for NVENC an NVIDIA GPU comes first. The capture-only Hermes-KMS node never qualifies.

Parameters
nvencWhether the stream encodes with NVENC rather than VAAPI.
Returns
An owned file descriptor, or -1.

Definition at line 80 of file encode_gpu.cpp.

◆ render_node_descriptions()

std::vector< std::string > platf::render_node_descriptions ( )

Describe every GPU render node, as encode_gpu_description() does, the capture-only Hermes-KMS node included and marked as such.

Definition at line 313 of file encode_gpu.cpp.