1
1
mirror of https://github.com/wader/fq.git synced 2024-11-26 21:55:57 +03:00
fq/format/mp4/pssh_playready.go
Mattias Wadman 8e0dde03d0 decode: Support multiple format args and some rename and refactor
This will allow passing both cli options and format options to sub decoder.
Ex: pass keylog option to a tls decoder when decoding a pcap.
Ex: pass decode options to a format inside a http body inside a pcap.

Add ArgAs method to lookup argument based on type. This also makes the format
decode function have same signature as sub decoders in the decode API.

This change decode.Format a bit:
DecodeFn is now just func(d *D) any
DecodeInArg renamed to DefaultInArg
2023-02-18 21:38:51 +01:00

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 {
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
}