-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass number of threads argument to external codecs as a hidden range …
…parameter.
- Loading branch information
Showing
17 changed files
with
420 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* BoCA - BonkEnc Component Architecture | ||
* Copyright (C) 2007-2022 Robert Kausch <[email protected]> | ||
* Copyright (C) 2007-2024 Robert Kausch <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
|
@@ -13,8 +13,7 @@ | |
#ifndef H_BOCA_COMPONENTSPECS | ||
#define H_BOCA_COMPONENTSPECS | ||
|
||
#include <smooth.h> | ||
#include "../core/definitions.h" | ||
#include "../common/config.h" | ||
|
||
using namespace smooth; | ||
using namespace smooth::System; | ||
|
@@ -74,6 +73,13 @@ namespace BoCA | |
NUM_PARAMETER_TYPES | ||
}; | ||
|
||
struct ParameterRequirement | ||
{ | ||
String option; | ||
String arguments; | ||
Bool useStderr; | ||
}; | ||
|
||
struct ParameterDependency | ||
{ | ||
String setting; | ||
|
@@ -276,6 +282,12 @@ namespace BoCA | |
|
||
const Array<ParameterDependency> &GetDependencies() const; | ||
Void AddDependency(const ParameterDependency &); | ||
|
||
Bool GetHidden() const; | ||
Void SetHidden(Bool nHidden); | ||
|
||
const Array<ParameterRequirement> &GetRequirements() const; | ||
Void AddRequirement(const ParameterRequirement &); | ||
}; | ||
|
||
class BOCA_DLL_EXPORT ComponentSpecs | ||
|
@@ -288,6 +300,7 @@ namespace BoCA | |
Bool ParseXMLSpec(const String &); | ||
|
||
Bool ParseParameters(XML::Node *); | ||
Bool ParseParameterRequirements(Parameter *, XML::Node *); | ||
Bool ParseParameterDependencies(Parameter *, XML::Node *); | ||
public: | ||
String id; | ||
|
@@ -333,7 +346,7 @@ namespace BoCA | |
Bool LoadFromDLL(const String &); | ||
Bool LoadFromXML(const String &); | ||
|
||
String GetExternalArgumentsString(); | ||
String GetExternalArgumentsString(const Config *); | ||
|
||
const char *(*func_GetComponentSpecs)(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* BoCA - BonkEnc Component Architecture | ||
* Copyright (C) 2007-2022 Robert Kausch <[email protected]> | ||
* Copyright (C) 2007-2024 Robert Kausch <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
|
@@ -14,6 +14,9 @@ | |
#include <boca/common/config.h> | ||
|
||
static Array< Array<String> > formatCompanions; | ||
|
||
static Array< Bool > parameterHidden; | ||
static Array< Array<BoCA::ParameterRequirement> > parameterRequirements; | ||
static Array< Array<BoCA::ParameterDependency> > parameterDependencies; | ||
|
||
const Array<String> &BoCA::AS::FileFormat::GetCompanionExtensions() const | ||
|
@@ -32,6 +35,37 @@ Void BoCA::AS::FileFormat::AddCompanionExtension(const String &nExt) | |
formatCompanions.GetReference(index).Add(nExt); | ||
} | ||
|
||
Bool BoCA::AS::Parameter::GetHidden() const | ||
{ | ||
Int index = Number(Int64(this)).ToHexString().ComputeCRC32(); | ||
|
||
return parameterHidden.Get(index); | ||
} | ||
|
||
Void BoCA::AS::Parameter::SetHidden(Bool nHidden) | ||
{ | ||
Int index = Number(Int64(this)).ToHexString().ComputeCRC32(); | ||
|
||
if (!parameterHidden.Set(index, nHidden)) | ||
parameterHidden.Add(nHidden, index); | ||
} | ||
|
||
const Array<BoCA::ParameterRequirement> &BoCA::AS::Parameter::GetRequirements() const | ||
{ | ||
Int index = Number(Int64(this)).ToHexString().ComputeCRC32(); | ||
|
||
return parameterRequirements.Get(index); | ||
} | ||
|
||
Void BoCA::AS::Parameter::AddRequirement(const BoCA::ParameterRequirement &nReq) | ||
{ | ||
Int index = Number(Int64(this)).ToHexString().ComputeCRC32(); | ||
|
||
if (GetRequirements().Length() == 0) parameterRequirements.Add(Array<ParameterRequirement>(), index); | ||
|
||
parameterRequirements.GetReference(index).Add(nReq); | ||
} | ||
|
||
const Array<BoCA::ParameterDependency> &BoCA::AS::Parameter::GetDependencies() const | ||
{ | ||
Int index = Number(Int64(this)).ToHexString().ComputeCRC32(); | ||
|
@@ -296,33 +330,59 @@ Bool BoCA::AS::ComponentSpecs::LoadFromXML(const String &file) | |
return ParseXMLSpec(in.InputString(in.Size()).Trim()); | ||
} | ||
|
||
String BoCA::AS::ComponentSpecs::GetExternalArgumentsString() | ||
String BoCA::AS::ComponentSpecs::GetExternalArgumentsString(const Config *config) | ||
{ | ||
Config *config = Config::Get(); | ||
/* Get number of threads to use. | ||
*/ | ||
Bool enableParallel = config->GetIntValue("Resources", "EnableParallelConversions", True); | ||
Bool enableSuperFast = config->GetIntValue("Resources", "EnableSuperFastMode", True); | ||
Int numberOfThreads = enableParallel && enableSuperFast ? config->GetIntValue("Resources", "NumberOfConversionThreads", 0) : 1; | ||
|
||
if (enableParallel && enableSuperFast && numberOfThreads <= 1) numberOfThreads = CPU().GetNumCores() + (CPU().GetNumLogicalCPUs() - CPU().GetNumCores()) / 2; | ||
|
||
/* Build arguments string. | ||
*/ | ||
String arguments; | ||
|
||
foreach (Parameter *param, parameters) | ||
{ | ||
String paramName = param->GetName(); | ||
Bool paramEnabled = param->GetEnabled(); | ||
String paramDefault = param->GetDefault().Replace("%THREADS", String::FromInt(numberOfThreads)); | ||
|
||
switch (param->GetType()) | ||
{ | ||
case PARAMETER_TYPE_SWITCH: | ||
if (!config->GetIntValue(id, param->GetName(), param->GetEnabled())) continue; | ||
if (!config->GetIntValue(id, paramName, paramEnabled)) continue; | ||
|
||
arguments.Append(param->GetArgument()).Append(" "); | ||
|
||
break; | ||
case PARAMETER_TYPE_SELECTION: | ||
if (!config->GetIntValue(id, String("Set ").Append(param->GetName()), param->GetEnabled())) continue; | ||
if (!config->GetIntValue(id, String("Set ").Append(paramName), paramEnabled)) continue; | ||
|
||
arguments.Append(param->GetArgument().Replace("%VALUE", config->GetStringValue(id, param->GetName(), param->GetDefault()))).Append(" "); | ||
arguments.Append(param->GetArgument().Replace("%VALUE", config->GetStringValue(id, paramName, paramDefault))).Append(" "); | ||
|
||
break; | ||
case PARAMETER_TYPE_RANGE: | ||
if (!config->GetIntValue(id, String("Set ").Append(param->GetName()), param->GetEnabled())) continue; | ||
{ | ||
if (!config->GetIntValue(id, String("Set ").Append(paramName), paramEnabled)) continue; | ||
|
||
Float value = config->GetIntValue(id, paramName, Math::Round(paramDefault.ToFloat() / param->GetStepSize())) * param->GetStepSize(); | ||
|
||
Float min = 0; | ||
Float max = 0; | ||
|
||
foreach(Option * option, param->GetOptions()) | ||
{ | ||
if (option->GetType() == OPTION_TYPE_MIN) min = option->GetValue().ToInt(); | ||
else if (option->GetType() == OPTION_TYPE_MAX) max = option->GetValue().ToInt(); | ||
} | ||
|
||
arguments.Append(param->GetArgument().Replace("%VALUE", String::FromFloat(config->GetIntValue(id, param->GetName(), Math::Round(param->GetDefault().ToFloat() / param->GetStepSize())) * param->GetStepSize()))).Append(" "); | ||
arguments.Append(param->GetArgument().Replace("%VALUE", String::FromFloat(Math::Max(min, Math::Min(value, max))))).Append(" "); | ||
|
||
break; | ||
} | ||
default: | ||
/* Unsupported parameter type. | ||
*/ | ||
|
@@ -618,12 +678,11 @@ Bool BoCA::AS::ComponentSpecs::ParseParameters(XML::Node *root) | |
if (node->GetAttributeByName("name") != NIL) parameter->SetName(node->GetAttributeByName("name")->GetContent()); | ||
if (node->GetAttributeByName("argument") != NIL) parameter->SetArgument(node->GetAttributeByName("argument")->GetContent()); | ||
if (node->GetAttributeByName("enabled") != NIL) parameter->SetEnabled(node->GetAttributeByName("enabled")->GetContent() == "true" ? True : False); | ||
if (node->GetAttributeByName("hidden") != NIL) parameter->SetHidden(node->GetAttributeByName("hidden")->GetContent() == "true" ? True : False); | ||
|
||
if (node->GetName() == "switch") | ||
{ | ||
parameter->SetType(PARAMETER_TYPE_SWITCH); | ||
|
||
ParseParameterDependencies(parameter, node); | ||
} | ||
else if (node->GetName() == "selection") | ||
{ | ||
|
@@ -649,8 +708,6 @@ Bool BoCA::AS::ComponentSpecs::ParseParameters(XML::Node *root) | |
parameter->AddOption(option); | ||
} | ||
} | ||
|
||
ParseParameterDependencies(parameter, node); | ||
} | ||
else if (node->GetName() == "range") | ||
{ | ||
|
@@ -680,16 +737,38 @@ Bool BoCA::AS::ComponentSpecs::ParseParameters(XML::Node *root) | |
parameter->AddOption(option); | ||
} | ||
} | ||
|
||
ParseParameterDependencies(parameter, node); | ||
} | ||
|
||
ParseParameterRequirements(parameter, node); | ||
ParseParameterDependencies(parameter, node); | ||
|
||
parameters.Add(parameter); | ||
} | ||
|
||
return True; | ||
} | ||
|
||
Bool BoCA::AS::ComponentSpecs::ParseParameterRequirements(Parameter *parameter, XML::Node *node) | ||
{ | ||
for (Int i = 0; i < node->GetNOfNodes(); i++) | ||
{ | ||
XML::Node *node2 = node->GetNthNode(i); | ||
|
||
if (node2->GetName() == "requires") | ||
{ | ||
ParameterRequirement requirement; | ||
|
||
requirement.option = node2->GetAttributeByName("option") != NIL ? node2->GetAttributeByName("option")->GetContent() : String(); | ||
requirement.arguments = node2->GetAttributeByName("arguments") != NIL ? node2->GetAttributeByName("arguments")->GetContent() : String(); | ||
requirement.useStderr = node2->GetAttributeByName("stream") != NIL ? (node2->GetAttributeByName("stream")->GetContent() == "stderr") : False; | ||
|
||
if (requirement.option != NIL) parameter->AddRequirement(requirement); | ||
} | ||
} | ||
|
||
return True; | ||
} | ||
|
||
Bool BoCA::AS::ComponentSpecs::ParseParameterDependencies(Parameter *parameter, XML::Node *node) | ||
{ | ||
for (Int i = 0; i < node->GetNOfNodes(); i++) | ||
|
Oops, something went wrong.