From cb008da1d6c2b8e807ac79900234c88390628a51 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Tue, 16 Apr 2024 10:29:53 -0700 Subject: [PATCH] add directOutput interface (#681) --- egress/types.go | 81 ++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/egress/types.go b/egress/types.go index a86cff67..31ca9977 100644 --- a/egress/types.go +++ b/egress/types.go @@ -45,6 +45,11 @@ type EncodedOutputDeprecated interface { GetSegments() *livekit.SegmentedFileOutput } +type DirectOutput interface { + GetFile() *livekit.DirectFileOutput + GetWebsocketUrl() string +} + func GetTypes(request interface{}) (string, string) { switch req := request.(type) { case *livekit.EgressInfo_RoomComposite: @@ -60,50 +65,56 @@ func GetTypes(request interface{}) (string, string) { return EgressTypeTrackComposite, GetOutputType(req.TrackComposite) case *livekit.EgressInfo_Track: - switch req.Track.Output.(type) { - case *livekit.TrackEgressRequest_File: - return EgressTypeTrack, OutputTypeFile - case *livekit.TrackEgressRequest_WebsocketUrl: - return EgressTypeTrack, OutputTypeStream - } + return EgressTypeTrack, GetOutputType(req.Track) } return Unknown, Unknown } -func GetOutputType(req EncodedOutput) string { - outputs := make([]string, 0) - if len(req.GetFileOutputs()) > 0 { - outputs = append(outputs, OutputTypeFile) - } - if len(req.GetStreamOutputs()) > 0 { - outputs = append(outputs, OutputTypeStream) - } - if len(req.GetSegmentOutputs()) > 0 { - outputs = append(outputs, OutputTypeSegments) - } - if len(req.GetImageOutputs()) > 0 { - outputs = append(outputs, OutputTypeImages) - } +func GetOutputType(req interface{}) string { + if r, ok := req.(EncodedOutput); ok { + outputs := make([]string, 0) + if len(r.GetFileOutputs()) > 0 { + outputs = append(outputs, OutputTypeFile) + } + if len(r.GetStreamOutputs()) > 0 { + outputs = append(outputs, OutputTypeStream) + } + if len(r.GetSegmentOutputs()) > 0 { + outputs = append(outputs, OutputTypeSegments) + } + if len(r.GetImageOutputs()) > 0 { + outputs = append(outputs, OutputTypeImages) + } - switch len(outputs) { - default: - return OutputTypeMultiple - case 1: - return outputs[0] - case 0: - if r, ok := req.(EncodedOutputDeprecated); ok { - if r.GetFile() != nil { - return OutputTypeFile - } - if r.GetStream() != nil { - return OutputTypeStream - } - if r.GetSegments() != nil { - return OutputTypeSegments + switch len(outputs) { + default: + return OutputTypeMultiple + case 1: + return outputs[0] + case 0: + if r, ok := req.(EncodedOutputDeprecated); ok { + if r.GetFile() != nil { + return OutputTypeFile + } + if r.GetStream() != nil { + return OutputTypeStream + } + if r.GetSegments() != nil { + return OutputTypeSegments + } } } } + if r, ok := req.(DirectOutput); ok { + if r.GetFile() != nil { + return OutputTypeFile + } + if r.GetWebsocketUrl() != "" { + return OutputTypeStream + } + } + return Unknown }