-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor flac_streaminfo and flac_metadata from flac_metadatablocks Some deocde bitbuf api cleanup
- Loading branch information
Showing
28 changed files
with
1,445 additions
and
950 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package flac | ||
|
||
// TODO: 24 bit picture length truncate warning | ||
// TODO: Cuesheet | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/wader/fq/format" | ||
"github.com/wader/fq/format/registry" | ||
"github.com/wader/fq/pkg/decode" | ||
) | ||
|
||
var flacStreaminfoFormat []*decode.Format | ||
var flacPicture []*decode.Format | ||
var vorbisCommentFormat []*decode.Format | ||
|
||
func init() { | ||
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}, | ||
}, | ||
}) | ||
} | ||
|
||
const ( | ||
MetadataBlockStreaminfo = 0 | ||
MetadataBlockPadding = 1 | ||
MetadataBlockApplication = 2 | ||
MetadataBlockSeektable = 3 | ||
MetadataBlockVorbisComment = 4 | ||
MetadataBlockCuesheet = 5 | ||
MetadataBlockPicture = 6 | ||
) | ||
|
||
var metadataBlockNames = map[uint]string{ | ||
MetadataBlockStreaminfo: "Streaminfo", | ||
MetadataBlockPadding: "Padding", | ||
MetadataBlockApplication: "Application", | ||
MetadataBlockSeektable: "Seektable", | ||
MetadataBlockVorbisComment: "Vorbis comment", | ||
MetadataBlockCuesheet: "Cuesheet", | ||
MetadataBlockPicture: "Picture", | ||
} | ||
|
||
func metadatablockDecode(d *decode.D, in interface{}) interface{} { | ||
var hasStreamInfo bool | ||
var streamInfo format.FlacStreamInfo | ||
|
||
isLastBlock := d.FieldBool("last_block") | ||
typ := d.FieldUFn("type", func() (uint64, decode.DisplayFormat, string) { | ||
t := d.U7() | ||
name := "Unknown" | ||
if s, ok := metadataBlockNames[uint(t)]; ok { | ||
name = s | ||
} | ||
return t, decode.NumberDecimal, name | ||
}) | ||
length := d.FieldU24("length") | ||
|
||
switch typ { | ||
case MetadataBlockStreaminfo: | ||
flacStreaminfoOut, ok := d.Format(flacStreaminfoFormat, nil).(format.FlacStreaminfoOut) | ||
if !ok { | ||
d.Invalid(fmt.Sprintf("expected FlacStreaminfoOut, got %#+v", flacStreaminfoOut)) | ||
} | ||
hasStreamInfo = true | ||
streamInfo = flacStreaminfoOut.StreamInfo | ||
case MetadataBlockVorbisComment: | ||
d.FieldFormatLen("comment", int64(length*8), vorbisCommentFormat, nil) | ||
case MetadataBlockPicture: | ||
d.FieldFormatLen("picture", int64(length*8), flacPicture, nil) | ||
case MetadataBlockSeektable: | ||
seektableCount := length / 18 | ||
d.FieldArrayFn("seekpoints", func(d *decode.D) { | ||
for i := uint64(0); i < seektableCount; i++ { | ||
d.FieldStructFn("seekpoint", func(d *decode.D) { | ||
d.FieldUFn("sample_number", func() (uint64, decode.DisplayFormat, string) { | ||
n := d.U64() | ||
d := "" | ||
if n == 0xffffffffffffffff { | ||
d = "Placeholder" | ||
} | ||
return n, decode.NumberDecimal, d | ||
}) | ||
d.FieldU64("offset") | ||
d.FieldU16("number_of_samples") | ||
}) | ||
} | ||
}) | ||
case MetadataBlockApplication: | ||
d.FieldUTF8("id", 4) | ||
d.FieldBitBufLen("data", int64((length-4)*8)) | ||
default: | ||
d.FieldBitBufLen("data", int64(length*8)) | ||
} | ||
|
||
return format.FlacMetadatablockOut{ | ||
IsLastBlock: isLastBlock, | ||
HasStreamInfo: hasStreamInfo, | ||
StreamInfo: streamInfo, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package flac | ||
|
||
import ( | ||
"github.com/wader/fq/format" | ||
"github.com/wader/fq/format/registry" | ||
"github.com/wader/fq/pkg/decode" | ||
) | ||
|
||
func init() { | ||
registry.MustRegister(&decode.Format{ | ||
Name: format.FLAC_STREAMINFO, | ||
Description: "FLAC streaminfo", | ||
DecodeFn: streaminfoDecode, | ||
}) | ||
} | ||
|
||
func streaminfoDecode(d *decode.D, in interface{}) interface{} { | ||
d.FieldU16("minimum_block_size") | ||
d.FieldU16("maximum_block_size") | ||
d.FieldU24("minimum_frame_size") | ||
d.FieldU24("maximum_frame_size") | ||
sampleRate := d.FieldU("sample_rate", 20) | ||
// <3> (number of channels)-1. FLAC supports from 1 to 8 channels | ||
d.FieldUFn("channels", func() (uint64, decode.DisplayFormat, string) { return d.U3() + 1, decode.NumberDecimal, "" }) | ||
// <5> (bits per sample)-1. FLAC supports from 4 to 32 bits per sample. Currently the reference encoder and decoders only support up to 24 bits per sample. | ||
bitPerSample := d.FieldUFn("bits_per_sample", func() (uint64, decode.DisplayFormat, string) { | ||
return d.U5() + 1, decode.NumberDecimal, "" | ||
}) | ||
totalSamplesInStream := d.FieldU("total_samples_in_stream", 36) | ||
d.FieldBitBufLen("md5", 16*8) | ||
|
||
return format.FlacStreaminfoOut{ | ||
StreamInfo: format.FlacStreamInfo{ | ||
SampleRate: sampleRate, | ||
BitPerSample: bitPerSample, | ||
TotalSamplesInStream: totalSamplesInStream, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.