-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyroenc.hpp
143 lines (115 loc) · 2.31 KB
/
pyroenc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) 2024 Arntzen Software AS
// SPDX-License-Identifier: MIT
#pragma once
#include <vulkan/vulkan.h>
#include <memory>
namespace PyroEnc
{
struct QueueInfo
{
VkQueue queue;
uint32_t family_index;
};
enum class Profile
{
H264_High
};
struct EncoderCreateInfo
{
PFN_vkGetInstanceProcAddr get_instance_proc_addr;
VkInstance instance;
VkPhysicalDevice gpu;
VkDevice device;
QueueInfo conversion_queue;
QueueInfo encode_queue;
uint32_t width;
uint32_t height;
Profile profile;
uint32_t frame_rate_num;
uint32_t frame_rate_den;
float quality_level;
struct
{
VkVideoEncodeTuningModeKHR tuning;
VkVideoEncodeContentFlagsKHR content;
VkVideoEncodeUsageFlagsKHR usage;
} hints;
};
struct FrameInfo
{
VkImageView view;
uint32_t width;
uint32_t height;
int64_t pts;
bool force_idr;
};
enum class RateControlMode
{
VBR,
CBR,
ConstantQP
};
struct RateControlInfo
{
uint32_t bitrate_kbits;
uint32_t max_bitrate_kbits;
int32_t constant_qp;
uint32_t gop_frames;
RateControlMode mode;
};
struct EncodedFrame
{
EncodedFrame();
~EncodedFrame();
int64_t get_pts() const;
int64_t get_dts() const;
bool wait(uint64_t timeout = UINT64_MAX) const;
size_t get_size() const;
const void *get_payload() const;
VkQueryResultStatusKHR get_status() const;
bool is_idr() const;
EncodedFrame(EncodedFrame &&other) noexcept;
EncodedFrame &operator=(EncodedFrame &&other) noexcept;
struct Impl;
Impl &get_impl();
private:
std::unique_ptr<Impl> impl;
};
enum class Severity
{
Debug,
Warn,
Error
};
enum class Result : int
{
Success = 1,
NotReady = 0,
Error = -1
};
struct LogCallback
{
virtual ~LogCallback() = default;
virtual void log(Severity severity, const char *msg) = 0;
};
class Encoder
{
public:
Encoder();
~Encoder();
void set_log_callback(LogCallback *cb);
Result init_encoder(const EncoderCreateInfo &info);
bool set_rate_control_info(const RateControlInfo &info);
Result send_frame(const FrameInfo &info);
Result send_eof();
Result receive_encoded_frame(EncodedFrame &frame);
VkPipelineStageFlags2 get_conversion_dst_stage() const;
VkAccessFlags2 get_conversion_dst_access() const;
VkImageLayout get_conversion_image_layout() const;
const void *get_encoded_parameters() const;
size_t get_encoded_parameters_size() const;
struct Impl;
private:
std::unique_ptr<Impl> impl;
};
}