-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuisettings_controller.cpp
More file actions
165 lines (134 loc) · 5.11 KB
/
uisettings_controller.cpp
File metadata and controls
165 lines (134 loc) · 5.11 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "ffmpeg_encoder.h"
UISettingsController::UISettingsController(const EncoderInfo& encoderInfo) : encoderInfo(encoderInfo) {
InitDefaults();
}
UISettingsController::UISettingsController(const HostCodecConfigCommon& commonProps, const EncoderInfo& encoderInfo)
: commonProps(commonProps), encoderInfo(encoderInfo) {
InitDefaults();
}
void UISettingsController::Load(IPropertyProvider* values) {
uint8_t val8 = 0;
values->GetUINT8("ffmpeg_reset", val8);
if (val8 != 0) {
*this = UISettingsController(encoderInfo);
return;
}
int32_t val32 = 0;
values->GetINT32(qualityModeId.c_str(), val32);
qualityMode = static_cast<QualityMode>(val32);
SetFirstSupportedQualityMode();
values->GetINT32(qpId.c_str(), qp);
values->GetINT32(bitrateId.c_str(), bitRate);
values->GetINT32(presetId.c_str(), preset);
}
StatusCode UISettingsController::Render(HostListRef* settingsList) const {
StatusCode err = RenderQuality(settingsList);
if (err != errNone) {
return err;
}
{
HostUIConfigEntryRef item("ffmpeg_reset");
item.MakeButton("Reset");
item.SetTriggersUpdate(true);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate the button entry");
return errFail;
}
}
return errNone;
}
void UISettingsController::InitDefaults() {
qualityMode = CRF;
SetFirstSupportedQualityMode();
qp = encoderInfo.qp[1];
bitRate = 6000;
preset = encoderInfo.defaultPreset;
const std::string prefix = std::string("ffmpeg_") + encoderInfo.encoder + "_";
qualityModeId = prefix + "q_mode";
qpId = prefix + "qp";
bitrateId = prefix + "bitrate";
presetId = prefix + "preset";
}
void UISettingsController::SetFirstSupportedQualityMode() {
if (!(qualityMode & encoderInfo.qualityModes)) {
if (encoderInfo.qualityModes & CRF)
qualityMode = CRF;
else if (encoderInfo.qualityModes & CQP)
qualityMode = CQP;
else if (encoderInfo.qualityModes & VBR)
qualityMode = VBR;
}
}
StatusCode UISettingsController::RenderQuality(HostListRef* settingsList) const {
{
HostUIConfigEntryRef item(presetId);
std::vector<std::string> textsVec;
std::vector<int> valuesVec;
for (const auto& [key, value] : encoderInfo.presets) {
valuesVec.push_back(key);
textsVec.emplace_back(value);
}
item.MakeComboBox("Encoder Preset", textsVec, valuesVec, preset);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate encoder preset UI entry");
return errFail;
}
}
{
HostUIConfigEntryRef item(qualityModeId);
std::vector<std::string> textsVec;
std::vector<int> valuesVec;
if (encoderInfo.qualityModes & CRF) {
textsVec.emplace_back("Constant Rate Factor");
valuesVec.push_back(CRF);
}
if (encoderInfo.qualityModes & CQP) {
textsVec.emplace_back("Constant Quality");
valuesVec.push_back(CQP);
}
if (encoderInfo.qualityModes & VBR) {
textsVec.emplace_back("Variable Rate");
valuesVec.push_back(VBR);
}
item.MakeRadioBox("Quality Control", textsVec, valuesVec, qualityMode);
item.SetTriggersUpdate(true);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate quality UI entry");
return errFail;
}
}
{
HostUIConfigEntryRef item(qpId);
const char* pLabel = nullptr;
if (encoderInfo.hwAcceleration == Nvenc && qp == 0) {
pLabel = "(automatic)";
} else if (qp < encoderInfo.qp[2] / 3) {
pLabel = "(high)";
} else if (qp < encoderInfo.qp[2] * 2 / 3) {
pLabel = "(medium)";
} else {
pLabel = "(low)";
}
item.MakeSlider("Factor", pLabel, qp, encoderInfo.qp[0], encoderInfo.qp[2], encoderInfo.qp[1]);
item.SetTriggersUpdate(true);
item.SetHidden(qualityMode == VBR);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate qp slider UI entry");
return errFail;
}
}
{
HostUIConfigEntryRef item(bitrateId);
item.MakeSlider("Bit Rate", "kb/s", bitRate, 100, 100000, 1);
item.SetHidden(qualityMode != VBR);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate bitrate slider UI entry");
return errFail;
}
}
return errNone;
}
QualityMode UISettingsController::GetQualityMode() const { return qualityMode; }
int32_t UISettingsController::GetQP() const { return std::max<int>(0, qp); }
int32_t UISettingsController::GetBitRate() const { return bitRate * 1000; }
int32_t UISettingsController::GetPreset() const { return preset; }