UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
Settings Class Reference

#include <settings.hpp>

Collaboration diagram for Settings:
Collaboration graph

Public Member Functions

 Settings ()
 
Option & addOption (std::string name, Option::OptType type, const std::string &param, const std::string &value="", bool enabled=true, const std::string &parent="", const std::string &limit="")
 
void changedAll ()
 
std::string getControlPort () const
 
std::string getLaunchParams () const
 
Option & getOption (const std::string &opt)
 
const Option & getOption (const std::string &opt) const
 
const std::map< std::string, std::unique_ptr< Option > > & getOptionMap () const
 
std::string getPreviewParams () const
 
const std::string & getSessRndKey () const
 
bool isAdvancedMode ()
 
void populateSettingsFromCapabilities (AvailableSettings *availSettings)
 

Private Member Functions

void populateDeviceSettings (AvailableSettings *availSettings)
 
void populateVideoCompressSettings (AvailableSettings *availSettings)
 

Private Attributes

const Option dummy
 
std::map< std::string, std::unique_ptr< Option > > options
 
std::string sessRndKey
 

Detailed Description

Definition at line 91 of file settings.hpp.

Constructor & Destructor Documentation

◆ Settings()

Settings::Settings ( )

Definition at line 258 of file settings.cpp.

258 : dummy(this){
259 std::random_device rd;
260 std::mt19937 gen(rd());
261 std::uniform_int_distribution<> bounds(0, ('9' - '0') + ('z' - 'a'));
262 for(int i = 0; i < 8; i++){
263 int rand = bounds(gen);
264 if(rand <= 9)
265 sessRndKey += '0' + rand;
266 else
267 sessRndKey += 'a' + (rand - 9);
268 }
269
270 for(const auto &i : optionList){
271 auto &opt = addOption(i.name,
272 i.type,
273 i.param,
274 i.defaultVal,
275 i.enabled,
276 i.parent,
277 i.limit);
278#ifdef DEBUG
279 if(!i.parent[0])
280 opt.addOnChangeCallback(Option::Callback(test_callback, nullptr));
281#endif
282 (void) opt; //suppress unused warning
283 }
284
285 for(const auto &i : optionCallbacks){
286 getOption(i.name).addOnChangeCallback(Option::Callback(i.callback, nullptr));
287 }
288
289 std::cout << getLaunchParams() << std::endl;
290}
void addOnChangeCallback(Callback callback)
Definition settings.cpp:107
const Option & getOption(const std::string &opt) const
Definition settings.cpp:384
std::string getLaunchParams() const
Definition settings.cpp:299
std::string sessRndKey
Definition settings.hpp:126
const Option dummy
Definition settings.hpp:128
Option & addOption(std::string name, Option::OptType type, const std::string &param, const std::string &value="", bool enabled=true, const std::string &parent="", const std::string &limit="")
Definition settings.cpp:397
static const struct @0 optionList[]
const struct @1 optionCallbacks[]

References Option::addOnChangeCallback(), addOption(), getLaunchParams(), getOption(), optionCallbacks, optionList, and sessRndKey.

Here is the call graph for this function:

Member Function Documentation

◆ addOption()

Option & Settings::addOption ( std::string name,
Option::OptType type,
const std::string & param,
const std::string & value = "",
bool enabled = true,
const std::string & parent = "",
const std::string & limit = "" )

Definition at line 397 of file settings.cpp.

404{
405 if(!parent.empty())
406 name = parent + "." + name;
407
408 auto search = options.find(name);
409
410 Option *opt;
411
412 if(search == options.end()){
413 std::unique_ptr<Option> newOption(new Option(this, name));
414 opt = newOption.get();
415 options[name] = std::move(newOption);
416 } else {
417 opt = search->second.get();
418 }
419
420 opt->setParam(param);
421 opt->setType(type);
422 opt->setValue(value);
423 opt->setDefaultValue(value);
424 opt->setEnabled(enabled);
425
426 if(!parent.empty()){
428 }
429
430 return *opt;
431}
void setType(OptType type)
Definition settings.hpp:64
void setParam(const std::string &p)
Definition settings.hpp:59
void setEnabled(bool enable, bool suppressCallback=false)
Definition settings.cpp:90
void addSuboption(Option *sub, const std::string &limit="")
Definition settings.cpp:96
virtual void setValue(const std::string &val, bool suppressCallback=false)
Definition settings.cpp:73
virtual void setDefaultValue(const std::string &val)
Definition settings.cpp:86
const char * parent
Definition settings.cpp:198
Option::OptType type
Definition settings.cpp:194
bool enabled
Definition settings.cpp:197
const char * param
Definition settings.cpp:195
const char * name
Definition settings.cpp:193
const char * limit
Definition settings.cpp:199
Definition rtp.c:253

References Option::addSuboption(), enabled, getOption(), limit, name, param, parent, Option::setDefaultValue(), Option::setEnabled(), Option::setParam(), Option::setType(), Option::setValue(), and type.

