1
1
mirror of https://github.com/wader/fq.git synced 2024-11-30 09:58:13 +03:00
fq/format/mpeg/adts.go

40 lines
793 B
Go
Raw Normal View History

2020-06-08 03:29:51 +03:00
package mpeg
import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
2020-06-08 03:29:51 +03:00
)
var adtsFrame []*decode.Format
func init() {
registry.MustRegister(&decode.Format{
Name: format.ADTS,
Description: "Audio Data Transport Stream",
Groups: []string{format.PROBE},
DecodeFn: adtsDecoder,
2021-09-16 17:26:31 +03:00
RootV: decode.Array{},
RootName: "frames",
2020-06-08 03:29:51 +03:00
Dependencies: []decode.Dependency{
{Names: []string{format.ADTS_FRAME}, Formats: &adtsFrame},
},
})
}
func adtsDecoder(d *decode.D, in interface{}) interface{} {
validFrames := 0
2021-09-16 17:26:31 +03:00
for !d.End() {
if dv, _, _ := d.FieldTryFormat("frame", adtsFrame, nil); dv == nil {
break
2020-06-08 03:29:51 +03:00
}
2021-09-16 17:26:31 +03:00
validFrames++
}
2020-06-08 03:29:51 +03:00
if validFrames == 0 {
d.Invalid("no valid frames")
}
return nil
}