Massively refactor packages.
parent
6fe3925e18
commit
51852d9f87
|
@ -1,7 +1,7 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
"git.icedream.tech/icedream/uplink/internal/channels"
|
||||
"git.icedream.tech/icedream/uplink/app/channels"
|
||||
)
|
||||
|
||||
type Authenticator interface {
|
|
@ -1,7 +1,7 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
"git.icedream.tech/icedream/uplink/internal/channels"
|
||||
"git.icedream.tech/icedream/uplink/app/channels"
|
||||
)
|
||||
|
||||
type DummyAuthenticator struct{}
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"sync"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/internal"
|
||||
"git.icedream.tech/icedream/uplink/app/streams"
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
|
@ -14,7 +14,7 @@ type Channel struct {
|
|||
Name string
|
||||
Description string
|
||||
MimeType string
|
||||
InputStream *internal.Stream
|
||||
InputStream *streams.Stream
|
||||
OutputStreams map[string]ChannelOutputStream
|
||||
}
|
||||
|
||||
|
@ -56,5 +56,5 @@ func NewChannel() *Channel {
|
|||
}
|
||||
|
||||
type ChannelOutputStream struct {
|
||||
*internal.Stream
|
||||
*streams.Stream
|
||||
}
|
|
@ -3,7 +3,7 @@ package media
|
|||
import (
|
||||
"io"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/internal/pubsub"
|
||||
"git.icedream.tech/icedream/uplink/app/pubsub"
|
||||
)
|
||||
|
||||
type DemuxedStream struct {
|
|
@ -4,7 +4,7 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/internal/pubsub"
|
||||
"git.icedream.tech/icedream/uplink/app/pubsub"
|
||||
|
||||
"github.com/3d0c/gmf"
|
||||
)
|
|
@ -0,0 +1,11 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"git.icedream.tech/icedream/uplink/app/channels"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
*gin.Engine
|
||||
*channels.ChannelManager
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
_ "git.icedream.tech/icedream/uplink/internal"
|
||||
"git.icedream.tech/icedream/uplink/internal/authentication"
|
||||
channels "git.icedream.tech/icedream/uplink/internal/channels"
|
||||
_ "git.icedream.tech/icedream/uplink/internal/transcoders"
|
||||
_ "git.icedream.tech/icedream/uplink/app"
|
||||
"git.icedream.tech/icedream/uplink/app/authentication"
|
||||
channels "git.icedream.tech/icedream/uplink/app/channels"
|
||||
_ "git.icedream.tech/icedream/uplink/app/transcoders"
|
||||
|
||||
"net/http"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package streams
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package streams
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package streams
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package streams
|
||||
|
||||
import (
|
||||
"io"
|
|
@ -0,0 +1,13 @@
|
|||
package streams
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
func NewStreamReader(stream *Stream) io.ReadCloser {
|
||||
r, w := io.Pipe()
|
||||
|
||||
stream.Subscribe(w)
|
||||
|
||||
return r
|
||||
}
|
|
@ -3,10 +3,10 @@ package transcoders
|
|||
import (
|
||||
"io"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/internal"
|
||||
"git.icedream.tech/icedream/uplink/app"
|
||||
)
|
||||
|
||||
type TranscoderInstance interface {
|
||||
io.WriteCloser
|
||||
Init(out *internal.Stream)
|
||||
Init(out *app.Stream)
|
||||
}
|
|
@ -3,9 +3,9 @@ package lametranscoder
|
|||
import (
|
||||
"github.com/viert/lame"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/internal"
|
||||
"git.icedream.tech/icedream/uplink/internal/transcoders"
|
||||
"git.icedream.tech/icedream/uplink/internal/transcoders/options"
|
||||
"git.icedream.tech/icedream/uplink/app"
|
||||
"git.icedream.tech/icedream/uplink/app/transcoders"
|
||||
"git.icedream.tech/icedream/uplink/app/transcoders/options"
|
||||
)
|
||||
|
||||
var transcoderOptions = map[string]options.TranscoderOptionType{
|
||||
|
@ -28,7 +28,7 @@ type TranscoderInstance struct {
|
|||
*lame.LameWriter
|
||||
}
|
||||
|
||||
func (instance *TranscoderInstance) Init(out *internal.Stream, samplerate int, channels int) {
|
||||
func (instance *TranscoderInstance) Init(out *app.Stream, samplerate int, channels int) {
|
||||
instance.LameWriter = lame.NewWriter(out)
|
||||
instance.LameWriter.Encoder.SetBitrate(int(instance.options["bitrate"].(int64)))
|
||||
instance.LameWriter.Encoder.SetQuality(int(instance.options["quality"].(int64)))
|
|
@ -1,7 +1,7 @@
|
|||
package transcoders
|
||||
|
||||
import (
|
||||
"git.icedream.tech/icedream/uplink/internal/transcoders/options"
|
||||
"git.icedream.tech/icedream/uplink/app/transcoders/options"
|
||||
)
|
||||
|
||||
type Transcoder interface {
|
|
@ -1,54 +0,0 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
type StreamReader struct {
|
||||
dataChan <-chan []byte
|
||||
cancelChan chan<- interface{}
|
||||
extraData []byte
|
||||
}
|
||||
|
||||
func NewStreamReader(stream *Stream) io.ReadCloser {
|
||||
|
||||
r, w := io.Pipe()
|
||||
|
||||
stream.Subscribe(w)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (reader *StreamReader) Close() error {
|
||||
reader.cancelChan <- nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (reader *StreamReader) Read(data []byte) (n int, err error) {
|
||||
n = 0
|
||||
ok := false
|
||||
|
||||
// Do we have a buffer to read data from?
|
||||
if reader.extraData == nil {
|
||||
// Fill our buffer with new data.
|
||||
reader.extraData, ok = <-reader.dataChan
|
||||
if !ok { // EOF?
|
||||
err = io.EOF
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Target array too small to fit all of our data? Keep the rest.
|
||||
if len(reader.extraData) > len(data) {
|
||||
copy(data, reader.extraData[0:len(data)])
|
||||
reader.extraData = reader.extraData[len(data):]
|
||||
n = len(data)
|
||||
return
|
||||
}
|
||||
|
||||
// Copy all of the buffer and reset the buffer.
|
||||
copy(data, reader.extraData)
|
||||
n = len(reader.extraData)
|
||||
reader.extraData = nil
|
||||
return
|
||||
}
|
10
main.go
10
main.go
|
@ -7,8 +7,8 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.icedream.tech/icedream/uplink/internal"
|
||||
"git.icedream.tech/icedream/uplink/internal/sources"
|
||||
"git.icedream.tech/icedream/uplink/app/sources"
|
||||
"git.icedream.tech/icedream/uplink/app/streams"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
stream := internal.NewStream(128 * 1024)
|
||||
stream := streams.NewStream(128 * 1024)
|
||||
|
||||
wr := lame.NewWriter(stream)
|
||||
wr.Encoder.SetBitrate(192)
|
||||
|
@ -57,11 +57,11 @@ func main() {
|
|||
|
||||
cancel := w.(http.CloseNotifier).CloseNotify()
|
||||
|
||||
sr := internal.NewStreamReader(stream)
|
||||
sr := streams.NewStreamReader(stream)
|
||||
var n int64
|
||||
var err error
|
||||
if r.Header.Get("icy-metadata") == "1" {
|
||||
mstream := internal.NewMetadataInjector(sr, 2*1024)
|
||||
mstream := streams.NewMetadataInjector(sr, 2*1024)
|
||||
mstream.Metadata = map[string]string{
|
||||
"StreamTitle": "beep",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue