mirror of
https://github.com/wader/fq.git
synced 2024-12-23 21:31:33 +03:00
9b81d4d3ab
Preparation to make decoder use less memory and API more type safe. Now each scalar type has it's own struct type so it can store different things and enables to have a scalar interface. Also own types will enable experimenting with decode DLS designs like using chained methods that are type aware.
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package mp4
|
|
|
|
import (
|
|
"github.com/wader/fq/format"
|
|
"github.com/wader/fq/pkg/decode"
|
|
"github.com/wader/fq/pkg/interp"
|
|
"github.com/wader/fq/pkg/scalar"
|
|
)
|
|
|
|
func init() {
|
|
interp.RegisterFormat(decode.Format{
|
|
Name: format.PSSH_PLAYREADY,
|
|
Description: "PlayReady PSSH",
|
|
DecodeFn: playreadyPsshDecode,
|
|
})
|
|
}
|
|
|
|
const (
|
|
recordTypeRightsManagementHeader = 1
|
|
recordTypeLicenseStore = 2
|
|
)
|
|
|
|
var recordTypeNames = scalar.UintMapSymStr{
|
|
recordTypeRightsManagementHeader: "Rights management header",
|
|
recordTypeLicenseStore: "License store",
|
|
}
|
|
|
|
func playreadyPsshDecode(d *decode.D, _ any) any {
|
|
d.Endian = decode.LittleEndian
|
|
|
|
d.FieldU32("size")
|
|
count := d.FieldU16("count")
|
|
i := uint64(0)
|
|
d.FieldStructArrayLoop("records", "record", func() bool { return i < count }, func(d *decode.D) {
|
|
recordType := d.FieldU16("type", recordTypeNames)
|
|
recordLen := d.FieldU16("len")
|
|
switch recordType {
|
|
case recordTypeRightsManagementHeader, recordTypeLicenseStore:
|
|
d.FieldUTF16LE("xml", int(recordLen))
|
|
default:
|
|
d.FieldRawLen("data", int64(recordLen)*8)
|
|
}
|
|
i++
|
|
})
|
|
|
|
return nil
|
|
}
|