-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use github.com/gpac/ComplianceWarden as a dependency to check all AVIF bitstreams output by avifEncoderFinish(). Add ext/compliance_warden.sh. Introduce AVIF_USE_CXX in CMakeLists.txt to regroup the use cases requiring C++.
- Loading branch information
Showing
6 changed files
with
143 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/obj* | ||
/ext/aom | ||
/ext/avm | ||
/ext/ComplianceWarden | ||
/ext/dav1d | ||
/ext/fuzztest | ||
/ext/googletest | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# | ||
# Local clone of ComplianceWarden (part of the gpac organization) for tests. | ||
# Used when AVIF_ENABLE_COMPLIANCE_WARDEN is ON. | ||
|
||
set -e | ||
|
||
git clone -b v33 --depth 1 https://github.com/gpac/ComplianceWarden.git | ||
# The provided Makefile only builds bin/cw.exe and objects. | ||
# We are interested in the library, so the files are directly used instead of building with make -j. | ||
ComplianceWarden/scripts/version.sh > ComplianceWarden/src/cw_version.cpp | ||
|
||
# registerSpec() does not seem to be called in the static 'registered' local variables, | ||
# for example in avif.cpp. Use the following hack to access the static SpecDescs. | ||
# Feel free to replace by a prettier solution. | ||
printf "extern const SpecDesc *const globalSpecAvif = &specAvif;\n" >> ComplianceWarden/src/specs/avif/avif.cpp | ||
printf "extern const SpecDesc *const globalSpecAv1Hdr10plus = &specAv1Hdr10plus;\n" >> ComplianceWarden/src/specs/av1_hdr10plus/av1_hdr10plus.cpp | ||
printf "extern const SpecDesc *const globalSpecHeif = &specHeif;\n" >> ComplianceWarden/src/specs/heif/heif.cpp | ||
printf "extern const SpecDesc *const globalSpecIsobmff = &specIsobmff;\n" >> ComplianceWarden/src/specs/isobmff/isobmff.cpp | ||
printf "extern const SpecDesc *const globalSpecMiaf = &specMiaf;\n" >> ComplianceWarden/src/specs/miaf/miaf.cpp |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2023 Google LLC | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <limits> | ||
|
||
#include "avif/internal.h" | ||
|
||
// From ../ext/ComplianceWarden/src/utils/ | ||
#include "box_reader_impl.h" | ||
#include "spec.h" | ||
|
||
bool checkComplianceStd(Box const & file, SpecDesc const * spec); | ||
|
||
SpecDesc const * specFind(const char * name); | ||
std::vector<SpecDesc const *> & g_allSpecs(); | ||
extern const SpecDesc * const globalSpecAvif; | ||
extern const SpecDesc * const globalSpecAv1Hdr10plus; | ||
extern const SpecDesc * const globalSpecHeif; | ||
extern const SpecDesc * const globalSpecIsobmff; | ||
extern const SpecDesc * const globalSpecMiaf; | ||
|
||
avifResult avifIsCompliant(uint8_t * data, size_t size) | ||
{ | ||
// See compliance_warden.sh. | ||
if (g_allSpecs().empty()) { | ||
registerSpec(globalSpecAvif); | ||
registerSpec(globalSpecAv1Hdr10plus); | ||
registerSpec(globalSpecHeif); | ||
registerSpec(globalSpecIsobmff); | ||
registerSpec(globalSpecMiaf); | ||
} | ||
|
||
// Inspired from ext/ComplianceWarden/src/app/cw.cpp | ||
BoxReader topReader; | ||
for (char sym : { 'f', 'i', 'l', 'e', '.', 'a', 'v', 'i', 'f' }) { | ||
// Setting made-up file name (letter by letter). | ||
topReader.myBox.syms.push_back({ "filename", static_cast<int64_t>(sym), 8 }); | ||
} | ||
AVIF_CHECKERR(size <= std::numeric_limits<int>::max(), AVIF_RESULT_INVALID_ARGUMENT); | ||
topReader.br = { data, static_cast<int>(size) }; | ||
topReader.myBox.original = data; | ||
topReader.myBox.position = 0; | ||
topReader.myBox.size = size; | ||
topReader.myBox.fourcc = FOURCC("root"); | ||
topReader.specs = { specFind("avif") }; | ||
AVIF_CHECKERR(topReader.specs[0] != nullptr, AVIF_RESULT_UNKNOWN_ERROR); | ||
auto parseFunc = getParseFunction(topReader.myBox.fourcc); | ||
parseFunc(&topReader); | ||
// gpac/ComplianceWarden will print the formatted result page to stdout, warnings and errors inclusive. | ||
AVIF_CHECKERR(!checkComplianceStd(topReader.myBox, topReader.specs[0]), AVIF_RESULT_BMFF_PARSE_FAILED); | ||
return AVIF_RESULT_OK; | ||
} |
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