Compare commits

...

2 commits

Author SHA1 Message Date
DataHoarder 95cc213b46
Bump goflac dependency
Some checks failed
continuous-integration/drone/push Build is failing
2023-01-29 12:51:40 +01:00
DataHoarder 3d1ca436e7
Changed format Identify to fixed number of bytes 2023-01-29 12:48:40 +01:00
15 changed files with 26 additions and 19 deletions

View file

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
"git.gammaspectra.live/S.O.N.G/go-fdkaac/fdkaac"
aacAdts "github.com/Eyevinn/mp4ff/aac"
"github.com/Eyevinn/mp4ff/mp4"
@ -503,7 +504,7 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
return nil
}
func (f Format) Identify(_ []byte, extension string) bool {
func (f Format) Identify(_ [format.IdentifyPeekBytes]byte, extension string) bool {
//TODO: add .m4a/mp4 detection
return extension == "aac" || extension == "adts"
}

View file

@ -6,7 +6,6 @@ import (
"fmt"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
"git.gammaspectra.live/S.O.N.G/voaac-go"
"io"
)
@ -93,6 +92,6 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
return nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
return extension == "aac" || extension == "adts"
}

View file

@ -136,6 +136,6 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
return nil
}
func (f Format) Identify(_ []byte, extension string) bool {
func (f Format) Identify(_ [format.IdentifyPeekBytes]byte, extension string) bool {
return extension == "alac" || extension == "mp4" || extension == "m4a"
}

View file

@ -224,7 +224,7 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
return nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
//No Ogg supported
return bytes.Compare(peek[:4], []byte{'f', 'L', 'a', 'C'}) == 0 || (bytes.Compare(peek[:3], []byte{'I', 'D', '3'}) == 0 && extension != "mp3") || extension == "flac"
}

View file

@ -161,6 +161,6 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
return nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
return (bytes.Compare(peek[:4], []byte{'O', 'g', 'g', 'S'}) == 0 && extension != "opus" && extension != "vorbis") || bytes.Compare(peek[:4], []byte{'f', 'L', 'a', 'C'}) == 0 || (bytes.Compare(peek[:3], []byte{'I', 'D', '3'}) == 0 && extension != "mp3") || extension == "flac" || extension == "ogg"
}

View file

@ -5,9 +5,11 @@ import (
"io"
)
const IdentifyPeekBytes = 16
type Format interface {
// Identify checks whether a format is of a type. peek includes a few first bytes, extension is the lowercase file extension without a dot.
Identify(peek []byte, extension string) bool
Identify(peek [IdentifyPeekBytes]byte, extension string) bool
// Name returns the name of the codec or format
Name() string
}

View file

