Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
vaapi.cpp
Go to the documentation of this file.
1
5// standard includes
6#include <algorithm>
7#include <fcntl.h>
8#include <format>
9#include <sstream>
10#include <string>
11
12extern "C" {
13#include <libavcodec/avcodec.h>
14#include <libavutil/pixdesc.h>
15#include <va/va.h>
16#include <va/va_drm.h>
17#if !VA_CHECK_VERSION(1, 9, 0)
18 // vaSyncBuffer stub allows Sunshine built against libva <2.9.0 to link against ffmpeg on libva 2.9.0 or later
19 VAStatus
20 vaSyncBuffer(
21 VADisplay dpy,
22 VABufferID buf_id,
23 uint64_t timeout_ns
24 ) {
25 return VA_STATUS_ERROR_UNIMPLEMENTED;
26 }
27#endif
28}
29
30// local includes
31#include "graphics.h"
32#include "misc.h"
33#include "src/config.h"
34#include "src/logging.h"
35#include "src/platform/common.h"
36#include "src/utility.h"
37#include "src/video.h"
38
39using namespace std::literals;
40
41extern "C" struct AVBufferRef;
42
43namespace va {
44 constexpr auto SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 = 0x40000000;
45 constexpr auto EXPORT_SURFACE_WRITE_ONLY = 0x0002;
46 constexpr auto EXPORT_SURFACE_SEPARATE_LAYERS = 0x0004;
47
48 using VADisplay = void *;
49 using VAStatus = int;
50 using VAGenericID = unsigned int;
51 using VASurfaceID = VAGenericID;
52
54 // VA Pixel format fourcc of the whole surface (VA_FOURCC_*).
55 uint32_t fourcc;
56
57 uint32_t width;
58 uint32_t height;
59
60 // Number of distinct DRM objects making up the surface.
61 uint32_t num_objects;
62
63 struct {
64 // DRM PRIME file descriptor for this object.
65 // Needs to be closed manually
66 int fd;
67
68 // Total size of this object (may include regions which are not part of the surface)
69 uint32_t size;
70 // Format modifier applied to this object, not sure what that means
71 uint64_t drm_format_modifier;
72 } objects[4];
73
74 // Number of layers making up the surface.
75 uint32_t num_layers;
76
77 struct {
78 // DRM format fourcc of this layer (DRM_FOURCC_*).
79 uint32_t drm_format;
80
81 // Number of planes in this layer.
82 uint32_t num_planes;
83
84 // references objects --> DRMPRIMESurfaceDescriptor.objects[object_index[0]]
85 uint32_t object_index[4];
86
87 // Offset within the object of each plane.
88 uint32_t offset[4];
89
90 // Pitch of each plane.
91 uint32_t pitch[4];
92 } layers[4];
93 };
94
95 using display_t = util::safe_ptr_v2<void, VAStatus, vaTerminate>;
96
97 int vaapi_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *encode_device, AVBufferRef **hw_device_buf);
98
100 public:
101 int init(int in_width, int in_height, file_t &&render_device) {
102 file = std::move(render_device);
103
104 if (!gbm::create_device) {
105 BOOST_LOG(warning) << "libgbm not initialized"sv;
106 return -1;
107 }
108
109 this->data = (void *) vaapi_init_avcodec_hardware_input_buffer;
110
111 gbm.reset(gbm::create_device(file.el));
112 if (!gbm) {
113 char string[1024];
114 BOOST_LOG(error) << "Couldn't create GBM device: ["sv << strerror_r(errno, string, sizeof(string)) << ']';
115 return -1;
116 }
117
118 display = egl::make_display(gbm.get());
119 if (!display) {
120 return -1;
121 }
122
123 auto ctx_opt = egl::make_ctx(display.get());
124 if (!ctx_opt) {
125 return -1;
126 }
127
128 ctx = std::move(*ctx_opt);
129
130 width = in_width;
131 height = in_height;
132
133 return 0;
134 }
135
141 VAEntrypoint select_va_entrypoint(VAProfile profile) {
142 std::vector<VAEntrypoint> entrypoints(vaMaxNumEntrypoints(va_display));
143 int num_eps;
144 auto status = vaQueryConfigEntrypoints(va_display, profile, entrypoints.data(), &num_eps);
145 if (status != VA_STATUS_SUCCESS) {
146 BOOST_LOG(error) << "Failed to query VA entrypoints: "sv << vaErrorStr(status);
147 return (VAEntrypoint) 0;
148 }
149 entrypoints.resize(num_eps);
150
151 // Sorted in order of descending preference
152 VAEntrypoint ep_preferences[] = {
153 VAEntrypointEncSliceLP,
154 VAEntrypointEncSlice,
155 VAEntrypointEncPicture
156 };
157 for (auto ep_pref : ep_preferences) {
158 if (std::find(entrypoints.begin(), entrypoints.end(), ep_pref) != entrypoints.end()) {
159 return ep_pref;
160 }
161 }
162
163 return (VAEntrypoint) 0;
164 }
165
171 bool is_va_profile_supported(VAProfile profile) {
172 std::vector<VAProfile> profiles(vaMaxNumProfiles(va_display));
173 int num_profs;
174 auto status = vaQueryConfigProfiles(va_display, profiles.data(), &num_profs);
175 if (status != VA_STATUS_SUCCESS) {
176 BOOST_LOG(error) << "Failed to query VA profiles: "sv << vaErrorStr(status);
177 return false;
178 }
179 profiles.resize(num_profs);
180
181 return std::find(profiles.begin(), profiles.end(), profile) != profiles.end();
182 }
183
189 VAProfile get_va_profile(AVCodecContext *ctx) {
190 if (ctx->codec_id == AV_CODEC_ID_H264) {
191 // There's no VAAPI profile for H.264 4:4:4
192 return VAProfileH264High;
193 } else if (ctx->codec_id == AV_CODEC_ID_HEVC) {
194 switch (ctx->profile) {
195 case AV_PROFILE_HEVC_REXT:
196 switch (av_pix_fmt_desc_get(ctx->sw_pix_fmt)->comp[0].depth) {
197 case 10:
198 return VAProfileHEVCMain444_10;
199 case 8:
200 return VAProfileHEVCMain444;
201 }
202 break;
203 case AV_PROFILE_HEVC_MAIN_10:
204 return VAProfileHEVCMain10;
205 case AV_PROFILE_HEVC_MAIN:
206 return VAProfileHEVCMain;
207 }
208 } else if (ctx->codec_id == AV_CODEC_ID_AV1) {
209 switch (ctx->profile) {
210 case AV_PROFILE_AV1_HIGH:
211 return VAProfileAV1Profile1;
212 case AV_PROFILE_AV1_MAIN:
213 return VAProfileAV1Profile0;
214 }
215 }
216
217 BOOST_LOG(error) << "Unknown encoder profile: "sv << ctx->profile;
218 return VAProfileNone;
219 }
220
221 void init_codec_options(AVCodecContext *ctx, AVDictionary **options) override {
222 auto va_profile = get_va_profile(ctx);
223 if (va_profile == VAProfileNone || !is_va_profile_supported(va_profile)) {
224 // Don't bother doing anything if the profile isn't supported
225 return;
226 }
227
228 auto va_entrypoint = select_va_entrypoint(va_profile);
229 if (va_entrypoint == 0) {
230 // It's possible that only decoding is supported for this profile
231 return;
232 }
233
234 auto vendor = vaQueryVendorString(va_display);
235
236 if (va_entrypoint == VAEntrypointEncSliceLP) {
237 BOOST_LOG(info) << "Using LP encoding mode"sv;
238 av_dict_set_int(options, "low_power", 1, 0);
239 } else {
240 BOOST_LOG(info) << "Using normal encoding mode"sv;
241 }
242
243 VAConfigAttrib rc_attr = {VAConfigAttribRateControl};
244 auto status = vaGetConfigAttributes(va_display, va_profile, va_entrypoint, &rc_attr, 1);
245 if (status != VA_STATUS_SUCCESS) {
246 // Stick to the default rate control (CQP)
247 rc_attr.value = 0;
248 }
249
250 VAConfigAttrib slice_attr = {VAConfigAttribEncMaxSlices};
251 status = vaGetConfigAttributes(va_display, va_profile, va_entrypoint, &slice_attr, 1);
252 if (status != VA_STATUS_SUCCESS) {
253 // Assume only a single slice is supported
254 slice_attr.value = 1;
255 }
256 if (ctx->slices > slice_attr.value) {
257 BOOST_LOG(info) << "Limiting slice count to encoder maximum: "sv << slice_attr.value;
258 ctx->slices = slice_attr.value;
259 }
260
261 // Use VBR with a single frame VBV when the user forces it and for known good cases:
262 // - Intel GPUs
263 // - AV1
264 //
265 // VBR ensures the bitstream isn't full of filler data for bitrate undershoots and
266 // single frame VBV ensures that we don't have large bitrate overshoots (at least
267 // as much as they can be avoided without pre-analysis).
268 //
269 // When we have to resort to the default 1 second VBV for encoding quality reasons,
270 // we stick to CBR in order to avoid encoding huge frames after bitrate undershoots
271 // leave headroom available in the RC window.
272 const bool amd_or_mesa_vaapi = vendor && (
273 strstr(vendor, "AMD") ||
274 strstr(vendor, "Mesa") ||
275 strstr(vendor, "RADV") ||
276 strstr(vendor, "radeonsi")
277 );
278 if (config::video.vaapi.strict_rc_buffer ||
279 (vendor && strstr(vendor, "Intel")) ||
280 amd_or_mesa_vaapi ||
281 ctx->codec_id == AV_CODEC_ID_AV1) {
282 ctx->rc_buffer_size = ctx->bit_rate * ctx->framerate.den / ctx->framerate.num;
283
284 // radeonsi accepts the VBV size in VBR but does not hold frames to it:
285 // the first key frame and frames after a still stretch came out far
286 // over the single-frame budget (39.6x at 2 Mbps on an RX 9070 XT,
287 // against 5.7x in CBR). CBR keeps the bound; the filler it pads
288 // H.264 and HEVC frames with is removed before sending (video.cpp).
289 const bool radeonsi = vendor && strstr(vendor, "radeonsi");
290
291 if (radeonsi && (rc_attr.value & VA_RC_CBR)) {
292 BOOST_LOG(info) << "Using CBR with single frame VBV size (radeonsi ignores the VBV in VBR)"sv;
293 av_dict_set(options, "rc_mode", "CBR", 0);
294 } else if (rc_attr.value & VA_RC_VBR) {
295 BOOST_LOG(info) << "Using VBR with single frame VBV size"sv;
296 av_dict_set(options, "rc_mode", "VBR", 0);
297 } else if (rc_attr.value & VA_RC_CBR) {
298 BOOST_LOG(info) << "Using CBR with single frame VBV size"sv;
299 av_dict_set(options, "rc_mode", "CBR", 0);
300 } else {
301 BOOST_LOG(warning) << "Using CQP with single frame VBV size"sv;
302 av_dict_set_int(options, "qp", config::video.qp, 0);
303 }
304 } else if (!(rc_attr.value & (VA_RC_CBR | VA_RC_VBR))) {
305 BOOST_LOG(warning) << "Using CQP rate control"sv;
306 av_dict_set_int(options, "qp", config::video.qp, 0);
307 } else {
308 // For remaining VAAPI encoders (typically AMD H.264/HEVC), explicitly
309 // select a rate control mode. The VBV buffer size is already set by
310 // the common encoder code in video.cpp.
311 if (rc_attr.value & VA_RC_CBR) {
312 BOOST_LOG(info) << "Using CBR rate control"sv;
313 av_dict_set(options, "rc_mode", "CBR", 0);
314 } else if (rc_attr.value & VA_RC_VBR) {
315 BOOST_LOG(info) << "Using VBR rate control"sv;
316 av_dict_set(options, "rc_mode", "VBR", 0);
317 }
318 }
319 }
320
321 int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx_buf) override {
322 this->hwframe.reset(frame);
323 this->frame = frame;
324
325 if (!frame->buf[0]) {
326 if (av_hwframe_get_buffer(hw_frames_ctx_buf, frame, 0)) {
327 BOOST_LOG(error) << "Couldn't get hwframe for VAAPI"sv;
328 return -1;
329 }
330 }
331
333 va::VASurfaceID surface = (std::uintptr_t) frame->data[3];
334 auto hw_frames_ctx = (AVHWFramesContext *) hw_frames_ctx_buf->data;
335
336 auto status = vaExportSurfaceHandle(
337 this->va_display,
338 surface,
339 va::SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
340 va::EXPORT_SURFACE_WRITE_ONLY | va::EXPORT_SURFACE_SEPARATE_LAYERS,
341 &prime
342 );
343 if (status) {
344 BOOST_LOG(error) << "Couldn't export va surface handle: ["sv << (int) surface << "]: "sv << vaErrorStr(status);
345
346 return -1;
347 }
348
349 // Keep track of file descriptors
350 std::array<file_t, egl::nv12_img_t::num_fds> fds;
351 for (int x = 0; x < prime.num_objects; ++x) {
352 fds[x] = prime.objects[x].fd;
353 }
354
355 if (prime.num_layers != 2) {
356 BOOST_LOG(error) << "Invalid layer count for VA surface: expected 2, got "sv << prime.num_layers;
357 return -1;
358 }
359
360 egl::surface_descriptor_t sds[2] = {};
361 for (int plane = 0; plane < 2; ++plane) {
362 auto &sd = sds[plane];
363 auto &layer = prime.layers[plane];
364
365 sd.fourcc = layer.drm_format;
366
367 // UV plane is subsampled
368 sd.width = prime.width / (plane == 0 ? 1 : 2);
369 sd.height = prime.height / (plane == 0 ? 1 : 2);
370
371 // The modifier must be the same for all planes
372 sd.modifier = prime.objects[layer.object_index[0]].drm_format_modifier;
373
374 std::fill_n(sd.fds, 4, -1);
375 for (int x = 0; x < layer.num_planes; ++x) {
376 sd.fds[x] = prime.objects[layer.object_index[x]].fd;
377 sd.pitches[x] = layer.pitch[x];
378 sd.offsets[x] = layer.offset[x];
379 }
380 }
381
382 auto nv12_opt = egl::import_target(display.get(), std::move(fds), sds[0], sds[1]);
383 if (!nv12_opt) {
384 return -1;
385 }
386
387 auto sws_opt = egl::sws_t::make(width, height, frame->width, frame->height, hw_frames_ctx->sw_format);
388 if (!sws_opt) {
389 return -1;
390 }
391
392 this->sws = std::move(*sws_opt);
393 this->nv12 = std::move(*nv12_opt);
394
395 return 0;
396 }
397
398 void apply_colorspace() override {
399 sws.apply_colorspace(colorspace);
400 }
401
402 va::display_t::pointer va_display;
403 file_t file;
404
405 gbm::gbm_t gbm;
406 egl::display_t display;
407 egl::ctx_t ctx;
408
409 // This must be destroyed before display_t to ensure the GPU
410 // driver is still loaded when vaDestroySurfaces() is called.
411 frame_t hwframe;
412
413 egl::sws_t sws;
414 egl::nv12_t nv12;
415
416 int width, height;
417 };
418
419 class va_ram_t: public va_t {
420 public:
421 int convert(platf::img_t &img) override {
422 sws.load_ram(img);
423
424 sws.convert(nv12->buf);
425 return 0;
426 }
427 };
428
429 class va_vram_t: public va_t {
430 public:
431 int convert(platf::img_t &img) override {
432 auto &descriptor = (egl::img_descriptor_t &) img;
433
434 if (descriptor.sequence == 0) {
435 // For dummy images, use a blank RGB texture instead of importing a DMA-BUF
436 rgb = egl::create_blank(img);
437 } else if (descriptor.sequence > sequence) {
438 sequence = descriptor.sequence;
439
440 rgb = egl::rgb_t {};
441
442 auto rgb_opt = egl::import_source(display.get(), descriptor.sd);
443
444 if (!rgb_opt) {
445 return -1;
446 }
447
448 rgb = std::move(*rgb_opt);
449 }
450
451 sws.load_vram(descriptor, offset_x, offset_y, rgb->tex[0]);
452
453 sws.convert(nv12->buf);
454 return 0;
455 }
456
457 int init(int in_width, int in_height, file_t &&render_device, int offset_x, int offset_y) {
458 if (va_t::init(in_width, in_height, std::move(render_device))) {
459 return -1;
460 }
461
462 sequence = 0;
463
464 this->offset_x = offset_x;
465 this->offset_y = offset_y;
466
467 return 0;
468 }
469
470 std::uint64_t sequence;
471 egl::rgb_t rgb;
472
473 int offset_x, offset_y;
474 };
475
482 typedef struct VAAPIDevicePriv {
483 union {
484 void *xdisplay;
485 int fd;
486 } drm;
487
488 int drm_fd;
489 } VAAPIDevicePriv;
490
496 typedef struct AVVAAPIDeviceContext {
500 va::VADisplay display;
508 unsigned int driver_quirks;
509 } AVVAAPIDeviceContext;
510
511 static void __log(void *level, const char *msg) {
512 BOOST_LOG(*(boost::log::sources::severity_logger<int> *) level) << msg;
513 }
514
515 static void vaapi_hwdevice_ctx_free(AVHWDeviceContext *ctx) {
516 auto hwctx = (AVVAAPIDeviceContext *) ctx->hwctx;
517 auto priv = (VAAPIDevicePriv *) ctx->user_opaque;
518
519 vaTerminate(hwctx->display);
520 close(priv->drm_fd);
521 av_freep(&priv);
522 }
523
524 int vaapi_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *base, AVBufferRef **hw_device_buf) {
525 auto va = (va::va_t *) base;
526 auto fd = dup(va->file.el);
527
528 auto *priv = (VAAPIDevicePriv *) av_mallocz(sizeof(VAAPIDevicePriv));
529 priv->drm_fd = fd;
530
531 auto fg = util::fail_guard([fd, priv]() {
532 close(fd);
533 av_free(priv);
534 });
535
536 va::display_t display {vaGetDisplayDRM(fd)};
537 if (!display) {
538 BOOST_LOG(error) << "Couldn't open a va display from DRM on the encoding GPU"sv;
539 return -1;
540 }
541
542 va->va_display = display.get();
543
544 vaSetErrorCallback(display.get(), __log, &error);
545 vaSetErrorCallback(display.get(), __log, &info);
546
547 int major, minor;
548 auto status = vaInitialize(display.get(), &major, &minor);
549 if (status) {
550 BOOST_LOG(error) << "Couldn't initialize va display: "sv << vaErrorStr(status);
551 return -1;
552 }
553
554 BOOST_LOG(info) << "vaapi vendor: "sv << vaQueryVendorString(display.get());
556
557 *hw_device_buf = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
558 auto ctx = (AVHWDeviceContext *) (*hw_device_buf)->data;
559 auto hwctx = (AVVAAPIDeviceContext *) ctx->hwctx;
560
561 // Ownership of the VADisplay and DRM fd is now ours to manage via the free() function
562 hwctx->display = display.release();
563 ctx->user_opaque = priv;
564 ctx->free = vaapi_hwdevice_ctx_free;
565 fg.disable();
566
567 auto err = av_hwdevice_ctx_init(*hw_device_buf);
568 if (err) {
569 char err_str[AV_ERROR_MAX_STRING_SIZE] {0};
570 BOOST_LOG(error) << "Failed to create FFMpeg hardware device context: "sv << av_make_error_string(err_str, AV_ERROR_MAX_STRING_SIZE, err);
571
572 return err;
573 }
574
575 return 0;
576 }
577
578 static bool query(display_t::pointer display, VAProfile profile) {
579 std::vector<VAEntrypoint> entrypoints;
580 entrypoints.resize(vaMaxNumEntrypoints(display));
581
582 int count;
583 auto status = vaQueryConfigEntrypoints(display, profile, entrypoints.data(), &count);
584 if (status) {
585 BOOST_LOG(error) << "Couldn't query entrypoints: "sv << vaErrorStr(status);
586 return false;
587 }
588 entrypoints.resize(count);
589
590 for (auto entrypoint : entrypoints) {
591 if (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointEncSliceLP) {
592 return true;
593 }
594 }
595
596 return false;
597 }
598
599 bool validate(int fd) {
600 va::display_t display {vaGetDisplayDRM(fd)};
601 if (!display) {
602 char string[1024];
603
604 auto bytes = readlink(std::format("/proc/self/fd/{}", fd).c_str(), string, sizeof(string));
605
606 std::string_view render_device {string, (std::size_t) bytes};
607
608 BOOST_LOG(error) << "Couldn't open a va display from DRM with device: "sv << render_device;
609 return false;
610 }
611
612 int major, minor;
613 auto status = vaInitialize(display.get(), &major, &minor);
614 if (status) {
615 BOOST_LOG(error) << "Couldn't initialize va display: "sv << vaErrorStr(status);
616 return false;
617 }
618
619 if (!query(display.get(), VAProfileH264Main)) {
620 return false;
621 }
622
623 if (video::active_hevc_mode > 1 && !query(display.get(), VAProfileHEVCMain)) {
624 return false;
625 }
626
627 if (video::active_hevc_mode > 2 && !query(display.get(), VAProfileHEVCMain10)) {
628 return false;
629 }
630
631 return true;
632 }
633
634 int encode_capability(int fd) {
635 va::display_t display {vaGetDisplayDRM(fd)};
636 if (!display) {
637 return 0;
638 }
639 // libva reports its driver search on stderr; a ranking pass is not the
640 // place for it.
641 vaSetErrorCallback(display.get(), nullptr, nullptr);
642 vaSetInfoCallback(display.get(), nullptr, nullptr);
643
644 int major, minor;
645 if (vaInitialize(display.get(), &major, &minor) != VA_STATUS_SUCCESS) {
646 return 0;
647 }
648
649 const auto encodes = [&](VAProfile profile) {
650 std::vector<VAEntrypoint> entrypoints(vaMaxNumEntrypoints(display.get()));
651 int count = 0;
652 if (vaQueryConfigEntrypoints(display.get(), profile, entrypoints.data(), &count) != VA_STATUS_SUCCESS) {
653 return false;
654 }
655 entrypoints.resize(count);
656 return std::ranges::any_of(entrypoints, [](VAEntrypoint entrypoint) {
657 return entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointEncSliceLP;
658 });
659 };
660
661 if (!encodes(VAProfileH264Main) && !encodes(VAProfileH264High)) {
662 return 0;
663 }
664 int capability = 1;
665 if (encodes(VAProfileHEVCMain)) {
666 capability |= 2;
667 }
668 if (encodes(VAProfileHEVCMain10)) {
669 capability |= 4;
670 }
671 if (encodes(VAProfileAV1Profile0)) {
672 capability |= 8;
673 }
674 return capability;
675 }
676
677 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) {
678 if (vram) {
679 auto egl = std::make_unique<va::va_vram_t>();
680 if (egl->init(width, height, std::move(card), offset_x, offset_y)) {
681 return nullptr;
682 }
683
684 return egl;
685 }
686
687 else {
688 auto egl = std::make_unique<va::va_ram_t>();
689 if (egl->init(width, height, std::move(card))) {
690 return nullptr;
691 }
692
693 return egl;
694 }
695 }
696
697 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, int offset_x, int offset_y, bool vram) {
698 file_t file {platf::open_encode_render_node()};
699 if (file.el < 0) {
700 BOOST_LOG(error) << "Couldn't open a GPU to encode on"sv;
701 return nullptr;
702 }
703
704 return make_avcodec_encode_device(width, height, std::move(file), offset_x, offset_y, vram);
705 }
706
707 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, bool vram) {
708 return make_avcodec_encode_device(width, height, 0, 0, vram);
709 }
710} // namespace va
VAEntrypoint select_va_entrypoint(VAProfile profile)
Finds a supported VA entrypoint for the given VA profile.
Definition vaapi.cpp:141
bool is_va_profile_supported(VAProfile profile)
Determines if a given VA profile is supported.
Definition vaapi.cpp:171
void init_codec_options(AVCodecContext *ctx, AVDictionary **options) override
Provides a hook for allow platform-specific code to adjust codec options.
Definition vaapi.cpp:221
VAProfile get_va_profile(AVCodecContext *ctx)
Determines the matching VA profile for the codec configuration.
Definition vaapi.cpp:189
int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx_buf) override
Set the frame to be encoded.
Definition vaapi.cpp:321
Declarations for common platform specific utilities.
std::shared_ptr< display_t > display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monit...
Definition misc.cpp:1658
Declarations for the configuration of Sunshine.
int open_encode_render_node(bool nvenc)
Open the render node of the best GPU to encode a stream on.
void note_vaapi_encode_gpu(int fd)
Record the GPU a VAAPI encoder actually opened, from its DRM fd.
rgb_t create_blank(platf::img_t &img)
Create a black RGB texture of the specified image size.
Definition graphics.cpp:621
Declarations for graphics related functions.
Declarations for logging related functions.
Miscellaneous declarations for Linux.
unsigned int driver_quirks
Definition vaapi.cpp:508
va::VADisplay display
Definition vaapi.cpp:500
Declarations for utility functions.
int encode_capability(int fd)
Rank what the GPU behind fd can encode, for choosing between GPUs.
Definition vaapi.cpp:634
Declarations for video.