Skip to content

Commit

Permalink
decode: Move registry package to decode/registry and add a format gro…
Browse files Browse the repository at this point in the history
…up type
  • Loading branch information
wader committed Nov 17, 2021
1 parent 3cea849 commit 986d5ec
Show file tree
Hide file tree
Showing 80 changed files with 422 additions and 419 deletions.
2 changes: 1 addition & 1 deletion doc/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[./formats_table.jq]: sh-start

|Name |Description |Uses|
|Name |Description |Dependencies|
|- |- |-|
|`aac_frame` |Advanced&nbsp;Audio&nbsp;Coding&nbsp;frame |<sub></sub>|
|`adts` |Audio&nbsp;Data&nbsp;Transport&nbsp;Stream |<sub>`adts_frame`</sub>|
Expand Down
2 changes: 1 addition & 1 deletion doc/formats_table.jq
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def nbsp: gsub(" "; "&nbsp;");
[ {
name: "Name",
desc: "Description",
uses: "Uses"
uses: "Dependencies"
},
{
name: "-",
Expand Down
2 changes: 1 addition & 1 deletion format/all/all.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package all imports and registers all formats in the default registry
// Package all registers all builtin formats with the default registry
//nolint:revive
package all

Expand Down
6 changes: 3 additions & 3 deletions format/ape/apev2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/wader/fq/pkg/decode"
)

var imageFormat []*decode.Format
var imageFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.APEV2,
Description: "APEv2 metadata tag",
DecodeFn: apev2Decode,
Dependencies: []decode.Dependency{
{Names: []string{format.IMAGE}, Formats: &imageFormat},
{Names: []string{format.IMAGE}, Group: &imageFormat},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion format/av1/av1_ccr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.AV1_CCR,
Description: "AV1 Codec Configuration Record",
DecodeFn: ccrDecode,
Expand Down
6 changes: 3 additions & 3 deletions format/av1/av1_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
"github.com/wader/fq/pkg/decode"
)

var obuFormat []*decode.Format
var obuFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.AV1_FRAME,
Description: "AV1 frame",
DecodeFn: frameDecode,
RootArray: true,
RootName: "frame",
Dependencies: []decode.Dependency{
{Names: []string{format.AV1_OBU}, Formats: &obuFormat},
{Names: []string{format.AV1_OBU}, Group: &obuFormat},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion format/av1/av1_obu.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.AV1_OBU,
Description: "AV1 Open Bitstream Unit",
DecodeFn: obuDecode,
Expand Down
8 changes: 4 additions & 4 deletions format/bzip2/bzip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
"github.com/wader/fq/pkg/decode"
)

var probeFormat []*decode.Format
var probeGroup decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.BZIP2,
Description: "bzip2 compression",
Groups: []string{format.PROBE},
DecodeFn: gzDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.PROBE}, Formats: &probeFormat},
{Names: []string{format.PROBE}, Group: &probeGroup},
},
})
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func gzDecode(d *decode.D, in interface{}) interface{} {
}
// calculatedCRC32 := crc32W.Sum(nil)
uncompressedBB := bitio.NewBufferFromBytes(uncompressed.Bytes(), -1)
dv, _, _ := d.FieldTryFormatBitBuf("uncompressed", uncompressedBB, probeFormat, nil)
dv, _, _ := d.FieldTryFormatBitBuf("uncompressed", uncompressedBB, probeGroup, nil)
if dv == nil {
d.FieldRootBitBuf("uncompressed", uncompressedBB)
}
Expand Down
2 changes: 1 addition & 1 deletion format/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.DNS,
Description: "DNS packet",
DecodeFn: dnsDecode,
Expand Down
2 changes: 1 addition & 1 deletion format/elf/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// TODO: p_type hi/lo

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.ELF,
Description: "Executable and Linkable Format",
Groups: []string{format.PROBE},
Expand Down
10 changes: 5 additions & 5 deletions format/flac/flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import (
"github.com/wader/fq/pkg/decode"
)

var flacMetadatablockFormat []*decode.Format
var flacFrameFormat []*decode.Format
var flacMetadatablockFormat decode.Group
var flacFrameFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLAC,
Description: "Free Lossless Audio Codec file",
Groups: []string{format.PROBE},
DecodeFn: flacDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.FLAC_METADATABLOCKS}, Formats: &flacMetadatablockFormat},
{Names: []string{format.FLAC_FRAME}, Formats: &flacFrameFormat},
{Names: []string{format.FLAC_METADATABLOCKS}, Group: &flacMetadatablockFormat},
{Names: []string{format.FLAC_FRAME}, Group: &flacFrameFormat},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion format/flac/flac_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLAC_FRAME,
Description: "FLAC frame",
DecodeFn: frameDecode,
Expand Down
14 changes: 7 additions & 7 deletions format/flac/flac_metadatablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"github.com/wader/fq/pkg/decode"
)

var flacStreaminfoFormat []*decode.Format
var flacPicture []*decode.Format
var vorbisCommentFormat []*decode.Format
var flacStreaminfoFormat decode.Group
var flacPicture decode.Group
var vorbisCommentFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLAC_METADATABLOCK,
Description: "FLAC metadatablock",
DecodeFn: metadatablockDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.FLAC_STREAMINFO}, Formats: &flacStreaminfoFormat},
{Names: []string{format.FLAC_PICTURE}, Formats: &flacPicture},
{Names: []string{format.VORBIS_COMMENT}, Formats: &vorbisCommentFormat},
{Names: []string{format.FLAC_STREAMINFO}, Group: &flacStreaminfoFormat},
{Names: []string{format.FLAC_PICTURE}, Group: &flacPicture},
{Names: []string{format.VORBIS_COMMENT}, Group: &vorbisCommentFormat},
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions format/flac/flac_metadatablocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"github.com/wader/fq/pkg/decode"
)

var flacMetadatablockForamt []*decode.Format
var flacMetadatablockForamt decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLAC_METADATABLOCKS,
Description: "FLAC metadatablocks",
DecodeFn: metadatablocksDecode,
RootArray: true,
RootName: "metadatablocks",
Dependencies: []decode.Dependency{
{Names: []string{format.FLAC_METADATABLOCK}, Formats: &flacMetadatablockForamt},
{Names: []string{format.FLAC_METADATABLOCK}, Group: &flacMetadatablockForamt},
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions format/flac/flac_picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/wader/fq/pkg/decode"
)

var images []*decode.Format
var images decode.Group

var pictureTypeNames = decode.UToStr{
0: "Other",
Expand All @@ -33,12 +33,12 @@ var pictureTypeNames = decode.UToStr{
}

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLAC_PICTURE,
Description: "FLAC metadatablock picture",
DecodeFn: pictureDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.IMAGE}, Formats: &images},
{Names: []string{format.IMAGE}, Group: &images},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion format/flac/flac_streaminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLAC_STREAMINFO,
Description: "FLAC streaminfo",
DecodeFn: streaminfoDecode,
Expand Down
2 changes: 1 addition & 1 deletion format/flv/flv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.FLV,
Description: "Flash video",
Groups: []string{format.PROBE},
Expand Down
2 changes: 1 addition & 1 deletion format/gif/gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.GIF,
Description: "Graphics Interchange Format",
Groups: []string{format.PROBE, format.IMAGE},
Expand Down
6 changes: 3 additions & 3 deletions format/gzip/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import (
"github.com/wader/fq/pkg/decode"
)

var probeFormat []*decode.Format
var probeFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.GZIP,
Description: "gzip compression",
Groups: []string{format.PROBE},
DecodeFn: gzDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.PROBE}, Formats: &probeFormat},
{Names: []string{format.PROBE}, Group: &probeFormat},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion format/icc/icc_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.ICC_PROFILE,
Description: "International Color Consortium profile",
DecodeFn: iccProfileDecode,
Expand Down
2 changes: 1 addition & 1 deletion format/id3/id3v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// TODO: comment 28 long, zero byte, track number

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.ID3V1,
Description: "ID3v1 metadata",
DecodeFn: id3v1Decode,
Expand Down
2 changes: 1 addition & 1 deletion format/id3/id3v11.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.ID3V11,
Description: "ID3v1.1 metadata",
DecodeFn: id3v11Decode,
Expand Down
6 changes: 3 additions & 3 deletions format/id3/id3v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
"golang.org/x/text/encoding/unicode"
)

var imageFormat []*decode.Format
var imageFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.ID3V2,
Description: "ID3v2 metadata",
DecodeFn: id3v2Decode,
Dependencies: []decode.Dependency{
{Names: []string{format.IMAGE}, Formats: &imageFormat},
{Names: []string{format.IMAGE}, Group: &imageFormat},
},
})
}
Expand Down
10 changes: 5 additions & 5 deletions format/jpeg/jpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (
"github.com/wader/fq/pkg/decode"
)

var exifFormat []*decode.Format
var iccProfileFormat []*decode.Format
var exifFormat decode.Group
var iccProfileFormat decode.Group

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.JPEG,
Description: "Joint Photographic Experts Group file",
Groups: []string{format.PROBE, format.IMAGE},
DecodeFn: jpegDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.EXIF}, Formats: &exifFormat},
{Names: []string{format.ICC_PROFILE}, Formats: &iccProfileFormat},
{Names: []string{format.EXIF}, Group: &exifFormat},
{Names: []string{format.ICC_PROFILE}, Group: &iccProfileFormat},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion format/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func init() {
registry.MustRegister(&decode.Format{
registry.MustRegister(decode.Format{
Name: format.JSON,
Description: "JSON",
ProbeOrder: 100, // last
Expand Down

0 comments on commit 986d5ec

Please sign in to comment.