2021-09-02 14:08:26 +03:00
|
|
|
package mp4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
2022-07-16 19:39:57 +03:00
|
|
|
"github.com/wader/fq/pkg/interp"
|
2021-12-02 00:48:25 +03:00
|
|
|
"github.com/wader/fq/pkg/scalar"
|
2021-09-02 14:08:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2022-07-16 19:39:57 +03:00
|
|
|
interp.RegisterFormat(decode.Format{
|
2021-09-02 14:08:26 +03:00
|
|
|
Name: format.PSSH_PLAYREADY,
|
|
|
|
Description: "PlayReady PSSH",
|
|
|
|
DecodeFn: playreadyPsshDecode,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
recordTypeRightsManagementHeader = 1
|
|
|
|
recordTypeLicenseStore = 2
|
|
|
|
)
|
|
|
|
|
2022-09-30 14:58:23 +03:00
|
|
|
var recordTypeNames = scalar.UintMapSymStr{
|
2021-09-02 14:08:26 +03:00
|
|
|
recordTypeRightsManagementHeader: "Rights management header",
|
|
|
|
recordTypeLicenseStore: "License store",
|
|
|
|
}
|
|
|
|
|
2023-02-18 23:10:48 +03:00
|
|
|
func playreadyPsshDecode(d *decode.D) any {
|
2021-09-02 14:08:26 +03:00
|
|
|
d.Endian = decode.LittleEndian
|
|
|
|
|
|
|
|
d.FieldU32("size")
|
|
|
|
count := d.FieldU16("count")
|
|
|
|
i := uint64(0)
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStructArrayLoop("records", "record", func() bool { return i < count }, func(d *decode.D) {
|
2021-12-02 00:48:25 +03:00
|
|
|
recordType := d.FieldU16("type", recordTypeNames)
|
2021-09-02 14:08:26 +03:00
|
|
|
recordLen := d.FieldU16("len")
|
|
|
|
switch recordType {
|
|
|
|
case recordTypeRightsManagementHeader, recordTypeLicenseStore:
|
|
|
|
d.FieldUTF16LE("xml", int(recordLen))
|
|
|
|
default:
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldRawLen("data", int64(recordLen)*8)
|
2021-09-02 14:08:26 +03:00
|
|
|
}
|
|
|
|
i++
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|