video-server
video-server copied to clipboard
Allow user to better control threads
I wanted to propose a new blocking method to run the Stream loop.
This blocking method allows us to pull out the go routines into the caller's code so that the caller can control startup, and shutdown for it's own methods. In my case, I wanted to split out the file generator from the api, but once those services were split I needed to be able to be able to wait for the process / be able to shut it down
Really like the abstractions, thank you for the code :)
Here's an example of it's usage, that allows the caller to configure signals to stop the process
import (
"context"
"fmt"
videoserver "github.com/LdDl/video-server"
"os"
"os/signal"
"providence/routes"
)
func main() {
conf, err := routes.LoadConfigFromEnv("APP")
if err != nil {
panic(err)
}
proxyConf, err := videoserver.NewConfiguration(conf.StreamProxyConfigFile)
if err != nil {
panic(fmt.Errorf("could not load config for stream proxy: %w", err))
}
proxy, err := videoserver.NewApplication(proxyConf)
if err != nil {
panic(fmt.Errorf("could not create new application: %w", err))
}
ctx := context.Background()
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, os.Kill)
for k, _ := range proxy.Streams.Streams {
go proxy.RunStream(ctx, k)
}
<-sigCh
}
Hi, thank you for PR
func (sm *StreamsStorage) GetStream(id uuid.UUID) (string, []string) {
sm.Lock()
defer sm.Unlock()
return sm.Streams[id].URL, sm.Streams[id].SupportedStreamTypes
}
Isn't this code could lead us to panic is case sm.Streams[id] == nil (not found)? I'd rather return ("", []string{}) in that case (or error?)