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
|
|
|
)
|
|
|
|
|
2021-11-17 18:46:10 +03:00
|
|
|
var adtsFrame decode.Group
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
func init() {
|
2021-11-17 18:46:10 +03:00
|
|
|
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,
|
2021-11-03 19:19:33 +03:00
|
|
|
RootArray: true,
|
2021-09-16 17:26:31 +03:00
|
|
|
RootName: "frames",
|
2020-06-08 03:29:51 +03:00
|
|
|
Dependencies: []decode.Dependency{
|
2021-11-17 18:46:10 +03:00
|
|
|
{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() {
|
2021-11-30 17:29:01 +03:00
|
|
|
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 {
|
2021-11-17 18:26:13 +03:00
|
|
|
d.Fatalf("no valid frames")
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|