Skip to content
Merged
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
12 changes: 12 additions & 0 deletions tools/standardTextToCode/DummyReaderAndBuildFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10)
project(ParsingTestApp)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Collect all .cpp files in the current directory
file(GLOB SOURCES "*.cpp")

# Change to create a library instead of executable
# Remove the add_executable line and replace with:
add_library(ParsingTestApp ${SOURCES})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#pragma once

#include <string>

namespace parser
{

class SubByteReaderDummy
{
public:
SubByteReaderDummy() = default;

bool byte_aligned() const { return false; }

bool readFlag(const std::string &name) { return false; }
int readBits(const std::string &name, const int numBits) { return 0; }
int readBitsSigned(const std::string &name, const int numBits) { return 0; }
unsigned readUEV(const std::string &name) { return 0; }
int readSEV(const std::string &name) { return 0; }
std::string readString(const std::string &name) { return ""; }
};

} // namespace parser
22 changes: 22 additions & 0 deletions tools/standardTextToCode/DummyReaderAndBuildFiles/Units.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

namespace parser
{

class NalUnit
{
public:
NalUnit() = default;

// This could contain file position info, nal unit type info, etc...
};

class SEI
{
public:
SEI() = default;

// This could contain a type as an enum etc...
};

} // namespace parser
4 changes: 4 additions & 0 deletions tools/standardTextToCode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ Read the `docx` document and parse all the tables (e.g `VPS`, `SPS`, ...). Put t
### writeTablesC++.py

Take the pickled file and write CPP classes from it. This can be used as the starting point to create the actual parsing code. Or it can be used to add new parsing code which was added in a later version of a standard.

### Prerequirements

Install python-docx (https://github.com/python-openxml/python-docx).
44 changes: 33 additions & 11 deletions tools/standardTextToCode/codingType.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ class Coding(Enum):
UNSIGNED_FIXED = auto() # u(x) - unsigned int with a fixed number of bits
UNSIGNED_VARIABLE = auto() # u(v) - unsigned int with a variable number of bits
UNSIGNED_EXP = auto() # ue(v) - unsigned int wit exp golomb coding
SIGNED_FIXED = auto() # i(x) - signed int with a fixed number of bits using twos complement
SIGNED_EXP = auto() # se(v) - signed int with exp golomb coding
BYTE = auto() # b(8) - a byte (8 bits)
STRING = auto() # st(x) - null terminated string in ISO/IEC 10646 UCS
UNKNOWN = auto()

def isCodingType(descriptor : str):
try:
Expand All @@ -20,30 +24,48 @@ def __init__(self, descriptor : str):
self.length = 0
self.codingType = None
self.parseCodingType(descriptor)

def parseCodingType(self, descriptor : str):
if (descriptor.startswith("f(")):
if descriptor.startswith("f("):
self.codingType = Coding.FIXED_CODE
self.length = int(descriptor[2:-1])
elif (descriptor.startswith("u(v)")):
elif descriptor.startswith("u(v)"):
self.codingType = Coding.UNSIGNED_VARIABLE
elif (descriptor.startswith("u(")):
elif descriptor.startswith("u("):
self.codingType = Coding.UNSIGNED_FIXED
self.length = int(descriptor[2:-1])
elif (descriptor.startswith("ue(v)")):
elif descriptor.startswith("ue(v)"):
self.codingType = Coding.UNSIGNED_EXP
elif (descriptor.startswith("se(v)")):
elif descriptor.startswith("se(v)"):
self.codingType = Coding.SIGNED_EXP
elif descriptor.startswith("b(8)"):
# Used in e.g. VSEI standard
self.codingType = Coding.BYTE
elif descriptor.startswith("i("):
self.codingType = Coding.SIGNED_FIXED
self.length = int(descriptor[2:-1])
elif descriptor.startswith("st(v)"):
self.codingType = Coding.STRING
else:
raise SyntaxError("Unknown descriptor type " + descriptor)
self.codingType = Coding.UNKNOWN

def __str__(self):
if (self.codingType == Coding.FIXED_CODE):
if self.codingType == Coding.FIXED_CODE:
return f"f({self.length})"
if (self.codingType == Coding.UNSIGNED_VARIABLE):
if self.codingType == Coding.UNSIGNED_VARIABLE:
return "u(v)"
if (self.codingType == Coding.UNSIGNED_FIXED):
if self.codingType == Coding.UNSIGNED_FIXED:
return f"u({self.length})"
if (self.codingType == Coding.UNSIGNED_EXP):
if self.codingType == Coding.UNSIGNED_EXP:
return "ue(v)"
if (self.codingType == Coding.SIGNED_EXP):
if self.codingType == Coding.SIGNED_EXP:
return "se(v)"
if self.codingType == Coding.BYTE:
return "b(8)"
if self.codingType == Coding.SIGNED_FIXED:
return f"i({self.length})"
if self.codingType == Coding.STRING:
return "st(v)"
if self.codingType == Coding.UNKNOWN:
return "unknown"
return "Err"
Loading
Loading