@ -37,7 +37,7 @@ func (f NullFormat) Encode(audio.Source, io.WriteCloser, map[string]interface{})
return errors.New("null format")
}
func (f NullFormat) Identify([]byte, string) bool {
func (f NullFormat) Identify([format.IdentifyPeekBytes]byte, string) bool {
return false
}
@ -103,8 +103,8 @@ func GetDecoders(r io.ReadSeekCloser, pathName string) (decoders []format.Decode
if err != nil {
return
}
peek := make([]byte, 16)
if _, err = r.Read(peek); err != nil {
var peek [format.IdentifyPeekBytes]byte
if _, err = r.Read(peek[:]); err != nil {
return
}
if _, err = r.Seek(startOffset, io.SeekStart); err != nil {

View file

@ -5,6 +5,7 @@ package mp3
import (
"bytes"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
mp3Lib "git.gammaspectra.live/S.O.N.G/minimp3"
"golang.org/x/exp/slices"
"io"
@ -53,7 +54,7 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
return source, nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
//match ID3 / sync header
return peek[0] == 0xff && (peek[1]>>5) == 0b111 || (bytes.Compare(peek[:3], []byte{'I', 'D', '3'}) == 0 && extension != "flac") || extension == "mp3"
}

View file

@ -5,6 +5,7 @@ package mp3
import (
"bytes"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
mp3Lib "git.gammaspectra.live/S.O.N.G/go-mp3"
"golang.org/x/exp/slices"
"io"
@ -51,7 +52,7 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
return source, nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
//match ID3 / sync header
return peek[0] == 0xff && (peek[1]>>5) == 0b111 || (bytes.Compare(peek[:3], []byte{'I', 'D', '3'}) == 0 && extension != "flac") || extension == "mp3"
}

View file

@ -8,6 +8,7 @@ import (
"fmt"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/filter"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
libopus "git.gammaspectra.live/S.O.N.G/go-pus"
"io"
"time"
@ -177,6 +178,6 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
return bytes.Compare(peek[:4], []byte{'O', 'g', 'g', 'S'}) == 0 || extension == "opus" || extension == "ogg"
}

View file

@ -180,6 +180,6 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
return nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
return bytes.Compare(peek[:4], []byte{'T', 'T', 'A', '1'}) == 0 || extension == "tta"
}

View file

@ -6,6 +6,7 @@ import (
"bytes"
"fmt"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
libvorbis "git.gammaspectra.live/S.O.N.G/go-vorbis"
"io"
)
@ -111,6 +112,6 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
return bytes.Compare(peek[:4], []byte{'O', 'g', 'g', 'S'}) == 0 || extension == "vorbis" || extension == "ogg"
}

View file

@ -5,6 +5,7 @@ package vorbis
import (
"bytes"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
libvorbis "github.com/jfreymuth/oggvorbis"
"io"
)
@ -53,6 +54,6 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
return source, nil
}
func (f Format) Identify(peek []byte, extension string) bool {
func (f Format) Identify(peek [format.IdentifyPeekBytes]byte, extension string) bool {
return bytes.Compare(peek[:4], []byte{'O', 'g', 'g', 'S'}) == 0 || extension == "vorbis" || extension == "ogg"
}

2
go.mod
View file

@ -11,7 +11,7 @@ require (
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220721130634-3d5460c48ab6
git.gammaspectra.live/S.O.N.G/go-tta v0.0.0-20220226150007-096de1072bd6
git.gammaspectra.live/S.O.N.G/go-vorbis v0.0.0-20220728124510-303b3425eec0
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20230128225810-b55589f8c12a
git.gammaspectra.live/S.O.N.G/minimp3 v0.0.0-20230128141646-872fc9482587
git.gammaspectra.live/S.O.N.G/voaac-go v0.0.0-20221206094054-e088a49a96bc
github.com/Eyevinn/mp4ff v0.33.2

4
go.sum
View file

@ -14,8 +14,8 @@ git.gammaspectra.live/S.O.N.G/go-tta v0.0.0-20220226150007-096de1072bd6 h1:pGzSq
git.gammaspectra.live/S.O.N.G/go-tta v0.0.0-20220226150007-096de1072bd6/go.mod h1:cobkT8u8vq/+ngLy+feKS2M2ZT2HoCec5riA/0Cex3Q=
git.gammaspectra.live/S.O.N.G/go-vorbis v0.0.0-20220728124510-303b3425eec0 h1:kZA/fy9BhBgNGjY8OlQbIR4xkq9fmIeRQ+sXZ+m9Ic4=
git.gammaspectra.live/S.O.N.G/go-vorbis v0.0.0-20220728124510-303b3425eec0/go.mod h1:EZl7z0vfpaiu0ykpEkk6dh59XxBgWxAh4QPCCnkhICE=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0 h1:imcnwHUqaAJzws41B8sCSp/sUmVranNjAX205Jr4Jc0=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0/go.mod h1:/po1QgOh3xynbvi4sxdY6Iw8m5WPJfGGmry2boZD8fs=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20230128225810-b55589f8c12a h1:Suhx/0ER6JCqp58BRiay6lEBjYscWYKMMI9SaVy2XnE=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20230128225810-b55589f8c12a/go.mod h1:/po1QgOh3xynbvi4sxdY6Iw8m5WPJfGGmry2boZD8fs=
git.gammaspectra.live/S.O.N.G/minimp3 v0.0.0-20230128141646-872fc9482587 h1:yCfo8C7ANblOn5FEZLpkJZDl0v8OL/jOh3lIIe+v1fo=
git.gammaspectra.live/S.O.N.G/minimp3 v0.0.0-20230128141646-872fc9482587/go.mod h1:B34pwapfc0f6be6rJYg37xDeFPPB0bSyH0+DYM1lyEE=
git.gammaspectra.live/S.O.N.G/voaac-go v0.0.0-20221206094054-e088a49a96bc h1:57tqeyhK5ypviBHumVxdhiphsAX3nJXli6Ni/1+6Jn4=