1
1
mirror of https://github.com/wader/fq.git synced 2024-12-25 14:23:18 +03:00
fq/format/mpeg/adts.go

40 lines
775 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.Group
2020-06-08 03:29:51 +03:00
func init() {
registry.MustRegister(decode.Format{
2020-06-08 03:29:51 +03:00
Name: format.ADTS,
Description: "Audio Data Transport Stream",
Groups: []string{format.PROBE},
DecodeFn: adtsDecoder,
RootArray: true,
2021-09-16 17:26:31 +03:00
RootName: "frames",
2020-06-08 03:29:51 +03:00
Dependencies: []decode.Dependency{
{Names: []string{format.ADTS_FRAME}, Group: &adtsFrame},
2020-06-08 03:29:51 +03:00
},
})
}
func adtsDecoder(d *decode.D, in interface{}) interface{} {
validFrames := 0
2021-09-16 17:26:31 +03:00
for !d.End() {
if dv, _, _ := d.TryFieldFormat("frame", adtsFrame, nil); dv == nil {
2021-09-16 17:26:31 +03:00
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.Fatalf("no valid frames")
2020-06-08 03:29:51 +03:00
}
return nil
}