Referenced by Settings(), addDevOpt(), populateDeviceSettings(), and populateVideoCompressSettings().

Here is the call graph for this function:

◆ changedAll()

void Settings::changedAll ( )

Definition at line 437 of file settings.cpp.

437 {
438 for(auto &i : options){
439 i.second->changed();
440 }
441}

Referenced by UltragridWindow::loadSettingsFile().

◆ getControlPort()

std::string Settings::getControlPort ( ) const

Definition at line 292 of file settings.cpp.

292 {
293 if(getOption("network.control_port.random").isEnabled())
294 return "0";
295
296 return getOption("network.control_port").getValue();
297}
std::string getValue() const
Definition settings.cpp:26

References getOption(), and Option::getValue().

Referenced by getLaunchParams(), and getPreviewParams().

Here is the call graph for this function:

◆ getLaunchParams()

std::string Settings::getLaunchParams ( ) const

Definition at line 299 of file settings.cpp.

299 {
300 std::string out;
301
302 out += getOption("extraOpts").getLaunchOption();
303
304 if(getOption("preview").isEnabled()){
305 out += " --capture-filter preview";
306 out += ":key=" + getSessRndKey();
307 }
308
309 out += getOption("video.source").getLaunchOption();
310 out += getOption("video.compress").getLaunchOption();
311 const auto &dispOpt = getOption("video.display");
312 if(dispOpt.isEnabled()){
313 if(getOption("preview").isEnabled()){
314 out += dispOpt.getParam();
315 out += "multiplier:" + dispOpt.getValue() + dispOpt.getSubVals();
316 out += "#preview";
317 out += ":key=" + getSessRndKey();
318 } else {
319 out += getOption("video.display").getLaunchOption();
320 }
321 } else {
322 if(getOption("preview").isEnabled()){
323 out += dispOpt.getParam();
324 out += "preview";
325 out += ":key=" + getSessRndKey();
326 }
327 }
328
329 out += " --audio-filter controlport_stats";
330 out += getOption("audio.source").getLaunchOption();
331 out += getOption("audio.source.channels").getLaunchOption();
332 out += getOption("audio.compress").getLaunchOption();
333 std::string audioPlay = getOption("audio.playback").getLaunchOption();
334 if(audioPlay.empty() && getOption("preview").isEnabled()){
335 audioPlay = " -r dummy";
336 }
337 out += audioPlay;
338 out += getOption("network.fec").getLaunchOption();
339 out += getOption("encryption").getLaunchOption();
340 out += getOption("network.port").getLaunchOption();
341 out += getOption("network.control_port").getParam();
342 out += getControlPort();
343 out += getOption("network.destination").getLaunchOption();
344 out += getOption("decode.hwaccel").getLaunchOption();
345 out += getOption("errors_fatal").getLaunchOption();
346 return out;
347}
virtual std::string getLaunchOption() const
Definition settings.cpp:46
std::string getParam() const
Definition settings.cpp:30
const std::string & getSessRndKey() const
Definition settings.hpp:117
std::string getControlPort() const
Definition settings.cpp:292

References getControlPort(), Option::getLaunchOption(), getOption(), Option::getParam(), and getSessRndKey().

Referenced by Settings(), UltragridWindow::setArgs(), and SettingsUi::test().

Here is the call graph for this function:

◆ getOption() [1/2]

Option & Settings::getOption ( const std::string & opt)

Definition at line 371 of file settings.cpp.

371 {
372 auto search = options.find(opt);
373
374 if(search == options.end()){
375 std::unique_ptr<Option> newOption(new Option(this, opt));
376 auto p = newOption.get();
377 options[opt] = std::move(newOption);
378 return *p;
379 }
380
381 return *search->second;
382}

◆ getOption() [2/2]

◆ getOptionMap()

const std::map< std::string, std::unique_ptr< Option > > & Settings::getOptionMap ( ) const

Definition at line 393 of file settings.cpp.

393 {
394 return options;
395}
std::map< std::string, std::unique_ptr< Option > > options
Definition settings.hpp:124

References options.

Referenced by UltragridWindow::saveSettings().

◆ getPreviewParams()

std::string Settings::getPreviewParams ( ) const

Definition at line 349 of file settings.cpp.

349 {
350 std::string out;
351
352 out += getOption("extraOpts").getLaunchOption();
353
354 out += " --capture-filter preview";
355 out += ":key=" + getSessRndKey();
356 out += ",every:0";
357 out += getOption("video.source").getLaunchOption();
358 out += " -d preview";
359 out += ":key=" + getSessRndKey();
360 out += " --audio-filter controlport_stats#discard";
361 out += getOption("audio.source").getLaunchOption();
362 out += getOption("audio.source.channels").getLaunchOption();
363 out += " -r dummy";
364 out += getOption("network.control_port").getParam();
365 out += getControlPort();
366 out += getOption("encryption").getLaunchOption();
367
368 return out;
369}

References getControlPort(), Option::getLaunchOption(), getOption(), Option::getParam(), and getSessRndKey().

Referenced by UltragridWindow::launchPreview().

Here is the call graph for this function:

◆ getSessRndKey()

const std::string & Settings::getSessRndKey ( ) const
inline

Definition at line 117 of file settings.hpp.

117{ return sessRndKey; }

References sessRndKey.

Referenced by getLaunchParams(), getPreviewParams(), and UltragridWindow::initializeUgOpts().

◆ isAdvancedMode()

bool Settings::isAdvancedMode ( )

Definition at line 433 of file settings.cpp.

433 {
434 return getOption("advanced").getValue() == "t";
435}

References getOption(), and Option::getValue().

Here is the call graph for this function:

◆ populateDeviceSettings()

void Settings::populateDeviceSettings ( AvailableSettings * availSettings)
private

Definition at line 453 of file settings.cpp.

453 {
454 struct{
456 const char *optPrefix;
457 } devTypes[] = {
458 {VIDEO_SRC, "video.source"},
459 {VIDEO_DISPLAY, "video.display"},
460 {AUDIO_SRC, "audio.source"},
461 {AUDIO_PLAYBACK, "audio.playback"},
462 };
463
464 for(const auto& devType : devTypes){
465 for(const auto& dev : availSettings->getDevices(devType.type)){
466 addDevOpt(this, dev, devType.optPrefix);
467
468 for(const auto& devOpt : dev.opts){
469 addOption(dev.deviceOpt + "." + devOpt.key,
470 devOpt.booleanOpt ? Option::BoolOpt : Option::StringOpt,
471 devOpt.optStr,
472 "",
473 false,
474 std::string(devType.optPrefix) + "." + dev.type + ".device",
475 dev.deviceOpt);
476 }
477 }
478 }
479}
const std::vector< Device > & getDevices(SettingType type) const
@ StringOpt
Definition settings.hpp:29
@ BoolOpt
Definition settings.hpp:30
static void addDevOpt(Settings *settings, const Device &dev, const char *parent)
Definition settings.cpp:443

References addDevOpt(), addOption(), Option::BoolOpt, AvailableSettings::getDevices(), Option::StringOpt, and type.

Referenced by populateSettingsFromCapabilities().

Here is the call graph for this function:

◆ populateSettingsFromCapabilities()

void Settings::populateSettingsFromCapabilities ( AvailableSettings * availSettings)

Definition at line 518 of file settings.cpp.

518 {
519 populateDeviceSettings(availSettings);
520 populateVideoCompressSettings(availSettings);
521}
void populateVideoCompressSettings(AvailableSettings *availSettings)
Definition settings.cpp:481
void populateDeviceSettings(AvailableSettings *availSettings)
Definition settings.cpp:453

References populateDeviceSettings(), and populateVideoCompressSettings().

Here is the call graph for this function:

◆ populateVideoCompressSettings()

void Settings::populateVideoCompressSettings ( AvailableSettings * availSettings)
private

Definition at line 481 of file settings.cpp.

481 {
482 for(const auto& mod : availSettings->getVideoCompressModules()){
483 addOption(mod.name + ".codec",
485 "",
486 "",
487 false,
488 "video.compress",
489 mod.name);
490
491 for(const auto& modOption: mod.opts){
492 addOption(mod.name + "." + modOption.key,
493 modOption.booleanOpt ? Option::BoolOpt : Option::StringOpt,
494 modOption.optStr,
495 "",
496 false,
497 "video.compress",
498 mod.name
499 );
500 }
501 }
502
503 for(const auto& codec : availSettings->getVideoCompressCodecs()){
504 std::string optName = "video.compress.";
505 optName += codec.module_name;
506 optName += ".codec";
507
508 addOption(codec.name + ".encoder",
510 "",
511 codec.encoders[0].optStr,
512 true,
513 optName,
514 codec.name);
515 }
516}
const std::vector< CompressModule > & getVideoCompressModules() const
const std::vector< Codec > & getVideoCompressCodecs() const
@ SilentOpt
Definition settings.hpp:31
std::string name
std::vector< encoder > encoders

References addOption(), Option::BoolOpt, codec::encoders, AvailableSettings::getVideoCompressCodecs(), AvailableSettings::getVideoCompressModules(), codec::name, Option::SilentOpt, and Option::StringOpt.

Referenced by populateSettingsFromCapabilities().

Here is the call graph for this function:

Member Data Documentation

◆ dummy

const Option Settings::dummy
private

Definition at line 128 of file settings.hpp.

Referenced by getOption().

◆ options

std::map<std::string, std::unique_ptr<Option> > Settings::options
private

Definition at line 124 of file settings.hpp.

Referenced by getOptionMap().

◆ sessRndKey

std::string Settings::sessRndKey
private

Definition at line 126 of file settings.hpp.

Referenced by Settings(), and getSessRndKey().


The documentation for this class was generated from the following files: