Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
encoder_probe_display.cpp
Go to the documentation of this file.
1
5// standard includes
6#include <algorithm>
7#include <memory>
8#include <vector>
9
10// local includes
11#include "cuda.h"
12#include "misc.h"
13#include "src/logging.h"
14#include "src/platform/common.h"
15#include "src/video.h"
16#include "vaapi.h"
17
18namespace platf {
19 namespace {
20 struct probe_image_t final: img_t {
21 std::vector<std::uint8_t> pixels;
22 };
23
33 class encoder_probe_display_t final: public display_t {
34 public:
35 encoder_probe_display_t(mem_type_e memory, const video::config_t &config):
36 memory_type {memory} {
37 width = config.width;
38 height = config.height;
39 env_width = width;
40 env_height = height;
41 }
42
43 std::shared_ptr<img_t> alloc_img() override {
44 auto image = std::make_shared<probe_image_t>();
45 image->width = width;
46 image->height = height;
47 image->pixel_pitch = 4;
48 image->row_pitch = width * 4;
49 image->pixels.resize(static_cast<std::size_t>(image->row_pitch) * height);
50 image->data = image->pixels.data();
51 return image;
52 }
53
54 int dummy_img(img_t *image) override {
55 auto *probe = dynamic_cast<probe_image_t *>(image);
56 if (!probe) {
57 return -1;
58 }
59 std::fill(probe->pixels.begin(), probe->pixels.end(), 0);
60 return 0;
61 }
62
63 capture_e capture(const push_captured_image_cb_t &, const pull_free_image_cb_t &, bool *) override {
64 BOOST_LOG(error) << "The encoder probe display has nothing to capture";
65 return capture_e::error;
66 }
67
68 std::unique_ptr<avcodec_encode_device_t> make_avcodec_encode_device(pix_fmt_e) override {
69#ifdef HERMES_BUILD_VAAPI
70 if (memory_type == mem_type_e::vaapi) {
71 file_t card {open_encode_render_node()};
72 if (card.el < 0) {
73 BOOST_LOG(error) << "The encoder probe found no GPU to encode on";
74 return nullptr;
75 }
76 return va::make_avcodec_encode_device(width, height, std::move(card), 0, 0, false);
77 }
78#endif
79#ifdef HERMES_BUILD_CUDA
80 if (memory_type == mem_type_e::cuda) {
81 return cuda::make_avcodec_encode_device(width, height, false);
82 }
83#endif
84 return std::make_unique<avcodec_encode_device_t>();
85 }
86
87 private:
88 mem_type_e memory_type;
89 };
90 } // namespace
91
92 std::shared_ptr<display_t> encoder_probe_display(mem_type_e memory, const video::config_t &config) {
93 if (config.width <= 0 || config.height <= 0) {
94 return nullptr;
95 }
96 return std::make_shared<encoder_probe_display_t>(memory, config);
97 }
98} // namespace platf
Declarations for common platform specific utilities.
mem_type_e
Definition common.h:211
std::shared_ptr< display_t > encoder_probe_display(mem_type_e hwdevice_type, const video::config_t &config)
A display with no screen behind it, for validating encoders.
capture_e
Definition common.h:435
Definitions for CUDA implementation.
int open_encode_render_node(bool nvenc)
Open the render node of the best GPU to encode a stream on.
Declarations for logging related functions.
Miscellaneous declarations for Linux.
Declarations for VA-API hardware accelerated capture.
Declarations for video.