feat: new option to ignore unknown boxes
This commit is contained in:
parent
f2a9a75725
commit
c96343ad39
2 changed files with 9 additions and 5 deletions
|
@ -26,6 +26,7 @@ import (
|
|||
type Parser struct {
|
||||
reader io.Reader
|
||||
childBoxDefinitions map[string]map[string]BoxDefinition
|
||||
IgnoreUnknownBoxes bool
|
||||
Content []any
|
||||
}
|
||||
|
||||
|
@ -119,7 +120,9 @@ func parseNextBox(parser *Parser, reader io.Reader, currentBoxType string, fileP
|
|||
box, err = boxTypeDefinition.Parser(parser, filePosition, boxHeaderSize, boxContentBytes)
|
||||
} else {
|
||||
logger.Println("unknown box type", boxType, "at", filePosition, "in", currentBoxType)
|
||||
return nil, filePosition, false, errors.New("unknown box type " + boxType + " in " + currentBoxType)
|
||||
if !parser.IgnoreUnknownBoxes {
|
||||
return nil, filePosition, false, errors.New("unknown box type " + boxType + " in " + currentBoxType)
|
||||
}
|
||||
}
|
||||
|
||||
// check for box errors
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
parser, err := testFile(t, "test/fmp4.mp4")
|
||||
parser, err := testFile(t, "test/fmp4.mp4", false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func TestParser(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestParserFragmentedMP4Init(t *testing.T) {
|
||||
_, err := testFile(t, "test/fmp4_init.mp4")
|
||||
_, err := testFile(t, "test/fmp4_init.mp4", true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -70,12 +70,12 @@ func validateFileType(t *testing.T, parser *Parser) {
|
|||
}
|
||||
|
||||
func TestParserInvalidSampleCount(t *testing.T) {
|
||||
if _, err := testFile(t, "test/fmp4-incorrect-sample-count.mp4"); err == nil {
|
||||
if _, err := testFile(t, "test/fmp4-incorrect-sample-count.mp4", false); err == nil {
|
||||
t.Error("missing error of invalid sample count of track fragment run box")
|
||||
}
|
||||
}
|
||||
|
||||
func testFile(t *testing.T, filePath string) (*Parser, error) {
|
||||
func testFile(t *testing.T, filePath string, allowIgnore bool) (*Parser, error) {
|
||||
// open test file
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
|
@ -85,6 +85,7 @@ func testFile(t *testing.T, filePath string) (*Parser, error) {
|
|||
|
||||
// create new parser
|
||||
parser := NewParser(file)
|
||||
parser.IgnoreUnknownBoxes = allowIgnore
|
||||
err = parser.Parse()
|
||||
return parser, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue