Compare commits
No commits in common. "f8dce5ce9d100b76653226626553ea7c67655759" and "69147a81b3143f95119fc99ba4e77bb5cd770cf2" have entirely different histories.
f8dce5ce9d
...
69147a81b3
|
@ -56,7 +56,6 @@ func (channel *Channel) SetMetadata(data map[string]string) {
|
||||||
func (channel *Channel) Metadata() chan map[string]string {
|
func (channel *Channel) Metadata() chan map[string]string {
|
||||||
outC := make(chan map[string]string)
|
outC := make(chan map[string]string)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(outC)
|
|
||||||
c := channel.Events.Sub("metadata")
|
c := channel.Events.Sub("metadata")
|
||||||
forloop:
|
forloop:
|
||||||
for event := range c {
|
for event := range c {
|
||||||
|
|
|
@ -39,23 +39,22 @@ func (mi *MetadataInjector) writeMetadata() (n int, err error) {
|
||||||
|
|
||||||
func (mi *MetadataInjector) Write(data []byte) (n int, err error) {
|
func (mi *MetadataInjector) Write(data []byte) (n int, err error) {
|
||||||
for n < len(data) {
|
for n < len(data) {
|
||||||
restLen := len(data) - n
|
|
||||||
toWrite := mi.MetadataInterval - mi.offset
|
toWrite := mi.MetadataInterval - mi.offset
|
||||||
if toWrite > restLen {
|
|
||||||
toWrite = restLen
|
|
||||||
}
|
|
||||||
|
|
||||||
if toWrite <= 0 {
|
if toWrite <= 0 {
|
||||||
_, err = mi.writeMetadata()
|
_, cerr := mi.writeMetadata()
|
||||||
if err != nil {
|
//n += cn
|
||||||
|
if cerr != nil {
|
||||||
|
err = cerr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mi.offset = 0
|
mi.offset = 0
|
||||||
|
// toWrite = mi.MetadataInterval
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
outBytes := make([]byte, toWrite)
|
outBytes := make([]byte, toWrite)
|
||||||
copy(outBytes, data[n:n+toWrite])
|
copy(outBytes, data[mi.offset:mi.offset+toWrite])
|
||||||
cn, cerr := mi.Writer.Write(outBytes)
|
cn, cerr := mi.Writer.Write(outBytes)
|
||||||
n += cn
|
n += cn
|
||||||
mi.offset += cn
|
mi.offset += cn
|
||||||
|
|
|
@ -60,13 +60,6 @@ func (instance *pluginInstance) Init() {
|
||||||
ctx.Writer.Header().Set("icy-metadata", "1")
|
ctx.Writer.Header().Set("icy-metadata", "1")
|
||||||
ctx.Writer.Header().Set("icy-metaint", fmt.Sprintf("%d", metaInt))
|
ctx.Writer.Header().Set("icy-metaint", fmt.Sprintf("%d", metaInt))
|
||||||
}
|
}
|
||||||
ctx.Writer.Header().Set("icy-name", "Channel name") // TODO
|
|
||||||
ctx.Writer.Header().Set("icy-pub", "0") // TODO
|
|
||||||
ctx.Writer.Header().Set("Server", "Uplink/0.0.0; Icecast 2.4.0 compatible")
|
|
||||||
ctx.Writer.Header().Set("Cache-Control", "no-cache, no-store")
|
|
||||||
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type")
|
|
||||||
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD")
|
|
||||||
ctx.Writer.WriteHeader(200)
|
ctx.Writer.WriteHeader(200)
|
||||||
|
|
||||||
w := ctx.Writer
|
w := ctx.Writer
|
||||||
|
@ -80,23 +73,11 @@ func (instance *pluginInstance) Init() {
|
||||||
if sendMetadata {
|
if sendMetadata {
|
||||||
mw = streams.NewMetadataInjector(w, metaInt)
|
mw = streams.NewMetadataInjector(w, metaInt)
|
||||||
nw = mw
|
nw = mw
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
mw.SetMetadata(metadataToWrite)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := io.Copy(nw, sr)
|
_, err := io.Copy(nw, sr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("copying stream to output failed:", err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue