2020-06-08 03:29:51 +03:00
|
|
|
package mpeg
|
|
|
|
|
|
|
|
import (
|
2021-08-17 13:06:32 +03:00
|
|
|
"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
|
|
|
|
}
|