Skip to content

Commit

Permalink
add example box support
Browse files Browse the repository at this point in the history
  • Loading branch information
DenizUgur committed Nov 7, 2024
1 parent fe1a675 commit 3699435
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
6 changes: 5 additions & 1 deletion data/schemas/gpac-extension.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
"description": "Combined flags in base 10"
},
"@Specification": { "type": "string" },
"@Container": { "type": "string" }
"@Container": { "type": "string" },
"example": {
"type": "boolean",
"description": "Set to true for example boxes"
}
},
"patternProperties": {
"^(?![@#]).+": {
Expand Down
45 changes: 34 additions & 11 deletions src/construct/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

def get_all_fourccs_inside(root):
fourccs = set([root["@Type"]])
examples = set()

def crawl(hierarchy):
for key, value in hierarchy.items():
Expand All @@ -15,14 +16,19 @@ def crawl(hierarchy):
continue
fourcc = value["@Type"]

# Skip examples
if value.get("example", False):
examples.add(fourcc)
continue

fourccs.add(fourcc)
crawl(value)
elif isinstance(value, list):
for item in value:
crawl({key: item})

crawl(root)
return fourccs
crawl({"root": root})
return fourccs, examples


def main():
Expand Down Expand Up @@ -97,6 +103,7 @@ def main():

missing_extensions = set()
fourcc_in_extensions = set()
examples_in_extensions = set()
for extension in extensions:
with open(extension, "r", encoding="utf-8") as f:
ext_data = json.load(f)
Expand All @@ -105,27 +112,29 @@ def main():
)

for e in ext_data["extensions"]:
fourcc_in_extensions.update(get_all_fourccs_inside(e["box"]))
fourccs, examples = get_all_fourccs_inside(e["box"])
fourcc_in_extensions.update(fourccs)
examples_in_extensions.update(examples)

# Remove all known and unknown paths from missing extensions (to reduce redundancy)
missing_extensions.difference_update(set(files["not_found"]))
missing_extensions.difference_update(set(files["path_file_map"].keys()))

NOT_FOUND = {
"count": len(files["not_found"]),
"percentage": len(files["not_found"]) / len(files["path_file_map"]),
"boxes": list(set(p.split(".")[-1] for p in files["not_found"])),
"missing_extensions": list(missing_extensions),
"paths": list(files["not_found"].keys()),
}

# FIXME: All the logs here should be errors, except for info
for upath, in_files in files["not_found"].items():
# Easy to access variables
container_path = upath.split(".")[:-1]
box_fourcc = upath.split(".")[-1]
known_box = box_fourcc in dictionary["fourccs"]

# Check if this is an example box
if box_fourcc in examples_in_extensions:
if known_box:
logger.error(
f"Box {box_fourcc} is an example box but it is in our database"
)
continue

if not known_box:
# Check if this was in under consideration files
if (
Expand Down Expand Up @@ -183,6 +192,20 @@ def main():
f"Path ~{'.'.join(broken_path)} is not listed as container for box {box_fourcc}"
)

# Remove all known examples from not_found
for not_found in list(files["not_found"].keys()):
last_4cc = not_found.split(".")[-1]
if last_4cc in examples_in_extensions:
del files["not_found"][not_found]

NOT_FOUND = {
"count": len(files["not_found"]),
"percentage": len(files["not_found"]) / len(files["path_file_map"]),
"boxes": list(set(p.split(".")[-1] for p in files["not_found"])),
"missing_extensions": list(missing_extensions),
"paths": list(files["not_found"].keys()),
}

for path in NOT_FOUND["missing_extensions"]:
logger.warning(
f"Path {path} was found in the extension files but not in our database"
Expand Down
2 changes: 1 addition & 1 deletion src/construct/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def crawl(root, path):
continue

add_variant(add, root, path)
crawl(root, path + [root["@Type"]])
crawl({"root": root}, path)

return paths

Expand Down

0 comments on commit 3699435

Please sign in to comment.