Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
Go to the documentation of this file.
1
5#pragma once
6
7#if defined(SUNSHINE_BUILD_CUDA)
8 // standard includes
9 #include <cstdint>
10 #include <memory>
11 #include <optional>
12 #include <string>
13 #include <vector>
14
15 // local includes
16 #include "src/video_colorspace.h"
17
18namespace platf {
20 struct img_t;
21} // namespace platf
22
23namespace cuda {
24
25 namespace nvfbc {
26 std::vector<std::string> display_names();
27 }
28
29 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, bool vram);
30
39 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_gl_encode_device(int width, int height, int offset_x, int offset_y);
40
41 int init();
42} // namespace cuda
43
47using cudaArray_t = struct cudaArray *;
48
49 #if !defined(__CUDACC__)
53using cudaStream_t = struct CUstream_st *;
57using cudaTextureObject_t = unsigned long long;
58 #else /* defined(__CUDACC__) */
59typedef __location__(device_builtin) struct CUstream_st *cudaStream_t;
60typedef __location__(device_builtin) unsigned long long cudaTextureObject_t;
61 #endif /* !defined(__CUDACC__) */
62
63namespace cuda {
64
65 class freeCudaPtr_t {
66 public:
67 void operator()(void *ptr);
68 };
69
70 class freeCudaStream_t {
71 public:
72 void operator()(cudaStream_t ptr);
73 };
74
75 using ptr_t = std::unique_ptr<void, freeCudaPtr_t>;
76 using stream_t = std::unique_ptr<CUstream_st, freeCudaStream_t>;
77
78 stream_t make_stream(int flags = 0);
79
80 struct viewport_t {
81 int width;
82 int height;
83 int offsetX;
84 int offsetY;
85 };
86
87 class tex_t {
88 public:
89 static std::optional<tex_t> make(int height, int pitch);
90
91 tex_t();
92 tex_t(tex_t &&);
93
94 tex_t &operator=(tex_t &&other);
95
96 ~tex_t();
97
98 int copy(std::uint8_t *src, int height, int pitch);
99
100 cudaArray_t array;
101
105 struct texture_t {
106 cudaTextureObject_t point;
107 cudaTextureObject_t linear;
108 };
109
110 texture_t texture;
111 };
112
113 class sws_t {
114 public:
115 sws_t() = default;
116 sws_t(int in_width, int in_height, int out_width, int out_height, int pitch, int threadsPerBlock, ptr_t &&color_matrix);
117
124 static std::optional<sws_t> make(int in_width, int in_height, int out_width, int out_height, int pitch);
125
126 // Converts loaded image into a CUDevicePtr
127 int convert_nv12(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture, stream_t::pointer stream);
128 int convert_nv12(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture, stream_t::pointer stream, const viewport_t &viewport);
129 int convert_yuv444(std::uint8_t *Y, std::uint8_t *U, std::uint8_t *V, std::uint32_t pitch, cudaTextureObject_t texture, stream_t::pointer stream);
130 int convert_yuv444(std::uint8_t *Y, std::uint8_t *U, std::uint8_t *V, std::uint32_t pitch, cudaTextureObject_t texture, stream_t::pointer stream, const viewport_t &viewport);
131
132 void apply_colorspace(const video::sunshine_colorspace_t &colorspace);
133
134 int load_ram(platf::img_t &img, cudaArray_t array);
135
136 ptr_t color_matrix;
137
138 int threadsPerBlock;
139
140 viewport_t viewport;
141
142 float scale;
143 };
144} // namespace cuda
145
146#endif
std::vector< std::string > display_names(mem_type_e hwdevice_type)
List display names accepted by the selected capture backend.
Definition misc.cpp:1312
std::unique_ptr< platf::avcodec_encode_device_t > make_avcodec_encode_device(int width, int height, bool vram)
Create AVCodec encode device.
Definition cuda.cpp:655
int init()
Map CUDA graphics resources for use as an image.
Definition cuda.cpp:143
std::unique_ptr< platf::avcodec_encode_device_t > make_avcodec_gl_encode_device(int width, int height, int offset_x, int offset_y)
Create a GL->CUDA encoding device for consuming captured dmabufs.
Definition cuda.cpp:683
@ linear
Linear scRGB input; apply the sRGB curve.
Definition display.h:194
util::safe_ptr< T, free< T > > ptr_t
Owning pointer for Avahi allocations released with avahi_free.
Definition publish.cpp:386
AVCodec-backed encode device and frame state.
Definition common.h:594
Captured frame buffer shared between capture and encode stages.
Definition common.h:530
util::safe_ptr< SwsContext, &sws_freeContext > sws_t
Owning pointer for an FFmpeg software-scaling context released with sws_freeContext().
Definition video.h:120
Declarations for colorspace functions.
@ copy
Ask for a frame now.
Definition wayland.h:104