Massively refactor packages.
parent
6fe3925e18
commit
51852d9f87
|
@ -1,7 +1,7 @@
|
||||||
package authentication
|
package authentication
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.icedream.tech/icedream/uplink/internal/channels"
|
"git.icedream.tech/icedream/uplink/app/channels"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Authenticator interface {
|
type Authenticator interface {
|
|
@ -1,7 +1,7 @@
|
||||||
package authentication
|
package authentication
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.icedream.tech/icedream/uplink/internal/channels"
|
"git.icedream.tech/icedream/uplink/app/channels"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DummyAuthenticator struct{}
|
type DummyAuthenticator struct{}
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"git.icedream.tech/icedream/uplink/internal"
|
"git.icedream.tech/icedream/uplink/app/streams"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
|
@ -14,7 +14,7 @@ type Channel struct {
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
MimeType string
|
MimeType string
|
||||||
InputStream *internal.Stream
|
InputStream *streams.Stream
|
||||||
OutputStreams map[string]ChannelOutputStream
|
OutputStreams map[string]ChannelOutputStream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,5 +56,5 @@ func NewChannel() *Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelOutputStream struct {
|
type ChannelOutputStream struct {
|
||||||
*internal.Stream
|
*streams.Stream
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ package media
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"git.icedream.tech/icedream/uplink/internal/pubsub"
|
"git.icedream.tech/icedream/uplink/app/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DemuxedStream struct {
|
type DemuxedStream struct {
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.icedream.tech/icedream/uplink/internal/pubsub"
|
"git.icedream.tech/icedream/uplink/app/pubsub"
|
||||||
|
|
||||||
"github.com/3d0c/gmf"
|
"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
|
package httpserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "git.icedream.tech/icedream/uplink/internal"
|
_ "git.icedream.tech/icedream/uplink/app"
|
||||||
"git.icedream.tech/icedream/uplink/internal/authentication"
|
"git.icedream.tech/icedream/uplink/app/authentication"
|
||||||
channels "git.icedream.tech/icedream/uplink/internal/channels"
|
channels "git.icedream.tech/icedream/uplink/app/channels"
|
||||||
_ "git.icedream.tech/icedream/uplink/internal/transcoders"
|
_ "git.icedream.tech/icedream/uplink/app/transcoders"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package internal
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package internal
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package internal
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package internal
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"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 (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"git.icedream.tech/icedream/uplink/internal"
|
"git.icedream.tech/icedream/uplink/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TranscoderInstance interface {
|
type TranscoderInstance interface {
|
||||||
io.WriteCloser
|
io.WriteCloser
|
||||||
Init(out *internal.Stream)
|
Init(out *app.Stream)
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@ package lametranscoder
|
||||||
import (
|
import (
|
||||||
"github.com/viert/lame"
|
"github.com/viert/lame"
|
||||||
|
|
||||||
"git.icedream.tech/icedream/uplink/internal"
|
"git.icedream.tech/icedream/uplink/app"
|
||||||
"git.icedream.tech/icedream/uplink/internal/transcoders"
|
"git.icedream.tech/icedream/uplink/app/transcoders"
|
||||||
"git.icedream.tech/icedream/uplink/internal/transcoders/options"
|
"git.icedream.tech/icedream/uplink/app/transcoders/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
var transcoderOptions = map[string]options.TranscoderOptionType{
|
var transcoderOptions = map[string]options.TranscoderOptionType{
|
||||||
|
@ -28,7 +28,7 @@ type TranscoderInstance struct {
|
||||||
*lame.LameWriter
|
*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 = lame.NewWriter(out)
|
||||||
instance.LameWriter.Encoder.SetBitrate(int(instance.options["bitrate"].(int64)))
|
instance.LameWriter.Encoder.SetBitrate(int(instance.options["bitrate"].(int64)))
|
||||||
instance.LameWriter.Encoder.SetQuality(int(instance.options["quality"].(int64)))
|
instance.LameWriter.Encoder.SetQuality(int(instance.options["quality"].(int64)))
|
|
@ -1,7 +1,7 @@
|
||||||
package transcoders
|
package transcoders
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.icedream.tech/icedream/uplink/internal/transcoders/options"
|
"git.icedream.tech/icedream/uplink/app/transcoders/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Transcoder interface {
|
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"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.icedream.tech/icedream/uplink/internal"
|
"git.icedream.tech/icedream/uplink/app/sources"
|
||||||
"git.icedream.tech/icedream/uplink/internal/sources"
|
"git.icedream.tech/icedream/uplink/app/streams"
|
||||||
|
|
||||||
humanize "github.com/dustin/go-humanize"
|
humanize "github.com/dustin/go-humanize"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
stream := internal.NewStream(128 * 1024)
|
stream := streams.NewStream(128 * 1024)
|
||||||
|
|
||||||
wr := lame.NewWriter(stream)
|
wr := lame.NewWriter(stream)
|
||||||
wr.Encoder.SetBitrate(192)
|
wr.Encoder.SetBitrate(192)
|
||||||
|
@ -57,11 +57,11 @@ func main() {
|
||||||
|
|
||||||
cancel := w.(http.CloseNotifier).CloseNotify()
|
cancel := w.(http.CloseNotifier).CloseNotify()
|
||||||
|
|
||||||
sr := internal.NewStreamReader(stream)
|
sr := streams.NewStreamReader(stream)
|
||||||
var n int64
|
var n int64
|
||||||
var err error
|
var err error
|
||||||
if r.Header.Get("icy-metadata") == "1" {
|
if r.Header.Get("icy-metadata") == "1" {
|
||||||
mstream := internal.NewMetadataInjector(sr, 2*1024)
|
mstream := streams.NewMetadataInjector(sr, 2*1024)
|
||||||
mstream.Metadata = map[string]string{
|
mstream.Metadata = map[string]string{
|
||||||
"StreamTitle": "beep",
|
"StreamTitle": "beep",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue