Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usdUtils: CompressionValidator #3400

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pxr/usd/usdUtils/plugInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"UsdzValidators"
]
},
"CompressionValidator": {
"doc": "Files within a usdz package should not be compressed or encrypted.",
"keywords": [
"UsdzValidators"
]
},
"keywords": [
"UsdUtilsValidators"
]
Expand Down
18 changes: 10 additions & 8 deletions pxr/usd/usdUtils/validatorTokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

PXR_NAMESPACE_OPEN_SCOPE

#define USD_UTILS_VALIDATOR_NAME_TOKENS \
((packageEncapsulationValidator, "usdUtils:PackageEncapsulationValidator"))
#define USD_UTILS_VALIDATOR_NAME_TOKENS \
((packageEncapsulationValidator, "usdUtils:PackageEncapsulationValidator")) \
((compressionValidator, "usdUtils:compressionValidator"))

#define USD_UTILS_VALIDATOR_KEYWORD_TOKENS \
(UsdUtilsValidators) \
#define USD_UTILS_VALIDATOR_KEYWORD_TOKENS \
(UsdUtilsValidators) \
(UsdzValidators)

#define USD_UTILS_VALIDATION_ERROR_NAME_TOKENS \
((layerNotInPackage, "LayerNotInPackage")) \
((assetNotInPackage, "AssetNotInPackage")) \
((invalidLayerInPackage, "InvalidLayerInPackage"))
#define USD_UTILS_VALIDATION_ERROR_NAME_TOKENS \
((layerNotInPackage, "LayerNotInPackage")) \
((assetNotInPackage, "AssetNotInPackage")) \
((invalidLayerInPackage, "InvalidLayerInPackage")) \
((compressionDetected, "CompressionDetected"))

///\def
/// Tokens representing validator names. Note that for plugin provided
Expand Down
45 changes: 44 additions & 1 deletion pxr/usd/usdUtils/validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "pxr/usd/usdUtils/validatorTokens.h"
#include "pxr/usd/ar/packageUtils.h"
#include "pxr/usd/usdUtils/dependencies.h"
#include "pxr/usd/usdUtils/userProcessingFunc.h"
#include "pxr/usd/usd/zipFile.h"

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -104,11 +104,54 @@ _PackageEncapsulationValidator(const UsdStagePtr& usdStage) {
return errors;
}

static
UsdValidationErrorVector
_CompressionValidator(const UsdStagePtr& usdStage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tallytalwar I've come across something in this validator that's not clear to me.

My expectation from reading the description from the existing CompressionChecker is that this test should make sure that files within the USDZ file itself were not compressed. So I've created a sample file like this (in this repo as compressedUsdaInside.usdz). However this file fails here, before it can get to the usdchecker code.

If I try a different approach of compressing the usdz itself, it also fails early here.

Do you know how to reproduce the nicer errors from usdchecker itself?

const SdfLayerHandle &rootLayer = usdStage->GetRootLayer();
const UsdZipFile zipFile = UsdZipFile::Open(rootLayer->GetRealPath().c_str());

std::string packagePath = ArSplitPackageRelativePathOuter(rootLayer->GetIdentifier()).first;
if (!zipFile)
{
return {};
}

UsdValidationErrorVector errors;
for(auto it = zipFile.begin(); it != zipFile.end(); ++it)
{
const UsdZipFile::FileInfo &fileInfo = it.GetFileInfo();
if (fileInfo.compressionMethod != 0)
{
const std::string &fileName = *it;
errors.emplace_back(
UsdUtilsValidationErrorNameTokens->compressionDetected,
UsdValidationErrorType::Error,
UsdValidationErrorSites {
UsdValidationErrorSite(
rootLayer, SdfPath(fileName))
},
TfStringPrintf(
("File '%s' in package '%s' has "
"compression. Compression method is '%u', actual size "
"is %lu. Uncompressed size is %lu."),
fileName.c_str(), packagePath.c_str(),
fileInfo.compressionMethod,
fileInfo.size, fileInfo.uncompressedSize)
);
}
}

return errors;
}

TF_REGISTRY_FUNCTION(UsdValidationRegistry)
{
UsdValidationRegistry& registry = UsdValidationRegistry::GetInstance();
registry.RegisterPluginValidator(
UsdUtilsValidatorNameTokens->packageEncapsulationValidator, _PackageEncapsulationValidator);

registry.RegisterPluginValidator(
UsdUtilsValidatorNameTokens->compressionValidator, _CompressionValidator);
}

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down