Compare commits
4 Commits
0d8ecc64ad
...
994c0995e0
Author | SHA1 | Date |
---|---|---|
|
994c0995e0 | |
|
a99fa94072 | |
|
331286f9d0 | |
|
c0774e8ba6 |
|
@ -13,7 +13,7 @@ import (
|
|||
func Test_Demux(t *testing.T) {
|
||||
Convey("Demuxer", t, func() {
|
||||
Convey("audio-only", func() {
|
||||
reader, _ := os.Open("mpthreetest.mp3")
|
||||
reader, _ := os.Open("testassets/mpthreetest.mp3")
|
||||
defer reader.Close()
|
||||
|
||||
demuxer := Demux(reader)
|
||||
|
@ -43,7 +43,7 @@ func Test_Demux(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("video and audio", func() {
|
||||
reader, _ := os.Open("small.ogv")
|
||||
reader, _ := os.Open("testassets/small.ogv")
|
||||
defer reader.Close()
|
||||
|
||||
demuxer := Demux(reader)
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
func Test_Muxer(t *testing.T) {
|
||||
Convey("Muxer", t, func() {
|
||||
Convey("audio-only", func() {
|
||||
reader, _ := os.Open("mpthreetest.mp3")
|
||||
reader, _ := os.Open("testassets/mpthreetest.mp3")
|
||||
defer reader.Close()
|
||||
|
||||
demuxer := Demux(reader)
|
||||
|
|
3
main.go
3
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"log"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/app"
|
||||
"git.icedream.tech/icedream/uplink/plugins/icecast/input"
|
||||
"git.icedream.tech/icedream/uplink/plugins/icecast/output"
|
||||
"git.icedream.tech/icedream/uplink/plugins/test/sine"
|
||||
)
|
||||
|
@ -16,7 +17,7 @@ func main() {
|
|||
|
||||
func run() (err error) {
|
||||
backend := app.New()
|
||||
// backend.UsePlugin(icecast_input.Plugin)
|
||||
backend.UsePlugin(icecast_input.Plugin)
|
||||
backend.UsePlugin(icecast_output.Plugin)
|
||||
backend.UsePlugin(sine.Plugin)
|
||||
backend.Init()
|
||||
|
|
|
@ -2,13 +2,24 @@ package icecast_input
|
|||
|
||||
import (
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/app/authentication"
|
||||
"git.icedream.tech/icedream/uplink/app/channels"
|
||||
"git.icedream.tech/icedream/uplink/app/servers/http"
|
||||
"git.icedream.tech/icedream/uplink/app/streams"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var allowedCopyHeaders = []string{
|
||||
"icy-br",
|
||||
"icy-name",
|
||||
"icy-description",
|
||||
"icy-pub",
|
||||
"icy-url",
|
||||
"icy-genre",
|
||||
}
|
||||
|
||||
type pluginInstance struct {
|
||||
server *httpserver.Server
|
||||
authenticator authentication.Authenticator
|
||||
|
@ -25,7 +36,9 @@ func (instance *pluginInstance) SetChannelManager(channelManager *channels.Chann
|
|||
|
||||
func (instance *pluginInstance) SetServer(server *httpserver.Server) {
|
||||
instance.server = server
|
||||
}
|
||||
|
||||
func (instance *pluginInstance) Init() {
|
||||
router := instance.server.Router
|
||||
|
||||
router.PUT("/:channel", func(ctx *gin.Context) {
|
||||
|
@ -43,6 +56,36 @@ func (instance *pluginInstance) SetServer(server *httpserver.Server) {
|
|||
ctx.Status(401)
|
||||
return
|
||||
}
|
||||
io.Copy(channel.InputStream, ctx.Request.Body)
|
||||
|
||||
var sr io.Reader = ctx.Request.Body
|
||||
defer ctx.Request.Body.Close()
|
||||
if ctx.GetHeader("icy-metadata") == "1" {
|
||||
metaInt64, err := strconv.ParseInt(ctx.GetHeader("icy-metaint"), 10, 32)
|
||||
if err != nil {
|
||||
ctx.Status(400)
|
||||
return
|
||||
}
|
||||
metaInt := int(metaInt64)
|
||||
|
||||
// Client is sending metadata!
|
||||
mr := streams.NewMetadataExtractor(sr, metaInt)
|
||||
sr = mr
|
||||
|
||||
metadataChan := channel.Metadata()
|
||||
defer func() { metadataChan <- nil }()
|
||||
go func() {
|
||||
for metadata := range metadataChan {
|
||||
metadataToWrite := streams.Metadata{}
|
||||
if value, ok := metadata["StreamTitle"]; ok {
|
||||
metadataToWrite["StreamTitle"] = value
|
||||
}
|
||||
channel.SetMetadata(metadataToWrite)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
input := channel.AddInputStream("icecast")
|
||||
|
||||
io.Copy(input, sr)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue