mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-29 07:30:54 +02:00
Use reference to Stream
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"gitlab.crans.org/nounous/ghostream/stream"
|
||||
)
|
||||
|
||||
func handleStreamer(socket *srtgo.SrtSocket, streams map[string]stream.Stream, name string) {
|
||||
func handleStreamer(socket *srtgo.SrtSocket, streams map[string]*stream.Stream, name string) {
|
||||
// Check stream does not exist
|
||||
if _, ok := streams[name]; ok {
|
||||
log.Print("Stream already exists, refusing new streamer")
|
||||
@ -18,7 +18,7 @@ func handleStreamer(socket *srtgo.SrtSocket, streams map[string]stream.Stream, n
|
||||
|
||||
// Create stream
|
||||
log.Printf("New SRT streamer for stream %s", name)
|
||||
st := *stream.New()
|
||||
st := stream.New()
|
||||
streams[name] = st
|
||||
|
||||
// Create a new buffer
|
||||
@ -54,7 +54,7 @@ func handleStreamer(socket *srtgo.SrtSocket, streams map[string]stream.Stream, n
|
||||
delete(streams, name)
|
||||
}
|
||||
|
||||
func handleViewer(s *srtgo.SrtSocket, streams map[string]stream.Stream, name string) {
|
||||
func handleViewer(s *srtgo.SrtSocket, streams map[string]*stream.Stream, name string) {
|
||||
log.Printf("New SRT viewer for stream %s", name)
|
||||
|
||||
// Get requested stream
|
||||
@ -66,16 +66,16 @@ func handleViewer(s *srtgo.SrtSocket, streams map[string]stream.Stream, name str
|
||||
|
||||
// Register new output
|
||||
c := make(chan []byte, 128)
|
||||
st.Register(c)
|
||||
st.Register(c, false)
|
||||
|
||||
// Receive data and send them
|
||||
for {
|
||||
data := <-c
|
||||
for data := range c {
|
||||
if len(data) < 1 {
|
||||
log.Print("Remove SRT viewer because of end of stream")
|
||||
break
|
||||
}
|
||||
|
||||
// Send data
|
||||
_, err := s.Write(data, 1000)
|
||||
if err != nil {
|
||||
log.Printf("Remove SRT viewer because of sending error, %s", err)
|
||||
@ -84,6 +84,6 @@ func handleViewer(s *srtgo.SrtSocket, streams map[string]stream.Stream, name str
|
||||
}
|
||||
|
||||
// Close output
|
||||
st.Unregister(c)
|
||||
st.Unregister(c, false)
|
||||
s.Close()
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func splitHostPort(hostport string) (string, uint16, error) {
|
||||
}
|
||||
|
||||
// Serve SRT server
|
||||
func Serve(streams map[string]stream.Stream, authBackend auth.Backend, cfg *Options) {
|
||||
func Serve(streams map[string]*stream.Stream, authBackend auth.Backend, cfg *Options) {
|
||||
if !cfg.Enabled {
|
||||
// SRT is not enabled, ignore
|
||||
return
|
||||
|
@ -58,7 +58,7 @@ func TestServeSRT(t *testing.T) {
|
||||
}
|
||||
|
||||
// Init streams messaging and SRT server
|
||||
streams := make(map[string]stream.Stream)
|
||||
streams := make(map[string]*stream.Stream)
|
||||
go Serve(streams, nil, &Options{Enabled: true, ListenAddress: ":9711", MaxClients: 2})
|
||||
|
||||
ffmpeg := exec.Command("ffmpeg", "-hide_banner", "-loglevel", "error",
|
||||
|
Reference in New Issue
Block a user