From 5558aa52282805fc0963d480a94506e6c39e698f Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Mon, 1 Aug 2022 11:35:30 -0700 Subject: [PATCH] Make sure CreateIngest populates the stream_key and URL fields (#861) --- go.mod | 2 +- go.sum | 8 ++++++++ pkg/config/config.go | 5 +++++ pkg/service/ingress.go | 26 +++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 62e41acc6..cf982eec5 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/golang-lru v0.5.4 - github.com/livekit/protocol v0.13.5-0.20220728214908-67539ebcab2a + github.com/livekit/protocol v0.13.5-0.20220801175011-ae34dc3ec45d github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a github.com/mackerelio/go-osstat v0.2.1 github.com/magefile/mage v1.13.0 diff --git a/go.sum b/go.sum index ac3c9a612..d9051edc1 100644 --- a/go.sum +++ b/go.sum @@ -237,6 +237,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8= github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= +github.com/livekit/protocol v0.13.5-0.20220726184153-ad9c55ddef52 h1:E0trQ3RLu2b9hjSiJG1+1hyK/8v57NPJznA7/lKj0qY= +github.com/livekit/protocol v0.13.5-0.20220726184153-ad9c55ddef52/go.mod h1:Qd/Dn4BkJfZQy/IjtEeUOGXARrR7l09WDkg5SY8thkw= +github.com/livekit/protocol v0.13.5-0.20220727215941-ac26418a52e9 h1:e12j1EyiiTG56Ag44fwpVtnYQ6MVgLv4bYYI0nTgxZY= +github.com/livekit/protocol v0.13.5-0.20220727215941-ac26418a52e9/go.mod h1:Qd/Dn4BkJfZQy/IjtEeUOGXARrR7l09WDkg5SY8thkw= +github.com/livekit/protocol v0.13.5-0.20220801175011-ae34dc3ec45d h1:9VHZG4Tu723DA/jsg0APEmnk5blWRif9indB/nkdeFY= +github.com/livekit/protocol v0.13.5-0.20220801175011-ae34dc3ec45d/go.mod h1:vGQzKUaSYC92o5y7EbnhosgpoLWK9a3PneyYkGOGL0o= github.com/livekit/protocol v0.13.5-0.20220728214908-67539ebcab2a h1:tRioM9WNDjxGryt03ROYa8zq17J0MqHftCLr8Ex4dM0= github.com/livekit/protocol v0.13.5-0.20220728214908-67539ebcab2a/go.mod h1:vGQzKUaSYC92o5y7EbnhosgpoLWK9a3PneyYkGOGL0o= github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a h1:cENjhGfslLSDV07gt8ASy47Wd12Q0kBS7hsdunyQ62I= @@ -757,6 +763,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/pkg/config/config.go b/pkg/config/config.go index 043a57b0d..f263d4dc6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -38,6 +38,7 @@ type Config struct { Video VideoConfig `yaml:"video,omitempty"` Room RoomConfig `yaml:"room,omitempty"` TURN TURNConfig `yaml:"turn,omitempty"` + Ingress IngressConfig `yaml:ingress,omitempty"` WebHook WebHookConfig `yaml:"webhook,omitempty"` NodeSelector NodeSelectorConfig `yaml:"node_selector,omitempty"` KeyFile string `yaml:"key_file,omitempty"` @@ -190,6 +191,10 @@ type LimitConfig struct { BytesPerSec float32 `yaml:"bytes_per_sec"` } +type IngressConfig struct { + RTMPBaseURL string `yaml:"rtmp_base_url"` +} + func NewConfig(confString string, c *cli.Context) (*Config, error) { // start with defaults conf := &Config{ diff --git a/pkg/service/ingress.go b/pkg/service/ingress.go index 7e0c007e6..ec6483c80 100644 --- a/pkg/service/ingress.go +++ b/pkg/service/ingress.go @@ -2,9 +2,12 @@ package service import ( "context" + "errors" + "fmt" "google.golang.org/protobuf/proto" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/telemetry" "github.com/livekit/protocol/ingress" "github.com/livekit/protocol/livekit" @@ -13,6 +16,7 @@ import ( ) type IngressService struct { + conf *config.IngressConfig rpc ingress.RPC store IngressStore roomService livekit.RoomService @@ -21,6 +25,7 @@ type IngressService struct { } func NewIngressService( + conf *config.IngressConfig, rpc ingress.RPC, store IngressStore, rs livekit.RoomService, @@ -28,6 +33,7 @@ func NewIngressService( ) *IngressService { return &IngressService{ + conf: conf, rpc: rpc, store: store, roomService: rs, @@ -52,11 +58,13 @@ func (s *IngressService) CreateIngress(ctx context.Context, req *livekit.CreateI return nil, twirpAuthError(err) } + sk := utils.NewGuid("") + info := &livekit.IngressInfo{ IngressId: utils.NewGuid(utils.IngressPrefix), Name: req.Name, - StreamKey: "TODO", - Url: "TODO", + StreamKey: sk, + Url: newRtmpUrl(s.conf.RTMPBaseURL, sk), InputType: req.InputType, Audio: req.Audio, Video: req.Video, @@ -241,7 +249,15 @@ func (s *IngressService) entitiesWorker() { continue } - info, err := s.store.LoadIngress(context.Background(), req.IngressId) + var info *livekit.IngressInfo + var err error + if req.IngressId != "" { + info, err = s.store.LoadIngress(context.Background(), req.IngressId) + } else if req.StreamKey != "" { + info, err = s.store.LoadIngressFromStreamKey(context.Background(), req.StreamKey) + } else { + err = errors.New("request needs to specity either IngressId or StreamKey") + } err = s.rpc.SendResponse(context.Background(), req, info, err) if err != nil { logger.Errorw("could not send response", err) @@ -253,3 +269,7 @@ func (s *IngressService) entitiesWorker() { } } } + +func newRtmpUrl(baseUrl string, ingressId string) string { + return fmt.Sprintf("%s/%s", baseUrl, ingressId) +}