Skip to content

Commit 66c76d8

Browse files
DatanoiseTVDatanoiseTV
authored andcommitted
feat: Ogg Vorbis / Ogg Opus / FLAC decode, capture SOURCE Ogg headers
Transcoder and AutoDJ now handle any of MP3, Ogg Vorbis, Ogg Opus or native FLAC as input instead of only MP3. A new OpenDecoder factory sniffs the first bytes (ID3/MP3 sync, OggS with OpusHead/vorbis, fLaC) and returns a PCMDecoder producing interleaved S16LE stereo PCM. This replaces the direct mp3.NewDecoder calls in relay/transcode.go and relay/streamer.go. Output encoding still targets MP3 (shine) or Opus (kazzmir opus-go) — AAC is intentionally not included because no pure-Go encoder is viable. validateAudioFile now accepts OggS and fLaC magic bytes so AutoDJ will play .ogg/.opus/.flac files from disk. Fix BOS/Tags handling on the Icecast SOURCE handler: the code captures the initial Ogg pages (those with granule_position == 0 or the continuation sentinel) as bytes flow in, then stores them on the Stream as OggHead / OggHeaderOffset. Late-joining listeners get the full codec setup prepended instead of "Codec not found". Triggered by Content-Type of application/ogg or audio/ogg (plus variants). New deps: github.com/jfreymuth/oggvorbis, github.com/mewkiz/flac. Both pure Go, no CGO required. Added relay/decode_test.go covering the Ogg page walker and the decoder sniff.
1 parent cc26bbd commit 66c76d8

8 files changed

Lines changed: 577 additions & 8 deletions

File tree

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ require (
3434
github.com/google/uuid v1.6.0 // indirect
3535
github.com/hashicorp/errwrap v1.1.0 // indirect
3636
github.com/hashicorp/go-multierror v1.1.0 // indirect
37+
github.com/icza/bitio v1.1.0 // indirect
38+
github.com/jfreymuth/oggvorbis v1.0.5 // indirect
39+
github.com/jfreymuth/vorbis v1.0.2 // indirect
3740
github.com/jinzhu/inflection v1.0.0 // indirect
3841
github.com/jinzhu/now v1.1.5 // indirect
3942
github.com/mattn/go-isatty v0.0.20 // indirect
43+
github.com/mewkiz/flac v1.0.13 // indirect
44+
github.com/mewkiz/pkg v0.0.0-20250417130911-3f050ff8c56d // indirect
45+
github.com/mewpkg/term v0.0.0-20241026122259-37a80af23985 // indirect
4046
github.com/mitchellh/mapstructure v1.4.1 // indirect
4147
github.com/pion/datachannel v1.6.0 // indirect
4248
github.com/pion/dtls/v3 v3.1.2 // indirect

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
4949
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
5050
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
5151
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
52+
github.com/icza/bitio v1.1.0 h1:ysX4vtldjdi3Ygai5m1cWy4oLkhWTAi+SyO6HC8L9T0=
53+
github.com/icza/bitio v1.1.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
54+
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
55+
github.com/jfreymuth/oggvorbis v1.0.5 h1:u+Ck+R0eLSRhgq8WTmffYnrVtSztJcYrl588DM4e3kQ=
56+
github.com/jfreymuth/oggvorbis v1.0.5/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
57+
github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE=
58+
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
5259
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
5360
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
5461
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -57,6 +64,12 @@ github.com/kazzmir/opus-go v1.2.1 h1:uKHJgA4zlZv60eatfwGBhLdrovlPdRVBVco22MQQvmU
5764
github.com/kazzmir/opus-go v1.2.1/go.mod h1:oKDlLYxYVpknE4zKDmJyiLPB9RyhKw0n/l7EoPr6000=
5865
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
5966
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
67+
github.com/mewkiz/flac v1.0.13 h1:6wF8rRQKBFW159Daqx6Ro7K5ZnlVhHUKfS5aTsC4oXs=
68+
github.com/mewkiz/flac v1.0.13/go.mod h1:HfPYDA+oxjyuqMu2V+cyKcxF51KM6incpw5eZXmfA6k=
69+
github.com/mewkiz/pkg v0.0.0-20250417130911-3f050ff8c56d h1:IL2tii4jXLdhCeQN69HNzYYW1kl0meSG0wt5+sLwszU=
70+
github.com/mewkiz/pkg v0.0.0-20250417130911-3f050ff8c56d/go.mod h1:SIpumAnUWSy0q9RzKD3pyH3g1t5vdawUAPcW5tQrUtI=
71+
github.com/mewpkg/term v0.0.0-20241026122259-37a80af23985 h1:h8O1byDZ1uk6RUXMhj1QJU3VXFKXHDZxr4TXRPGeBa8=
72+
github.com/mewpkg/term v0.0.0-20241026122259-37a80af23985/go.mod h1:uiPmbdUbdt1NkGApKl7htQjZ8S7XaGUAVulJUJ9v6q4=
6073
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
6174
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
6275
github.com/pion/datachannel v1.6.0 h1:XecBlj+cvsxhAMZWFfFcPyUaDZtd7IJvrXqlXD/53i0=

0 commit comments

Comments
 (0)