Debian Codegraph @

components/encoder/fdkaac/config.cpp

raw symbols SCIP
1 /* BoCA - BonkEnc Component Architecture
2 * Copyright (C) 2007-2025 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include "config.h"
14 #include "dllinterface.h"
15
16 const String BoCA::ConfigureFDKAAC::ConfigID = "FDKAAC";
17
18 BoCA::ConfigureFDKAAC::ConfigureFDKAAC()
19 {
20 const Config *config = Config::Get();
21
22 Int aacType = config->GetIntValue(ConfigID, "AACType", AOT_AAC_LC);
23
24 mpegVersion = config->GetIntValue(ConfigID, "MPEGVersion", 0);
25 mode = config->GetIntValue(ConfigID, "Mode", 0);
26 bitrate = config->GetIntValue(ConfigID, "Bitrate", 64);
27 quality = config->GetIntValue(ConfigID, "Quality", 4);
28 afterburner = config->GetIntValue(ConfigID, "Afterburner", True);
29 bandwidth = config->GetIntValue(ConfigID, "Bandwidth", 0);
30 allowID3 = config->GetIntValue(ConfigID, "AllowID3v2", False);
31 fileFormat = config->GetIntValue(ConfigID, "MP4Container", True);
32 fileExtension = config->GetIntValue(ConfigID, "MP4FileExtension", 0);
33
34 if (bandwidth) bandwidth = (bandwidth - 7900) / 100;
35
36 previousBandwidth = 0;
37
38 I18n *i18n = I18n::Get();
39
40 tabwidget = new TabWidget(Point(7, 7), Size(500, 258));
41
42 i18n->SetContext("Encoders::AAC::Format");
43
44 layer_format = new Layer(i18n->TranslateString("Format"));
45
46 group_mp4 = new GroupBox(i18n->TranslateString("File format"), Point(7, 11), Size(120, 65));
47
48 option_mp4 = new OptionBox("MP4", Point(10, 13), Size(99, 0), &fileFormat, 1);
49 option_mp4->onAction.Connect(&ConfigureFDKAAC::SetFileFormat, this);
50
51 if (mp4v2dll == NIL)
52 {
53 option_mp4->Deactivate();
54
55 fileFormat = 0;
56 }
57
58 option_aac = new OptionBox("AAC", Point(10, 38), Size(99, 0), &fileFormat, 0);
59 option_aac->onAction.Connect(&ConfigureFDKAAC::SetFileFormat, this);
60
61 group_mp4->Add(option_mp4);
62 group_mp4->Add(option_aac);
63
64 group_version = new GroupBox(i18n->TranslateString("MPEG version"), Point(135, 11), Size(120, 65));
65
66 option_version_mpeg2 = new OptionBox("MPEG 2", Point(10, 13), Size(group_version->GetWidth() - 21, 0), &mpegVersion, 127);
67 option_version_mpeg2->onAction.Connect(&ConfigureFDKAAC::SetMPEGVersion, this);
68
69 option_version_mpeg4 = new OptionBox("MPEG 4", Point(10, 38), Size(group_version->GetWidth() - 21, 0), &mpegVersion, 0);
70 option_version_mpeg4->onAction.Connect(&ConfigureFDKAAC::SetMPEGVersion, this);
71
72 group_version->Add(option_version_mpeg2);
73 group_version->Add(option_version_mpeg4);
74
75 group_id3v2 = new GroupBox(i18n->TranslateString("Tags"), Point(7, 88), Size(279, 90));
76
77 check_id3v2 = new CheckBox(i18n->TranslateString("Allow ID3v2 tags in AAC files"), Point(10, 13), Size(200, 0), &allowID3);
78 check_id3v2->SetWidth(check_id3v2->GetUnscaledTextWidth() + 20);
79
80 text_note = new Text(i18n->AddColon(i18n->TranslateString("Note")), Point(10, 38));
81 text_id3v2 = new Text(i18n->TranslateString("Some players may have problems playing AAC\nfiles with ID3 tags attached. Please use this option only\nif you are sure that your player can handle these tags."), Point(text_note->GetUnscaledTextWidth() + 12, 38));
82
83 group_id3v2->SetSize(Size(Math::Max(384, text_note->GetUnscaledTextWidth() + text_id3v2->GetUnscaledTextWidth() + 22), Math::Max(text_note->GetUnscaledTextHeight(), text_id3v2->GetUnscaledTextHeight()) + 48));
84
85 group_id3v2->Add(check_id3v2);
86 group_id3v2->Add(text_note);
87 group_id3v2->Add(text_id3v2);
88
89 group_extension = new GroupBox(i18n->TranslateString("File extension"), Point(263, 11), Size(group_id3v2->GetWidth() - 256, 65));
90
91 option_extension_m4a = new OptionBox(".m4a", Point(10, 13), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 0);
92 option_extension_m4b = new OptionBox(".m4b", Point(10, 38), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 1);
93 option_extension_m4r = new OptionBox(".m4r", Point(group_extension->GetWidth() / 2 + 4, 13), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 2);
94 option_extension_mp4 = new OptionBox(".mp4", Point(group_extension->GetWidth() / 2 + 4, 38), Size(group_extension->GetWidth() / 2 - 14, 0), &fileExtension, 3);
95
96 group_extension->Add(option_extension_m4a);
97 group_extension->Add(option_extension_m4b);
98 group_extension->Add(option_extension_m4r);
99 group_extension->Add(option_extension_mp4);
100
101 i18n->SetContext("Encoders::AAC::Codec");
102
103 layer_quality = new Layer(i18n->TranslateString("Codec"));
104
105 group_codec = new GroupBox(i18n->TranslateString("Audio codec"), Point(7, 11), Size(group_id3v2->GetWidth(), 43));
106
107 text_codec = new Text(i18n->AddColon(i18n->TranslateString("Audio codec")), Point(10, 15));
108
109 combo_codec = new ComboBox(Point(text_codec->GetUnscaledTextSize().cx + 17, 12), Size(group_codec->GetWidth() - text_codec->GetUnscaledTextSize().cx - 27, 0));
110
111 FillCodecs();
112
113 foreach (Int codec, codecs) if (aacType == codec) combo_codec->SelectNthEntry(foreachindex);
114
115 combo_codec->onSelectEntry.Connect(&ConfigureFDKAAC::SetCodec, this);
116
117 group_codec->Add(text_codec);
118 group_codec->Add(combo_codec);
119
120 i18n->SetContext("Encoders::AAC::Quality");
121
122 group_bitrate = new GroupBox(i18n->TranslateString("Bitrate / Quality"), Point(7, 66), Size(group_id3v2->GetWidth(), 103));
123
124 option_bitrate = new OptionBox(i18n->AddColon(i18n->TranslateString("Bitrate per channel")), Point(10, 13), Size(150, 0), &mode, 0);
125 option_bitrate->onAction.Connect(&ConfigureFDKAAC::SetMode, this);
126 option_bitrate->SetWidth(option_bitrate->GetUnscaledTextWidth() + 19);
127
128 text_bitrate_kbps = new Text(i18n->TranslateString("%1 kbps", "Technical").Replace("%1", NIL).Trim(), Point(35, 15));
129 text_bitrate_kbps->SetX(text_bitrate_kbps->GetUnscaledTextWidth() + 10);
130 text_bitrate_kbps->SetOrientation(OR_UPPERRIGHT);
131
132 edit_bitrate = new EditBox(Point(text_bitrate_kbps->GetX() + 32, 12), Size(25, 0), 3);
133 edit_bitrate->SetFlags(EDB_NUMERIC);
134 edit_bitrate->SetOrientation(OR_UPPERRIGHT);
135 edit_bitrate->onInput.Connect(&ConfigureFDKAAC::SetBitrateByEditBox, this);
136
137 slider_bitrate = new Slider(Point(option_bitrate->GetWidth() + 18, 13), Size(group_bitrate->GetWidth() - edit_bitrate->GetX() - 26 - option_bitrate->GetWidth(), 0), OR_HORZ, &bitrate, 8, 256);
138 slider_bitrate->onValueChange.Connect(&ConfigureFDKAAC::SetBitrate, this);
139
140 option_quality = new OptionBox(i18n->AddColon(i18n->TranslateString("Set quality")), Point(10, 38), Size(150, 0), &mode, 1);
141 option_quality->onAction.Connect(&ConfigureFDKAAC::SetMode, this);
142 option_quality->SetWidth(option_bitrate->GetWidth());
143
144 slider_quality = new Slider(Point(option_quality->GetWidth() + 18, 38), Size(slider_bitrate->GetWidth(), 0), OR_HORZ, &quality, 1, 5);
145 slider_quality->onValueChange.Connect(&ConfigureFDKAAC::SetQuality, this);
146
147 text_quality_level = new Text(NIL, Point(edit_bitrate->GetX(), 40));
148 text_quality_level->SetOrientation(OR_UPPERRIGHT);
149
150 text_quality_worse = new Text(i18n->TranslateString("worse"), Point(slider_quality->GetX(), 57));
151 text_quality_worse->SetX(text_quality_worse->GetX() - text_quality_worse->GetUnscaledTextWidth() / 2);
152
153 text_quality_better = new Text(i18n->TranslateString("better"), Point(slider_quality->GetX() + slider_quality->GetWidth(), 57));
154 text_quality_better->SetX(text_quality_better->GetX() - text_quality_better->GetUnscaledTextWidth() / 2);
155
156 check_afterburner = new CheckBox(i18n->TranslateString("Enable Afterburner processing"), Point(10, 76), Size(group_bitrate->GetWidth() - 20, 0), &afterburner);
157
158 group_bitrate->Add(option_bitrate);
159 group_bitrate->Add(slider_bitrate);
160 group_bitrate->Add(edit_bitrate);
161 group_bitrate->Add(text_bitrate_kbps);
162 group_bitrate->Add(option_quality);
163 group_bitrate->Add(slider_quality);
164 group_bitrate->Add(text_quality_level);
165 group_bitrate->Add(text_quality_worse);
166 group_bitrate->Add(text_quality_better);
167 group_bitrate->Add(check_afterburner);
168
169 group_bandwidth = new GroupBox(i18n->TranslateString("Maximum bandwidth"), Point(7, group_bitrate->GetHeight() + 78), Size(group_id3v2->GetWidth(), 40));
170
171 text_bandwidth = new Text(i18n->AddColon(i18n->TranslateString("Maximum AAC frequency bandwidth to use (Hz)")), Point(9, 15));
172
173 text_bandwidth_hz = new Text(i18n->TranslateString("%1 Hz", "Technical").Replace("%1", "20000"), Point(35, 15));
174 text_bandwidth_hz->SetX(Math::Max(text_bandwidth_hz->GetUnscaledTextWidth(), text_bandwidth_hz->GetFont().GetUnscaledTextSizeX(i18n->TranslateString("auto"))) + 10);
175 text_bandwidth_hz->SetOrientation(OR_UPPERRIGHT);
176
177 slider_bandwidth = new Slider(Point(text_bandwidth->GetUnscaledTextWidth() + 16, 13), Size(group_bandwidth->GetWidth() - text_bandwidth->GetUnscaledTextWidth() - text_bandwidth_hz->GetX() - 24, 0), OR_HORZ, &bandwidth, 0, 121);
178 slider_bandwidth->onValueChange.Connect(&ConfigureFDKAAC::SetBandwidth, this);
179
180 group_bandwidth->Add(text_bandwidth);
181 group_bandwidth->Add(slider_bandwidth);
182 group_bandwidth->Add(text_bandwidth_hz);
183
184 SetCodec();
185 SetFileFormat();
186 SetMPEGVersion();
187 SetMode();
188 SetBitrate();
189 SetQuality();
190 SetBandwidth();
191
192 tabwidget->SetSize(Size(group_id3v2->GetWidth() + 18, Math::Max(251, group_id3v2->GetHeight() + 118)));
193
194 Add(tabwidget);
195
196 tabwidget->Add(layer_quality);
197 tabwidget->Add(layer_format);
198
199 layer_format->Add(group_version);
200 layer_format->Add(group_mp4);
201 layer_format->Add(group_extension);
202 layer_format->Add(group_id3v2);
203
204 layer_quality->Add(group_codec);
205 layer_quality->Add(group_bitrate);
206 layer_quality->Add(group_bandwidth);
207
208 SetSize(tabwidget->GetSize() + Size(14, 14));
209 }
210
211 BoCA::ConfigureFDKAAC::~ConfigureFDKAAC()
212 {
213 DeleteObject(tabwidget);
214 DeleteObject(layer_format);
215 DeleteObject(layer_quality);
216
217 DeleteObject(group_version);
218 DeleteObject(option_version_mpeg2);
219 DeleteObject(option_version_mpeg4);
220 DeleteObject(group_mp4);
221 DeleteObject(option_mp4);
222 DeleteObject(option_aac);
223 DeleteObject(group_extension);
224 DeleteObject(option_extension_m4a);
225 DeleteObject(option_extension_m4b);
226 DeleteObject(option_extension_m4r);
227 DeleteObject(option_extension_mp4);
228 DeleteObject(group_id3v2);
229 DeleteObject(check_id3v2);
230 DeleteObject(text_note);
231 DeleteObject(text_id3v2);
232
233 DeleteObject(group_codec);
234 DeleteObject(text_codec);
235 DeleteObject(combo_codec);
236 DeleteObject(group_bitrate);
237 DeleteObject(option_bitrate);
238 DeleteObject(slider_bitrate);
239 DeleteObject(edit_bitrate);
240 DeleteObject(text_bitrate_kbps);
241 DeleteObject(option_quality);
242 DeleteObject(slider_quality);
243 DeleteObject(text_quality_level);
244 DeleteObject(text_quality_worse);
245 DeleteObject(text_quality_better);
246 DeleteObject(check_afterburner);
247
248 DeleteObject(group_bandwidth);
249 DeleteObject(text_bandwidth);
250 DeleteObject(slider_bandwidth);
251 DeleteObject(text_bandwidth_hz);
252 }
253
254 Int BoCA::ConfigureFDKAAC::SaveSettings()
255 {
256 Config *config = Config::Get();
257
258 if (bitrate < 8) bitrate = 8;
259 if (bitrate > 256) bitrate = 256;
260
261 Int aacType = codecs.GetNth(combo_codec->GetSelectedEntryNumber());
262
263 if (aacType != AOT_AAC_LC &&
264 aacType != AOT_ER_AAC_LD) bandwidth = previousBandwidth;
265
266 if (bandwidth) bandwidth = 7900 + 100 * bandwidth;
267
268 config->SetIntValue(ConfigID, "MPEGVersion", mpegVersion);
269 config->SetIntValue(ConfigID, "AACType", aacType);
270 config->SetIntValue(ConfigID, "Mode", mode);
271 config->SetIntValue(ConfigID, "Bitrate", bitrate);
272 config->SetIntValue(ConfigID, "Quality", quality);
273 config->SetIntValue(ConfigID, "Afterburner", afterburner);
274 config->SetIntValue(ConfigID, "Bandwidth", bandwidth);
275 config->SetIntValue(ConfigID, "AllowID3v2", allowID3);
276 config->SetIntValue(ConfigID, "MP4Container", fileFormat);
277 config->SetIntValue(ConfigID, "MP4FileExtension", fileExtension);
278
279 return Success();
280 }
281
282 Void BoCA::ConfigureFDKAAC::FillCodecs()
283 {
284 LIB_INFO info[FDK_MODULE_LAST];
285
286 FDKinitLibInfo(info);
287 ex_aacEncGetLibInfo(info);
288
289 UINT sbrFlags = FDKlibInfo_getCapabilities(info, FDK_SBRENC);
290
291 codecs.RemoveAll();
292 combo_codec->RemoveAllEntries();
293
294 { combo_codec->AddEntry("MPEG AAC Low Complexity"); codecs.Add(AOT_AAC_LC); }
295
296 if (sbrFlags ) { combo_codec->AddEntry("MPEG AAC High Efficiency"); codecs.Add(AOT_SBR); }
297 if (sbrFlags & CAPF_SBR_PS_MPEG ) { combo_codec->AddEntry("MPEG AAC High Efficiency v2"); codecs.Add(AOT_PS); }
298
299 if (mpegVersion == 0 ) { combo_codec->AddEntry("MPEG AAC Low Delay"); codecs.Add(AOT_ER_AAC_LD); }
300 if (mpegVersion == 0 && sbrFlags) { combo_codec->AddEntry("MPEG AAC Enhanced Low Delay"); codecs.Add(AOT_ER_AAC_ELD); }
301 }
302
303 Void BoCA::ConfigureFDKAAC::SetMPEGVersion()
304 {
305 Int aacType = codecs.GetNth(combo_codec->GetSelectedEntryNumber());
306
307 FillCodecs();
308
309 if (mpegVersion == 127 && (aacType == AOT_ER_AAC_LD || aacType == AOT_ER_AAC_ELD)) aacType = AOT_AAC_LC;
310
311 foreach (Int codec, codecs) if (aacType == codec) combo_codec->SelectNthEntry(foreachindex);
312 }
313
314 Void BoCA::ConfigureFDKAAC::SetCodec()
315 {
316 Int aacType = codecs.GetNth(combo_codec->GetSelectedEntryNumber());
317
318 if (aacType == AOT_ER_AAC_LD ||
319 aacType == AOT_ER_AAC_ELD) option_version_mpeg2->Deactivate();
320 else option_version_mpeg2->Activate();
321
322 /* Toggle bandwidth controls.
323 */
324 if (aacType == AOT_AAC_LC || aacType == AOT_ER_AAC_LD)
325 {
326 if (!group_bandwidth->IsActive()) bandwidth = previousBandwidth;
327
328 group_bandwidth->Activate();
329 }
330 else
331 {
332 if (group_bandwidth->IsActive()) previousBandwidth = bandwidth;
333
334 group_bandwidth->Deactivate();
335
336 bandwidth = 0;
337 }
338
339 SetQuality();
340 SetBandwidth();
341
342 /* Set bitrate range for AAC type.
343 */
344 switch (aacType)
345 {
346 case AOT_AAC_LC:
347 slider_bitrate->SetRange(8, 256);
348 slider_quality->SetRange(3, 5);
349
350 break;
351 case AOT_SBR:
352 slider_bitrate->SetRange(8, 64);
353 slider_quality->SetRange(2, 5);
354
355 break;
356 case AOT_PS:
357 slider_bitrate->SetRange(8, 32);
358 slider_quality->SetRange(1, 5);
359
360 break;
361 case AOT_ER_AAC_LD:
362 slider_bitrate->SetRange(8, 256);
363 slider_quality->SetRange(3, 5);
364
365 break;
366 case AOT_ER_AAC_ELD:
367 slider_bitrate->SetRange(8, 256);
368 slider_quality->SetRange(1, 5);
369
370 break;
371 }
372
373 SetBitrate();
374 }
375
376 Void BoCA::ConfigureFDKAAC::SetMode()
377 {
378 if (mode == 0) // bitrate
379 {
380 slider_quality->Deactivate();
381 text_quality_level->Deactivate();
382 text_quality_worse->Deactivate();
383 text_quality_better->Deactivate();
384
385 slider_bitrate->Activate();
386 edit_bitrate->Activate();
387 text_bitrate_kbps->Activate();
388 }
389 else // quality
390 {
391 slider_bitrate->Deactivate();
392 edit_bitrate->Deactivate();
393 text_bitrate_kbps->Deactivate();
394
395 slider_quality->Activate();
396 text_quality_level->Activate();
397 text_quality_worse->Activate();
398 text_quality_better->Activate();
399 }
400 }
401
402 Void BoCA::ConfigureFDKAAC::SetBitrate()
403 {
404 if (!edit_bitrate->IsFocussed()) edit_bitrate->SetText(String::FromInt(bitrate));
405 }
406
407 Void BoCA::ConfigureFDKAAC::SetBitrateByEditBox()
408 {
409 slider_bitrate->SetValue(edit_bitrate->GetText().ToInt());
410 }
411
412 Void BoCA::ConfigureFDKAAC::SetQuality()
413 {
414 text_quality_level->SetText(String::FromInt(quality));
415 }
416
417 Void BoCA::ConfigureFDKAAC::SetBandwidth()
418 {
419 I18n *i18n = I18n::Get();
420
421 i18n->SetContext("Encoders::AAC::Quality");
422
423 if (bandwidth) text_bandwidth_hz->SetText(i18n->TranslateString("%1 Hz", "Technical").Replace("%1", String::FromInt(7900 + 100 * bandwidth)));
424 else text_bandwidth_hz->SetText(i18n->TranslateString("auto"));
425 }
426
427 Void BoCA::ConfigureFDKAAC::SetFileFormat()
428 {
429 if (fileFormat == 1) // MP4 container
430 {
431 group_version->Deactivate();
432 group_id3v2->Deactivate();
433
434 group_extension->Activate();
435
436 if (mpegVersion == 127) // MPEG2
437 {
438 mpegVersion = 0;
439
440 SetMPEGVersion();
441 }
442 }
443 else // raw AAC file format
444 {
445 group_version->Activate();
446 group_id3v2->Activate();
447
448 group_extension->Deactivate();
449 }
450 }