2021-09-17 16:46:13 +03:00
|
|
|
package flac
|
|
|
|
|
|
|
|
import (
|
2021-10-28 02:44:09 +03:00
|
|
|
"fmt"
|
|
|
|
|
2021-09-17 16:46:13 +03:00
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/format/registry"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
|
|
|
)
|
|
|
|
|
2021-10-28 02:44:09 +03:00
|
|
|
var flacMetadatablockForamt []*decode.Format
|
2021-09-17 16:46:13 +03:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
registry.MustRegister(&decode.Format{
|
|
|
|
Name: format.FLAC_METADATABLOCKS,
|
|
|
|
Description: "FLAC metadatablocks",
|
2021-10-28 02:44:09 +03:00
|
|
|
DecodeFn: metadatablocksDecode,
|
2021-09-17 16:46:13 +03:00
|
|
|
RootV: decode.Array{},
|
|
|
|
RootName: "metadatablocks",
|
|
|
|
Dependencies: []decode.Dependency{
|
2021-10-28 02:44:09 +03:00
|
|
|
{Names: []string{format.FLAC_METADATABLOCK}, Formats: &flacMetadatablockForamt},
|
2021-09-17 16:46:13 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-28 02:44:09 +03:00
|
|
|
func metadatablocksDecode(d *decode.D, in interface{}) interface{} {
|
|
|
|
flacMetadatablocksOut := format.FlacMetadatablocksOut{}
|
2021-09-17 16:46:13 +03:00
|
|
|
|
|
|
|
isLastBlock := false
|
|
|
|
for !isLastBlock {
|
2021-10-28 02:44:09 +03:00
|
|
|
_, flacMetadatablockOutAny := d.FieldFormat("metadatablock", flacMetadatablockForamt, nil)
|
|
|
|
flacMetadatablockOut, ok := flacMetadatablockOutAny.(format.FlacMetadatablockOut)
|
|
|
|
if !ok {
|
|
|
|
d.Invalid(fmt.Sprintf("expected FlacMetadatablocksOut, got %#+v", flacMetadatablockOut))
|
|
|
|
}
|
|
|
|
isLastBlock = flacMetadatablockOut.IsLastBlock
|
|
|
|
if flacMetadatablockOut.HasStreamInfo {
|
|
|
|
flacMetadatablocksOut.HasStreamInfo = true
|
|
|
|
flacMetadatablocksOut.StreamInfo = flacMetadatablockOut.StreamInfo
|
|
|
|
}
|
2021-09-17 16:46:13 +03:00
|
|
|
}
|
|
|
|
|
2021-10-28 02:44:09 +03:00
|
|
|
return flacMetadatablocksOut
|
2021-09-17 16:46:13 +03:00
|
|
|
}
|