1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 13:22:58 +03:00
fq/format/mpeg/avc_au.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
942 B
Go

package mpeg
// ISO/IEC 14496-15, 5.3.3.1.2 Syntax
import (
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
var avcNALUFormat decode.Group
func init() {
interp.RegisterFormat(decode.Format{
Name: format.AVC_AU,
Description: "H.264/AVC Access Unit",
DecodeFn: avcAUDecode,
DefaultInArg: format.AvcAuIn{
LengthSize: 0,
},
RootArray: true,
RootName: "access_unit",
Dependencies: []decode.Dependency{
{Names: []string{format.AVC_NALU}, Group: &avcNALUFormat},
},
})
}
func avcAUDecode(d *decode.D) any {
var ai format.AvcAuIn
d.ArgAs(&ai)
if ai.LengthSize == 0 {
// TODO: is annexb the correct name?
annexBDecode(d, avcNALUFormat)
return nil
}
for d.NotEnd() {
d.FieldStruct("nalu", func(d *decode.D) {
l := int64(d.FieldU("length", int(ai.LengthSize)*8)) * 8
d.FieldFormatLen("nalu", l, avcNALUFormat, nil)
})
}
return nil
}