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-11-24 23:20:46 +03:00
|
|
|
var flacMetadatablockFormat decode.Group
|
2021-09-17 16:46:13 +03:00
|
|
|
|
|
|
|
func init() {
|
2021-11-17 18:46:10 +03:00
|
|
|
registry.MustRegister(decode.Format{
|
2021-09-17 16:46:13 +03:00
|
|
|
Name: format.FLAC_METADATABLOCKS,
|
|
|
|
Description: "FLAC metadatablocks",
|
2021-10-28 02:44:09 +03:00
|
|
|
DecodeFn: metadatablocksDecode,
|
2021-11-03 19:19:33 +03:00
|
|
|
RootArray: true,
|
2021-09-17 16:46:13 +03:00
|
|
|
RootName: "metadatablocks",
|
|
|
|
Dependencies: []decode.Dependency{
|
2021-11-24 23:20:46 +03:00
|
|
|
{Names: []string{format.FLAC_METADATABLOCK}, Group: &flacMetadatablockFormat},
|
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-11-24 23:20:46 +03:00
|
|
|
dv, v := d.FieldFormat("metadatablock", flacMetadatablockFormat, nil)
|
2021-11-19 18:44:06 +03:00
|
|
|
flacMetadatablockOut, ok := v.(format.FlacMetadatablockOut)
|
|
|
|
if dv != nil && !ok {
|
2021-11-16 19:11:26 +03:00
|
|
|
panic(fmt.Sprintf("expected FlacMetadatablocksOut, got %#+v", flacMetadatablockOut))
|
2021-10-28 02:44:09 +03:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|