From 278e909a2f983a12e8ca2f64ba7db475076fe9a4 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Fri, 19 Nov 2021 15:24:53 +0100 Subject: [PATCH] mp4: Add tapt, prof, enof and clap boxes --- format/mp4/boxes.go | 30 ++++++++++++++++++++++++++++++ pkg/decode/scalar.go | 2 +- pkg/decode/scalar_gen.go | 20 ++++++++++---------- pkg/decode/scalar_gen.go.json | 4 ++-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/format/mp4/boxes.go b/format/mp4/boxes.go index 8be181ab..4198169a 100644 --- a/format/mp4/boxes.go +++ b/format/mp4/boxes.go @@ -274,6 +274,7 @@ func init() { d.FieldU24("flags") d.FieldU16("graphicsmode") d.FieldArray("opcolor", func(d *decode.D) { + // TODO: is FP16? d.FieldU16("value") d.FieldU16("value") d.FieldU16("value") @@ -1205,5 +1206,34 @@ func init() { d.FieldRawLen("data", d.BitsLeft()) } }, + "tapt": decodeBoxes, + "clef": func(_ *decodeContext, d *decode.D) { + d.FieldU8("version") + d.FieldU24("flags") + d.FieldFP32("width") + d.FieldFP32("height") + }, + "prof": func(_ *decodeContext, d *decode.D) { + d.FieldU8("version") + d.FieldU24("flags") + d.FieldFP32("width") + d.FieldFP32("height") + }, + "enof": func(_ *decodeContext, d *decode.D) { + d.FieldU8("version") + d.FieldU24("flags") + d.FieldFP32("width") + d.FieldFP32("height") + }, + "clap": func(_ *decodeContext, d *decode.D) { + d.FieldU32("aperture_width_n") + d.FieldU32("aperture_width_d") + d.FieldU32("aperture_height_n") + d.FieldU32("aperture_height_d") + d.FieldU32("horiz_off_n") + d.FieldU32("horiz_off_d") + d.FieldU32("vert_off_n") + d.FieldU32("vert_off_d") + }, } } diff --git a/pkg/decode/scalar.go b/pkg/decode/scalar.go index ec281049..47533435 100644 --- a/pkg/decode/scalar.go +++ b/pkg/decode/scalar.go @@ -358,7 +358,7 @@ func (d *D) tryFE(nBits int, endian Endian) (float64, error) { } } -func (d *D) tryFPE(nBits int, fBits int64, endian Endian) (float64, error) { +func (d *D) tryFPE(nBits int, fBits int, endian Endian) (float64, error) { n, err := d.bits(nBits) if err != nil { return 0, err diff --git a/pkg/decode/scalar_gen.go b/pkg/decode/scalar_gen.go index 0a2def11..474aaec5 100644 --- a/pkg/decode/scalar_gen.go +++ b/pkg/decode/scalar_gen.go @@ -12798,9 +12798,9 @@ func (d *D) FieldF64BE(name string, sfns ...ScalarFn) float64 { // Reader FP // TryFP tries to read nBits fixed-point number in current endian -func (d *D) TryFP(nBits int, fBits int64) (float64, error) { return d.tryFPE(nBits, fBits, d.Endian) } +func (d *D) TryFP(nBits int, fBits int) (float64, error) { return d.tryFPE(nBits, fBits, d.Endian) } -func (d *D) ScalarFP(nBits int, fBits int64) func(Scalar) (Scalar, error) { +func (d *D) ScalarFP(nBits int, fBits int) func(Scalar) (Scalar, error) { return func(s Scalar) (Scalar, error) { v, err := d.tryFPE(nBits, fBits, d.Endian) s.Actual = v @@ -12809,7 +12809,7 @@ func (d *D) ScalarFP(nBits int, fBits int64) func(Scalar) (Scalar, error) { } // FP reads nBits fixed-point number in current endian -func (d *D) FP(nBits int, fBits int64) float64 { +func (d *D) FP(nBits int, fBits int) float64 { v, err := d.tryFPE(nBits, fBits, d.Endian) if err != nil { panic(IOError{Err: err, Op: "FP", Pos: d.Pos()}) @@ -12818,7 +12818,7 @@ func (d *D) FP(nBits int, fBits int64) float64 { } // TryFieldFP tries to add a field and read nBits fixed-point number in current endian -func (d *D) TryFieldFP(name string, nBits int, fBits int64, sfns ...ScalarFn) (float64, error) { +func (d *D) TryFieldFP(name string, nBits int, fBits int, sfns ...ScalarFn) (float64, error) { v, err := d.TryFieldScalar(name, d.ScalarFP(nBits, fBits), sfns...) if err != nil { return 0, err @@ -12827,7 +12827,7 @@ func (d *D) TryFieldFP(name string, nBits int, fBits int64, sfns ...ScalarFn) (f } // FieldFP adds a field and reads nBits fixed-point number in current endian -func (d *D) FieldFP(name string, nBits int, fBits int64, sfns ...ScalarFn) float64 { +func (d *D) FieldFP(name string, nBits int, fBits int, sfns ...ScalarFn) float64 { v, err := d.TryFieldFP(name, nBits, fBits, sfns...) if err != nil { panic(IOError{Err: err, Name: name, Op: "FP", Pos: d.Pos()}) @@ -12838,11 +12838,11 @@ func (d *D) FieldFP(name string, nBits int, fBits int64, sfns ...ScalarFn) float // Reader FPE // TryFPE tries to read nBits fixed-point number in specified endian -func (d *D) TryFPE(nBits int, fBits int64, endian Endian) (float64, error) { +func (d *D) TryFPE(nBits int, fBits int, endian Endian) (float64, error) { return d.tryFPE(nBits, fBits, endian) } -func (d *D) ScalarFPE(nBits int, fBits int64, endian Endian) func(Scalar) (Scalar, error) { +func (d *D) ScalarFPE(nBits int, fBits int, endian Endian) func(Scalar) (Scalar, error) { return func(s Scalar) (Scalar, error) { v, err := d.tryFPE(nBits, fBits, endian) s.Actual = v @@ -12851,7 +12851,7 @@ func (d *D) ScalarFPE(nBits int, fBits int64, endian Endian) func(Scalar) (Scala } // FPE reads nBits fixed-point number in specified endian -func (d *D) FPE(nBits int, fBits int64, endian Endian) float64 { +func (d *D) FPE(nBits int, fBits int, endian Endian) float64 { v, err := d.tryFPE(nBits, fBits, endian) if err != nil { panic(IOError{Err: err, Op: "FPE", Pos: d.Pos()}) @@ -12860,7 +12860,7 @@ func (d *D) FPE(nBits int, fBits int64, endian Endian) float64 { } // TryFieldFPE tries to add a field and read nBits fixed-point number in specified endian -func (d *D) TryFieldFPE(name string, nBits int, fBits int64, endian Endian, sfns ...ScalarFn) (float64, error) { +func (d *D) TryFieldFPE(name string, nBits int, fBits int, endian Endian, sfns ...ScalarFn) (float64, error) { v, err := d.TryFieldScalar(name, d.ScalarFPE(nBits, fBits, endian), sfns...) if err != nil { return 0, err @@ -12869,7 +12869,7 @@ func (d *D) TryFieldFPE(name string, nBits int, fBits int64, endian Endian, sfns } // FieldFPE adds a field and reads nBits fixed-point number in specified endian -func (d *D) FieldFPE(name string, nBits int, fBits int64, endian Endian, sfns ...ScalarFn) float64 { +func (d *D) FieldFPE(name string, nBits int, fBits int, endian Endian, sfns ...ScalarFn) float64 { v, err := d.TryFieldFPE(name, nBits, fBits, endian, sfns...) if err != nil { panic(IOError{Err: err, Name: name, Op: "FPE", Pos: d.Pos()}) diff --git a/pkg/decode/scalar_gen.go.json b/pkg/decode/scalar_gen.go.json index 77eabe29..4a262cb6 100644 --- a/pkg/decode/scalar_gen.go.json +++ b/pkg/decode/scalar_gen.go.json @@ -76,14 +76,14 @@ { "name": "", "args": "nBits, fBits", - "params": "nBits int, fBits int64", + "params": "nBits int, fBits int", "call": "d.tryFPE(nBits, fBits, d.Endian)", "doc": "nBits fixed-point number in current endian" }, { "name": "E", "args": "nBits, fBits, endian", - "params": "nBits int, fBits int64, endian Endian", + "params": "nBits int, fBits int, endian Endian", "call": "d.tryFPE(nBits, fBits, endian)", "doc": "nBits fixed-point number in specified endian" },