1
1
mirror of https://github.com/wader/fq.git synced 2024-11-30 09:58:13 +03:00
fq/format/mp4/pssh_playready.go
Mattias Wadman 2fc0a71a47 decode: Refactor scalar usage
Move scalar into own package.
Split scalar code into decode related scalar code (that reads etc) and
scalar code that just transform the scalar value.
Use a scalar.Mapper interface instead of just a function.
Make mappers, assert and validat impement the interface.
2021-12-02 17:39:26 +01:00

48 lines
1.1 KiB
Go

package mp4
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/scalar"
)
func init() {
registry.MustRegister(decode.Format{
Name: format.PSSH_PLAYREADY,
Description: "PlayReady PSSH",
DecodeFn: playreadyPsshDecode,
})
}
const (
recordTypeRightsManagementHeader = 1
recordTypeLicenseStore = 2
)
var recordTypeNames = scalar.UToSymStr{
recordTypeRightsManagementHeader: "Rights management header",
recordTypeLicenseStore: "License store",
}
func playreadyPsshDecode(d *decode.D, in interface{}) interface{} {
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
}